1 19 20 package com.sslexplorer.boot; 21 22 import java.io.Serializable ; 23 import java.util.ArrayList ; 24 import java.util.Collection ; 25 import java.util.Collections ; 26 import java.util.List ; 27 28 29 34 public class DefaultPropertyDefinitionCategory implements PropertyDefinitionCategory, Serializable { 35 36 38 private int id; 39 private String imagePath; 40 private String bundle; 41 private List <PropertyDefinitionCategory> children; 42 private PropertyDefinitionCategory parent; 43 private boolean enabled = true; 44 private transient PropertyClass propertyClass; 45 46 53 public DefaultPropertyDefinitionCategory(int id, String bundle, String imagePath) { 54 this.id = id; 55 this.imagePath = imagePath; 56 this.bundle = bundle; 57 children = new ArrayList <PropertyDefinitionCategory>(); 58 } 59 60 65 public boolean equals(Object o) { 66 return o instanceof PropertyDefinitionCategory && ((PropertyDefinitionCategory) o).getId() == getId(); 67 } 68 69 74 public PropertyDefinitionCategory getParent() { 75 return parent; 76 } 77 78 83 public int getId() { 84 return id; 85 } 86 87 92 public String getBundle() { 93 return bundle; 94 } 95 96 101 public String getImagePath() { 102 return imagePath; 103 } 104 105 110 public PropertyDefinitionCategory addCategory(PropertyDefinitionCategory category) { 111 children.add(category); 112 return this; 113 } 114 115 120 public PropertyDefinitionCategory removeCategory(PropertyDefinitionCategory category) { 121 children.remove(category); 122 return this; 123 } 124 125 130 public void setParent(PropertyDefinitionCategory parent) { 131 this.parent = parent; 132 } 133 134 139 public int size() { 140 return children.size(); 141 } 142 143 148 public List <PropertyDefinitionCategory> getCategories() { 149 return children; 150 } 151 152 157 public boolean contains(PropertyDefinitionCategory category) { 158 return children.contains(category); 159 } 160 161 166 public boolean isEnabled() { 167 return enabled; 168 } 169 170 175 public void setEnabled(boolean enabled) { 176 this.enabled = enabled; 177 for(PropertyDefinitionCategory cat : children) { 178 cat.setEnabled(enabled); 179 } 180 } 181 182 187 public PropertyClass getPropertyClass() { 188 return propertyClass; 189 } 190 191 196 public void setPropertyClass(PropertyClass propertyClass) { 197 this.propertyClass = propertyClass; 198 } 199 200 203 public Collection <PropertyDefinition> getDefinitions() { 204 List <PropertyDefinition> l = new ArrayList <PropertyDefinition>(); 205 if(propertyClass == null) { 206 return l; 207 } 208 for(PropertyDefinition def : propertyClass.getDefinitions()) { 209 if(def.getCategory() == getId()) { 210 l.add(def); 211 } 212 } 213 Collections.sort(l); 214 return l; 215 } 216 217 220 public String toString() { 221 return "[parent=" + getParent() + ", id=" + getId() + ", bundle=" + getBundle() + ", image=" + getImagePath() + "]"; 222 } 223 } 224 | Popular Tags |