--- /dev/null
+/*\r
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.controller.model.util;\r
+\r
+import org.opendaylight.controller.model.api.type.LengthConstraint;\r
+import org.opendaylight.controller.model.api.type.PatternConstraint;\r
+import org.opendaylight.controller.model.api.type.RangeConstraint;\r
+\r
+public final class BaseConstraints {\r
+\r
+ private BaseConstraints() {\r
+ }\r
+\r
+ public static LengthConstraint lengthConstraint(final long min,\r
+ final long max, final String description, final String reference) {\r
+ return new LengthConstraintImpl(min, max, description, reference);\r
+ }\r
+\r
+ public static RangeConstraint rangeConstraint(final long min,\r
+ final long max, final String description, final String reference) {\r
+ return new RangeConstraintImpl(min, max, description, reference);\r
+ }\r
+\r
+ public static PatternConstraint patternConstraint(final String pattern,\r
+ final String description, final String reference) {\r
+ return new PatternConstraintImpl(pattern, description, reference);\r
+ }\r
+\r
+ private static final class LengthConstraintImpl implements LengthConstraint {\r
+\r
+ private final long min;\r
+ private final long max;\r
+\r
+ private final String description;\r
+ private final String reference;\r
+\r
+ private final String errorAppTag;\r
+ private final String errorMessage;\r
+\r
+ public LengthConstraintImpl(long min, long max,\r
+ final String description, final String reference) {\r
+ super();\r
+ this.min = min;\r
+ this.max = max;\r
+ this.description = description;\r
+ this.reference = reference;\r
+\r
+ this.errorAppTag = "length-out-of-specified-bounds";\r
+ this.errorMessage = "The argument is out of bounds <" + min + ", "\r
+ + max + ">";\r
+ }\r
+\r
+ @Override\r
+ public String getDescription() {\r
+ return description;\r
+ }\r
+\r
+ @Override\r
+ public String getErrorAppTag() {\r
+ return errorAppTag;\r
+ }\r
+\r
+ @Override\r
+ public String getErrorMessage() {\r
+ return errorMessage;\r
+ }\r
+\r
+ @Override\r
+ public String getReference() {\r
+ return reference;\r
+ }\r
+\r
+ @Override\r
+ public Long getMin() {\r
+ return min;\r
+ }\r
+\r
+ @Override\r
+ public Long getMax() {\r
+ return max;\r
+ }\r
+\r
+ @Override\r
+ public int hashCode() {\r
+ final int prime = 31;\r
+ int result = 1;\r
+ result = prime * result\r
+ + ((description == null) ? 0 : description.hashCode());\r
+ result = prime * result\r
+ + ((errorAppTag == null) ? 0 : errorAppTag.hashCode());\r
+ result = prime * result\r
+ + ((errorMessage == null) ? 0 : errorMessage.hashCode());\r
+ result = prime * result + (int) (max ^ (max >>> 32));\r
+ result = prime * result + (int) (min ^ (min >>> 32));\r
+ result = prime * result\r
+ + ((reference == null) ? 0 : reference.hashCode());\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public boolean equals(final Object obj) {\r
+ if (this == obj) {\r
+ return true;\r
+ }\r
+ if (obj == null) {\r
+ return false;\r
+ }\r
+ if (getClass() != obj.getClass()) {\r
+ return false;\r
+ }\r
+ final LengthConstraintImpl other = (LengthConstraintImpl) obj;\r
+ if (description == null) {\r
+ if (other.description != null) {\r
+ return false;\r
+ }\r
+ } else if (!description.equals(other.description)) {\r
+ return false;\r
+ }\r
+ if (errorAppTag == null) {\r
+ if (other.errorAppTag != null) {\r
+ return false;\r
+ }\r
+ } else if (!errorAppTag.equals(other.errorAppTag)) {\r
+ return false;\r
+ }\r
+ if (errorMessage == null) {\r
+ if (other.errorMessage != null) {\r
+ return false;\r
+ }\r
+ } else if (!errorMessage.equals(other.errorMessage)) {\r
+ return false;\r
+ }\r
+ if (max != other.max) {\r
+ return false;\r
+ }\r
+ if (min != other.min) {\r
+ return false;\r
+ }\r
+ if (reference == null) {\r
+ if (other.reference != null) {\r
+ return false;\r
+ }\r
+ } else if (!reference.equals(other.reference)) {\r
+ return false;\r
+ }\r
+ return true;\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ StringBuilder builder = new StringBuilder();\r
+ builder.append("LengthConstraintImpl [min=");\r
+ builder.append(min);\r
+ builder.append(", max=");\r
+ builder.append(max);\r
+ builder.append(", description=");\r
+ builder.append(description);\r
+ builder.append(", errorAppTag=");\r
+ builder.append(errorAppTag);\r
+ builder.append(", reference=");\r
+ builder.append(reference);\r
+ builder.append(", errorMessage=");\r
+ builder.append(errorMessage);\r
+ builder.append("]");\r
+ return builder.toString();\r
+ }\r
+ }\r
+\r
+ private final static class RangeConstraintImpl implements RangeConstraint {\r
+ private final Long min;\r
+ private final Long max;\r
+\r
+ private final String description;\r
+ private final String reference;\r
+\r
+ private final String errorAppTag;\r
+ private final String errorMessage;\r
+\r
+ public RangeConstraintImpl(Long min, Long max, String description,\r
+ String reference) {\r
+ super();\r
+ this.min = min;\r
+ this.max = max;\r
+ this.description = description;\r
+ this.reference = reference;\r
+\r
+ this.errorAppTag = "range-out-of-specified-bounds";\r
+ this.errorMessage = "The argument is out of bounds <" + min + ", "\r
+ + max + ">";\r
+ }\r
+\r
+ @Override\r
+ public String getDescription() {\r
+ return description;\r
+ }\r
+\r
+ @Override\r
+ public String getErrorAppTag() {\r
+ return errorAppTag;\r
+ }\r
+\r
+ @Override\r
+ public String getErrorMessage() {\r
+ return errorMessage;\r
+ }\r
+\r
+ @Override\r
+ public String getReference() {\r
+ return reference;\r
+ }\r
+\r
+ @Override\r
+ public Long getMin() {\r
+ return min;\r
+ }\r
+\r
+ @Override\r
+ public Long getMax() {\r
+ return max;\r
+ }\r
+\r
+ @Override\r
+ public int hashCode() {\r
+ final int prime = 31;\r
+ int result = 1;\r
+ result = prime * result\r
+ + ((description == null) ? 0 : description.hashCode());\r
+ result = prime * result\r
+ + ((errorAppTag == null) ? 0 : errorAppTag.hashCode());\r
+ result = prime * result\r
+ + ((errorMessage == null) ? 0 : errorMessage.hashCode());\r
+ result = prime * result + ((max == null) ? 0 : max.hashCode());\r
+ result = prime * result + ((min == null) ? 0 : min.hashCode());\r
+ result = prime * result\r
+ + ((reference == null) ? 0 : reference.hashCode());\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public boolean equals(final Object obj) {\r
+ if (this == obj) {\r
+ return true;\r
+ }\r
+ if (obj == null) {\r
+ return false;\r
+ }\r
+ if (getClass() != obj.getClass()) {\r
+ return false;\r
+ }\r
+ final RangeConstraintImpl other = (RangeConstraintImpl) obj;\r
+ if (description == null) {\r
+ if (other.description != null) {\r
+ return false;\r
+ }\r
+ } else if (!description.equals(other.description)) {\r
+ return false;\r
+ }\r
+ if (errorAppTag == null) {\r
+ if (other.errorAppTag != null) {\r
+ return false;\r
+ }\r
+ } else if (!errorAppTag.equals(other.errorAppTag)) {\r
+ return false;\r
+ }\r
+ if (errorMessage == null) {\r
+ if (other.errorMessage != null) {\r
+ return false;\r
+ }\r
+ } else if (!errorMessage.equals(other.errorMessage)) {\r
+ return false;\r
+ }\r
+ if (max == null) {\r
+ if (other.max != null) {\r
+ return false;\r
+ }\r
+ } else if (!max.equals(other.max)) {\r
+ return false;\r
+ }\r
+ if (min == null) {\r
+ if (other.min != null) {\r
+ return false;\r
+ }\r
+ } else if (!min.equals(other.min)) {\r
+ return false;\r
+ }\r
+ if (reference == null) {\r
+ if (other.reference != null) {\r
+ return false;\r
+ }\r
+ } else if (!reference.equals(other.reference)) {\r
+ return false;\r
+ }\r
+ return true;\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ final StringBuilder builder = new StringBuilder();\r
+ builder.append("RangeConstraintImpl [min=");\r
+ builder.append(min);\r
+ builder.append(", max=");\r
+ builder.append(max);\r
+ builder.append(", description=");\r
+ builder.append(description);\r
+ builder.append(", reference=");\r
+ builder.append(reference);\r
+ builder.append(", errorAppTag=");\r
+ builder.append(errorAppTag);\r
+ builder.append(", errorMessage=");\r
+ builder.append(errorMessage);\r
+ builder.append("]");\r
+ return builder.toString();\r
+ }\r
+ }\r
+\r
+ private final static class PatternConstraintImpl implements\r
+ PatternConstraint {\r
+\r
+ private final String regex;\r
+ private final String description;\r
+ private final String reference;\r
+\r
+ private final String errorAppTag;\r
+ private final String errorMessage;\r
+\r
+ public PatternConstraintImpl(final String regex,\r
+ final String description, final String reference) {\r
+ super();\r
+ this.regex = regex;\r
+ this.description = description;\r
+ this.reference = reference;\r
+\r
+ errorAppTag = "invalid-regular-expression";\r
+ // TODO: add erro message\r
+ errorMessage = "";\r
+ }\r
+\r
+ @Override\r
+ public String getDescription() {\r
+ return description;\r
+ }\r
+\r
+ @Override\r
+ public String getErrorAppTag() {\r
+ return errorAppTag;\r
+ }\r
+\r
+ @Override\r
+ public String getErrorMessage() {\r
+ return errorMessage;\r
+ }\r
+\r
+ @Override\r
+ public String getReference() {\r
+ return reference;\r
+ }\r
+\r
+ @Override\r
+ public String getRegularExpression() {\r
+ return regex;\r
+ }\r
+\r
+ @Override\r
+ public int hashCode() {\r
+ final int prime = 31;\r
+ int result = 1;\r
+ result = prime * result\r
+ + ((description == null) ? 0 : description.hashCode());\r
+ result = prime * result\r
+ + ((errorAppTag == null) ? 0 : errorAppTag.hashCode());\r
+ result = prime * result\r
+ + ((errorMessage == null) ? 0 : errorMessage.hashCode());\r
+ result = prime * result\r
+ + ((reference == null) ? 0 : reference.hashCode());\r
+ result = prime * result + ((regex == null) ? 0 : regex.hashCode());\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public boolean equals(final Object obj) {\r
+ if (this == obj) {\r
+ return true;\r
+ }\r
+ if (obj == null) {\r
+ return false;\r
+ }\r
+ if (getClass() != obj.getClass()) {\r
+ return false;\r
+ }\r
+ final PatternConstraintImpl other = (PatternConstraintImpl) obj;\r
+ if (description == null) {\r
+ if (other.description != null) {\r
+ return false;\r
+ }\r
+ } else if (!description.equals(other.description)) {\r
+ return false;\r
+ }\r
+ if (errorAppTag == null) {\r
+ if (other.errorAppTag != null) {\r
+ return false;\r
+ }\r
+ } else if (!errorAppTag.equals(other.errorAppTag)) {\r
+ return false;\r
+ }\r
+ if (errorMessage == null) {\r
+ if (other.errorMessage != null) {\r
+ return false;\r
+ }\r
+ } else if (!errorMessage.equals(other.errorMessage)) {\r
+ return false;\r
+ }\r
+ if (reference == null) {\r
+ if (other.reference != null) {\r
+ return false;\r
+ }\r
+ } else if (!reference.equals(other.reference)) {\r
+ return false;\r
+ }\r
+ if (regex == null) {\r
+ if (other.regex != null) {\r
+ return false;\r
+ }\r
+ } else if (!regex.equals(other.regex)) {\r
+ return false;\r
+ }\r
+ return true;\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ StringBuilder builder = new StringBuilder();\r
+ builder.append("PatternConstraintImpl [regex=");\r
+ builder.append(regex);\r
+ builder.append(", description=");\r
+ builder.append(description);\r
+ builder.append(", reference=");\r
+ builder.append(reference);\r
+ builder.append(", errorAppTag=");\r
+ builder.append(errorAppTag);\r
+ builder.append(", errorMessage=");\r
+ builder.append(errorMessage);\r
+ builder.append("]");\r
+ return builder.toString();\r
+ }\r
+ }\r
+}\r