aboutsummaryrefslogtreecommitdiffstats
path: root/javaparser-core/src/main/java/com/github/javaparser/utils
diff options
context:
space:
mode:
Diffstat (limited to 'javaparser-core/src/main/java/com/github/javaparser/utils')
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/utils/ClassUtils.java16
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/utils/Pair.java13
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java107
3 files changed, 66 insertions, 70 deletions
diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/ClassUtils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/ClassUtils.java
index 476986812..9a948d713 100644
--- a/javaparser-core/src/main/java/com/github/javaparser/utils/ClassUtils.java
+++ b/javaparser-core/src/main/java/com/github/javaparser/utils/ClassUtils.java
@@ -8,6 +8,7 @@ public class ClassUtils {
* Maps primitive {@code Class}es to their corresponding wrapper {@code Class}.
*/
private static final Map<Class<?>, Class<?>> primitiveWrapperMap = new HashMap<Class<?>, Class<?>>();
+
static {
primitiveWrapperMap.put(Boolean.TYPE, Boolean.class);
primitiveWrapperMap.put(Byte.TYPE, Byte.class);
@@ -24,6 +25,7 @@ public class ClassUtils {
* Maps wrapper {@code Class}es to their corresponding primitive types.
*/
private static final Map<Class<?>, Class<?>> wrapperPrimitiveMap = new HashMap<Class<?>, Class<?>>();
+
static {
for (final Class<?> primitiveClass : primitiveWrapperMap.keySet()) {
final Class<?> wrapperClass = primitiveWrapperMap.get(primitiveClass);
@@ -38,11 +40,9 @@ public class ClassUtils {
* {@link Character},
* {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}).
*
- * @param type
- * The class to query or null.
- * @return true if the given {@code type} is a primitive or primitive wrapper ({@link Boolean}, {@link Byte},
- * {@link Character},
- * {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}).
+ * @param type The class to query or null.
+ * @return true if the given {@code type} is a primitive or primitive wrapper ({@link Boolean}, {@link Byte}, {@link
+ * Character}, {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}).
*/
public static boolean isPrimitiveOrWrapper(final Class<?> type) {
if (type == null) {
@@ -56,11 +56,9 @@ public class ClassUtils {
* {@link Short},
* {@link Integer}, {@link Long}, {@link Double}, {@link Float}).
*
- * @param type
- * The class to query or null.
+ * @param type The class to query or null.
* @return true if the given {@code type} is a primitive wrapper ({@link Boolean}, {@link Byte}, {@link Character},
- * {@link Short},
- * {@link Integer}, {@link Long}, {@link Double}, {@link Float}).
+ * {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}).
* @since 3.1
*/
public static boolean isPrimitiveWrapper(final Class<?> type) {
diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/Pair.java b/javaparser-core/src/main/java/com/github/javaparser/utils/Pair.java
index 40ce85d83..cf459b604 100644
--- a/javaparser-core/src/main/java/com/github/javaparser/utils/Pair.java
+++ b/javaparser-core/src/main/java/com/github/javaparser/utils/Pair.java
@@ -2,15 +2,16 @@ package com.github.javaparser.utils;
/**
* Simply a pair of objects.
+ *
* @param <A> type of object a.
* @param <B> type of object b.
*/
public class Pair<A, B> {
- public final A a;
- public final B b;
+ public final A a;
+ public final B b;
- public Pair(A a, B b) {
- this.a = a;
- this.b = b;
- }
+ public Pair(A a, B b) {
+ this.a = a;
+ this.b = b;
+ }
}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java
index d91b99c73..8f9ef853b 100644
--- a/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java
+++ b/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java
@@ -23,11 +23,7 @@ package com.github.javaparser.utils;
import java.io.IOException;
import java.io.Reader;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
+import java.util.*;
/**
* Any kind of utility.
@@ -35,62 +31,63 @@ import java.util.List;
* @author Federico Tomassetti
*/
public class Utils {
- public static final String EOL = System.getProperty("line.separator");
- public static <T> List<T> ensureNotNull(List<T> list) {
- return list == null ? new ArrayList<>() : list;
- }
+ public static final String EOL = System.getProperty("line.separator");
- public static <E> boolean isNullOrEmpty(Collection<E> collection) {
- return collection == null || collection.isEmpty();
- }
+ public static <T> List<T> ensureNotNull(List<T> list) {
+ return list == null ? new ArrayList<>() : list;
+ }
+ public static <E> boolean isNullOrEmpty(Collection<E> collection) {
+ return collection == null || collection.isEmpty();
+ }
- public static <T> T assertNotNull(T o) {
- if (o == null) {
- throw new AssertionError("A reference was unexpectedly null.");
- }
- return o;
- }
- /**
- * @return string with ASCII characters 10 and 13 replaced by the text "\n" and "\r".
- */
- public static String escapeEndOfLines(String string) {
- StringBuilder escapedString = new StringBuilder();
- for (char c : string.toCharArray()) {
- switch (c) {
- case '\n':
- escapedString.append("\\n");
- break;
- case '\r':
- escapedString.append("\\r");
- break;
- default:
- escapedString.append(c);
- }
- }
- return escapedString.toString();
- }
+ public static <T> T assertNotNull(T o) {
+ if (o == null) {
+ throw new AssertionError("A reference was unexpectedly null.");
+ }
+ return o;
+ }
- public static String readerToString(Reader reader) throws IOException {
- final StringBuilder result = new StringBuilder();
- final char[] buffer = new char[8 * 1024];
- int numChars;
+ /**
+ * @return string with ASCII characters 10 and 13 replaced by the text "\n" and "\r".
+ */
+ public static String escapeEndOfLines(String string) {
+ StringBuilder escapedString = new StringBuilder();
+ for (char c : string.toCharArray()) {
+ switch (c) {
+ case '\n':
+ escapedString.append("\\n");
+ break;
+ case '\r':
+ escapedString.append("\\r");
+ break;
+ default:
+ escapedString.append(c);
+ }
+ }
+ return escapedString.toString();
+ }
- while ((numChars = reader.read(buffer, 0, buffer.length)) > 0) {
- result.append(buffer, 0, numChars);
- }
+ public static String readerToString(Reader reader) throws IOException {
+ final StringBuilder result = new StringBuilder();
+ final char[] buffer = new char[8 * 1024];
+ int numChars;
- return result.toString();
- }
+ while ((numChars = reader.read(buffer, 0, buffer.length)) > 0) {
+ result.append(buffer, 0, numChars);
+ }
- /**
- * Puts varargs in a mutable list.
- * This does not have the disadvantage of Arrays#asList that it has a static size.
- */
- public static <T> List<T> arrayToList(T[] array){
- List<T> list = new LinkedList<>();
- Collections.addAll(list, array);
- return list;
- }
+ return result.toString();
+ }
+
+ /**
+ * Puts varargs in a mutable list.
+ * This does not have the disadvantage of Arrays#asList that it has a static size.
+ */
+ public static <T> List<T> arrayToList(T[] array) {
+ List<T> list = new LinkedList<>();
+ Collections.addAll(list, array);
+ return list;
+ }
}