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