private List<String> values = new ArrayList<String>();
public WhitespaceEqualsTest() {
values.add("I ");
values.add("I");
values.add(". ");
values.add(".");
values.add("1");
values.add("1 ");
System.out.println(refine(values));
}
private List<String> refine(List<String> input){
ArrayList<String> outerLoopValues = (ArrayList<String>) input;
ArrayList<String> innerLoopValues = (ArrayList<String>) input;
ArrayList<String> results = new ArrayList<String>();
for(String string1 : outerLoopValues){
for(String string2 : innerLoopValues){
if(string1.contains(string2) == false){
results.add(string1);
}
}
}
Set<String> temp = new HashSet<String>();
temp.addAll(results);
results.clear();
results.addAll(temp);
return results;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((values == null) ? 0 : values.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
WhitespaceEqualsTest other = (WhitespaceEqualsTest) obj;
if (values == null) {
if (other.values != null)
return false;
} else if (!values.equals(other.values))
return false;
return true;
}
I've overriden the hashCode()
and equals()
, so I'm not really sure what's wrong. They are generated using Eclipse (Source -> Generate hashCode() and equals()). Why isn't it detecting that the same character without a space is contained within a character with a space? The output is:
[1, . , I , I, ., 1 ]