home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1995 November
/
PCWK1195.iso
/
inne
/
win95
/
sieciowe
/
hotja32.lzh
/
hotjava
/
classsrc
/
java
/
tools
/
mem4
/
dict.java
next >
Wrap
Text File
|
1995-08-11
|
2KB
|
81 lines
/*
* @(#)Dict.java 1.1 95/05/11 Mary Campione
*
* Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for NON-COMMERCIAL purposes and without
* fee is hereby granted provided that this copyright notice
* appears in all copies. Please refer to the file "copyright.html"
* for further important copyright and licensing information.
*
* SUN 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. SUN SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
*/
package java.tools.mem4;
class Dict {
static final int NOTFOUND = -1;
static final int MAXENTRIES = 50;
String keyArray[];
String valueArray[];
int numEntries;
Dict() {
keyArray = new String[MAXENTRIES];
valueArray = new String[MAXENTRIES];
numEntries = 0;
}
boolean addPair(String key, String value) {
int loc;
if ((loc = locationOf(key)) == NOTFOUND)
if (numEntries + 1 < MAXENTRIES) {
keyArray[numEntries] = key;
valueArray[numEntries] = value;
numEntries++;
return true;
} else {
return false;
}
else {
return changeValue(loc, value);
}
}
String valueOf(String key) {
int i;
for (i = 0; i < numEntries; i++) {
if (key.equals(keyArray[i]))
return valueArray[i];
}
return key;
}
int locationOf(String key) {
int i;
for (i = 0; i < numEntries; i++) {
if (key.equals(keyArray[i]))
return i;
}
return NOTFOUND;
}
boolean changeValue(int loc, String newvalue) {
if (loc >= 0 && loc < numEntries) {
valueArray[loc] = newvalue;
return true;
} else {
return false;
}
}
}