public CollectionSettingCandidate getCandidate() { return new CollectionSettingCandidate(name, value); }
@Override public boolean equals(Object o) { if (o == null) return false; if (this == o) return true; if (getClass() != o.getClass()) return false; return isEquivalent((CollectionSettingCandidate) o); }
@Override public int hashCode() { return super.hashCode() + ListUtil.size(getInternalAgents()) // using size since order may vary ; } }
/** * Add a global CollectionSettingGroup, which will use the global prefix */ public void addGlobalCollectionSettings(CollectionSettingGroup group) { String key = GLOBAL_SCOPE_PREFIX + "." + COLLECTION_SETTING_PREFIX + "." + group.getName().getKey(); configuration.put(key, group.getCandidate().getValue()); }
@Override protected boolean isEquivalent (CollectionSettingCandidate o) { if (!super.isEquivalent(o)) { return false; } // we know we can cast since equals calls us CollectionSettingGroup other = (CollectionSettingGroup) o; return ListUtil.compareCollections(getInternalAgents(), other.getInternalAgents()); }
/** * Rig the election by forcing a setting into the global group */ public void forceGlobalSetting(CollectionSettingName name, Serializable value) { forcedGlobal.add(new CollectionSettingCandidate(name, value)); }
/** * Tallies the results of the election, sub-divides the CollectionSettings into * those that are global and those that are specific to agents. */ public void tally() { int votesRequiredForGlobal=uniqueAgents.size(); ServerResource[] agents=(votesRequiredForGlobal <= 0) ? EMPTY_SERVERS : ArrayUtil.toArray(uniqueAgents, ServerResource.class); for (CollectionSettingCandidate forced : forcedGlobal) { elect.put(forced, new CollectionSettingGroup(forced.getName(), forced.getValue(), agents)); } List<CollectionSettingCandidate> all=new LinkedList<CollectionSettingCandidate>(elect.keySet()); List<CollectionSettingGroup> global=new LinkedList<CollectionSettingGroup>(); List<CollectionSettingGroup> local=new LinkedList<CollectionSettingGroup>(); for (CollectionSettingCandidate candidate : all) { CollectionSettingGroup votes = elect.get(candidate); if (votes.getVotes() == votesRequiredForGlobal) { global.add(votes); } else { local.add(votes); } } globalSettings = global; localSettings = local; }