home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-18 | 5.3 KB | 187 lines |
- /*
- * Copyright (c) 1996 Krumel & Associates, Inc. All Rights Reserved.
- *
- * www.krumel.com - controls@krumel.com
- *
- * Permission is given to the buyer of this package for one software
- * developer to use this software on one CPU (one workstation) and to make
- * one backup copy. You may uitilize and/or midfy this class for use in your
- * projects. You may distribute or sell any executable which results from
- * using this code in yur application, except a utility or class of similar
- * nature to this product. You may distribute this this product in compiled
- * form only, but soley to be used with your cmpiled executable product
- * for the puposes of dynamic loading. You may NOT redistribute the source
- * code in any form or make it accessible through a network or other
- * distribution media to others. Please refer to the file "copyright.html"
- * for further important copyright and licensing information.
- *
- * The source code is the confidential and proprietary information
- * of Krumel & Associates, Inc. ("Confidential Information"). You shall
- * not disclose such Confidential Information and shall use it only in
- * accordance with the terms of the license agreement you entered into
- * with Krumel & Associates, Inc..
-
- * KRUMEL & ASSOCIATES MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
- * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
- * NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. KRUMEL & ASSOCIATES SHALL NOT
- * BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
- * MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
- */
-
- package symantec.itools.db.awt.genutil;
-
- import java.util.Enumeration;
-
- /**
- * An enumeration for the Matrix class.
- *
- * @version 1.1 June 2, 1997
- * @author Andy Krumel
- */
- public class MatrixEnumeration implements Enumeration {
- Matrix m ;
- int row = -1;
- MatrixElement elt;
-
- /**
- * Creates an enumeration for a matrix.
- */
- public MatrixEnumeration(Matrix matrix) {
- m = (Matrix)matrix.clone();
- }
-
- /**
- * Determines if more data exists in matrix.
- */
- public final boolean hasMoreElements() {
- if (m==null) {
- //already iterated
- return false;
- } else if (row==-1) {
- //have not gotten first element so see if any in matrix
- int size = m.rows();
- int currRow = 0;
- while(!m.containsRow(currRow)) {
- currRow++;
- if (size<currRow) { return false; }
- }
-
- return true;
- }
-
- return elt!=null;
- }
-
- /**
- * Determines if more valid rows exist in the matrix.
- */
- public final boolean hasMoreRows() {
- int size = m.rows();
- int nextRow = row+1;
-
- while(!m.containsRow(nextRow)) {
- nextRow++;
- if (size < nextRow) {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * Gets the next object.
- */
- public final Object nextElement() {
- if (row==-1 || elt.next==null) {
- findNextRow();
- } else {
- elt = elt.next;
- }
-
- return elt.obj;
- }
-
- private MatrixElement findNextRow() {
- int size = m.rows();
- row++;
- while(!m.containsRow(row)) {
- row++;
- if (size<row) {
- //no data left in matrix so we are done
- m = null;
- return null;
- }
- }
-
- return elt = m.firstRowElement(row);
- }
-
- /**
- * Gets the row number for the current element.
- */
- public final int currRow() { return row; }
-
- /**
- * Gets the column number for the current element.
- */
- public final int currCol() {
- if (elt==null) {
- return -1;
- } else {
- return elt.col;
- }
- }
-
- /**
- * Moves the matrix element pointer to the next valid row and returns the
- * first element in that row.
- */
- public final Object nextRow() {
- findNextRow();
-
- if (elt==null) {
- return null;
- }
-
- return elt.obj;
- }
-
- /**
- * Moves the matrix element pointer to the specified row. If no data exists
- * for that row, the pointer is moved to the next row with data.
- * @return The first object at that row (or next valid row) or null if no more
- * valid rows exist.
- */
- public final Object advanceTo(int r) throws IllegalArgumentException {
- if (r < row || r == row)
- throw new
- IllegalArgumentException("r must be greater than current row: r=" +
- r + " current row=" + row);
-
- if (r > m.rows()) {
- throw new IllegalArgumentException("requested row too large: r=" + r);
- }
-
- int size = m.rows();
- row = r;
- while(!m.containsRow(row)) {
- row++;
- if (size < row) {
- //no data left in matrix we are done
- m = null;
- return null;
- }
- }
-
- elt = m.firstRowElement(row);
-
- return elt.obj;
- }
-
- public final String toString() {
- return "MatrixEnumeration: row="+row+" col="+ (elt!=null ?(""+elt.col) :"-");
- }
- }
-