com.anwen.mongo.toolkit.ObjectIdUtil Maven / Gradle / Ivy
package com.anwen.mongo.toolkit;
import com.anwen.mongo.cache.global.PropertyCache;
import org.bson.types.ObjectId;
import java.util.Collection;
import java.util.Collections;
import java.util.stream.Collectors;
public class ObjectIdUtil {
/**
* 转换单个ObjectId
*/
public static Object convertObjectId(T id) {
if (id == null) {
return null;
}
String strId = String.valueOf(id);
if (ObjectId.isValid(strId)) {
return new ObjectId(strId);
}
return id;
}
/**
* 批量转换ObjectId
*/
public static Collection