工作总结(一)

1、List是否为空

List<Integer>  list = new Array<Integer>();
if (CollectionUtils.isEmpty(userOtfList)) {
	break;
}

如果返回null或empty,返回true。

2、Key为key的map在map中是否存在

Map<String,List<Integer>> map= new HashMap<String,List<Integer>>();
if(!map.containsKey(String.valueOf(key))){
	map.put(String.valueOf(outfitId), new ArrayList<Integer>());
}

3、System.currentTimeMillis();

从1970年1月1日到现在的毫秒数,常用于游戏时间的相关设定,跟线程执行有很大的相关性。

4、Java中Comparator的用法

①实体类Step

package com.ljq.entity;


/**
 * 运号单流程
 * 
 * @author Administrator
 * 
 */
public class Step{
    /** 处理时间 */
    private String acceptTime = "";
    /** 快件所在地点 */
    private String acceptAddress = "";

    public Step() {
        super();
    }

    public Step(String acceptTime, String acceptAddress) {
        super();
        this.acceptTime = acceptTime;
        this.acceptAddress = acceptAddress;
    }

    public String getAcceptTime() {
        return acceptTime;
    }

    public void setAcceptTime(String acceptTime) {
        this.acceptTime = acceptTime;
    }

    public String getAcceptAddress() {
        return acceptAddress;
    }

    public void setAcceptAddress(String acceptAddress) {
        this.acceptAddress = acceptAddress;
    }

}
②实现Comparator接口
package com.ljq.entity;

import java.util.Comparator;
import java.util.Date;

import com.ljq.util.UtilTool;

/**
 * 对Step类进行排序
 * 
 * @author Administrator
 *
 */
public class StepComparator implements Comparator<Step>{

    /**
     * 如果o1小于o2,返回一个负数;如果o1大于o2,返回一个正数;如果他们相等,则返回0;
     */
    @Override
    public int compare(Step o1, Step o2) {
        Date acceptTime1=UtilTool.strToDate(o1.getAcceptTime(), null);
        Date acceptTime2=UtilTool.strToDate(o2.getAcceptTime(), null);
        
        //对日期字段进行升序,如果欲降序可采用before方法
        if(acceptTime1.after(acceptTime2)) return 1;
        return -1;
    }

}
③测试
package junit;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.junit.Test;


public class StepComparatorTest {

    @Test
    public void sort() throws Exception{
        List<Step> steps=new ArrayList<Step>;
        //对集合对象进行排序
         StepComparator comparator=new StepComparator();
        Collections.sort(steps, comparator);
        if(steps!=null&&steps.size()>0){
            for(Step step:steps){
               System.out.println(step.getAcceptAddress());
               System.out.println(step.getAcceptTime());
            }
        }

    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值