提交 b94fe304 authored 作者: Thomas Mueller's avatar Thomas Mueller

Cleanup:

- add missing //## Java 1.5 end ##
- according to checkstyle final static fields names are all caps
- remove trailing spaces (please configure the IDE accordingly)
- add missing space after comma (please configure checkstyle)

Please note that counter++ is counter.getAndIncrement() and not counter.incrementAndGet(). But I guess this doesn't make a difference here.
上级 0bedabe6
...@@ -25,6 +25,7 @@ import java.util.Map; ...@@ -25,6 +25,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
//## Java 1.5 end ##
/** /**
* Generic utility methods. * Generic utility methods.
...@@ -32,30 +33,30 @@ import java.util.concurrent.atomic.AtomicLong; ...@@ -32,30 +33,30 @@ import java.util.concurrent.atomic.AtomicLong;
public class Utils { public class Utils {
//## Java 1.5 begin ## //## Java 1.5 begin ##
private static final AtomicLong counter = new AtomicLong(0); private static final AtomicLong COUNTER = new AtomicLong(0);
private static final boolean MAKE_ACCESSIBLE = true; private static final boolean MAKE_ACCESSIBLE = true;
private static final int BUFFER_BLOCK_SIZE = 4 * 1024; private static final int BUFFER_BLOCK_SIZE = 4 * 1024;
public static <T> ArrayList<T> newArrayList() { public static <T> ArrayList<T> newArrayList() {
return new ArrayList<T>(); return new ArrayList<T>();
} }
public static <T> ArrayList<T> newArrayList(Collection<T> c) { public static <T> ArrayList<T> newArrayList(Collection<T> c) {
return new ArrayList<T>(c); return new ArrayList<T>(c);
} }
public static <T> HashSet<T> newHashSet() { public static <T> HashSet<T> newHashSet() {
return new HashSet<T>(); return new HashSet<T>();
} }
public static <T> HashSet<T> newHashSet(Collection<T> list) { public static <T> HashSet<T> newHashSet(Collection<T> list) {
return new HashSet<T>(list); return new HashSet<T>(list);
} }
public static <T> Set<T> newConcurrentHashSet() { public static <T> Set<T> newConcurrentHashSet() {
return Collections.newSetFromMap(new ConcurrentHashMap<T,Boolean>()); return Collections.newSetFromMap(new ConcurrentHashMap<T, Boolean>());
} }
public static <A, B> HashMap<A, B> newHashMap() { public static <A, B> HashMap<A, B> newHashMap() {
...@@ -75,35 +76,35 @@ public class Utils { ...@@ -75,35 +76,35 @@ public class Utils {
public static <T> T newObject(Class<T> clazz) { public static <T> T newObject(Class<T> clazz) {
// must create new instances // must create new instances
if (clazz == Integer.class) { if (clazz == Integer.class) {
return (T) new Integer((int) counter.incrementAndGet()); return (T) new Integer((int) COUNTER.incrementAndGet());
} else if (clazz == String.class) { } else if (clazz == String.class) {
return (T) ("" + counter.incrementAndGet()); return (T) ("" + COUNTER.incrementAndGet());
} else if (clazz == Long.class) { } else if (clazz == Long.class) {
return (T) new Long(counter.incrementAndGet()); return (T) new Long(COUNTER.incrementAndGet());
} else if (clazz == Short.class) { } else if (clazz == Short.class) {
return (T) new Short((short) counter.incrementAndGet()); return (T) new Short((short) COUNTER.incrementAndGet());
} else if (clazz == Byte.class) { } else if (clazz == Byte.class) {
return (T) new Byte((byte) counter.incrementAndGet()); return (T) new Byte((byte) COUNTER.incrementAndGet());
} else if (clazz == Float.class) { } else if (clazz == Float.class) {
return (T) new Float(counter.incrementAndGet()); return (T) new Float(COUNTER.incrementAndGet());
} else if (clazz == Double.class) { } else if (clazz == Double.class) {
return (T) new Double(counter.incrementAndGet()); return (T) new Double(COUNTER.incrementAndGet());
} else if (clazz == Boolean.class) { } else if (clazz == Boolean.class) {
return (T) new Boolean(false); return (T) new Boolean(false);
} else if (clazz == BigDecimal.class) { } else if (clazz == BigDecimal.class) {
return (T) new BigDecimal(counter.incrementAndGet()); return (T) new BigDecimal(COUNTER.incrementAndGet());
} else if (clazz == BigInteger.class) { } else if (clazz == BigInteger.class) {
return (T) new BigInteger("" + counter.incrementAndGet()); return (T) new BigInteger("" + COUNTER.incrementAndGet());
} else if (clazz == java.sql.Date.class) { } else if (clazz == java.sql.Date.class) {
return (T) new java.sql.Date(counter.incrementAndGet()); return (T) new java.sql.Date(COUNTER.incrementAndGet());
} else if (clazz == java.sql.Time.class) { } else if (clazz == java.sql.Time.class) {
return (T) new java.sql.Time(counter.incrementAndGet()); return (T) new java.sql.Time(COUNTER.incrementAndGet());
} else if (clazz == java.sql.Timestamp.class) { } else if (clazz == java.sql.Timestamp.class) {
return (T) new java.sql.Timestamp(counter.incrementAndGet()); return (T) new java.sql.Timestamp(COUNTER.incrementAndGet());
} else if (clazz == java.util.Date.class) { } else if (clazz == java.util.Date.class) {
return (T) new java.util.Date(counter.incrementAndGet()); return (T) new java.util.Date(COUNTER.incrementAndGet());
} else if (clazz == List.class) { } else if (clazz == List.class) {
return (T) newArrayList(); return (T) new ArrayList();
} }
try { try {
return clazz.newInstance(); return clazz.newInstance();
...@@ -186,7 +187,7 @@ public class Utils { ...@@ -186,7 +187,7 @@ public class Utils {
throw new RuntimeException("Can not convert the value " + o + throw new RuntimeException("Can not convert the value " + o +
" from " + currentType + " to " + targetType); " from " + currentType + " to " + targetType);
} }
/** /**
* Read a number of characters from a reader and close it. * Read a number of characters from a reader and close it.
* *
...@@ -217,6 +218,6 @@ public class Utils { ...@@ -217,6 +218,6 @@ public class Utils {
in.close(); in.close();
} }
} }
//## Java 1.5 end ## //## Java 1.5 end ##
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论