List of usage examples for org.apache.commons.collections CollectionUtils addAll
public static void addAll(Collection collection, Object[] elements)
From source file:org.silverpeas.core.i18n.I18NHelperTest.java
/** * Test of getLanguages method, of class I18NHelper. *//* w w w .j a v a 2 s . c o m*/ @Test public void testGetLanguages() { Iterator<String> result = I18NHelper.getLanguages().iterator(); List<String> languages = new ArrayList<String>(3); CollectionUtils.addAll(languages, result); assertThat(languages, containsInAnyOrder("en", "fr", "de")); }
From source file:org.sipfoundry.sipxconfig.common.DataCollectionUtil.java
/** * Moves items from collections by their primary key and updates the positions on the items. * Items that are attempted to move out of list bounds are quietly moved to beginning or end * of list.//w w w.jav a2 s . com * * @param step how many slots to move items, positive or negative * @param c items must implement DataCollectionItem */ public static void moveByPrimaryKey(List c, Object[] primaryKeys, int step) { Set toBeMovedSet = new HashSet(primaryKeys.length); CollectionUtils.addAll(toBeMovedSet, primaryKeys); if (step < 0) { // move up int minPosition = 0; for (int i = 0; i < c.size() && !toBeMovedSet.isEmpty(); i++) { PrimaryKeySource item = (PrimaryKeySource) c.get(i); if (toBeMovedSet.remove(item.getPrimaryKey())) { int newPosition = Math.max(minPosition, i + step); c.remove(i); c.add(newPosition, item); minPosition = newPosition + 1; } } } else if (step > 0) { // move down int maxPosition = c.size() - 1; for (int i = c.size() - 1; i >= 0 && !toBeMovedSet.isEmpty(); i--) { PrimaryKeySource item = (PrimaryKeySource) c.get(i); if (toBeMovedSet.remove(item.getPrimaryKey())) { int newPosition = Math.min(i + step, maxPosition); c.remove(i); c.add(newPosition, item); maxPosition = newPosition - 1; } } } }
From source file:org.springmodules.validation.bean.conf.DefaultBeanValidationConfiguration.java
/** * Sets the global rules for this configuration. * * @param globalRules The global rules for this configuration *///from w w w . ja v a 2 s . c om public void setGlobalRules(ValidationRule[] globalRules) { List rules = new ArrayList(); CollectionUtils.addAll(rules, globalRules); this.globalRules = rules; }
From source file:org.springmodules.validation.bean.conf.DefaultBeanValidationConfiguration.java
/** * Adds the given rules as global rules for this configuration. * * @param globalRules The rules to be added as global rules for this configuration. *///from w ww .j a va2 s . c o m public void addGlobalRules(ValidationRule[] globalRules) { CollectionUtils.addAll(this.globalRules, globalRules); }
From source file:org.springmodules.validation.bean.conf.DefaultBeanValidationConfiguration.java
/** * Sets the property validation rules for the given property. * * @param propertyName The name of the property. * @param rules The validation rules for the given property. *///from w w w . j a va 2s .com public void setPropertyRules(String propertyName, ValidationRule[] rules) { List ruleList = new ArrayList(); CollectionUtils.addAll(ruleList, rules); rulesByProperty.put(propertyName, ruleList); }
From source file:org.springmodules.validation.bean.conf.DefaultBeanValidationConfiguration.java
/** * Adds the given validation rules to the given property. * * @param propertyName The name of the property. * @param extraRules The extra validation rules that will be added to the given property. *//*from w ww. j av a 2 s . c o m*/ public void addPropertyRules(String propertyName, ValidationRule[] extraRules) { List rules = (List) rulesByProperty.get(propertyName); if (rules == null) { rules = new ArrayList(); rulesByProperty.put(propertyName, rules); } CollectionUtils.addAll(rules, extraRules); }
From source file:org.springmodules.validation.bean.conf.loader.annotation.AnnotationBeanValidationConfigurationLoader.java
/** * Extracts all fields in the class hierarchy of the given class. * * @param clazz The given class./*from www .j a v a2 s. co m*/ * @return All fields in the class hierarchy of the given class. */ protected List<Field> extractFieldFromClassHierarchy(Class clazz) { List<Field> fields = new ArrayList<Field>(); while (clazz != null) { CollectionUtils.addAll(fields, clazz.getDeclaredFields()); clazz = clazz.getSuperclass(); } return fields; }
From source file:org.springmodules.xt.model.notification.NotificationImpl.java
public Message[] getAllMessages() { Collection<Message> result = new LinkedList(); for (Message.Type type : Message.Type.values()) { CollectionUtils.addAll(result, this.messagesMap.get(type).toArray()); }/* w w w . j ava 2s . c om*/ return result.toArray(new Message[result.size()]); }
From source file:org.springside.examples.quickstart.service.BulletinDataService.java
/** * ????//from w w w. j av a 2s . c o m * @param ids */ public boolean synBulletin(Long[] ids) { // boolean result = false; List<Long> idls = new ArrayList<Long>(); CollectionUtils.addAll(idls, ids); Iterable<BulletinData> bulletinDatas = bulletinDataDao.findAll(idls); for (BulletinData bulletinData : bulletinDatas) { //bulletinData // bulletinData.setBulletinUrl("http://gxoa.cc/attachmentDownload.do?filePath="+bulletinData.getAttachmentPath()+"&fileName="+bulletinData.getAttachmentId()); //?? StringWriter writer = new StringWriter(); BodyXml<BulletinData> bodyXml = new BodyXml<BulletinData>(); bodyXml.setProjectInfo(bulletinData); BulletinXml bulletinXml = new BulletinXml(); bulletinXml.setBody(bodyXml); try { marshaller.marshal(bulletinXml, writer); } catch (JAXBException e) { logger.error("{}|{}XML?:" + e.getStackTrace(), bulletinData.getId(), bulletinData.getAnnouncementDate()); } try { HttpPost httpPost = new HttpPost(propertiesLoader.getProperty("syn.synBulletinUrl")); // ??/ List<NameValuePair> parameters = new ArrayList<NameValuePair>(); parameters.add(new BasicNameValuePair("xmlContent", writer.toString())); // UrlEncodedFormEntity UrlEncodedFormEntity formEntiry = new UrlEncodedFormEntity(parameters, "UTF-8"); httpPost.setEntity(formEntiry); // ?connection poolclient CloseableHttpResponse closeableHttpResponse = httpClient.execute(httpPost); closeableHttpResponse.getEntity().getContent(); String xmlContentresp = IOUtils.toString(closeableHttpResponse.getEntity().getContent()); if (xmlContentresp.contains("operTag")) { String operTag = StringUtils.substringBetween(xmlContentresp, "<operTag>", "</operTag>"); if ("Y".equals(operTag)) {//? //?? bulletinData.setSynStatus(BuyerData.SYNSTATUS_SUCCESS); bulletinDataDao.save(bulletinData); result = true; } else { logger.error("?{}|{}??", bulletinData.getId(), bulletinData.getAnnouncementDate()); } } //httpClient.close(); } catch (IOException e) { e.printStackTrace(); logger.error("?{}|{}??:" + e.getStackTrace(), bulletinData.getId(), bulletinData.getAnnouncementDate()); } } return result; }
From source file:org.talend.dataquality.record.linkage.grouping.swoosh.DQMFBRecordMerger.java
@Override protected Record createNewRecord(Record record1, Record record2, long mergedRecordTimestamp) { RichRecord richRecord1 = (RichRecord) record1; RichRecord richRecord2 = (RichRecord) record2; RichRecord mergedRecord = new RichRecord(record1.getId(), mergedRecordTimestamp, mergedRecordSource); DQAttribute<?>[] mergedRows = richRecord1.getOriginRow() .toArray(new DQAttribute<?>[richRecord1.getOriginRow().size()]); // Merge columns which are not maching keys using default survior rules. List<Attribute> matchingAttributes = record1.getAttributes(); for (int colIdx = 0; colIdx < richRecord1.getOriginRow().size(); colIdx++) { boolean isMatchKeyIndex = false; for (Attribute attribute : matchingAttributes) { if (attribute.getColumnIndex() == colIdx) { isMatchKeyIndex = true;/* w w w .j av a 2s . c om*/ break; } } if (!isMatchKeyIndex) { Map<Integer, SurvivorshipFunction> defaultSurvivorshipFuncs = matchMergeParam .getDefaultSurviorshipRules(); SurvivorshipFunction survivorshipFunc = defaultSurvivorshipFuncs.get(colIdx); if (survivorshipFunc == null || survivorshipFunc.getSurvivorShipAlgoEnum() == null) { // No default survivorship function was set. continue; } // Get the merged value and update the merged row. mergedRows[colIdx] = new DQAttribute(StringUtils.EMPTY, colIdx);// No label for the // attributes which are not // matching keys; // Keep values from original records (if any) String leftValue = richRecord1.getOriginRow().get(colIdx).getValue(); String rightValue = richRecord2.getOriginRow().get(colIdx).getValue(); AttributeValues<String> leftValues = richRecord1.getOriginRow().get(colIdx).getValues(); if (leftValues.size() > 0) { mergedRows[colIdx].getValues().merge(leftValues); } else { mergedRows[colIdx].getValues().get(leftValue).increment(); } AttributeValues<String> rightValues = richRecord2.getOriginRow().get(colIdx).getValues(); if (rightValues.size() > 0) { mergedRows[colIdx].getValues().merge(rightValues); } else { mergedRows[colIdx].getValues().get(rightValue).increment(); } // Merge values if (leftValue == null && rightValue == null) { mergedRows[colIdx].setValue(null); } else { SurvivorShipAlgorithmEnum survAlgo = survivorshipFunc.getSurvivorShipAlgoEnum(); String parameter = survivorshipFunc.getParameter(); String mergedValue = createMergeValue(record1.getSource(), record2.getSource(), parameter, record1.getTimestamp(), record2.getTimestamp(), survAlgo, leftValue, rightValue, mergedRows[colIdx].getValue(), mergedRows[colIdx].getValues()); if (mergedValue != null) { mergedRows[colIdx].setValue(mergedValue); } } } /** * Else the matching key's value will be udpated when call {@link RichRecord#getOutputRow()} */ } List<DQAttribute<?>> originalRowList = new ArrayList<DQAttribute<?>>(); CollectionUtils.addAll(originalRowList, mergedRows); mergedRecord.setOriginRow(originalRowList); mergedRecord.setRecordSize(richRecord1.getRecordSize()); // Set the group quality double gQuality1 = richRecord1.getGroupQuality(); double gQuality2 = richRecord2.getGroupQuality(); double minQuality = Math.min(gQuality1, gQuality2); if (minQuality != 0) { mergedRecord.setGroupQuality(minQuality); } return mergedRecord; }