source:
java/main/src/main/java/com/framsticks/core/ListChange.java
@
102
Last change on this file since 102 was 102, checked in by , 11 years ago | |
---|---|
File size: 2.5 KB |
Rev | Line | |
---|---|---|
[77] | 1 | package com.framsticks.core; |
2 | ||
[102] | 3 | import java.util.Arrays; |
4 | import java.util.Set; | |
5 | import java.util.TreeSet; | |
6 | ||
7 | import org.apache.commons.lang.StringUtils; | |
8 | ||
[87] | 9 | import com.framsticks.params.annotations.FramsClassAnnotation; |
10 | import com.framsticks.params.annotations.ParamAnnotation; | |
[100] | 11 | import com.framsticks.util.Misc; |
[84] | 12 | import com.framsticks.util.lang.Strings; |
[77] | 13 | |
14 | /** | |
15 | * @author Piotr Sniegowski | |
16 | */ | |
[102] | 17 | @FramsClassAnnotation(order = {"type", "pos", "id", "hint"}) |
[77] | 18 | public class ListChange { |
19 | ||
[102] | 20 | public static enum Action { |
21 | Add, | |
22 | Remove, | |
23 | Modify | |
24 | } | |
[100] | 25 | |
[102] | 26 | |
27 | public ListChange(Action action, Integer position, String identifier, Object... hints) { | |
[100] | 28 | this.action = action; |
29 | this.position = position; | |
30 | this.identifier = identifier; | |
[102] | 31 | if (hints.length != 0) { |
32 | this.hints = new TreeSet<>(); | |
33 | for (Object h : hints) { | |
34 | this.hints.add(h.toString()); | |
35 | } | |
36 | } | |
[100] | 37 | } |
38 | ||
39 | /** | |
40 | * | |
41 | */ | |
42 | public ListChange() { | |
43 | } | |
44 | ||
[84] | 45 | public Action getAction() { |
46 | return action; | |
47 | } | |
[77] | 48 | |
[84] | 49 | public Integer getPosition() { |
50 | return position; | |
51 | } | |
[77] | 52 | |
[84] | 53 | public String getIdentifier() { |
54 | return identifier; | |
55 | } | |
[77] | 56 | |
[87] | 57 | |
[102] | 58 | public boolean hasHint(String hint) { |
59 | if (hints == null) { | |
60 | return false; | |
61 | } | |
62 | return hints.contains(hint); | |
63 | } | |
[87] | 64 | |
65 | ||
66 | public Action action = Action.Add; | |
[100] | 67 | @ParamAnnotation(id = "pos", def = "-1") |
[87] | 68 | public Integer position; |
69 | @ParamAnnotation(id = "id") | |
70 | public String identifier; | |
[77] | 71 | |
[102] | 72 | protected Set<String> hints; |
73 | ||
[87] | 74 | @ParamAnnotation |
[102] | 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 | } | |
88 | ||
89 | @ParamAnnotation | |
[84] | 90 | public Integer getType() { return action.ordinal(); } |
[87] | 91 | @ParamAnnotation |
[84] | 92 | public void setType(Integer type) { action = Action.values()[type]; } |
[77] | 93 | |
[84] | 94 | public String getBestIdentifier() { |
95 | if (Strings.notEmpty(identifier)) { | |
96 | return identifier; | |
97 | } | |
98 | return position.toString(); | |
99 | } | |
[77] | 100 | |
[84] | 101 | @Override |
102 | public String toString() { | |
[102] | 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(); | |
[84] | 109 | } |
[100] | 110 | |
111 | @Override | |
112 | public boolean equals(Object object) { | |
113 | if (object instanceof ListChange) { | |
114 | ListChange r = (ListChange) object; | |
[102] | 115 | return Misc.equals(action, r.action) && Misc.equals(position, r.position) && Misc.equals(identifier, r.identifier) && Misc.equals(hints, r.hints); |
[100] | 116 | } |
117 | return false; | |
118 | } | |
119 | ||
[77] | 120 | } |
Note: See TracBrowser
for help on using the repository browser.