Skip to content

Commit

Permalink
Merge pull request veraPDF#5 from shem-sergey/policy-branch
Browse files Browse the repository at this point in the history
Moved choosing operations for type to FeatureType enum.
  • Loading branch information
BezrukovM authored Apr 13, 2017
2 parents 524bcfa + e5842b7 commit d5a1409
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 46 deletions.
36 changes: 35 additions & 1 deletion core/src/main/java/org/verapdf/features/objects/Feature.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
*/
package org.verapdf.features.objects;

import org.verapdf.policy.SchematronOperation;

import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;

import static org.verapdf.policy.SchematronOperation.*;

/**
* @author Maksim Bezrukov
*/
Expand Down Expand Up @@ -51,6 +60,31 @@ public FeatureType getFeatureType() {
public enum FeatureType {
BOOLEAN,
NUMBER,
STRING
STRING;

EnumSet<SchematronOperation> legalOperations;

FeatureType() {
switch (this) {
case BOOLEAN:
legalOperations = EnumSet.of(PRESENT, NOT_PRESENT, IS_TRUE, IS_FALSE);
break;
case NUMBER:
legalOperations = EnumSet.of(PRESENT, NOT_PRESENT, IS_EQUAL,
NOT_EQUAL, IS_GREATER, IS_GREATER_OR_EQUAL, IS_LESS,
IS_LESS_OR_EQUAL);
break;
case STRING:
legalOperations = EnumSet.of(PRESENT, NOT_PRESENT, IS_EQUAL,
NOT_EQUAL, STARTS_WITH, ENDS_WITH, CONTAINS);
break;
default:
throw new IllegalStateException("Unsupported FeatureType in getOperationsForType: " + this);
}
}

public EnumSet<SchematronOperation> getLegalOperations() {
return this.legalOperations;
}
}
}
45 changes: 0 additions & 45 deletions core/src/main/java/org/verapdf/policy/SchematronOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

import org.verapdf.features.objects.Feature;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* Enum with operations on elements of Feature.FeatureType that can be used in
* policy configuration file.
Expand Down Expand Up @@ -37,34 +33,6 @@ public enum SchematronOperation {
ENDS_WITH(true, "ends with"),
CONTAINS(true, "contains substring");

private static List<SchematronOperation> operationsOnBooleans = new ArrayList<>(4);
private static List<SchematronOperation> operationsOnNumbers = new ArrayList<>(8);
private static List<SchematronOperation> operationsOnStrings = new ArrayList<>(7);

static {
operationsOnBooleans.add(PRESENT);
operationsOnBooleans.add(NOT_PRESENT);
operationsOnBooleans.add(IS_TRUE);
operationsOnBooleans.add(IS_FALSE);

operationsOnNumbers.add(PRESENT);
operationsOnNumbers.add(NOT_PRESENT);
operationsOnNumbers.add(IS_EQUAL);
operationsOnNumbers.add(NOT_EQUAL);
operationsOnNumbers.add(IS_GREATER);
operationsOnNumbers.add(IS_GREATER_OR_EQUAL);
operationsOnNumbers.add(IS_LESS);
operationsOnNumbers.add(IS_LESS_OR_EQUAL);

operationsOnStrings.add(PRESENT);
operationsOnStrings.add(NOT_PRESENT);
operationsOnStrings.add(IS_EQUAL);
operationsOnStrings.add(NOT_EQUAL);
operationsOnStrings.add(STARTS_WITH);
operationsOnStrings.add(ENDS_WITH);
operationsOnStrings.add(CONTAINS);
}

private boolean hasArguments;
private String description;

Expand All @@ -81,19 +49,6 @@ public String getDescription() {
return description;
}

public static List<SchematronOperation> getOperationsForType(Feature.FeatureType type) {
switch (type) {
case BOOLEAN:
return Collections.unmodifiableList(operationsOnBooleans);
case NUMBER:
return Collections.unmodifiableList(operationsOnNumbers);
case STRING:
return Collections.unmodifiableList(operationsOnStrings);
default:
throw new IllegalStateException("Unsupported FeatureType in getOperationsForType: " + type);
}
}

public AssertionInformation getAssertionInfo(Feature feature, String argument) {
if (feature == null) {
throw new IllegalArgumentException("Feature argument can not be null");
Expand Down

0 comments on commit d5a1409

Please sign in to comment.