openrat-java-client

Unnamed repository; edit this file 'description' to name the repository.
git clone http://git.code.weiherhei.de/openrat-java-client.git
Log | Files | Refs

CMSNode.java (1833B)


      1 package de.openrat.client.util;
      2 
      3 import java.util.ArrayList;
      4 import java.util.List;
      5 
      6 public class CMSNode {
      7 
      8     private static final CMSNode EMPTY_NODE = new CMSNode(null, null, new ArrayList<>());
      9 
     10     private String name;
     11     private String value;
     12     private List<CMSNode> children;
     13 
     14     public CMSNode(String name, String value, List<CMSNode> children) {
     15         super();
     16         this.name = name;
     17         this.value = value;
     18         this.children = children;
     19     }
     20 
     21     public List<CMSNode> getChildren() {
     22 
     23         if (children != null)
     24             return children;
     25         else
     26             return new ArrayList<CMSNode>();
     27     }
     28 
     29     public String getFirstChildValue(String name) {
     30         CMSNode node = getFirstChildByName(name);
     31         if (node != null)
     32             return node.getValue();
     33         else
     34             return null;
     35     }
     36 
     37     public CMSNode getFirstChildByName(String name) {
     38 
     39         if (children == null)
     40             return EMPTY_NODE;
     41 
     42         for (CMSNode node : children) {
     43             if (name.equals(node.getName()))
     44                 return node;
     45         }
     46 
     47         return EMPTY_NODE;
     48     }
     49 
     50     public String getValue() {
     51         return value;
     52     }
     53 
     54     public boolean isTrue() {
     55         return Boolean.valueOf(value).booleanValue();
     56     }
     57 
     58     public int toInt() {
     59         return NumberUtils.toInt(value);
     60     }
     61 
     62     public long toLong() {
     63         return NumberUtils.toLong(value);
     64     }
     65 
     66 
     67     public String getName() {
     68         return name;
     69     }
     70 
     71     public boolean isEmpty() {
     72         return name == null;
     73     }
     74 
     75     public boolean isNotEmpty() {
     76         return !isEmpty();
     77     }
     78 
     79     @Override
     80     public String toString() {
     81         return this.getClass().getSimpleName() + ": " + getName() + "=" + getValue() + " children:" + children.size() + " "
     82                 + children.toString();
     83     }
     84 }