?? 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[].
* @author fsn
* @version 1.0
*/
public class Strings
{
/** Holder for the string array encapsulated */
private String[] strs;
/** Empty Strings */
public Strings(int n)
{
strs = new String[n];
}
/** Directly wrap given String-array */
public Strings(String[] strs)
{
this.strs = strs;
}
/** Modify a particular String in the array
* @param i the position in the array.
* @param h the value to set.
*/
public void setString(int i, String h)
{
strs[i] = h;
}
/**
* @return the number of Strings in the array.
*/
public int getLength()
{
return strs.length;
}
/**
* @return a particular String from the array.
*/
public String getString(int i)
{
return strs[i];
}
/**
* provide a working overall hashCode.
* @return the hashcode
*/
public int hashCode()
{
int h = 0x55555555 + getLength() * getLength();
for (int i = 0; i < getLength(); i++)
h ^= 60 * h + strs[i].hashCode();
return h;
}
/**
* provide a working overall equals()
* @return true if object equal to me.
*/
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;
}
/**
* @return prettyprinted String array.
*/
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
//
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -