org.apache.commons.collections4.ListUtils Java Examples

The following examples show how to use org.apache.commons.collections4.ListUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseAction.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
protected <T extends JpaObject> String idlePortalName(Business business, String name, String excludeId)
		throws Exception {
	if (StringUtils.isEmpty(name)) {
		return "";
	}
	List<String> list = new ArrayList<>();
	list.add(name);
	for (int i = 1; i < 99; i++) {
		list.add(name + String.format("%02d", i));
	}
	list.add(StringTools.uniqueToken());
	EntityManager em = business.entityManagerContainer().get(Portal.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Portal> root = cq.from(Portal.class);
	Predicate p = root.get(Portal_.name).in(list);
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	cq.select(root.get(Portal_.name)).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example #2
Source File: ActionCover.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private <T extends JpaObject> String idleNameWithAppInfo(Business business, String appId, String name,
		Class<T> cls, String excludeId) throws Exception {
	if (StringUtils.isEmpty(name)) {
		return "";
	}
	List<String> list = new ArrayList<>();
	list.add(name);
	for (int i = 1; i < 99; i++) {
		list.add(name + String.format("%02d", i));
	}
	list.add(StringTools.uniqueToken());
	EntityManager em = business.entityManagerContainer().get(cls);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<T> root = cq.from(cls);
	Predicate p = root.get("name").in(list);
	p = cb.and(p, cb.equal(root.get("appId"), appId));
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	cq.select(root.get("name")).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example #3
Source File: AbstractGroups.java    From syncope with Apache License 2.0 6 votes vote down vote up
public <T extends AnyTO> AbstractGroups(final AnyWrapper<T> modelObject) {
    super();
    this.anyTO = modelObject.getInnerObject();

    setOutputMarkupId(true);

    groupsContainer = new WebMarkupContainer("groupsContainer");
    groupsContainer.setOutputMarkupId(true);
    groupsContainer.setOutputMarkupPlaceholderTag(true);
    add(groupsContainer);

    // ------------------
    // insert changed label if needed
    // ------------------
    if (modelObject instanceof UserWrapper
            && UserWrapper.class.cast(modelObject).getPreviousUserTO() != null
            && !ListUtils.isEqualList(
                    UserWrapper.class.cast(modelObject).getInnerObject().getMemberships(),
                    UserWrapper.class.cast(modelObject).getPreviousUserTO().getMemberships())) {
        groupsContainer.add(new LabelInfo("changed", StringUtils.EMPTY));
    } else {
        groupsContainer.add(new Label("changed", StringUtils.EMPTY));
    }
    // ------------------
}
 
Example #4
Source File: ActionCover.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 根据id 和 alias属性,查询重复的对象,适用Dict、Form、Scrpt
 * @param business
 * @param id
 * @param alias
 * @param cls
 * @param excludeId
 * @return
 * @throws Exception
 */
private <T extends JpaObject> String idleAliasWithEntity(Business business, String id, String alias,
		Class<T> cls, String excludeId) throws Exception {
	if (StringUtils.isEmpty(alias)) {
		return "";
	}
	List<String> list = new ArrayList<>();
	list.add(alias);
	for (int i = 1; i < 99; i++) {
		list.add(alias + String.format("%02d", i));
	}
	list.add(StringTools.uniqueToken());
	EntityManager em = business.entityManagerContainer().get(cls);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<T> root = cq.from(cls);
	Predicate p = root.get("alias").in( list );
	p = cb.and(p, cb.equal(root.get("id"), id));
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	cq.select(root.get("alias")).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example #5
Source File: ActionCover.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 根据id 和 name属性,查询重复的对象,适用CategoryInfo
 * @param business
 * @param id
 * @param name
 * @param cls
 * @param excludeId
 * @return
 * @throws Exception
 */
private <T extends JpaObject> String idleNameWithCategory(Business business, String id, String name,
		Class<T> cls, String excludeId) throws Exception {
	if (StringUtils.isEmpty(name)) {
		return "";
	}
	List<String> list = new ArrayList<>();
	list.add(name);
	for (int i = 1; i < 99; i++) {
		list.add(name + String.format("%02d", i));
	}
	list.add(StringTools.uniqueToken());
	EntityManager em = business.entityManagerContainer().get( CategoryInfo.class );
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<CategoryInfo> root = cq.from(CategoryInfo.class);
	Predicate p = root.get( CategoryInfo_.categoryName ).in(list);
	p = cb.and(p, cb.equal(root.get( CategoryInfo_.id ), id));
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	cq.select(root.get( CategoryInfo_.categoryName  )).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example #6
Source File: ActionCover.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 根据id 和 alias属性,查询重复的对象,适用CategoryInfo
 * @param business
 * @param id
 * @param alias
 * @param cls
 * @param excludeId
 * @return
 * @throws Exception
 */
private <T extends JpaObject> String idleAliasWithCategory(Business business, String id, String alias,
		Class<T> cls, String excludeId) throws Exception {
	if (StringUtils.isEmpty(alias)) {
		return "";
	}
	List<String> list = new ArrayList<>();
	list.add(alias);
	for (int i = 1; i < 99; i++) {
		list.add(alias + String.format("%02d", i));
	}
	list.add(StringTools.uniqueToken());
	EntityManager em = business.entityManagerContainer().get(CategoryInfo.class );
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<CategoryInfo> root = cq.from(CategoryInfo.class);
	Predicate p = root.get( CategoryInfo_.categoryAlias ).in( list );
	p = cb.and(p, cb.equal(root.get(CategoryInfo_.id ), id));
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	cq.select(root.get(CategoryInfo_.categoryAlias)).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example #7
Source File: BaseAction.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
protected <T extends JpaObject> String idleAppInfoName(Business business, String name, String excludeId)
		throws Exception {
	if (StringUtils.isEmpty(name)) {
		return "";
	}
	List<String> list = new ArrayList<>();
	list.add(name);
	for (int i = 1; i < 99; i++) {
		list.add(name + String.format("%02d", i));
	}
	list.add(StringTools.uniqueToken());
	EntityManager em = business.entityManagerContainer().get(AppInfo.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<AppInfo> root = cq.from(AppInfo.class);
	Predicate p = root.get(AppInfo_.appName).in(list);
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	cq.select(root.get(AppInfo_.appName)).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example #8
Source File: WorkLogTree.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public WorkLogTree(List<WorkLog> list) throws Exception {

		for (WorkLog o : list) {
			this.nodes().add(new Node(o));
		}

		List<String> froms = ListTools.extractProperty(list, WorkLog.fromActivityToken_FIELDNAME, String.class, true,
				true);
		List<String> arriveds = ListTools.extractProperty(list, WorkLog.arrivedActivityToken_FIELDNAME, String.class,
				true, true);
		List<String> values = ListUtils.subtract(froms, arriveds);
		WorkLog begin = list.stream()
				.filter(o -> BooleanUtils.isTrue(o.getConnected()) && values.contains(o.getFromActivityToken()))
				.findFirst().orElse(null);
		if (null == begin) {
			throw new ExceptionBeginNotFound();
		}
		root = this.find(begin);
//		for (Node o : nodes) {
//			this.associate();
//		}
		this.associate();
	}
 
Example #9
Source File: ActionCover.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private <T extends JpaObject> String idleNameWithApplication(Business business, String applicationId, String name,
		Class<T> cls, String excludeId) throws Exception {
	if (StringUtils.isEmpty(name)) {
		return "";
	}
	List<String> list = new ArrayList<>();
	list.add(name);
	for (int i = 1; i < 99; i++) {
		list.add(name + String.format("%02d", i));
	}
	list.add(StringTools.uniqueToken());
	EntityManager em = business.entityManagerContainer().get(cls);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<T> root = cq.from(cls);
	Predicate p = root.get("name").in(list);
	p = cb.and(p, cb.equal(root.get("application"), applicationId));
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	cq.select(root.get("name")).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example #10
Source File: FieldCode.java    From nuls with MIT License 6 votes vote down vote up
public FieldCode(FieldNode fieldNode) {
    access = fieldNode.access;
    name = fieldNode.name;
    desc = fieldNode.desc;
    signature = fieldNode.signature;
    value = fieldNode.value;
    visibleAnnotations = ListUtils.emptyIfNull(fieldNode.visibleAnnotations);
    invisibleAnnotations = ListUtils.emptyIfNull(fieldNode.invisibleAnnotations);
    visibleTypeAnnotations = ListUtils.emptyIfNull(fieldNode.visibleTypeAnnotations);
    invisibleTypeAnnotations = ListUtils.emptyIfNull(fieldNode.invisibleTypeAnnotations);
    attrs = ListUtils.emptyIfNull(fieldNode.attrs);
    //
    variableType = VariableType.valueOf(desc);
    isStatic = (access & Opcodes.ACC_STATIC) != 0;
    isFinal = (access & Opcodes.ACC_FINAL) != 0;
    isSynthetic = (access & Opcodes.ACC_SYNTHETIC) != 0;
}
 
Example #11
Source File: VtrackHandler.java    From prebid-server-java with Apache License 2.0 6 votes vote down vote up
private List<PutObject> vtrackPuts(RoutingContext context) {
    final Buffer body = context.getBody();
    if (body == null || body.length() == 0) {
        throw new IllegalArgumentException("Incoming request has no body");
    }

    final BidCacheRequest bidCacheRequest;
    try {
        bidCacheRequest = mapper.decodeValue(body, BidCacheRequest.class);
    } catch (DecodeException e) {
        throw new IllegalArgumentException("Failed to parse request body", e);
    }

    final List<PutObject> putObjects = ListUtils.emptyIfNull(bidCacheRequest.getPuts());
    for (PutObject putObject : putObjects) {
        if (StringUtils.isEmpty(putObject.getBidid())) {
            throw new IllegalArgumentException("'bidid' is required field and can't be empty");
        }
        if (StringUtils.isEmpty(putObject.getBidder())) {
            throw new IllegalArgumentException("'bidder' is required field and can't be empty");
        }
    }
    return putObjects;
}
 
Example #12
Source File: BidResponseCreator.java    From prebid-server-java with Apache License 2.0 6 votes vote down vote up
private static Map<String, List<ExtHttpCall>> toExtHttpCalls(List<BidderResponse> bidderResponses,
                                                             CacheServiceResult cacheResult) {
    final Map<String, List<ExtHttpCall>> bidderHttpCalls = bidderResponses.stream()
            .collect(Collectors.toMap(BidderResponse::getBidder,
                    bidderResponse -> ListUtils.emptyIfNull(bidderResponse.getSeatBid().getHttpCalls())));

    final CacheHttpCall httpCall = cacheResult.getHttpCall();
    final ExtHttpCall cacheExtHttpCall = httpCall != null ? toExtHttpCall(httpCall) : null;
    final Map<String, List<ExtHttpCall>> cacheHttpCalls = cacheExtHttpCall != null
            ? Collections.singletonMap(CACHE, Collections.singletonList(cacheExtHttpCall))
            : Collections.emptyMap();

    final Map<String, List<ExtHttpCall>> httpCalls = new HashMap<>();
    httpCalls.putAll(bidderHttpCalls);
    httpCalls.putAll(cacheHttpCalls);
    return httpCalls.isEmpty() ? null : httpCalls;
}
 
Example #13
Source File: PrivacyEnforcementService.java    From prebid-server-java with Apache License 2.0 6 votes vote down vote up
private Set<String> extractCcpaEnforcedBidders(List<String> bidders, BidRequest bidRequest, BidderAliases aliases) {
    final Set<String> ccpaEnforcedBidders = new HashSet<>(bidders);

    final ExtBidRequest extBidRequest = requestExt(bidRequest);
    final ExtRequestPrebid extRequestPrebid = extBidRequest != null ? extBidRequest.getPrebid() : null;
    final List<String> nosaleBidders = extRequestPrebid != null
            ? ListUtils.emptyIfNull(extRequestPrebid.getNosale())
            : Collections.emptyList();

    if (nosaleBidders.size() == 1 && nosaleBidders.contains(CATCH_ALL_BIDDERS)) {
        ccpaEnforcedBidders.clear();
    } else {
        ccpaEnforcedBidders.removeAll(nosaleBidders);
    }

    ccpaEnforcedBidders.removeIf(bidder ->
            !bidderCatalog.bidderInfoByName(aliases.resolveBidder(bidder)).isCcpaEnforced());

    return ccpaEnforcedBidders;
}
 
Example #14
Source File: TaskResultCreator.java    From scheduling with GNU Affero General Public License v3.0 6 votes vote down vote up
private Map<String, byte[]> extractTaskResultsAndMergeIntoMap(SchedulerDBManager dbManager,
        EligibleTaskDescriptor eligibleTaskDescriptor, InternalJob job) {
    Map<String, byte[]> mergedVariables = new HashMap<>();

    int numberOfParentTasks = eligibleTaskDescriptor.getParents().size();
    List<TaskId> parentIds = new ArrayList<>(numberOfParentTasks);
    for (int i = 0; i < numberOfParentTasks; i++) {
        parentIds.add(eligibleTaskDescriptor.getParents().get(i).getTaskId());
    }

    // Batch fetching of parent tasks results
    Map<TaskId, TaskResult> taskResults = new HashMap<>();
    for (List<TaskId> parentsSubList : ListUtils.partition(new ArrayList<>(parentIds),
                                                           PASchedulerProperties.SCHEDULER_DB_FETCH_TASK_RESULTS_BATCH_SIZE.getValueAsInt())) {
        taskResults.putAll(dbManager.loadTasksResults(job.getId(), parentsSubList));
    }

    for (TaskResult taskResult : taskResults.values()) {
        if (taskResult.getPropagatedVariables() != null) {
            mergedVariables.putAll(taskResult.getPropagatedVariables());
        }
    }
    return mergedVariables;
}
 
Example #15
Source File: BaseAction.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public String adjustFileName(Business business, String job, String fileName) throws Exception {
	List<String> list = new ArrayList<>();
	list.add(fileName);
	String base = FilenameUtils.getBaseName(fileName);
	String extension = FilenameUtils.getExtension(fileName);
	for (int i = 1; i < 50; i++) {
		list.add(base + i + (StringUtils.isEmpty(extension) ? "" : "." + extension));
	}
	list.add(StringTools.uniqueToken());
	EntityManager em = business.entityManagerContainer().get(Attachment.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Attachment> root = cq.from(Attachment.class);
	Predicate p = root.get(Attachment_.name).in(list);
	p = cb.and(p, cb.equal(root.get(Attachment_.job), job));
	cq.select(root.get(Attachment_.name)).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example #16
Source File: BaseAction.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
protected <T extends JpaObject> String idleQueryName(Business business, String name, String excludeId)
		throws Exception {
	if (StringUtils.isEmpty(name)) {
		return "";
	}
	List<String> list = new ArrayList<>();
	list.add(name);
	for (int i = 1; i < 99; i++) {
		list.add(name + String.format("%02d", i));
	}
	list.add(StringTools.uniqueToken());
	EntityManager em = business.entityManagerContainer().get(Query.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Query> root = cq.from(Query.class);
	Predicate p = root.get(Query_.name).in(list);
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	cq.select(root.get(Query_.name)).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example #17
Source File: ActionCover.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private <T extends JpaObject> String idleNameWithPortal(Business business, String portalId, String name,
		Class<T> cls, String excludeId) throws Exception {
	if (StringUtils.isEmpty(name)) {
		return "";
	}
	List<String> list = new ArrayList<>();
	list.add(name);
	for (int i = 1; i < 99; i++) {
		list.add(name + String.format("%02d", i));
	}
	list.add(StringTools.uniqueToken());
	EntityManager em = business.entityManagerContainer().get(cls);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<T> root = cq.from(cls);
	Predicate p = root.get("name").in(list);
	p = cb.and(p, cb.equal(root.get("portal"), portalId));
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	cq.select(root.get("name")).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example #18
Source File: ResultBuilder.java    From feilong-taglib with Apache License 2.0 6 votes vote down vote up
/**
 * 拼接.
 *
 * @param itemSrcList
 *            the item src list
 * @param template
 *            the template
 * @param standardHttpConcatParam
 *            the standard http concat param
 * @return the string
 * @since 1.11.1
 */
private static String handlerConcat(List<String> itemSrcList,String template,HttpConcatParam standardHttpConcatParam){
    Integer autoPartitionSize = GLOBAL_CONFIG.getAutoPartitionSize();
    //不需要分片
    if (null == autoPartitionSize || itemSrcList.size() <= autoPartitionSize){
        return MessageFormatUtil.format(template, ConcatLinkResolver.resolver(itemSrcList, standardHttpConcatParam));
    }

    //---------------------------------------------------------------
    //since 1.12.6
    //将 list 分成 N 份
    List<List<String>> groupList = ListUtils.partition(itemSrcList, autoPartitionSize);

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < groupList.size(); ++i){
        sb.append("<!-- HttpConcatTag,auto partition [" + (i + 1) + "] -->");
        sb.append(lineSeparator());

        sb.append(MessageFormatUtil.format(template, ConcatLinkResolver.resolver(groupList.get(i), standardHttpConcatParam)));
        sb.append(lineSeparator());
    }
    return sb.toString();
}
 
Example #19
Source File: TestListenJobLogs.java    From scheduling with GNU Affero General Public License v3.0 6 votes vote down vote up
public synchronized void waitForLoggingEvent(long timeout, String... expectedMessages)
        throws InterruptedException {
    List<String> expectedMessagesList = new ArrayList<>(expectedMessages.length);

    Collections.addAll(expectedMessagesList, expectedMessages);

    System.out.println("Waiting for logging events with messages: " + expectedMessagesList + " (" + name + ")");

    long endTime = System.currentTimeMillis() + timeout;
    while (!ListUtils.removeAll(expectedMessagesList, actualMessages).isEmpty()) {
        long waitTime = endTime - System.currentTimeMillis();
        if (waitTime > 0) {
            wait(100);
        } else {
            break;
        }
    }

    Assert.assertTrue("Didn't receive expected events, expected: " + expectedMessagesList + ", actual: " +
                      actualMessages, ListUtils.removeAll(expectedMessagesList, actualMessages).isEmpty());
    actualMessages.clear();
}
 
Example #20
Source File: ActionCover.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private <T extends JpaObject> String idleNameWithPortal(Business business, String portalId, String name,
		Class<T> cls, String excludeId) throws Exception {
	if (StringUtils.isEmpty(name)) {
		return "";
	}
	List<String> list = new ArrayList<>();
	list.add(name);
	for (int i = 1; i < 99; i++) {
		list.add(name + String.format("%02d", i));
	}
	list.add(StringTools.uniqueToken());
	EntityManager em = business.entityManagerContainer().get(cls);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<T> root = cq.from(cls);
	Predicate p = root.get("name").in(list);
	p = cb.and(p, cb.equal(root.get("portal"), portalId));
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	cq.select(root.get("name")).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example #21
Source File: ActionCover.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 根据id 和 name属性,查询重复的对象,适用Dict、Form、Scrpt
 * @param business
 * @param name
 * @param cls
 * @param excludeId
 * @return
 * @throws Exception
 */
private <T extends JpaObject> String idleNameWithEntity(Business business, String name,
		Class<T> cls, String excludeId) throws Exception {
	if (StringUtils.isEmpty(name)) {
		return "";
	}
	List<String> list = new ArrayList<>();
	list.add(name);
	for (int i = 1; i < 99; i++) {
		list.add(name + String.format("%02d", i));
	}
	list.add(StringTools.uniqueToken());
	EntityManager em = business.entityManagerContainer().get(cls);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<T> root = cq.from(cls);
	Predicate p = root.get("name").in(list);
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	cq.select(root.get("name")).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example #22
Source File: Occasion.java    From sample-acmegifts with Eclipse Public License 1.0 5 votes vote down vote up
public static BasicDBList listToDBList(List<Contribution> contributions) {
  String method = "listToString";
  logger.entering(clazz, method);
  BasicDBList dbl = new BasicDBList();
  for (Contribution contribution : ListUtils.emptyIfNull(contributions)) {
    dbl.add(contribution.toDbo());
  }
  logger.exiting(clazz, method);
  return dbl;
}
 
Example #23
Source File: PluginExtensionsAndVersionValidatorImpl.java    From gocd with Apache License 2.0 5 votes vote down vote up
private void validateExtensionVersions(ValidationResult validationResult, String extensionType, List<Double> gocdSupportedExtensionVersions, List<String> requiredExtensionVersionsByPlugin) {
    final List<Double> requiredExtensionVersions = requiredExtensionVersionsByPlugin.stream()
            .map(parseToDouble())
            .collect(toList());

    final List<Double> intersection = ListUtils.intersection(gocdSupportedExtensionVersions, requiredExtensionVersions);

    if (intersection.isEmpty()) {
        validationResult.addError(format(UNSUPPORTED_VERSION_ERROR_MESSAGE, extensionType, requiredExtensionVersionsByPlugin, gocdSupportedExtensionVersions));
    }
}
 
Example #24
Source File: RelatedConceptsController.java    From find with MIT License 5 votes vote down vote up
@SuppressWarnings("MethodWithTooManyParameters")
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public List<T> findRelatedConcepts(
    @RequestParam(QUERY_TEXT_PARAM) final String queryText,
    @RequestParam(value = FIELD_TEXT_PARAM, defaultValue = "") final String fieldText,
    @RequestParam(DATABASES_PARAM) final Collection<S> databases,
    @RequestParam(value = MIN_DATE_PARAM, required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) final ZonedDateTime minDate,
    @RequestParam(value = MAX_DATE_PARAM, required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) final ZonedDateTime maxDate,
    @RequestParam(value = MIN_SCORE_PARAM, defaultValue = "0") final Integer minScore,
    @RequestParam(value = STATE_MATCH_TOKEN_PARAM, required = false) final List<String> stateMatchTokens,
    @RequestParam(value = STATE_DONT_MATCH_TOKEN_PARAM, required = false) final List<String> stateDontMatchTokens,
    @RequestParam(value = MAX_RESULTS, required = false) final Integer maxResults,
    @RequestParam(value = QUERY_TYPE_PARAM, defaultValue = "MODIFIED") final String queryType
) throws E {
    final Q queryRestrictions = queryRestrictionsBuilderFactory.getObject()
            .queryText(queryText)
            .fieldText(fieldText)
            .databases(databases)
            .minDate(minDate)
            .maxDate(maxDate)
            .minScore(minScore)
            .stateMatchIds(ListUtils.emptyIfNull(stateMatchTokens))
            .stateDontMatchIds(ListUtils.emptyIfNull(stateDontMatchTokens))
            .build();

    final R relatedConceptsRequest = relatedConceptsRequestBuilderFactory.getObject()
        .maxResults(maxResults)
        .querySummaryLength(QUERY_SUMMARY_LENGTH)
        .queryRestrictions(queryRestrictions)
        .queryType(QueryRequest.QueryType.valueOf(queryType))
        .build();

    return relatedConceptsService.findRelatedConcepts(relatedConceptsRequest);
}
 
Example #25
Source File: CollectionApachePartitionUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public final void givenListPartitioned_whenOriginalListIsModified_thenPartitionsChange() {
    // Given
    final List<Integer> intList = Lists.newArrayList(1, 2, 3, 4, 5, 6, 7, 8);
    final List<List<Integer>> subSets = ListUtils.partition(intList, 3);

    // When
    intList.add(9);
    final List<Integer> lastPartition = subSets.get(2);
    final List<Integer> expectedLastPartition = Lists.<Integer> newArrayList(7, 8, 9);
    assertThat(lastPartition, equalTo(expectedLastPartition));
}
 
Example #26
Source File: ActionListWithPersonComplex.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 从可见的application中获取一份ids<br/>
 * 从可启动的process中获取一份ids <br/>
 * 两份ids的交集,这样避免列示只有application没有可以启动process的应用
 */
private List<String> list(Business business, EffectivePerson effectivePerson, List<String> roles,
		List<String> identities, List<String> units) throws Exception {
	List<String> ids = this.listFromApplication(business, effectivePerson, roles, identities, units);
	List<String> fromProcessIds = this.listFromProcess(business, effectivePerson, roles, identities, units);
	return ListUtils.intersection(ids, fromProcessIds);
}
 
Example #27
Source File: CopyRatioSegmenter.java    From gatk-protected with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * evenly-spaced log-2 copy ratios
 * @param K the initial number of hidden states
 */
private static List<Double> initialNonConstantLog2CopyRatios(final int K) {
    ParamUtils.isPositive(K, "must have at least one non-constant state");
    final double spacing = (MAX_INITIAL_LOG_2_COPY_RATIO  - MIN_INITIAL_LOG_2_COPY_RATIO) / (K + 1);
    final int numNegativeStates = K / 2;
    final int numPositiveStates = K - numNegativeStates;
    final List<Double> negativeStates = Doubles.asList(GATKProtectedMathUtils.createEvenlySpacedPoints(MIN_INITIAL_LOG_2_COPY_RATIO, spacing, numNegativeStates));
    final List<Double> positiveStates = Doubles.asList(GATKProtectedMathUtils.createEvenlySpacedPoints(spacing, MAX_INITIAL_LOG_2_COPY_RATIO, numPositiveStates));
    return ListUtils.union(negativeStates, positiveStates);
}
 
Example #28
Source File: CDOMObjectUtilities.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void checkRemovals(CDOMObject cdo, PlayerCharacter pc)
{
	if (!pc.isAllowInteraction())
	{
		return;
	}
	List<PersistentTransitionChoice<?>> removeList = ListUtils.emptyIfNull(cdo.getListFor(ListKey.REMOVE));
	removeList.forEach(tc -> driveChoice(cdo, tc, pc));
}
 
Example #29
Source File: Test3.java    From spring-boot with Apache License 2.0 5 votes vote down vote up
private void subList() {
    System.out.println(StringUtils.center("apache commons", 80, "="));
    List<Integer> largeList = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
    MyFastJsonUtils.prettyPrint(ListUtils.partition(largeList, 3));
    System.out.println(StringUtils.center("Guava", 80, "="));
    MyFastJsonUtils.prettyPrint(Lists.partition(largeList, 3));
    System.out.println(StringUtils.center("my customize", 80, "="));
    MyFastJsonUtils.prettyPrint(MyCollectionUtils.partition(largeList, 3));

}
 
Example #30
Source File: CrawlWorkCompleted.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void schedule(JobExecutionContext jobExecutionContext) throws Exception {
	TimeStamp stamp = new TimeStamp();
	List<String> add_workCompleteds = null;
	List<String> update_workCompleteds = null;
	List<String> update_references = null;
	List<String> updates = null;
	Long workCompletedCount = null;
	Long entryCount = null;
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Business business = new Business(emc);
		workCompletedCount = emc.count(WorkCompleted.class);
		entryCount = emc.countEqual(Entry.class, Entry.type_FIELDNAME, Entry.TYPE_WORKCOMPLETED);
		add_workCompleteds = this.listAddWorkCompleted(business);
		update_workCompleteds = this.listUpdateWorkCompleted(business);
		update_references = this.listUpdateEntryReference(business);
		updates = ListUtils.sum(ListUtils.sum(add_workCompleteds, update_workCompleteds), update_references);
	} catch (Exception e) {
		logger.error(e);
		throw new JobExecutionException(e);
	}
	this.update(update_references);
	logger.print(
			"完成工作索引器运行完成, 已完成工作总数:{}, 新索引已完成工作数量:{}, 轮询更新已完成工作数量:{}, 已索引条目总数:{}, 已索引条目更新数量:{}, 合并更新数量:{}, 数量限制:{}, 耗时{}.",
			workCompletedCount, add_workCompleteds.size(), update_workCompleteds.size(), entryCount,
			update_references.size(), updates.size(), Config.query().getCrawlWorkCompleted().getCount(),
			stamp.consumingMilliseconds());
}