您的位置:首页 > 其它

工作总结(一)

2012-07-18 17:49 183 查看
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());
}
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: