java实现分组

//返回参数必须包含 错误的List,需要提交的List
public HashMap pass_hours(List<InstanceContentVO> applyList,
InstanceContentVO instancecontentvo) throws ApplicationException {

String message= "";
HashMap map = new HashMap();

List<InstanceContentVO> errorList = new ArrayList<InstanceContentVO>();
List<InstanceContentVO> newList =new ArrayList<InstanceContentVO>();
Comparator c = new ContentComparator();
// 为集合排序
Collections.sort(applyList, c);
Date cFlag = null;

List<ApplyVO> groupList = new ArrayList<ApplyVO>(); //存放不同的组
ApplyVO applyVO = null;
List<InstanceContentVO> contentList = new ArrayList<InstanceContentVO>(); //存放同组记录

for(int i=0;i<applyList.size();i++){

InstanceContentVO vo = applyList.get(i);
Date sdate = conversionDate(vo.getStartDate());


if(i==0 || sdate.before(cFlag) || sdate.after(cFlag) ){ //不同日期

applyVO = new ApplyVO();
contentList = new ArrayList<InstanceContentVO>();
contentList.add(vo);
applyVO.setInstanceContentList(contentList);

groupList.add(applyVO);
cFlag = sdate;

} else {

contentList.add(vo);
applyVO.setInstanceContentList(contentList);


}

}

//对每组的合计时间进行获取和判断
for(int i=0;i<groupList.size();i++){

ApplyVO avo = groupList.get(i);
long groupHour =getGroupHour(avo.getInstanceContentList());//获取各组的合计时间,判断是否满足4小时

if(groupHour<AllowanceConstants.HOLIDAY_ON_SITE_HOUR){//如果小于4小时,那么继续判断是否在系统中有同一天的申报,如果不存在,不可以申报

InstanceContentVO vo=(InstanceContentVO)avo.getInstanceContentList().get(0);
vo.setPayrollId(instancecontentvo.getPayrollId());
vo.setEmployee_id(instancecontentvo.getEmployee_id());
vo.setElement_id(instancecontentvo.getElement_id());

int countRecord=getRecordCount(vo);//判断该员工是否已经有了同一天的申报数据

if(countRecord==0){ // countRecord==0是第一次申报,所以不满足提交的条件,校验不通过,必须添加到错误List,同时从提交list中删除


Iterator it=avo.getInstanceContentList().iterator();

while(it.hasNext()){ //如果该组不符合提交条件,把他们的记录都迭代出放到错误列表中

errorList.add((InstanceContentVO)it.next());


}

message ="errors.oneday.no4Hour";
groupList.remove(i); //整个组从引用中删除
i--;
}

}
}

for(int k=0;k<groupList.size();k++){

ApplyVO applyvo = groupList.get(k);
for(int u=0;u<applyvo.getInstanceContentList().size();u++){


InstanceContentVO icvo = (InstanceContentVO)applyvo.getInstanceContentList().get(u); //获取组的数据
newList.add(icvo);//重新包装申报数据
}
}

map.put("errorList", errorList);
map.put("applyList", newList);
map.put("message", message);
return map;}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
DES(Data Encryption Standard)是一种对称加密算法,它将明文按照一定的规则转换成密文,以保障数据的保密性。下面是使用Java实现DES分组加密算法的示例代码: ```java import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; public class DESExample { private static final String ALGORITHM = "DES"; private static final String CHARSET = "UTF-8"; public static void main(String[] args) throws Exception { String message = "Hello, world!"; String password = "12345678"; // 生成密钥 SecretKey secretKey = generateKey(password); // 加密 byte[] encryptedData = encrypt(message.getBytes(CHARSET), secretKey); System.out.println("Encrypted data: " + new String(encryptedData, CHARSET)); // 解密 byte[] decryptedData = decrypt(encryptedData, secretKey); System.out.println("Decrypted data: " + new String(decryptedData, CHARSET)); } /** * 生成密钥 */ public static SecretKey generateKey(String password) throws NoSuchAlgorithmException { KeyGenerator keyGenerator = KeyGenerator.getInstance(ALGORITHM); SecureRandom secureRandom = new SecureRandom(password.getBytes()); keyGenerator.init(secureRandom); return keyGenerator.generateKey(); } /** * 加密 */ public static byte[] encrypt(byte[] data, SecretKey secretKey) throws Exception { Cipher cipher = Cipher.getInstance(ALGORITHM); cipher.init(Cipher.ENCRYPT_MODE, secretKey); return cipher.doFinal(data); } /** * 解密 */ public static byte[] decrypt(byte[] data, SecretKey secretKey) throws Exception { Cipher cipher = Cipher.getInstance(ALGORITHM); cipher.init(Cipher.DECRYPT_MODE, secretKey); return cipher.doFinal(data); } } ``` 在上面的示例代码中,我们使用了Java自带的`javax.crypto`包中的一些类来实现DES分组加密算法。具体来说,我们使用了`KeyGenerator`类来生成密钥,使用`Cipher`类来进行加密和解密操作。在生成密钥时,我们指定了密钥生成器的算法为DES,并使用了一个随机数生成器来生成密钥。在加密和解密操作时,我们都需要传入一个`SecretKey`对象,这个对象就是我们生成的密钥。 需要注意的是,DES算法的密钥长度为56位,但是Java默认只支持64位的密钥长度。如果想要使用56位的密钥,需要手动将密钥的奇偶校验位去掉,或者使用其他的库来实现。另外,由于DES算法已经被认为不安全,建议使用更加安全的AES算法来进行加密。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值