Skip to content

Instantly share code, notes, and snippets.

View codethereforam's full-sized avatar
:octocat:
Focusing

thinkam codethereforam

:octocat:
Focusing
View GitHub Profile
@codethereforam
codethereforam / StringFormatterUtil.java
Last active July 22, 2018 10:37
Java优雅且高效地格式化字符串
import org.slf4j.helpers.MessageFormatter;
/**
* @author thinkam
* @date 2018/07/22
*/
public class StringFormatterUtil {
/**
* elegant and efficient way to format string
@codethereforam
codethereforam / ListsTransform.java
Created July 26, 2018 11:47
集合转换为其成员变量的集合(before java8)
List<String> nameList = Lists.transform(departmentDtoList, new Function<DepartmentDto, String>() {
@Nullable
@Override
public String apply(@Nullable DepartmentDto input) {
return input != null ? input.getDepartmentName() : null;
}
});
@codethereforam
codethereforam / ArrayListUtil.java
Created July 31, 2018 05:49
去除数组重复元素(不改变原数组),返回ArrayList,并保持原来元素顺序
/**
* 去除数组重复元素(不改变原数组),返回ArrayList,并保持原来元素顺序
*
* @author yanganyu
* @date 2018/7/4 9:27
* @param array 泛型数组
* @return 保持顺序的且元素不重复的ArrayList
*/
public static <T> ArrayList<T> removeDuplicateInOrder(T[] array) {
return new ArrayList<T>(new LinkedHashSet<T>(Arrays.asList(array)));
@codethereforam
codethereforam / ArrayListUtil.java
Created July 31, 2018 05:49
去除数组重复元素(不改变原数组),返回ArrayList,不保持原来元素顺序
/**
* 去除数组重复元素(不改变原数组),返回ArrayList,不保持原来元素顺序
*
* @author yanganyu
* @date 2018/7/4 9:27
* @param array 泛型数组
* @return 元素不重复的ArrayList(不保持原来元素顺序)
*/
public static <T> ArrayList<T> removeDuplicate(T[] array) {
return new ArrayList<T>(new HashSet<T>(Arrays.asList(array)));
@codethereforam
codethereforam / open symlink's real path
Created August 13, 2018 07:01
open a symbolic link's real path in nautilus
@codethereforam
codethereforam / MultimapExample.java
Created October 17, 2018 08:08
Multimap常用例子
// brief (brief = complex)
public List<EnvConfigGroupVo> listEnvConfigGroupVoFrom1(List<EnvConfigVo> envConfigVoList) {
ListMultimap<Integer, EnvConfigVo> multimap = ArrayListMultimap.create();
envConfigVoList.forEach(e -> multimap.put(e.getGroupType(), e));
return multimap.keySet().stream()
.map(k -> new EnvConfigGroupVo(k, EnvConfigGroupTypeEnum.getByValue(k).getDesc(), multimap.get(k)))
.collect(Collectors.toList());
}
// complex
@codethereforam
codethereforam / how-to-remove-remote-idea.md
Last active November 16, 2018 03:50
如何移除远程".idea"
@codethereforam
codethereforam / how-to-improve-code-quality.md
Created November 13, 2018 06:01
如何提高代码质量
  1. 参考一个编程规范
  2. 解决IDE本身检测出来的问题
  3. 使用静态代码扫描工具
  4. 阅读开源框架、库源码
  5. 阅读相关书籍
    • 代码大全
    • 重构
  • 代码整洁之道