From: <pat...@us...> - 2010-09-20 16:48:53
|
Revision: 1134 http://cishell.svn.sourceforge.net/cishell/?rev=1134&view=rev Author: pataphil Date: 2010-09-20 16:48:46 +0000 (Mon, 20 Sep 2010) Log Message: ----------- * Fixed up Javadocs/comments for DataModel and DataModelField. * Added OneOccurrenceOfValueValidationRule (for allowing only one COUNT DISTINCT). * Minor cleanup in UniqueValueValidationRule. * Not reviewed. Modified Paths: -------------- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/DataModel.java trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/DataModelField.java trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/UniqueValueValidationRule.java Added Paths: ----------- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/OneOccurrenceOfValueValidationRule.java Modified: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/DataModel.java =================================================================== --- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/DataModel.java 2010-09-07 19:26:49 UTC (rev 1133) +++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/DataModel.java 2010-09-20 16:48:46 UTC (rev 1134) @@ -57,30 +57,30 @@ // DataModelAreaContainer methods - /// {@inheritDoc} + /** {@inheritDoc} */ public Collection<String> getAreaNames(); - /// {@inheritDoc} + /** {@inheritDoc} */ public Collection<DataModelArea> getAreas(); - /// {@inheritDoc} + /** {@inheritDoc} */ public DataModelArea getArea(String name); - /// {@inheritDoc} + /** {@inheritDoc} */ public DataModelArea createArea(String name) throws UniqueNameException; - /// {@inheritDoc} + /** {@inheritDoc} */ public DataModelArea createArea(String name, Object componentForArea) throws ClassCastException, ModelStructureException, UniqueNameException; - /// {@inheritDoc} + /** {@inheritDoc} */ public void addArea(DataModelArea area) throws ClassCastException, ModelStructureException, UniqueNameException; - /// {@inheritDoc} + /** {@inheritDoc} */ public boolean areaDisposed(String name); - /// {@inheritDoc} + /** {@inheritDoc} */ public boolean areaDisposed(DataModelArea area); // Group methods - /// @return all of the group names in this DataModel. + /** @return all of the group names in this DataModel. */ public Collection<String> getGroupNames(); - /// @return all of the groups in this DataModel. + /** @return all of the groups in this DataModel. */ public Collection<DataModelGroup> getGroups(); /** * Get a group by specific name. Modified: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/DataModelField.java =================================================================== --- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/DataModelField.java 2010-09-07 19:26:49 UTC (rev 1133) +++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/DataModelField.java 2010-09-20 16:48:46 UTC (rev 1134) @@ -21,15 +21,17 @@ public ValueType setValue(ValueType value); public ValueType reset(); - /// Add a validator to that should validate this field. + /** Add a validator that should validate this field. */ public void addValidator(FieldValidator<ValueType> validator); - /// Add validators that should be considered when performing validation actions. + /** Add all of the specified validators as validators that validate this field. */ + public void addValidators(Collection<FieldValidator<ValueType>> validators); + /** Add validators that should be considered when performing validation actions. */ public void addOtherValidators(Collection<FieldValidator<ValueType>> otherValidators); - /// Add an action to perform, given if everything validated or not. + /** Add an action to perform, given if everything validated or not. */ public void addValidationAction(FieldValidationAction action); - /// Notify everything that has added this field that this field has been disposed. + /** Notify everything that has added this field that this field has been disposed. */ public void dispose(); - /// Has this field been disposed? + /** Has this field been disposed? */ public boolean isDisposed(); } \ No newline at end of file Added: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/OneOccurrenceOfValueValidationRule.java =================================================================== --- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/OneOccurrenceOfValueValidationRule.java (rev 0) +++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/OneOccurrenceOfValueValidationRule.java 2010-09-20 16:48:46 UTC (rev 1134) @@ -0,0 +1,56 @@ +package org.cishell.utility.datastructure.datamodel.field.validation; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.cishell.utilities.MapUtilities; +import org.cishell.utilities.StringUtilities; +import org.cishell.utility.datastructure.datamodel.DataModel; +import org.cishell.utility.datastructure.datamodel.exception.ModelValidationException; +import org.cishell.utility.datastructure.datamodel.field.DataModelField; + +public class OneOccurrenceOfValueValidationRule<ValueType> + implements FieldValidationRule<ValueType> { + private String baseFieldName; + private Collection<ValueType> targetValue = new ArrayList<ValueType>(1); + private Map<String, ValueType> fieldValuesByNames = new HashMap<String, ValueType>(); + + public OneOccurrenceOfValueValidationRule(String baseFieldName, ValueType targetValue) { + this.baseFieldName = baseFieldName; + this.targetValue.add(targetValue); + } + + public void validateField(DataModelField<ValueType> field, DataModel model) + throws ModelValidationException { + String fieldName = field.getName(); + ValueType fieldValue = field.getValue(); + + this.fieldValuesByNames.put(fieldName, fieldValue); + Collection<String> namesOfFieldsWithValue = MapUtilities.getValidKeysOfTypesInMap( + this.fieldValuesByNames, this.targetValue, new ArrayList<String>()); + + if (namesOfFieldsWithValue.size() > 1) { + String exceptionMessage = String.format( + "Field's value must be not identical. Matches %sfields: [%s]", + this.baseFieldName, + StringUtilities.implodeItems(namesOfFieldsWithValue, ", ")); + throw new ModelValidationException(exceptionMessage); + } + } + + public void fieldUpdated(DataModelField<ValueType> field) { + this.fieldValuesByNames.put(field.getName(), field.getValue()); + } + + public void fieldsUpdated(Collection<DataModelField<ValueType>> fields) { + for (DataModelField<ValueType> field : fields) { + fieldUpdated(field); + } + } + + public void fieldDisposed(DataModelField<ValueType> field) { + this.fieldValuesByNames.remove(field.getName()); + } +} \ No newline at end of file Modified: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/UniqueValueValidationRule.java =================================================================== --- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/UniqueValueValidationRule.java 2010-09-07 19:26:49 UTC (rev 1133) +++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/UniqueValueValidationRule.java 2010-09-20 16:48:46 UTC (rev 1134) @@ -14,7 +14,6 @@ public class UniqueValueValidationRule<ValueType> implements FieldValidationRule<ValueType> { private String baseFieldName; private Map<String, ValueType> fieldValuesByNames = new HashMap<String, ValueType>(); -// private Multimap<ValueType, String> fieldNamesByValues = HashMultimap.create(); public UniqueValueValidationRule(String baseFieldName) { this.baseFieldName = baseFieldName; @@ -34,7 +33,7 @@ if (namesOfFieldsWithValue.size() > 0) { String exceptionMessage = String.format( - "Field's value must be identical. Matches %sfields: [%s]", + "Field's value must be not identical. Matches %sfields: [%s]", this.baseFieldName, StringUtilities.implodeItems(namesOfFieldsWithValue, ", ")); throw new ModelValidationException(exceptionMessage); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |