preparing to manage weights in poll
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -51,4 +51,5 @@ public class Path {
|
||||
public static final String USER = "user";
|
||||
public static final String USES = "uses";
|
||||
|
||||
public static final String WEIGHT = "weight";
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ public class Text {
|
||||
public static final String UNIT = "unit";
|
||||
public static final String USER_WITH_ID = "user ({id})";
|
||||
|
||||
public static final String WEIGHT = "weight";
|
||||
public static final String WIKI = "wiki";
|
||||
public static final String WIKI_PAGE = "wiki page";
|
||||
public static final String WIKI_PAGES = "wiki pages";
|
||||
|
||||
@@ -15,12 +15,12 @@ import static java.text.MessageFormat.format;
|
||||
|
||||
public class Poll implements Mappable {
|
||||
public static class Option implements Mappable{
|
||||
|
||||
private int id;
|
||||
Integer status;
|
||||
private String description;
|
||||
private String name;
|
||||
private final Set<String> dirtyFields = new HashSet<>();
|
||||
|
||||
public Option(int id, String name, String description, Integer status) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
@@ -102,16 +102,16 @@ public class Poll implements Mappable {
|
||||
public String toString() {
|
||||
return format("Option \"{0}\"",name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private Owner owner;
|
||||
|
||||
private String id, name, description;
|
||||
private boolean isPrivate;
|
||||
private List<Option> options;
|
||||
private Map<Integer,String> weights;
|
||||
private Map<UmbrellaUser,Long> shares;
|
||||
private Set<String> dirtyFields = new HashSet<>();
|
||||
|
||||
public Poll(String id, Owner owner, String name, String description, boolean isPrivate, List<Option> options, Map<Integer,String> weights, Map<UmbrellaUser,Long> shares){
|
||||
this.id = id;
|
||||
this.owner = owner;
|
||||
@@ -141,6 +141,13 @@ public class Poll implements Mappable {
|
||||
return !dirtyFields.isEmpty();
|
||||
}
|
||||
|
||||
public boolean isDirty(String ... fields){
|
||||
for (var field : fields){
|
||||
if (dirtyFields.contains(field)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isPrivate(){
|
||||
return isPrivate;
|
||||
}
|
||||
@@ -180,10 +187,17 @@ public class Poll implements Mappable {
|
||||
public List<Option> options(){
|
||||
return options;
|
||||
}
|
||||
|
||||
public Owner owner(){
|
||||
return owner;
|
||||
}
|
||||
|
||||
public Poll setWeight(Integer weight, String description) {
|
||||
weights.put(weight,description);
|
||||
dirtyFields.add(WEIGHTS);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Map<UmbrellaUser, Long> shares(){
|
||||
return shares;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user