joda-convert-1.5/0000775000175000017500000000000012216415242013303 5ustar ebourgebourgjoda-convert-1.5/src/0000755000175000017500000000000012203130321014054 5ustar ebourgebourgjoda-convert-1.5/src/site/0000755000175000017500000000000012216415242015034 5ustar ebourgebourgjoda-convert-1.5/src/site/site.xml0000644000175000017500000000355012203151725016524 0ustar ebourgebourg Joda.org http://www.joda.org/ Joda-Convert http://www.joda.org/joda-convert/ joda-convert-1.5/src/site/xdoc/0000755000175000017500000000000012216415242015771 5ustar ebourgebourgjoda-convert-1.5/src/site/xdoc/privacy.xml0000644000175000017500000000414512202714763020201 0ustar ebourgebourg Privacy

Information about your use of this website is collected using cookies. The collected information consists of the following:
1. The IP address from which you access the website;
2. The type of browser and operating system you use to access our site;
3. The date and time you access our site;
4. The pages you visit; and
5. The addresses of pages from where you followed a link to our site.

Part of this information is gathered using a tracking cookie set by the Google Analytics service and handled by Google as described in their privacy policy. See your browser documentation for instructions on how to disable the cookie if you prefer not to share this data with Google.

We use the gathered information to help us make our site more useful to visitors and to better understand how and when our site is used. We do not track or collect personally identifiable information or associate gathered data with any personally identifying information from other sources.

By using this website, you consent to the collection of this data in the manner and for the purpose described above.

joda-convert-1.5/src/site/xdoc/index.xml0000644000175000017500000000617112216065552017634 0ustar ebourgebourg Joda Convert Stephen Colebourne

Joda-Convert provides a small set of classes to aid conversion between Objects and Strings. It is not intended to tackle the wider problem of Object to Object transformation.

// conversion to String
String str = StringConvert.INSTANCE.convertToString(foo);

// conversion from String
Foo bar = StringConvert.INSTANCE.convertFromString(Foo.class, str);

Joda-Convert supports two mechanisms of extending the list of supported conversions. The first is to write your own converter implementing an interface. The second is to use annotations.

The ability of Joda-Convert to use annotations to define the conversion methods is a key difference from other projects. For example, most value classes, like Currency or TimeZone, already have methods to convert to and from a standard format String. Consider a Distance class:

public class Distance {

  @FromString
  public static Distance parse(String str) { ... }

  @ToString
  public String getStandardOutput() { ... }

}

As shown, the two methods may have any name. They must simply fulfil the required method signatures for conversion. The FromString annotation may also be applied to a constructor.

When Joda-Convert is asked to convert between an object and a String, if there is no registered converter then the annotations are checked. If they are found, then the methods are called by reflection.

Joda-Convert is licensed under the business-friendly Apache 2.0 licence.

Various documentation is available:

Release 1.5 is the current latest release. This release is considered stable and worthy of the 1.x tag. It depends on JDK 1.6 or later.

Available in the Maven Central repository.

Support on bugs, library usage or enhancement requests is available on a best efforts basis.

To suggest enhancements or contribute, please fork the source code on GitHub. Alternatively, use GitHub issues.




joda-convert-1.5/src/site/xdoc/userguide.xml0000644000175000017500000001426412216065551020522 0ustar ebourgebourg Joda Convert Stephen Colebourne

Joda-Convert is intended for one simple task - Converting objects to and from strings. This is a common problem, particularly when communicating over textual protocols like XML or JSON.

Using Joda-Convert is easy at the simplest level. The main access is via the class StringConvert.

The easiest way to use the conversion is via the global constant:

// conversion to a String
TimeZone zone = ...
String str = StringConvert.INSTANCE.convertToString(zone);

// conversion from a String
TimeZone zone = StringConvert.INSTANCE.convertFromString(TimeZone.class, str);

In both cases, if the input is null then the output will also be null.

The global constant is quick and easy to use, but is shared between all users in the ClassLoader. It also cannot be extended.

The alternative approach is to instantiate your own instance of StringConvert. This would normally be stored in your own static variable, or made available as needed by dependency injection. This may be updated by registering your own converters.

Each instance of StringConvert, including the global singleton, includes a standard set of JDK-based converters. These cover all the standard JDK types for which conversion to and from a string is sensible. The set also includes JSR-310 types, but these are optional and loaded by reflection. The system will run without any dependency.

Arrays of byte are handled as a standard JDK type using Base64. Arrays of char are handled by a standard JDK type by conversion to a string.

Each StringConvert instance, other than the global singleton, may have additional converters registered manually. Each converter implements the StringConverter interface, which is self explanatory.

Converters may also be manually added by method name. This is equivalent to using annotations, but suitable when you don't own the code to add them. See StringConvert.registerMethods and StringConvert.registerMethodConstructor.

In addition to manual registration of individual converters, each instance of StringConvert has a list of factories to use. The StringConverterFactory interface defines the factory. This allows either bulk registration or dynamic lookup of converters.

A factory is provided to allow numeric arrays to be converted to/from a comma separated list. A separate factory handles numeric object arrays. Another factory is provided to allow boolean arrays to be converted to/from a string such as 'TTFFT'. Again, a separate factory handles boolean object arrays. Primitive byte and char arrays are handled by default, but the primitive object arrays are handled via their own factories.

These extra factories must be manually registered, unless the StringConvert.create() static method is used, which defines an "extended" converter with the factories included.

If there is no registered converter for a type, then a search by annotation is performed. This will search for the ToString and FromString annotation on the type. These annotations will indicate which method should be called to perform the conversion.

public class Distance {

  @FromString
  public static Distance parse(String str) { ... }

  @ToString
  public String getStandardOutput() { ... }

}

To be valid, the class must contain one ToString annotation and one FromString annotation. The ToString annotation must be an instance method taking no parameters and returning a String. The FromString annotation must be either a static method or a constructor taking a String parameter and returning the correct type. If the annotations are not found on the target class, then superclasses are searched, followed by immediate parent interfaces.

Sometimes, you want to provide to/from string conversions for interfaces. In JDK 8 this can be done using static methods on interfaces. However in earlier versions, a separate "factory" class is necessary. This can also be annotated:

@FromStringFactory(factory = DistanceFactory.class)
public interface Distance {

  @ToString
  String standardFormat();

}

public class Metres implements Distance {

  @Override
  public String standardFormat() { ... }

}

public class DistanceFactory {

  @FromString
  public static Distance parseDistance(String str) { ... }

}

The FromStringFactory annotation points at the factory class that will provide the factory method. Although intended for use with interfaces, it can also be used on the target class or any superclass. Note that only the immediate parent interfaces of a class will be searched.

The concept is that other open source libraries, as well as your application code, will implement these two annotations. For open source projects, a key point is that adding the annotations is a compile-time only event. The Joda-Convert jar file is not needed by your users unless they want to use conversion. If they don't want to use Joda-Convert then the annotations are effectively ignored.

Joda-Time v2.0 and Joda-Money will both contain the annotations. In both cases, the dependency is not a runtime for users of the projects.

joda-convert-1.5/src/site/resources/0000755000175000017500000000000012216415242017046 5ustar ebourgebourgjoda-convert-1.5/src/site/resources/css/0000755000175000017500000000000012216415242017636 5ustar ebourgebourgjoda-convert-1.5/src/site/resources/css/site.css0000644000175000017500000000476612202714763021336 0ustar ebourgebourgbody, td, select, input, li{ font-family: Helvetica, Arial, sans-serif; font-size: 13px; background-color: #fff; } a { text-decoration: none; } a:link { color:#009; } a:visited { color:#009; } a:active, a:hover { text-decoration: underline; } a.externalLink, a.externalLink:link, a.externalLink:visited, a.externalLink:active, a.externalLink:hover { background: url(../images/external.png) right center no-repeat; padding-right: 15px; } a.newWindow, a.newWindow:link, a.newWindow:visited, a.newWindow:active, a.newWindow:hover { background: url(../images/newwindow.png) right center no-repeat; padding-right: 18px; } h2 { font-family: Verdana, Helvetica, Arial, sans-serif; padding: 4px 4px 4px 6px; border: 1px solid #999; color: #006; background-color: #eef; font-weight:bold; font-size: 16px; margin-top: 4px; margin-bottom: 6px; } h3 { padding: 4px 4px 4px 6px; border: 1px solid #aaa; color: #006; background-color: #eee; font-weight: normal; font-size: 14px; margin-top: 4px; margin-bottom: 6px; } p, ul { font-size: 13px; margin-top: 4px; margin-bottom: 6px; } #banner { background-color: #eef; border-bottom: 1px solid #aaa; padding: 8px; } #bannerLeft, #bannerRight { font-size: 30px; color:black; background-color:white; border: 1px solid #999; padding: 0px 5px; } #banner a:hover { text-decoration:none; } #breadcrumbs { padding-top: 1px; padding-bottom: 2px; border-bottom: 1px solid #aaa; background-color: #ddf; } #leftColumn { margin: 8px 0 8px 4px; border: 1px solid #999; background-color: #eef; } #navcolumn { padding: 6px 4px 0 6px; } #navcolumn h5 { font-size: 12px; border-bottom: 1px solid #aaaaaa; padding-top: 2px; font-weight: normal; } #navcolumn li { font-size: 12px; padding-left: 12px; background-color: #eef; } #navcolumn a:active, #navcolumn a:hover { text-decoration: none; } #lastPublished { font-size: 10px; } table.bodyTable th { color: white; background-color: #bbb; text-align: left; font-weight: bold; font-size: 13px; } table.bodyTable th, table.bodyTable td { font-size: 13px; } table.bodyTable tr.a { background-color: #ddd; } table.bodyTable tr.b { background-color: #eee; } .source { border: 1px solid #999; padding: 8px; margin: 6px; } #footer { background-color: #eef; border-top: 1px solid #999; } body { padding-bottom: 0px; } joda-convert-1.5/src/site/resources/download.html0000644000175000017500000000026112203151725021541 0ustar ebourgebourg OpenGamma joda-convert-1.5/src/test/0000755000175000017500000000000012202714763015054 5ustar ebourgebourgjoda-convert-1.5/src/test/java/0000755000175000017500000000000012202714763015775 5ustar ebourgebourgjoda-convert-1.5/src/test/java/org/0000755000175000017500000000000012202714763016564 5ustar ebourgebourgjoda-convert-1.5/src/test/java/org/joda/0000755000175000017500000000000012202714763017501 5ustar ebourgebourgjoda-convert-1.5/src/test/java/org/joda/convert/0000755000175000017500000000000012216415242021154 5ustar ebourgebourgjoda-convert-1.5/src/test/java/org/joda/convert/test1/0000755000175000017500000000000012216415242022214 5ustar ebourgebourgjoda-convert-1.5/src/test/java/org/joda/convert/test1/Test1Interface.java0000644000175000017500000000151112215600015025667 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert.test1; import org.joda.convert.ToString; /** * Example interface with annotated methods. */ public interface Test1Interface { @ToString String print(); } joda-convert-1.5/src/test/java/org/joda/convert/test1/Test1Class.java0000644000175000017500000000244012215600015025036 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert.test1; import org.joda.convert.FromString; /** * Example class with annotated methods. */ public class Test1Class implements Test1Interface { /** Amount. */ public final int amount; @FromString public static Test1Class parse(String amount) { amount = amount.substring(0, amount.length() - 1); return new Test1Class(Integer.parseInt(amount)); } public Test1Class(int amount) { this.amount = amount; } public String print() { return amount + "g"; } @Override public String toString() { return "Weight[" + amount + "g]"; } } joda-convert-1.5/src/test/java/org/joda/convert/TestBooleanObjectArrayStringConverterFactory.java0000644000175000017500000000330412216065551032777 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.Arrays; import org.joda.convert.factory.BooleanObjectArrayStringConverterFactory; import org.junit.Test; /** * Test BooleanObjectArrayStringConverterFactory. */ public class TestBooleanObjectArrayStringConverterFactory { @Test public void test_longArray() { doTest(new Boolean[0], ""); doTest(new Boolean[] {true}, "T"); doTest(new Boolean[] {false}, "F"); doTest(new Boolean[] {null}, "-"); doTest(new Boolean[] {true, true, false, null, true, false, null, null, false}, "TTF-TF--F"); } private void doTest(Boolean[] array, String str) { StringConvert test = new StringConvert(true, BooleanObjectArrayStringConverterFactory.INSTANCE); assertEquals(str, test.convertToString(array)); assertEquals(str, test.convertToString(Boolean[].class, array)); assertTrue(Arrays.equals(array, test.convertFromString(Boolean[].class, str))); } } joda-convert-1.5/src/test/java/org/joda/convert/SubMethodConstructor.java0000644000175000017500000000157412215577750026202 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class with annotated methods. */ public class SubMethodConstructor extends DistanceMethodConstructor { @FromString public SubMethodConstructor(String amount) { super(amount); } } joda-convert-1.5/src/test/java/org/joda/convert/TestBooleanArrayStringConverterFactory.java0000644000175000017500000000315312216065551031652 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.Arrays; import org.joda.convert.factory.BooleanArrayStringConverterFactory; import org.junit.Test; /** * Test BooleanArrayStringConverterFactory. */ public class TestBooleanArrayStringConverterFactory { @Test public void test_longArray() { doTest(new boolean[0], ""); doTest(new boolean[] {true}, "T"); doTest(new boolean[] {false}, "F"); doTest(new boolean[] {true, true, false, true, false, false}, "TTFTFF"); } private void doTest(boolean[] array, String str) { StringConvert test = new StringConvert(true, BooleanArrayStringConverterFactory.INSTANCE); assertEquals(str, test.convertToString(array)); assertEquals(str, test.convertToString(boolean[].class, array)); assertTrue(Arrays.equals(array, test.convertFromString(boolean[].class, str))); } } joda-convert-1.5/src/test/java/org/joda/convert/DistanceMethodMethod.java0000644000175000017500000000241312215600005026043 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class with annotated methods. */ public class DistanceMethodMethod { /** Amount. */ final int amount; @FromString public static DistanceMethodMethod parse(String amount) { amount = amount.substring(0, amount.length() - 1); return new DistanceMethodMethod(Integer.parseInt(amount)); } public DistanceMethodMethod(int amount) { this.amount = amount; } @ToString public String print() { return amount + "m"; } @Override public String toString() { return "Distance[" + amount + "m]"; } } joda-convert-1.5/src/test/java/org/joda/convert/test4/0000755000175000017500000000000012216415242022217 5ustar ebourgebourgjoda-convert-1.5/src/test/java/org/joda/convert/test4/Test4Factory.java0000644000175000017500000000226712215600015025415 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert.test4; import org.joda.convert.FromString; /** * Example class with annotated methods. */ public class Test4Factory { @FromString public static Test4Interface parseInterface(String amount) { amount = amount.substring(0, amount.length() - 1); return new Test4Class(Integer.parseInt(amount)); } @FromString public static Test4Class parseClass(String amount) { amount = amount.substring(0, amount.length() - 1); return new Test4Class(Integer.parseInt(amount)); } } joda-convert-1.5/src/test/java/org/joda/convert/test4/Test4Interface.java0000644000175000017500000000164712215600015025707 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert.test4; import org.joda.convert.FromStringFactory; import org.joda.convert.ToString; /** * Example interface with annotated methods. */ @FromStringFactory(factory = Test4Factory.class) public interface Test4Interface { @ToString String print(); } joda-convert-1.5/src/test/java/org/joda/convert/test4/Test4Class.java0000644000175000017500000000206412215600015025046 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert.test4; /** * Example class with annotated methods. */ public class Test4Class implements Test4Interface { /** Amount. */ public final int amount; public Test4Class(int amount) { this.amount = amount; } public String print() { return amount + "g"; } @Override public String toString() { return "Weight[" + amount + "g]"; } } joda-convert-1.5/src/test/java/org/joda/convert/SubNoAnnotations.java0000644000175000017500000000153312215577750025301 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class with annotated methods. */ public class SubNoAnnotations extends DistanceMethodMethod { public SubNoAnnotations(int amount) { super(amount); } } joda-convert-1.5/src/test/java/org/joda/convert/DistanceFromStringException.java0000644000175000017500000000241012215577750027454 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; import java.text.ParseException; /** * Example class with annotated methods. */ public class DistanceFromStringException { /** Amount. */ final int amount; @FromString public static DistanceFromStringException parse(String amount) throws ParseException { throw new ParseException("Test", 2); } public DistanceFromStringException(int amount) { this.amount = amount; } @ToString public String print() { return amount + "m"; } @Override public String toString() { return "Distance[" + amount + "m]"; } } joda-convert-1.5/src/test/java/org/joda/convert/DistanceWithFactory.java0000644000175000017500000000203212215600015025723 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class with no annotations. */ @FromStringFactory(factory = DistanceWithFactoryFactory.class) public class DistanceWithFactory { /** Amount. */ final int amount; public DistanceWithFactory(int amount) { this.amount = amount; } @ToString @Override public String toString() { return amount + "m"; } } joda-convert-1.5/src/test/java/org/joda/convert/TestNumericArrayStringConverterFactory.java0000644000175000017500000001131512216065551031674 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.Arrays; import org.joda.convert.factory.NumericArrayStringConverterFactory; import org.junit.Test; /** * Test NumericArrayStringConverterFactory. */ public class TestNumericArrayStringConverterFactory { @Test public void test_longArray() { doTest(new long[0], ""); doTest(new long[] {5}, "5"); doTest(new long[] {-1234, 56789}, "-1234,56789"); doTest(new long[] {12345678912345L, 12345678912345L}, "12345678912345,12345678912345"); } private void doTest(long[] array, String str) { StringConvert test = new StringConvert(true, NumericArrayStringConverterFactory.INSTANCE); assertEquals(str, test.convertToString(array)); assertEquals(str, test.convertToString(long[].class, array)); assertTrue(Arrays.equals(array, test.convertFromString(long[].class, str))); } //----------------------------------------------------------------------- @Test public void test_intArray() { doTest(new int[0], ""); doTest(new int[] {5}, "5"); doTest(new int[] {-1234, 56789}, "-1234,56789"); } private void doTest(int[] array, String str) { StringConvert test = new StringConvert(true, NumericArrayStringConverterFactory.INSTANCE); assertEquals(str, test.convertToString(array)); assertEquals(str, test.convertToString(int[].class, array)); assertTrue(Arrays.equals(array, test.convertFromString(int[].class, str))); } //----------------------------------------------------------------------- @Test public void test_shortArray() { doTest(new short[0], ""); doTest(new short[] {5}, "5"); doTest(new short[] {-1234, 5678}, "-1234,5678"); } private void doTest(short[] array, String str) { StringConvert test = new StringConvert(true, NumericArrayStringConverterFactory.INSTANCE); assertEquals(str, test.convertToString(array)); assertEquals(str, test.convertToString(short[].class, array)); assertTrue(Arrays.equals(array, test.convertFromString(short[].class, str))); } //----------------------------------------------------------------------- @Test public void test_doubleArray() { doTest(new double[0], ""); doTest(new double[] {5d}, "5.0"); doTest(new double[] {5.123456789d}, "5.123456789"); doTest(new double[] {-1234d, 5678d}, "-1234.0,5678.0"); doTest(new double[] {Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, -0.0d, +0.0d, 0d}, "NaN,-Infinity,Infinity,-0.0,0.0,0.0"); doTest(new double[] {0.0000006d, 6000000000d}, "6.0E-7,6.0E9"); } private void doTest(double[] array, String str) { StringConvert test = new StringConvert(true, NumericArrayStringConverterFactory.INSTANCE); assertEquals(str, test.convertToString(array)); assertEquals(str, test.convertToString(double[].class, array)); assertTrue(Arrays.equals(array, test.convertFromString(double[].class, str))); } //----------------------------------------------------------------------- @Test public void test_floatArray() { doTest(new float[0], ""); doTest(new float[] {5f}, "5.0"); doTest(new float[] {5.1234f}, "5.1234"); doTest(new float[] {-1234f, 5678f}, "-1234.0,5678.0"); doTest(new float[] {Float.NaN, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, -0.0f, +0.0f, 0f}, "NaN,-Infinity,Infinity,-0.0,0.0,0.0"); doTest(new float[] {0.0000006f, 6000000000f}, "6.0E-7,6.0E9"); } private void doTest(float[] array, String str) { StringConvert test = new StringConvert(true, NumericArrayStringConverterFactory.INSTANCE); assertEquals(str, test.convertToString(array)); assertEquals(str, test.convertToString(float[].class, array)); assertTrue(Arrays.equals(array, test.convertFromString(float[].class, str))); } } joda-convert-1.5/src/test/java/org/joda/convert/DistanceFromStringInvalidParameterCount.java0000644000175000017500000000234212215577750031762 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class with no annotations. */ public class DistanceFromStringInvalidParameterCount { /** Amount. */ final int amount; @FromString public static DistanceFromStringInvalidParameterCount parse(String amount, int value) { return null; } public DistanceFromStringInvalidParameterCount(int amount) { this.amount = amount; } @ToString public String print() { return amount + "m"; } @Override public String toString() { return "Distance[" + amount + "m]"; } } joda-convert-1.5/src/test/java/org/joda/convert/TestStringConverterFactory.java0000644000175000017500000000374412215615213027354 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; import static org.junit.Assert.assertSame; import org.junit.Test; /** * Test StringConvert factory. */ public class TestStringConverterFactory { @Test public void test_constructor() { StringConvert test = new StringConvert(true, new Factory1()); assertSame(MockDistanceStringConverter.INSTANCE, test.findConverter(DistanceMethodMethod.class)); } @Test(expected = IllegalArgumentException.class) public void test_constructor_null() { new StringConvert(true, (StringConverterFactory[]) null); } @Test(expected = IllegalArgumentException.class) public void test_constructor_nullInArray() { new StringConvert(true, new StringConverterFactory[] {null}); } @Test public void test_registerFactory() { StringConvert test = new StringConvert(); test.registerFactory(new Factory1()); assertSame(MockDistanceStringConverter.INSTANCE, test.findConverter(DistanceMethodMethod.class)); } static class Factory1 implements StringConverterFactory { @Override public StringConverter findConverter(Class cls) { if (cls == DistanceMethodMethod.class) { return MockDistanceStringConverter.INSTANCE; } return null; } } } joda-convert-1.5/src/test/java/org/joda/convert/TestStringConvert.java0000644000175000017500000007263412215610377025507 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; import java.math.RoundingMode; import java.text.ParseException; import org.joda.convert.test1.Test1Class; import org.joda.convert.test2.Test2Class; import org.joda.convert.test2.Test2Interface; import org.joda.convert.test3.Test3Class; import org.joda.convert.test4.Test4Class; import org.joda.convert.test4.Test4Interface; import org.junit.Test; /** * Test StringConvert. */ public class TestStringConvert { @Test public void test_constructor() { StringConvert test = new StringConvert(); StringConverter conv = test.findConverter(Integer.class); assertEquals(true, conv instanceof JDKStringConverter); } @Test public void test_constructor_true() { StringConvert test = new StringConvert(true); StringConverter conv = test.findConverter(Integer.class); assertEquals(true, conv instanceof JDKStringConverter); } @Test(expected=IllegalStateException.class) public void test_constructor_false() { StringConvert test = new StringConvert(false); StringConverter conv = test.findConverter(Integer.class); assertEquals(null, conv); } //----------------------------------------------------------------------- @Test public void test_isConvertible() { assertTrue(StringConvert.INSTANCE.isConvertible(Integer.class)); assertTrue(StringConvert.INSTANCE.isConvertible(String.class)); assertFalse(StringConvert.INSTANCE.isConvertible(Object.class)); } //----------------------------------------------------------------------- @Test public void test_convertToString() { Integer i = 6; assertEquals("6", StringConvert.INSTANCE.convertToString(i)); } @Test public void test_convertToString_primitive() { int i = 6; assertEquals("6", StringConvert.INSTANCE.convertToString(i)); } @Test public void test_convertToString_inherit() { assertEquals("CEILING", StringConvert.INSTANCE.convertToString(RoundingMode.CEILING)); } @Test public void test_convertToString_null() { assertEquals(null, StringConvert.INSTANCE.convertToString(null)); } //----------------------------------------------------------------------- @Test public void test_convertToString_withType() { Integer i = 6; assertEquals("6", StringConvert.INSTANCE.convertToString(Integer.class, i)); } @Test public void test_convertToString_withType_noGenerics() { Integer i = 6; Class cls = Integer.class; assertEquals("6", StringConvert.INSTANCE.convertToString(cls, i)); } @Test public void test_convertToString_withType_primitive1() { int i = 6; assertEquals("6", StringConvert.INSTANCE.convertToString(Integer.class, i)); } @Test public void test_convertToString_withType_primitive2() { int i = 6; assertEquals("6", StringConvert.INSTANCE.convertToString(Integer.TYPE, i)); } @Test public void test_convertToString_withType_inherit1() { assertEquals("CEILING", StringConvert.INSTANCE.convertToString(RoundingMode.class, RoundingMode.CEILING)); } @Test public void test_convertToString_withType_inherit2() { assertEquals("CEILING", StringConvert.INSTANCE.convertToString(Enum.class, RoundingMode.CEILING)); } @Test public void test_convertToString_withType_null() { assertEquals(null, StringConvert.INSTANCE.convertToString(Integer.class, null)); } @Test(expected = IllegalArgumentException.class) public void test_convertToString_withType_nullClass() { assertEquals(null, StringConvert.INSTANCE.convertToString(null, "6")); } //----------------------------------------------------------------------- @Test public void test_convertFromString() { assertEquals(Integer.valueOf(6), StringConvert.INSTANCE.convertFromString(Integer.class, "6")); } @Test public void test_convertFromString_primitiveInt() { assertEquals(Integer.valueOf(6), StringConvert.INSTANCE.convertFromString(Integer.TYPE, "6")); } @Test public void test_convertFromString_primitiveBoolean() { assertEquals(Boolean.TRUE, StringConvert.INSTANCE.convertFromString(Boolean.TYPE, "true")); } @Test public void test_convertFromString_inherit() { assertEquals(RoundingMode.CEILING, StringConvert.INSTANCE.convertFromString(RoundingMode.class, "CEILING")); } @Test public void test_convertFromString_null() { assertEquals(null, StringConvert.INSTANCE.convertFromString(Integer.class, null)); } @Test(expected = IllegalArgumentException.class) public void test_convertFromString_nullClass() { assertEquals(null, StringConvert.INSTANCE.convertFromString(null, "6")); } //----------------------------------------------------------------------- @Test public void test_findConverter() { Class cls = Integer.class; StringConverter conv = StringConvert.INSTANCE.findConverter(cls); assertEquals(Integer.valueOf(12), conv.convertFromString(cls, "12")); assertEquals("12", conv.convertToString(12)); } @Test(expected=IllegalArgumentException.class) public void test_findConverter_null() { StringConvert.INSTANCE.findConverter(null); } @Test(expected=IllegalStateException.class) public void test_findConverter_Object() { StringConvert.INSTANCE.findConverter(Object.class); } //----------------------------------------------------------------------- @Test public void test_findConverterNoGenerics() { Class cls = Integer.class; StringConverter conv = StringConvert.INSTANCE.findConverterNoGenerics(cls); assertEquals(Integer.valueOf(12), conv.convertFromString(cls, "12")); assertEquals("12", conv.convertToString(12)); } @Test(expected=IllegalArgumentException.class) public void test_findConverterNoGenerics_null() { StringConvert.INSTANCE.findConverterNoGenerics(null); } @Test(expected=IllegalStateException.class) public void test_findConverterNoGenerics_Object() { StringConvert.INSTANCE.findConverterNoGenerics(Object.class); } //----------------------------------------------------------------------- @Test public void test_convert_annotationMethodMethod() { StringConvert test = new StringConvert(); DistanceMethodMethod d = new DistanceMethodMethod(25); assertEquals("25m", test.convertToString(d)); assertEquals(d.amount, test.convertFromString(DistanceMethodMethod.class, "25m").amount); StringConverter conv = test.findConverter(DistanceMethodMethod.class); assertEquals(true, conv instanceof MethodsStringConverter); assertSame(conv, test.findConverter(DistanceMethodMethod.class)); assertEquals(true, conv.toString().startsWith("RefectionStringConverter")); } @Test public void test_convert_annotationMethodMethodCharSequence() { StringConvert test = new StringConvert(); DistanceMethodMethodCharSequence d = new DistanceMethodMethodCharSequence(25); assertEquals("25m", test.convertToString(d)); assertEquals(d.amount, test.convertFromString(DistanceMethodMethodCharSequence.class, "25m").amount); StringConverter conv = test.findConverter(DistanceMethodMethodCharSequence.class); assertEquals(true, conv instanceof MethodsStringConverter); assertSame(conv, test.findConverter(DistanceMethodMethodCharSequence.class)); assertEquals(true, conv.toString().startsWith("RefectionStringConverter")); } @Test public void test_convert_annotationMethodConstructor() { StringConvert test = new StringConvert(); DistanceMethodConstructor d = new DistanceMethodConstructor(25); assertEquals("25m", test.convertToString(d)); assertEquals(d.amount, test.convertFromString(DistanceMethodConstructor.class, "25m").amount); StringConverter conv = test.findConverter(DistanceMethodConstructor.class); assertEquals(true, conv instanceof MethodConstructorStringConverter); assertSame(conv, test.findConverter(DistanceMethodConstructor.class)); assertEquals(true, conv.toString().startsWith("RefectionStringConverter")); } @Test public void test_convert_annotationMethodConstructorCharSequence() { StringConvert test = new StringConvert(); DistanceMethodConstructorCharSequence d = new DistanceMethodConstructorCharSequence(25); assertEquals("25m", test.convertToString(d)); assertEquals(d.amount, test.convertFromString(DistanceMethodConstructorCharSequence.class, "25m").amount); StringConverter conv = test.findConverter(DistanceMethodConstructorCharSequence.class); assertEquals(true, conv instanceof MethodConstructorStringConverter); assertSame(conv, test.findConverter(DistanceMethodConstructorCharSequence.class)); assertEquals(true, conv.toString().startsWith("RefectionStringConverter")); } @Test public void test_convert_annotationSubMethodMethod() { StringConvert test = new StringConvert(); SubMethodMethod d = new SubMethodMethod(25); assertEquals("25m", test.convertToString(d)); assertEquals(d.amount, test.convertFromString(SubMethodMethod.class, "25m").amount); StringConverter conv = test.findConverter(SubMethodMethod.class); assertEquals(true, conv instanceof MethodsStringConverter); assertSame(conv, test.findConverter(SubMethodMethod.class)); } @Test public void test_convert_annotationSubMethodConstructor() { StringConvert test = new StringConvert(); SubMethodConstructor d = new SubMethodConstructor("25m"); assertEquals("25m", test.convertToString(d)); assertEquals(d.amount, test.convertFromString(SubMethodConstructor.class, "25m").amount); StringConverter conv = test.findConverter(SubMethodConstructor.class); assertEquals(true, conv instanceof MethodConstructorStringConverter); assertSame(conv, test.findConverter(SubMethodConstructor.class)); } @Test public void test_convert_annotationSuperFactorySuper() { StringConvert test = new StringConvert(); SuperFactorySuper d = new SuperFactorySuper(25); assertEquals("25m", test.convertToString(d)); assertEquals(d.amount, test.convertFromString(SuperFactorySuper.class, "25m").amount); StringConverter conv = test.findConverter(SuperFactorySuper.class); assertEquals(true, conv instanceof MethodsStringConverter); assertSame(conv, test.findConverter(SuperFactorySuper.class)); } @Test public void test_convert_annotationSuperFactorySubViaSuper() { StringConvert test = new StringConvert(); SuperFactorySub d = new SuperFactorySub(8); assertEquals("8m", test.convertToString(d)); SuperFactorySuper fromStr = test.convertFromString(SuperFactorySuper.class, "8m"); assertEquals(d.amount, fromStr.amount); assertEquals(true, fromStr instanceof SuperFactorySub); StringConverter conv = test.findConverter(SuperFactorySuper.class); assertEquals(true, conv instanceof MethodsStringConverter); assertSame(conv, test.findConverter(SuperFactorySuper.class)); } @Test public void test_convert_annotationSuperFactorySubViaSub1() { StringConvert test = new StringConvert(); SuperFactorySub d = new SuperFactorySub(25); assertEquals("25m", test.convertToString(d)); } // TODO problem is fwks, that just request a converter based on the type of the object @Test(expected = ClassCastException.class) public void test_convert_annotationSuperFactorySubViaSub2() { StringConvert test = new StringConvert(); test.convertFromString(SuperFactorySub.class, "25m"); } @Test public void test_convert_annotationToStringInvokeException() { StringConvert test = new StringConvert(); DistanceToStringException d = new DistanceToStringException(25); StringConverter conv = test.findConverter(DistanceToStringException.class); try { conv.convertToString(d); fail(); } catch (RuntimeException ex) { assertEquals(ParseException.class, ex.getCause().getClass()); } } @Test public void test_convert_annotationFromStringInvokeException() { StringConvert test = new StringConvert(); StringConverter conv = test.findConverter(DistanceFromStringException.class); try { conv.convertFromString(DistanceFromStringException.class, "25m"); fail(); } catch (RuntimeException ex) { assertEquals(ParseException.class, ex.getCause().getClass()); } } //----------------------------------------------------------------------- @Test public void test_convert_annotationFactoryMethod() { StringConvert test = new StringConvert(); DistanceWithFactory d = new DistanceWithFactory(25); assertEquals("25m", test.convertToString(d)); assertEquals(d.amount, test.convertFromString(DistanceWithFactory.class, "25m").amount); StringConverter conv = test.findConverter(DistanceWithFactory.class); assertEquals(true, conv instanceof MethodsStringConverter); assertSame(conv, test.findConverter(DistanceWithFactory.class)); assertEquals(true, conv.toString().startsWith("RefectionStringConverter")); } @Test public void test_convert_annotation_ToStringOnInterface() { StringConvert test = new StringConvert(); Test1Class d = new Test1Class(25); assertEquals("25g", test.convertToString(d)); assertEquals(d.amount, test.convertFromString(Test1Class.class, "25g").amount); StringConverter conv = test.findConverter(Test1Class.class); assertEquals(true, conv instanceof MethodsStringConverter); assertSame(conv, test.findConverter(Test1Class.class)); assertEquals(true, conv.toString().startsWith("RefectionStringConverter")); } @Test public void test_convert_annotation_FactoryAndToStringOnInterface() { StringConvert test = new StringConvert(); Test2Class d = new Test2Class(25); assertEquals("25g", test.convertToString(d)); assertEquals(d.amount, test.convertFromString(Test2Class.class, "25g").amount); StringConverter conv = test.findConverter(Test2Class.class); assertEquals(true, conv instanceof MethodsStringConverter); assertSame(conv, test.findConverter(Test2Class.class)); assertEquals(true, conv.toString().startsWith("RefectionStringConverter")); } @Test public void test_convert_annotation_FactoryAndToStringOnInterface_usingInterface() { StringConvert test = new StringConvert(); Test2Class d = new Test2Class(25); assertEquals("25g", test.convertToString(d)); assertEquals("25g", test.convertFromString(Test2Interface.class, "25g").print()); StringConverter conv = test.findConverter(Test2Interface.class); assertEquals(true, conv instanceof MethodsStringConverter); assertSame(conv, test.findConverter(Test2Interface.class)); assertEquals(true, conv.toString().startsWith("RefectionStringConverter")); } @Test public void test_convert_annotation_ToStringFromStringOnSuperClassBeatsInterface() { StringConvert test = new StringConvert(); Test3Class d = new Test3Class(25); assertEquals("25g", test.convertToString(d)); assertEquals(d.amount, test.convertFromString(Test3Class.class, "25g").amount); StringConverter conv = test.findConverter(Test3Class.class); assertEquals(true, conv instanceof MethodsStringConverter); assertSame(conv, test.findConverter(Test3Class.class)); assertEquals(true, conv.toString().startsWith("RefectionStringConverter")); } @Test(expected=IllegalStateException.class) public void test_convert_annotation_FromStringFactoryClashingMethods_fromClass() { StringConvert test = new StringConvert(); test.findConverter(Test4Class.class); } @Test(expected=IllegalStateException.class) public void test_convert_annotation_FromStringFactoryClashingMethods_fromInterface() { StringConvert test = new StringConvert(); test.findConverter(Test4Interface.class); } //----------------------------------------------------------------------- @Test(expected=IllegalStateException.class) public void test_convert_annotationNoMethods() { StringConvert test = new StringConvert(); test.findConverter(DistanceNoAnnotations.class); } @Test(expected=IllegalStateException.class) public void test_convert_annotatedMethodAndConstructor() { StringConvert test = new StringConvert(); test.findConverter(DistanceMethodAndConstructorAnnotations.class); } @Test(expected=IllegalStateException.class) public void test_convert_annotatedTwoToString() { StringConvert test = new StringConvert(); test.findConverter(DistanceTwoToStringAnnotations.class); } @Test(expected=IllegalStateException.class) public void test_convert_annotatedToStringInvalidReturnType() { StringConvert test = new StringConvert(); test.findConverter(DistanceToStringInvalidReturnType.class); } @Test(expected=IllegalStateException.class) public void test_convert_annotatedToStringInvalidParameters() { StringConvert test = new StringConvert(); test.findConverter(DistanceToStringInvalidParameters.class); } @Test(expected=IllegalStateException.class) public void test_convert_annotatedFromStringInvalidReturnType() { StringConvert test = new StringConvert(); test.findConverter(DistanceFromStringInvalidReturnType.class); } @Test(expected=IllegalStateException.class) public void test_convert_annotatedFromStringInvalidParameter() { StringConvert test = new StringConvert(); test.findConverter(DistanceFromStringInvalidParameter.class); } @Test(expected=IllegalStateException.class) public void test_convert_annotatedFromStringInvalidParameterCount() { StringConvert test = new StringConvert(); test.findConverter(DistanceFromStringInvalidParameterCount.class); } @Test(expected=IllegalStateException.class) public void test_convert_annotatedFromStringConstructorInvalidParameter() { StringConvert test = new StringConvert(); test.findConverter(DistanceFromStringConstructorInvalidParameter.class); } @Test(expected=IllegalStateException.class) public void test_convert_annotatedFromStringConstructorInvalidParameterCount() { StringConvert test = new StringConvert(); test.findConverter(DistanceFromStringConstructorInvalidParameterCount.class); } @Test(expected=IllegalStateException.class) public void test_convert_annotatedToStringNoFromString() { StringConvert test = new StringConvert(); test.findConverter(DistanceToStringNoFromString.class); } @Test(expected=IllegalStateException.class) public void test_convert_annotatedFromStringNoToString() { StringConvert test = new StringConvert(); test.findConverter(DistanceFromStringNoToString.class); } @Test(expected=IllegalStateException.class) public void test_convert_annotatedTwoFromStringMethod() { StringConvert test = new StringConvert(); test.findConverter(DistanceTwoFromStringMethodAnnotations.class); } //----------------------------------------------------------------------- @Test(expected=IllegalArgumentException.class) public void test_register_classNotNull() { StringConvert.INSTANCE.register(null, MockIntegerStringConverter.INSTANCE); } @Test(expected=IllegalArgumentException.class) public void test_register_converterNotNull() { StringConvert.INSTANCE.register(Integer.class, null); } @Test(expected=IllegalStateException.class) public void test_register_notOnShared() { StringConvert.INSTANCE.register(Integer.class, MockIntegerStringConverter.INSTANCE); } @Test public void test_register_classAlreadyRegistered() { new StringConvert().register(Integer.class, MockIntegerStringConverter.INSTANCE); } public void test_register_distance() { StringConvert test = new StringConvert(); test.register(DistanceMethodMethod.class, MockDistanceStringConverter.INSTANCE); assertSame(MockDistanceStringConverter.INSTANCE, test.findConverter(DistanceMethodMethod.class)); } //------------------------------------------------------------------------- ToStringConverter DISTANCE_TO_STRING_CONVERTER = new ToStringConverter() { public String convertToString(DistanceNoAnnotations object) { return object.toString(); } }; FromStringConverter DISTANCE_FROM_STRING_CONVERTER = new FromStringConverter() { public DistanceNoAnnotations convertFromString(Class cls, String str) { return DistanceNoAnnotations.parse(str); } }; @Test public void test_register_FunctionalInterfaces() { StringConvert test = new StringConvert(); test.register(DistanceNoAnnotations.class, DISTANCE_TO_STRING_CONVERTER, DISTANCE_FROM_STRING_CONVERTER); DistanceNoAnnotations d = new DistanceNoAnnotations(25); assertEquals("Distance[25m]", test.convertToString(d)); assertEquals(d.amount, test.convertFromString(DistanceNoAnnotations.class, "25m").amount); StringConverter conv = test.findConverter(DistanceNoAnnotations.class); assertEquals(true, conv.getClass().getName().contains("$")); assertSame(conv, test.findConverter(DistanceNoAnnotations.class)); } @Test(expected=IllegalArgumentException.class) public void test_register_FunctionalInterfaces_nullClass() { StringConvert test = new StringConvert(); test.register(null, DISTANCE_TO_STRING_CONVERTER, DISTANCE_FROM_STRING_CONVERTER); } @Test(expected=IllegalArgumentException.class) public void test_register_FunctionalInterfaces_nullToString() { StringConvert test = new StringConvert(); test.register(DistanceNoAnnotations.class, null, DISTANCE_FROM_STRING_CONVERTER); } @Test(expected=IllegalArgumentException.class) public void test_register_FunctionalInterfaces_nullFromString() { StringConvert test = new StringConvert(); test.register(DistanceNoAnnotations.class, DISTANCE_TO_STRING_CONVERTER, null); } //------------------------------------------------------------------------- @Test public void test_registerMethods() { StringConvert test = new StringConvert(); test.registerMethods(DistanceNoAnnotations.class, "toString", "parse"); DistanceNoAnnotations d = new DistanceNoAnnotations(25); assertEquals("Distance[25m]", test.convertToString(d)); assertEquals(d.amount, test.convertFromString(DistanceNoAnnotations.class, "25m").amount); StringConverter conv = test.findConverter(DistanceNoAnnotations.class); assertEquals(true, conv instanceof MethodsStringConverter); assertSame(conv, test.findConverter(DistanceNoAnnotations.class)); } @Test public void test_registerMethodsCharSequence() { StringConvert test = new StringConvert(); test.registerMethods(DistanceNoAnnotationsCharSequence.class, "toString", "parse"); DistanceNoAnnotationsCharSequence d = new DistanceNoAnnotationsCharSequence(25); assertEquals("Distance[25m]", test.convertToString(d)); assertEquals(d.amount, test.convertFromString(DistanceNoAnnotationsCharSequence.class, "25m").amount); StringConverter conv = test.findConverter(DistanceNoAnnotationsCharSequence.class); assertEquals(true, conv instanceof MethodsStringConverter); assertSame(conv, test.findConverter(DistanceNoAnnotationsCharSequence.class)); } @Test(expected=IllegalArgumentException.class) public void test_registerMethods_nullClass() { StringConvert test = new StringConvert(); test.registerMethods(null, "toString", "parse"); } @Test(expected=IllegalArgumentException.class) public void test_registerMethods_nullToString() { StringConvert test = new StringConvert(); test.registerMethods(DistanceNoAnnotations.class, null, "parse"); } @Test(expected=IllegalArgumentException.class) public void test_registerMethods_nullFromString() { StringConvert test = new StringConvert(); test.registerMethods(DistanceNoAnnotations.class, "toString", null); } @Test public void test_registerMethods_classAlreadyRegistered() { StringConvert test = new StringConvert(); test.registerMethods(DistanceNoAnnotations.class, "toString", "parse"); test.registerMethods(DistanceNoAnnotations.class, "toString", "parse"); } //------------------------------------------------------------------------- @Test public void test_registerMethodConstructorCharSequence() { StringConvert test = new StringConvert(); test.registerMethodConstructor(DistanceNoAnnotationsCharSequence.class, "toString"); DistanceNoAnnotationsCharSequence d = new DistanceNoAnnotationsCharSequence(25); assertEquals("Distance[25m]", test.convertToString(d)); assertEquals(d.amount, test.convertFromString(DistanceNoAnnotationsCharSequence.class, "25m").amount); StringConverter conv = test.findConverter(DistanceNoAnnotationsCharSequence.class); assertEquals(true, conv instanceof MethodConstructorStringConverter); assertSame(conv, test.findConverter(DistanceNoAnnotationsCharSequence.class)); } @Test public void test_registerMethodConstructor() { StringConvert test = new StringConvert(); test.registerMethodConstructor(DistanceNoAnnotations.class, "toString"); DistanceNoAnnotations d = new DistanceNoAnnotations(25); assertEquals("Distance[25m]", test.convertToString(d)); assertEquals(d.amount, test.convertFromString(DistanceNoAnnotations.class, "25m").amount); StringConverter conv = test.findConverter(DistanceNoAnnotations.class); assertEquals(true, conv instanceof MethodConstructorStringConverter); assertSame(conv, test.findConverter(DistanceNoAnnotations.class)); } @Test(expected=IllegalArgumentException.class) public void test_registerMethodConstructor_nullClass() { StringConvert test = new StringConvert(); test.registerMethodConstructor(null, "toString"); } @Test(expected=IllegalArgumentException.class) public void test_registerMethodConstructor_nullToString() { StringConvert test = new StringConvert(); test.registerMethodConstructor(DistanceNoAnnotations.class, null); } @Test public void test_registerMethodConstructor_classAlreadyRegistered() { StringConvert test = new StringConvert(); test.registerMethodConstructor(DistanceNoAnnotations.class, "toString"); test.registerMethodConstructor(DistanceNoAnnotations.class, "toString"); } //----------------------------------------------------------------------- @Test public void test_convert_toString() { assertEquals("StringConvert", new StringConvert().toString()); } } joda-convert-1.5/src/test/java/org/joda/convert/DistanceMethodAndConstructorAnnotations.java0000644000175000017500000000304012215577750032032 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class with no annotations. */ public class DistanceMethodAndConstructorAnnotations { /** Amount. */ final int amount; @FromString public static DistanceMethodAndConstructorAnnotations parse(String amount) { amount = amount.substring(0, amount.length() - 1); return new DistanceMethodAndConstructorAnnotations(Integer.parseInt(amount)); } public DistanceMethodAndConstructorAnnotations(int amount) { this.amount = amount; } @FromString public DistanceMethodAndConstructorAnnotations(String amount) { amount = amount.substring(0, amount.length() - 1); this.amount = Integer.parseInt(amount); } @ToString public String print() { return amount + "m"; } @Override public String toString() { return "Distance[" + amount + "m]"; } } joda-convert-1.5/src/test/java/org/joda/convert/DistanceFromStringConstructorInvalidParameter.java0000644000175000017500000000234012215577750033215 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class with no annotations. */ public class DistanceFromStringConstructorInvalidParameter { /** Amount. */ final int amount; @FromString public DistanceFromStringConstructorInvalidParameter(Object amount) { this.amount = 0; } public DistanceFromStringConstructorInvalidParameter(int amount) { this.amount = amount; } @ToString public String print() { return amount + "m"; } @Override public String toString() { return "Distance[" + amount + "m]"; } } joda-convert-1.5/src/test/java/org/joda/convert/DistanceTwoToStringAnnotations.java0000644000175000017500000000242512215577750030172 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class with no annotations. */ public class DistanceTwoToStringAnnotations { /** Amount. */ final int amount; public DistanceTwoToStringAnnotations(int amount) { this.amount = amount; } @FromString public DistanceTwoToStringAnnotations(String amount) { amount = amount.substring(0, amount.length() - 1); this.amount = Integer.parseInt(amount); } @ToString public String print() { return amount + "m"; } @ToString @Override public String toString() { return "Distance[" + amount + "m]"; } } joda-convert-1.5/src/test/java/org/joda/convert/test3/0000755000175000017500000000000012216415242022216 5ustar ebourgebourgjoda-convert-1.5/src/test/java/org/joda/convert/test3/Test3Factory.java0000644000175000017500000000164212215600015025407 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert.test3; import org.joda.convert.FromString; /** * Example class with annotated methods. */ public class Test3Factory { @FromString public static Test3Interface parse(String amount) { throw new UnsupportedOperationException(); } } joda-convert-1.5/src/test/java/org/joda/convert/test3/Test3Class.java0000644000175000017500000000213312215600015025041 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert.test3; /** * Example class with annotated methods. */ public class Test3Class extends Test3SuperClass implements Test3Interface { /** Amount. */ public final int amount; public Test3Class(int amount) { this.amount = amount; } @Override public String print() { return amount + "g"; } @Override public String toString() { return "Weight[" + amount + "g]"; } } joda-convert-1.5/src/test/java/org/joda/convert/test3/Test3SuperClass.java0000644000175000017500000000211212215600015026055 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert.test3; import org.joda.convert.FromString; import org.joda.convert.ToString; /** * Example class with annotated methods. */ public abstract class Test3SuperClass { @FromString public static Test3SuperClass parse(String amount) { amount = amount.substring(0, amount.length() - 1); return new Test3Class(Integer.parseInt(amount)); } @ToString public abstract String print(); } joda-convert-1.5/src/test/java/org/joda/convert/test3/Test3Interface.java0000644000175000017500000000167112215600015025702 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert.test3; import org.joda.convert.FromStringFactory; import org.joda.convert.ToString; /** * Example interface with annotated methods. */ @FromStringFactory(factory = Test3Factory.class) public interface Test3Interface { @ToString @Override String toString(); } joda-convert-1.5/src/test/java/org/joda/convert/DistanceFromStringInvalidReturnType.java0000644000175000017500000000225712215577750031157 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class with no annotations. */ public class DistanceFromStringInvalidReturnType { /** Amount. */ final int amount; @FromString public static Integer parse(String amount) { return null; } public DistanceFromStringInvalidReturnType(int amount) { this.amount = amount; } @ToString public String print() { return amount + "m"; } @Override public String toString() { return "Distance[" + amount + "m]"; } } joda-convert-1.5/src/test/java/org/joda/convert/DistanceWithFactoryFactory.java0000644000175000017500000000167612215600015027270 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example factory. */ public class DistanceWithFactoryFactory { @FromString public static DistanceWithFactory parse(String amount) { amount = amount.substring(0, amount.length() - 1); return new DistanceWithFactory(Integer.parseInt(amount)); } } joda-convert-1.5/src/test/java/org/joda/convert/DistanceNoAnnotationsCharSequence.java0000644000175000017500000000263312215600005030547 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class with no annotations. */ public class DistanceNoAnnotationsCharSequence { /** Amount. */ final int amount; public static DistanceNoAnnotationsCharSequence parse(CharSequence amount) { return new DistanceNoAnnotationsCharSequence(amount); } public DistanceNoAnnotationsCharSequence(int amount) { this.amount = amount; } public DistanceNoAnnotationsCharSequence(CharSequence amount) { String amt = amount.toString().substring(0, amount.length() - 1); this.amount = Integer.parseInt(amt); } public String print() { return amount + "m"; } @Override public String toString() { return "Distance[" + amount + "m]"; } } joda-convert-1.5/src/test/java/org/joda/convert/TestCharObjectArrayStringConverterFactory.java0000644000175000017500000000346112216065551032301 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.Arrays; import org.joda.convert.factory.CharObjectArrayStringConverterFactory; import org.junit.Test; /** * Test CharObjectArrayStringConverterFactory. */ public class TestCharObjectArrayStringConverterFactory { @Test public void test_CharacterArray() { doTest(new Character[0], ""); doTest(new Character[] {'T'}, "T"); doTest(new Character[] {'-'}, "-"); doTest(new Character[] {null}, "\\-"); doTest(new Character[] {'J', '-', 'T'}, "J-T"); doTest(new Character[] {'\\', '\\', null}, "\\\\\\\\\\-"); doTest(new Character[] {'-', 'H', 'e', null, null, 'o'}, "-He\\-\\-o"); } private void doTest(Character[] array, String str) { StringConvert test = new StringConvert(true, CharObjectArrayStringConverterFactory.INSTANCE); assertEquals(str, test.convertToString(array)); assertEquals(str, test.convertToString(Character[].class, array)); assertTrue(Arrays.equals(array, test.convertFromString(Character[].class, str))); } } joda-convert-1.5/src/test/java/org/joda/convert/DistanceToStringException.java0000644000175000017500000000255112215577750027141 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; import java.text.ParseException; /** * Example class with annotated methods. */ public class DistanceToStringException { /** Amount. */ final int amount; @FromString public static DistanceToStringException parse(String amount) { amount = amount.substring(0, amount.length() - 1); return new DistanceToStringException(Integer.parseInt(amount)); } public DistanceToStringException(int amount) { this.amount = amount; } @ToString public String print() throws ParseException { throw new ParseException("Test", 2); } @Override public String toString() { return "Distance[" + amount + "m]"; } } joda-convert-1.5/src/test/java/org/joda/convert/DistanceFromStringNoToString.java0000644000175000017500000000236112215577750027571 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class with no annotations. */ public class DistanceFromStringNoToString { /** Amount. */ final int amount; public DistanceFromStringNoToString(int amount) { this.amount = amount; } @FromString public DistanceFromStringNoToString(String amount) { amount = amount.substring(0, amount.length() - 1); this.amount = Integer.parseInt(amount); } public String print() { return amount + "m"; } @Override public String toString() { return "Distance[" + amount + "m]"; } } joda-convert-1.5/src/test/java/org/joda/convert/TestJDKStringConverters.java0000644000175000017500000003732012215617723026545 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.File; import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; import java.net.InetAddress; import java.net.URI; import java.net.URL; import java.util.Arrays; import java.util.Calendar; import java.util.Currency; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import org.junit.Test; /** * Test JDKStringConverters. */ public class TestJDKStringConverters { @Test public void test_String() { JDKStringConverter test = JDKStringConverter.STRING; doTest(test, String.class, "Hello", "Hello"); } @Test public void test_StringBuffer() { JDKStringConverter test = JDKStringConverter.STRING_BUFFER; Object obj = new StringBuffer("Hello"); assertEquals(StringBuffer.class, test.getType()); assertEquals("Hello", test.convertToString(obj)); StringBuffer back = (StringBuffer) test.convertFromString(StringBuffer.class, "Hello"); assertEquals("Hello", back.toString()); } @Test public void test_StringBuilder() { JDKStringConverter test = JDKStringConverter.STRING_BUILDER; Object obj = new StringBuilder("Hello"); assertEquals(StringBuilder.class, test.getType()); assertEquals("Hello", test.convertToString(obj)); StringBuilder back = (StringBuilder) test.convertFromString(StringBuilder.class, "Hello"); assertEquals("Hello", back.toString()); } @Test public void test_CharSequence() { JDKStringConverter test = JDKStringConverter.CHAR_SEQUENCE; doTest(test, CharSequence.class, "Hello", "Hello"); doTest(test, CharSequence.class, new StringBuffer("Hello"), "Hello", "Hello"); doTest(test, CharSequence.class, new StringBuilder("Hello"), "Hello", "Hello"); } @Test public void test_Long() { JDKStringConverter test = JDKStringConverter.LONG; doTest(test, Long.class, Long.valueOf(12L), "12"); } @Test public void test_Int() { JDKStringConverter test = JDKStringConverter.INTEGER; doTest(test, Integer.class, Integer.valueOf(12), "12"); } @Test public void test_Short() { JDKStringConverter test = JDKStringConverter.SHORT; doTest(test, Short.class, Short.valueOf((byte) 12), "12"); } @Test public void test_Character() { JDKStringConverter test = JDKStringConverter.CHARACTER; doTest(test, Character.class, Character.valueOf('a'), "a"); doTest(test, Character.class, Character.valueOf('z'), "z"); } @Test(expected=IllegalArgumentException.class) public void test_Character_fail() { JDKStringConverter.CHARACTER.convertFromString(Character.class, "RUBBISH"); } @Test public void test_charArray() { JDKStringConverter test = JDKStringConverter.CHAR_ARRAY; char[] array = new char[] {'M', 'a', 'p'}; String str = "Map"; assertEquals(char[].class, test.getType()); assertEquals(str, test.convertToString(array)); assertTrue(Arrays.equals(array, (char[]) test.convertFromString(char[].class, str))); } @Test public void test_Byte() { JDKStringConverter test = JDKStringConverter.BYTE; doTest(test, Byte.class, Byte.valueOf((byte) 12), "12"); } @Test public void test_byteArray1() { JDKStringConverter test = JDKStringConverter.BYTE_ARRAY; byte[] array = new byte[] {77, 97, 112}; String str = "TWFw"; assertEquals(byte[].class, test.getType()); assertEquals(str, test.convertToString(array)); assertTrue(Arrays.equals(array, (byte[]) test.convertFromString(byte[].class, str))); } @Test public void test_byteArray2() { JDKStringConverter test = JDKStringConverter.BYTE_ARRAY; byte[] array = new byte[] {77, 97}; String str = "TWE="; assertEquals(byte[].class, test.getType()); assertEquals(str, test.convertToString(array)); assertTrue(Arrays.equals(array, (byte[]) test.convertFromString(byte[].class, str))); } @Test public void test_Boolean() { JDKStringConverter test = JDKStringConverter.BOOLEAN; doTest(test, Boolean.class, Boolean.TRUE, "true"); doTest(test, Boolean.class, Boolean.FALSE, "false"); } @Test(expected=IllegalArgumentException.class) public void test_Boolean_fail() { JDKStringConverter.BOOLEAN.convertFromString(Boolean.class, "RUBBISH"); } @Test public void test_Double() { JDKStringConverter test = JDKStringConverter.DOUBLE; doTest(test, Double.class, Double.valueOf(12.4d), "12.4"); } @Test public void test_Float() { JDKStringConverter test = JDKStringConverter.FLOAT; doTest(test, Float.class, Float.valueOf(12.2f), "12.2"); } @Test public void test_BigInteger() { JDKStringConverter test = JDKStringConverter.BIG_INTEGER; doTest(test, BigInteger.class, BigInteger.valueOf(12L), "12"); } @Test public void test_BigDecimal() { JDKStringConverter test = JDKStringConverter.BIG_DECIMAL; doTest(test, BigDecimal.class, BigDecimal.valueOf(12.23d), "12.23"); } @Test public void test_AtomicLong() { JDKStringConverter test = JDKStringConverter.ATOMIC_LONG; AtomicLong obj = new AtomicLong(12); assertEquals(AtomicLong.class, test.getType()); assertEquals("12", test.convertToString(obj)); AtomicLong back = (AtomicLong) test.convertFromString(AtomicLong.class, "12"); assertEquals(12, back.get()); } @Test public void test_AtomicInteger() { JDKStringConverter test = JDKStringConverter.ATOMIC_INTEGER; AtomicInteger obj = new AtomicInteger(12); assertEquals(AtomicInteger.class, test.getType()); assertEquals("12", test.convertToString(obj)); AtomicInteger back = (AtomicInteger) test.convertFromString(AtomicInteger.class, "12"); assertEquals(12, back.get()); } @Test public void test_AtomicBoolean_true() { JDKStringConverter test = JDKStringConverter.ATOMIC_BOOLEAN; AtomicBoolean obj = new AtomicBoolean(true); assertEquals(AtomicBoolean.class, test.getType()); assertEquals("true", test.convertToString(obj)); AtomicBoolean back = (AtomicBoolean) test.convertFromString(AtomicBoolean.class, "true"); assertEquals(true, back.get()); } @Test public void test_AtomicBoolean_false() { JDKStringConverter test = JDKStringConverter.ATOMIC_BOOLEAN; AtomicBoolean obj = new AtomicBoolean(false); assertEquals(AtomicBoolean.class, test.getType()); assertEquals("false", test.convertToString(obj)); AtomicBoolean back = (AtomicBoolean) test.convertFromString(AtomicBoolean.class, "false"); assertEquals(false, back.get()); } @Test(expected=IllegalArgumentException.class) public void test_AtomicBoolean_fail() { JDKStringConverter.ATOMIC_BOOLEAN.convertFromString(AtomicBoolean.class, "RUBBISH"); } @Test public void test_Locale() { JDKStringConverter test = JDKStringConverter.LOCALE; doTest(test, Locale.class, new Locale("en"), "en"); doTest(test, Locale.class, new Locale("en", "GB"), "en_GB"); doTest(test, Locale.class, new Locale("en", "GB", "VARIANT_B"), "en_GB_VARIANT_B"); } @Test public void test_Class() { JDKStringConverter test = JDKStringConverter.CLASS; doTest(test, Class.class, Locale.class, "java.util.Locale"); doTest(test, Class.class, FromString.class, "org.joda.convert.FromString"); } @Test(expected=RuntimeException.class) public void test_Class_fail() { JDKStringConverter.CLASS.convertFromString(Class.class, "RUBBISH"); } @Test public void test_Package() { JDKStringConverter test = JDKStringConverter.PACKAGE; doTest(test, Package.class, Locale.class.getPackage(), "java.util"); doTest(test, Package.class, FromString.class.getPackage(), "org.joda.convert"); } @Test public void test_Currency() { JDKStringConverter test = JDKStringConverter.CURRENCY; doTest(test, Currency.class, Currency.getInstance("GBP"), "GBP"); doTest(test, Currency.class, Currency.getInstance("USD"), "USD"); } @Test public void test_TimeZone() { JDKStringConverter test = JDKStringConverter.TIME_ZONE; doTest(test, TimeZone.class, TimeZone.getTimeZone("Europe/London"), "Europe/London"); doTest(test, TimeZone.class, TimeZone.getTimeZone("America/New_York"), "America/New_York"); } @Test public void test_UUID() { JDKStringConverter test = JDKStringConverter.UUID; UUID uuid = UUID.randomUUID(); doTest(test, UUID.class, uuid, uuid.toString()); } @Test public void test_URL() throws Exception { JDKStringConverter test = JDKStringConverter.URL; doTest(test, URL.class, new URL("http://localhost:8080/my/test"), "http://localhost:8080/my/test"); doTest(test, URL.class, new URL(null, "ftp:world"), "ftp:world"); } @Test(expected=RuntimeException.class) public void test_URL_invalidFormat() { JDKStringConverter.URL.convertFromString(URL.class, "RUBBISH:RUBBISH"); } @Test public void test_URI() { JDKStringConverter test = JDKStringConverter.URI; doTest(test, URI.class, URI.create("http://localhost:8080/my/test"), "http://localhost:8080/my/test"); doTest(test, URI.class, URI.create("/my/test"), "/my/test"); doTest(test, URI.class, URI.create("/my/../test"), "/my/../test"); doTest(test, URI.class, URI.create("urn:hello"), "urn:hello"); } @Test public void test_InetAddress() throws Exception { JDKStringConverter test = JDKStringConverter.INET_ADDRESS; doTest(test, InetAddress.class, InetAddress.getByName("1.2.3.4"), "1.2.3.4"); doTest(test, InetAddress.class, InetAddress.getByName("2001:0db8:85a3:0000:0000:8a2e:0370:7334"), "2001:db8:85a3:0:0:8a2e:370:7334"); } // @Test(expected=RuntimeException.class) // public void test_InetAddress_invalidFormat() { // JDKStringConverter.INET_ADDRESS.convertFromString(InetAddress.class, "RUBBISH"); // } @Test public void test_File() { JDKStringConverter test = JDKStringConverter.FILE; File file = new File("/path/to/file"); doTest(test, File.class, file, file.toString()); } @SuppressWarnings("deprecation") @Test public void test_Date() { TimeZone zone = TimeZone.getDefault(); try { TimeZone.setDefault(TimeZone.getTimeZone("Europe/Paris")); JDKStringConverter test = JDKStringConverter.DATE; doTest(test, Date.class, new Date(2010 - 1900, 9 - 1, 3, 12, 34, 5), "2010-09-03T12:34:05.000+02:00"); doTest(test, Date.class, new Date(2011 - 1900, 1 - 1, 4, 12, 34, 5), "2011-01-04T12:34:05.000+01:00"); } finally { TimeZone.setDefault(zone); } } @Test(expected=RuntimeException.class) public void test_Date_invalidLength() { JDKStringConverter.DATE.convertFromString(Date.class, "2010-09-03"); } @Test(expected=RuntimeException.class) public void test_Date_invalidFormat() { JDKStringConverter.DATE.convertFromString(Date.class, "2010-09-03XXX:34:05.000+02:00"); } @Test public void test_Calendar() { JDKStringConverter test = JDKStringConverter.CALENDAR; GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("Europe/Paris")); cal.set(2010, 9 - 1, 3, 12, 34, 5); cal.set(Calendar.MILLISECOND, 0); doTest(test, Calendar.class, cal, "2010-09-03T12:34:05.000+02:00[Europe/Paris]"); GregorianCalendar cal2 = new GregorianCalendar(TimeZone.getTimeZone("Europe/Paris")); cal2.set(2011, 1 - 1, 4, 12, 34, 5); cal2.set(Calendar.MILLISECOND, 0); doTest(test, Calendar.class, cal2, "2011-01-04T12:34:05.000+01:00[Europe/Paris]"); } @Test(expected=RuntimeException.class) public void test_Calendar_invalidLength() { JDKStringConverter.CALENDAR.convertFromString(GregorianCalendar.class, "2010-09-03"); } @Test(expected=RuntimeException.class) public void test_Calendar_invalidFormat() { JDKStringConverter.CALENDAR.convertFromString(GregorianCalendar.class, "2010-09-03XXX:34:05.000+02:00[Europe/London]"); } @Test(expected=RuntimeException.class) public void test_Calendar_notGregorian() { JDKStringConverter.CALENDAR.convertToString(new Calendar() { private static final long serialVersionUID = 1L; @Override public void roll(int field, boolean up) { } @Override public int getMinimum(int field) { return 0; } @Override public int getMaximum(int field) { return 0; } @Override public int getLeastMaximum(int field) { return 0; } @Override public int getGreatestMinimum(int field) { return 0; } @Override protected void computeTime() { } @Override protected void computeFields() { } @Override public void add(int field, int amount) { } }); } @Test public void test_Enum() { JDKStringConverter test = JDKStringConverter.ENUM; assertEquals(Enum.class, test.getType()); assertEquals("CEILING", test.convertToString(RoundingMode.CEILING)); assertEquals(RoundingMode.CEILING, test.convertFromString(RoundingMode.class, "CEILING")); } @Test(expected=RuntimeException.class) public void test_Enum_invalidConstant() { JDKStringConverter.ENUM.convertFromString(RoundingMode.class, "RUBBISH"); } //----------------------------------------------------------------------- public void doTest(JDKStringConverter test, Class cls, Object obj, String str) { doTest(test, cls, obj, str, obj); } public void doTest(JDKStringConverter test, Class cls, Object obj, String str, Object objFromStr) { assertEquals(cls, test.getType()); assertEquals(str, test.convertToString(obj)); assertEquals(objFromStr, test.convertFromString(cls, str)); } } joda-convert-1.5/src/test/java/org/joda/convert/DistanceMethodConstructor.java0000644000175000017500000000241112215577750027172 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class with annotated constructor and method. */ public class DistanceMethodConstructor { /** Amount. */ final int amount; public DistanceMethodConstructor(int amount) { this.amount = amount; } @FromString public DistanceMethodConstructor(String amount) { amount = amount.substring(0, amount.length() - 1); this.amount = Integer.parseInt(amount); } @ToString public String print() { return amount + "m"; } @Override public String toString() { return "Distance[" + amount + "m]"; } } joda-convert-1.5/src/test/java/org/joda/convert/SuperFactorySub.java0000644000175000017500000000160212215577750025132 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class which matches the case where a superclass acts as the sole factory. */ public class SuperFactorySub extends SuperFactorySuper { public SuperFactorySub(int amount) { super(amount); } } joda-convert-1.5/src/test/java/org/joda/convert/DistanceTwoFromStringMethodAnnotations.java0000644000175000017500000000341012215577750031647 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class with no annotations. */ public class DistanceTwoFromStringMethodAnnotations { /** Amount. */ final int amount; public DistanceTwoFromStringMethodAnnotations(int amount) { this.amount = amount; } @FromString public static DistanceTwoFromStringMethodAnnotations parse(String amount) { amount = amount.substring(0, amount.length() - 1); return new DistanceTwoFromStringMethodAnnotations(Integer.parseInt(amount)); } @FromString public static DistanceTwoFromStringMethodAnnotations parse2(String amount) { amount = amount.substring(0, amount.length() - 1); return new DistanceTwoFromStringMethodAnnotations(Integer.parseInt(amount)); } public DistanceTwoFromStringMethodAnnotations(String amount) { amount = amount.substring(0, amount.length() - 1); this.amount = Integer.parseInt(amount); } @ToString public String print() { return amount + "m"; } @Override public String toString() { return "Distance[" + amount + "m]"; } } joda-convert-1.5/src/test/java/org/joda/convert/DistanceToStringNoFromString.java0000644000175000017500000000235712215577750027576 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class with no annotations. */ public class DistanceToStringNoFromString { /** Amount. */ final int amount; public DistanceToStringNoFromString(int amount) { this.amount = amount; } public DistanceToStringNoFromString(String amount) { amount = amount.substring(0, amount.length() - 1); this.amount = Integer.parseInt(amount); } @ToString public String print() { return amount + "m"; } @Override public String toString() { return "Distance[" + amount + "m]"; } } joda-convert-1.5/src/test/java/org/joda/convert/DistanceMethodMethodCharSequence.java0000644000175000017500000000251512215600005030335 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class with annotated methods. */ public class DistanceMethodMethodCharSequence { /** Amount. */ final int amount; @FromString public static DistanceMethodMethodCharSequence parse(CharSequence amount) { String amt = amount.toString().substring(0, amount.length() - 1); return new DistanceMethodMethodCharSequence(Integer.parseInt(amt)); } public DistanceMethodMethodCharSequence(int amount) { this.amount = amount; } @ToString public String print() { return amount + "m"; } @Override public String toString() { return "Distance[" + amount + "m]"; } } joda-convert-1.5/src/test/java/org/joda/convert/MockDistanceStringConverter.java0000644000175000017500000000315712215577750027464 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Conversion between an {@code DistanceMethodMethod} and a {@code String}. */ public enum MockDistanceStringConverter implements StringConverter { /** Singleton instance. */ INSTANCE; /** * Converts the {@code DistanceMethodMethod} to a {@code String}. * @param object the object to convert, not null * @return the converted string, may be null but generally not */ public String convertToString(DistanceMethodMethod object) { return object.print(); } /** * Converts the {@code String} to an {@code DistanceMethodMethod}. * @param cls the class to convert to, not null * @param str the string to convert, not null * @return the converted integer, may be null but generally not */ public DistanceMethodMethod convertFromString(Class cls, String str) { return DistanceMethodMethod.parse(str); } } joda-convert-1.5/src/test/java/org/joda/convert/DistanceNoAnnotations.java0000644000175000017500000000250712215600005026260 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class with no annotations. */ public class DistanceNoAnnotations { /** Amount. */ final int amount; public static DistanceNoAnnotations parse(String amount) { return new DistanceNoAnnotations(amount); } public DistanceNoAnnotations(int amount) { this.amount = amount; } public DistanceNoAnnotations(String amount) { amount = amount.substring(0, amount.length() - 1); this.amount = Integer.parseInt(amount); } public String print() { return amount + "m"; } @Override public String toString() { return "Distance[" + amount + "m]"; } } joda-convert-1.5/src/test/java/org/joda/convert/DistanceToStringInvalidReturnType.java0000644000175000017500000000241712215577750030634 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class with no annotations. */ public class DistanceToStringInvalidReturnType { /** Amount. */ final int amount; public DistanceToStringInvalidReturnType(int amount) { this.amount = amount; } @FromString public DistanceToStringInvalidReturnType(String amount) { amount = amount.substring(0, amount.length() - 1); this.amount = Integer.parseInt(amount); } @ToString public Object print() { return amount + "m"; } @Override public String toString() { return "Distance[" + amount + "m]"; } } joda-convert-1.5/src/test/java/org/joda/convert/DistanceFromStringInvalidParameter.java0000644000175000017500000000231012215577750030744 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class with no annotations. */ public class DistanceFromStringInvalidParameter { /** Amount. */ final int amount; @FromString public static DistanceFromStringInvalidParameter parse(Object amount) { return null; } public DistanceFromStringInvalidParameter(int amount) { this.amount = amount; } @ToString public String print() { return amount + "m"; } @Override public String toString() { return "Distance[" + amount + "m]"; } } joda-convert-1.5/src/test/java/org/joda/convert/TestByteObjectArrayStringConverterFactory.java0000644000175000017500000000324612216065551032330 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.Arrays; import org.joda.convert.factory.ByteObjectArrayStringConverterFactory; import org.junit.Test; /** * Test ByteObjectArrayStringConverterFactory. */ public class TestByteObjectArrayStringConverterFactory { @Test public void test_ByteArray() { doTest(new Byte[0], ""); doTest(new Byte[] {(byte) 0}, "00"); doTest(new Byte[] {null}, "--"); doTest(new Byte[] {(byte) 0, (byte) 1, null, null, (byte) 15, (byte) 16, (byte) 127, (byte) -128, (byte) -1}, "0001----0F107F80FF"); } private void doTest(Byte[] array, String str) { StringConvert test = new StringConvert(true, ByteObjectArrayStringConverterFactory.INSTANCE); assertEquals(str, test.convertToString(array)); assertEquals(str, test.convertToString(Byte[].class, array)); assertTrue(Arrays.equals(array, test.convertFromString(Byte[].class, str))); } } joda-convert-1.5/src/test/java/org/joda/convert/test2/0000755000175000017500000000000012216415242022215 5ustar ebourgebourgjoda-convert-1.5/src/test/java/org/joda/convert/test2/Test2Factory.java0000644000175000017500000000174012215600015025404 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert.test2; import org.joda.convert.FromString; /** * Example class with annotated methods. */ public class Test2Factory { @FromString public static Test2Class parse(String amount) { amount = amount.substring(0, amount.length() - 1); return new Test2Class(Integer.parseInt(amount)); } } joda-convert-1.5/src/test/java/org/joda/convert/test2/Test2Interface.java0000644000175000017500000000164712215600015025703 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert.test2; import org.joda.convert.FromStringFactory; import org.joda.convert.ToString; /** * Example interface with annotated methods. */ @FromStringFactory(factory = Test2Factory.class) public interface Test2Interface { @ToString String print(); } joda-convert-1.5/src/test/java/org/joda/convert/test2/Test2Class.java0000644000175000017500000000206412215600015025042 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert.test2; /** * Example class with annotated methods. */ public class Test2Class implements Test2Interface { /** Amount. */ public final int amount; public Test2Class(int amount) { this.amount = amount; } public String print() { return amount + "g"; } @Override public String toString() { return "Weight[" + amount + "g]"; } } joda-convert-1.5/src/test/java/org/joda/convert/MockIntegerStringConverter.java0000644000175000017500000000300712215577750027321 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Conversion between an {@code Integer} and a {@code String}. */ public enum MockIntegerStringConverter implements StringConverter { /** Singleton instance. */ INSTANCE; /** * Converts the {@code Integer} to a {@code String}. * @param object the object to convert, not null * @return the converted string, may be null but generally not */ public String convertToString(Integer object) { return object.toString(); } /** * Converts the {@code String} to an {@code Integer}. * @param cls the class to convert to, not null * @param str the string to convert, not null * @return the converted integer, may be null but generally not */ public Integer convertFromString(Class cls, String str) { return new Integer(str); } } joda-convert-1.5/src/test/java/org/joda/convert/TestNumericObjectArrayStringConverterFactory.java0000644000175000017500000001221012216065551033016 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.Arrays; import org.joda.convert.factory.NumericObjectArrayStringConverterFactory; import org.junit.Test; /** * Test NumericObjectArrayStringConverterFactory. */ public class TestNumericObjectArrayStringConverterFactory { @Test public void test_LongArray() { doTest(new Long[0], ""); doTest(new Long[] {5L}, "5"); doTest(new Long[] {null}, "-"); doTest(new Long[] {-1234L, null, 56789L, null, null, 5L}, "-1234,-,56789,-,-,5"); doTest(new Long[] {12345678912345L, 12345678912345L}, "12345678912345,12345678912345"); } private void doTest(Long[] array, String str) { StringConvert test = new StringConvert(true, NumericObjectArrayStringConverterFactory.INSTANCE); assertEquals(str, test.convertToString(array)); assertEquals(str, test.convertToString(Long[].class, array)); assertTrue(Arrays.equals(array, test.convertFromString(Long[].class, str))); } //----------------------------------------------------------------------- @Test public void test_IntegerArray() { doTest(new Integer[0], ""); doTest(new Integer[] {5}, "5"); doTest(new Integer[] {null}, "-"); doTest(new Integer[] {-1234, null, 56789, null, null, 5}, "-1234,-,56789,-,-,5"); } private void doTest(Integer[] array, String str) { StringConvert test = new StringConvert(true, NumericObjectArrayStringConverterFactory.INSTANCE); assertEquals(str, test.convertToString(array)); assertEquals(str, test.convertToString(Integer[].class, array)); assertTrue(Arrays.equals(array, test.convertFromString(Integer[].class, str))); } //----------------------------------------------------------------------- @Test public void test_ShortArray() { doTest(new Short[0], ""); doTest(new Short[] {5}, "5"); doTest(new Short[] {null}, "-"); doTest(new Short[] {-1234, null, 5678, null, null, 5}, "-1234,-,5678,-,-,5"); } private void doTest(Short[] array, String str) { StringConvert test = new StringConvert(true, NumericObjectArrayStringConverterFactory.INSTANCE); assertEquals(str, test.convertToString(array)); assertEquals(str, test.convertToString(Short[].class, array)); assertTrue(Arrays.equals(array, test.convertFromString(Short[].class, str))); } //----------------------------------------------------------------------- @Test public void test_DoubleArray() { doTest(new Double[0], ""); doTest(new Double[] {5d}, "5.0"); doTest(new Double[] {null}, "-"); doTest(new Double[] {5.123456789d}, "5.123456789"); doTest(new Double[] {-1234d, null, 5678d, null, null, 5d}, "-1234.0,-,5678.0,-,-,5.0"); doTest(new Double[] {Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, -0.0d, +0.0d, 0d}, "NaN,-Infinity,Infinity,-0.0,0.0,0.0"); doTest(new Double[] {0.0000006d, 6000000000d}, "6.0E-7,6.0E9"); } private void doTest(Double[] array, String str) { StringConvert test = new StringConvert(true, NumericObjectArrayStringConverterFactory.INSTANCE); assertEquals(str, test.convertToString(array)); assertEquals(str, test.convertToString(Double[].class, array)); assertTrue(Arrays.equals(array, test.convertFromString(Double[].class, str))); } //----------------------------------------------------------------------- @Test public void test_FloatArray() { doTest(new Float[0], ""); doTest(new Float[] {5f}, "5.0"); doTest(new Float[] {null}, "-"); doTest(new Float[] {5.1234f}, "5.1234"); doTest(new Float[] {-1234f, null, 5678f, null, null, 5f}, "-1234.0,-,5678.0,-,-,5.0"); doTest(new Float[] {Float.NaN, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, -0.0f, +0.0f, 0f}, "NaN,-Infinity,Infinity,-0.0,0.0,0.0"); doTest(new Float[] {0.0000006f, 6000000000f}, "6.0E-7,6.0E9"); } private void doTest(Float[] array, String str) { StringConvert test = new StringConvert(true, NumericObjectArrayStringConverterFactory.INSTANCE); assertEquals(str, test.convertToString(array)); assertEquals(str, test.convertToString(Float[].class, array)); assertTrue(Arrays.equals(array, test.convertFromString(Float[].class, str))); } } joda-convert-1.5/src/test/java/org/joda/convert/SubMethodMethod.java0000644000175000017500000000205012215577750025063 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class with annotated methods. */ public class SubMethodMethod extends DistanceMethodMethod { @FromString public static SubMethodMethod parse(String amount) { amount = amount.substring(0, amount.length() - 1); return new SubMethodMethod(Integer.parseInt(amount)); } public SubMethodMethod(int amount) { super(amount); } } joda-convert-1.5/src/test/java/org/joda/convert/DistanceMethodConstructorCharSequence.java0000644000175000017500000000247712215600004031450 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class with annotated constructor and method. */ public class DistanceMethodConstructorCharSequence { /** Amount. */ final int amount; public DistanceMethodConstructorCharSequence(int amount) { this.amount = amount; } @FromString public DistanceMethodConstructorCharSequence(CharSequence amount) { String amt = amount.toString().substring(0, amount.length() - 1); this.amount = Integer.parseInt(amt); } @ToString public String print() { return amount + "m"; } @Override public String toString() { return "Distance[" + amount + "m]"; } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootjoda-convert-1.5/src/test/java/org/joda/convert/DistanceFromStringConstructorInvalidParameterCount.javajoda-convert-1.5/src/test/java/org/joda/convert/DistanceFromStringConstructorInvalidParameterCount.j0000644000175000017500000000237212215577750033543 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class with no annotations. */ public class DistanceFromStringConstructorInvalidParameterCount { /** Amount. */ final int amount; @FromString public DistanceFromStringConstructorInvalidParameterCount(String amount, int value) { this.amount = 0; } public DistanceFromStringConstructorInvalidParameterCount(int amount) { this.amount = amount; } @ToString public String print() { return amount + "m"; } @Override public String toString() { return "Distance[" + amount + "m]"; } } joda-convert-1.5/src/test/java/org/joda/convert/DistanceToStringInvalidParameters.java0000644000175000017500000000242612215577750030616 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class with no annotations. */ public class DistanceToStringInvalidParameters { /** Amount. */ final int amount; public DistanceToStringInvalidParameters(int amount) { this.amount = amount; } @FromString public DistanceToStringInvalidParameters(String amount) { amount = amount.substring(0, amount.length() - 1); this.amount = Integer.parseInt(amount); } @ToString public Object print(int num) { return amount + "m"; } @Override public String toString() { return "Distance[" + amount + "m]"; } } joda-convert-1.5/src/test/java/org/joda/convert/SuperFactorySuper.java0000644000175000017500000000254112215577750025502 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Example class which matches the case where a superclass acts as the sole factory. */ public class SuperFactorySuper { /** Amount. */ final int amount; @FromString public static SuperFactorySuper parse(String amount) { amount = amount.substring(0, amount.length() - 1); int i = Integer.parseInt(amount); return i > 10 ? new SuperFactorySuper(i) : new SuperFactorySub(i); } public SuperFactorySuper(int amount) { this.amount = amount; } @ToString public String print() { return amount + "m"; } @Override public String toString() { return "Distance[" + amount + "m]"; } } joda-convert-1.5/src/changes/0000755000175000017500000000000012216415242015500 5ustar ebourgebourgjoda-convert-1.5/src/changes/changes.xml0000644000175000017500000000767312216065552017654 0ustar ebourgebourg Java convert - Changes Stephen Colebourne Add support for all primitive object arrays. Add support for boolean[]. Add support for numeric primitive arrays. Add support for char[] and byte[]. Add StringConverterFactory for more flexible initialization. Weaken generics to better support framework-level access. Add isConvertible() method. Validate the @FromString is a static method. Change to use Maven plugin for OSGi, changing some published info. Home page at GitHub. Add support for FromString using a factory. Issue #5. Change to use m2e Maven Eclipse. Fix OSGI manifest. Add register method designed for JDK 1.8 method references or lambdas. Change to requiring JDK 1.6. Add alternate package locations for JSR-310 classes. Add support for CharSequence based fromString methods. Add support for JSR-310 by reflection, avoiding a dependency. Allow registration of conversions by method name. Allow toString conversion to specify the desired type. Allow conversion of primitive types. Allow conversion of primitive types Enable superclass factories. Lots of tests and fixes. Initial checkin. joda-convert-1.5/src/main/0000755000175000017500000000000012202714763015021 5ustar ebourgebourgjoda-convert-1.5/src/main/checkstyle/0000755000175000017500000000000012216415242017152 5ustar ebourgebourgjoda-convert-1.5/src/main/checkstyle/checkstyle.xml0000644000175000017500000001373512215600074022041 0ustar ebourgebourg joda-convert-1.5/src/main/assembly/0000755000175000017500000000000012216415242016633 5ustar ebourgebourgjoda-convert-1.5/src/main/assembly/dist.xml0000644000175000017500000000154112202714763020326 0ustar ebourgebourg dist tar.gz zip ${artifactId}-${version} checkstyle.xml LICENSE.txt NOTICE.txt pom.xml RELEASE-NOTES.txt src target *.jar joda-convert-1.5/src/main/java/0000755000175000017500000000000012202714763015742 5ustar ebourgebourgjoda-convert-1.5/src/main/java/org/0000755000175000017500000000000012202714763016531 5ustar ebourgebourgjoda-convert-1.5/src/main/java/org/joda/0000755000175000017500000000000012202714763017446 5ustar ebourgebourgjoda-convert-1.5/src/main/java/org/joda/convert/0000755000175000017500000000000012216415242021121 5ustar ebourgebourgjoda-convert-1.5/src/main/java/org/joda/convert/ToStringConverter.java0000644000175000017500000000225712215577720025444 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Interface defining conversion to a {@code String}. *

* ToStringConverter is an interface and must be implemented with care. * Implementations must be immutable and thread-safe. * * @param the type of the converter */ public interface ToStringConverter { /** * Converts the specified object to a {@code String}. * @param object the object to convert, not null * @return the converted string, may be null but generally not */ String convertToString(T object); } joda-convert-1.5/src/main/java/org/joda/convert/ReflectionStringConverter.java0000644000175000017500000000575012215577701027154 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; /** * Conversion to and from a string using reflection. *

* The toString method must meet the following signature:
* {@code String anyName()} on Class T. *

* ReflectionStringConverter is abstract, but all known implementations are thread-safe and immutable. * * @param the type of the converter */ abstract class ReflectionStringConverter implements StringConverter { /** The converted class. */ private final Class cls; /** Conversion to a string. */ private final Method toString; /** * Creates an instance using two methods. * @param cls the class this converts for, not null * @param toString the toString method, not null * @throws RuntimeException (or subclass) if the method signatures are invalid */ ReflectionStringConverter(Class cls, Method toString) { if (toString.getParameterTypes().length != 0) { throw new IllegalStateException("ToString method must have no parameters: " + toString); } if (toString.getReturnType() != String.class) { throw new IllegalStateException("ToString method must return a String: " + toString); } this.cls = cls; this.toString = toString; } //----------------------------------------------------------------------- /** * Converts the object to a {@code String}. * @param object the object to convert, not null * @return the converted string, may be null but generally not */ public String convertToString(T object) { try { return (String) toString.invoke(object); } catch (IllegalAccessException ex) { throw new IllegalStateException("Method is not accessible: " + toString); } catch (InvocationTargetException ex) { if (ex.getCause() instanceof RuntimeException) { throw (RuntimeException) ex.getCause(); } throw new RuntimeException(ex.getMessage(), ex.getCause()); } } //----------------------------------------------------------------------- @Override public String toString() { return "RefectionStringConverter[" + cls.getSimpleName() + "]"; } } joda-convert-1.5/src/main/java/org/joda/convert/FromString.java0000644000175000017500000000275212215577654024103 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Annotation used to mark a method or constructor as being suitable for converting * an object from a {@code String}. *

* When applying to a method, this annotation should be applied once per class. * The method must be static and have one {@code String} parameter with a * return type of the type that the method is implemented on. * For example, {@link Integer#parseInt(String)}. *

* When applying to a constructor, this annotation should be applied to the constructor * that takes one {@code String} parameter. */ @Target({ElementType.METHOD, ElementType.CONSTRUCTOR }) @Retention(RetentionPolicy.RUNTIME) public @interface FromString { } joda-convert-1.5/src/main/java/org/joda/convert/MethodConstructorStringConverter.java0000644000175000017500000000650012215577672030551 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; /** * Conversion to and from a string using a toString method and a fromString constructor. *

* The toString method must meet the following signature:
* {@code String anyName()} on Class T. *

* The fromString constructor must take a single {@code String} parameter. *

* MethodConstructorStringConverter is thread-safe and immutable. * * @param the type of the converter */ final class MethodConstructorStringConverter extends ReflectionStringConverter { /** Conversion from a string. */ private final Constructor fromString; /** * Creates an instance using a method and a constructor. * @param cls the class this converts for, not null * @param toString the toString method, not null * @param fromString the fromString method, not null * @throws RuntimeException (or subclass) if the method signatures are invalid */ MethodConstructorStringConverter(Class cls, Method toString, Constructor fromString) { super(cls, toString); if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers()) || cls.isLocalClass() || cls.isMemberClass()) { throw new IllegalArgumentException("FromString constructor must be on an instantiable class: " + fromString); } if (fromString.getDeclaringClass() != cls) { throw new IllegalStateException("FromString constructor must be defined on specified class: " + fromString); } this.fromString = fromString; } //----------------------------------------------------------------------- /** * Converts the {@code String} to an object. * @param cls the class to convert to, not null * @param str the string to convert, not null * @return the converted object, may be null but generally not */ public T convertFromString(Class cls, String str) { try { return fromString.newInstance(str); } catch (IllegalAccessException ex) { throw new IllegalStateException("Constructor is not accessible: " + fromString); } catch (InstantiationException ex) { throw new IllegalStateException("Constructor is not valid: " + fromString); } catch (InvocationTargetException ex) { if (ex.getCause() instanceof RuntimeException) { throw (RuntimeException) ex.getCause(); } throw new RuntimeException(ex.getMessage(), ex.getCause()); } } } joda-convert-1.5/src/main/java/org/joda/convert/FromStringConverter.java0000644000175000017500000000240112215577657025765 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Interface defining conversion from a {@code String}. *

* FromStringConverter is an interface and must be implemented with care. * Implementations must be immutable and thread-safe. * * @param the type of the converter */ public interface FromStringConverter { /** * Converts the specified object from a {@code String}. * @param cls the class to convert to, not null * @param str the string to convert, not null * @return the converted object, may be null but generally not */ T convertFromString(Class cls, String str); } joda-convert-1.5/src/main/java/org/joda/convert/AnnotationStringConverterFactory.java0000644000175000017500000002060012215626470030511 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; import java.lang.reflect.Constructor; import java.lang.reflect.Method; /** * Factory for {@code StringConverter} looking up annotations. *

* This class is immutable and thread-safe. * * @since 1.5 */ final class AnnotationStringConverterFactory implements StringConverterFactory { /** * Singleton instance. */ static final StringConverterFactory INSTANCE = new AnnotationStringConverterFactory(); /** * Restricted constructor. */ private AnnotationStringConverterFactory() { } //----------------------------------------------------------------------- /** * Finds a converter by type. * * @param cls the type to lookup, not null * @return the converter, null if not found * @throws RuntimeException (or subclass) if source code is invalid */ public StringConverter findConverter(Class cls) { return findAnnotatedConverter(cls); // capture generics } /** * Finds a converter searching annotated. * * @param the type of the converter * @param cls the class to find a method for, not null * @return the converter, not null * @throws RuntimeException if none found */ private StringConverter findAnnotatedConverter(final Class cls) { Method toString = findToStringMethod(cls); // checks superclasses if (toString == null) { return null; } Constructor con = findFromStringConstructor(cls); Method fromString = findFromStringMethod(cls, con == null); // optionally checks superclasses if (con == null && fromString == null) { throw new IllegalStateException("Class annotated with @ToString but not with @FromString: " + cls.getName()); } if (con != null && fromString != null) { throw new IllegalStateException("Both method and constructor are annotated with @FromString: " + cls.getName()); } if (con != null) { return new MethodConstructorStringConverter(cls, toString, con); } else { return new MethodsStringConverter(cls, toString, fromString); } } /** * Finds the conversion method. * * @param cls the class to find a method for, not null * @return the method to call, null means use {@code toString} * @throws RuntimeException if invalid */ private Method findToStringMethod(Class cls) { Method matched = null; // find in superclass hierarchy Class loopCls = cls; while (loopCls != null && matched == null) { Method[] methods = loopCls.getDeclaredMethods(); for (Method method : methods) { ToString toString = method.getAnnotation(ToString.class); if (toString != null) { if (matched != null) { throw new IllegalStateException("Two methods are annotated with @ToString: " + cls.getName()); } matched = method; } } loopCls = loopCls.getSuperclass(); } // find in immediate parent interfaces if (matched == null) { for (Class loopIfc : cls.getInterfaces()) { Method[] methods = loopIfc.getDeclaredMethods(); for (Method method : methods) { ToString toString = method.getAnnotation(ToString.class); if (toString != null) { if (matched != null) { throw new IllegalStateException("Two methods are annotated with @ToString on interfaces: " + cls.getName()); } matched = method; } } } } return matched; } /** * Finds the conversion method. * * @param the type of the converter * @param cls the class to find a method for, not null * @return the method to call, null means use {@code toString} * @throws RuntimeException if invalid */ private Constructor findFromStringConstructor(Class cls) { Constructor con; try { con = cls.getDeclaredConstructor(String.class); } catch (NoSuchMethodException ex) { try { con = cls.getDeclaredConstructor(CharSequence.class); } catch (NoSuchMethodException ex2) { return null; } } FromString fromString = con.getAnnotation(FromString.class); return fromString != null ? con : null; } /** * Finds the conversion method. * * @param cls the class to find a method for, not null * @return the method to call, null means not found * @throws RuntimeException if invalid */ private Method findFromStringMethod(Class cls, boolean searchSuperclasses) { Method matched = null; // find in superclass hierarchy Class loopCls = cls; while (loopCls != null && matched == null) { matched = findFromString(loopCls, matched); if (searchSuperclasses == false) { break; } loopCls = loopCls.getSuperclass(); } // find in immediate parent interfaces if (searchSuperclasses && matched == null) { for (Class loopIfc : cls.getInterfaces()) { matched = findFromString(loopIfc, matched); } } return matched; } /** * Finds the conversion method. * * @param cls the class to find a method for, not null * @param matched the matched method, may be null * @return the method to call, null means not found * @throws RuntimeException if invalid */ private Method findFromString(Class cls, Method matched) { // find in declared methods Method[] methods = cls.getDeclaredMethods(); for (Method method : methods) { FromString fromString = method.getAnnotation(FromString.class); if (fromString != null) { if (matched != null) { throw new IllegalStateException("Two methods are annotated with @FromString: " + cls.getName()); } matched = method; } } // check for factory FromStringFactory factory = cls.getAnnotation(FromStringFactory.class); if (factory != null) { if (matched != null) { throw new IllegalStateException("Class annotated with @FromString and @FromStringFactory: " + cls.getName()); } Method[] factoryMethods = factory.factory().getDeclaredMethods(); for (Method method : factoryMethods) { // handle factory containing multiple FromString for different types if (cls.isAssignableFrom(method.getReturnType())) { FromString fromString = method.getAnnotation(FromString.class); if (fromString != null) { if (matched != null) { throw new IllegalStateException("Two methods are annotated with @FromString on the factory: " + factory.factory().getName()); } matched = method; } } } } return matched; } //----------------------------------------------------------------------- @Override public String toString() { return getClass().getSimpleName(); } } joda-convert-1.5/src/main/java/org/joda/convert/factory/0000755000175000017500000000000012216415242022570 5ustar ebourgebourgjoda-convert-1.5/src/main/java/org/joda/convert/factory/NumericArrayStringConverterFactory.java0000644000175000017500000002136212216065551032453 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert.factory; import java.util.regex.Pattern; import org.joda.convert.StringConverter; import org.joda.convert.StringConverterFactory; /** * Factory for {@code StringConverter} providing support for primitive arrays * as a comma separated list. *

* To use, simply register the instance with a {@code StringConvert} instance. *

* This class is immutable and thread-safe. * * @since 1.5 */ public final class NumericArrayStringConverterFactory implements StringConverterFactory { /** * Singleton instance. */ public static final StringConverterFactory INSTANCE = new NumericArrayStringConverterFactory(); /** * Delimiter to find. */ static final Pattern DELIMITER = Pattern.compile("[,]"); /** * Restricted constructor. */ private NumericArrayStringConverterFactory() { } //----------------------------------------------------------------------- /** * Finds a converter by type. * * @param cls the type to lookup, not null * @return the converter, null if not found * @throws RuntimeException (or subclass) if source code is invalid */ public StringConverter findConverter(Class cls) { if (cls.isArray() && cls.getComponentType().isPrimitive()) { if (cls == long[].class) { return LongArrayStringConverter.INSTANCE; } if (cls == int[].class) { return IntArrayStringConverter.INSTANCE; } if (cls == short[].class) { return ShortArrayStringConverter.INSTANCE; } if (cls == double[].class) { return DoubleArrayStringConverter.INSTANCE; } if (cls == float[].class) { return FloatArrayStringConverter.INSTANCE; } } return null; } //----------------------------------------------------------------------- @Override public String toString() { return getClass().getSimpleName(); } //----------------------------------------------------------------------- enum LongArrayStringConverter implements StringConverter { INSTANCE { @Override public String convertToString(long[] array) { if (array.length == 0) { return ""; } StringBuilder buf = new StringBuilder(array.length * 8); buf.append(array[0]); for (int i = 1; i < array.length; i++) { buf.append(',').append(array[i]); } return buf.toString(); } @Override public long[] convertFromString(Class cls, String str) { if (str.length() == 0) { return EMPTY; } String[] split = DELIMITER.split(str); long[] array = new long[split.length]; for (int i = 0; i < split.length; i++) { array[i] = Long.parseLong(split[i]); } return array; } }; private static final long[] EMPTY = new long[0]; } //----------------------------------------------------------------------- enum IntArrayStringConverter implements StringConverter { INSTANCE { @Override public String convertToString(int[] array) { if (array.length == 0) { return ""; } StringBuilder buf = new StringBuilder(array.length * 6); buf.append(array[0]); for (int i = 1; i < array.length; i++) { buf.append(',').append(array[i]); } return buf.toString(); } @Override public int[] convertFromString(Class cls, String str) { if (str.length() == 0) { return EMPTY; } String[] split = DELIMITER.split(str); int[] array = new int[split.length]; for (int i = 0; i < split.length; i++) { array[i] = Integer.parseInt(split[i]); } return array; } }; private static final int[] EMPTY = new int[0]; } //----------------------------------------------------------------------- enum ShortArrayStringConverter implements StringConverter { INSTANCE { @Override public String convertToString(short[] array) { if (array.length == 0) { return ""; } StringBuilder buf = new StringBuilder(array.length * 3); buf.append(array[0]); for (int i = 1; i < array.length; i++) { buf.append(',').append(array[i]); } return buf.toString(); } @Override public short[] convertFromString(Class cls, String str) { if (str.length() == 0) { return EMPTY; } String[] split = DELIMITER.split(str); short[] array = new short[split.length]; for (int i = 0; i < split.length; i++) { array[i] = Short.parseShort(split[i]); } return array; } }; private static final short[] EMPTY = new short[0]; } //----------------------------------------------------------------------- enum DoubleArrayStringConverter implements StringConverter { INSTANCE { @Override public String convertToString(double[] array) { if (array.length == 0) { return ""; } StringBuilder buf = new StringBuilder(array.length * 8); buf.append(array[0]); for (int i = 1; i < array.length; i++) { buf.append(',').append(array[i]); } return buf.toString(); } @Override public double[] convertFromString(Class cls, String str) { if (str.length() == 0) { return EMPTY; } String[] split = DELIMITER.split(str); double[] array = new double[split.length]; for (int i = 0; i < split.length; i++) { array[i] = Double.parseDouble(split[i]); } return array; } }; private static final double[] EMPTY = new double[0]; } //----------------------------------------------------------------------- enum FloatArrayStringConverter implements StringConverter { INSTANCE { @Override public String convertToString(float[] array) { if (array.length == 0) { return ""; } StringBuilder buf = new StringBuilder(array.length * 8); buf.append(array[0]); for (int i = 1; i < array.length; i++) { buf.append(',').append(array[i]); } return buf.toString(); } @Override public float[] convertFromString(Class cls, String str) { if (str.length() == 0) { return EMPTY; } String[] split = DELIMITER.split(str); float[] array = new float[split.length]; for (int i = 0; i < split.length; i++) { array[i] = Float.parseFloat(split[i]); } return array; } }; private static final float[] EMPTY = new float[0]; } } joda-convert-1.5/src/main/java/org/joda/convert/factory/BooleanArrayStringConverterFactory.java0000644000175000017500000000712312216065551032427 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert.factory; import org.joda.convert.StringConverter; import org.joda.convert.StringConverterFactory; /** * Factory for {@code StringConverter} providing support for primitive boolean array * as a sequence of 'T' and 'F'. *

* This is intended as a human readable format, not a compact format. *

* To use, simply register the instance with a {@code StringConvert} instance. *

* This class is immutable and thread-safe. * * @since 1.5 */ public final class BooleanArrayStringConverterFactory implements StringConverterFactory { /** * Singleton instance. */ public static final StringConverterFactory INSTANCE = new BooleanArrayStringConverterFactory(); /** * Restricted constructor. */ private BooleanArrayStringConverterFactory() { } //----------------------------------------------------------------------- /** * Finds a converter by type. * * @param cls the type to lookup, not null * @return the converter, null if not found * @throws RuntimeException (or subclass) if source code is invalid */ public StringConverter findConverter(Class cls) { if (cls == boolean[].class) { return BooleanArrayStringConverter.INSTANCE; } return null; } //----------------------------------------------------------------------- @Override public String toString() { return getClass().getSimpleName(); } //----------------------------------------------------------------------- enum BooleanArrayStringConverter implements StringConverter { INSTANCE { @Override public String convertToString(boolean[] array) { if (array.length == 0) { return ""; } StringBuilder buf = new StringBuilder(array.length); for (int i = 0; i < array.length; i++) { buf.append(array[i] ? 'T' : 'F'); } return buf.toString(); } @Override public boolean[] convertFromString(Class cls, String str) { if (str.length() == 0) { return EMPTY; } boolean[] array = new boolean[str.length()]; for (int i = 0; i < array.length; i++) { char ch = str.charAt(i); if (ch == 'T') { array[i] = true; } else if (ch == 'F') { array[i] = false; } else { throw new IllegalArgumentException("Invalid boolean[] string, must consist only of 'T' and 'F'"); } } return array; } }; private static final boolean[] EMPTY = new boolean[0]; } } joda-convert-1.5/src/main/java/org/joda/convert/factory/ByteObjectArrayStringConverterFactory.java0000644000175000017500000000767112216065551033112 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert.factory; import org.joda.convert.StringConverter; import org.joda.convert.StringConverterFactory; /** * Factory for {@code StringConverter} providing support for Byte object array * as a sequence of two letter hex codes for each byte plus '--' for null. *

* This is intended as a human readable format, not a compact format. *

* To use, simply register the instance with a {@code StringConvert} instance. *

* This class is immutable and thread-safe. * * @since 1.5 */ public final class ByteObjectArrayStringConverterFactory implements StringConverterFactory { /** * Singleton instance. */ public static final StringConverterFactory INSTANCE = new ByteObjectArrayStringConverterFactory(); /** * Restricted constructor. */ private ByteObjectArrayStringConverterFactory() { } //----------------------------------------------------------------------- /** * Finds a converter by type. * * @param cls the type to lookup, not null * @return the converter, null if not found * @throws RuntimeException (or subclass) if source code is invalid */ public StringConverter findConverter(Class cls) { if (cls == Byte[].class) { return ByteArrayStringConverter.INSTANCE; } return null; } //----------------------------------------------------------------------- @Override public String toString() { return getClass().getSimpleName(); } //----------------------------------------------------------------------- enum ByteArrayStringConverter implements StringConverter { INSTANCE { @Override public String convertToString(Byte[] array) { if (array.length == 0) { return ""; } StringBuilder buf = new StringBuilder(array.length); for (int i = 0; i < array.length; i++) { if (array[i] == null) { buf.append('-').append('-'); } else { int b = array[i].byteValue(); buf.append(HEX.charAt((b & 0xF0) >>> 4)).append(HEX.charAt(b & 0x0F)); } } return buf.toString(); } @Override public Byte[] convertFromString(Class cls, String str) { if (str.length() == 0) { return EMPTY; } if (str.length() % 2 == 1) { throw new IllegalArgumentException("Invalid Byte[] string"); } Byte[] array = new Byte[str.length() / 2]; for (int i = 0; i < array.length; i++) { String in = str.substring(i * 2, i * 2 + 2); if (in.equals("--")) { array[i] = null; } else { array[i] = (byte) Integer.parseInt(in, 16); } } return array; } }; private static final Byte[] EMPTY = new Byte[0]; private static final String HEX = "0123456789ABCDEF"; } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootjoda-convert-1.5/src/main/java/org/joda/convert/factory/BooleanObjectArrayStringConverterFactory.javajoda-convert-1.5/src/main/java/org/joda/convert/factory/BooleanObjectArrayStringConverterFactory.jav0000644000175000017500000000740612216065551033421 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert.factory; import org.joda.convert.StringConverter; import org.joda.convert.StringConverterFactory; /** * Factory for {@code StringConverter} providing support for Boolean object array * as a sequence of 'T', 'F' and '-' for null. *

* This is intended as a human readable format, not a compact format. *

* To use, simply register the instance with a {@code StringConvert} instance. *

* This class is immutable and thread-safe. * * @since 1.5 */ public final class BooleanObjectArrayStringConverterFactory implements StringConverterFactory { /** * Singleton instance. */ public static final StringConverterFactory INSTANCE = new BooleanObjectArrayStringConverterFactory(); /** * Restricted constructor. */ private BooleanObjectArrayStringConverterFactory() { } //----------------------------------------------------------------------- /** * Finds a converter by type. * * @param cls the type to lookup, not null * @return the converter, null if not found * @throws RuntimeException (or subclass) if source code is invalid */ public StringConverter findConverter(Class cls) { if (cls == Boolean[].class) { return BooleanArrayStringConverter.INSTANCE; } return null; } //----------------------------------------------------------------------- @Override public String toString() { return getClass().getSimpleName(); } //----------------------------------------------------------------------- enum BooleanArrayStringConverter implements StringConverter { INSTANCE { @Override public String convertToString(Boolean[] array) { if (array.length == 0) { return ""; } StringBuilder buf = new StringBuilder(array.length); for (int i = 0; i < array.length; i++) { buf.append(array[i] == null ? '-' : (array[i].booleanValue() ? 'T' : 'F')); } return buf.toString(); } @Override public Boolean[] convertFromString(Class cls, String str) { if (str.length() == 0) { return EMPTY; } Boolean[] array = new Boolean[str.length()]; for (int i = 0; i < array.length; i++) { char ch = str.charAt(i); if (ch == 'T') { array[i] = Boolean.TRUE; } else if (ch == 'F') { array[i] = Boolean.FALSE; } else if (ch == '-') { array[i] = null; } else { throw new IllegalArgumentException("Invalid Boolean[] string, must consist only of 'T', 'F' and '-'"); } } return array; } }; private static final Boolean[] EMPTY = new Boolean[0]; } } joda-convert-1.5/src/main/java/org/joda/convert/factory/CharObjectArrayStringConverterFactory.java0000644000175000017500000001103312216065551033047 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert.factory; import java.util.Arrays; import java.util.regex.Pattern; import org.joda.convert.StringConverter; import org.joda.convert.StringConverterFactory; /** * Factory for {@code StringConverter} providing support for Character object arrays * as a string, using backslash as an escape. *

* Double backslash is a backslash. * One backslash followed by a dash is null. *

* To use, simply register the instance with a {@code StringConvert} instance. *

* This class is immutable and thread-safe. * * @since 1.5 */ public final class CharObjectArrayStringConverterFactory implements StringConverterFactory { /** * Singleton instance. */ public static final StringConverterFactory INSTANCE = new CharObjectArrayStringConverterFactory(); /** * Delimiter to find. */ static final Pattern DELIMITER = Pattern.compile("[,]"); /** * Restricted constructor. */ private CharObjectArrayStringConverterFactory() { } //----------------------------------------------------------------------- /** * Finds a converter by type. * * @param cls the type to lookup, not null * @return the converter, null if not found * @throws RuntimeException (or subclass) if source code is invalid */ public StringConverter findConverter(Class cls) { if (cls == Character[].class) { return CharecterArrayStringConverter.INSTANCE; } return null; } //----------------------------------------------------------------------- @Override public String toString() { return getClass().getSimpleName(); } //----------------------------------------------------------------------- enum CharecterArrayStringConverter implements StringConverter { INSTANCE { @Override public String convertToString(Character[] array) { if (array.length == 0) { return ""; } StringBuilder buf = new StringBuilder(array.length * 8); for (int i = 0; i < array.length; i++) { if (array[i] == null) { buf.append("\\-"); } else { char ch = array[i].charValue(); if (ch == '\\') { buf.append("\\\\"); } else { buf.append(ch); } } } return buf.toString(); } @Override public Character[] convertFromString(Class cls, String str) { if (str.length() == 0) { return EMPTY; } Character[] array = new Character[str.length()]; int arrayPos = 0; int pos; while ((pos = str.indexOf('\\')) >= 0) { for (int i = 0; i < pos; i++) { array[arrayPos++] = str.charAt(i); } if (str.charAt(pos + 1) == '\\') { array[arrayPos++] = '\\'; } else if (str.charAt(pos + 1) == '-') { array[arrayPos++] = null; } else { throw new IllegalArgumentException("Invalid Character[] string, incorrect escape"); } str = str.substring(pos + 2); } for (int i = 0; i < str.length(); i++) { array[arrayPos++] = str.charAt(i); } return Arrays.copyOf(array, arrayPos); } }; private static final Character[] EMPTY = new Character[0]; } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootjoda-convert-1.5/src/main/java/org/joda/convert/factory/NumericObjectArrayStringConverterFactory.javajoda-convert-1.5/src/main/java/org/joda/convert/factory/NumericObjectArrayStringConverterFactory.jav0000644000175000017500000002267412216065551033450 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert.factory; import java.util.regex.Pattern; import org.joda.convert.StringConverter; import org.joda.convert.StringConverterFactory; /** * Factory for {@code StringConverter} providing support for numeric object arrays * as a comma separated list, using '-' for null. *

* To use, simply register the instance with a {@code StringConvert} instance. *

* This class is immutable and thread-safe. * * @since 1.5 */ public final class NumericObjectArrayStringConverterFactory implements StringConverterFactory { /** * Singleton instance. */ public static final StringConverterFactory INSTANCE = new NumericObjectArrayStringConverterFactory(); /** * Delimiter to find. */ static final Pattern DELIMITER = Pattern.compile("[,]"); /** * Restricted constructor. */ private NumericObjectArrayStringConverterFactory() { } //----------------------------------------------------------------------- /** * Finds a converter by type. * * @param cls the type to lookup, not null * @return the converter, null if not found * @throws RuntimeException (or subclass) if source code is invalid */ public StringConverter findConverter(Class cls) { if (cls.isArray()) { if (cls == Long[].class) { return LongArrayStringConverter.INSTANCE; } if (cls == Integer[].class) { return IntArrayStringConverter.INSTANCE; } if (cls == Short[].class) { return ShortArrayStringConverter.INSTANCE; } if (cls == Double[].class) { return DoubleArrayStringConverter.INSTANCE; } if (cls == Float[].class) { return FloatArrayStringConverter.INSTANCE; } } return null; } //----------------------------------------------------------------------- @Override public String toString() { return getClass().getSimpleName(); } //----------------------------------------------------------------------- enum LongArrayStringConverter implements StringConverter { INSTANCE { @Override public String convertToString(Long[] array) { if (array.length == 0) { return ""; } StringBuilder buf = new StringBuilder(array.length * 8); buf.append(array[0] != null ? array[0] : "-"); for (int i = 1; i < array.length; i++) { buf.append(',').append(array[i] != null ? array[i] : "-"); } return buf.toString(); } @Override public Long[] convertFromString(Class cls, String str) { if (str.length() == 0) { return EMPTY; } String[] split = DELIMITER.split(str); Long[] array = new Long[split.length]; for (int i = 0; i < split.length; i++) { if (split[i].equals("-") == false) { array[i] = Long.parseLong(split[i]); } } return array; } }; private static final Long[] EMPTY = new Long[0]; } //----------------------------------------------------------------------- enum IntArrayStringConverter implements StringConverter { INSTANCE { @Override public String convertToString(Integer[] array) { if (array.length == 0) { return ""; } StringBuilder buf = new StringBuilder(array.length * 6); buf.append(array[0] != null ? array[0] : "-"); for (int i = 1; i < array.length; i++) { buf.append(',').append(array[i] != null ? array[i] : "-"); } return buf.toString(); } @Override public Integer[] convertFromString(Class cls, String str) { if (str.length() == 0) { return EMPTY; } String[] split = DELIMITER.split(str); Integer[] array = new Integer[split.length]; for (int i = 0; i < split.length; i++) { if (split[i].equals("-") == false) { array[i] = Integer.parseInt(split[i]); } } return array; } }; private static final Integer[] EMPTY = new Integer[0]; } //----------------------------------------------------------------------- enum ShortArrayStringConverter implements StringConverter { INSTANCE { @Override public String convertToString(Short[] array) { if (array.length == 0) { return ""; } StringBuilder buf = new StringBuilder(array.length * 3); buf.append(array[0] != null ? array[0] : "-"); for (int i = 1; i < array.length; i++) { buf.append(',').append(array[i] != null ? array[i] : "-"); } return buf.toString(); } @Override public Short[] convertFromString(Class cls, String str) { if (str.length() == 0) { return EMPTY; } String[] split = DELIMITER.split(str); Short[] array = new Short[split.length]; for (int i = 0; i < split.length; i++) { if (split[i].equals("-") == false) { array[i] = Short.parseShort(split[i]); } } return array; } }; private static final Short[] EMPTY = new Short[0]; } //----------------------------------------------------------------------- enum DoubleArrayStringConverter implements StringConverter { INSTANCE { @Override public String convertToString(Double[] array) { if (array.length == 0) { return ""; } StringBuilder buf = new StringBuilder(array.length * 8); buf.append(array[0] != null ? array[0] : "-"); for (int i = 1; i < array.length; i++) { buf.append(',').append(array[i] != null ? array[i] : "-"); } return buf.toString(); } @Override public Double[] convertFromString(Class cls, String str) { if (str.length() == 0) { return EMPTY; } String[] split = DELIMITER.split(str); Double[] array = new Double[split.length]; for (int i = 0; i < split.length; i++) { if (split[i].equals("-") == false) { array[i] = Double.parseDouble(split[i]); } } return array; } }; private static final Double[] EMPTY = new Double[0]; } //----------------------------------------------------------------------- enum FloatArrayStringConverter implements StringConverter { INSTANCE { @Override public String convertToString(Float[] array) { if (array.length == 0) { return ""; } StringBuilder buf = new StringBuilder(array.length * 8); buf.append(array[0] != null ? array[0] : "-"); for (int i = 1; i < array.length; i++) { buf.append(',').append(array[i] != null ? array[i] : "-"); } return buf.toString(); } @Override public Float[] convertFromString(Class cls, String str) { if (str.length() == 0) { return EMPTY; } String[] split = DELIMITER.split(str); Float[] array = new Float[split.length]; for (int i = 0; i < split.length; i++) { if (split[i].equals("-") == false) { array[i] = Float.parseFloat(split[i]); } } return array; } }; private static final Float[] EMPTY = new Float[0]; } } joda-convert-1.5/src/main/java/org/joda/convert/StringConvert.java0000644000175000017500000006653212216065551024613 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CopyOnWriteArrayList; import org.joda.convert.factory.BooleanArrayStringConverterFactory; import org.joda.convert.factory.BooleanObjectArrayStringConverterFactory; import org.joda.convert.factory.ByteObjectArrayStringConverterFactory; import org.joda.convert.factory.CharObjectArrayStringConverterFactory; import org.joda.convert.factory.NumericArrayStringConverterFactory; import org.joda.convert.factory.NumericObjectArrayStringConverterFactory; /** * Manager for conversion to and from a {@code String}, acting as the main client interface. *

* Support is provided for conversions based on the {@link StringConverter} interface * or the {@link ToString} and {@link FromString} annotations. *

* StringConvert is thread-safe with concurrent caches. */ public final class StringConvert { /** * An immutable global instance. *

* This instance cannot be added to using {@link #register}, however annotated classes * are picked up. To register your own converters, simply create an instance of this class. */ public static final StringConvert INSTANCE = new StringConvert(); /** * The cached null object. */ private static final StringConverter CACHED_NULL = new StringConverter() { @Override public String convertToString(Object object) { return null; } @Override public Object convertFromString(Class cls, String str) { return null; } }; /** * The list of factories. */ private final CopyOnWriteArrayList factories = new CopyOnWriteArrayList(); /** * The cache of converters. */ private final ConcurrentMap, StringConverter> registered = new ConcurrentHashMap, StringConverter>(); //----------------------------------------------------------------------- /** * Creates a new conversion manager including the extended standard set of converters. *

* The returned converter is a new instance that includes additional converters: *

    *
  • JDK converters *
  • {@link NumericArrayStringConverterFactory} *
  • {@link NumericObjectArrayStringConverterFactory} *
  • {@link CharObjectArrayStringConverterFactory} *
  • {@link ByteObjectArrayStringConverterFactory} *
  • {@link BooleanArrayStringConverterFactory} *
  • {@link BooleanObjectArrayStringConverterFactory} *
*

* The convert instance is mutable in a thread-safe manner. * Converters may be altered at any time, including the JDK converters. * It is strongly recommended to only alter the converters before performing * actual conversions. * * @return the new converter, not null * @since 1.5 */ public static StringConvert create() { return new StringConvert(true, NumericArrayStringConverterFactory.INSTANCE, NumericObjectArrayStringConverterFactory.INSTANCE, CharObjectArrayStringConverterFactory.INSTANCE, ByteObjectArrayStringConverterFactory.INSTANCE, BooleanArrayStringConverterFactory.INSTANCE, BooleanObjectArrayStringConverterFactory.INSTANCE); } //----------------------------------------------------------------------- /** * Creates a new conversion manager including the JDK converters. *

* The convert instance is mutable in a thread-safe manner. * Converters may be altered at any time, including the JDK converters. * It is strongly recommended to only alter the converters before performing * actual conversions. */ public StringConvert() { this(true); } /** * Creates a new conversion manager. *

* The convert instance is mutable in a thread-safe manner. * Converters may be altered at any time, including the JDK converters. * It is strongly recommended to only alter the converters before performing * actual conversions. *

* If specified, the factories will be queried in the order specified. * * @param includeJdkConverters true to include the JDK converters * @param factories optional array of factories to use, not null */ public StringConvert(boolean includeJdkConverters, StringConverterFactory... factories) { if (factories == null) { throw new IllegalArgumentException("StringConverterFactory array must not be null"); } for (int i = 0; i < factories.length; i++) { if (factories[i] == null) { throw new IllegalArgumentException("StringConverterFactory array must not contain a null element"); } } if (includeJdkConverters) { for (JDKStringConverter conv : JDKStringConverter.values()) { registered.put(conv.getType(), conv); } registered.put(Boolean.TYPE, JDKStringConverter.BOOLEAN); registered.put(Byte.TYPE, JDKStringConverter.BYTE); registered.put(Short.TYPE, JDKStringConverter.SHORT); registered.put(Integer.TYPE, JDKStringConverter.INTEGER); registered.put(Long.TYPE, JDKStringConverter.LONG); registered.put(Float.TYPE, JDKStringConverter.FLOAT); registered.put(Double.TYPE, JDKStringConverter.DOUBLE); registered.put(Character.TYPE, JDKStringConverter.CHARACTER); // JDK 1.8 classes tryRegister("java.time.Instant", "parse"); tryRegister("java.time.Duration", "parse"); tryRegister("java.time.LocalDate", "parse"); tryRegister("java.time.LocalTime", "parse"); tryRegister("java.time.LocalDateTime", "parse"); tryRegister("java.time.OffsetTime", "parse"); tryRegister("java.time.OffsetDateTime", "parse"); tryRegister("java.time.ZonedDateTime", "parse"); tryRegister("java.time.Year", "parse"); tryRegister("java.time.YearMonth", "parse"); tryRegister("java.time.MonthDay", "parse"); tryRegister("java.time.Period", "parse"); tryRegister("java.time.ZoneOffset", "of"); tryRegister("java.time.ZoneId", "of"); // ThreeTen backport classes tryRegister("org.threeten.bp.Instant", "parse"); tryRegister("org.threeten.bp.Duration", "parse"); tryRegister("org.threeten.bp.LocalDate", "parse"); tryRegister("org.threeten.bp.LocalTime", "parse"); tryRegister("org.threeten.bp.LocalDateTime", "parse"); tryRegister("org.threeten.bp.OffsetTime", "parse"); tryRegister("org.threeten.bp.OffsetDateTime", "parse"); tryRegister("org.threeten.bp.ZonedDateTime", "parse"); tryRegister("org.threeten.bp.Year", "parse"); tryRegister("org.threeten.bp.YearMonth", "parse"); tryRegister("org.threeten.bp.MonthDay", "parse"); tryRegister("org.threeten.bp.Period", "parse"); tryRegister("org.threeten.bp.ZoneOffset", "of"); tryRegister("org.threeten.bp.ZoneId", "of"); // Old ThreeTen/JSR-310 classes v0.6.3 and beyond tryRegister("javax.time.Instant", "parse"); tryRegister("javax.time.Duration", "parse"); tryRegister("javax.time.calendar.LocalDate", "parse"); tryRegister("javax.time.calendar.LocalTime", "parse"); tryRegister("javax.time.calendar.LocalDateTime", "parse"); tryRegister("javax.time.calendar.OffsetDate", "parse"); tryRegister("javax.time.calendar.OffsetTime", "parse"); tryRegister("javax.time.calendar.OffsetDateTime", "parse"); tryRegister("javax.time.calendar.ZonedDateTime", "parse"); tryRegister("javax.time.calendar.Year", "parse"); tryRegister("javax.time.calendar.YearMonth", "parse"); tryRegister("javax.time.calendar.MonthDay", "parse"); tryRegister("javax.time.calendar.Period", "parse"); tryRegister("javax.time.calendar.ZoneOffset", "of"); tryRegister("javax.time.calendar.ZoneId", "of"); tryRegister("javax.time.calendar.TimeZone", "of"); } if (factories.length > 0) { this.factories.addAll(Arrays.asList(factories)); } this.factories.add(AnnotationStringConverterFactory.INSTANCE); } /** * Tries to register a class using the standard toString/parse pattern. * * @param className the class name, not null */ private void tryRegister(String className, String fromStringMethodName) { try { Class cls = getClass().getClassLoader().loadClass(className); registerMethods(cls, "toString", fromStringMethodName); } catch (Exception ex) { // ignore } } //----------------------------------------------------------------------- /** * Converts the specified object to a {@code String}. *

* This uses {@link #findConverter} to provide the converter. * * @param object the object to convert, null returns null * @return the converted string, may be null * @throws RuntimeException (or subclass) if unable to convert */ public String convertToString(Object object) { if (object == null) { return null; } Class cls = object.getClass(); StringConverter conv = findConverterNoGenerics(cls); return conv.convertToString(object); } /** * Converts the specified object to a {@code String}. *

* This uses {@link #findConverter} to provide the converter. * The class can be provided to select a more specific converter. * * @param cls the class to convert from, not null * @param object the object to convert, null returns null * @return the converted string, may be null * @throws RuntimeException (or subclass) if unable to convert */ public String convertToString(Class cls, Object object) { if (object == null) { return null; } StringConverter conv = findConverterNoGenerics(cls); return conv.convertToString(object); } /** * Converts the specified object from a {@code String}. *

* This uses {@link #findConverter} to provide the converter. * * @param the type to convert to * @param cls the class to convert to, not null * @param str the string to convert, null returns null * @return the converted object, may be null * @throws RuntimeException (or subclass) if unable to convert */ public T convertFromString(Class cls, String str) { if (str == null) { return null; } StringConverter conv = findConverter(cls); return conv.convertFromString(cls, str); } //----------------------------------------------------------------------- /** * Checks if a suitable converter exists for the type. *

* This performs the same checks as the {@code findConverter} methods. * Calling this before {@code findConverter} will cache the converter. *

* Note that all exceptions, including developer errors are caught and hidden. * * @param cls the class to find a converter for, null returns false * @return true if convertible * @since 1.5 */ public boolean isConvertible(final Class cls) { try { return cls != null && findConverterQuiet(cls) != null; } catch (RuntimeException ex) { return false; } } /** * Finds a suitable converter for the type. *

* This returns an instance of {@code StringConverter} for the specified class. * This is designed for user code where the {@code Class} object generics is known. *

* The search algorithm first searches the registered converters in the * class hierarchy and immediate parent interfaces. * It then searches for {@code ToString} and {@code FromString} annotations on the * specified class, class hierarchy or immediate parent interfaces. * * @param the type of the converter * @param cls the class to find a converter for, not null * @return the converter, not null * @throws RuntimeException (or subclass) if no converter found */ public StringConverter findConverter(final Class cls) { StringConverter conv = findConverterQuiet(cls); if (conv == null) { throw new IllegalStateException("No registered converter found: " + cls); } return conv; } /** * Finds a suitable converter for the type with open generics. *

* This returns an instance of {@code StringConverter} for the specified class. * This is designed for framework usage where the {@code Class} object generics are unknown'?'. * The returned type is declared with {@code Object} instead of '?' to * allow the {@link ToStringConverter} to be invoked. *

* The search algorithm first searches the registered converters in the * class hierarchy and immediate parent interfaces. * It then searches for {@code ToString} and {@code FromString} annotations on the * specified class, class hierarchy or immediate parent interfaces. * * @param cls the class to find a converter for, not null * @return the converter, using {@code Object} to avoid generics, not null * @throws RuntimeException (or subclass) if no converter found * @since 1.5 */ @SuppressWarnings("unchecked") public StringConverter findConverterNoGenerics(final Class cls) { StringConverter conv = (StringConverter) findConverterQuiet(cls); if (conv == null) { throw new IllegalStateException("No registered converter found: " + cls); } return conv; } /** * Finds a converter searching registered and annotated. * * @param the type of the converter * @param cls the class to find a method for, not null * @return the converter, null if no converter * @throws RuntimeException if invalid */ @SuppressWarnings("unchecked") private StringConverter findConverterQuiet(final Class cls) { if (cls == null) { throw new IllegalArgumentException("Class must not be null"); } StringConverter conv = (StringConverter) registered.get(cls); if (conv == CACHED_NULL) { return null; } if (conv == null) { try { conv = findAnyConverter(cls); } catch (RuntimeException ex) { registered.putIfAbsent(cls, CACHED_NULL); throw ex; } if (conv == null) { registered.putIfAbsent(cls, CACHED_NULL); return null; } registered.putIfAbsent(cls, conv); } return conv; } /** * Finds a converter searching registered and annotated. * * @param the type of the converter * @param cls the class to find a method for, not null * @return the converter, not null * @throws RuntimeException if invalid */ @SuppressWarnings("unchecked") private StringConverter findAnyConverter(final Class cls) { StringConverter conv = null; // check for registered on superclass Class loopCls = cls.getSuperclass(); while (loopCls != null && conv == null) { conv = (StringConverter) registered.get(loopCls); if (conv != null && conv != CACHED_NULL) { return conv; } loopCls = loopCls.getSuperclass(); } // check for registered on interfaces for (Class loopIfc : cls.getInterfaces()) { conv = (StringConverter) registered.get(loopIfc); if (conv != null && conv != CACHED_NULL) { return conv; } } // check factories for (StringConverterFactory factory : factories) { conv = (StringConverter) factory.findConverter(cls); if (conv != null) { return conv; } } return null; } //----------------------------------------------------------------------- /** * Registers a converter factory. *

* This will be registered ahead of all existing factories. *

* No new factories may be registered for the global singleton. * * @param factory the converter factory, not null * @throws IllegalStateException if trying to alter the global singleton * @since 1.5 */ public void registerFactory(final StringConverterFactory factory) { if (factory == null) { throw new IllegalArgumentException("Factory must not be null"); } if (this == INSTANCE) { throw new IllegalStateException("Global singleton cannot be extended"); } factories.add(0, factory); } //----------------------------------------------------------------------- /** * Registers a converter for a specific type. *

* The converter will be used for subclasses unless overidden. *

* No new converters may be registered for the global singleton. * * @param the type of the converter * @param cls the class to register a converter for, not null * @param converter the String converter, not null * @throws IllegalArgumentException if the class or converter are null * @throws IllegalStateException if trying to alter the global singleton */ public void register(final Class cls, StringConverter converter) { if (cls == null) { throw new IllegalArgumentException("Class must not be null"); } if (converter == null) { throw new IllegalArgumentException("StringConverter must not be null"); } if (this == INSTANCE) { throw new IllegalStateException("Global singleton cannot be extended"); } registered.put(cls, converter); } /** * Registers a converter for a specific type using two separate converters. *

* This method registers a converter for the specified class. * It is primarily intended for use with JDK 1.8 method references or lambdas: *

     *  sc.register(Distance.class, Distance::toString, Distance::parse);
     * 
* The converter will be used for subclasses unless overidden. *

* No new converters may be registered for the global singleton. * * @param the type of the converter * @param cls the class to register a converter for, not null * @param toString the to String converter, typically a method reference, not null * @param fromString the from String converter, typically a method reference, not null * @throws IllegalArgumentException if the class or converter are null * @throws IllegalStateException if trying to alter the global singleton * @since 1.3 */ public void register(final Class cls, final ToStringConverter toString, final FromStringConverter fromString) { if (fromString == null || toString == null) { throw new IllegalArgumentException("Converters must not be null"); } register(cls, new StringConverter() { public String convertToString(T object) { return toString.convertToString(object); } public T convertFromString(Class cls, String str) { return fromString.convertFromString(cls, str); } }); } /** * Registers a converter for a specific type by method names. *

* This method allows the converter to be used when the target class cannot have annotations added. * The two method names must obey the same rules as defined by the annotations * {@link ToString} and {@link FromString}. * The converter will be used for subclasses unless overidden. *

* No new converters may be registered for the global singleton. *

* For example, {@code convert.registerMethods(Distance.class, "toString", "parse");} * * @param the type of the converter * @param cls the class to register a converter for, not null * @param toStringMethodName the name of the method converting to a string, not null * @param fromStringMethodName the name of the method converting from a string, not null * @throws IllegalArgumentException if the class or method name are null or invalid * @throws IllegalStateException if trying to alter the global singleton */ public void registerMethods(final Class cls, String toStringMethodName, String fromStringMethodName) { if (cls == null) { throw new IllegalArgumentException("Class must not be null"); } if (toStringMethodName == null || fromStringMethodName == null) { throw new IllegalArgumentException("Method names must not be null"); } if (this == INSTANCE) { throw new IllegalStateException("Global singleton cannot be extended"); } Method toString = findToStringMethod(cls, toStringMethodName); Method fromString = findFromStringMethod(cls, fromStringMethodName); MethodsStringConverter converter = new MethodsStringConverter(cls, toString, fromString); registered.putIfAbsent(cls, converter); } /** * Registers a converter for a specific type by method and constructor. *

* This method allows the converter to be used when the target class cannot have annotations added. * The two method name and constructor must obey the same rules as defined by the annotations * {@link ToString} and {@link FromString}. * The converter will be used for subclasses unless overidden. *

* No new converters may be registered for the global singleton. *

* For example, {@code convert.registerMethodConstructor(Distance.class, "toString");} * * @param the type of the converter * @param cls the class to register a converter for, not null * @param toStringMethodName the name of the method converting to a string, not null * @throws IllegalArgumentException if the class or method name are null or invalid * @throws IllegalStateException if trying to alter the global singleton */ public void registerMethodConstructor(final Class cls, String toStringMethodName) { if (cls == null) { throw new IllegalArgumentException("Class must not be null"); } if (toStringMethodName == null) { throw new IllegalArgumentException("Method name must not be null"); } if (this == INSTANCE) { throw new IllegalStateException("Global singleton cannot be extended"); } Method toString = findToStringMethod(cls, toStringMethodName); Constructor fromString = findFromStringConstructorByType(cls); MethodConstructorStringConverter converter = new MethodConstructorStringConverter(cls, toString, fromString); registered.putIfAbsent(cls, converter); } /** * Finds the conversion method. * * @param cls the class to find a method for, not null * @param methodName the name of the method to find, not null * @return the method to call, null means use {@code toString} */ private Method findToStringMethod(Class cls, String methodName) { Method m; try { m = cls.getMethod(methodName); } catch (NoSuchMethodException ex) { throw new IllegalArgumentException(ex); } if (Modifier.isStatic(m.getModifiers())) { throw new IllegalArgumentException("Method must not be static: " + methodName); } return m; } /** * Finds the conversion method. * * @param cls the class to find a method for, not null * @param methodName the name of the method to find, not null * @return the method to call, null means use {@code toString} */ private Method findFromStringMethod(Class cls, String methodName) { Method m; try { m = cls.getMethod(methodName, String.class); } catch (NoSuchMethodException ex) { try { m = cls.getMethod(methodName, CharSequence.class); } catch (NoSuchMethodException ex2) { throw new IllegalArgumentException("Method not found", ex2); } } if (Modifier.isStatic(m.getModifiers()) == false) { throw new IllegalArgumentException("Method must be static: " + methodName); } return m; } /** * Finds the conversion method. * * @param the type of the converter * @param cls the class to find a method for, not null * @return the method to call, null means use {@code toString} */ private Constructor findFromStringConstructorByType(Class cls) { try { return cls.getDeclaredConstructor(String.class); } catch (NoSuchMethodException ex) { try { return cls.getDeclaredConstructor(CharSequence.class); } catch (NoSuchMethodException ex2) { throw new IllegalArgumentException("Constructor not found", ex2); } } } //----------------------------------------------------------------------- /** * Returns a simple string representation of the object. * * @return the string representation, never null */ @Override public String toString() { return getClass().getSimpleName(); } } joda-convert-1.5/src/main/java/org/joda/convert/JDKStringConverter.java0000644000175000017500000003233012215616656025467 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; import java.io.File; import java.math.BigDecimal; import java.math.BigInteger; import java.net.InetAddress; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; import java.net.UnknownHostException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Currency; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import javax.xml.bind.DatatypeConverter; /** * Conversion between JDK classes and a {@code String}. */ enum JDKStringConverter implements StringConverter { /** * String converter. */ STRING(String.class) { public Object convertFromString(Class cls, String str) { return str; } }, /** * CharSequence converter. */ CHAR_SEQUENCE(CharSequence.class) { public Object convertFromString(Class cls, String str) { return str; } }, /** * StringBuffer converter. */ STRING_BUFFER(StringBuffer.class) { public Object convertFromString(Class cls, String str) { return new StringBuffer(str); } }, /** * StringBuilder converter. */ STRING_BUILDER(StringBuilder.class) { public Object convertFromString(Class cls, String str) { return new StringBuilder(str); } }, /** * Long converter. */ LONG(Long.class) { public Object convertFromString(Class cls, String str) { return new Long(str); } }, /** * Integer converter. */ INTEGER(Integer.class) { public Object convertFromString(Class cls, String str) { return new Integer(str); } }, /** * Short converter. */ SHORT (Short.class) { public Object convertFromString(Class cls, String str) { return new Short(str); } }, /** * Byte converter. */ BYTE(Byte.class) { public Object convertFromString(Class cls, String str) { return new Byte(str); } }, /** * String converter. */ BYTE_ARRAY(byte[].class) { @Override public String convertToString(Object object) { return DatatypeConverter.printBase64Binary((byte[]) object); } public Object convertFromString(Class cls, String str) { return DatatypeConverter.parseBase64Binary(str); } }, /** * Character converter. */ CHARACTER(Character.class) { public Object convertFromString(Class cls, String str) { if (str.length() != 1) { throw new IllegalArgumentException("Character value must be a string length 1"); } return new Character(str.charAt(0)); } }, /** * String converter. */ CHAR_ARRAY(char[].class) { @Override public String convertToString(Object object) { return new String((char[]) object); } public Object convertFromString(Class cls, String str) { return str.toCharArray(); } }, /** * Boolean converter. */ BOOLEAN(Boolean.class) { public Object convertFromString(Class cls, String str) { if ("true".equalsIgnoreCase(str)) { return Boolean.TRUE; } if ("false".equalsIgnoreCase(str)) { return Boolean.FALSE; } throw new IllegalArgumentException("Boolean value must be 'true' or 'false', case insensitive"); } }, /** * Double converter. */ DOUBLE(Double.class) { public Object convertFromString(Class cls, String str) { return new Double(str); } }, /** * Float converter. */ FLOAT(Float.class) { public Object convertFromString(Class cls, String str) { return new Float(str); } }, /** * BigInteger converter. */ BIG_INTEGER(BigInteger.class) { public Object convertFromString(Class cls, String str) { return new BigInteger(str); } }, /** * BigDecimal converter. */ BIG_DECIMAL(BigDecimal.class) { public Object convertFromString(Class cls, String str) { return new BigDecimal(str); } }, /** * AtomicLong converter. */ ATOMIC_LONG(AtomicLong.class) { public Object convertFromString(Class cls, String str) { long val = Long.parseLong(str); return new AtomicLong(val); } }, /** * AtomicLong converter. */ ATOMIC_INTEGER(AtomicInteger.class) { public Object convertFromString(Class cls, String str) { int val = Integer.parseInt(str); return new AtomicInteger(val); } }, /** * AtomicBoolean converter. */ ATOMIC_BOOLEAN(AtomicBoolean.class) { public Object convertFromString(Class cls, String str) { if ("true".equalsIgnoreCase(str)) { return new AtomicBoolean(true); } if ("false".equalsIgnoreCase(str)) { return new AtomicBoolean(false); } throw new IllegalArgumentException("Boolean value must be 'true' or 'false', case insensitive"); } }, /** * Locale converter. */ LOCALE(Locale.class) { public Object convertFromString(Class cls, String str) { String[] split = str.split("_", 3); switch (split.length) { case 1: return new Locale(split[0]); case 2: return new Locale(split[0], split[1]); case 3: return new Locale(split[0], split[1], split[2]); } throw new IllegalArgumentException("Unable to parse Locale: " + str); } }, /** * Class converter. */ CLASS(Class.class) { @Override public String convertToString(Object object) { return ((Class) object).getName(); } public Object convertFromString(Class cls, String str) { try { return getClass().getClassLoader().loadClass(str); } catch (ClassNotFoundException ex) { throw new RuntimeException("Unable to create class: " + str, ex); } } }, /** * Package converter. */ PACKAGE(Package.class) { @Override public String convertToString(Object object) { return ((Package) object).getName(); } public Object convertFromString(Class cls, String str) { return Package.getPackage(str); } }, /** * Currency converter. */ CURRENCY(Currency.class) { public Object convertFromString(Class cls, String str) { return Currency.getInstance(str); } }, /** * TimeZone converter. */ TIME_ZONE(TimeZone.class) { @Override public String convertToString(Object object) { return ((TimeZone) object).getID(); } public Object convertFromString(Class cls, String str) { return TimeZone.getTimeZone(str); } }, /** * UUID converter. */ UUID(UUID.class) { public Object convertFromString(Class cls, String str) { return java.util.UUID.fromString(str); } }, /** * URL converter. */ URL(URL.class) { public Object convertFromString(Class cls, String str) { try { return new URL(str); } catch (MalformedURLException ex) { throw new RuntimeException(ex.getMessage(), ex); } } }, /** * URI converter. */ URI(URI.class) { public Object convertFromString(Class cls, String str) { return java.net.URI.create(str); } }, /** * InetAddress converter. */ INET_ADDRESS(InetAddress.class) { @Override public String convertToString(Object object) { return ((InetAddress) object).getHostAddress(); } public Object convertFromString(Class cls, String str) { try { return InetAddress.getByName(str); } catch (UnknownHostException ex) { throw new RuntimeException(ex); } } }, /** * File converter. */ FILE(File.class) { public Object convertFromString(Class cls, String str) { return new File(str); } }, /** * Date converter. */ DATE(Date.class) { @Override public String convertToString(Object object) { SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); String str = f.format(object); return str.substring(0, 26) + ":" + str.substring(26); } public Object convertFromString(Class cls, String str) { if (str.length() != 29) { throw new IllegalArgumentException("Unable to parse date: " + str); } str = str.substring(0, 26) + str.substring(27); SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); try { return f.parseObject(str); } catch (ParseException ex) { throw new RuntimeException(ex); } } }, /** * Calendar converter. */ CALENDAR(Calendar.class) { @Override public String convertToString(Object object) { if (object instanceof GregorianCalendar == false) { throw new RuntimeException("Unable to convert calendar as it is not a GregorianCalendar"); } GregorianCalendar cal = (GregorianCalendar) object; SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); f.setCalendar(cal); String str = f.format(cal.getTime()); return str.substring(0, 26) + ":" + str.substring(26) + "[" + cal.getTimeZone().getID() + "]"; } public Object convertFromString(Class cls, String str) { if (str.length() < 31 || str.charAt(26) != ':' || str.charAt(29) != '[' || str.charAt(str.length() - 1) != ']') { throw new IllegalArgumentException("Unable to parse date: " + str); } TimeZone zone = TimeZone.getTimeZone(str.substring(30, str.length() - 1)); str = str.substring(0, 26) + str.substring(27, 29); SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); GregorianCalendar cal = new GregorianCalendar(zone); cal.setTimeInMillis(0); f.setCalendar(cal); try { f.parseObject(str); return f.getCalendar(); } catch (ParseException ex) { throw new RuntimeException(ex); } } }, /** * Enum converter. */ ENUM(Enum.class) { @SuppressWarnings("rawtypes") public String convertToString(Object object) { return ((Enum) object).name(); // avoid toString() as that can be overridden } @SuppressWarnings({ "unchecked", "rawtypes" }) public Object convertFromString(Class cls, String str) { return Enum.valueOf(cls, str); } }, ; /** The type. */ private Class type; /** * Creates an enum. * @param type the type, not null */ private JDKStringConverter(Class type) { this.type = type; } /** * Gets the type of the converter. * @return the type, not null */ Class getType() { return type; } //----------------------------------------------------------------------- public String convertToString(Object object) { return object.toString(); } } joda-convert-1.5/src/main/java/org/joda/convert/StringConverterFactory.java0000644000175000017500000000227112216050733026454 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Factory for {@code StringConverter} that allows converters to be * created dynamically or easily initialised. *

* Implementations must be immutable and thread-safe. * * @since 1.5 */ public interface StringConverterFactory { /** * Finds a converter by type. * * @param cls the type to lookup, not null * @return the converter, null if not found * @throws RuntimeException (or subclass) if source code is invalid */ StringConverter findConverter(Class cls); } joda-convert-1.5/src/main/java/org/joda/convert/FromStringFactory.java0000644000175000017500000000342412215577663025430 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Annotation used on a type to indicate that another class, the factory, * provides the 'from string' method. *

* This annotation is applied at the type level, typically to an interface. * It indicates the class which contains the relevant {@code FromString} * annotation, which follows the normal rules. *

* For example, the interface {@code Foo} could be annotated to define its * associated factory as being {@code FooFactory}. The {@code FooFactory} * class would then be expected to provide a method returning {@code Foo} * with a single {@code String} parameter, annotated with {@code FromString}. * * @since 1.4 */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface FromStringFactory { /** * The factory class containing the static method. * The static method must have a return type of the type that declares * the factory annotation. */ Class factory(); } joda-convert-1.5/src/main/java/org/joda/convert/ToString.java0000644000175000017500000000265012215577716023556 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Annotation used to mark a method as being suitable for converting an * object to a standard format {@code String}. *

* This annotation should be applied to one method on a class. * The method must not be static. It must take no parameters and return a {@code String}. * The string format must be able to be parsed by the matching @FromString on * the same class. The format should be human readable and an industry standard * where possible, for example ISO-8601 for dates and times. */ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface ToString { } joda-convert-1.5/src/main/java/org/joda/convert/StringConverter.java0000644000175000017500000000177012215577711025140 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; /** * Interface defining conversion to and from a {@code String}. *

* StringConverter is an interface and must be implemented with care. * Implementations must be immutable and thread-safe. * * @param the type of the converter */ public interface StringConverter extends ToStringConverter, FromStringConverter { } joda-convert-1.5/src/main/java/org/joda/convert/MethodsStringConverter.java0000644000175000017500000000703112215577676026472 0ustar ebourgebourg/* * Copyright 2010-present Stephen Colebourne * * Licensed 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.joda.convert; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; /** * Conversion to and from a string using two methods. *

* The toString method must meet the following signature:
* {@code String anyName()} on Class T. *

* The fromString method must meet the following signature:
* {@code static T anyName(String)} on any class. *

* MethodsStringConverter is thread-safe and immutable. * * @param the type of the converter */ final class MethodsStringConverter extends ReflectionStringConverter { /** Conversion from a string. */ private final Method fromString; /** * Creates an instance using two methods. * @param cls the class this converts for, not null * @param toString the toString method, not null * @param fromString the fromString method, not null * @throws RuntimeException (or subclass) if the method signatures are invalid */ MethodsStringConverter(Class cls, Method toString, Method fromString) { super(cls, toString); if (Modifier.isStatic(fromString.getModifiers()) == false) { throw new IllegalStateException("FromString method must be static: " + fromString); } if (fromString.getParameterTypes().length != 1) { throw new IllegalStateException("FromString method must have one parameter: " + fromString); } Class param = fromString.getParameterTypes()[0]; if (param != String.class && param != CharSequence.class) { throw new IllegalStateException("FromString method must take a String or CharSequence: " + fromString); } if (fromString.getReturnType().isAssignableFrom(cls) == false && cls.isAssignableFrom(fromString.getReturnType()) == false) { throw new IllegalStateException("FromString method must return specified class or a supertype: " + fromString); } this.fromString = fromString; } //----------------------------------------------------------------------- /** * Converts the {@code String} to an object. * @param cls the class to convert to, not null * @param str the string to convert, not null * @return the converted object, may be null but generally not */ public T convertFromString(Class cls, String str) { try { return cls.cast(fromString.invoke(null, str)); } catch (IllegalAccessException ex) { throw new IllegalStateException("Method is not accessible: " + fromString); } catch (InvocationTargetException ex) { if (ex.getCause() instanceof RuntimeException) { throw (RuntimeException) ex.getCause(); } throw new RuntimeException(ex.getMessage(), ex.getCause()); } } } joda-convert-1.5/LICENSE.txt0000644000175000017500000002645012202714763015140 0ustar ebourgebourg Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed 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. joda-convert-1.5/pom.xml0000644000175000017500000004766612216067350014644 0ustar ebourgebourg 4.0.0 org.joda joda-convert jar Joda-Convert 1.5 Library to convert Objects to and from String http://www.joda.org/joda-convert/ GitHub https://github.com/JodaOrg/joda-convert/issues 2010 Joda Convert Interest list https://lists.sourceforge.net/lists/listinfo/joda-convert-interest https://lists.sourceforge.net/lists/listinfo/joda-convert-interest http://sourceforge.net/mailarchive/forum.php?forum_name=joda-convert-interest scolebourne Stephen Colebourne Project Lead 0 https://github.com/jodastephen Chris Kent https://github.com/cjkent Raman Gupta https://github.com/rocketraman Apache 2 http://www.apache.org/licenses/LICENSE-2.0.txt repo scm:git:https://github.com/JodaOrg/joda-convert.git scm:git:git@github.com:JodaOrg/joda-convert.git https://github.com/JodaOrg/joda-convert Joda.org http://www.joda.org META-INF ${project.basedir} LICENSE.txt NOTICE.txt org.apache.maven.plugins maven-checkstyle-plugin run-checkstyle process-sources checkstyle org.apache.maven.plugins maven-jar-plugin ${project.build.outputDirectory}/META-INF/MANIFEST.MF true true org.apache.felix maven-bundle-plugin 2.4.0 bundle-manifest process-classes manifest org.apache.maven.plugins maven-javadoc-plugin attach-javadocs package jar org.apache.maven.plugins maven-source-plugin attach-sources package jar-no-fork org.apache.maven.plugins maven-assembly-plugin false src/main/assembly/dist.xml gnu make-assembly deploy single org.apache.maven.plugins maven-site-plugin true com.github.github site-maven-plugin 0.8 github-site site site-deploy Create website for ${project.artifactId} v${project.version} joda-convert true github JodaOrg jodaorg.github.io refs/heads/master org.apache.maven.plugins maven-assembly-plugin ${maven-assembly-plugin.version} org.apache.maven.plugins maven-checkstyle-plugin ${maven-checkstyle-plugin.version} org.apache.maven.plugins maven-changes-plugin ${maven-changes-plugin.version} org.apache.maven.plugins maven-clean-plugin ${maven-clean-plugin.version} org.apache.maven.plugins maven-compiler-plugin ${maven-compiler-plugin.version} org.apache.maven.plugins maven-deploy-plugin ${maven-deploy-plugin.version} org.apache.maven.plugins maven-dependency-plugin ${maven-dependency-plugin.version} org.apache.maven.plugins maven-gpg-plugin ${maven-gpg-plugin.version} org.apache.maven.plugins maven-install-plugin ${maven-install-plugin.version} org.apache.maven.plugins maven-jar-plugin ${maven-jar-plugin.version} org.apache.maven.plugins maven-javadoc-plugin ${maven-javadoc-plugin.version} org.apache.maven.plugins maven-jxr-plugin ${maven-jxr-plugin.version} org.apache.maven.plugins maven-plugin-plugin ${maven-plugin-plugin.version} org.apache.maven.plugins maven-pmd-plugin ${maven-pmd-plugin.version} org.apache.maven.plugins maven-project-info-reports-plugin ${maven-project-info-reports-plugin.version} org.apache.maven.plugins maven-repository-plugin ${maven-repository-plugin.version} org.apache.maven.plugins maven-resources-plugin ${maven-resources-plugin.version} org.apache.maven.plugins maven-site-plugin ${maven-site-plugin.version} org.apache.maven.plugins maven-source-plugin ${maven-source-plugin.version} org.apache.maven.plugins maven-surefire-plugin ${maven-surefire-plugin.version} org.apache.maven.plugins maven-surefire-report-plugin ${maven-surefire-report-plugin.version} org.apache.maven.plugins maven-toolchains-plugin ${maven-toolchains-plugin.version} org.eclipse.m2e lifecycle-mapping 1.0.0 org.apache.felix maven-bundle-plugin [2.4.0,) manifest 3.0.4 junit junit 4.11 test org.apache.maven.plugins maven-project-info-reports-plugin ${maven-project-info-plugin.version} dependencies dependency-info issue-tracking license mailing-list project-team scm summary org.apache.maven.plugins maven-checkstyle-plugin ${maven-checkstyle-plugin.version} org.apache.maven.plugins maven-javadoc-plugin ${maven-javadoc-plugin.version} javadoc org.apache.maven.plugins maven-surefire-report-plugin ${maven-surefire-report-plugin.version} true org.apache.maven.plugins maven-changes-plugin ${maven-changes-plugin.version} changes-report org.apache.maven.plugins maven-jxr-plugin ${maven-jxr-plugin.version} jxr sonatype-joda-staging Sonatype OSS staging repository http://oss.sonatype.org/service/local/staging/deploy/maven2/ default false sonatype-joda-snapshot Sonatype OSS snapshot repository http://oss.sonatype.org/content/repositories/joda-snapshots default http://oss.sonatype.org/content/repositories/joda-releases repo-sign-artifacts oss.repo true org.apache.maven.plugins maven-toolchains-plugin validate toolchain 1.6 sun org.apache.maven.plugins maven-gpg-plugin sign-artifacts verify sign 2.4 2.9 2.10 2.5 3.1 2.7 2.8 1.4 2.5 2.4 2.9.1 2.3 3.2 3.0.1 2.7 2.3.1 2.6 3.3 2.2.1 2.16 2.16 1.0 1.6 1.6 1.6 true true true true false true ${project.basedir}/src/main/checkstyle/checkstyle.xml UTF-8 UTF-8 joda-convert-1.5/NOTICE.txt0000644000175000017500000000047412202714763015035 0ustar ebourgebourg============================================================================= = NOTICE file corresponding to section 4d of the Apache License Version 2.0 = ============================================================================= This product includes software developed by Joda.org (http://www.joda.org/). joda-convert-1.5/RELEASE-NOTES.txt0000644000175000017500000000107612203151725016013 0ustar ebourgebourg Joda-Convert ================================================ Joda-Convert is a small library providing conversion to and from String. The release runs on JDK 6 or later. See http://www.joda.org/joda-convert/changes-report.html for changes Joda-Convert is licensed under the business-friendly Apache License Version 2. This is the same license as all of Apache, plus other open source projects such as Spring. Feedback -------- Feedback is best received using GitHub issues and Pull Requests. https://github.com/JodaOrg/joda-convert/ The Joda team