Esempio n. 1
0
 public static boolean isEmpty(@Nullable Parent element) {
   if (element == null) {
     return true;
   } else if (element instanceof Element) {
     return JDOMUtil.isEmpty((Element) element);
   } else {
     Document document = (Document) element;
     return !document.hasRootElement() || JDOMUtil.isEmpty(document.getRootElement());
   }
 }
  public void writeExternal(@NotNull Element element) {
    if (myExternalizers.isEmpty()) {
      return;
    }

    List<AbstractProperty> properties = new ArrayList<>(myExternalizers.keySet());
    Collections.sort(properties, AbstractProperty.NAME_COMPARATOR);
    for (AbstractProperty property : properties) {
      Externalizer externalizer = myExternalizers.get(property);
      if (externalizer == null) {
        continue;
      }

      Object propValue = property.get(this);
      if (!Comparing.equal(propValue, property.getDefault(this))) {
        Element child = new Element(property.getName());
        externalizer.writeValue(child, propValue);
        if (!JDOMUtil.isEmpty(child)) {
          element.addContent(child);
        }
      }
    }
  }