Java Code Examples for org.apache.commons.collections.CollectionUtils#addAll()

The following examples show how to use org.apache.commons.collections.CollectionUtils#addAll() . 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: ReflectionUtils.java    From base-framework with Apache License 2.0 6 votes vote down vote up
/**
 * 获取对象的所有DeclaredField,并强制设置为可访问.
 * 
 * @param targetClass
 *            目标对象Class
 * @param ignoreParent
 *            是否循环向上转型,获取所有父类的Field
 * 
 * @return List
 */
public static List<Field> getAccessibleFields(final Class targetClass,
		final boolean ignoreParent) {
	Assert.notNull(targetClass, "targetClass不能为空");
	List<Field> fields = new ArrayList<Field>();

	Class<?> sc = targetClass;

	do {
		Field[] result = sc.getDeclaredFields();

		if (!ArrayUtils.isEmpty(result)) {

			for (Field field : result) {
				field.setAccessible(true);
			}

			CollectionUtils.addAll(fields, result);
		}

		sc = sc.getSuperclass();

	} while (sc != Object.class && !ignoreParent);

	return fields;
}
 
Example 2
Source File: ReflectionUtils.java    From base-framework with Apache License 2.0 6 votes vote down vote up
/**
 * 获取对象的所有DeclaredMethod 并强制设置为可访问.
 * 
 * @param targetClass
 *            目标对象Class
 * @param ignoreParent
 *            是否循环向上转型,获取所有父类的Method
 * 
 * @return List
 */
public static List<Method> getAccessibleMethods(final Class targetClass,
		boolean ignoreParent) {
	Assert.notNull(targetClass, "targetClass不能为空");
	List<Method> methods = new ArrayList<Method>();

	Class<?> superClass = targetClass;
	do {
		Method[] result = superClass.getDeclaredMethods();

		if (!ArrayUtils.isEmpty(result)) {

			for (Method method : result) {
				method.setAccessible(true);
			}

			CollectionUtils.addAll(methods, result);
		}

		superClass = superClass.getSuperclass();
	} while (superClass != Object.class && !ignoreParent);

	return methods;
}
 
Example 3
Source File: FormFieldHelper.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @param formFieldList
 * @param formValueMap 
 */
public static void setValueToFormField(
        List<FormField> formFieldList,
        Map<String, Object> formValueMap) {
    for (FormField ff : formFieldList) {
        if (ff instanceof SelectFormField) {
            for (Map.Entry<String, List<SelectElement>> entry : ((SelectFormField)ff).getSelectElementMap().entrySet()) {
                for (SelectElement se : entry.getValue()) {
                    se.setDefault(false);
                    if (formValueMap.get(entry.getKey()).equals(se.getValue())) {
                        se.setDefault(true);
                    }
                }
            }
        } else if (ff instanceof CheckboxFormField) {
            // retrieve the user selection and select the UI elements
            CheckboxFormField cff = ((CheckboxFormField)ff);
            Collection<String> selectedValues = new HashSet<String>();
            if ((formValueMap.get(cff.getCode()) instanceof String[])) {
                CollectionUtils.addAll(selectedValues, ((String[])formValueMap.get(cff.getCode())));
            } else if ((formValueMap.get(cff.getCode()) instanceof String)) {
                selectedValues.add(((String)formValueMap.get(cff.getCode())));
            }
            for (CheckboxElement  ce : cff.getCheckboxElementList()) {
                if(selectedValues.add(ce.getValue())) {
                    ce.setSelected(true);
                } else {
                    ce.setSelected(false);
                }
            }
        } else {
            ff.setValue(formValueMap.get(ff.getI18nKey()).toString());
        }
    }
}
 
Example 4
Source File: ConvertArrayToList.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void convert_string_array_to_list_with_apachecommons () {

	String[] planetsAsStringArray = { "The Sun", "Mercury", "Venus",
			"Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune" };

	List<String> planetsAsArrayList = new ArrayList<String>();
	CollectionUtils.addAll(planetsAsArrayList, planetsAsStringArray);
	
	assertEquals(9, planetsAsArrayList.size());
}
 
Example 5
Source File: MyBatisConfiguration.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
private Resource[] buildBatchMapperResources(String... resourcesPath) throws IOException {
    ArrayList<Resource> resources = new ArrayList<>();
    for (String resourcePath : resourcesPath) {
        CollectionUtils.addAll(resources, buildMapperResources(resourcePath));
    }
    return resources.toArray(new Resource[0]);
}
 
Example 6
Source File: URLTag.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected List<String> getParametersToExclude() {
	List<String> parameters = new ArrayList<String>();
	String csv = this.getExcludeParameters();
	if (null != csv && csv.trim().length() > 0) {
		CollectionUtils.addAll(parameters, csv.split(","));
	}
	parameters.add(SystemConstants.LOGIN_PASSWORD_PARAM_NAME);
	return parameters;
}
 
Example 7
Source File: AbstractAuditResultController.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: SourceCodeAssistProcessor.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected void doComputeCompletionProposals(T context, List<ICompletionProposal> completionProposals) {
   	for (IContentAssistProcessor contentAssistProcessor : contentAssistProcessors) {
   		if (contentAssistProcessor instanceof ICompletionContextUser) {
   			((ICompletionContextUser<T>)contentAssistProcessor).setCompletionContext(context);
   		}
   		ICompletionProposal[] cp = contentAssistProcessor.computeCompletionProposals(context.getViewer(), context.getOffset());
   		CollectionUtils.addAll(completionProposals, cp);
   	}
   }
 
Example 9
Source File: TestDataDictionaryManager.java    From base-framework with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteDataDictionary() {
	
	List<String> ids = new ArrayList<String>();
	CollectionUtils.addAll(ids, new String[]{"402881e437d47b250137d481b6920001","402881e437d47b250137d481dda30002"});
	
	int beforeRow = countRowsInTable("TB_DATA_DICTIONARY");
	systemVariableManager.deleteDataDictionary(ids);
	int afterRow = countRowsInTable("TB_DATA_DICTIONARY");
	
	assertEquals(afterRow, beforeRow - 2);
}
 
Example 10
Source File: AbstractCsvReader.java    From the-app with Apache License 2.0 5 votes vote down vote up
protected CsvToBean<T> getParser() {
    return new CsvToBean<T>() {
        @Override
        protected PropertyEditor getPropertyEditor(final PropertyDescriptor desc) throws InstantiationException, IllegalAccessException {

            if (getDestinationClass().isAssignableFrom(User.class) && "categories".equalsIgnoreCase(
                    desc.getDisplayName())) {
                return new DummyPropertyEditor() {
                    @Override
                    public Object getValue() {
                        if (StringUtils.isBlank(getAsText())) {
                            return null;
                        }
                        Set<String> result = new HashSet<>();
                        CollectionUtils.addAll(result, StringUtils.split(getAsText(), ","));
                        return result;
                    }
                };
            }
            final Class<?> enumCandidate = desc.getWriteMethod().getParameterTypes()[0];

            if (enumCandidate.isEnum()) {
                return new DummyPropertyEditor() {
                    @Override
                    public Object getValue() {
                        try {
                            Method valueOfMethod = enumCandidate.getMethod("valueOf", String.class);
                            return valueOfMethod.invoke(null, getAsText());
                        } catch (Exception e) {
                            throw new RuntimeException("Unable to parse enum " + enumCandidate + " from csv value "
                                    + getAsText());
                        }
                    }
                };
            }
            return super.getPropertyEditor(desc);
        }
    };
}
 
Example 11
Source File: XiamiParser.java    From java-tutorial with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	XiamiParser parser = new XiamiParser();
	Set<SongInfo> allSongInfos = new HashSet<>();
	for (int page = 0; page <= 65; page++) {
		Set<SongInfo> curPageSongs = parser.getSongInfoSet(BLOG_URL, page);
		CollectionUtils.addAll(allSongInfos, curPageSongs.iterator());
	}
	System.out.println("总歌曲数目:" + allSongInfos.size());
	parser.printAllSongInfo(allSongInfos);
}
 
Example 12
Source File: ReflectionUtils.java    From base-framework with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * 获取对象中的所有annotationClass注解
 * 
 * @param targetClass
 *            目标对象Class
 * @param annotationClass
 *            注解类型Class
 * 
 * @return List
 */
public static <T extends Annotation> List<T> getAnnotations(
		Class targetClass, Class annotationClass) {
	Assert.notNull(targetClass, "targetClass不能为空");
	Assert.notNull(annotationClass, "annotationClass不能为空");

	List<T> result = new ArrayList<T>();
	Annotation annotation = targetClass.getAnnotation(annotationClass);
	if (annotation != null) {
		result.add((T) annotation);
	}
	Constructor[] constructors = targetClass.getDeclaredConstructors();
	// 获取构造方法里的注解
	CollectionUtils.addAll(result,
			getAnnotations(constructors, annotationClass).iterator());

	Field[] fields = targetClass.getDeclaredFields();
	// 获取字段中的注解
	CollectionUtils.addAll(result, getAnnotations(fields, annotationClass)
			.iterator());

	Method[] methods = targetClass.getDeclaredMethods();
	// 获取方法中的注解
	CollectionUtils.addAll(result, getAnnotations(methods, annotationClass)
			.iterator());

	for (Class<?> superClass = targetClass.getSuperclass(); superClass == null
			|| superClass == Object.class; superClass = superClass
			.getSuperclass()) {
		List<T> temp = getAnnotations(superClass, annotationClass);
		if (CollectionUtils.isNotEmpty(temp)) {
			CollectionUtils.addAll(result, temp.iterator());
		}
	}

	return result;
}
 
Example 13
Source File: PaginationQuery.java    From boubei-tss with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * 执行分页查询,获取分页结果及相关信息
 * </p>
 * @return
 */
public PageInfo getResultList() {
    Set<String> ignores = condition.getIgnoreProperties();
    CollectionUtils.addAll(ignores, COMMON_IGNORE_PROPERTIES);
    Map<String, Object> properties = BeanUtil.getProperties(condition, ignores);
    
    // 过滤空参数、无效参数对应的宏代码 
    Map<String, Object> macrocodes = condition.getConditionMacrocodes();
    for (  Iterator<String> it = macrocodes.keySet().iterator(); it.hasNext(); ) {
        String key = it.next();
        if (key.startsWith("${") && key.endsWith("}")) {
            String name = key.substring(2, key.length() - 1);
            Object value = properties.get(name);
            if ( !"domain".equals(name) && isValueNullOrEmpty(value) ) { // 查询条件字段值为空,则移除该条件
            	it.remove();
            }
        }
    }
    
    // 添加HQL中order by 语句
    appendOrderBy();
    
    // 解析带了宏定义的QL语句
    String queryQl = MacrocodeCompiler.run(ql, macrocodes, false);
 
    PageInfo page = condition.getPage();
    page.setItems(null); // 清空上次的查询结果,一个condition多次被用来查询的情况
    page.setTotalRows(getTotalRows(queryQl, properties));
    
    // 获取当前页数据记录集
    Query query = createQuery(queryQl.replace("order by 1", ""));
    query.setFirstResult(page.getFirstResult());
    query.setMaxResults(page.getPageSize());
    
    // 为查询语句设置相应的参数
    setProperties4Query(query, properties);
    page.setItems( query.getResultList() );

    return page;
}
 
Example 14
Source File: ServletTestUtils.java    From uyuni with GNU General Public License v2.0 4 votes vote down vote up
private static Set createQueryStringParameterSet(String queryString) {
    Set parameterSet = new TreeSet();
    CollectionUtils.addAll(parameterSet, queryString.split("&"));

    return parameterSet;
}
 
Example 15
Source File: AbstractEventTriggerMatcher.java    From aws-codecommit-trigger-plugin with Apache License 2.0 4 votes vote down vote up
public AbstractEventTriggerMatcher or(EventTriggerMatcher... matchers) {
    CollectionUtils.addAll(this.matchers, matchers);
    return new OrEventTriggerMatcher(this.matchers.toArray(new EventTriggerMatcher[]{}));
}
 
Example 16
Source File: AbstractEventTriggerMatcher.java    From aws-codecommit-trigger-plugin with Apache License 2.0 4 votes vote down vote up
public AbstractEventTriggerMatcher and(EventTriggerMatcher... matchers) {
    CollectionUtils.addAll(this.matchers, matchers);
    return new AndEventTriggerMatcher(this.matchers.toArray(new EventTriggerMatcher[]{}));
}
 
Example 17
Source File: ServletTestUtils.java    From spacewalk with GNU General Public License v2.0 4 votes vote down vote up
private static Set createQueryStringParameterSet(String queryString) {
    Set parameterSet = new TreeSet();
    CollectionUtils.addAll(parameterSet, queryString.split("&"));

    return parameterSet;
}
 
Example 18
Source File: DataDictionaryDao.java    From base-framework with Apache License 2.0 4 votes vote down vote up
/**
 * 通过字典类别代码获取数据字典集合
 * 
 * @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());
}
 
Example 19
Source File: PredicateFactory.java    From rice with Educational Community License v2.0 3 votes vote down vote up
/**
 * Creates an and predicate that is used to "and" predicates together.
 *
 * <p>An "and" predicate will evaluate the truth value of of it's
 * internal predicates and, if all of them evaluate to true, then
 * the and predicate itself should evaluate to true.  The implementation
    * of an and predicate may short-circuit.
    *
    * <p>
    *     This factory method does automatic reductions.
    * </p>
 *
    * @param predicates to "and" together
    *
 * @return a predicate
 */
public static Predicate and(Predicate... predicates) {
       //reduce single item compound
       if (predicates != null && predicates.length == 1 && predicates[0] != null) {
           return predicates[0];
       }
       final Set<Predicate> predicateSet = new HashSet<Predicate>();
       CollectionUtils.addAll(predicateSet, predicates);
       return new AndPredicate(predicateSet);
}
 
Example 20
Source File: PredicateFactory.java    From rice with Educational Community License v2.0 3 votes vote down vote up
/**
 * Creates an  or predicate that is used to "or" predicate together.
 *
 * <p>An "or" predicate will evaluate the truth value of of it's
 * internal predicates and, if any one of them evaluate to true, then
 * the or predicate itself should evaluate to true.  If all predicates
 * contained within the "or" evaluate to false, then the or iself will
 * evaluate to false.   The implementation of an or predicate may
    * short-circuit.
 *
    * <p>
    *     This factory method does automatic reductions.
    * </p>
    * @param predicates to "or" together
    *
 * @return a predicate
 */
public static Predicate or(Predicate... predicates) {
       //reduce single item compound
       if (predicates != null && predicates.length == 1 && predicates[0] != null) {
           return predicates[0];
       }

       final Set<Predicate> predicateSet = new HashSet<Predicate>();
       CollectionUtils.addAll(predicateSet, predicates);
	return new OrPredicate(predicateSet);
}