Esempio n. 1
0
  /**
   * Returns <tt>true</tt> if and only if this <tt>CompositeData</tt> instance contains an item
   * whose name is <tt>key</tt>. If <tt>key</tt> is a null or empty String, this method simply
   * returns false.
   */
  public boolean containsKey(String key) {

    if ((key == null) || (key.trim().equals(""))) {
      return false;
    }
    return contents.containsKey(key);
  }
Esempio n. 2
0
  private static SortedMap<String, Object> makeMap(String[] itemNames, Object[] itemValues)
      throws OpenDataException {

    if (itemNames == null || itemValues == null)
      throw new IllegalArgumentException("Null itemNames or itemValues");
    if (itemNames.length == 0 || itemValues.length == 0)
      throw new IllegalArgumentException("Empty itemNames or itemValues");
    if (itemNames.length != itemValues.length) {
      throw new IllegalArgumentException(
          "Different lengths: itemNames["
              + itemNames.length
              + "], itemValues["
              + itemValues.length
              + "]");
    }

    SortedMap<String, Object> map = new TreeMap<String, Object>();
    for (int i = 0; i < itemNames.length; i++) {
      String name = itemNames[i];
      if (name == null || name.equals(""))
        throw new IllegalArgumentException("Null or empty item name");
      if (map.containsKey(name)) throw new OpenDataException("Duplicate item name " + name);
      map.put(itemNames[i], itemValues[i]);
    }

    return map;
  }
Esempio n. 3
0
  /**
   * Returns the value of the item whose name is <tt>key</tt>.
   *
   * @throws IllegalArgumentException if <tt>key</tt> is a null or empty String.
   * @throws InvalidKeyException if <tt>key</tt> is not an existing item name for this
   *     <tt>CompositeData</tt> instance.
   */
  public Object get(String key) {

    if ((key == null) || (key.trim().equals(""))) {
      throw new IllegalArgumentException("Argument key cannot be a null or empty String.");
    }
    if (!contents.containsKey(key.trim())) {
      throw new InvalidKeyException(
          "Argument key=\""
              + key.trim()
              + "\" is not an existing item name for this CompositeData instance.");
    }
    return contents.get(key.trim());
  }