From e01492284901c4b94310f6647f4d3bebddfd06ab Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Thu, 17 Apr 2014 13:42:32 -0700 Subject: [PATCH 01/19] Initial commit --- LICENSE | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 4 ++ 2 files changed, 205 insertions(+) create mode 100644 LICENSE create mode 100644 README.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ad410e1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ +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. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..18a85fb --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +rome-utils +========== + +Utility classes for ROME projects From 5f65787ca531ad5eab2f00427698ed0cdf9c89c3 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Thu, 17 Apr 2014 22:49:06 +0200 Subject: [PATCH 02/19] Initial commit --- .gitignore | 4 + LICENSE | 10 +- pom.xml | 55 +++++++++ .../com/rometools/utils/Alternatives.java | 23 ++++ src/main/java/com/rometools/utils/Dates.java | 24 ++++ src/main/java/com/rometools/utils/Lists.java | 100 +++++++++++++++++ .../java/com/rometools/utils/Strings.java | 78 +++++++++++++ src/main/resources/.gitignore | 0 .../com/rometools/utils/AlternativesTest.java | 23 ++++ .../java/com/rometools/utils/DatesTest.java | 26 +++++ .../java/com/rometools/utils/ListsTest.java | 105 ++++++++++++++++++ .../java/com/rometools/utils/StringsTest.java | 97 ++++++++++++++++ src/test/resources/.gitignore | 0 13 files changed, 541 insertions(+), 4 deletions(-) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/com/rometools/utils/Alternatives.java create mode 100644 src/main/java/com/rometools/utils/Dates.java create mode 100644 src/main/java/com/rometools/utils/Lists.java create mode 100644 src/main/java/com/rometools/utils/Strings.java create mode 100644 src/main/resources/.gitignore create mode 100644 src/test/java/com/rometools/utils/AlternativesTest.java create mode 100644 src/test/java/com/rometools/utils/DatesTest.java create mode 100644 src/test/java/com/rometools/utils/ListsTest.java create mode 100644 src/test/java/com/rometools/utils/StringsTest.java create mode 100644 src/test/resources/.gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c708c36 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/target +/.settings +/.classpath +/.project diff --git a/LICENSE b/LICENSE index ad410e1..6b0b127 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,5 @@ -Apache License + + Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -178,7 +179,7 @@ Apache License 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 "{}" + 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 @@ -186,7 +187,7 @@ Apache License same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright {yyyy} {name of copyright owner} + 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. @@ -198,4 +199,5 @@ Apache License 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. \ No newline at end of file + limitations under the License. + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..b8defa9 --- /dev/null +++ b/pom.xml @@ -0,0 +1,55 @@ + + + + 4.0.0 + + + com.rometools + rome-parent + 1.5.0-SNAPSHOT + + + rome-utils + jar + + rome-utils + + Utility classes for ROME projects + + http://rometools.github.io/rome-utils/ + + + scm:git:git@github.com:rometools/rome-utils.git + scm:git:git@github.com:rometools/rome-utils.git + https://github.com/rometools/rome-utils + + + + + Patrick Gotthard + http://www.patrick-gotthard.de + +1 + + + + + + junit + junit + test + + + hamcrest-core + org.hamcrest + + + + + org.hamcrest + hamcrest-all + test + + + + \ No newline at end of file diff --git a/src/main/java/com/rometools/utils/Alternatives.java b/src/main/java/com/rometools/utils/Alternatives.java new file mode 100644 index 0000000..cf8fba2 --- /dev/null +++ b/src/main/java/com/rometools/utils/Alternatives.java @@ -0,0 +1,23 @@ +package com.rometools.utils; + +public final class Alternatives { + + private Alternatives() { + } + + /** + * Returns the first object that is not null + * + * @param objects The objects to process + * @return The first value that is not null. null when there is no not-null value + */ + public static T firstNotNull(final T... objects) { + for (final T object : objects) { + if (object != null) { + return object; + } + } + return null; + } + +} diff --git a/src/main/java/com/rometools/utils/Dates.java b/src/main/java/com/rometools/utils/Dates.java new file mode 100644 index 0000000..9060e30 --- /dev/null +++ b/src/main/java/com/rometools/utils/Dates.java @@ -0,0 +1,24 @@ +package com.rometools.utils; + +import java.util.Date; + +public final class Dates { + + private Dates() { + } + + /** + * Creates a copy on a Date. + * + * @param d The Date to copy, can be null + * @return null when the input Date was null, a copy of the Date otherwise + */ + public static Date copy(final Date d) { + if (d == null) { + return null; + } else { + return new Date(d.getTime()); + } + } + +} diff --git a/src/main/java/com/rometools/utils/Lists.java b/src/main/java/com/rometools/utils/Lists.java new file mode 100644 index 0000000..3cbdc10 --- /dev/null +++ b/src/main/java/com/rometools/utils/Lists.java @@ -0,0 +1,100 @@ +package com.rometools.utils; + +import java.util.ArrayList; +import java.util.List; + +public final class Lists { + + private Lists() { + } + + /** + * Returns the list when it is not null. Returns a new list otherwise. + * + * @param list The list to process, can be null + * @return The input list when it is not null, a new list otherwise + */ + public static List createWhenNull(final List list) { + if (list == null) { + return new ArrayList(); + } else { + return list; + } + } + + /** + * Creates a new List with the given item as the first entry. + * + * @param item The item to add to the new list + * @return List containing the given item + */ + public static List create(final T item) { + final List list = new ArrayList(); + list.add(item); + return list; + } + + /** + * Extracts the first entry of the list when it is not null and contains values. + * + * @param list The list to extract the first entry from, can be null + * @return The first entry of the list when it is not null or empty, null otherwise + */ + public static T firstEntry(final List list) { + if (list != null && !list.isEmpty()) { + return list.get(0); + } else { + return null; + } + } + + /** + * Checks whether the list is null or empty. + * + * @param list The list to check + * @return true when the list is null or empty, false otherwise + */ + public static boolean isEmpty(final List list) { + return list == null || list.isEmpty(); + } + + /** + * Checks whether the list is not null and not empty. + * + * @param list The list to check + * @return true when the list is not null and not empty + */ + public static boolean isNotEmpty(final List list) { + return !isEmpty(list); + } + + /** + * Checks whether the list has the given size. A null list is treated like a list without entries. + * + * @param list The list to check + * @param size The size to check + * @return true when the list has the given size or when size = 0 and the list is null, false otherwise + */ + public static boolean sizeIs(final List list, final int size) { + if (size == 0) { + return list == null || list.isEmpty(); + } else { + return list != null && list.size() == size; + } + } + + /** + * Returns null, when the given list is empty or null + * + * @param list The list to process + * @return null when the list is empty or null, the given list otherwise + */ + public static List emptyToNull(final List list) { + if (isEmpty(list)) { + return null; + } else { + return list; + } + } + +} diff --git a/src/main/java/com/rometools/utils/Strings.java b/src/main/java/com/rometools/utils/Strings.java new file mode 100644 index 0000000..76f56e4 --- /dev/null +++ b/src/main/java/com/rometools/utils/Strings.java @@ -0,0 +1,78 @@ +package com.rometools.utils; + +import java.util.Locale; + +public final class Strings { + + private Strings() { + } + + /** + * Checks whether a String is null. + * + * @param s The String to check + * @return true when the String is null, false otherwise + */ + public static boolean isNull(final String s) { + return s == null; + } + + /** + * Checks whether a String is null or empty. + * + * @param s The String to check + * @return true when the String is null or empty, false otherwise + */ + public static boolean isEmpty(final String s) { + return isNull(s) || s.isEmpty(); + } + + /** + * Checks whether a String is neither null nor empty. + * + * @param s The String to check + * @return true when the String is neither null nor empty, false otherwise + */ + public static boolean isNotEmpty(final String s) { + return !isEmpty(s); + } + + /** + * Checks whether a String is null, empty or blank. + * + * @param s The String to check + * @return true when the String is null, empty or blank, false otherwise + */ + public static boolean isBlank(final String s) { + return isEmpty(s) || s.trim().isEmpty(); + } + + /** + * null-safe trimming of a String. + * + * @param s The String to trim, may be null + * @return null when the input String is null, the trimmed String otherwise + */ + public static String trim(final String s) { + if (s == null) { + return null; + } else { + return s.trim(); + } + } + + /** + * null-safe lower-case conversion of a String. + * + * @param s The String to process, may be null + * @return null when the input String is null, the String in lower-case otherwise + */ + public static String toLowerCase(final String s) { + if (s == null) { + return null; + } else { + return s.toLowerCase(Locale.ENGLISH); + } + } + +} diff --git a/src/main/resources/.gitignore b/src/main/resources/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/src/test/java/com/rometools/utils/AlternativesTest.java b/src/test/java/com/rometools/utils/AlternativesTest.java new file mode 100644 index 0000000..ba23641 --- /dev/null +++ b/src/test/java/com/rometools/utils/AlternativesTest.java @@ -0,0 +1,23 @@ +package com.rometools.utils; + +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +public class AlternativesTest { + + @Test + public void testFirstNotNull() { + + final Integer nullInteger = null; + final Integer notNullInteger = 1; + + assertThat(Alternatives.firstNotNull(notNullInteger, nullInteger), is(notNullInteger)); + assertThat(Alternatives.firstNotNull(nullInteger, notNullInteger), is(notNullInteger)); + assertThat(Alternatives.firstNotNull(nullInteger, nullInteger), is(nullValue())); + + } + +} diff --git a/src/test/java/com/rometools/utils/DatesTest.java b/src/test/java/com/rometools/utils/DatesTest.java new file mode 100644 index 0000000..d38edcc --- /dev/null +++ b/src/test/java/com/rometools/utils/DatesTest.java @@ -0,0 +1,26 @@ +package com.rometools.utils; + +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + +import java.util.Date; + +import org.junit.Test; + +public class DatesTest { + + @Test + public void testCopy() { + + final Date date = new Date(); + final Date nullDate = null; + + assertThat(Dates.copy(date), is(notNullValue())); + assertThat(Dates.copy(date).getTime(), is(date.getTime())); + assertThat(Dates.copy(nullDate), is(nullValue())); + + } + +} diff --git a/src/test/java/com/rometools/utils/ListsTest.java b/src/test/java/com/rometools/utils/ListsTest.java new file mode 100644 index 0000000..dc1b7a8 --- /dev/null +++ b/src/test/java/com/rometools/utils/ListsTest.java @@ -0,0 +1,105 @@ +package com.rometools.utils; + +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; + +public class ListsTest { + + @Test + public void testCreateWhenNull() { + + final List list = new ArrayList(); + final List nullList = null; + + assertThat(Lists.createWhenNull(list), is(notNullValue())); + assertThat(Lists.createWhenNull(list), is(list)); + assertThat(Lists.createWhenNull(nullList), is(notNullValue())); + + } + + @Test + public void testCreate() { + + final List create = Lists.create(1); + assertThat(create, is(notNullValue())); + assertThat(create.size(), is(1)); + assertThat(create, hasItem(1)); + + } + + @Test + public void testFirstEntry() { + + final List nullList = null; + final List listWithoutEntries = new ArrayList(); + final List listWithOneEntry = Arrays.asList(1); + final List listWithTwoEntries = Arrays.asList(1, 2); + + assertThat(Lists.firstEntry(nullList), is(nullValue())); + assertThat(Lists.firstEntry(listWithoutEntries), is(nullValue())); + assertThat(Lists.firstEntry(listWithOneEntry), is(1)); + assertThat(Lists.firstEntry(listWithTwoEntries), is(1)); + + } + + @Test + public void testIsEmpty() { + + final List nullList = null; + final List listWithoutEntries = new ArrayList(); + final List listWithOneEntry = Arrays.asList(1); + + assertThat(Lists.isEmpty(nullList), is(true)); + assertThat(Lists.isEmpty(listWithoutEntries), is(true)); + assertThat(Lists.isEmpty(listWithOneEntry), is(false)); + + } + + @Test + public void testIsNotEmpty() { + + final List nullList = null; + final List listWithoutEntries = new ArrayList(); + final List listWithOneEntry = Arrays.asList(1); + + assertThat(Lists.isNotEmpty(nullList), is(false)); + assertThat(Lists.isNotEmpty(listWithoutEntries), is(false)); + assertThat(Lists.isNotEmpty(listWithOneEntry), is(true)); + } + + @Test + public void testSizeIs() { + + final List nullList = null; + final List listWithoutEntries = new ArrayList(); + final List listWithOneEntry = Arrays.asList(1); + + assertThat(Lists.sizeIs(nullList, 0), is(true)); + assertThat(Lists.sizeIs(listWithoutEntries, 0), is(true)); + assertThat(Lists.sizeIs(listWithOneEntry, 1), is(true)); + + } + + @Test + public void testEmptyToNull() { + + final List nullList = null; + final List listWithoutEntries = new ArrayList(); + final List listWithOneEntry = Arrays.asList(1); + + assertThat(Lists.emptyToNull(nullList), is(nullValue())); + assertThat(Lists.emptyToNull(listWithoutEntries), is(nullValue())); + assertThat(Lists.emptyToNull(listWithOneEntry), is(notNullValue())); + + } + +} diff --git a/src/test/java/com/rometools/utils/StringsTest.java b/src/test/java/com/rometools/utils/StringsTest.java new file mode 100644 index 0000000..97e82ac --- /dev/null +++ b/src/test/java/com/rometools/utils/StringsTest.java @@ -0,0 +1,97 @@ +package com.rometools.utils; + +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +public class StringsTest { + + @Test + public void testIsNull() { + + final String nullString = null; + final String emptyString = ""; + final String blankString = " "; + final String string = "a"; + + assertThat(Strings.isNull(nullString), is(true)); + assertThat(Strings.isNull(emptyString), is(false)); + assertThat(Strings.isNull(blankString), is(false)); + assertThat(Strings.isNull(string), is(false)); + + } + + @Test + public void testIsEmpty() { + + final String nullString = null; + final String emptyString = ""; + final String blankString = " "; + final String string = "a"; + + assertThat(Strings.isEmpty(nullString), is(true)); + assertThat(Strings.isEmpty(emptyString), is(true)); + assertThat(Strings.isEmpty(blankString), is(false)); + assertThat(Strings.isEmpty(string), is(false)); + + } + + @Test + public void testIsNotEmpty() { + + final String nullString = null; + final String emptyString = ""; + final String blankString = " "; + final String string = "a"; + + assertThat(Strings.isNotEmpty(nullString), is(false)); + assertThat(Strings.isNotEmpty(emptyString), is(false)); + assertThat(Strings.isNotEmpty(blankString), is(true)); + assertThat(Strings.isNotEmpty(string), is(true)); + } + + @Test + public void testIsBlank() { + + final String nullString = null; + final String emptyString = ""; + final String blankString = " "; + final String string = "a"; + + assertThat(Strings.isBlank(nullString), is(true)); + assertThat(Strings.isBlank(emptyString), is(true)); + assertThat(Strings.isBlank(blankString), is(true)); + assertThat(Strings.isBlank(string), is(false)); + } + + @Test + public void testTrim() { + + final String nullString = null; + final String emptyString = ""; + final String blankString = " "; + final String string = " a "; + + assertThat(Strings.trim(nullString), is(nullValue())); + assertThat(Strings.trim(emptyString), is("")); + assertThat(Strings.trim(blankString), is("")); + assertThat(Strings.trim(string), is("a")); + } + + @Test + public void testToLowerCase() { + + final String nullString = null; + final String emptyString = ""; + final String blankString = " "; + final String string = "A"; + + assertThat(Strings.toLowerCase(nullString), is(nullValue())); + assertThat(Strings.toLowerCase(emptyString), is("")); + assertThat(Strings.toLowerCase(blankString), is(" ")); + assertThat(Strings.toLowerCase(string), is("a")); + } + +} diff --git a/src/test/resources/.gitignore b/src/test/resources/.gitignore new file mode 100644 index 0000000..e69de29 From 94104fd50dafa0f932f2b4218fb6b9dd7404ff83 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Fri, 18 Apr 2014 18:37:28 +0200 Subject: [PATCH 03/19] Added additional trim methods for Strings --- .../java/com/rometools/utils/Strings.java | 32 ++++++++++++++++++- .../java/com/rometools/utils/StringsTest.java | 28 ++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/rometools/utils/Strings.java b/src/main/java/com/rometools/utils/Strings.java index 76f56e4..3ac0697 100644 --- a/src/main/java/com/rometools/utils/Strings.java +++ b/src/main/java/com/rometools/utils/Strings.java @@ -48,7 +48,7 @@ public final class Strings { } /** - * null-safe trimming of a String. + * Removes the whitespace at the beginning and end of a String. * * @param s The String to trim, may be null * @return null when the input String is null, the trimmed String otherwise @@ -61,6 +61,36 @@ public final class Strings { } } + /** + * Removes the whitespace at the beginning and end of a String. When the String only contains whitespace, it returns null. + * + * @param s The String to trim, may be null + * @return null when the input String is null or does only contain whitespace, the trimmed String otherwise + */ + public static String trimToNull(final String s) { + final String trimmed = trim(s); + if (trimmed == null || trimmed.isEmpty()) { + return null; + } else { + return trimmed; + } + } + + /** + * Removes the whitespace at the beginning and end of a String. When the String only contains whitespace, it returns null. + * + * @param s The String to trim, may be null + * @return null when the input String is null or does only contain whitespace, the trimmed String otherwise + */ + public static String trimToEmpty(final String s) { + final String trimmed = trim(s); + if (trimmed == null || trimmed.isEmpty()) { + return ""; + } else { + return trimmed; + } + } + /** * null-safe lower-case conversion of a String. * diff --git a/src/test/java/com/rometools/utils/StringsTest.java b/src/test/java/com/rometools/utils/StringsTest.java index 97e82ac..9983549 100644 --- a/src/test/java/com/rometools/utils/StringsTest.java +++ b/src/test/java/com/rometools/utils/StringsTest.java @@ -80,6 +80,34 @@ public class StringsTest { assertThat(Strings.trim(string), is("a")); } + @Test + public void testTrimToEmpty() { + + final String nullString = null; + final String emptyString = ""; + final String blankString = " "; + final String string = " a "; + + assertThat(Strings.trimToEmpty(nullString), is("")); + assertThat(Strings.trimToEmpty(emptyString), is("")); + assertThat(Strings.trimToEmpty(blankString), is("")); + assertThat(Strings.trimToEmpty(string), is("a")); + } + + @Test + public void testTrimToNull() { + + final String nullString = null; + final String emptyString = ""; + final String blankString = " "; + final String string = " a "; + + assertThat(Strings.trimToNull(nullString), is(nullValue())); + assertThat(Strings.trimToNull(emptyString), is(nullValue())); + assertThat(Strings.trimToNull(blankString), is(nullValue())); + assertThat(Strings.trimToNull(string), is("a")); + } + @Test public void testToLowerCase() { From 90a3792ccc7909fa9a54412f3f48dc02efe093e0 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Fri, 18 Apr 2014 19:28:04 +0200 Subject: [PATCH 04/19] Added method to parse Integers --- .../java/com/rometools/utils/Integers.java | 22 ++++++++++++++++ .../com/rometools/utils/IntegersTest.java | 26 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/main/java/com/rometools/utils/Integers.java create mode 100644 src/test/java/com/rometools/utils/IntegersTest.java diff --git a/src/main/java/com/rometools/utils/Integers.java b/src/main/java/com/rometools/utils/Integers.java new file mode 100644 index 0000000..ec5ca85 --- /dev/null +++ b/src/main/java/com/rometools/utils/Integers.java @@ -0,0 +1,22 @@ +package com.rometools.utils; + +public final class Integers { + + private Integers() { + } + + /** + * Converts a String into an Integer. + * + * @param s The String to convert, may be null + * @return The parsed Integer or null when parsing is not possible + */ + public static Integer parse(final String s) { + try { + return Integer.parseInt(s); + } catch (final NumberFormatException e) { + return null; + } + } + +} diff --git a/src/test/java/com/rometools/utils/IntegersTest.java b/src/test/java/com/rometools/utils/IntegersTest.java new file mode 100644 index 0000000..8fc40db --- /dev/null +++ b/src/test/java/com/rometools/utils/IntegersTest.java @@ -0,0 +1,26 @@ +package com.rometools.utils; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +import org.junit.Test; + +public class IntegersTest { + + @Test + public void testParse() { + + final String nullString = null; + final String emptyString = null; + final String integerString = "1"; + final String decimalString = "1.0"; + + assertThat(Integers.parse(nullString), is(nullValue())); + assertThat(Integers.parse(emptyString), is(nullValue())); + assertThat(Integers.parse(integerString), is(1)); + assertThat(Integers.parse(decimalString), is(nullValue())); + + } + +} From 25abc65f91a213c4b103b6d71d35e99fde1f10ca Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Fri, 18 Apr 2014 20:52:04 +0200 Subject: [PATCH 05/19] Added method to convert a (decimal) String to Long --- src/main/java/com/rometools/utils/Longs.java | 25 ++++++++++++++++++ .../java/com/rometools/utils/LongsTest.java | 26 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/main/java/com/rometools/utils/Longs.java create mode 100644 src/test/java/com/rometools/utils/LongsTest.java diff --git a/src/main/java/com/rometools/utils/Longs.java b/src/main/java/com/rometools/utils/Longs.java new file mode 100644 index 0000000..8a8ce02 --- /dev/null +++ b/src/main/java/com/rometools/utils/Longs.java @@ -0,0 +1,25 @@ +package com.rometools.utils; + +public final class Longs { + + private Longs() { + } + + /** + * Converts a String into a Long by first parsing it as Double and then casting it to Long. + * + * @param s The String to convert, may be null or in decimal format + * @return The parsed Long or null when parsing is not possible + */ + public static Long parseDecimal(final String s) { + Long parsed = null; + try { + if (s != null) { + parsed = (long) Double.parseDouble(s); + } + } catch (final NumberFormatException e) { + } + return parsed; + } + +} diff --git a/src/test/java/com/rometools/utils/LongsTest.java b/src/test/java/com/rometools/utils/LongsTest.java new file mode 100644 index 0000000..79100cb --- /dev/null +++ b/src/test/java/com/rometools/utils/LongsTest.java @@ -0,0 +1,26 @@ +package com.rometools.utils; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +import org.junit.Test; + +public class LongsTest { + + @Test + public void testParseDecimal() { + + final String nullString = null; + final String emptyString = ""; + final String longString = String.valueOf(Long.MAX_VALUE); + final String decimalString = String.valueOf(Double.MAX_VALUE); + + assertThat(Longs.parseDecimal(nullString), is(nullValue())); + assertThat(Longs.parseDecimal(emptyString), is(nullValue())); + assertThat(Longs.parseDecimal(longString), is(Long.MAX_VALUE)); + assertThat(Longs.parseDecimal(decimalString), is((long) Double.MAX_VALUE)); + + } + +} From 7fa58a52348a32a0b16f252fb0c0c72b082c3753 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Fri, 18 Apr 2014 21:35:30 +0200 Subject: [PATCH 06/19] Added method for parsing Doubles --- .../java/com/rometools/utils/Doubles.java | 25 ++++++++++++++++++ .../java/com/rometools/utils/DoublesTest.java | 26 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/main/java/com/rometools/utils/Doubles.java create mode 100644 src/test/java/com/rometools/utils/DoublesTest.java diff --git a/src/main/java/com/rometools/utils/Doubles.java b/src/main/java/com/rometools/utils/Doubles.java new file mode 100644 index 0000000..c3cf6da --- /dev/null +++ b/src/main/java/com/rometools/utils/Doubles.java @@ -0,0 +1,25 @@ +package com.rometools.utils; + +public class Doubles { + + private Doubles() { + } + + /** + * Converts a String into an Double. + * + * @param s The String to convert, may be null + * @return The parsed Double or null when parsing is not possible + */ + public static Double parse(final String s) { + Double parsed = null; + try { + if (s != null) { + parsed = Double.parseDouble(s); + } + } catch (final NumberFormatException e) { + } + return parsed; + } + +} diff --git a/src/test/java/com/rometools/utils/DoublesTest.java b/src/test/java/com/rometools/utils/DoublesTest.java new file mode 100644 index 0000000..f688d80 --- /dev/null +++ b/src/test/java/com/rometools/utils/DoublesTest.java @@ -0,0 +1,26 @@ +package com.rometools.utils; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +import org.junit.Test; + +public class DoublesTest { + + @Test + public void testParse() { + + final String nullString = null; + final String emptyString = null; + final String integerString = "1"; + final String decimalString = "1.0"; + + assertThat(Doubles.parse(nullString), is(nullValue())); + assertThat(Doubles.parse(emptyString), is(nullValue())); + assertThat(Doubles.parse(integerString), is(1.0)); + assertThat(Doubles.parse(decimalString), is(1.0)); + + } + +} From 50425fd263c3a1f2b9a075d093dadb693b9b5e68 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Mon, 28 Apr 2014 17:48:17 +0200 Subject: [PATCH 07/19] Added snapshot repository --- pom.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pom.xml b/pom.xml index b8defa9..7f9d1e7 100644 --- a/pom.xml +++ b/pom.xml @@ -33,6 +33,19 @@ + + + sonatype-nexus-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + false + + + true + + + + junit From 532ff8e6fef2e66fbf2288e3c57bbcdec04d0217 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Tue, 13 May 2014 19:28:52 +0200 Subject: [PATCH 08/19] Formatted and cleaned up sources --- src/main/java/com/rometools/utils/Alternatives.java | 2 +- src/main/java/com/rometools/utils/Integers.java | 2 +- src/main/java/com/rometools/utils/Lists.java | 6 ++++-- src/main/java/com/rometools/utils/Strings.java | 12 ++++++++---- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/rometools/utils/Alternatives.java b/src/main/java/com/rometools/utils/Alternatives.java index cf8fba2..0666233 100644 --- a/src/main/java/com/rometools/utils/Alternatives.java +++ b/src/main/java/com/rometools/utils/Alternatives.java @@ -7,7 +7,7 @@ public final class Alternatives { /** * Returns the first object that is not null - * + * * @param objects The objects to process * @return The first value that is not null. null when there is no not-null value */ diff --git a/src/main/java/com/rometools/utils/Integers.java b/src/main/java/com/rometools/utils/Integers.java index ec5ca85..4046eb9 100644 --- a/src/main/java/com/rometools/utils/Integers.java +++ b/src/main/java/com/rometools/utils/Integers.java @@ -7,7 +7,7 @@ public final class Integers { /** * Converts a String into an Integer. - * + * * @param s The String to convert, may be null * @return The parsed Integer or null when parsing is not possible */ diff --git a/src/main/java/com/rometools/utils/Lists.java b/src/main/java/com/rometools/utils/Lists.java index 3cbdc10..354388b 100644 --- a/src/main/java/com/rometools/utils/Lists.java +++ b/src/main/java/com/rometools/utils/Lists.java @@ -69,11 +69,13 @@ public final class Lists { } /** - * Checks whether the list has the given size. A null list is treated like a list without entries. + * Checks whether the list has the given size. A null list is treated like a list without + * entries. * * @param list The list to check * @param size The size to check - * @return true when the list has the given size or when size = 0 and the list is null, false otherwise + * @return true when the list has the given size or when size = 0 and the list is null, false + * otherwise */ public static boolean sizeIs(final List list, final int size) { if (size == 0) { diff --git a/src/main/java/com/rometools/utils/Strings.java b/src/main/java/com/rometools/utils/Strings.java index 3ac0697..47102c6 100644 --- a/src/main/java/com/rometools/utils/Strings.java +++ b/src/main/java/com/rometools/utils/Strings.java @@ -62,10 +62,12 @@ public final class Strings { } /** - * Removes the whitespace at the beginning and end of a String. When the String only contains whitespace, it returns null. + * Removes the whitespace at the beginning and end of a String. When the String only contains + * whitespace, it returns null. * * @param s The String to trim, may be null - * @return null when the input String is null or does only contain whitespace, the trimmed String otherwise + * @return null when the input String is null or does only contain whitespace, the trimmed + * String otherwise */ public static String trimToNull(final String s) { final String trimmed = trim(s); @@ -77,10 +79,12 @@ public final class Strings { } /** - * Removes the whitespace at the beginning and end of a String. When the String only contains whitespace, it returns null. + * Removes the whitespace at the beginning and end of a String. When the String only contains + * whitespace, it returns null. * * @param s The String to trim, may be null - * @return null when the input String is null or does only contain whitespace, the trimmed String otherwise + * @return null when the input String is null or does only contain whitespace, the trimmed + * String otherwise */ public static String trimToEmpty(final String s) { final String trimmed = trim(s); From 12f7d4d71e16aa4f795a9ebe0167a55cc33757bd Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Tue, 3 Jun 2014 23:43:14 +0200 Subject: [PATCH 09/19] Fixed connection urls --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 7f9d1e7..f01a8f9 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.rometools rome-parent - 1.5.0-SNAPSHOT + 1.5.0 rome-utils @@ -20,8 +20,8 @@ http://rometools.github.io/rome-utils/ - scm:git:git@github.com:rometools/rome-utils.git - scm:git:git@github.com:rometools/rome-utils.git + scm:git:ssh://github.com/rometools/rome-utils.git + scm:git:ssh//git@github.com/rometools/rome-utils.git https://github.com/rometools/rome-utils From cd636e80766f267be22fb4afd9ac06976bfa7eb8 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Tue, 3 Jun 2014 23:46:48 +0200 Subject: [PATCH 10/19] Fixed version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f01a8f9..f10ecbc 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.rometools rome-parent - 1.5.0 + 1.5.0-SNAPSHOT rome-utils From 00762e1ca8aaea294ed8b30b1452ee0fa6644134 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Tue, 3 Jun 2014 23:48:17 +0200 Subject: [PATCH 11/19] Child version must be independent from parent version for releases --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f10ecbc..8f48949 100644 --- a/pom.xml +++ b/pom.xml @@ -7,11 +7,12 @@ com.rometools rome-parent - 1.5.0-SNAPSHOT + 1.5.0 rome-utils jar + 1.5.0-SNAPSHOT rome-utils From ae110720e694ed02fad9c87a79b8a4ceb6636df5 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Tue, 3 Jun 2014 23:50:05 +0200 Subject: [PATCH 12/19] Added missing colon to developerConnection --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8f48949..ba20e42 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ scm:git:ssh://github.com/rometools/rome-utils.git - scm:git:ssh//git@github.com/rometools/rome-utils.git + scm:git:ssh://git@github.com/rometools/rome-utils.git https://github.com/rometools/rome-utils From c4d0b9a69594096422eba9e2b5ff8488d87ae4ef Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Tue, 3 Jun 2014 23:50:51 +0200 Subject: [PATCH 13/19] [maven-release-plugin] prepare release rome-utils-1.5.0 --- pom.xml | 135 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 67 insertions(+), 68 deletions(-) diff --git a/pom.xml b/pom.xml index ba20e42..22f53d5 100644 --- a/pom.xml +++ b/pom.xml @@ -1,69 +1,68 @@ - - - - 4.0.0 - - - com.rometools - rome-parent - 1.5.0 - - - rome-utils - jar - 1.5.0-SNAPSHOT - - rome-utils - - Utility classes for ROME projects - - http://rometools.github.io/rome-utils/ - - - scm:git:ssh://github.com/rometools/rome-utils.git - scm:git:ssh://git@github.com/rometools/rome-utils.git - https://github.com/rometools/rome-utils - - - - - Patrick Gotthard - http://www.patrick-gotthard.de - +1 - - - - - - sonatype-nexus-snapshots - https://oss.sonatype.org/content/repositories/snapshots - - false - - - true - - - - - - - junit - junit - test - - - hamcrest-core - org.hamcrest - - - - - org.hamcrest - hamcrest-all - test - - - + + + + 4.0.0 + + + com.rometools + rome-parent + 1.5.0 + + + rome-utils + jar + 1.5.0 + + rome-utils + + Utility classes for ROME projects + + http://rometools.github.io/rome-utils/ + + + scm:git:ssh://github.com/rometools/rome-utils.git + scm:git:ssh://git@github.com/rometools/rome-utils.git + https://github.com/rometools/rome-utils + + + + + Patrick Gotthard + http://www.patrick-gotthard.de + +1 + + + + + + sonatype-nexus-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + false + + + true + + + + + + + junit + junit + test + + + hamcrest-core + org.hamcrest + + + + + org.hamcrest + hamcrest-all + test + + + \ No newline at end of file From 0d5c0c0535a6115e3f624cf34062eaab221d9339 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Tue, 3 Jun 2014 23:50:56 +0200 Subject: [PATCH 14/19] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 22f53d5..b6e18e5 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ rome-utils jar - 1.5.0 + 1.6.0-SNAPSHOT rome-utils From 4e4e5a8fe35bcbf86acddb5061b7800f82c79dfa Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Tue, 3 Jun 2014 23:57:49 +0200 Subject: [PATCH 15/19] Moved version to the right place --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b6e18e5..47fb510 100644 --- a/pom.xml +++ b/pom.xml @@ -10,8 +10,8 @@ rome-utils - jar 1.6.0-SNAPSHOT + jar rome-utils From 28a5b8f2c767c031d8b2cad2d58eaadfddf37fa0 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Wed, 4 Jun 2014 22:20:02 +0200 Subject: [PATCH 16/19] Prepared next development version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 47fb510..033af3a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.rometools rome-parent - 1.5.0 + 1.6.0-SNAPSHOT rome-utils From 8c2050f8f26fdbb98ffd476bfaf8372055926c5b Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Sat, 7 Feb 2015 09:47:44 +0100 Subject: [PATCH 17/19] Replaced hamcrest-all through hamcrest-library --- pom.xml | 84 +++++++++++++++++++++++++++------------------------------ 1 file changed, 39 insertions(+), 45 deletions(-) diff --git a/pom.xml b/pom.xml index 033af3a..b6b5ed6 100644 --- a/pom.xml +++ b/pom.xml @@ -1,37 +1,37 @@ - - + - 4.0.0 + 4.0.0 - - com.rometools - rome-parent - 1.6.0-SNAPSHOT - + + com.rometools + rome-parent + 1.6.0-SNAPSHOT + - rome-utils - 1.6.0-SNAPSHOT - jar + rome-utils + 1.6.0-SNAPSHOT + jar - rome-utils + rome-utils - Utility classes for ROME projects + Utility classes for ROME projects - http://rometools.github.io/rome-utils/ + http://rometools.github.io/rome-utils/ - - scm:git:ssh://github.com/rometools/rome-utils.git - scm:git:ssh://git@github.com/rometools/rome-utils.git - https://github.com/rometools/rome-utils - + + scm:git:ssh://github.com/rometools/rome-utils.git + scm:git:ssh://git@github.com/rometools/rome-utils.git + https://github.com/rometools/rome-utils + - - - Patrick Gotthard - http://www.patrick-gotthard.de - +1 - - + + + Patrick Gotthard + http://www.patrick-gotthard.de + +1 + + @@ -46,23 +46,17 @@ - - - junit - junit - test - - - hamcrest-core - org.hamcrest - - - - - org.hamcrest - hamcrest-all - test - - - + + + junit + junit + test + + + org.hamcrest + hamcrest-library + test + + + \ No newline at end of file From df7cff28d4dbe4aed95b659d11333e4a47f8ef7e Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Mon, 16 Feb 2015 22:23:38 +0100 Subject: [PATCH 18/19] Added util class to handle I/O operations --- pom.xml | 4 ++ src/main/java/com/rometools/utils/IO.java | 49 +++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 src/main/java/com/rometools/utils/IO.java diff --git a/pom.xml b/pom.xml index b6b5ed6..2945b69 100644 --- a/pom.xml +++ b/pom.xml @@ -47,6 +47,10 @@ + + org.slf4j + slf4j-api + junit junit diff --git a/src/main/java/com/rometools/utils/IO.java b/src/main/java/com/rometools/utils/IO.java new file mode 100644 index 0000000..f92f83f --- /dev/null +++ b/src/main/java/com/rometools/utils/IO.java @@ -0,0 +1,49 @@ +package com.rometools.utils; + +import java.io.Closeable; +import java.io.IOException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Utility class to handle I/O operations. + * + * @author Patrick Gotthard + * + */ +public final class IO { + + private static final Logger LOG = LoggerFactory.getLogger(IO.class); + + private IO() { + } + + /** + * Closes a {@link Closeable} object without suppressing a possible {@link IOException}. + * + * @param closeable The {@link Closeable} to close + * @throws IOException when the {@link Closeable} can't be closed + */ + public static void close(final Closeable closeable) throws IOException { + if (closeable != null) { + closeable.close(); + } + } + + /** + * Closes a {@link Closeable} object and suppresses a possible {@link IOException}. + * + * @param closeable The {@link Closeable} to close + */ + public static void closeQuietly(final Closeable closeable) { + if (closeable != null) { + try { + closeable.close(); + } catch (final IOException e) { + LOG.warn("Unable to close resource", e); + } + } + } + +} From 49568dd3ec366055b2dfa28d53973516d6235dd9 Mon Sep 17 00:00:00 2001 From: mishako Date: Tue, 9 Feb 2016 12:02:57 +0100 Subject: [PATCH 19/19] Add license header to all source files --- .../java/com/rometools/utils/Alternatives.java | 14 ++++++++++++++ src/main/java/com/rometools/utils/Dates.java | 14 ++++++++++++++ src/main/java/com/rometools/utils/Doubles.java | 14 ++++++++++++++ src/main/java/com/rometools/utils/IO.java | 14 ++++++++++++++ src/main/java/com/rometools/utils/Integers.java | 14 ++++++++++++++ src/main/java/com/rometools/utils/Lists.java | 14 ++++++++++++++ src/main/java/com/rometools/utils/Longs.java | 14 ++++++++++++++ src/main/java/com/rometools/utils/Strings.java | 14 ++++++++++++++ .../java/com/rometools/utils/AlternativesTest.java | 14 ++++++++++++++ src/test/java/com/rometools/utils/DatesTest.java | 14 ++++++++++++++ src/test/java/com/rometools/utils/DoublesTest.java | 14 ++++++++++++++ .../java/com/rometools/utils/IntegersTest.java | 14 ++++++++++++++ src/test/java/com/rometools/utils/ListsTest.java | 14 ++++++++++++++ src/test/java/com/rometools/utils/LongsTest.java | 14 ++++++++++++++ src/test/java/com/rometools/utils/StringsTest.java | 14 ++++++++++++++ 15 files changed, 210 insertions(+) diff --git a/src/main/java/com/rometools/utils/Alternatives.java b/src/main/java/com/rometools/utils/Alternatives.java index 0666233..8baea38 100644 --- a/src/main/java/com/rometools/utils/Alternatives.java +++ b/src/main/java/com/rometools/utils/Alternatives.java @@ -1,3 +1,17 @@ +/* + * 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 com.rometools.utils; public final class Alternatives { diff --git a/src/main/java/com/rometools/utils/Dates.java b/src/main/java/com/rometools/utils/Dates.java index 9060e30..c1149f7 100644 --- a/src/main/java/com/rometools/utils/Dates.java +++ b/src/main/java/com/rometools/utils/Dates.java @@ -1,3 +1,17 @@ +/* + * 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 com.rometools.utils; import java.util.Date; diff --git a/src/main/java/com/rometools/utils/Doubles.java b/src/main/java/com/rometools/utils/Doubles.java index c3cf6da..7f4f8fd 100644 --- a/src/main/java/com/rometools/utils/Doubles.java +++ b/src/main/java/com/rometools/utils/Doubles.java @@ -1,3 +1,17 @@ +/* + * 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 com.rometools.utils; public class Doubles { diff --git a/src/main/java/com/rometools/utils/IO.java b/src/main/java/com/rometools/utils/IO.java index f92f83f..7c7c57f 100644 --- a/src/main/java/com/rometools/utils/IO.java +++ b/src/main/java/com/rometools/utils/IO.java @@ -1,3 +1,17 @@ +/* + * 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 com.rometools.utils; import java.io.Closeable; diff --git a/src/main/java/com/rometools/utils/Integers.java b/src/main/java/com/rometools/utils/Integers.java index 4046eb9..8694fdf 100644 --- a/src/main/java/com/rometools/utils/Integers.java +++ b/src/main/java/com/rometools/utils/Integers.java @@ -1,3 +1,17 @@ +/* + * 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 com.rometools.utils; public final class Integers { diff --git a/src/main/java/com/rometools/utils/Lists.java b/src/main/java/com/rometools/utils/Lists.java index 354388b..5beff55 100644 --- a/src/main/java/com/rometools/utils/Lists.java +++ b/src/main/java/com/rometools/utils/Lists.java @@ -1,3 +1,17 @@ +/* + * 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 com.rometools.utils; import java.util.ArrayList; diff --git a/src/main/java/com/rometools/utils/Longs.java b/src/main/java/com/rometools/utils/Longs.java index 8a8ce02..023e1cf 100644 --- a/src/main/java/com/rometools/utils/Longs.java +++ b/src/main/java/com/rometools/utils/Longs.java @@ -1,3 +1,17 @@ +/* + * 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 com.rometools.utils; public final class Longs { diff --git a/src/main/java/com/rometools/utils/Strings.java b/src/main/java/com/rometools/utils/Strings.java index 47102c6..03ab2fd 100644 --- a/src/main/java/com/rometools/utils/Strings.java +++ b/src/main/java/com/rometools/utils/Strings.java @@ -1,3 +1,17 @@ +/* + * 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 com.rometools.utils; import java.util.Locale; diff --git a/src/test/java/com/rometools/utils/AlternativesTest.java b/src/test/java/com/rometools/utils/AlternativesTest.java index ba23641..09dc66f 100644 --- a/src/test/java/com/rometools/utils/AlternativesTest.java +++ b/src/test/java/com/rometools/utils/AlternativesTest.java @@ -1,3 +1,17 @@ +/* + * 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 com.rometools.utils; import static org.hamcrest.Matchers.is; diff --git a/src/test/java/com/rometools/utils/DatesTest.java b/src/test/java/com/rometools/utils/DatesTest.java index d38edcc..5738169 100644 --- a/src/test/java/com/rometools/utils/DatesTest.java +++ b/src/test/java/com/rometools/utils/DatesTest.java @@ -1,3 +1,17 @@ +/* + * 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 com.rometools.utils; import static org.hamcrest.Matchers.is; diff --git a/src/test/java/com/rometools/utils/DoublesTest.java b/src/test/java/com/rometools/utils/DoublesTest.java index f688d80..342f990 100644 --- a/src/test/java/com/rometools/utils/DoublesTest.java +++ b/src/test/java/com/rometools/utils/DoublesTest.java @@ -1,3 +1,17 @@ +/* + * 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 com.rometools.utils; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/src/test/java/com/rometools/utils/IntegersTest.java b/src/test/java/com/rometools/utils/IntegersTest.java index 8fc40db..6893b08 100644 --- a/src/test/java/com/rometools/utils/IntegersTest.java +++ b/src/test/java/com/rometools/utils/IntegersTest.java @@ -1,3 +1,17 @@ +/* + * 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 com.rometools.utils; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/src/test/java/com/rometools/utils/ListsTest.java b/src/test/java/com/rometools/utils/ListsTest.java index dc1b7a8..25e7861 100644 --- a/src/test/java/com/rometools/utils/ListsTest.java +++ b/src/test/java/com/rometools/utils/ListsTest.java @@ -1,3 +1,17 @@ +/* + * 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 com.rometools.utils; import static org.hamcrest.Matchers.hasItem; diff --git a/src/test/java/com/rometools/utils/LongsTest.java b/src/test/java/com/rometools/utils/LongsTest.java index 79100cb..0955cfd 100644 --- a/src/test/java/com/rometools/utils/LongsTest.java +++ b/src/test/java/com/rometools/utils/LongsTest.java @@ -1,3 +1,17 @@ +/* + * 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 com.rometools.utils; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/src/test/java/com/rometools/utils/StringsTest.java b/src/test/java/com/rometools/utils/StringsTest.java index 9983549..ce72aa4 100644 --- a/src/test/java/com/rometools/utils/StringsTest.java +++ b/src/test/java/com/rometools/utils/StringsTest.java @@ -1,3 +1,17 @@ +/* + * 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 com.rometools.utils; import static org.hamcrest.Matchers.is;