/** * Checks the type of a field, throwing an IllegalArgumentException if given or if the field * number is invalid. * * @param field identifier of field * @param dataType data type for field value */ private void checkType(int field, int dataType) { int correctDataType = pimHandler.getFieldDataType(pimListHandle, field); if (dataType != correctDataType && correctDataType != -1) { throw new IllegalArgumentException("Wrong data type"); } if (correctDataType == -1) { throw complaintAboutField(listType, field); } }
/** * Checks the type of a field, throwing an IllegalArgumentException if given or if the field * number is invalid. * * @param field identifier for field * @param value data to be checked * @throws IllegalArgumentException if data type is not known */ private void checkType(int field, Object value) { try { int dataType = pimHandler.getFieldDataType(pimListHandle, field); switch (dataType) { case PIMItem.BINARY: { byte[] b = (byte[]) value; break; } case PIMItem.BOOLEAN: { Boolean b = (Boolean) value; break; } case PIMItem.DATE: { Long l = (Long) value; break; } case PIMItem.INT: { Integer i = (Integer) value; break; } case PIMItem.STRING: { String s = (String) value; break; } case PIMItem.STRING_ARRAY: { String[] s = (String[]) value; break; } default: throw complaintAboutField(listType, field); } } catch (ClassCastException cce) { throw new IllegalArgumentException(cce.getMessage()); } }
/** * 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(); }