Added data objects needed for polls
This commit is contained in:
parent
0c27b1ccd8
commit
e31678a275
|
|
@ -0,0 +1,49 @@
|
|||
package com.alttd.commandManager.commands.PollCommand;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ButtonData {
|
||||
private final UUID buttonId;
|
||||
private final long pollId;
|
||||
List<Long> votes;
|
||||
|
||||
public ButtonData(UUID buttonId, long pollId) {
|
||||
this.buttonId = buttonId;
|
||||
this.pollId = pollId;
|
||||
votes = new ArrayList<>();
|
||||
}
|
||||
|
||||
public ButtonData(UUID buttonId, long pollId, List<Long> votes) {
|
||||
this.buttonId = buttonId;
|
||||
this.pollId = pollId;
|
||||
this.votes = votes;
|
||||
}
|
||||
|
||||
public UUID getButtonId() {
|
||||
return buttonId;
|
||||
}
|
||||
|
||||
public long getPollId() {
|
||||
return pollId;
|
||||
}
|
||||
|
||||
public int totalVotes() {
|
||||
return votes.size();
|
||||
}
|
||||
|
||||
public boolean addVote(long id) {
|
||||
if (votes.contains(id))
|
||||
return false;
|
||||
votes.add(id);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean removeVote(long id) {
|
||||
if (!votes.contains(id))
|
||||
return false;
|
||||
votes.remove(id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package com.alttd.commandManager.commands.PollCommand;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PollData {
|
||||
private boolean enabled;
|
||||
private final int pollId;
|
||||
private final HashMap<UUID, ButtonData> buttons;
|
||||
|
||||
public PollData(int pollId) {
|
||||
enabled = false;
|
||||
this.pollId = pollId;
|
||||
this.buttons = new HashMap<>();
|
||||
}
|
||||
|
||||
public PollData(boolean enabled, int pollId, HashMap<UUID, ButtonData> buttons) {
|
||||
this.enabled = enabled;
|
||||
this.pollId = pollId;
|
||||
this.buttons = buttons;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public int getPollId() {
|
||||
return pollId;
|
||||
}
|
||||
|
||||
public ButtonData getButtonData(UUID uuid) {
|
||||
return buttons.getOrDefault(uuid, null);
|
||||
}
|
||||
|
||||
public boolean addButtonData(UUID uuid, ButtonData buttonData) {
|
||||
if (buttons.containsKey(uuid))
|
||||
return false;
|
||||
buttons.put(uuid, buttonData);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package com.alttd.commandManager.commands.PollCommand;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Polls {
|
||||
|
||||
private static Polls instance = null;
|
||||
private HashMap<Long, PollData> pollDataMap;
|
||||
|
||||
private Polls() {
|
||||
pollDataMap = new HashMap<>();
|
||||
//TODO load poll data
|
||||
}
|
||||
|
||||
public static Polls getInstance() {
|
||||
if (instance == null)
|
||||
instance = new Polls();
|
||||
return instance;
|
||||
}
|
||||
|
||||
public boolean addPoll(long pollId, PollData pollData) {
|
||||
if (pollDataMap.containsKey(pollId))
|
||||
return (false);
|
||||
pollDataMap.put(pollId, pollData);
|
||||
return true;
|
||||
}
|
||||
|
||||
public PollData getPoll(long pollId) {
|
||||
return pollDataMap.getOrDefault(pollId, null);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user