Author: simonetripodi
Date: Sat Jan 7 15:13:26 2012
New Revision: 1228631
URL: http://svn.apache.org/viewvc?rev=1228631&view=rev
Log:
added Sedol validation, imported and readapted from commons-validations
Added:
incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/Sedol.java
(with props)
incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/SedolValidator.java
(with props)
incubator/bval/trunk/bval-extras/src/test/java/org/apache/bval/extras/constraints/checkdigit/SedolCheckDigitTest.java
(with props)
Added:
incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/Sedol.java
URL:
http://svn.apache.org/viewvc/incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/Sedol.java?rev=1228631&view=auto
==============================================================================
---
incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/Sedol.java
(added)
+++
incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/Sedol.java
Sat Jan 7 15:13:26 2012
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bval.extras.constraints.checkdigit;
+
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.validation.Constraint;
+import javax.validation.Payload;
+
+/**
+ * <p>
+ * --
+ * TODO - This class is NOT part of the bean_validation spec and might
disappear
+ * as soon as a final version of the specification contains a similar
functionality.
+ * --
+ * </p>
+ * Description: annotation to validate a java.io.File is a directory<br/>
+ */
+@Documented
+@Constraint( validatedBy = SedolValidator.class )
+@Target( { FIELD, ANNOTATION_TYPE, PARAMETER } )
+@Retention( RUNTIME )
+public @interface Sedol {
+
+ Class<?>[] groups() default {};
+
+ String message() default
"{org.apache.bval.extras.constraints.checkdigit.Sedol.message}";
+
+ Class<? extends Payload>[] payload() default {};
+
+}
Propchange:
incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/Sedol.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/Sedol.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/Sedol.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/SedolValidator.java
URL:
http://svn.apache.org/viewvc/incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/SedolValidator.java?rev=1228631&view=auto
==============================================================================
---
incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/SedolValidator.java
(added)
+++
incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/SedolValidator.java
Sat Jan 7 15:13:26 2012
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bval.extras.constraints.checkdigit;
+
+import static java.lang.Character.getNumericValue;
+
+/**
+ * Modulus 10 <b>SEDOL</b> (UK Securities) Check Digit calculation/validation.
+ * <p>
+ * SEDOL Numbers are 7 character alphanumeric codes used
+ * to identify UK Securities (SEDOL stands for Stock Exchange Daily Official
List).
+ * <p>
+ * Check digit calculation is based on <i>modulus 10</i> with digits being
weighted
+ * based on their position, from left to right, as follows:
+ * <p>
+ * <pre><code>
+ * position: 1 2 3 4 5 6 7
+ * weighting: 1 3 1 7 3 9 1
+ * </code></pre>
+ * <p>
+ * See <a href="http://en.wikipedia.org/wiki/SEDOL">Wikipedia - SEDOL</a>
+ * for more details.
+ */
+public final class SedolValidator
+ extends ModulusValidator<Sedol> {
+
+ /** weighting given to digits depending on their right position */
+ private static final int[] POSITION_WEIGHT = new int[] {1, 3, 1, 7, 3, 9,
1};
+
+ public SedolValidator() {
+ super(10);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int weightedValue( int charValue, int leftPos, int rightPos )
+ throws Exception {
+ return (charValue * POSITION_WEIGHT[leftPos - 1]);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int toInt( char character, int leftPos, int rightPos ) {
+ int charValue = getNumericValue(character);
+ if (charValue < 0 || charValue > 35) {
+ throw new IllegalArgumentException("Invalid Character["
+ + leftPos
+ + "] = '"
+ + charValue
+ + "'");
+ }
+ return charValue;
+ }
+
+}
Propchange:
incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/SedolValidator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/SedolValidator.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/SedolValidator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
incubator/bval/trunk/bval-extras/src/test/java/org/apache/bval/extras/constraints/checkdigit/SedolCheckDigitTest.java
URL:
http://svn.apache.org/viewvc/incubator/bval/trunk/bval-extras/src/test/java/org/apache/bval/extras/constraints/checkdigit/SedolCheckDigitTest.java?rev=1228631&view=auto
==============================================================================
---
incubator/bval/trunk/bval-extras/src/test/java/org/apache/bval/extras/constraints/checkdigit/SedolCheckDigitTest.java
(added)
+++
incubator/bval/trunk/bval-extras/src/test/java/org/apache/bval/extras/constraints/checkdigit/SedolCheckDigitTest.java
Sat Jan 7 15:13:26 2012
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bval.extras.constraints.checkdigit;
+
+import java.lang.annotation.Annotation;
+
+import javax.validation.ConstraintValidator;
+
+/**
+ * Sedol Check Digit Test.
+ */
+public class SedolCheckDigitTest extends AbstractCheckDigitTest {
+
+ @Override
+ protected ConstraintValidator<? extends Annotation, String>
getConstraint() {
+ return new SedolValidator();
+ }
+
+ @Override
+ protected String[] getValid() {
+ return new String[] {
+ "0263494",
+ "0870612",
+ "B06LQ97",
+ "3437575",
+ "B07LF55",
+ };
+ }
+
+ @Override
+ protected String[] getInvalid() {
+ return new String[] {"123#567"};
+ }
+
+ @Override
+ protected String getZeroSum() {
+ return "0000000";
+ }
+
+}
Propchange:
incubator/bval/trunk/bval-extras/src/test/java/org/apache/bval/extras/constraints/checkdigit/SedolCheckDigitTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/bval/trunk/bval-extras/src/test/java/org/apache/bval/extras/constraints/checkdigit/SedolCheckDigitTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
incubator/bval/trunk/bval-extras/src/test/java/org/apache/bval/extras/constraints/checkdigit/SedolCheckDigitTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain