Beispiel #1
0
 // JAVADOC COMMENT ELIDED
 public void removeValue(int field, int index) {
   PIMField pimField = getField(field, false, true);
   if (pimField == null) {
     throw new IndexOutOfBoundsException("Empty field: " + field);
   }
   int currentValues = pimField.getValueCount();
   if (index < 0 || index >= currentValues) {
     throw new IndexOutOfBoundsException(
         "0 <= index < " + currentValues + ", " + index + " not in range");
   }
   checkReadOnlyFields(field);
   pimField.removeValue(index);
   currentValues--;
   if (currentValues == 0) {
     removeField(field);
   } else if (currentValues == 1) {
     // downgrade field
     Object value = pimField.getValue(0);
     int attributes = pimField.getAttributes(0);
     pimField = new ScalarPIMField();
     pimField.addValue(attributes, value);
     putField(field, pimField);
   }
   modified = true;
 }
Beispiel #2
0
  /**
   * Adds a value to a field.
   *
   * @param field identifier of field
   * @param attributes field properties
   * @param value field to update
   * @param force if <code>true</code> create the value
   * @throws FieldFullException if no more values can be added to the field
   */
  private void addValue(int field, int attributes, Object value, boolean force) {

    checkType(field, value);
    PIMField pimField = getField(field, true, true);
    int maxValues = pimHandler.getMaximumValues(pimListHandle, field);
    int currentValues = pimField.getValueCount();
    if (maxValues != -1 && currentValues >= maxValues) {
      throw new FieldFullException("Can only store " + maxValues + " in field", field);
    }
    if (!force) {
      checkReadOnlyFields(field);
    }
    if (value instanceof Integer) {
      checkIntValue(field, ((Integer) value).intValue());
    }
    if (pimField.isScalar()) {
      // upgrade PIM field
      if (currentValues == 0) {
        pimField = new ScalarPIMField();
        putField(field, pimField);
      } else {
        Object value0 = pimField.getValue(0);
        int attributes0 = pimField.getAttributes(0);
        pimField = new VectorPIMField();
        pimField.addValue(attributes0, value0);
        putField(field, pimField);
      }
    }
    attributes = filterAttributes(field, attributes);
    pimField.addValue(attributes, value);
    modified = true;
  }
Beispiel #3
0
 /**
  * Gets current value.
  *
  * @param field identifier of field
  * @param index field identifier
  * @return requested field
  */
 private Object getValue(int field, int index) {
   PIMField pimField = getField(field, false, true);
   if (pimField == null) {
     throw new IndexOutOfBoundsException("Empty field: " + field);
   }
   int currentValues = pimField.getValueCount();
   if (index < 0 || index >= currentValues) {
     throw new IndexOutOfBoundsException(
         "0 <= index < " + currentValues + ", " + index + " not in range");
   }
   return pimField.getValue(index);
 }
Beispiel #4
0
 /**
  * Format the data for output.
  *
  * @return formatted data
  */
 protected String formatData() {
   StringBuffer sb = new StringBuffer();
   for (int i = 0; i < fieldValues.length; i++) {
     if (fieldValues[i].getValueCount() != 0) {
       PIMField pimField = fieldValues[i];
       int field = fieldKeys[i];
       int valueCount = pimField.getValueCount();
       if (valueCount == 0) {
         continue;
       }
       if (i != 0) {
         sb.append(", ");
       }
       String label = pimHandler.getFieldLabel(pimListHandle, field);
       int dataType = pimHandler.getFieldDataType(pimListHandle, field);
       for (int j = 0; j < valueCount; j++) {
         sb.append(label);
         if (valueCount != 1) {
           sb.append("[");
           sb.append(j);
           sb.append("]");
         }
         sb.append("=");
         Object value = pimField.getValue(j);
         if (value == null) {
           sb.append("null");
           continue;
         }
         switch (dataType) {
           case STRING_ARRAY:
             {
               String[] aValue = (String[]) value;
               sb.append("[");
               for (int k = 0; k < aValue.length; k++) {
                 if (k != 0) {
                   sb.append(",");
                 }
                 sb.append(aValue[k]);
               }
               sb.append("]");
               break;
             }
           case BINARY:
             {
               byte[] bValue = (byte[]) value;
               sb.append("<" + bValue.length + " bytes>");
               break;
             }
           case DATE:
             {
               long dValue = ((Long) value).longValue();
               sb.append(pimHandler.composeDateTime(dValue));
               break;
             }
           default:
             sb.append(value);
         }
       }
     }
   }
   if (categories != null && categories.length != 0) {
     if (sb.length() > 0) {
       sb.append(", ");
     }
     sb.append("Categories=[");
     for (int i = 0; i < categories.length; i++) {
       if (i > 0) {
         sb.append(",");
       }
       sb.append(categories[i]);
     }
     sb.append("]");
   }
   return sb.toString();
 }