CSSSelector.java 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package de.tu_darmstadt.informatik.tk.scopviz.ui.css;
  2. import java.util.HashSet;
  3. import java.util.Iterator;
  4. class CSSSelector {
  5. // TODO comment
  6. String type;
  7. // TODO comment
  8. HashSet<String> classes;
  9. // TODO comment
  10. int value;
  11. // TODO comment
  12. CSSSelector(String type, HashSet<String> classes) {
  13. if (type != null && type.trim().length() > 0)
  14. this.type = type;
  15. this.classes = classes;
  16. value = (type != null ? 1 : 0) + classes.size() << 1;
  17. }
  18. // TODO comment
  19. boolean ConditionsMetBy(CSSable suspect) {
  20. if (type != null && !type.equals(suspect.getType()))
  21. return false;
  22. Iterator<String> i = classes.iterator();
  23. HashSet<String> sC = suspect.getClasses();
  24. while (i.hasNext()) {
  25. if (sC == null || !sC.contains(i.next()))
  26. return false;
  27. }
  28. return true;
  29. }
  30. // TODO comment
  31. int getValue() {
  32. return value;
  33. }
  34. @Override
  35. public String toString() {
  36. String ret = "";
  37. for (String c : classes) {
  38. ret = ret.concat(".").concat(c);
  39. }
  40. if (type == null)
  41. return ret;
  42. return type.concat(ret);
  43. }
  44. }