1 | package com.framsticks.core; |
---|
2 | |
---|
3 | import com.framsticks.params.FramsClass; |
---|
4 | import com.framsticks.params.Param; |
---|
5 | import com.framsticks.params.types.DecimalParam; |
---|
6 | import com.framsticks.params.types.EnumParam; |
---|
7 | import com.framsticks.params.types.StringParam; |
---|
8 | import com.framsticks.util.lang.Strings; |
---|
9 | |
---|
10 | import java.util.Arrays; |
---|
11 | |
---|
12 | /** |
---|
13 | * @author Piotr Sniegowski |
---|
14 | */ |
---|
15 | public class ListChange { |
---|
16 | |
---|
17 | public Action getAction() { |
---|
18 | return action; |
---|
19 | } |
---|
20 | |
---|
21 | public Integer getPosition() { |
---|
22 | return position; |
---|
23 | } |
---|
24 | |
---|
25 | public String getIdentifier() { |
---|
26 | return identifier; |
---|
27 | } |
---|
28 | |
---|
29 | public static enum Action { |
---|
30 | Add, |
---|
31 | Remove, |
---|
32 | Modify |
---|
33 | } |
---|
34 | |
---|
35 | private Action action; |
---|
36 | private Integer position; |
---|
37 | private String identifier; |
---|
38 | |
---|
39 | public Integer getType() { return action.ordinal(); } |
---|
40 | public void setType(Integer type) { action = Action.values()[type]; } |
---|
41 | |
---|
42 | public Integer getPos() { return position; } |
---|
43 | public void setPos(Integer pos) { position = pos; } |
---|
44 | |
---|
45 | public String getId() { return identifier; } |
---|
46 | public void setId(String id) { identifier = id; } |
---|
47 | |
---|
48 | public String getBestIdentifier() { |
---|
49 | if (Strings.notEmpty(identifier)) { |
---|
50 | return identifier; |
---|
51 | } |
---|
52 | return position.toString(); |
---|
53 | } |
---|
54 | |
---|
55 | public static FramsClass getFramsClass() { |
---|
56 | return new FramsClass("ListChange", "ListChange", null) |
---|
57 | .append(Param.build().id("type").name("type").type(new EnumParam(Arrays.asList("Add", "Remove", "Modify")))) |
---|
58 | .append(Param.build().id("id").name("identifier").type(StringParam.class)) |
---|
59 | .append(Param.build().id("pos").name("position").type(DecimalParam.class)); |
---|
60 | } |
---|
61 | |
---|
62 | @Override |
---|
63 | public String toString() { |
---|
64 | return action + " " + identifier + " " + position; |
---|
65 | } |
---|
66 | } |
---|