0
こんにちはを参照してください等しいであれば、私がチェックし、これと同じリスト:のJavaなぜ2私は、私は2つのオブジェクトのリストを持っている偽
public class TimeTableForBus {
String bsName;
int bsType;
Time ttTime;
int lon;
int lat;
int ttID;
int bus_stop_status;
}
をそして、私はちょうどこのような2つのリスト生成:
private static ArrayList getList(QueryRunner qRunner, Connection conn){
try {
beans = (List) qRunner.query(conn, "call mpklocal.LCD_GetDispInfoAllTimeTable()",
new BeanListHandler(TimeTableForBus.class));
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (int i = 0; i < beans.size(); i++) {
TimeTableForBus bean = (TimeTableForBus) beans.get(i);
// bean.print();
}
ArrayList<TimeTableForBus> bus = new ArrayList<>();
for (int i = 0; i < beans.size(); i++) {
bus.add((TimeTableForBus) beans.get(i));
}
return bus;
}
私はそれが等しいかどうかをチェックする私はこれを行うときに偽を見る、私は偽を見る。リストは、この同じオブジェクトを持っている:
public static boolean equalLists(List<TimeTableForBus> one, List<TimeTableForBus> two){
if (one == null && two == null){
return true;
}
if((one == null && two != null)
|| one != null && two == null
|| one.size() != two.size()){
return false;
}
//to avoid messing the order of the lists we will use a copy
//as noted in comments by A. R. S.
// one = new ArrayList<String>(one);
// two = new ArrayList<String>(two);
//
// Collections.sort(one);
// Collections.sort(two);
return one.equals(two);
}
public static boolean listsAreEquivelent(List<? extends Object> a, List<? extends Object> b) {
if(a==null) {
if(b==null) {
//Here 2 null lists are equivelent. You may want to change this.
return true;
} else {
return false;
}
}
if(b==null) {
return false;
}
Map<Object, Integer> tempMap = new HashMap<>();
for(Object element : a) {
Integer currentCount = tempMap.get(element);
if(currentCount == null) {
tempMap.put(element, 1);
} else {
tempMap.put(element, currentCount+1);
}
}
for(Object element : b) {
Integer currentCount = tempMap.get(element);
if(currentCount == null) {
return false;
} else {
tempMap.put(element, currentCount-1);
}
}
for(Integer count : tempMap.values()) {
if(count != 0) {
return false;
}
}
return true;
}
そして、私はこの結果に
は 'TimeTableForBus'オーバーライド'い等しい? – Eran
@Eranいいえ、それは等価をオーバーライドする必要がありますか?どのように見える必要がありますか? –
@エランと私はこれをどのように使うことができますか? –