List of usage examples for org.apache.commons.collections.list SetUniqueList decorate
public static SetUniqueList decorate(List list)
From source file:com.redhat.persistence.oql.QFrame.java
QFrame(Generator generator) { m_generator = generator;//from ww w . ja v a 2 s . c o m m_alias = "t" + m_generator.getFrames().size(); m_equisetpool = new EquiSet(m_generator); m_nonnullpool = SetUniqueList.decorate(new ArrayList()); m_valuespool = new ArrayList(); m_columnspool = new HashMap(); m_qvaluespool = new ArrayList(); m_children = new ArrayList(); m_colkeys = new ArrayList(); }
From source file:net.sourceforge.atunes.kernel.modules.favorites.FavoritesSongsManager.java
/** * Takes songs from a list of audio objects and add or remove songs from * favorites//from w w w . j av a2s.c o m * * @param favorites * @param songs * @return if favorites have changed */ public boolean toggleFavoriteSongs(final IFavorites favorites, final List<ILocalAudioObject> songs) { if (CollectionUtils.isEmpty(songs)) { return false; } @SuppressWarnings("unchecked") Set<ILocalAudioObject> set = SetUniqueList.decorate(songs).asSet(); Set<ILocalAudioObject> toAdd = new HashSet<ILocalAudioObject>(); Set<ILocalAudioObject> toRemove = new HashSet<ILocalAudioObject>(); for (ILocalAudioObject song : set) { // Toggle favorite songs if (favorites.containsSong(song)) { toRemove.add(song); } else { toAdd.add(song); } } addSongs(favorites, toAdd, true); removeSongs(favorites, toRemove, true); return !toAdd.isEmpty() || !toRemove.isEmpty(); }
From source file:ke.co.tawi.babblesms.server.servlet.sms.send.SendSMS.java
/** * Method to handle form processing// w w w .j a v a2s . c o m * * @param request * @param response * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) * * @throws IOException */ @SuppressWarnings("unchecked") @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { // Respond as soon as possible to the client request HttpSession session = request.getSession(true); session.setAttribute(SessionConstants.SENT_SUCCESS, "success"); response.sendRedirect("sendsms.jsp"); // Get the relevant account Account account = new Account(); String username = request.getParameter("username"); Element element; if ((element = accountsCache.get(username)) != null) { account = (Account) element.getObjectValue(); } TawiGateway smsGateway = gatewayDAO.get(account); // Retrieve the web parameters String[] groupselected = request.getParameterValues("groupselected"); String[] phones = request.getParameterValues("phones"); String source = request.getParameter("source"); String message = request.getParameter("message"); // Deal with the case where one or more Groups has been selected // Get phones of all the Contacts in the Group(s) SetUniqueList phoneList = SetUniqueList.decorate(new LinkedList<Phone>()); // Does not allow duplicates Group group; List<Contact> contactList; List<OutgoingGrouplog> outgoingGroupList = new LinkedList<>(); if (groupselected != null) { OutgoingGrouplog groupLog; for (String groupUuid : groupselected) { group = new Group(); group.setUuid(groupUuid); contactList = ctgrpDAO.getContacts(group); for (Contact contact : contactList) { phoneList.addAll(phoneDAO.getPhones(contact)); } // Save an outgoing log for the group groupLog = new OutgoingGrouplog(); groupLog.setMessagestatusUuid(MsgStatus.SENT); groupLog.setSender(account.getUuid()); groupLog.setDestination(group.getUuid()); groupLog.setMessage(message); outgoingGroupList.add(groupLog); } // end 'for(String groupUuid : groupselected)' } // end 'if(groupselected != null)' // This is the case where individual Contacts may have been selected if (phones == null) { phones = new String[0]; } phones = StringUtil.removeDuplicates(phones); for (String phone : phones) { phoneList.add(phoneDAO.getPhone(phone)); } // Determine whether a shortcode or mask is the source SMSSource smsSource; Shortcode shortcode = shortcodeDAO.get(source); Mask mask = null; if (shortcode == null) { mask = maskDAO.get(source); smsSource = mask; } else { smsSource = shortcode; } // Set the network in the groups (if any) and save the log for (OutgoingGrouplog log : outgoingGroupList) { log.setNetworkUuid(smsSource.getNetworkuuid()); log.setOrigin(smsSource.getUuid()); groupLogDAO.put(log); } // Filter the phones to the Network of the source (mask or short code) List<Phone> validPhoneList = new LinkedList<>(); validPhoneList.addAll( CollectionUtils.select(phoneList, new PhonesByNetworkPredicate(smsSource.getNetworkuuid()))); // Break down the phone list to go out to manageable sizes, each sublist // being sent to the SMS Gateway in one URL POST List<List<Phone>> phonePartition = ListPartitioner.partition(validPhoneList, 10); // Send the lists one by one PostSMS postThread; for (List<Phone> list : phonePartition) { postThread = new PostSMS(smsGateway, list, smsSource, message, account, true); postThread.start(); } // Deduct credit smsBalanceDAO.deductBalance(account, smsSource, validPhoneList.size()); }
From source file:gov.nih.nci.caarray.dao.ArrayDaoImpl.java
/** * {@inheritDoc}/* w w w . ja v a2 s.com*/ */ @Override @SuppressWarnings({ "unchecked", "PMD.ExcessiveMethodLength", "PMD.NPathComplexity" }) public List<QuantitationType> searchForQuantitationTypes(PageSortParams<QuantitationType> params, QuantitationTypeSearchCriteria criteria) { final Criteria c = getCurrentSession().createCriteria(HybridizationData.class); c.createCriteria("hybridization").add(Restrictions.eq("id", criteria.getHybridization().getId())); c.createCriteria("dataSet").createAlias("quantitationTypes", "qt").createAlias("arrayData", "ad"); c.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP); if (!criteria.getArrayDataTypes().isEmpty()) { final List<Long> ids = new LinkedList<Long>(); for (final ArrayDataType type : criteria.getArrayDataTypes()) { ids.add(type.getId()); } c.createCriteria("ad.type").add(Restrictions.in("id", ids)); } if (!criteria.getFileTypes().isEmpty() || !criteria.getFileCategories().isEmpty()) { c.createAlias("ad.dataFile", "df"); } if (!criteria.getFileTypes().isEmpty()) { c.add(Restrictions.in("df.type", Sets.newHashSet(FileTypeRegistryImpl.namesForTypes(criteria.getFileTypes())))); } if (!criteria.getFileCategories().isEmpty()) { final Disjunction categoryCriterion = Restrictions.disjunction(); if (criteria.getFileCategories().contains(FileCategory.DERIVED_DATA)) { categoryCriterion.add(Restrictions.in("df.type", Sets.newHashSet( FileTypeRegistryImpl.namesForTypes(this.typeRegistry.getDerivedArrayDataTypes())))); } if (criteria.getFileCategories().contains(FileCategory.RAW_DATA)) { categoryCriterion.add(Restrictions.in("df.type", Sets .newHashSet(FileTypeRegistryImpl.namesForTypes(this.typeRegistry.getRawArrayDataTypes())))); } c.add(categoryCriterion); } c.setFirstResult(params.getIndex()); if (params.getPageSize() > 0) { c.setMaxResults(params.getPageSize()); } c.addOrder(toOrder(params, "qt")); final List<Map<String, Object>> results = c.list(); final List<QuantitationType> qTypes = SetUniqueList.decorate(new LinkedList<QuantitationType>()); for (final Map<String, Object> row : results) { final QuantitationType qt = (QuantitationType) row.get("qt"); qTypes.add(qt); } return qTypes; }
From source file:org.amplafi.json.JSONArray.java
public static JSONArray toJsonSet(Object value) { JSONArray r = toJsonArray(value);/* w w w . j av a 2s . c om*/ if (r != null) { r.myArrayList = SetUniqueList.decorate(r.myArrayList); } return r; }
From source file:org.apache.maven.shared.jar.classes.ImportVisitor.java
/** * Create an Import visitor./*ww w .j av a 2 s .c o m*/ * * @param javaClass the javaclass to work from */ public ImportVisitor(JavaClass javaClass) { this.javaClass = javaClass; // Create a list that is guaranteed to be unique while retaining it's list qualities (LinkedHashSet does not // expose the list interface even if natural ordering is retained) this.imports = SetUniqueList.decorate(new ArrayList()); }
From source file:org.apache.maven.shared.jar.classes.JarClasses.java
/** * Constructor to create an empty instance. *///w w w .j a v a 2s .c o m public JarClasses() { // Unique list decorators are used to ensure natural ordering is retained, the list interface is availble, and // that duplicates are not entered. imports = SetUniqueList.decorate(new ArrayList()); packages = SetUniqueList.decorate(new ArrayList()); classNames = SetUniqueList.decorate(new ArrayList()); methods = SetUniqueList.decorate(new ArrayList()); }
From source file:org.cropinformatics.ui.viewers.list.AbstractSingleListStructuredViewer.java
@SuppressWarnings("unchecked") public final boolean setItems(List<T> items) { if (items != null && !items.isEmpty()) { if (ConfigurationUtils.isCopyItemsInUse(getConfiguration())) { if (!getConfiguration().isDuplicateAllowed()) this.items = SetUniqueList.decorate(new LinkedList<T>()); else/*from w w w . ja v a 2s. c om*/ this.items = new LinkedList<T>(); Iterator<T> iterator = items.iterator(); while (iterator.hasNext()) this.items.add(copyItem(iterator.next())); } else { //TODO not supported //if (!getListViewerProperties().isDuplicateAllowed()) // this.items = SetUniqueList.decorate(items); //else setItemsInternal(items); } } else { //TODO not supported //if (!getListViewerProperties().isDuplicateAllowed()) // this.items = SetUniqueList.decorate(items); //else this.items = new LinkedList<T>(); } // reset selected items if (ConfigurationUtils.isMantainingSelectionState(getConfiguration())) initialiseSelection(); else setSelectedItems((List<T>) null); if (ConfigurationUtils.isMantainingCheckedState(getConfiguration())) initialiseChecked(); else setCheckedItems((List<T>) null); updateButtons(); updateItemList(); return true; }
From source file:org.cropinformatics.ui.viewers.list.AbstractSingleListStructuredViewer.java
@SuppressWarnings("unchecked") public final boolean addItems(List<T> items) { boolean success = true; if (items != null && !items.isEmpty()) { List<T> itemsToAdd; if (getConfiguration() != null && !getConfiguration().isDuplicateAllowed()) itemsToAdd = SetUniqueList.decorate(items); else//from w ww . j a v a 2s. co m itemsToAdd = items; if (getConfiguration() != null && getConfiguration().isCopyItemsInUse()) { Iterator<T> iterator = itemsToAdd.iterator(); while (success && iterator.hasNext()) success = this.items.add(copyItem(iterator.next())); } else { success = this.items.addAll(itemsToAdd); } updateButtons(); updateItemList(); } return success; }
From source file:org.jahia.modules.contribute.toolbar.actions.MultipleCopyAction.java
public ActionResult doExecute(HttpServletRequest req, RenderContext renderContext, Resource resource, JCRSessionWrapper session, Map<String, List<String>> parameters, URLResolver urlResolver) throws Exception { List<String> uuids = parameters.get(UUIDS); assert uuids != null && uuids.size() > 0; List<String> sessionUUIDS = (List<String>) req.getSession().getAttribute(UUIDS_TO_COPY); uuids = SetUniqueList.decorate(uuids); if (sessionUUIDS != null) { uuids.addAll(sessionUUIDS);/*from w ww. ja v a 2s . c o m*/ } req.getSession().setAttribute(UUIDS_TO_COPY, uuids); return ActionResult.OK_JSON; }