package de.tu_darmstadt.informatik.tk.scopviz.ui.css; import java.util.HashSet; import java.util.Iterator; /** * Stores a single Rule containing selectors and declarations. Offers a function * to check whether a CSSable matches one selector. * * @author Matthias Wilhelm */ class CSSRule { /** * A Set to store all selectors for the this rule. */ HashSet selectors = new HashSet(); /** * A Set to store all declarations for the this rule. */ HashSet declarations = new HashSet(); /** * A String to store the declarations in a human readable form. */ String css; /** * * @param selectors * @param declarations */ CSSRule(HashSet selectors, HashSet declarations) { super(); this.selectors = selectors; this.declarations = declarations; css = ""; for (CSSDeclaration dc : declarations) { css = css.concat(dc.toString()).concat("; "); } css = css.trim(); } /** * Checks whether a CSSable matches one selector. * * @param suspect * the CSSable to check * @return a positive integer if the condition is met. The more difficult * the rule was to meet, the greater the integer. */ int ConditionsMetBy(CSSable suspect) { int result = 0; Iterator i = selectors.iterator(); while (i.hasNext()) { CSSSelector condition = i.next(); int r = -1; if (condition.ConditionsMetBy(suspect)) r = condition.getValue(); if (r > result) result = r; } return result; } /** * * @return all stored declarations */ public HashSet getDeclarations() { return declarations; } @Override public String toString() { return selectors.toString().replace("[", "").replace("]", "") + " { " + css + " }"; } }