private Collection<Tag> collectResourceTags(Resource resource, boolean recurse) { if (resource == null) { return Collections.emptyList(); } Set<Tag> treeTags = new HashSet<Tag>(); Queue<Resource> searchResources = new LinkedList<Resource>(); searchResources.add(resource); while (!searchResources.isEmpty()) { Resource searchResource = searchResources.poll(); if (recurse) { CollectionUtils.addAll(searchResources, searchResource.listChildren()); } String[] tags = resource.getValueMap().get(TagConstants.PN_TAGS, String[].class); if (tags == null) { continue; } for (String tagStr : tags) { Tag tag = resolve(tagStr); if (tag != null) { treeTags.add(tag); } } } return treeTags; }
/** * 保存角色资源 * * @param roleId * @param resourceIds */ @SuppressWarnings("unchecked") public void saveUserRole(String userId, String[] roleIds) { List<String> roleIdList = new ArrayList<String>(roleIds.length); CollectionUtils.addAll(roleIdList, roleIds); List<String> remainRoleIdList = dao.findRoleIdsByUserId(userId); Collection<String> bothHadList = CollectionUtils.retainAll(remainRoleIdList, roleIdList); // 并集 remainRoleIdList.removeAll(bothHadList); roleIdList.removeAll(bothHadList); if (CollectionUtils.isNotEmpty(remainRoleIdList)) { FilterMap filterMap = new FilterMap(); filterMap.eq("userId", userId); filterMap.in("roleId", remainRoleIdList); OrderMap orderMap = new OrderMap(); List<UserRole> entities = list(filterMap, orderMap); dao.delete(entities); } for (String roleId : roleIdList) { UserRole userRole = new UserRole(); userRole.setUserId(userId); userRole.setRoleId(roleId); dao.save(userRole); } }
public SetSearchField(String oper, T... vals) { if (!ArrayUtils.isEmpty(vals)) { CollectionUtils.addAll(values, vals); } this.operation = oper; }
private Collection<String> getTestResultSortSelection(AuditResultSortCommand asuc) { Collection<String> selectedValues = new HashSet<>(); if ((asuc.getSortOptionMap().get(testResultSortKey)) instanceof Object[]) { CollectionUtils.addAll( selectedValues, ((Object[]) asuc.getSortOptionMap().get(testResultSortKey))); } else if ((asuc.getSortOptionMap().get(testResultSortKey)) instanceof String) { selectedValues.add((String) asuc.getSortOptionMap().get(testResultSortKey)); } return selectedValues; }
private <T> List<T> getListFromTracker(ServiceTracker tracker) { tracker.open(); Object[] services = tracker.getServices(); List<T> result = new ArrayList<T>(); if (services != null) { CollectionUtils.addAll(result, services); } tracker.close(); return result; }
/** * 获取模块的角色ID集合 * * @param moduleId * @return */ public Set<String> getRoleIdSetByModuleId(String moduleId, boolean writable) { String hql = "select t.id from Role t,ModuleRoleRel r where r.roleId=t.id and r.moduleId=?"; Object[] params = null; if (writable) { hql += " and t.writable=?"; params = new Object[] {moduleId, true}; } else { params = new Object[] {moduleId}; } String[] roleIds = this.hibernateTemplate.queryForArray(hql, params, String.class); Set<String> roleIdSet = new HashSet<String>(); CollectionUtils.addAll(roleIdSet, roleIds); return roleIdSet; }
@Override @SuppressWarnings("unchecked") public List<ServiceReference> listServiceReferences(Class<?> clazz, String filter) { List<ServiceReference> result = new ArrayList<ServiceReference>(); String className = clazz == null ? null : clazz.getName(); try { ServiceReference[] serviceReferences = bundleContext.getServiceReferences(className, filter); if (serviceReferences == null) { return result; } CollectionUtils.addAll(result, serviceReferences); Collections.sort(result); } catch (InvalidSyntaxException e) { throw new IllegalArgumentException(e); } return result; }
/** * 取得本类中所有的属性列表 * * @param targetClass 要反射的目标 * @param ignoreParen 是否忽略父类中的属性 * @return */ public static List<Field> getAccessibleFileds(final Class<?> targetClass, boolean ignoreParen) { Assert.notNull(targetClass, "targetClass不能为空"); List<Field> list = new ArrayList<Field>(); Class<?> superClass = targetClass; do { Field[] fields = superClass.getDeclaredFields(); if (ArrayUtils.isNotEmpty(fields)) { for (Field field : fields) { field.setAccessible(true); } CollectionUtils.addAll(list, fields); } superClass = superClass.getSuperclass(); } while (superClass != Object.class && !ignoreParen); return list; }
public void constructCache(DefaultSolverScope solverScope) { long childSize = childMoveSelector.getSize(); if (childSize > (long) Integer.MAX_VALUE) { throw new IllegalStateException( "The selector (" + this + ") has a childMoveSelector (" + childMoveSelector + ") with childSize (" + childSize + ") which is higher than Integer.MAX_VALUE."); } cachedMoveList = new ArrayList<Move>((int) childSize); CollectionUtils.addAll(cachedMoveList, childMoveSelector.iterator()); logger.trace( " Created cachedMoveList with size ({}) in moveSelector({}).", cachedMoveList.size(), this); }
/** * 通过字典类别代码获取数据字典集合 * * @param code 字典列别 * @param ignoreValue 忽略字典的值 * @return List */ public List<DataDictionary> getByCategoryCode(SystemDictionaryCode code, String... ignoreValue) { StringBuffer hql = new StringBuffer("from DataDictionary dd where dd.category.code = ?"); List<String> args = Lists.newArrayList(code.getCode()); if (ArrayUtils.isNotEmpty(ignoreValue)) { String[] qm = new String[ignoreValue.length]; for (int i = 0; i < ignoreValue.length; i++) { qm[i] = "?"; } CollectionUtils.addAll(args, ignoreValue); hql.append(MessageFormat.format(" and dd.value not in({0})", StringUtils.join(qm, ","))); } return findByQuery(hql.toString(), args.toArray()); }
private void readListMembers(PagableResponseList<User> members, List<TwitterUser> existingUsers) { final List<TwitterUser> users = new ArrayList<TwitterUser>(); for (User member : members) { TwitterUser user = TwitterUser.fromUser(member); if (!existingUsers.contains(user)) { TwitterUser existingUser = twitterUserRepository.findOne(user.getId()); if (existingUser != null) { existingUser.setListMember(true); existingUser.setType(TweepTypes.MEMBER); users.add(existingUser); } else { user.setListMember(true); user.setType(TweepTypes.MEMBER); users.add(user); } } } CollectionUtils.addAll(existingUsers, twitterUserRepository.save(users).iterator()); // log.info(users.size() + " new members added."); }
/** * 获取对象的所有DeclaredMethod,并强制设置为可访问 * * @param targetClass 要反射的对象 * @param ignoreParent 是否忽略父类 * @return */ public static List<Method> getAccessibleMethods( final Class<?> targetClass, boolean ignoreParent) { Assert.notNull(targetClass, "targetClass不能为空"); List<Method> list = new ArrayList<Method>(); Class<?> superClass = targetClass; do { Method[] ms = superClass.getDeclaredMethods(); // 方法数组不为空 if (ArrayUtils.isNotEmpty(ms)) { // 修改访问权限 for (Method method : ms) { method.setAccessible(true); } CollectionUtils.addAll(list, ms); } superClass = superClass.getSuperclass(); logger.debug("superClass {}", superClass); } while (superClass != Object.class && !ignoreParent); return list; }
@Override public RangeIterator<Resource> find(String basePath, String[] tagIDs, boolean oneMatchIsEnough) { Resource base = resourceResolver.getResource(basePath); if (base == null) { return new CollectionRangeIterator<Resource>(Collections.<Resource>emptyList()); } Collection<String> tagPaths = new HashSet<String>(tagIDs.length); for (String tagID : tagIDs) { Tag tag = resolve(tagID); // clause - if tag does not exist, should return null. if (tag == null) { return null; } tagPaths.add(tag.adaptTo(Resource.class).getPath()); } Queue<Resource> searchResources = new LinkedList<Resource>(); searchResources.add(base); Collection<Resource> matchedResources = new ArrayList<Resource>(); while (!searchResources.isEmpty()) { Resource resource = searchResources.poll(); // add the children to search the entire tree CollectionUtils.addAll(searchResources, resource.listChildren()); // now process the tags String[] resourceTags = resource.getValueMap().get(TagConstants.PN_TAGS, String[].class); if (resourceTags == null) { continue; } List<String> resourceTagPaths = new ArrayList<String>(resourceTags.length); try { for (String resourceTag : resourceTags) { resourceTagPaths.add(getPathFromID(resourceTag)); } } catch (InvalidTagFormatException e) { log.error("invalid tag id encountered", e); } if (resourceTagPaths.isEmpty()) { continue; } boolean matches = false; if (oneMatchIsEnough) { // this is essentially an OR list, so break out on the first positive oneMatched: for (String tagPath : tagPaths) { for (String resourceTagPath : resourceTagPaths) { matches = doTagsMatch(resourceTagPath, tagPath); if (matches) { break oneMatched; } } } } else { // this is essentially an AND list, so break out on the first failure matches = true; for (String tagPath : tagPaths) { boolean tagMatched = false; for (Iterator<String> resourceTagPathIter = resourceTagPaths.iterator(); !tagMatched && resourceTagPathIter.hasNext(); ) { String resourceTagPath = resourceTagPathIter.next(); tagMatched = doTagsMatch(resourceTagPath, tagPath); } // if no tag on the resource matched the current search tag, it fails the search if (!tagMatched) { matches = false; break; } } } if (matches) { matchedResources.add(resource); } } return new CollectionRangeIterator<Resource>(matchedResources); }