/**
* ==============================================
* Copy right 2015-2018 by ja
* ----------------------------------------------
* This is not a free software, without any authorization is not allowed to use and spread.
* ==============================================
*
* @author : Jalan
* @version : v1.0.0
* @desc : 把对象属性抽象出来,可做为参数传递
* @since : 2018/2/7 21:07
*/
@FunctionalInterface
public interface ObjectPropertyPredicate {
/**
* 把属性当参数传递到方法中,由方法去处理这个属性的值做什么。
* 传参使用: o -> o.propertyName
* 接收参数方法内使用:
* 参数:ObjectPropertyPredicate express
* Predicate
/**
*
* ==============================================
* Copy right 2015-2018 by Jalan
* ----------------------------------------------
* This is not a free software, without any authorization is not allowed to use and spread.
* ==============================================
*
* @author : Jalan
* @version : v1.0.0
* @desc : 查询选项
* @since : 2018/2/7 19:28
*/
public enum FilterModeEnum {
startsWith ,
equals,
contains
}
/**
*
* ==============================================
* Copy right 2015-2018 by Jalan
* ----------------------------------------------
* This is not a free software, without any authorization is not allowed to use and spread.
* ==============================================
*
* @author : Jalan
* @version : v1.0.0
* @desc : 测试实体类
* @since : 2018/2/7 11:58
*/
@ApiModel(description = "测试实体类")
@Data
@EqualsAndHashCode(callSuper = true)
public class TestDataVO{
private String code;
private String name;
private String remark;
}
/**
* 通过批量过滤条件(codes) 过滤指定对象属性的值
* @param dataSource 数据源集合
* @param codes 过滤条件集合
* @param express 过滤集合对象目标属性表达式
* @param filterMode 过滤方式
* @return 返回符合过滤条件codes的对象集合
*/
public static List queryArray(List dataSource, List codes, ObjectPropertyPredicate express, FilterModeEnum filterMode) {
List result = new ArrayList<>();
if (dataSource == null) {
return result;
}
if (codes == null || (long) codes.size() == 0) {
return dataSource;
}
if (express == null) {
return dataSource;
}
if (filterMode == FilterModeEnum.startsWith) {
Predicate expressOr = f -> false;
for (String code : codes) {
Predicate press = (w) -> express.getProperty(w).toString().startsWith(code);
expressOr = expressOr.or(press);
}
result = dataSource.stream().filter(expressOr).collect(Collectors.toList());
} else if (filterMode == FilterModeEnum.contains) {
result = dataSource.stream().filter(f -> codes.contains(express.getProperty(f).toString())).collect(Collectors.toList());
} else if (filterMode == FilterModeEnum.equals) {
Predicate expressOr = f -> false;
for (String code : codes) {
Predicate press = (w) ->StringUtils.equals(express.getProperty(w).toString(),code);
expressOr = expressOr.or(press);
}
result = dataSource.stream().filter(expressOr).collect(Collectors.toList());
}
return result;
}
最后测试:
List data = new ArrayList<>();
TestDataVO td1 = new TestDataVO();
td1.setCode("测试A-code");
td1.setName("测试A-name");
TestDataVO td2 = new TestDataVO();
td2.setCode("测试B-code");
td2.setName("测试B-name");
TestDataVO td3 = new TestDataVO();
td3.setCode("测试C-code");
td3.setName("测试C-name");
TestDataVO td4 = new TestDataVO();
td4.setCode("测试D-code");
td4.setName("测试D-name");
TestDataVO td5= new TestDataVO();
td5.setCode("测试E-code");
td5.setName("测试E-name");
data.add(td1);
data.add(td2);
data.add(td3);
data.add(td4);
data.add(td5);
List filterCodeCondition = ArrayList<>();
filterCodeCondition.add("测试A-code");
filterCodeCondition.add("测试C-code");
/**
* 过滤结果为 td1,td3 对象
*/
List filterResult = queryArray(data,filterCodeCondition , TestDataVO::getCode, FilterModeEnum.startsWith);
List filterNameCondition = ArrayList<>();
filterCodeCondition.add("D-name");
filterCodeCondition.add("E-name");
/**
* 过滤结果为 td4,td5 对象
*/
List filterResult = queryArray(data,filterCodeCondition , TestDataVO::getName, FilterModeEnum.contains);
今天和同事争论一问题,关于静态变量与非静态变量的初始化顺序,谁先谁后,最终想整理出来!测试代码:
import java.util.Map;
public class T {
public static T t = new T();
private Map map = new HashMap();
public T(){
System.out.println(&quo
完整命令
CREATE DATABASE mynewdb USER SYS IDENTIFIED BY sys_password USER SYSTEM IDENTIFIED BY system_password LOGFILE GROUP 1 ('/u01/logs/my/redo01a.log','/u02/logs/m
多线程并发使用同一个channel
java.nio.BufferOverflowException: null
at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:183) ~[na:1.7.0_60-ea]
at java.nio.ByteBuffer.put(ByteBuffer.java:832) ~[na:1.7.0_60-ea]