请教一个问题.现在我有两条List..第一条里面是Hibernate查询返回的temp的pojo的集合.第二条是Hibernate返回的tempClass的pojo的集合.两个不同属性的pojo,但他们都有一个idNo属性是相同的.tempClass里面的list的tempClass pojo的idNo是包含temp里面的list的temp pojo 的idNo的.现在我想把包含temp的list 在包含tempClass的list中remove掉temp中与tempClass 的idNo相同的pojo..现在我用了个嵌套循环.读取idNo进行逐个比较.因为数据量很大.有什么方法可以更快速的排除?本人还是学生刚开始写管理系统,谢谢各位大侠指导一下~
* 经下面操作,listAll的结果变为应该要去上课,而没有在有效时间内打卡的学生
*/
Iterator<Temp> itEffective = listEffective.iterator();
while (itEffective.hasNext()) {
temp = itEffective.next(); for (int count = 0; count < listAll.size(); count++) {
atc = (AbsenceTempClass) listAll.get(count);
if (temp.getIdNo().equals(atc.getIdno())) {
listAll.remove(count);// 此步是删除在有效时间内打卡的学生 }
}
}这是排除了有效打卡的学生下面是pojopackage org.appfuse.model;import java.io.Serializable;
import java.util.Date;
/**
* @struts.form include-all="true" extends="BaseForm"
* @hibernate.class table="Temp"
*
*/
public class Temp extends BaseObject implements Serializable {
private static final long serialVersionUID = -5838248339861940285L;
private Integer tempNo;
private String idNo;
private Date printTime;
private Integer week; public Temp(){
}
/** minimal constructor */
public Temp(Integer tempNo, CourseTime courseTime, String idNo) {
this.tempNo = tempNo;
this.idNo = idNo;
}
public Temp(Integer tempNo,String idNo,Date printTime,CourseTime courseTime,Integer week){
this.tempNo=tempNo;
this.idNo=idNo;
this.printTime=printTime;
this.week=week;
}
/**
*
* @hibernate.id generator-class="increment" type="java.lang.Integer" column="TempNo"
*
*
*/
public Integer getTempNo() {
return tempNo;
} public void setTempNo(Integer tempNo) {
this.tempNo = tempNo;
} /**
*
* @hibernate.property column="IDNo" length="18"
*
*/
public String getIdNo() {
return idNo;
} public void setIdNo(String idNo) {
this.idNo = idNo;
}
/**
* @hibernate.property column="PrintTime" length="25"
*/
public Date getPrintTime() {
return printTime;
} public void setPrintTime(Date printTime) {
this.printTime = printTime;
} /**
* @hibernate.property column="Week" length="4"
*/
public Integer getWeek() {
return week;
} public void setWeek(Integer week) {
this.week = week;
}
public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( (other == null ) ) return false;
if ( !(other instanceof Temp) ) return false;
Temp castOther = ( Temp ) other;
return ( (this.getTempNo()==castOther.getTempNo()) || ( this.getTempNo()!=null && castOther.getTempNo()!=null && this.getTempNo().equals(castOther.getTempNo()) ) )
&& ( (this.getIdNo()==castOther.getIdNo()) || ( this.getIdNo()!=null && castOther.getIdNo()!=null && this.getIdNo().equals(castOther.getIdNo()) ) )
&&( (this.getPrintTime()==castOther.getPrintTime()) || ( this.getPrintTime()!=null && castOther.getPrintTime()!=null && this.getPrintTime().equals(castOther.getPrintTime()) ) )
&& ( (this.getWeek()==castOther.getWeek()) || ( this.getWeek()!=null && castOther.getWeek()!=null && this.getWeek().equals(castOther.getWeek()) ) ); }
public int hashCode() {
int result = 17;
result = 37 * result + ( getTempNo() == null ? 0 : this.getTempNo().hashCode() );
result = 37 * result + ( getIdNo() == null ? 0 : this.getIdNo().hashCode() );
result = 37 * result + ( getPrintTime() == null ? 0 : this.getPrintTime().hashCode() );
result = 37 * result + ( getWeek() == null ? 0 : this.getWeek().hashCode() );
return result;
}
public String toString() {
StringBuffer buffer = new StringBuffer(); buffer.append(getClass().getName()).append("@").append(Integer.toHexString(hashCode())).append(" [");
buffer.append("IDNo").append("='").append(getIdNo()).append("' ");
buffer.append("PrintTime").append("='").append(getPrintTime()).append("'");
buffer.append("Week").append("='").append(getWeek()).append("'");
buffer.append("]");
return buffer.toString();
}}package org.appfuse.model;/**
* 功能:临时缺勤记录
* */
public class AbsenceTempClass {
String studentId;
String courseNo;
String teacherNo;
String gradeId;
String idno;
public String getIdno() {
return idno;
} public void setIdno(String idno) {
this.idno = idno;
} public AbsenceTempClass(){
}
public AbsenceTempClass(String studentId,String StudentName,
String studentSex,String courseName,String teacherName,
String className,String grade){
}
public String getStudentId() {
return studentId;
}
public void setStudentId(String studentId) {
this.studentId = studentId;
} public String getCourseNo() {
return courseNo;
} public void setCourseNo(String courseNo) {
this.courseNo = courseNo;
} public String getGradeId() {
return gradeId;
} public void setGradeId(String gradeId) {
this.gradeId = gradeId;
} public String getTeacherNo() {
return teacherNo;
} public void setTeacherNo(String teacherNo) {
this.teacherNo = teacherNo;
}
}
if(list.contains(idNo)) {
list.remove();
}
List listEl = tempMgr.getElectiveHaveClass(String.valueOf(ct.getCourseTimeNo()), weekNumber[0], weekNumber[1], currentDateTime); // 查出有课且无请假的学生 必修课
List listRequest = tempMgr.getRequiredHaveClass(String.valueOf(ct.getCourseTimeNo()), weekNumber[0], weekNumber[1], academicYear, currentGradeTerm[0], currentGradeTerm[1], currentGradeTerm[2], currentDateTime);
//查出调课表中当天且当前时段被调课的学生
List listCourseTransfer = tempMgr.getCourseTransfer(date.format(new Date()), String.valueOf(ct.getCourseTimeNo())); // 有效时间内打卡的学生
String[] timeRce = readCardInEffectiveTimeTime(ct.getCourseTimeNo(), ct.getBeginClass(), ct.getOverClass());
List listEffective = tempMgr.getReadCardInEffectiveTime(timeRce[0], timeRce[1], timeRce[2], timeRce[3]);
其他早退,迟到那些方法省略了, 因为只要把正常出勤的排除了.其他数量就不大了.
list.get(0).getIdNo();应该可以拿到