org.beetl.sql.clazz.kit.CaseInsensitiveOrderSet Maven / Gradle / Ivy
package org.beetl.sql.clazz.kit;
import java.util.Collection;
import java.util.LinkedHashSet;
public class CaseInsensitiveOrderSet extends LinkedHashSet {
private static final long serialVersionUID = 9178606903603606032L;
private final LinkedHashSet lowerSet = new LinkedHashSet();
String first = null;
//Override
@Override
public boolean contains(Object value) {
String t = (String)value;
return lowerSet.contains(t.toLowerCase());
}
//Override
@Override
public boolean add(String value) {
if(value==null){
throw new NullPointerException(value);
}
boolean b = lowerSet.add(value.toLowerCase());
if (b) {
super.add(value);
}
if(first==null){
first = value;
}
return b;
}
//Override
@Override
public boolean addAll(Collection c) {
Collection t = (Collection) c;
for (String s : t) {
lowerSet.add(s.toLowerCase());
}
return super.addAll(c);
}
public String getFirst() {
return first;
}
}