Итак, у меня есть интерфейс.Удалить дублируемую запись из массива настраиваемых объектов
public interface ARecord {
public BigInteger getAutoID();
public String getACompId();
}
и
public class APPPRecord extends AbstratAPRecord implements ARecord{
private BigInteger autoID;
private String ACompId = null;
//setter and getter}
В службе,
List<APPPRecord> PFRecord = null;
while(scroll.next()){
APPPRecord item = (APPPRecord) scroll.get(0);
List<ARecord> recs = new ArrayList<ARecord>();
unique(APPPRecord);
recs.addAll(APPPRecord);
Мой РИК имеют повторяющиеся записи, которые я пытаюсь удалить, и есть одна уникальная записи для каждого дублированного recod. До сих пор я пробовал Set и hash set, но безрезультатно. Любая помощь приветствуется.
EDIT: Я пробовал хеш-код и равный.
@Override
public boolean equals(Object obj) {
if(obj instanceof APPPRecord)
{
APPPRecord temp = (APPPRecord) obj;
if(this.getACompId() == temp.getACompId())
return true;
}
return false;
}
@Override
public int hashCode() {
return (this.getACompId().hashCode());
}
в обслуживании:
private List<APPPRecord> unique(List<APPPRecord> list) {
List<APPPRecord> uniqueList = new ArrayList<APPPRecord>();
Set<APPPRecord> uniqueSet = new HashSet<APPPRecord>();
for (APPPRecord obj : list) {
if (uniqueSet.add(obj)) {
uniqueList.add(obj);
}
}
return uniqueList;
}
Комплект должен работать. А что нет? Вы переопределили 'equals()' и 'hashcode()' в своем классе? –
обновил мой вопрос. – Jay