Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
calvin1978 committed Jan 24, 2017
1 parent 457b1ae commit 6eadd01
Show file tree
Hide file tree
Showing 44 changed files with 183 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,4 @@ public static boolean or(final boolean... array) {
return BooleanUtils.or(array);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
* @author calvin
*
*/
public abstract class EnumUtil {
public class EnumUtil {

/**
* 将若干个枚举值转换为long,用于使用long保存多个选项的情况.
*/
public static <E extends Enum<E>> long generateBits(final Class<E> enumClass,
final Iterable<? extends E> values) {
public static <E extends Enum<E>> long generateBits(final Class<E> enumClass, final Iterable<? extends E> values) {
return EnumUtils.generateBitVector(enumClass, values);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @author calvin
*/
public abstract class ExceptionUtil {
public class ExceptionUtil {

private static final StackTraceElement[] EMPTY_STACK_TRACE = new StackTraceElement[0];

Expand All @@ -43,14 +43,13 @@ public abstract class ExceptionUtil {
*/
public static RuntimeException unchecked(Throwable t) {

Throwable unwrapped = unwrap(t);
if (unwrapped instanceof RuntimeException) {
throw (RuntimeException) unwrapped;
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
if (unwrapped instanceof Error) {
throw (Error) unwrapped;
if (t instanceof Error) {
throw (Error) t;
}
throw new UncheckedException(unwrapped);
throw new UncheckedException(t);
}

/**
Expand All @@ -71,6 +70,21 @@ public static Throwable unwrap(Throwable t) {
return t;
}

/**
* 组合unchecked与unwrap的效果
*/
public static RuntimeException uncheckedAndWrap(Throwable t) {

Throwable unwrapped = unwrap(t);
if (unwrapped instanceof RuntimeException) {
throw (RuntimeException) unwrapped;
}
if (unwrapped instanceof Error) {
throw (Error) unwrapped;
}
throw new UncheckedException(unwrapped);
}

/**
* 将StackTrace[]转换为String, 供Logger或e.printStackTrace()外的其他地方使用.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
*
* @author calvin
*/
public abstract class Platforms {
public class Platforms {

// 文件路径分隔符
public static final String FILE_PATH_SEPARATOR = File.separator;
public static final char FILE_PATH_SEPARATOR_CHAR = File.separatorChar;
public static final char WINDOWS_FILE_PATH_SEPARATOR_CHAR='\\';
public static final char LINUX_FILE_PATH_SEPARATOR_CHAR='/';
public static final char WINDOWS_FILE_PATH_SEPARATOR_CHAR = '\\';
public static final char LINUX_FILE_PATH_SEPARATOR_CHAR = '/';

// ClassPath分隔符
public static final String CLASS_PATH_SEPARATOR = File.pathSeparator;
Expand Down Expand Up @@ -66,7 +66,7 @@ public static int getPid() {
if (split.length != 2) {
return -1;
}

try {
return Integer.parseInt(split[0]);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @author calvin
*/
public abstract class PropertiesUtil {
public class PropertiesUtil {

private static final Logger logger = LoggerFactory.getLogger(PropertiesUtil.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ArrayUtil {
/**
* 将传入的数组乱序
*/
public final static <T> T[] shuffle(T[] array) {
public static <T> T[] shuffle(T[] array) {
List<T> list = new ArrayList<T>(array.length);
Collections.addAll(list, array);
Collections.shuffle(list);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import org.springside.modules.utils.collection.type.Pair;

import com.google.common.annotations.Beta;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
import com.google.common.collect.Ordering;
Expand All @@ -29,8 +28,7 @@
*
* @see com.google.common.collect.Ordering
*/
@Beta
public abstract class CollectionUtil {
public class CollectionUtil {

/**
* 判断是否为空.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @author calvin
*/
@SuppressWarnings("unchecked")
public abstract class ListUtil {
public class ListUtil {

/**
* 判断是否为空.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* @author calvin
*/
@SuppressWarnings("unchecked")
public abstract class MapUtil {
public class MapUtil {

/**
* 判断是否为空.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* 2.特殊类型Queue:LIFO的Stack, LRU的Queue
*/
public abstract class QueueUtil {
public class QueueUtil {

/**
* 创建ArrayDeque (JDK无ArrayQueue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* 2. 集合运算函数(交集,并集等,from guava)
*/
public abstract class SetUtil {
public class SetUtil {

/**
* 根据等号左边的类型,构造类型正确的HashSet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,33 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
Pair other = (Pair) obj;
if (first == null) {
if (other.first != null)
if (other.first != null) {
return false;
} else if (!first.equals(other.first))
}
} else if (!first.equals(other.first)) {
return false;
}
if (second == null) {
if (other.second != null)
if (other.second != null) {
return false;
} else if (!second.equals(other.second))
}
} else if (!second.equals(other.second)) {
return false;
}
return true;
}

@Override
public String toString() {
return "Pair [first=" + first + ", second=" + second + "]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* 1. 处理了InterruptedException的sleep
*/
public abstract class ThreadUtil {
public class ThreadUtil {

/**
* sleep等待, 单位为毫秒, 已捕捉并处理InterruptedException.
Expand Down Expand Up @@ -50,7 +50,7 @@ public static void handleInterruptedException() {
*/
public static String getCallerClass() {
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
if (stacktrace.length >= 3) {
if (stacktrace.length >= 4) {
StackTraceElement element = stacktrace[3];
return element.getClassName();
} else {
Expand All @@ -63,12 +63,38 @@ public static String getCallerClass() {
*/
public static String getCallerMethod() {
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
if (stacktrace.length >= 3) {
if (stacktrace.length >= 4) {
StackTraceElement element = stacktrace[3];
return element.getClassName() + '.' + element.getMethodName() + "()";
} else {
return StringUtils.EMPTY;
}
}

/**
* 通过StackTrace,获得调用者的类名.
*/
public static String getCurrentClass() {
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
if (stacktrace.length >= 3) {
StackTraceElement element = stacktrace[2];
return element.getClassName();
} else {
return StringUtils.EMPTY;
}
}

/**
* 通过StackTrace,获得当前方法的"类名.方法名()"
*/
public static String getCurrentMethod() {
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
if (stacktrace.length >= 3) {
StackTraceElement element = stacktrace[2];
return element.getClassName() + '.' + element.getMethodName() + "()";
} else {
return StringUtils.EMPTY;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
*/
public class ThreadPoolUtil {



/**
* 按照ExecutorService JavaDoc示例代码编写的Graceful Shutdown方法.
*
Expand Down Expand Up @@ -93,16 +91,16 @@ public static Runnable safeRunnable(@NotNull Runnable runnable) {
* 保证不会有Exception抛出到线程池的Runnable包裹类,防止用户没有捕捉异常导致中断了线程池中的线程, 使得SchedulerService无法执行. 在无法控制第三方包的Runnalbe实现时,使用本类进行包裹.
*/
public static class SafeRunnable implements Runnable {

private static Logger logger = LoggerFactory.getLogger(SafeRunnable.class);

private Runnable runnable;

public SafeRunnable(Runnable runnable) {
Validate.notNull(runnable);
this.runnable = runnable;
}

@Override
public void run() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public boolean select() {
* 采样率为100时,总是返回true
*/
public static class AlwaysSampler extends Sampler {
@Override
public boolean select() {
return true;
}
Expand All @@ -63,6 +64,7 @@ public boolean select() {
* 采样率为0时,总是返回false
*/
public static class NeverSampler extends Sampler {
@Override
public boolean select() {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* @author calvin
*/
public abstract class FilePathUtil {
public class FilePathUtil {

/**
* 在Windows环境里,兼容Windows上的路径分割符,将 '/' 转回 '\'
Expand Down Expand Up @@ -70,10 +70,11 @@ public static String getParentPath(String path) {
parentPath = MoreStringUtil.removeEnd(parentPath, Platforms.FILE_PATH_SEPARATOR_CHAR);

int idx = parentPath.lastIndexOf(Platforms.FILE_PATH_SEPARATOR_CHAR);
if (idx >= 0)
if (idx >= 0) {
parentPath = parentPath.substring(0, idx + 1);
else
} else {
parentPath = Platforms.FILE_PATH_SEPARATOR;
}

return parentPath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public static List<File> listFileWithRegexFileName(final File rootDir, final Str
* 如 ("/a/b/hello.txt", "he.*\.text") 将被返回
*/
public static List<File> listFileWithAntPath(final File rootDir, final String antPathPattern) {
return Files.fileTreeTraverser().preOrderTraversal(rootDir).filter(new AntPathFilter(FilePathUtil.contact(rootDir.getAbsolutePath(), antPathPattern))).toList();
return Files.fileTreeTraverser().preOrderTraversal(rootDir)
.filter(new AntPathFilter(FilePathUtil.contact(rootDir.getAbsolutePath(), antPathPattern))).toList();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @author calvin
*/
public abstract class FileUtil {
public class FileUtil {

//////// 文件读写//////

Expand Down Expand Up @@ -148,8 +148,9 @@ public static void copyDir(@NotNull File from, @NotNull File to) throws IOExcept
if (files != null) {
for (int i = 0; i < files.length; i++) {
String name = files[i].getName();
if (".".equals(name) || "..".equals(name))
if (".".equals(name) || "..".equals(name)) {
continue;
}
copy(files[i], new File(to, name));
}
}
Expand Down Expand Up @@ -182,7 +183,7 @@ public static void moveDir(@NotNull File from, @NotNull File to) throws IOExcept
copyDir(from, to);
deleteDir(from);
if (from.exists()) {
throw new IOException("Failed to delete original directory '" + from + "' after copy to '" + to + "'");
throw new IOException("Failed to delete original directory '" + from + "' after copy to '" + to + '\'');
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @author calvin
*/
@Beta
public abstract class GeneralResourceUtil {
public class GeneralResourceUtil {

public static final String CLASSPATH = "classpath://";

Expand Down
Loading

1 comment on commit 6eadd01

@calvin1978
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有点分不清,哪些是同步ss最新版的,哪些是你改的呀。

Please sign in to comment.