GithubHelp home page GithubHelp logo

feilong-core's Introduction

feilong-core 2系列将不在维护, 请移步到 feilong 3版本,地址 https://github.com/ifeilong/feilong

feilong core 让Java开发更简便的工具包

License JDK 1.7 jar size 110K javadoc 83% tests 2259 Coverage 91%

sonar

Reduce development, Release ideas (减少开发,释放**)

focus on J2SE,是 feilong platform 核心项目

详细帮助文档参见 http://feilong-core.mydoc.io/

1.简介:

  1. 让你从大量重复的底层代码中脱身,提高工作效率;
  2. 让你的代码更简炼易写易读易于维护;

2.feilong-core 优点:

对比1:

对比2:

  1. 有常用的工具类 (如 处理日期的 DateUtil,处理 集合 的 CollectionsUtil 等)
  2. 有常用的JAVA常量类 (如日期格式 DatePattern, 时间间隔 TimeInterval 等)
  3. 不必要的Exception 转成了RuntimeException,减少不必要的代码
  4. 国内中文注释最完善的API
  5. 有完善的单元测试

3.一图概述:

one-feilong-core

这里有详细的帮助文档 http://feilong-core.mydoc.io/

4.:dragon: Maven使用配置

feilong-core jar你可以直接在 仓库 浏览

如果你使用 maven, 您可以通过以下方式来配置 pom.xml:

<project>

	....
	<properties>
		<version.feilong-platform>2.1.0</version.feilong-platform>
		....
	</properties>

	....
	<repositories>
		<repository>
			<id>feilong-repository</id>
			<url>https://raw.github.com/venusdrogon/feilong-platform/repository</url>
		</repository>
	</repositories>

	....
	<dependencies>
		....
		<dependency>
			<groupId>com.feilong.platform</groupId>
			<artifactId>feilong-core</artifactId>
			<version>${version.feilong-platform}</version>
		</dependency>
		....
	</dependencies>
	....
</project>

此外强烈建议你使用 feilong 工具类全家桶(含IO操作,Net操作,Json,XML,自定义标签等等工具类)

<project>

	....
	<properties>
		<version.feilong-platform>2.1.0</version.feilong-platform>
		....
	</properties>

	....
	<repositories>
		<repository>
			<id>feilong-repository</id>
			<url>https://raw.github.com/venusdrogon/feilong-platform/repository</url>
		</repository>
	</repositories>

	....
	<dependencies>
		....
		<dependency>
			<groupId>com.feilong.platform</groupId>
			<artifactId>feilong-util-all</artifactId>
			<version>${version.feilong-platform}</version>
		</dependency>
		....
	</dependencies>
	....
</project>

5. How to install?

有些小伙伴想下载并 自行install 进行研究, 你需要执行以下 4 个步骤:

git clone https://github.com/venusdrogon/feilong-platform.git --depth 1
mvn install -f feilong-platform/pom.xml

git clone https://github.com/venusdrogon/feilong-core.git --depth 1
mvn install -f feilong-core/pom.xml

详细参考 https://github.com/venusdrogon/feilong-core/wiki/install

6. Proxying feilong Repositories with Nexus

如果你使用 Sonatype's Nexus repository manager, 你可能想要在Nexus configuration配置中将 feilong repositories 添加到 nexus proxy repositories.

下面是注意点:

  • 由于 feilong repositories 没有索引. 你需要将 Remote Repository Access > Download Remote Indexes 设置为 false.
  • 由于 GitHub 对于 raw repository url目录不会生成目录列表 , 请将 Nexus Remote Repository Access > Auto blocking active 设置为 false.

上面两步操作之后, 你可以看到 Repository Status 变成了 Attempting to Proxy and Remote Unavailable.

Nexus 在缺失目录列表的情况下仍然可以访问指定的 artifact, pom 和其他文件 .

示例:

nexus-config.jpg

7.帮助:

8.sonar 扫描

sonar

9.:memo: 说明

  1. 基于 Apache2 协议,您可以下载代码用于闭源项目,但每个修改的过的文件必须放置版权说明;
  2. require-jdk-version
  3. dependencies

10.Q&A

10.1 Q1:这是重复造轮子吗?

A: https://github.com/venusdrogon/feilong-core/wiki/Repeat-the-wheel

11.:cyclone: feilong 即时交流

QQ 群 243306798

12:panda_face: About

如果您对本项目有任何建议和批评,可以使用下面的联系方式:

feilong-core's People

Contributors

venusdrogon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

feilong-core's Issues

可以将ResourceBundleUtil readAllPropertiesToMap(ResourceBundle) 方法移动到ConvertUtil 里面

目前方法在 com.feilong.core.util.ResourceBundleUtil.readAllPropertiesToMap(ResourceBundle)

    public static Map<String, String> readAllPropertiesToMap(ResourceBundle resourceBundle){
        Validate.notNull(resourceBundle, "resourceBundle can't be null!");

        Enumeration<String> keysEnumeration = resourceBundle.getKeys();
        if (Validator.isNullOrEmpty(keysEnumeration)){
            return Collections.emptyMap();
        }

        Map<String, String> propertyMap = new TreeMap<String, String>();
        while (keysEnumeration.hasMoreElements()){
            String key = keysEnumeration.nextElement();
            propertyMap.put(key, resourceBundle.getString(key));
        }
        return propertyMap;
    }

PropertiesUtil 支持解析 xml格式的 Properties

目前代码仅支持 普通的 .Properties 文件

    public static Properties getProperties(InputStream inputStream){
        Validate.notNull(inputStream, "inputStream can't be null!");
        Properties properties = new Properties();
        try{
            properties.load(inputStream);
            return properties;
        }catch (IOException e){
            throw new UncheckedIOException(e);
        }
    }

可以借鉴 spring org.springframework.core.io.support.PropertiesLoaderUtils

public static Properties loadAllProperties(String resourceName, ClassLoader classLoader) throws IOException {
        Assert.notNull(resourceName, "Resource name must not be null");
        ClassLoader classLoaderToUse = classLoader;
        if (classLoaderToUse == null) {
            classLoaderToUse = ClassUtils.getDefaultClassLoader();
        }
        Enumeration<URL> urls = (classLoaderToUse != null ? classLoaderToUse.getResources(resourceName) :
                ClassLoader.getSystemResources(resourceName));
        Properties props = new Properties();
        while (urls.hasMoreElements()) {
            URL url = urls.nextElement();
            URLConnection con = url.openConnection();
            ResourceUtils.useCachesIfNecessary(con);
            InputStream is = con.getInputStream();
            try {
                if (resourceName != null && resourceName.endsWith(XML_FILE_EXTENSION)) {
                    props.loadFromXML(is);
                }
                else {
                    props.load(is);
                }
            }
            finally {
                is.close();
            }
        }
        return props;
    }

ClassLoaderUtil.getResource(ClassLoader, String) 增加路径容错功能

基于classLoader 查找资源, 通常不需要 根路径 /

比如 假设配置文件在 src/main/resources下面,比如 messages/feilong-core-message_en_US.properties,

需要这么写 "messages/feilong-core-message_en_US.properties",
ClassLoaderJVM会使用BootstrapLoader去加载资源文件.
所以路径还是这种相对于工程的根目录即"messages/feilong-core-message_en_US.properties" 不需要"/"

但是很多时候会误写,如果写成 "/messages/feilong-core-message_en_US.properties", 就加载不到资源

这方面 spring的 org.springframework.core.io.ClassPathResource 做的很好,可以借鉴

    private static URL getResource(ClassLoader classLoader,String resourceName){
        Validate.notNull(classLoader, "classLoader can't be null!");
        Validate.notNull(resourceName, "resourceName can't be null!");
        return classLoader.getResource(resourceName);
    }

URIUtil.decodeISO88591String(String, String) 通常是解析 HttpServletRequest才会用到, 可以移到feilong-servlet包

    /**
     * {@link CharsetType#ISO_8859_1} 的方式去除乱码.
     * 
     * <p>
     * {@link CharsetType#ISO_8859_1} 是JAVA网络传输使用的标准 字符集
     * </p>
     * 
     * <h3></h3>
     * 
     * <blockquote>
     * <ul>
     * <li>tomcat server.xml Connector URIEncoding="UTF-8"</li>
     * <li>{@code <fmt:requestEncoding value="UTF-8"/>}</li>
     * </ul>
     * </blockquote>
     *
     * @param str
     *            字符串
     * @param charsetType
     *            使用的编码,see {@link CharsetType}
     * @return 如果 <code>str</code> 是null或者empty,返回 {@link StringUtils#EMPTY}<br>
     * @see "org.apache.commons.codec.net.URLCodec#encode(String, String)"
     * @see "org.apache.taglibs.standard.tag.common.fmt.RequestEncodingSupport"
     * @see "org.apache.catalina.filters.SetCharacterEncodingFilter"
     */
    @Deprecated
    public static String decodeISO88591String(String str,String charsetType){
        return Validator.isNullOrEmpty(str) ? StringUtils.EMPTY
                        : StringUtil.newString(StringUtil.getBytes(str, CharsetType.ISO_8859_1), charsetType);
    }

这个方法 一般用在 feilong-servlet module 里面

    public static String getRequestFullURL(HttpServletRequest request,String charsetType){
        String requestURL = getRequestURL(request);
        String queryString = request.getQueryString();
        return Validator.isNullOrEmpty(queryString) ? requestURL
                        : requestURL + URIComponents.QUESTIONMARK + URIUtil.decodeISO88591String(queryString, charsetType);
    }

可以移到这个方法 下面 或者有其他优化方法

ClassUtil.loadClass(String) 和 ClassUtil.getClass(String) 感觉重复了 ,可以去掉一个

ClassUtil.loadClass(String)ClassUtil.getClass(String) 感觉重复了 ,可以去掉一个

ClassUtil.getClass(String)

    public static Class<?> getClass(String className){
        Validate.notBlank(className, "className can't be blank!");
        try{
            return org.apache.commons.lang3.ClassUtils.getClass(className);
        }catch (ClassNotFoundException e){
            throw new ReflectException(e);
        }
    }

ClassUtil.loadClass(String)

    public static Class<?> loadClass(String className){
        Validate.notBlank(className, "className can't be blank!");
        try{
            return Class.forName(className);
        }catch (ClassNotFoundException e){
            throw new ReflectException(e);
        }
    }

优化 com.feilong.core.util.RegexUtil.group(String, CharSequence) 方法的日志

优化 com.feilong.core.util.RegexUtil.group(String, CharSequence) 方法的日志

08:30 DEBUG (RegexUtil.java:124) [group()] 
    regexPattern:[(.*?)@(.*?)],
    input:[venusdrogon@163.com]
08:30 DEBUG (RegexUtil.java:129) [group()] matcher.start(0):[0],matcher.end(0):[19]
08:30 DEBUG (RegexUtil.java:133) [group()] matcher.start(1):[0],matcher.end(1):[11]
08:30 DEBUG (RegexUtil.java:133) [group()] matcher.start(2):[12],matcher.end(2):[19]
08:30 DEBUG (RegexUtil.java:138) [group()] groupMap:    {
        "0": "[email protected]",
        "1": "venusdrogon",
        "2": "163.com"
    }

现在的日志 可以优化

StringUtil.replace 不应该使用 CharSequence 做为参数

StringUtil.replace 不应该使用 CharSequence 做为参数

    public static String replace(CharSequence content,CharSequence target,CharSequence replacement){
        return null == content ? StringUtils.EMPTY
                        : content.toString().replace(target, null == replacement ? StringUtils.EMPTY : replacement);
    }

代码里面依旧再转换,并且 commons-lang org.apache.commons.lang3.StringUtils.replace(String, String, String) 使用的是原生的 String 做参数

单元测试类,优化对 list map的单元测试

目前的单元测试的 对list 以及map的单元测试 还比较原始, 直接使用 jsonutil format

自从 JUnit 4.4 之后, 新增了 新的断言语法(Assertion syntax)—— assertThat

可以使用 里面的 相关语法和特性

DateExtensionUtil getIntervalForView支持 月 年更大的单位

com.feilong.core.date.DateExtensionUtil.getIntervalForView(long)

        StringBuilder sb = new StringBuilder();
        if (0 != spaceDay){
            sb.append(spaceDay + DAY);
        }
        if (0 != spaceHour){
            sb.append(spaceHour + HOUR);
        }
        if (0 != spaceMinute){
            sb.append(spaceMinute + MINUTE);
        }
        if (0 != spaceSecond){
            sb.append(spaceSecond + SECOND);
        }
        if (0 != spaceMillisecond){
            sb.append(spaceMillisecond + MILLISECOND);
        }

目前代码里面最大单位仅支持到 天, 可以支持到月 到年

DateExtensionUtil 可以新增 getIntervalForView(Date beginDate) 方法

目前大部分代码都是这样写的

        Date beginDate = new Date();

        //do some logic 

        LOGGER.info("time:{}", getIntervalForView(beginDate, new Date()));

其实可以封装 getIntervalForView(Date beginDate) 仅需要一个参数的方法, 而内部调用 getIntervalForView(beginDate, new Date()) 减少代码

可以创建AbstractJsonValueProcessor

下面3个类, 有重复的代码

BigDecimalJsonValueProcessor
DateJsonValueProcessor
SensitiveWordsJsonValueProcessor

 public Object processArrayValue(Object value,JsonConfig jsonConfig){
        return process(value);
    }


    public Object processObjectValue(String key,Object value,JsonConfig jsonConfig){
        return process(value);
    }

这些方法 可以提取到 AbstractJsonValueProcessor 类里面去

新增按照指定字符串的顺序来排序的Comparator

比如现在有一组的尺码乱序的,

String[] strs = { "XL", "S", "M", "XS", "S", "M", "L", "XL" };

现在也有固定顺序的 尺码字符串组

private static final String[] REFER_ORDER_ARRAY = { "XS", "S", "M", "L", "XL" };

要求上面的乱序尺码按照这个尺码字符串排序

如果乱码的尺码组,有尺码不在指定的尺码组里面, 那么排在最后

json-lib 换成 jackson

目前feilong-core 使用的 json-lib 作为 json处理工具 其主页: http://json-lib.sourceforge.net/

json-lib

但是 json-lib 自从 就不再维护了 (Last Published: 12/14/2010)

而且 json-lib 自身依赖的jar 版本都比较老

commons-lang 2.5
commons-beanutils 1.8.0
commons-collections 3.2.1
commons-logging 1.1.1
ezmorph 1.0.6

image

jackson

而jackson 目前社区很活跃 其主页是: https://github.com/FasterXML/jackson
相比json-lib框架,Jackson所依赖的jar包较少,简单易用并且性能也要相对高些。而且Jackson社区相对比较活跃,更新速度也比较快。

这里有性能对比 :

http://wangym.iteye.com/blog/738933
http://www.tuicool.com/articles/2a2eAb

这种测试报告均显示 jackson 性能更好

RegexUtil.group(String, CharSequence) 方法 可以使用LOGGER.trace 替代 LOGGER.debug

group 方法使用的是 debug 级别 log

    public static Map<Integer, String> group(String regexPattern,CharSequence input){
        Matcher matcher = getMatcher(regexPattern, input);
        if (!matcher.matches()){
            LOGGER.debug("[not matches] ,\n\tregexPattern:[{}] \n\tinput:[{}]", regexPattern, input);
            return Collections.emptyMap();
        }
        int groupCount = matcher.groupCount();
        Map<Integer, String> map = MapUtil.newLinkedHashMap(groupCount + 1);
        for (int i = 0; i <= groupCount; ++i){
            //匹配的索引
            String groupValue = matcher.group(i); //map.put(0, matcher.group());// 捕获组是从 1 开始从左到右的索引.组0表示整个模式,因此表达式 m.group(0) 等效于 m.group().
            LOGGER.debug("matcher group[{}],start-end:[{}-{}],groupValue:[{}]", i, matcher.start(i), matcher.end(i), groupValue);
            map.put(i, groupValue);//groupValue
        }

        if (LOGGER.isDebugEnabled()){
            LOGGER.debug("regexPattern:[{}],input:[{}],groupMap:{}", regexPattern, input, JsonUtil.format(map));
        }
        return map;
    }

http://programmers.stackexchange.com/questions/279690/why-does-the-trace-level-exist-and-when-should-i-use-it-rather-than-debug

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.