@Override public List<PlugwiseBindingConfigElement> getIntervalList() { List<PlugwiseBindingConfigElement> result = new ArrayList<PlugwiseBindingConfigElement>(); Collection<String> items = getItemNames(); Iterator<String> itemIterator = items.iterator(); while (itemIterator.hasNext()) { String anItem = itemIterator.next(); PlugwiseBindingConfig pbConfig = (PlugwiseBindingConfig) bindingConfigs.get(anItem); for (Command command : pbConfig.keySet()) { boolean found = false; PlugwiseBindingConfigElement element = pbConfig.get(command); // check if we already have a reference to this {ID,command} Iterator<PlugwiseBindingConfigElement> elementIterator = result.iterator(); while (elementIterator.hasNext()) { PlugwiseBindingConfigElement resultElement = elementIterator.next(); if (resultElement.getId().equals(element.getId()) && resultElement .getCommandType() .getJobClass() .equals(element.getCommandType().getJobClass())) { // bingo - now check if the interval is smaller found = true; if (resultElement.getInterval() > element.getInterval()) { result.remove(resultElement); result.add(element); break; } } } if (!found) { result.add(element); } } } return result; }
@Override public String getPlugwiseID(String itemName, Command someCommand) { if (itemName != null && someCommand != null) { PlugwiseBindingConfig aConfig = (PlugwiseBindingConfig) bindingConfigs.get(itemName); if (aConfig != null) { PlugwiseBindingConfigElement element = aConfig.get(someCommand); if (element != null) { return element.getId(); } } } return null; }
@Override public List<String> getPlugwiseID(String itemName) { List<String> ids = new ArrayList<String>(); for (String anItem : bindingConfigs.keySet()) { PlugwiseBindingConfig aConfig = (PlugwiseBindingConfig) bindingConfigs.get(anItem); for (Command aCommand : aConfig.keySet()) { PlugwiseBindingConfigElement element = aConfig.get(aCommand); if (element != null) { ids.add(element.getId()); } } } return ids; }
@Override public Set<String> getItemNames(String PlugwiseID, PlugwiseCommandType type) { Set<String> result = new HashSet<String>(); Collection<String> items = getItemNames(); Iterator<String> itemIterator = items.iterator(); while (itemIterator.hasNext()) { String anItem = itemIterator.next(); PlugwiseBindingConfig pbConfig = (PlugwiseBindingConfig) bindingConfigs.get(anItem); for (Command command : pbConfig.keySet()) { PlugwiseBindingConfigElement element = pbConfig.get(command); if (element.getCommandType() == type && element.getId().equals(PlugwiseID)) { if (!result.contains(anItem)) { result.add(anItem); } } } } return result; }