Move rome-utils files into a subdirectory

This commit is contained in:
mishako 2016-02-13 18:37:48 +01:00
parent 1f79112706
commit 56a9150d95
21 changed files with 886 additions and 886 deletions

View file

View file

@ -1,37 +1,37 @@
/* /*
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.rometools.utils; package com.rometools.utils;
public final class Alternatives { public final class Alternatives {
private Alternatives() { private Alternatives() {
} }
/** /**
* Returns the first object that is not null * Returns the first object that is not null
* *
* @param objects The objects to process * @param objects The objects to process
* @return The first value that is not null. null when there is no not-null value * @return The first value that is not null. null when there is no not-null value
*/ */
public static <T> T firstNotNull(final T... objects) { public static <T> T firstNotNull(final T... objects) {
for (final T object : objects) { for (final T object : objects) {
if (object != null) { if (object != null) {
return object; return object;
} }
} }
return null; return null;
} }
} }

View file

@ -1,38 +1,38 @@
/* /*
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.rometools.utils; package com.rometools.utils;
import java.util.Date; import java.util.Date;
public final class Dates { public final class Dates {
private Dates() { private Dates() {
} }
/** /**
* Creates a copy on a Date. * Creates a copy on a Date.
* *
* @param d The Date to copy, can be null * @param d The Date to copy, can be null
* @return null when the input Date was null, a copy of the Date otherwise * @return null when the input Date was null, a copy of the Date otherwise
*/ */
public static Date copy(final Date d) { public static Date copy(final Date d) {
if (d == null) { if (d == null) {
return null; return null;
} else { } else {
return new Date(d.getTime()); return new Date(d.getTime());
} }
} }
} }

View file

@ -1,39 +1,39 @@
/* /*
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.rometools.utils; package com.rometools.utils;
public class Doubles { public class Doubles {
private Doubles() { private Doubles() {
} }
/** /**
* Converts a String into an Double. * Converts a String into an Double.
* *
* @param s The String to convert, may be null * @param s The String to convert, may be null
* @return The parsed Double or null when parsing is not possible * @return The parsed Double or null when parsing is not possible
*/ */
public static Double parse(final String s) { public static Double parse(final String s) {
Double parsed = null; Double parsed = null;
try { try {
if (s != null) { if (s != null) {
parsed = Double.parseDouble(s); parsed = Double.parseDouble(s);
} }
} catch (final NumberFormatException e) { } catch (final NumberFormatException e) {
} }
return parsed; return parsed;
} }
} }

View file

@ -1,36 +1,36 @@
/* /*
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.rometools.utils; package com.rometools.utils;
public final class Integers { public final class Integers {
private Integers() { private Integers() {
} }
/** /**
* Converts a String into an Integer. * Converts a String into an Integer.
* *
* @param s The String to convert, may be null * @param s The String to convert, may be null
* @return The parsed Integer or null when parsing is not possible * @return The parsed Integer or null when parsing is not possible
*/ */
public static Integer parse(final String s) { public static Integer parse(final String s) {
try { try {
return Integer.parseInt(s); return Integer.parseInt(s);
} catch (final NumberFormatException e) { } catch (final NumberFormatException e) {
return null; return null;
} }
} }
} }

View file

@ -1,116 +1,116 @@
/* /*
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.rometools.utils; package com.rometools.utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public final class Lists { public final class Lists {
private Lists() { private Lists() {
} }
/** /**
* Returns the list when it is not null. Returns a new list otherwise. * Returns the list when it is not null. Returns a new list otherwise.
* *
* @param list The list to process, can be null * @param list The list to process, can be null
* @return The input list when it is not null, a new list otherwise * @return The input list when it is not null, a new list otherwise
*/ */
public static <T> List<T> createWhenNull(final List<T> list) { public static <T> List<T> createWhenNull(final List<T> list) {
if (list == null) { if (list == null) {
return new ArrayList<T>(); return new ArrayList<T>();
} else { } else {
return list; return list;
} }
} }
/** /**
* Creates a new List with the given item as the first entry. * Creates a new List with the given item as the first entry.
* *
* @param item The item to add to the new list * @param item The item to add to the new list
* @return List containing the given item * @return List containing the given item
*/ */
public static <T> List<T> create(final T item) { public static <T> List<T> create(final T item) {
final List<T> list = new ArrayList<T>(); final List<T> list = new ArrayList<T>();
list.add(item); list.add(item);
return list; return list;
} }
/** /**
* Extracts the first entry of the list when it is not null and contains values. * 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 * @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 * @return The first entry of the list when it is not null or empty, null otherwise
*/ */
public static <T> T firstEntry(final List<T> list) { public static <T> T firstEntry(final List<T> list) {
if (list != null && !list.isEmpty()) { if (list != null && !list.isEmpty()) {
return list.get(0); return list.get(0);
} else { } else {
return null; return null;
} }
} }
/** /**
* Checks whether the list is null or empty. * Checks whether the list is null or empty.
* *
* @param list The list to check * @param list The list to check
* @return true when the list is null or empty, false otherwise * @return true when the list is null or empty, false otherwise
*/ */
public static boolean isEmpty(final List<?> list) { public static boolean isEmpty(final List<?> list) {
return list == null || list.isEmpty(); return list == null || list.isEmpty();
} }
/** /**
* Checks whether the list is not null and not empty. * Checks whether the list is not null and not empty.
* *
* @param list The list to check * @param list The list to check
* @return true when the list is not null and not empty * @return true when the list is not null and not empty
*/ */
public static boolean isNotEmpty(final List<?> list) { public static boolean isNotEmpty(final List<?> list) {
return !isEmpty(list); return !isEmpty(list);
} }
/** /**
* Checks whether the list has the given size. A null list is treated like a list without * Checks whether the list has the given size. A null list is treated like a list without
* entries. * entries.
* *
* @param list The list to check * @param list The list to check
* @param size The size 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 * @return true when the list has the given size or when size = 0 and the list is null, false
* otherwise * otherwise
*/ */
public static boolean sizeIs(final List<?> list, final int size) { public static boolean sizeIs(final List<?> list, final int size) {
if (size == 0) { if (size == 0) {
return list == null || list.isEmpty(); return list == null || list.isEmpty();
} else { } else {
return list != null && list.size() == size; return list != null && list.size() == size;
} }
} }
/** /**
* Returns null, when the given list is empty or null * Returns null, when the given list is empty or null
* *
* @param list The list to process * @param list The list to process
* @return null when the list is empty or null, the given list otherwise * @return null when the list is empty or null, the given list otherwise
*/ */
public static <T> List<T> emptyToNull(final List<T> list) { public static <T> List<T> emptyToNull(final List<T> list) {
if (isEmpty(list)) { if (isEmpty(list)) {
return null; return null;
} else { } else {
return list; return list;
} }
} }
} }

View file

@ -1,39 +1,39 @@
/* /*
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.rometools.utils; package com.rometools.utils;
public final class Longs { public final class Longs {
private Longs() { private Longs() {
} }
/** /**
* Converts a String into a Long by first parsing it as Double and then casting it to Long. * 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 * @param s The String to convert, may be null or in decimal format
* @return The parsed Long or null when parsing is not possible * @return The parsed Long or null when parsing is not possible
*/ */
public static Long parseDecimal(final String s) { public static Long parseDecimal(final String s) {
Long parsed = null; Long parsed = null;
try { try {
if (s != null) { if (s != null) {
parsed = (long) Double.parseDouble(s); parsed = (long) Double.parseDouble(s);
} }
} catch (final NumberFormatException e) { } catch (final NumberFormatException e) {
} }
return parsed; return parsed;
} }
} }

View file

@ -1,126 +1,126 @@
/* /*
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.rometools.utils; package com.rometools.utils;
import java.util.Locale; import java.util.Locale;
public final class Strings { public final class Strings {
private Strings() { private Strings() {
} }
/** /**
* Checks whether a String is null. * Checks whether a String is null.
* *
* @param s The String to check * @param s The String to check
* @return true when the String is null, false otherwise * @return true when the String is null, false otherwise
*/ */
public static boolean isNull(final String s) { public static boolean isNull(final String s) {
return s == null; return s == null;
} }
/** /**
* Checks whether a String is null or empty. * Checks whether a String is null or empty.
* *
* @param s The String to check * @param s The String to check
* @return true when the String is null or empty, false otherwise * @return true when the String is null or empty, false otherwise
*/ */
public static boolean isEmpty(final String s) { public static boolean isEmpty(final String s) {
return isNull(s) || s.isEmpty(); return isNull(s) || s.isEmpty();
} }
/** /**
* Checks whether a String is neither null nor empty. * Checks whether a String is neither null nor empty.
* *
* @param s The String to check * @param s The String to check
* @return true when the String is neither null nor empty, false otherwise * @return true when the String is neither null nor empty, false otherwise
*/ */
public static boolean isNotEmpty(final String s) { public static boolean isNotEmpty(final String s) {
return !isEmpty(s); return !isEmpty(s);
} }
/** /**
* Checks whether a String is null, empty or blank. * Checks whether a String is null, empty or blank.
* *
* @param s The String to check * @param s The String to check
* @return true when the String is null, empty or blank, false otherwise * @return true when the String is null, empty or blank, false otherwise
*/ */
public static boolean isBlank(final String s) { public static boolean isBlank(final String s) {
return isEmpty(s) || s.trim().isEmpty(); return isEmpty(s) || s.trim().isEmpty();
} }
/** /**
* Removes the whitespace at the beginning and end of a String. * Removes the whitespace at the beginning and end of a String.
* *
* @param s The String to trim, may be null * @param s The String to trim, may be null
* @return null when the input String is null, the trimmed String otherwise * @return null when the input String is null, the trimmed String otherwise
*/ */
public static String trim(final String s) { public static String trim(final String s) {
if (s == null) { if (s == null) {
return null; return null;
} else { } else {
return s.trim(); return s.trim();
} }
} }
/** /**
* Removes the whitespace at the beginning and end of a String. When the String only contains * Removes the whitespace at the beginning and end of a String. When the String only contains
* whitespace, it returns null. * whitespace, it returns null.
* *
* @param s The String to trim, may be 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 * @return null when the input String is null or does only contain whitespace, the trimmed
* String otherwise * String otherwise
*/ */
public static String trimToNull(final String s) { public static String trimToNull(final String s) {
final String trimmed = trim(s); final String trimmed = trim(s);
if (trimmed == null || trimmed.isEmpty()) { if (trimmed == null || trimmed.isEmpty()) {
return null; return null;
} else { } else {
return trimmed; return trimmed;
} }
} }
/** /**
* Removes the whitespace at the beginning and end of a String. When the String only contains * Removes the whitespace at the beginning and end of a String. When the String only contains
* whitespace, it returns null. * whitespace, it returns null.
* *
* @param s The String to trim, may be 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 * @return null when the input String is null or does only contain whitespace, the trimmed
* String otherwise * String otherwise
*/ */
public static String trimToEmpty(final String s) { public static String trimToEmpty(final String s) {
final String trimmed = trim(s); final String trimmed = trim(s);
if (trimmed == null || trimmed.isEmpty()) { if (trimmed == null || trimmed.isEmpty()) {
return ""; return "";
} else { } else {
return trimmed; return trimmed;
} }
} }
/** /**
* null-safe lower-case conversion of a String. * null-safe lower-case conversion of a String.
* *
* @param s The String to process, may be null * @param s The String to process, may be null
* @return null when the input String is null, the String in lower-case otherwise * @return null when the input String is null, the String in lower-case otherwise
*/ */
public static String toLowerCase(final String s) { public static String toLowerCase(final String s) {
if (s == null) { if (s == null) {
return null; return null;
} else { } else {
return s.toLowerCase(Locale.ENGLISH); return s.toLowerCase(Locale.ENGLISH);
} }
} }
} }

View file

@ -1,37 +1,37 @@
/* /*
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.rometools.utils; package com.rometools.utils;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import org.junit.Test; import org.junit.Test;
public class AlternativesTest { public class AlternativesTest {
@Test @Test
public void testFirstNotNull() { public void testFirstNotNull() {
final Integer nullInteger = null; final Integer nullInteger = null;
final Integer notNullInteger = 1; final Integer notNullInteger = 1;
assertThat(Alternatives.firstNotNull(notNullInteger, nullInteger), is(notNullInteger)); assertThat(Alternatives.firstNotNull(notNullInteger, nullInteger), is(notNullInteger));
assertThat(Alternatives.firstNotNull(nullInteger, notNullInteger), is(notNullInteger)); assertThat(Alternatives.firstNotNull(nullInteger, notNullInteger), is(notNullInteger));
assertThat(Alternatives.firstNotNull(nullInteger, nullInteger), is(nullValue())); assertThat(Alternatives.firstNotNull(nullInteger, nullInteger), is(nullValue()));
} }
} }

View file

@ -1,40 +1,40 @@
/* /*
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.rometools.utils; package com.rometools.utils;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import java.util.Date; import java.util.Date;
import org.junit.Test; import org.junit.Test;
public class DatesTest { public class DatesTest {
@Test @Test
public void testCopy() { public void testCopy() {
final Date date = new Date(); final Date date = new Date();
final Date nullDate = null; final Date nullDate = null;
assertThat(Dates.copy(date), is(notNullValue())); assertThat(Dates.copy(date), is(notNullValue()));
assertThat(Dates.copy(date).getTime(), is(date.getTime())); assertThat(Dates.copy(date).getTime(), is(date.getTime()));
assertThat(Dates.copy(nullDate), is(nullValue())); assertThat(Dates.copy(nullDate), is(nullValue()));
} }
} }

View file

@ -1,40 +1,40 @@
/* /*
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.rometools.utils; package com.rometools.utils;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.nullValue;
import org.junit.Test; import org.junit.Test;
public class DoublesTest { public class DoublesTest {
@Test @Test
public void testParse() { public void testParse() {
final String nullString = null; final String nullString = null;
final String emptyString = null; final String emptyString = null;
final String integerString = "1"; final String integerString = "1";
final String decimalString = "1.0"; final String decimalString = "1.0";
assertThat(Doubles.parse(nullString), is(nullValue())); assertThat(Doubles.parse(nullString), is(nullValue()));
assertThat(Doubles.parse(emptyString), is(nullValue())); assertThat(Doubles.parse(emptyString), is(nullValue()));
assertThat(Doubles.parse(integerString), is(1.0)); assertThat(Doubles.parse(integerString), is(1.0));
assertThat(Doubles.parse(decimalString), is(1.0)); assertThat(Doubles.parse(decimalString), is(1.0));
} }
} }

View file

@ -1,40 +1,40 @@
/* /*
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.rometools.utils; package com.rometools.utils;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.nullValue;
import org.junit.Test; import org.junit.Test;
public class IntegersTest { public class IntegersTest {
@Test @Test
public void testParse() { public void testParse() {
final String nullString = null; final String nullString = null;
final String emptyString = null; final String emptyString = null;
final String integerString = "1"; final String integerString = "1";
final String decimalString = "1.0"; final String decimalString = "1.0";
assertThat(Integers.parse(nullString), is(nullValue())); assertThat(Integers.parse(nullString), is(nullValue()));
assertThat(Integers.parse(emptyString), is(nullValue())); assertThat(Integers.parse(emptyString), is(nullValue()));
assertThat(Integers.parse(integerString), is(1)); assertThat(Integers.parse(integerString), is(1));
assertThat(Integers.parse(decimalString), is(nullValue())); assertThat(Integers.parse(decimalString), is(nullValue()));
} }
} }

View file

@ -1,119 +1,119 @@
/* /*
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.rometools.utils; package com.rometools.utils;
import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.junit.Test; import org.junit.Test;
public class ListsTest { public class ListsTest {
@Test @Test
public void testCreateWhenNull() { public void testCreateWhenNull() {
final List<Integer> list = new ArrayList<Integer>(); final List<Integer> list = new ArrayList<Integer>();
final List<Integer> nullList = null; final List<Integer> nullList = null;
assertThat(Lists.createWhenNull(list), is(notNullValue())); assertThat(Lists.createWhenNull(list), is(notNullValue()));
assertThat(Lists.createWhenNull(list), is(list)); assertThat(Lists.createWhenNull(list), is(list));
assertThat(Lists.createWhenNull(nullList), is(notNullValue())); assertThat(Lists.createWhenNull(nullList), is(notNullValue()));
} }
@Test @Test
public void testCreate() { public void testCreate() {
final List<Integer> create = Lists.create(1); final List<Integer> create = Lists.create(1);
assertThat(create, is(notNullValue())); assertThat(create, is(notNullValue()));
assertThat(create.size(), is(1)); assertThat(create.size(), is(1));
assertThat(create, hasItem(1)); assertThat(create, hasItem(1));
} }
@Test @Test
public void testFirstEntry() { public void testFirstEntry() {
final List<Integer> nullList = null; final List<Integer> nullList = null;
final List<Integer> listWithoutEntries = new ArrayList<Integer>(); final List<Integer> listWithoutEntries = new ArrayList<Integer>();
final List<Integer> listWithOneEntry = Arrays.asList(1); final List<Integer> listWithOneEntry = Arrays.asList(1);
final List<Integer> listWithTwoEntries = Arrays.asList(1, 2); final List<Integer> listWithTwoEntries = Arrays.asList(1, 2);
assertThat(Lists.firstEntry(nullList), is(nullValue())); assertThat(Lists.firstEntry(nullList), is(nullValue()));
assertThat(Lists.firstEntry(listWithoutEntries), is(nullValue())); assertThat(Lists.firstEntry(listWithoutEntries), is(nullValue()));
assertThat(Lists.firstEntry(listWithOneEntry), is(1)); assertThat(Lists.firstEntry(listWithOneEntry), is(1));
assertThat(Lists.firstEntry(listWithTwoEntries), is(1)); assertThat(Lists.firstEntry(listWithTwoEntries), is(1));
} }
@Test @Test
public void testIsEmpty() { public void testIsEmpty() {
final List<Integer> nullList = null; final List<Integer> nullList = null;
final List<Integer> listWithoutEntries = new ArrayList<Integer>(); final List<Integer> listWithoutEntries = new ArrayList<Integer>();
final List<Integer> listWithOneEntry = Arrays.asList(1); final List<Integer> listWithOneEntry = Arrays.asList(1);
assertThat(Lists.isEmpty(nullList), is(true)); assertThat(Lists.isEmpty(nullList), is(true));
assertThat(Lists.isEmpty(listWithoutEntries), is(true)); assertThat(Lists.isEmpty(listWithoutEntries), is(true));
assertThat(Lists.isEmpty(listWithOneEntry), is(false)); assertThat(Lists.isEmpty(listWithOneEntry), is(false));
} }
@Test @Test
public void testIsNotEmpty() { public void testIsNotEmpty() {
final List<Integer> nullList = null; final List<Integer> nullList = null;
final List<Integer> listWithoutEntries = new ArrayList<Integer>(); final List<Integer> listWithoutEntries = new ArrayList<Integer>();
final List<Integer> listWithOneEntry = Arrays.asList(1); final List<Integer> listWithOneEntry = Arrays.asList(1);
assertThat(Lists.isNotEmpty(nullList), is(false)); assertThat(Lists.isNotEmpty(nullList), is(false));
assertThat(Lists.isNotEmpty(listWithoutEntries), is(false)); assertThat(Lists.isNotEmpty(listWithoutEntries), is(false));
assertThat(Lists.isNotEmpty(listWithOneEntry), is(true)); assertThat(Lists.isNotEmpty(listWithOneEntry), is(true));
} }
@Test @Test
public void testSizeIs() { public void testSizeIs() {
final List<Integer> nullList = null; final List<Integer> nullList = null;
final List<Integer> listWithoutEntries = new ArrayList<Integer>(); final List<Integer> listWithoutEntries = new ArrayList<Integer>();
final List<Integer> listWithOneEntry = Arrays.asList(1); final List<Integer> listWithOneEntry = Arrays.asList(1);
assertThat(Lists.sizeIs(nullList, 0), is(true)); assertThat(Lists.sizeIs(nullList, 0), is(true));
assertThat(Lists.sizeIs(listWithoutEntries, 0), is(true)); assertThat(Lists.sizeIs(listWithoutEntries, 0), is(true));
assertThat(Lists.sizeIs(listWithOneEntry, 1), is(true)); assertThat(Lists.sizeIs(listWithOneEntry, 1), is(true));
} }
@Test @Test
public void testEmptyToNull() { public void testEmptyToNull() {
final List<Integer> nullList = null; final List<Integer> nullList = null;
final List<Integer> listWithoutEntries = new ArrayList<Integer>(); final List<Integer> listWithoutEntries = new ArrayList<Integer>();
final List<Integer> listWithOneEntry = Arrays.asList(1); final List<Integer> listWithOneEntry = Arrays.asList(1);
assertThat(Lists.emptyToNull(nullList), is(nullValue())); assertThat(Lists.emptyToNull(nullList), is(nullValue()));
assertThat(Lists.emptyToNull(listWithoutEntries), is(nullValue())); assertThat(Lists.emptyToNull(listWithoutEntries), is(nullValue()));
assertThat(Lists.emptyToNull(listWithOneEntry), is(notNullValue())); assertThat(Lists.emptyToNull(listWithOneEntry), is(notNullValue()));
} }
} }

View file

@ -1,40 +1,40 @@
/* /*
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.rometools.utils; package com.rometools.utils;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.nullValue;
import org.junit.Test; import org.junit.Test;
public class LongsTest { public class LongsTest {
@Test @Test
public void testParseDecimal() { public void testParseDecimal() {
final String nullString = null; final String nullString = null;
final String emptyString = ""; final String emptyString = "";
final String longString = String.valueOf(Long.MAX_VALUE); final String longString = String.valueOf(Long.MAX_VALUE);
final String decimalString = String.valueOf(Double.MAX_VALUE); final String decimalString = String.valueOf(Double.MAX_VALUE);
assertThat(Longs.parseDecimal(nullString), is(nullValue())); assertThat(Longs.parseDecimal(nullString), is(nullValue()));
assertThat(Longs.parseDecimal(emptyString), is(nullValue())); assertThat(Longs.parseDecimal(emptyString), is(nullValue()));
assertThat(Longs.parseDecimal(longString), is(Long.MAX_VALUE)); assertThat(Longs.parseDecimal(longString), is(Long.MAX_VALUE));
assertThat(Longs.parseDecimal(decimalString), is((long) Double.MAX_VALUE)); assertThat(Longs.parseDecimal(decimalString), is((long) Double.MAX_VALUE));
} }
} }

View file

@ -1,139 +1,139 @@
/* /*
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.rometools.utils; package com.rometools.utils;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import org.junit.Test; import org.junit.Test;
public class StringsTest { public class StringsTest {
@Test @Test
public void testIsNull() { public void testIsNull() {
final String nullString = null; final String nullString = null;
final String emptyString = ""; final String emptyString = "";
final String blankString = " "; final String blankString = " ";
final String string = "a"; final String string = "a";
assertThat(Strings.isNull(nullString), is(true)); assertThat(Strings.isNull(nullString), is(true));
assertThat(Strings.isNull(emptyString), is(false)); assertThat(Strings.isNull(emptyString), is(false));
assertThat(Strings.isNull(blankString), is(false)); assertThat(Strings.isNull(blankString), is(false));
assertThat(Strings.isNull(string), is(false)); assertThat(Strings.isNull(string), is(false));
} }
@Test @Test
public void testIsEmpty() { public void testIsEmpty() {
final String nullString = null; final String nullString = null;
final String emptyString = ""; final String emptyString = "";
final String blankString = " "; final String blankString = " ";
final String string = "a"; final String string = "a";
assertThat(Strings.isEmpty(nullString), is(true)); assertThat(Strings.isEmpty(nullString), is(true));
assertThat(Strings.isEmpty(emptyString), is(true)); assertThat(Strings.isEmpty(emptyString), is(true));
assertThat(Strings.isEmpty(blankString), is(false)); assertThat(Strings.isEmpty(blankString), is(false));
assertThat(Strings.isEmpty(string), is(false)); assertThat(Strings.isEmpty(string), is(false));
} }
@Test @Test
public void testIsNotEmpty() { public void testIsNotEmpty() {
final String nullString = null; final String nullString = null;
final String emptyString = ""; final String emptyString = "";
final String blankString = " "; final String blankString = " ";
final String string = "a"; final String string = "a";
assertThat(Strings.isNotEmpty(nullString), is(false)); assertThat(Strings.isNotEmpty(nullString), is(false));
assertThat(Strings.isNotEmpty(emptyString), is(false)); assertThat(Strings.isNotEmpty(emptyString), is(false));
assertThat(Strings.isNotEmpty(blankString), is(true)); assertThat(Strings.isNotEmpty(blankString), is(true));
assertThat(Strings.isNotEmpty(string), is(true)); assertThat(Strings.isNotEmpty(string), is(true));
} }
@Test @Test
public void testIsBlank() { public void testIsBlank() {
final String nullString = null; final String nullString = null;
final String emptyString = ""; final String emptyString = "";
final String blankString = " "; final String blankString = " ";
final String string = "a"; final String string = "a";
assertThat(Strings.isBlank(nullString), is(true)); assertThat(Strings.isBlank(nullString), is(true));
assertThat(Strings.isBlank(emptyString), is(true)); assertThat(Strings.isBlank(emptyString), is(true));
assertThat(Strings.isBlank(blankString), is(true)); assertThat(Strings.isBlank(blankString), is(true));
assertThat(Strings.isBlank(string), is(false)); assertThat(Strings.isBlank(string), is(false));
} }
@Test @Test
public void testTrim() { public void testTrim() {
final String nullString = null; final String nullString = null;
final String emptyString = ""; final String emptyString = "";
final String blankString = " "; final String blankString = " ";
final String string = " a "; final String string = " a ";
assertThat(Strings.trim(nullString), is(nullValue())); assertThat(Strings.trim(nullString), is(nullValue()));
assertThat(Strings.trim(emptyString), is("")); assertThat(Strings.trim(emptyString), is(""));
assertThat(Strings.trim(blankString), is("")); assertThat(Strings.trim(blankString), is(""));
assertThat(Strings.trim(string), is("a")); assertThat(Strings.trim(string), is("a"));
} }
@Test @Test
public void testTrimToEmpty() { public void testTrimToEmpty() {
final String nullString = null; final String nullString = null;
final String emptyString = ""; final String emptyString = "";
final String blankString = " "; final String blankString = " ";
final String string = " a "; final String string = " a ";
assertThat(Strings.trimToEmpty(nullString), is("")); assertThat(Strings.trimToEmpty(nullString), is(""));
assertThat(Strings.trimToEmpty(emptyString), is("")); assertThat(Strings.trimToEmpty(emptyString), is(""));
assertThat(Strings.trimToEmpty(blankString), is("")); assertThat(Strings.trimToEmpty(blankString), is(""));
assertThat(Strings.trimToEmpty(string), is("a")); assertThat(Strings.trimToEmpty(string), is("a"));
} }
@Test @Test
public void testTrimToNull() { public void testTrimToNull() {
final String nullString = null; final String nullString = null;
final String emptyString = ""; final String emptyString = "";
final String blankString = " "; final String blankString = " ";
final String string = " a "; final String string = " a ";
assertThat(Strings.trimToNull(nullString), is(nullValue())); assertThat(Strings.trimToNull(nullString), is(nullValue()));
assertThat(Strings.trimToNull(emptyString), is(nullValue())); assertThat(Strings.trimToNull(emptyString), is(nullValue()));
assertThat(Strings.trimToNull(blankString), is(nullValue())); assertThat(Strings.trimToNull(blankString), is(nullValue()));
assertThat(Strings.trimToNull(string), is("a")); assertThat(Strings.trimToNull(string), is("a"));
} }
@Test @Test
public void testToLowerCase() { public void testToLowerCase() {
final String nullString = null; final String nullString = null;
final String emptyString = ""; final String emptyString = "";
final String blankString = " "; final String blankString = " ";
final String string = "A"; final String string = "A";
assertThat(Strings.toLowerCase(nullString), is(nullValue())); assertThat(Strings.toLowerCase(nullString), is(nullValue()));
assertThat(Strings.toLowerCase(emptyString), is("")); assertThat(Strings.toLowerCase(emptyString), is(""));
assertThat(Strings.toLowerCase(blankString), is(" ")); assertThat(Strings.toLowerCase(blankString), is(" "));
assertThat(Strings.toLowerCase(string), is("a")); assertThat(Strings.toLowerCase(string), is("a"));
} }
} }