- Timestamp:
- 07/16/13 23:31:35 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/core/ListChange.java
r100 r102 1 1 package com.framsticks.core; 2 3 import java.util.Arrays; 4 import java.util.Set; 5 import java.util.TreeSet; 6 7 import org.apache.commons.lang.StringUtils; 2 8 3 9 import com.framsticks.params.annotations.FramsClassAnnotation; … … 9 15 * @author Piotr Sniegowski 10 16 */ 11 @FramsClassAnnotation(order = {"type", "pos", "id" })17 @FramsClassAnnotation(order = {"type", "pos", "id", "hint"}) 12 18 public class ListChange { 13 19 20 public static enum Action { 21 Add, 22 Remove, 23 Modify 24 } 14 25 15 /** 16 * @param action 17 */ 18 public ListChange(Action action, Integer position, String identifier) { 26 27 public ListChange(Action action, Integer position, String identifier, Object... hints) { 19 28 this.action = action; 20 29 this.position = position; 21 30 this.identifier = identifier; 31 if (hints.length != 0) { 32 this.hints = new TreeSet<>(); 33 for (Object h : hints) { 34 this.hints.add(h.toString()); 35 } 36 } 22 37 } 23 38 … … 40 55 } 41 56 42 public static enum Action {43 Add,44 Remove,45 Modify46 // Add(0),47 // Remove(1),48 // Modify(2);49 57 50 // public final int value; 58 public boolean hasHint(String hint) { 59 if (hints == null) { 60 return false; 61 } 62 return hints.contains(hint); 63 } 51 64 52 // /**53 // * @param value54 // */55 // Action(int value) {56 // this.value = value;57 // }58 59 }60 65 61 66 public Action action = Action.Add; … … 64 69 @ParamAnnotation(id = "id") 65 70 public String identifier; 71 72 protected Set<String> hints; 73 74 @ParamAnnotation 75 public String getHints() { 76 return StringUtils.join(hints, ","); 77 } 78 79 @ParamAnnotation 80 public void setHints(String hints) { 81 if (!Strings.notEmpty(hints)) { 82 this.hints = null; 83 return; 84 } 85 this.hints = new TreeSet<>(); 86 this.hints.addAll(Arrays.asList(StringUtils.split(hints, ","))); 87 } 66 88 67 89 @ParamAnnotation … … 79 101 @Override 80 102 public String toString() { 81 return action + " " + identifier + " " + position; 103 StringBuilder b = new StringBuilder(); 104 b.append(action).append(" ").append(identifier).append(" ").append(position); 105 if (hints != null && !hints.isEmpty()) { 106 b.append(" ").append(getHints()); 107 } 108 return b.toString(); 82 109 } 83 110 … … 86 113 if (object instanceof ListChange) { 87 114 ListChange r = (ListChange) object; 88 return Misc.equals(action, r.action) && Misc.equals(position, r.position) && Misc.equals(identifier, r.identifier) ;115 return Misc.equals(action, r.action) && Misc.equals(position, r.position) && Misc.equals(identifier, r.identifier) && Misc.equals(hints, r.hints); 89 116 } 90 117 return false;
Note: See TracChangeset
for help on using the changeset viewer.