Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.util.*;
- public class Row {
- private String styleName = "editable-grid-row";
- private Map<String,String> rowData;
- private int index;
- public interface RowSelectChangeListener{
- void onSelectChange(Row row);
- }
- public Map<String, String> getRowData() {
- return rowData;
- }
- public void setStyleName(String styleName) {
- this.styleName = styleName;
- }
- RowSelectChangeListener selectListener;
- public void setSelectListener(RowSelectChangeListener selectListener) {
- this.selectListener = selectListener;
- }
- public int getIndex() {
- return index;
- }
- public void setIndex(int index) {
- this.index = index;
- }
- @Override
- public String toString() {
- return "Row [" + (rowData != null ? "rowData=" + rowData : "") + "]";
- }
- private static String SELECTED = "eg-selected-row";
- public String getValue(String key){
- return rowData.get(key);
- }
- public String getId(){
- return rowData.get("DFOBJ");
- }
- public void putValue(String k , String v){
- rowData.put(k , v);
- }
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- Row row = (Row) o;
- Map<String, String> OrowData = row.rowData;
- //проверим списки ключей
- Set<String> copy = new HashSet<>(OrowData.keySet());
- Set<String> original = new HashSet<>(rowData.keySet());
- copy.remove(null);
- original.remove(null);
- if (!copy.equals(original))
- return false;
- //если все ключи совпадают проверим каждое занчение по ключу
- for (String key : original) {
- if (!rowData.get(key).equals(OrowData.get(key)))
- return false;
- }
- return true;
- }
- @Override
- public int hashCode() {
- int h = 0;
- Iterator<Map.Entry<String, String>> i = rowData.entrySet().iterator();
- while (i.hasNext()) {
- Map.Entry<String, String> next = i.next();
- if(next.getKey() != null) {
- h += next.hashCode();
- }
- }
- return h;
- }
- public static void main(String[] args) {
- Row originRow = new Row();
- originRow.rowData = originMap();
- Row copyRow = new Row();
- copyRow.rowData = copyMap();
- System.out.println("origin hashCode = " + originRow.hashCode());
- System.out.println("copy hashCode = " + copyRow.hashCode());
- System.out.println(originRow.equals(copyRow));
- }
- private static Map<String, String> originMap(){
- HashMap<String, String> map = new HashMap<>();
- map.put("DFOBJ_ACC","105708976");
- map.put("DFNUMBER_ACC","229000032841");
- map.put("DFALIAS","Северо-Запад");
- map.put("FIRST_GROUP_DFOBJ","3180360969");
- map.put("FIRST_GROUP_NAME","Test 2 lines");
- map.put("SECOND_GROUP_DFOBJ","3180360970");
- map.put("SECOND_GROUP_NAME","Алиас");
- map.put("DFGROUP_NAME","");
- map.put("DFOBJ_CONTR","105708991");
- map.put("DFNUMBER_CONTR","№, от 09.07.2013");
- map.put("DFDATE_BEGIN","09.07.13");
- map.put("DFSUB_NUM","503");
- map.put("DFINVOICE","");
- map.put("DFBALANCE_OUT","0");
- map.put(null,"T");
- return map;
- }
- private static Map<String, String> copyMap(){
- HashMap<String, String> map = new HashMap<>();
- map.put("DFOBJ_ACC","105708976");
- map.put("DFNUMBER_ACC","229000032841");
- map.put("DFALIAS","Северо-Запад");
- map.put("FIRST_GROUP_DFOBJ","3180360969");
- map.put("FIRST_GROUP_NAME","Test 2 lines");
- map.put("SECOND_GROUP_DFOBJ","3180360970");
- map.put("SECOND_GROUP_NAME","Алиас");
- map.put("DFGROUP_NAME","");
- map.put("DFOBJ_CONTR","105708991");
- map.put("DFNUMBER_CONTR","№, от 09.07.2013");
- map.put("DFDATE_BEGIN","09.07.13");
- map.put("DFSUB_NUM","503");
- map.put("DFINVOICE","");
- map.put("DFBALANCE_OUT","0");
- return map;
- }
- }
Add Comment
Please, Sign In to add comment