You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by pl...@apache.org on 2015/08/25 21:49:46 UTC
[1/4] incubator-tamaya git commit: TAMAYA-91 Added comment on the
test implementation.
Repository: incubator-tamaya
Updated Branches:
refs/heads/master 80995f40c -> 0319f3b13
TAMAYA-91 Added comment on the test implementation.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/9b046f50
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/9b046f50
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/9b046f50
Branch: refs/heads/master
Commit: 9b046f509f760c5c9d5b5994182dc92cc4c2d5b4
Parents: d285876
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Tue Aug 25 21:23:29 2015 +0200
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Tue Aug 25 21:23:41 2015 +0200
----------------------------------------------------------------------
.../java/org/apache/tamaya/jodatime/PeriodConverterTest.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9b046f50/sandbox/jodatime/src/test/java/org/apache/tamaya/jodatime/PeriodConverterTest.java
----------------------------------------------------------------------
diff --git a/sandbox/jodatime/src/test/java/org/apache/tamaya/jodatime/PeriodConverterTest.java b/sandbox/jodatime/src/test/java/org/apache/tamaya/jodatime/PeriodConverterTest.java
index 29315a5..291959d 100644
--- a/sandbox/jodatime/src/test/java/org/apache/tamaya/jodatime/PeriodConverterTest.java
+++ b/sandbox/jodatime/src/test/java/org/apache/tamaya/jodatime/PeriodConverterTest.java
@@ -24,11 +24,14 @@ import org.joda.time.format.PeriodFormatter;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
public class PeriodConverterTest {
+ /*
+ * I am aware of the 'Parameterized tests' feature of JUnit but
+ * decided not to use it. Oliver B. Fischer, 3th April 2015
+ */
private static PeriodConverter converter = new PeriodConverter();
[4/4] incubator-tamaya git commit: Update to Maven Site Plugin 3.4
(was 3.3).
Posted by pl...@apache.org.
Update to Maven Site Plugin 3.4 (was 3.3).
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/0319f3b1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/0319f3b1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/0319f3b1
Branch: refs/heads/master
Commit: 0319f3b13624af452221203c4a89cc9327b31383
Parents: 9b046f5
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Tue Aug 25 21:49:25 2015 +0200
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Tue Aug 25 21:49:25 2015 +0200
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0319f3b1/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 11ba8b7..ce86508 100644
--- a/pom.xml
+++ b/pom.xml
@@ -479,7 +479,7 @@ under the License.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
- <version>3.3</version>
+ <version>3.4</version>
<inherited>true</inherited>
</plugin>
</plugins>
[3/4] incubator-tamaya git commit: TAMAYA-91 Introducing the
PeriodConverter. Currently it is able to handle periods given in the standard
ISO 8501 format for periods.
Posted by pl...@apache.org.
TAMAYA-91 Introducing the PeriodConverter. Currently it is able to handle periods given in the standard ISO 8501 format for periods.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/7010b594
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/7010b594
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/7010b594
Branch: refs/heads/master
Commit: 7010b594b6a08e486c183d5b983ae6514eff1179
Parents: 80995f4
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Sun Aug 23 13:22:24 2015 +0200
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Tue Aug 25 21:23:41 2015 +0200
----------------------------------------------------------------------
.../apache/tamaya/jodatime/PeriodConverter.java | 95 ++++++++++++++++++++
.../tamaya/jodatime/PeriodConverterTest.java | 45 ++++++++++
2 files changed, 140 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7010b594/sandbox/jodatime/src/main/java/org/apache/tamaya/jodatime/PeriodConverter.java
----------------------------------------------------------------------
diff --git a/sandbox/jodatime/src/main/java/org/apache/tamaya/jodatime/PeriodConverter.java b/sandbox/jodatime/src/main/java/org/apache/tamaya/jodatime/PeriodConverter.java
new file mode 100644
index 0000000..6950606
--- /dev/null
+++ b/sandbox/jodatime/src/main/java/org/apache/tamaya/jodatime/PeriodConverter.java
@@ -0,0 +1,95 @@
+/*
+ * 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.tamaya.jodatime;
+
+import org.apache.tamaya.spi.PropertyConverter;
+import org.joda.time.MutablePeriod;
+import org.joda.time.Period;
+import org.joda.time.ReadWritablePeriod;
+import org.joda.time.format.ISOPeriodFormat;
+import org.joda.time.format.PeriodParser;
+
+import java.util.Locale;
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * <p>A {@link PropertyConverter} for converting a string representation of a
+ * given period into a {@link org.joda.time.Period} instance.</p>
+ *
+ * <p>This converter supports the following string representations of a
+ * period:
+ *
+ * <ol>
+ * <li>Alternatice format ({@code Pyyyy-mm-ddThh:mm:ss})</li>
+ * <li>ISO format ({@code PyYmMwWdDThHmMsS})</li>
+ * </ol>
+ * </p>
+ *
+ *
+ */
+public class PeriodConverter implements PropertyConverter<org.joda.time.Period> {
+
+ private final static PeriodParser ISO_FORMAT = ISOPeriodFormat.standard()
+ .getParser();
+
+ private final static PeriodParser ALTERNATIVE_FORMAT = ISOPeriodFormat.alternateExtended()
+ .getParser();
+
+ private final static String ISO_REGEX = "^P\\d+Y(?:\\d+M)?(?:\\d+W)?(?:\\d+D)?(?:T(?:\\d+H)?(?:\\d+M)?(?:\\d+S)?)?";
+ private final static String ALTERNATIVE_REGEX = "^P\\d+(?:-\\d+(?:-\\d+(?:T(?:\\d+:(?:\\d+:(?:\\d+)?+)?+)?+)?+)?+)?+$";
+
+ private final static Pattern ISO_PATTERN = Pattern.compile(ISO_REGEX);
+
+ private final static Pattern ALTERNATIVE_PATTERN = Pattern.compile(ALTERNATIVE_REGEX);
+
+ @Override
+ public Period convert(String value) {
+ String trimmed = Objects.requireNonNull(value).trim();
+ MutablePeriod result = null;
+
+ PeriodParser format = null;
+
+ if (isISOFormat(trimmed)) {
+ format = ISO_FORMAT;
+ } else if (isAlternativeFormat(trimmed)) {
+ format = ALTERNATIVE_FORMAT;
+ }
+
+ if (format != null) {
+ result = new MutablePeriod();
+ int parseResult = format.parseInto(result, trimmed, 0, Locale.ENGLISH);
+
+ if (parseResult < 0) {
+ result = null;
+ }
+ }
+
+ return result != null ? result.toPeriod() : null;
+ }
+
+ private boolean isISOFormat(String value) {
+ return ISO_PATTERN.matcher(value).matches();
+ }
+
+ private boolean isAlternativeFormat(String value) {
+ return ALTERNATIVE_PATTERN.matcher(value).matches();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7010b594/sandbox/jodatime/src/test/java/org/apache/tamaya/jodatime/PeriodConverterTest.java
----------------------------------------------------------------------
diff --git a/sandbox/jodatime/src/test/java/org/apache/tamaya/jodatime/PeriodConverterTest.java b/sandbox/jodatime/src/test/java/org/apache/tamaya/jodatime/PeriodConverterTest.java
index 2dd01ce..29315a5 100644
--- a/sandbox/jodatime/src/test/java/org/apache/tamaya/jodatime/PeriodConverterTest.java
+++ b/sandbox/jodatime/src/test/java/org/apache/tamaya/jodatime/PeriodConverterTest.java
@@ -18,5 +18,50 @@
*/
package org.apache.tamaya.jodatime;
+import org.joda.time.Period;
+import org.joda.time.format.ISOPeriodFormat;
+import org.joda.time.format.PeriodFormatter;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+
public class PeriodConverterTest {
+
+ private static PeriodConverter converter = new PeriodConverter();
+
+ private static PeriodFormatter FORMATTER = ISOPeriodFormat.standard();
+
+ @Test
+ public void canConvertPropertiesInAllSupportedFormats() {
+ Object[][] inputResultPairs = {
+ // ISO format
+ {"P0007Y", FORMATTER.parsePeriod("P7Y0M0W0DT0H0M0S")},
+ {"P7Y", FORMATTER.parsePeriod("P7Y0M0W0DT0H0M0S")},
+ {"P7891Y", FORMATTER.parsePeriod("P7891Y0M0W0DT0H0M0S")},
+ {"P7891Y", FORMATTER.parsePeriod("P7891Y0M0W0DT0H0M0S")},
+
+ {"P1Y1M", FORMATTER.parsePeriod("P1Y1M0W0DT0H0M0S")},
+ {"P1Y9M", FORMATTER.parsePeriod("P1Y9M0W0DT0H0M0S")},
+
+ {"P1Y1D", FORMATTER.parsePeriod("P1Y0M0W1DT0H0M0S")},
+ {"P1YT1S", FORMATTER.parsePeriod("P1Y0M0W0DT0H0M1S")},
+
+ // Alternative format
+ {"P0002-03-00T00:00:05", FORMATTER.parsePeriod("P2Y3M0W0DT0H0M5S")},
+ {"P0002-03T00:00:05", FORMATTER.parsePeriod("P2Y3M0W0DT0H0M5S")},
+ {"P0002T00:00:05", FORMATTER.parsePeriod("P2Y3M0W0DT0H0M5S")},
+ {"P0002T00:05", FORMATTER.parsePeriod("P2Y3M0W0DT0H0M5S")}
+
+ };
+
+ for (Object[] pair : inputResultPairs) {
+ Period period = converter.convert((String) pair[0]);
+
+ assertThat("Converter failed to convert input value " + pair[0], period, notNullValue());
+ assertThat(period, equalTo((Period)pair[1]));
+ }
+ }
}
[2/4] incubator-tamaya git commit: TAMAYA-91 Removed imports.
Posted by pl...@apache.org.
TAMAYA-91 Removed imports.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/d285876a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/d285876a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/d285876a
Branch: refs/heads/master
Commit: d285876ae53dc8ae30a5bb52e4ac30967647a49a
Parents: 7010b59
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Tue Aug 25 21:23:11 2015 +0200
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Tue Aug 25 21:23:41 2015 +0200
----------------------------------------------------------------------
.../org/apache/tamaya/jodatime/DateTimeZoneConverterTest.java | 3 ---
1 file changed, 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d285876a/sandbox/jodatime/src/test/java/org/apache/tamaya/jodatime/DateTimeZoneConverterTest.java
----------------------------------------------------------------------
diff --git a/sandbox/jodatime/src/test/java/org/apache/tamaya/jodatime/DateTimeZoneConverterTest.java b/sandbox/jodatime/src/test/java/org/apache/tamaya/jodatime/DateTimeZoneConverterTest.java
index 0077c25..eba23ca 100644
--- a/sandbox/jodatime/src/test/java/org/apache/tamaya/jodatime/DateTimeZoneConverterTest.java
+++ b/sandbox/jodatime/src/test/java/org/apache/tamaya/jodatime/DateTimeZoneConverterTest.java
@@ -18,16 +18,13 @@
*/
package org.apache.tamaya.jodatime;
-import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.fail;
public class DateTimeZoneConverterTest {
private DateTimeZoneConverter converter = new DateTimeZoneConverter();