001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.data.vpf.io;
017:
018: import java.util.Map;
019:
020: import org.geotools.data.vpf.ifc.VPFRow;
021:
022: /**
023: * TableRow.java Created: Thu Jan 02 23:58:39 2003
024: *
025: * @author <a href="mailto:kobit@users.fs.net">Artur Hefczyc</a>
026: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/vpf/src/main/java/org/geotools/data/vpf/io/TableRow.java $
027: * @version 1.0
028: */
029: public class TableRow implements VPFRow {
030: /**
031: * Describe variable <code>fieldsArr</code> here.
032: *
033: */
034: private RowField[] fieldsArr = null;
035:
036: /**
037: * Describe variable <code>fieldsMap</code> here.
038: *
039: */
040: private Map fieldsMap = null;
041:
042: /**
043: * Creates a new <code>TableRow</code> instance.
044: *
045: * @param fieldsArr a <code>RowField[]</code> value
046: * @param fieldsMap a <code>HashMap</code> value
047: */
048: public TableRow(RowField[] fieldsArr, Map fieldsMap) {
049: this .fieldsArr = fieldsArr;
050: this .fieldsMap = fieldsMap;
051: }
052:
053: // TableRow constructor
054:
055: /**
056: * Describe <code>toString</code> method here.
057: *
058: * @return a <code>String</code> value
059: */
060: public String toString() {
061: // StringBuffer buff = new StringBuffer(" ["+getClass().getName());
062: // buff.append(" (fieldsMap=");
063: // if (fieldsMap == null)
064: // {
065: // buff.append("null)");
066: // } // end of if (columnDefs == null)
067: // else
068: // {
069: // Iterator it = fieldsMap.entrySet().iterator();
070: // while (it.hasNext())
071: // {
072: // Map.Entry entry = (Map.Entry)it.next();
073: // buff.append("\n"+
074: // entry.getKey().toString()+"="+
075: // entry.getValue().toString());
076: // } // end of while (it.hasNext())
077: // buff.append("\n)");
078: // } // end of if (columnDefs == null) else
079: // buff.append("]");
080: StringBuffer buff = new StringBuffer();
081:
082: if (fieldsMap == null) {
083: buff.append("null)");
084: } else {
085: for (int i = 0; i < fieldsArr.length; i++) {
086: buff.append(fieldsArr[i].toString() + ":");
087: }
088:
089: buff.append(";");
090: }
091:
092: return buff.toString();
093: }
094:
095: /**
096: * Describe <code>fieldsCount</code> method here.
097: *
098: * @return an <code>int</code> value
099: */
100: public int fieldsCount() {
101: return fieldsArr.length;
102: }
103:
104: /**
105: * Describe <code>get</code> method here.
106: *
107: * @param name a <code>String</code> value
108: * @return a <code>RowField</code> value
109: */
110: public RowField get(String name) {
111: return (RowField) fieldsMap.get(name);
112: }
113:
114: /**
115: * Describe <code>get</code> method here.
116: *
117: * @param idx an <code>int</code> value
118: * @return a <code>RowField</code> value
119: */
120: public RowField get(int idx) {
121: return fieldsArr[idx];
122: }
123:
124: /**
125: * Describe <code>equals</code> method here.
126: *
127: * @param obj an <code>Object</code> value
128: * @return a <code>boolean</code> value
129: */
130: public boolean equals(Object obj) {
131: if ((obj == null) || !(obj instanceof TableRow)) {
132: return false;
133: }
134:
135: TableRow row = (TableRow) obj;
136:
137: if ((fieldsArr == null) && (row.fieldsArr == null)) {
138: return true;
139: }
140:
141: if ((fieldsArr == null) || (row.fieldsArr == null)) {
142: return false;
143: }
144:
145: if (fieldsArr.length != row.fieldsArr.length) {
146: return false;
147: }
148:
149: for (int i = 0; i < fieldsArr.length; i++) {
150: if (!fieldsArr[i].equals(row.fieldsArr[i])) {
151: return false;
152: }
153: }
154:
155: return true;
156: }
157:
158: public int hashCode() {
159: int code = 0;
160:
161: if ((fieldsArr == null) || (fieldsArr.length == 0)) {
162: code = super .hashCode();
163: } else {
164: for (int i = 0; i < fieldsArr.length; i++) {
165: code += fieldsArr[i].hashCode();
166: }
167: }
168:
169: return code;
170: }
171: }
|