vampirit

Row

Nov 8th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.35 KB | None | 0 0
  1. package test;
  2.  
  3. import java.util.*;
  4.  
  5. public class Row {
  6.     private String styleName = "editable-grid-row";
  7.     private Map<String,String> rowData;
  8.     private int index;
  9.  
  10.     public interface RowSelectChangeListener{
  11.         void onSelectChange(Row row);
  12.     }
  13.  
  14.     public Map<String, String> getRowData() {
  15.         return rowData;
  16.     }
  17.  
  18.     public void setStyleName(String styleName) {
  19.         this.styleName = styleName;
  20.     }
  21.  
  22.     RowSelectChangeListener selectListener;
  23.  
  24.     public void setSelectListener(RowSelectChangeListener selectListener) {
  25.         this.selectListener = selectListener;
  26.     }
  27.  
  28.     public int getIndex() {
  29.         return index;
  30.     }
  31.  
  32.     public void setIndex(int index) {
  33.         this.index = index;
  34.     }
  35.  
  36.  
  37.     @Override
  38.     public String toString() {
  39.         return "Row [" + (rowData != null ? "rowData=" + rowData : "") + "]";
  40.     }
  41.  
  42.     private static String SELECTED = "eg-selected-row";
  43.  
  44.  
  45.     public String getValue(String key){
  46.         return rowData.get(key);
  47.     }
  48.  
  49.     public String getId(){
  50.         return rowData.get("DFOBJ");
  51.     }
  52.  
  53.     public void putValue(String k , String v){
  54.         rowData.put(k , v);
  55.     }
  56.  
  57.     @Override
  58.     public boolean equals(Object o) {
  59.         if (this == o) return true;
  60.         if (o == null || getClass() != o.getClass()) return false;
  61.  
  62.         Row row = (Row) o;
  63.  
  64.  
  65.         Map<String, String> OrowData = row.rowData;
  66.  
  67.         //проверим списки ключей
  68.         Set<String> copy = new HashSet<>(OrowData.keySet());
  69.         Set<String> original = new HashSet<>(rowData.keySet());
  70.         copy.remove(null);
  71.         original.remove(null);
  72.  
  73.         if (!copy.equals(original))
  74.             return false;
  75.  
  76.         //если все ключи совпадают проверим каждое занчение по ключу
  77.  
  78.         for (String key : original) {
  79.             if (!rowData.get(key).equals(OrowData.get(key)))
  80.                 return false;
  81.         }
  82.  
  83.         return true;
  84.     }
  85.  
  86.     @Override
  87.     public int hashCode() {
  88.         int h = 0;
  89.         Iterator<Map.Entry<String, String>> i = rowData.entrySet().iterator();
  90.         while (i.hasNext()) {
  91.             Map.Entry<String, String> next = i.next();
  92.             if(next.getKey() != null) {
  93.                 h += next.hashCode();
  94.             }
  95.         }
  96.         return h;
  97.     }
  98.  
  99.     public static void main(String[] args) {
  100.  
  101.         Row originRow = new Row();
  102.         originRow.rowData = originMap();
  103.         Row copyRow = new Row();
  104.         copyRow.rowData = copyMap();
  105.  
  106.         System.out.println("origin hashCode = " + originRow.hashCode());
  107.         System.out.println("copy hashCode = " + copyRow.hashCode());
  108.         System.out.println(originRow.equals(copyRow));
  109.  
  110.     }
  111.  
  112.     private static Map<String, String> originMap(){
  113.         HashMap<String, String> map = new HashMap<>();
  114.         map.put("DFOBJ_ACC","105708976");
  115.         map.put("DFNUMBER_ACC","229000032841");
  116.         map.put("DFALIAS","Северо-Запад");
  117.         map.put("FIRST_GROUP_DFOBJ","3180360969");
  118.         map.put("FIRST_GROUP_NAME","Test 2 lines");
  119.         map.put("SECOND_GROUP_DFOBJ","3180360970");
  120.         map.put("SECOND_GROUP_NAME","Алиас");
  121.         map.put("DFGROUP_NAME","");
  122.         map.put("DFOBJ_CONTR","105708991");
  123.         map.put("DFNUMBER_CONTR","№, от 09.07.2013");
  124.         map.put("DFDATE_BEGIN","09.07.13");
  125.         map.put("DFSUB_NUM","503");
  126.         map.put("DFINVOICE","");
  127.         map.put("DFBALANCE_OUT","0");
  128.         map.put(null,"T");
  129.  
  130.         return map;
  131.     }
  132.  
  133.     private static Map<String, String> copyMap(){
  134.         HashMap<String, String> map = new HashMap<>();
  135.         map.put("DFOBJ_ACC","105708976");
  136.         map.put("DFNUMBER_ACC","229000032841");
  137.         map.put("DFALIAS","Северо-Запад");
  138.         map.put("FIRST_GROUP_DFOBJ","3180360969");
  139.         map.put("FIRST_GROUP_NAME","Test 2 lines");
  140.         map.put("SECOND_GROUP_DFOBJ","3180360970");
  141.         map.put("SECOND_GROUP_NAME","Алиас");
  142.         map.put("DFGROUP_NAME","");
  143.         map.put("DFOBJ_CONTR","105708991");
  144.         map.put("DFNUMBER_CONTR","№, от 09.07.2013");
  145.         map.put("DFDATE_BEGIN","09.07.13");
  146.         map.put("DFSUB_NUM","503");
  147.         map.put("DFINVOICE","");
  148.         map.put("DFBALANCE_OUT","0");
  149.  
  150.         return map;
  151.     }
  152. }
Add Comment
Please, Sign In to add comment