📄 idtable.java
字号:
package toocom.ocgl;
import java.util.*;
import java.lang.*;
/**
* This class represent a table of id couples (int/int).
*
* @author Fr閐閞ic F黵st
*/
public class IdTable extends Hashtable{
public IdTable(){
super();
}
/** Maps the specified key to the specified value in this table. The value can be
* retrieved by calling the get method with a key that is equal to the original key.
* Returns the previous value of the specified key in this table, or -1 if it did not have one.
*/
public int put(int idKey,int idValue){
Integer result = (Integer) this.put(new Integer(idKey),new Integer(idValue));
if(result == null) return -1;
else return result.intValue();
}
/** Returns the value to which the specified key is mapped in this table, -1 if the key is
* not mapped to any value in this table. */
public int get(int idKey){
Integer result = (Integer) this.get(new Integer(idKey));
if(result == null) return -1;
else return result.intValue();
}
/** Returns from the keys of the table the id which is the key of the given value. The first
* encountered key is returned so the values must all be different to get the right key.
* Returns -1 if the value is not encountered in the table. */
public int getIdKey(int idValue){
for(Enumeration en = this.keys();en.hasMoreElements();){
Integer keyId = (Integer) en.nextElement();
if(((Integer) this.get(keyId)).equals(new Integer(idValue))) return keyId.intValue();
}
return -1;
}
/** Returns a clone of the table without the couple with the given key. */
public IdTable removeElement(int key){
IdTable result = new IdTable();
for(Enumeration en = this.keys();en.hasMoreElements();){
Integer k = (Integer) en.nextElement();
if(k.intValue() != key) result.put(k,this.get(k));
}
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -