List of usage examples for org.apache.commons.collections CollectionUtils collect
public static Collection collect(Iterator inputIterator, Transformer transformer)
From source file:org.sipfoundry.sipxconfig.firewall.FirewallConfig.java
void writeIptables(Writer w, Set<String> whiteList, Set<String> blackList, FirewallSettings settings, List<CallRateRule> rateRules, List<FirewallRule> rules, List<CustomFirewallRule> custom, List<ServerGroup> groups, List<Location> cluster, Location thisLocation) throws IOException { YamlConfiguration c = new YamlConfiguration(w); Collection<?> ips = CollectionUtils.collect(cluster, Location.GET_ADDRESS); c.write("logdropped", settings.isLogDroppedPacketsEnabled()); c.write("logdos", settings.isLogDosPacketsEnabled()); c.write("lograte", settings.isLogRatePacketsEnabled()); c.write("logregister", settings.isLogSipRegisterEnabled()); c.write("loginvite", settings.isLogSipInviteEnabled()); c.write("logack", settings.isLogSipAckEnabled()); c.write("logoptions", settings.isLogSipOptionsEnabled()); c.write("logsubscribe", settings.isLogSipSubscribeEnabled()); c.write("loglimit", settings.getLogLimitNumber()); c.write("loginterval", settings.getLogLimitInterval()); c.writeInlineArray("cluster", ips); c.startArray("chains"); for (ServerGroup group : groups) { c.nextElement();/* w w w . j av a 2s.c om*/ c.write(":name", group.getName()); List<String> sourceIPs = new ArrayList<String>(); String servers = group.getServerList(); if (StringUtils.isNotBlank(servers)) { sourceIPs = Arrays.asList(StringUtils.split(servers, " ")); } c.writeArray(":ipv4s", sourceIPs); } c.endArray(); c.writeArray("whitelist", whiteList); c.writeArray("blacklist", blackList); c.writeArray("deniedsip", settings.getDeniedSipUAs()); c.startArray("raterules"); for (CallRateRule rule : rateRules) { c.nextElement(); c.write(":rule", StringUtils.deleteWhitespace(rule.getName())); c.write(":startIp", rule.getStartIp()); if (rule.getEndIp() != null) { c.write(":endIp", rule.getEndIp()); } c.startArray(":limits"); for (CallRateLimit limit : rule.getCallRateLimits()) { c.nextElement(); c.write(":method", limit.getSipMethod()); c.write(":rate", limit.getRate()); c.write(":interval", limit.getInterval()); } c.endArray(); } c.endArray(); c.startArray("rules"); for (FirewallRule rule : rules) { AddressType type = rule.getAddressType(); List<Address> addresses = m_addressManager.getAddresses(type, thisLocation); if (addresses != null) { for (Address address : addresses) { // not a rule for this server if (!address.getAddress().equals(thisLocation.getAddress())) { continue; } AddressType atype = address.getType(); String id = atype.getId(); int port = address.getCanonicalPort(); // internal error if (port == 0) { LOG.error("Cannot open up port zero for service id " + id); continue; } // blindly allowed if (FirewallRule.SystemId.CLUSTER == rule.getSystemId() && rule.getServerGroup() == null) { continue; } c.write(":port", port); c.write(":protocol", atype.getProtocol()); c.write(":sip", atype.isExternalSip()); c.write(":service", id); c.write(":priority", rule.isPriority()); if (address.getEndPort() != 0) { c.write(":end_port", address.getEndPort()); } ServerGroup group = rule.getServerGroup(); String chain; if (group != null) { chain = group.getName(); } else if (rule.getSystemId() == FirewallRule.SystemId.PUBLIC) { chain = "ACCEPT"; } else { chain = rule.getSystemId().name(); } c.write(":chain", chain); c.nextElement(); } } } c.endArray(); for (FirewallTable table : FirewallTable.values()) { Collection<?> tableRules = CollectionUtils.select(custom, CustomFirewallRule.byTable(table)); if (!tableRules.isEmpty()) { c.writeArray(table.toString(), tableRules); } } }
From source file:org.sipfoundry.sipxconfig.site.admin.commserver.BundlePanel.java
@SuppressWarnings("unchecked") public FeatureChangeRequest buildFeatureChangeRequest() { Map<Location, Set<LocationFeature>> byLocation = new HashMap<Location, Set<LocationFeature>>(); // location/* w ww. ja va 2 s . c o m*/ for (Location l : getLocations()) { ByLocation filter = new ByLocation(l, getBundle()); Collection<String> subset = CollectionUtils.select(getCellIds(), filter); Collection<LocationFeature> selected = CollectionUtils.collect(subset, filter); Set<LocationFeature> featureSet = new HashSet<LocationFeature>(selected); byLocation.put(l, featureSet); } FeatureChangeRequest req = FeatureChangeRequest.byBundle(getBundle(), getGlobalFeatures(), byLocation); return req; }
From source file:org.sipfoundry.sipxconfig.site.admin.commserver.BundlePanel.java
public Collection<Cell> getCells() { Feature f = getFeature();/*from w w w . ja va2s. c om*/ FeatureManager fm = getFeatureManager(); BundleConstraint c = getBundle().getConstraint(f); Collection<Location> validLocations = c.getApplicableLocations(fm, f, getLocations()); Collection<Integer> valid = CollectionUtils.collect(validLocations, new BeanWithId.BeanToId()); List<Cell> cells = new ArrayList<Cell>(valid.size()); for (Location l : getLocations()) { Cell cell = new Cell(getFeature(), l); cell.m_enabled = valid.contains(l.getId()); cells.add(cell); } return cells; }
From source file:org.sonar.api.profiles.RulesProfile.java
@Override public Object clone() { RulesProfile clone = RulesProfile.create(getName(), getLanguage()); clone.setDefaultProfile(getDefaultProfile()); clone.setParentName(getParentName()); if (activeRules != null && !activeRules.isEmpty()) { clone.setActiveRules(new ArrayList<ActiveRule>(CollectionUtils.collect(activeRules, new Transformer() { public Object transform(Object input) { return ((ActiveRule) input).clone(); }/*from w ww.j a v a 2 s . c o m*/ }))); } if (CollectionUtils.isNotEmpty(getAlerts())) { clone.setAlerts(new ArrayList<Alert>(CollectionUtils.collect(getAlerts(), new Transformer() { public Object transform(Object input) { return ((Alert) input).clone(); } }))); } return clone; }
From source file:org.sonar.api.rules.ActiveRule.java
@Override public Object clone() { final ActiveRule clone = new ActiveRule(getRulesProfile(), getRule(), getSeverity()); clone.setInheritance(getInheritance()); if (CollectionUtils.isNotEmpty(getActiveRuleParams())) { clone.setActiveRuleParams(new ArrayList<ActiveRuleParam>( CollectionUtils.collect(getActiveRuleParams(), new Transformer() { public Object transform(Object input) { ActiveRuleParam activeRuleParamClone = (ActiveRuleParam) ((ActiveRuleParam) input) .clone(); activeRuleParamClone.setActiveRule(clone); return activeRuleParamClone; }/* www . j a v a 2 s .com*/ }))); } return clone; }
From source file:org.squashtest.tm.domain.library.structures.LibraryGraph.java
public <X> List<X> collect(Transformer transformer) { return new ArrayList<>(CollectionUtils.collect(getNodes(), transformer)); }
From source file:org.squashtest.tm.domain.library.structures.LibraryGraph.java
/** * first we'll filter, then we'll collect. So write your predicate and transformer carefully. * *///from w w w . j a va 2 s .c o m public <X> List<X> filterAndcollect(Predicate predicate, Transformer transformer) { List<T> filtered = filter(predicate); return new ArrayList<>(CollectionUtils.collect(filtered, transformer)); }
From source file:org.squashtest.tm.domain.library.structures.LibraryTree.java
/** * <p>// w w w.j av a2 s . c om * That method will gather arbitrary informations on every single nodes and return the list of the gathered informations. What will be gathered and how it is done is defined in the * {@link Transformer} parameter. The tree will be processed top-down, ie, walked down (see {@link #doTopDown(Closure)}). * </p> * * @param <X> the type of the data returned by the transformer. * @param transformer the code to be applied over all the nodes. * @return the list of the gathered data. */ @SuppressWarnings("unchecked") public <X> List<X> collect(Transformer transformer) { return new ArrayList<>(CollectionUtils.collect(getAllNodes(), transformer)); }
From source file:org.squashtest.tm.service.internal.advancedsearch.AdvancedSearchServiceImpl.java
protected Criteria createMilestoneHibernateCriteria(Map<String, AdvancedSearchFieldModel> fields) { Session session = em.unwrap(Session.class); Criteria crit = session.createCriteria(Milestone.class, "milestone"); for (Entry<String, AdvancedSearchFieldModel> entry : fields.entrySet()) { AdvancedSearchFieldModel model = entry.getValue(); if (model != null) { switch (entry.getKey()) { case "milestone.label": List<String> labelValues = ((AdvancedSearchListFieldModel) model).getValues(); if (labelValues != null && !labelValues.isEmpty()) { Collection<Long> ids = CollectionUtils.collect(labelValues, new Transformer() { @Override public Object transform(Object val) { return Long.parseLong((String) val); }/* w w w . j a v a 2s .com*/ }); crit.add(Restrictions.in("id", ids));// milestone.label now contains ids } break; case "milestone.status": List<String> statusValues = ((AdvancedSearchListFieldModel) model).getValues(); if (statusValues != null && !statusValues.isEmpty()) { crit.add(Restrictions.in("status", convertStatus(statusValues))); } break; case "milestone.endDate": Date startDate = ((AdvancedSearchTimeIntervalFieldModel) model).getStartDate(); Date endDate = ((AdvancedSearchTimeIntervalFieldModel) model).getEndDate(); if (startDate != null) { Calendar cal = Calendar.getInstance(); cal.setTime(startDate); cal.set(Calendar.HOUR, 0); crit.add(Restrictions.ge("endDate", cal.getTime())); } if (endDate != null) { crit.add(Restrictions.le("endDate", endDate)); } break; default: // do nothing } } } // set the criteria projection so that we only fetch the ids crit.setProjection(Projections.property("milestone.id")); return crit; }
From source file:org.squashtest.tm.service.internal.advancedsearch.AdvancedSearchServiceImpl.java
protected Query buildLuceneTagsQuery(QueryBuilder qb, String fieldKey, List<String> tags, Operation operation) { Query main = null;//from ww w. j av a2 s . c o m @SuppressWarnings("unchecked") List<String> lowerTags = (List<String>) CollectionUtils.collect(tags, new Transformer() { @Override public Object transform(Object input) { return ((String) input).toLowerCase(); } }); switch (operation) { case AND: Query query; for (String tag : lowerTags) { query = qb.bool().must(qb.phrase().withSlop(0).onField(fieldKey).ignoreFieldBridge() .ignoreAnalyzer().sentence(tag).createQuery()).createQuery(); if (query == null) { break; } if (main == null) { main = query; } else { main = qb.bool().must(main).must(query).createQuery(); } } return qb.bool().must(main).createQuery(); case OR: return buildLuceneValueInListQuery(qb, fieldKey, lowerTags, true); default: throw new IllegalArgumentException("search on tag '" + fieldKey + "' : operation unknown"); } }