1 17 package org.alfresco.repo.action.evaluator.compare; 18 19 import java.io.Serializable ; 20 21 import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator; 22 import org.alfresco.service.cmr.action.ActionServiceException; 23 import org.alfresco.service.cmr.dictionary.DataTypeDefinition; 24 25 30 public class NumericPropertyValueComparator implements PropertyValueComparator 31 { 32 35 private static final String MSGID_INVALID_OPERATION = "numeric_property_value_comparator.invalid_operation"; 36 37 40 public boolean compare( 41 Serializable propertyValue, 42 Serializable compareValue, 43 ComparePropertyValueOperation operation) 44 { 45 boolean result = false; 46 if (operation == null) 47 { 48 operation = ComparePropertyValueOperation.EQUALS; 49 } 50 51 double property = ((Number )propertyValue).doubleValue(); 53 double compare = ((Number )compareValue).doubleValue(); 54 55 switch (operation) 56 { 57 case EQUALS: 58 { 59 result = (property == compare); 60 break; 61 } 62 case GREATER_THAN: 63 { 64 result = (property > compare); 65 break; 66 } 67 case GREATER_THAN_EQUAL: 68 { 69 result = (property >= compare); 70 break; 71 } 72 case LESS_THAN: 73 { 74 result = (property < compare); 75 break; 76 } 77 case LESS_THAN_EQUAL: 78 { 79 result = (property <= compare); 80 break; 81 } 82 default: 83 { 84 throw new ActionServiceException( 86 MSGID_INVALID_OPERATION, 87 new Object []{operation.toString()}); 88 } 89 } 90 91 return result; 92 } 93 94 97 public void registerComparator(ComparePropertyValueEvaluator evaluator) 98 { 99 evaluator.registerComparator(DataTypeDefinition.DOUBLE, this); 100 evaluator.registerComparator(DataTypeDefinition.FLOAT, this); 101 evaluator.registerComparator(DataTypeDefinition.INT, this); 102 evaluator.registerComparator(DataTypeDefinition.LONG, this); 103 104 } 105 106 } 107
| Popular Tags
|