PageRenderTime 63ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/components/forks/poi/src/loci/poi/util/IntList2d.java

http://github.com/openmicroscopy/bioformats
Java | 110 lines | 52 code | 10 blank | 48 comment | 5 complexity | ecc51e10801a2144eb4cd743948c6edf MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, BSD-2-Clause, MPL-2.0-no-copyleft-exception
  1. /*
  2. * #%L
  3. * Fork of Apache Jakarta POI.
  4. * %%
  5. * Copyright (C) 2008 - 2013 Open Microscopy Environment:
  6. * - Board of Regents of the University of Wisconsin-Madison
  7. * - Glencoe Software, Inc.
  8. * - University of Dundee
  9. * %%
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. * #L%
  22. */
  23. /*
  24. * Licensed to the Apache Software Foundation (ASF) under one or more
  25. * contributor license agreements. See the NOTICE file distributed with
  26. * this work for additional information regarding copyright ownership.
  27. * The ASF licenses this file to You under the Apache License, Version 2.0
  28. * (the "License"); you may not use this file except in compliance with
  29. * the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing, software
  34. * distributed under the License is distributed on an "AS IS" BASIS,
  35. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  36. * See the License for the specific language governing permissions and
  37. * limitations under the License.
  38. */
  39. package loci.poi.util;
  40. import java.util.List;
  41. import java.util.ArrayList;
  42. /**
  43. * Provides an interface for interacting with 2d arrays of integers. This
  44. * implementation will return 0 for items not yet allocated and automatically
  45. * increase the array size for set operations. You never get an index out of
  46. * bounds.
  47. *
  48. * @author Glen Stampoultzis (glens at apache.org)
  49. * @version $Id: IntList2d.java 496526 2007-01-15 22:46:35Z markt $
  50. */
  51. public class IntList2d
  52. {
  53. // Implemented using a List of IntList's.
  54. List rows = new ArrayList();
  55. public int get(int col, int row)
  56. {
  57. if (row >= rows.size())
  58. {
  59. return 0;
  60. }
  61. else
  62. {
  63. IntList cols = (IntList) rows.get(row);
  64. if (col >= cols.size())
  65. return 0;
  66. else
  67. return cols.get( col );
  68. }
  69. }
  70. public void set(int col, int row, int value)
  71. {
  72. resizeRows(row);
  73. resizeCols(row,col);
  74. IntList cols = (IntList) rows.get( row );
  75. cols.set( col, value );
  76. }
  77. private void resizeRows( int row )
  78. {
  79. while (rows.size() <= row)
  80. rows.add( new IntList() );
  81. }
  82. private void resizeCols( int row, int col )
  83. {
  84. IntList cols = (IntList) rows.get( row );
  85. while (cols.size() <= col)
  86. cols.add(0);
  87. }
  88. public boolean isAllocated( int col, int row )
  89. {
  90. if (row < rows.size())
  91. {
  92. IntList cols = (IntList) rows.get( row );
  93. return ( col < cols.size() );
  94. }
  95. else
  96. {
  97. return false;
  98. }
  99. }
  100. }