public String buildCompleteKey() {
    String ret = keyFragment;
    PropertyKeyTreeNode currentParent = this.parent;
    while (currentParent != null && currentParent.getKeyFragment() != null) {
      ret = currentParent.getKeyFragment() + "." + ret;
      currentParent = currentParent.parent;
    }

    return ret;
  }
  /**
   * Collects into the target set my key from the root and my children's keys.
   *
   * @param targetSet the set where to place the keys
   * @return the exact same set provided as input, for convenience.
   */
  public Set<String> collectKeys(Set<String> targetSet) {

    String mykey = buildCompleteKey();

    targetSet.add(mykey);

    for (PropertyKeyTreeNode node : children.values()) {
      node.collectKeys(targetSet);
    }

    return targetSet;
  }
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((keyFragment == null) ? 0 : keyFragment.hashCode());
   result = prime * result + ((parent == null) ? 0 : parent.hashCode());
   return result;
 }
  public void storeKey(String key) {

    if (key == null) {
      throw new IllegalArgumentException("Cannot send null key!");
    }

    if (StringUtils.isEmpty(key)) {
      // we have nothing else to do.
      return;
    }

    int dotIndex = key.indexOf('.');

    String childKey = null;

    // leaf
    if (dotIndex == -1) {
      childKey = key;
    } else {
      childKey = key.substring(0, dotIndex);
    }

    // store the new children.
    PropertyKeyTreeNode childNode = children.get(childKey);

    if (childNode == null) {
      childNode = new PropertyKeyTreeNode(childKey, this);
      children.put(childKey, childNode);
    }

    if (dotIndex == -1) {
      // nothing else to do
      return;
    }

    // continue to store any subkeys that might be
    childNode.storeKey(key.substring(dotIndex + 1));
  }
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   PropertyKeyTreeNode other = (PropertyKeyTreeNode) obj;
   if (keyFragment == null) {
     if (other.keyFragment != null) return false;
   } else if (!keyFragment.equals(other.keyFragment)) return false;
   if (parent == null) {
     if (other.parent != null) return false;
   } else if (!parent.equals(other.parent)) return false;
   return true;
 }