Android Open Source - sodf Key Value Node






From Project

Back to project page sodf.

License

The source code is released under:

Copyright (c) 2013 Lorenz Lehmann Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Sof...

If you think the Android project sodf listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package lal.sodf.framework.ontology;
//from   w  w  w.ja v  a2  s  .c o  m
import java.util.LinkedList;

/**
 * A node that has one or multiple values attached to it
 * @author Lorenz Lehmann
 *
 */
public class KeyValueNode extends Node{
  /** The list of values, enclosed in this node */
  private LinkedList<String> values = new LinkedList<String>();

  /** Create a new KeyValueNode with one value */
  public KeyValueNode(KeyNode _parent, String _key, String _value) {
    super(_parent, _key);
    addValue(_value);
  }
  /** Create a new KeyValueNode with one value */
  public KeyValueNode(String _key, String _value) {
    super(_key);
    addValue(_value);
  }
  /** Create a new KeyValueNode with multiple values */
  public KeyValueNode(KeyNode _parent, String _key, String[] _values) {
    super(_parent, _key);
    addValue(_values);
  }
  /** Create a new KeyValueNode with multiple values */
  public KeyValueNode(String _key, String[] _values) {
    super(_key);
    addValue(_values);
  }
  
  /** Get all the values within this node */
  public String[] getValues(){
    return values.toArray(new String[values.size()]);
  }
  
  /** Get the first value of this node. If the node only has one value this will be returned */
  public String getFirstValue(){
    return values.getFirst();
  }
  
  /** 
   * Add a value to the list of values
   * @param _value The value to be added
   * @return True if the value was added, false if the value is already in the list
   */
  public boolean addValue(String _value){
    //only add the value if it does not exist in the value list
    if (values.contains(_value)) return false;
    //otherwise just add it
    values.add(_value);
    return true;
  }
  
  /** 
   * Add a number of values to the list of values
   * @param _values The value to be added
   * @return The list of values, which were not added to the list because they were already in it. The array has size 0 if all values were added.
   */
  public String[] addValue(String[] _values){
    LinkedList<String> notAdded = new LinkedList<String>();
    for (int i = 0; i < _values.length; i++){
      //if the value cannot be added move it to another list to inform the user which values did not get added
      if (addValue(_values[i]) == false){
        notAdded.add(_values[i]);
      }
    }
    //check first if anything was rejected at all
    if (notAdded.size() <= 0) return new String[0];
    return notAdded.toArray(new String[notAdded.size()]);
  }
  
  /**
   * Remove a value from the list of values. A KeyValueNode must always contain at least one value!
   * @param _value The value to be removed
   * @return True if the value was removed. False if the value was not found or if this is the only value in the list.
   */
  public boolean removeValue(String _value){
    if (values.size()<=1) return false;//always at least one value
    return values.remove(_value);        
  }
  
  /** 
   * Check if a given value is a value of this node
   * @return True if this value is within this node, else false
   */
  public boolean containsValue(String _value){
    return values.contains(_value);
  }
  
  /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
  @Override
  public String toString() {
    return "KeyValueNode [values=" + values + ", key=" + key + "]";
  }
  
  
  
  
  

}




Java Source Code List

lal.apps.ontap.MainActivity.java
lal.apps.ontap.WifiVocabulary.java
lal.apps.smartfoodenvironment.activities.ExpiredActivity.java
lal.apps.smartfoodenvironment.activities.FactoryActivity.java
lal.apps.smartfoodenvironment.activities.MicrowaveActivity.java
lal.apps.smartfoodenvironment.activities.StartActivity.java
lal.apps.smartfoodenvironment.model.MicrowaveVocabulary.java
lal.apps.smartfoodenvironment.model.ProductFactory.java
lal.apps.smartfoodenvironment.model.ProductVocabulary.java
lal.sodf.example.MainActivity.java
lal.sodf.framework.SodfCallback.java
lal.sodf.framework.SodfCallback.java
lal.sodf.framework.SodfCallback.java
lal.sodf.framework.SodfFramework.java
lal.sodf.framework.SodfFramework.java
lal.sodf.framework.SodfFramework.java
lal.sodf.framework.SodfWrapper.java
lal.sodf.framework.SodfWrapper.java
lal.sodf.framework.SodfWrapper.java
lal.sodf.framework.compressor.CompressionAlgorithm.java
lal.sodf.framework.compressor.CompressionAlgorithm.java
lal.sodf.framework.compressor.CompressionAlgorithm.java
lal.sodf.framework.compressor.Compressor.java
lal.sodf.framework.compressor.Compressor.java
lal.sodf.framework.compressor.Compressor.java
lal.sodf.framework.compressor.Gzip.java
lal.sodf.framework.compressor.Gzip.java
lal.sodf.framework.compressor.Gzip.java
lal.sodf.framework.exceptions.CompressionAlgorithmNotFoundException.java
lal.sodf.framework.exceptions.CompressionAlgorithmNotFoundException.java
lal.sodf.framework.exceptions.CompressionAlgorithmNotFoundException.java
lal.sodf.framework.exceptions.DuplicateKeyException.java
lal.sodf.framework.exceptions.DuplicateKeyException.java
lal.sodf.framework.exceptions.DuplicateKeyException.java
lal.sodf.framework.exceptions.MalformedTypeException.java
lal.sodf.framework.exceptions.MalformedTypeException.java
lal.sodf.framework.exceptions.MalformedTypeException.java
lal.sodf.framework.exceptions.TagEmptyException.java
lal.sodf.framework.exceptions.TagEmptyException.java
lal.sodf.framework.exceptions.TagEmptyException.java
lal.sodf.framework.exceptions.UnformattedTagException.java
lal.sodf.framework.exceptions.UnformattedTagException.java
lal.sodf.framework.exceptions.UnformattedTagException.java
lal.sodf.framework.nfc.NfcContentWrapper.java
lal.sodf.framework.nfc.NfcContentWrapper.java
lal.sodf.framework.nfc.NfcContentWrapper.java
lal.sodf.framework.nfc.NfcHandler.java
lal.sodf.framework.nfc.NfcHandler.java
lal.sodf.framework.nfc.NfcHandler.java
lal.sodf.framework.ontology.FunctionsNode.java
lal.sodf.framework.ontology.FunctionsNode.java
lal.sodf.framework.ontology.FunctionsNode.java
lal.sodf.framework.ontology.KeyNode.java
lal.sodf.framework.ontology.KeyNode.java
lal.sodf.framework.ontology.KeyNode.java
lal.sodf.framework.ontology.KeyValueNode.java
lal.sodf.framework.ontology.KeyValueNode.java
lal.sodf.framework.ontology.KeyValueNode.java
lal.sodf.framework.ontology.MetadataNode.java
lal.sodf.framework.ontology.MetadataNode.java
lal.sodf.framework.ontology.MetadataNode.java
lal.sodf.framework.ontology.Node.java
lal.sodf.framework.ontology.Node.java
lal.sodf.framework.ontology.Node.java
lal.sodf.framework.ontology.PropertiesNode.java
lal.sodf.framework.ontology.PropertiesNode.java
lal.sodf.framework.ontology.PropertiesNode.java
lal.sodf.framework.ontology.RestInteractionNode.java
lal.sodf.framework.ontology.RestInteractionNode.java
lal.sodf.framework.ontology.RestInteractionNode.java
lal.sodf.framework.ontology.RestParameters.java
lal.sodf.framework.ontology.RestParameters.java
lal.sodf.framework.ontology.RestParameters.java
lal.sodf.framework.ontology.SodfTree.java
lal.sodf.framework.ontology.SodfTree.java
lal.sodf.framework.ontology.SodfTree.java
lal.sodf.framework.ontology.SodfVocabulary.java
lal.sodf.framework.ontology.SodfVocabulary.java
lal.sodf.framework.ontology.SodfVocabulary.java
lal.sodf.framework.parser.SodfParser.java
lal.sodf.framework.parser.SodfParser.java
lal.sodf.framework.parser.SodfParser.java