Search in sources :

Example 1 with SingleIdentifier

use of com.revolsys.identifier.SingleIdentifier in project com.revolsys.open by revolsys.

the class AbstractCodeTable method getValueById.

protected List<Object> getValueById(Object id) {
    if (this.valueIdCache.containsKey(Collections.singletonList(id))) {
        if (id instanceof SingleIdentifier) {
            final SingleIdentifier identifier = (SingleIdentifier) id;
            return Collections.singletonList(identifier.getValue(0));
        } else {
            return Collections.singletonList(id);
        }
    } else {
        List<Object> values = this.idValueCache.get(id);
        if (values == null) {
            String lowerId = id.toString();
            if (!this.caseSensitive) {
                lowerId = lowerId.toLowerCase();
            }
            if (this.stringIdMap.containsKey(lowerId)) {
                id = this.stringIdMap.get(lowerId);
                values = this.idValueCache.get(id);
            }
        }
        return values;
    }
}
Also used : SingleIdentifier(com.revolsys.identifier.SingleIdentifier)

Example 2 with SingleIdentifier

use of com.revolsys.identifier.SingleIdentifier in project com.revolsys.open by revolsys.

the class CodeTableProperty method addValue.

public void addValue(final Record code) {
    final String idFieldName = getIdFieldName();
    final Identifier id = code.getIdentifier(idFieldName);
    if (id == null) {
        throw new NullPointerException(idFieldName + "=null for " + code);
    } else {
        final List<Object> values = new ArrayList<>();
        for (final String fieldName : this.valueFieldNames) {
            Object value = code.getValue(fieldName);
            if (value instanceof SingleIdentifier) {
                final SingleIdentifier identifier = (SingleIdentifier) value;
                value = identifier.getValue(0);
            }
            if (value == null) {
                if (!this.allowNullValues) {
                    throw new NullPointerException(this.valueFieldNames + "=null for " + code);
                }
            }
            values.add(value);
        }
        addValue(id, values);
    }
}
Also used : Identifier(com.revolsys.identifier.Identifier) SingleIdentifier(com.revolsys.identifier.SingleIdentifier) ListIdentifier(com.revolsys.identifier.ListIdentifier) SingleIdentifier(com.revolsys.identifier.SingleIdentifier) ArrayList(java.util.ArrayList)

Example 3 with SingleIdentifier

use of com.revolsys.identifier.SingleIdentifier in project com.revolsys.open by revolsys.

the class ArrayRecord method setValue.

/**
 * Set the value of the field with the specified name.
 *
 * @param index The index of the field.
 * @param value The new value.
 */
@Override
protected boolean setValue(final FieldDefinition fieldDefinition, Object value) {
    boolean updated = false;
    if (value instanceof String) {
        final String string = (String) value;
        if (!Property.hasValue(string)) {
            value = null;
        }
    }
    if (value instanceof SingleIdentifier) {
        final SingleIdentifier identifier = (SingleIdentifier) value;
        value = identifier.getValue(0);
    }
    final Object newValue = fieldDefinition.toFieldValue(value);
    final int index = fieldDefinition.getIndex();
    final Object oldValue = this.values[index];
    if (!fieldDefinition.equals(oldValue, newValue)) {
        updated = true;
        updateState();
        fieldDefinition.equals(oldValue, newValue);
    }
    this.values[index] = newValue;
    return updated;
}
Also used : SingleIdentifier(com.revolsys.identifier.SingleIdentifier)

Example 4 with SingleIdentifier

use of com.revolsys.identifier.SingleIdentifier in project com.revolsys.open by revolsys.

the class XbaseRecordWriter method writeField.

protected boolean writeField(final Record record, final XBaseFieldDefinition field) throws IOException {
    if (this.out == null) {
        return true;
    } else {
        final String fieldName = field.getFullName();
        Object value;
        if (isWriteCodeValues()) {
            value = record.getCodeValue(fieldName);
        } else {
            value = record.getValue(fieldName);
        }
        if (value instanceof SingleIdentifier) {
            final SingleIdentifier identifier = (SingleIdentifier) value;
            value = identifier.getValue(0);
        } else if (value instanceof TypedIdentifier) {
            final TypedIdentifier identifier = (TypedIdentifier) value;
            value = identifier.getIdentifier().getValue(0);
        }
        final int fieldLength = field.getLength();
        switch(field.getType()) {
            case XBaseFieldDefinition.NUMBER_TYPE:
                String numString = "";
                final DecimalFormat numberFormat = field.getNumberFormat();
                if (value == null) {
                    if (this.useZeroForNull) {
                        numString = numberFormat.format(0);
                    }
                } else {
                    if (value instanceof Number) {
                        Number number = (Number) value;
                        final int decimalPlaces = field.getDecimalPlaces();
                        if (decimalPlaces >= 0) {
                            if (number instanceof BigDecimal) {
                                final BigDecimal bigDecimal = new BigDecimal(number.toString());
                                number = bigDecimal.setScale(decimalPlaces, RoundingMode.HALF_UP);
                            } else if (number instanceof Double || number instanceof Float) {
                                final double doubleValue = number.doubleValue();
                                final double precisionScale = field.getPrecisionScale();
                                number = Doubles.makePrecise(precisionScale, doubleValue);
                            }
                        }
                        numString = numberFormat.format(number);
                    } else {
                        throw new IllegalArgumentException("Not a number " + fieldName + "=" + value);
                    }
                }
                final byte[] numberBytes = numString.getBytes();
                final int numLength = numberBytes.length;
                if (numLength > fieldLength) {
                    for (int i = 0; i < fieldLength; i++) {
                        this.recordBuffer.put((byte) '9');
                    }
                } else {
                    for (int i = numLength; i < fieldLength; i++) {
                        this.recordBuffer.put((byte) ' ');
                    }
                    this.recordBuffer.put(numberBytes);
                }
                return true;
            case XBaseFieldDefinition.FLOAT_TYPE:
                String floatString = "";
                if (value != null) {
                    floatString = value.toString();
                }
                final byte[] floatBytes = floatString.getBytes();
                final int floatLength = floatBytes.length;
                if (floatLength > fieldLength) {
                    for (int i = 0; i < fieldLength; i++) {
                        this.recordBuffer.put((byte) '9');
                    }
                } else {
                    for (int i = floatLength; i < fieldLength; i++) {
                        this.recordBuffer.put((byte) ' ');
                    }
                    this.recordBuffer.put(floatBytes);
                }
                return true;
            case XBaseFieldDefinition.CHARACTER_TYPE:
                String string = "";
                if (value != null) {
                    final Object value1 = value;
                    string = DataTypes.toString(value1);
                }
                final byte[] stringBytes = string.getBytes(this.charset);
                if (stringBytes.length >= fieldLength) {
                    this.recordBuffer.put(stringBytes, 0, fieldLength);
                } else {
                    this.recordBuffer.put(stringBytes);
                    for (int i = stringBytes.length; i < fieldLength; i++) {
                        this.recordBuffer.put((byte) ' ');
                    }
                }
                return true;
            case XBaseFieldDefinition.DATE_TYPE:
                if (value instanceof Date) {
                    final Date date = (Date) value;
                    final String dateString = Dates.format("yyyyMMdd", date);
                    this.recordBuffer.put(dateString.getBytes());
                } else if (value == null) {
                    this.recordBuffer.put("        ".getBytes());
                } else {
                    final byte[] dateBytes = value.toString().getBytes();
                    this.recordBuffer.put(dateBytes, 0, 8);
                }
                return true;
            case XBaseFieldDefinition.LOGICAL_TYPE:
                boolean logical = false;
                if (value instanceof Boolean) {
                    final Boolean boolVal = (Boolean) value;
                    logical = boolVal.booleanValue();
                } else if (value != null) {
                    logical = Boolean.valueOf(value.toString());
                }
                if (logical) {
                    this.recordBuffer.put((byte) 'T');
                } else {
                    this.recordBuffer.put((byte) 'F');
                }
                return true;
            default:
                return false;
        }
    }
}
Also used : SingleIdentifier(com.revolsys.identifier.SingleIdentifier) DecimalFormat(java.text.DecimalFormat) BigDecimal(java.math.BigDecimal) Date(java.util.Date) TypedIdentifier(com.revolsys.identifier.TypedIdentifier)

Example 5 with SingleIdentifier

use of com.revolsys.identifier.SingleIdentifier in project com.revolsys.open by revolsys.

the class FormAllFieldsModifiedPredicate method isHighlighted.

@Override
public boolean isHighlighted(final Component renderer, final ComponentAdapter adapter) {
    try {
        final int rowIndex = adapter.convertRowIndexToModel(adapter.row);
        final String fieldName = this.model.getColumnFieldName(rowIndex);
        if (fieldName != null) {
            final LayerRecordForm form = this.form.get();
            if (form.isFieldValid(fieldName)) {
                if (form.hasOriginalValue(fieldName)) {
                    Object fieldValue = form.getFieldValue(fieldName);
                    if (fieldValue instanceof SingleIdentifier) {
                        final SingleIdentifier singleIdentifier = (SingleIdentifier) fieldValue;
                        fieldValue = singleIdentifier.getValue(0);
                    }
                    final Object originalValue = form.getOriginalValue(fieldName);
                    boolean equal = DataType.equal(originalValue, fieldValue);
                    if (!equal) {
                        if (originalValue == null) {
                            if (fieldValue instanceof String) {
                                final String string = (String) fieldValue;
                                if (!Property.hasValue(string)) {
                                    equal = true;
                                }
                            }
                        }
                    }
                    return !equal;
                }
            }
        }
    } catch (final IndexOutOfBoundsException e) {
    }
    return false;
}
Also used : LayerRecordForm(com.revolsys.swing.map.form.LayerRecordForm) SingleIdentifier(com.revolsys.identifier.SingleIdentifier)

Aggregations

SingleIdentifier (com.revolsys.identifier.SingleIdentifier)6 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)1 Identifier (com.revolsys.identifier.Identifier)1 ListIdentifier (com.revolsys.identifier.ListIdentifier)1 TypedIdentifier (com.revolsys.identifier.TypedIdentifier)1 LayerRecordForm (com.revolsys.swing.map.form.LayerRecordForm)1 BigDecimal (java.math.BigDecimal)1 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1