Files

50 lines
1.2 KiB
Java

package pickMaint;
public class LoomDSKey {
private final int DATE;
private final int SHIFT;
private final int LOOM;
private final int WEAVER;
private final String TYPE;
public LoomDSKey(int date, int shift, int loom, int weaver, String type){
this.DATE = date;
this.SHIFT = shift;
this.LOOM = loom;
this.WEAVER = weaver;
this.TYPE = type;
}
public String toString(){
return DATE + "-" + SHIFT + "-" + LOOM + "-" + WEAVER + "-" + TYPE;
}
/**
* All 5 components of the composite key must be equal
*/
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof LoomDSKey)) return false;
LoomDSKey key = (LoomDSKey) o;
return DATE == key.DATE &&
SHIFT == key.SHIFT &&
LOOM == key.LOOM &&
WEAVER == key.WEAVER &&
TYPE.equalsIgnoreCase(key.TYPE);
}
/**
* Obviously not a perfect hash; although I suspect collisions will be rare in our use case.
*/
@Override
public int hashCode() {
int hash = DATE * SHIFT;
hash = hash + LOOM;
hash = hash * (WEAVER / 2);
hash = hash + TYPE.hashCode();
return hash;
}
}