Strings.java |
package de.spieleck.util; /** * A class to represent a list of strings with appropriate * hashCode and equals implemented. * <P> * I'm surprised, that this is needed instead of String[]. */ public class Strings { String[] strs; public Strings(int n) { strs = new String[n]; } public Strings(String[] strs) { this.strs = strs; } public void setString(int i, String h) { strs[i] = h; } public int getLength() { return strs.length; } public String getString(int i) { return strs[i]; } public int hashCode() { int h = 0x55555555 + getLength() * getLength(); for(int i = 0; i < getLength(); i++) h ^= 60 * h + strs[i].hashCode(); return h; } public boolean equals(Object o) { if ( ! ( o instanceof Strings ) ) return false; // could be relaxed for String[] Strings h = (Strings) o; if ( getLength() != h.getLength() ) return false; for(int i = 0; i < getLength(); i++ ) if ( ! h.getString(i).equals(getString(i)) ) return false; return true; } public String toString() { StringBuffer sb = new StringBuffer(100); sb.append(""+getLength()); for(int i = 0; i < getLength(); i++) { sb.append(' '); sb.append(getString(i)); } return sb.toString(); } } // // Jacson - Text Filtering with Java. // Copyright (C) 2002 Frank S. Nestel (nestefan -at- users.sourceforge.net) // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
Strings.java |