public static ScopeType getScopeType(final String scope) { ScopeType result = null; if (scope != null) { for (ScopeType type : ScopeType.values()) { if (type.getScope().equalsIgnoreCase(scope.trim())) { result = type; } } } return result; }
/** Sets value for given scope and given key. */ public void putScopedValue(ScopeType scope, String key, Serializable value) { if (scope == null || key == null) { log.error(String.format("Cannot set scope value using scopeType=%s and key=%s", scope, key)); } else { put(scope.getScopedKey(key), value); } }
/** Gets value for given scope and given key. */ public Serializable getScopedValue(ScopeType scope, String key) { Serializable res = null; if (scope != null && key != null) { res = get(scope.getScopedKey(key)); } return res; }
@Override public void read(Element element, Project project) { Element scopeTypeXML = element.getChild(SCOPE_TYPE); myScopeType = ScopeType.valueOf(scopeTypeXML.getAttributeValue(SCOPE_TYPE)); myModule = scopeTypeXML.getAttributeValue(MODULE); myModel = scopeTypeXML.getAttributeValue(MODEL); }
@Override public void write(Element element, Project project) { Element scopeTypeXML = new Element(SCOPE_TYPE); scopeTypeXML.setAttribute(SCOPE_TYPE, myScopeType.name()); scopeTypeXML.setAttribute(MODULE, myModule == null ? "" : myModule); scopeTypeXML.setAttribute(MODEL, myModel == null ? "" : myModel); element.addContent(scopeTypeXML); }
public int compareTo(HealthStateScope o) { int comparison; comparison = type.compareTo(o.type); if (comparison != 0) { return comparison; } comparison = scope.compareTo(o.scope); if (comparison != 0) { return comparison; } return 0; }
/** Creates a Map with entries from specified scope. */ public Map<String, Serializable> getScopeValues(ScopeType scopeType) { Map<String, Serializable> defMap = new HashMap<String, Serializable>(); final String defaultScopePrefix = scopeType.getScopePrefix(); final int prefixLen = defaultScopePrefix.length(); for (Map.Entry<String, Serializable> entry : entrySet()) { String key = entry.getKey(); if (key.startsWith(defaultScopePrefix)) { defMap.put(key.substring(prefixLen), entry.getValue()); } } return defMap; }
/** Removes all mappings for given scope. */ public void clearScope(ScopeType scopeType) { if (scopeType == null) { log.error("Cannot clear map, specified scope is null"); } else { String prefix = scopeType.getScopePrefix(); List<String> toRemove = new ArrayList<String>(); for (Map.Entry<String, Serializable> entry : entrySet()) { String key = entry.getKey(); if (key.startsWith(prefix)) { toRemove.add(key); } } for (String key : toRemove) { remove(key); } } }
public boolean isRemovedFromConfig(CruiseConfig cruiseConfig) { return type.isRemovedFromConfig(cruiseConfig, scope); }
public int hashCode() { int result = type.hashCode(); result = 31 * result + (scope != null ? scope.hashCode() : 0); return result; }