List of usage examples for org.apache.commons.collections CollectionUtils addAll
public static void addAll(Collection collection, Object[] elements)
From source file:com.liangc.hq.base.utils.BizappUtils.java
public static List sortAIResource(List resource) { List sortedList = new ArrayList(); SortedSet sSet = new TreeSet(new BizappUtils().new AIResourceIdComparator()); sSet.addAll(resource);/*from w w w .j a v a2 s . com*/ CollectionUtils.addAll(sortedList, sSet.iterator()); return sortedList; }
From source file:com.lushapp.common.utils.reflection.ReflectionUtils.java
/** * * ?annotationClass/*from w w w. j a va 2 s . c o m*/ * * @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 = (List<T>) getAnnotations(superClass, annotationClass); if (CollectionUtils.isNotEmpty(temp)) { CollectionUtils.addAll(result, temp.iterator()); } } return result; }
From source file:net.sf.diningout.app.ui.FriendsFragment.java
/** * Start an email app to send an invitation to selected contacts. *///from ww w .j av a 2 s . com void invite() { if (mGrid.getCheckedItemCount() <= 0) { return; } List<String> to = null; int[] keys = SparseArrays.trueKeys(mGrid.getCheckedItemPositions()); for (int pos : keys) { EasyCursor c = (EasyCursor) mGrid.getItemAtPosition(pos); if (c.isNull(Contacts.GLOBAL_ID) && !c.isNull(Contacts.EMAIL)) { if (to == null) { to = new ArrayList<>(keys.length); } String email = c.getString(Contacts.EMAIL); if (!email.contains("\t")) { to.add(email); } else { CollectionUtils.addAll(to, email.split("\t")); } } } if (to != null) { sendInvite(to, this); event("friends", "invite", to.size()); } }
From source file:com.liangc.hq.base.utils.BizappUtils.java
/** * This method sorts list of AppdefResourceValue objects * //from w w w .ja v a 2 s . c om * @return a list of AppdefResourceValue objects */ public static List<AppdefResourceValue> sortAppdefResource(List appdefList, PageControl pc) { List sortedList = new ArrayList(); SortedSet sSet = new TreeSet(new BizappUtils().new AppdefResourceNameComparator(pc)); sSet.addAll(appdefList); CollectionUtils.addAll(sortedList, sSet.iterator()); // There are duplicated names, figure out where to insert them for (Iterator it = appdefList.iterator(); sortedList.size() != appdefList.size() && it.hasNext();) { AppdefResourceValue res = (AppdefResourceValue) it.next(); for (int i = 0; i < sortedList.size(); i++) { AppdefResourceValue sorted = (AppdefResourceValue) sortedList.get(i); if (sorted.getEntityId().equals(res.getEntityId())) break; // Either it's meant to go in between or the last if (res.getName().toLowerCase().compareTo(sorted.getName().toLowerCase()) < 0 || i == sortedList.size() - 1) { sortedList.add(i, res); break; } } } return sortedList; }
From source file:com.google.gdt.eclipse.designer.nls.GwtSource.java
/** * Adds or removes (depending on value of "add" parameter) given locale into module. *//*www. ja v a 2 s. c o m*/ private void modifyLocalesSet(final LocaleInfo locale, final boolean add) throws Exception { // don't add default locale if (locale.isDefault()) { return; } // ModuleDescription module = getModule(m_root); DefaultModuleProvider.modify(module, new ModuleModification() { public void modify(ModuleElement moduleElement) throws Exception { // build list of locales in <extent-property name='locale'> elements, remove these elements List<String> locales = Lists.newArrayList(); for (ExtendPropertyElement extendPropertyElement : moduleElement.getExtendPropertyElements()) { if (extendPropertyElement.getName().equals("locale")) { extendPropertyElement.remove(); String[] parts = StringUtils.split(extendPropertyElement.getValues(), ", "); CollectionUtils.addAll(locales, parts); } } // add/remove new locale { String localeName = locale.getTitle(); if (add) { locales.add(localeName); } else { locales.remove(localeName); } } // sort locales Collections.sort(locales); // add new <extent-property> with all locales { ExtendPropertyElement extendPropertyElement = new ExtendPropertyElement(); moduleElement.addChild(extendPropertyElement); extendPropertyElement.setName("locale"); extendPropertyElement.setValues(StringUtils.join(locales.iterator(), ",")); } } }); }
From source file:com.startupbidder.dao.MockDataBuilder.java
public String iterateThroughDatastore(boolean delete, List<Object> dtoList) { StringBuffer outputBuffer = new StringBuffer(); outputBuffer.append("<a href=\"/setup\">Setup page</a>"); if (delete) { outputBuffer.append("<p>Deleted objects:</p>"); } else {/* www . ja va 2s . c o m*/ outputBuffer.append("<p>Datastore objects:</p>"); } List<Key<SBUser>> userKeys = new ArrayList<Key<SBUser>>(); CollectionUtils.addAll(userKeys, getOfy().query(SBUser.class).fetchKeys().iterator()); outputBuffer.append("<p>Users (" + userKeys.size() + "):</p>"); for (SBUser obj : getOfy().get(userKeys).values()) { outputBuffer.append(obj).append("<br/>"); } if (delete) { getOfy().delete(userKeys); } List<Key<UserStats>> userStatKeys = new ArrayList<Key<UserStats>>(); CollectionUtils.addAll(userStatKeys, getOfy().query(UserStats.class).fetchKeys().iterator()); outputBuffer.append("<p>User stats (" + userStatKeys.size() + "):</p>"); for (UserStats obj : getOfy().get(userStatKeys).values()) { outputBuffer.append(obj).append("<br/>"); } if (delete) { getOfy().delete(userStatKeys); } List<Key<Category>> catKeys = new ArrayList<Key<Category>>(); CollectionUtils.addAll(catKeys, getOfy().query(Category.class).fetchKeys().iterator()); outputBuffer.append("<p>Categories (" + catKeys.size() + "):</p>"); if (catKeys.size() > 0) { //for (Bid obj : getOfy().get(bidKeys).values()) { for (Key<Category> key : catKeys) { Category obj = getOfy().get(key); outputBuffer.append(obj).append("<br/>"); } if (delete) { getOfy().delete(catKeys); } } List<Key<Bid>> bidKeys = new ArrayList<Key<Bid>>(); CollectionUtils.addAll(bidKeys, getOfy().query(Bid.class).fetchKeys().iterator()); outputBuffer.append("<p>Bids (" + bidKeys.size() + "):</p>"); if (bidKeys.size() > 0) { //for (Bid obj : getOfy().get(bidKeys).values()) { for (Key<Bid> key : bidKeys) { Bid obj = getOfy().get(key); outputBuffer.append(obj).append("<br/>"); } if (delete) { getOfy().delete(bidKeys); } } List<Key<BidUser>> bidUserKeys = new ArrayList<Key<BidUser>>(); CollectionUtils.addAll(bidUserKeys, getOfy().query(BidUser.class).fetchKeys().iterator()); outputBuffer.append("<p>Bid users (" + bidUserKeys.size() + "):</p>"); if (bidUserKeys.size() > 0) { for (BidUser obj : getOfy().get(bidUserKeys).values()) { outputBuffer.append(obj).append("<br/>"); } if (delete) { getOfy().delete(bidUserKeys); } } List<Key<Comment>> comKeys = new ArrayList<Key<Comment>>(); CollectionUtils.addAll(comKeys, getOfy().query(Comment.class).fetchKeys().iterator()); outputBuffer.append("<p>Comments (" + comKeys.size() + "):</p>"); if (comKeys.size() > 0) { for (Comment obj : getOfy().get(comKeys).values()) { outputBuffer.append(obj).append("<br/>"); } if (delete) { getOfy().delete(comKeys); } } List<Key<Listing>> listingKeys = new ArrayList<Key<Listing>>(); CollectionUtils.addAll(listingKeys, getOfy().query(Listing.class).fetchKeys().iterator()); outputBuffer.append("<p>Listings (" + listingKeys.size() + "):</p>"); if (listingKeys.size() > 0) { // for (Listing obj : getOfy().get(listingKeys).values()) { // outputBuffer.append(obj).append("<br/>"); // } if (delete) { getOfy().delete(listingKeys); } } List<Key<ListingDoc>> listingDocKeys = new ArrayList<Key<ListingDoc>>(); CollectionUtils.addAll(listingDocKeys, getOfy().query(ListingDoc.class).fetchKeys().iterator()); outputBuffer.append("<p>Listing docs (" + listingDocKeys.size() + "):</p>"); if (listingDocKeys.size() > 0) { // for (ListingDoc obj : getOfy().get(listingDocKeys).values()) { // outputBuffer.append(obj).append("<br/>"); // } if (delete) { getOfy().delete(listingDocKeys); } } List<Key<ListingStats>> listingStatKeys = new ArrayList<Key<ListingStats>>(); CollectionUtils.addAll(listingStatKeys, getOfy().query(ListingStats.class).fetchKeys().iterator()); // outputBuffer.append("<p>Listing stats (" + listingStatKeys.size() + "):</p>"); // for (ListingStats obj : getOfy().get(listingStatKeys).values()) { // outputBuffer.append(obj).append("<br/>"); // } if (delete) { getOfy().delete(listingStatKeys); } List<Key<Rank>> rankKeys = new ArrayList<Key<Rank>>(); CollectionUtils.addAll(rankKeys, getOfy().query(Rank.class).fetchKeys().iterator()); // outputBuffer.append("<p>Listing stats (" + rankKeys.size() + "):</p>"); // for (Rank obj : getOfy().get(rankKeys).values()) { // outputBuffer.append(obj).append("<br/>"); // } if (delete) { getOfy().delete(rankKeys); } List<Key<SystemProperty>> propKeys = new ArrayList<Key<SystemProperty>>(); CollectionUtils.addAll(propKeys, getOfy().query(SystemProperty.class).fetchKeys().iterator()); // outputBuffer.append("<p>System properties (" + propKeys.size() + "):</p>"); // for (SystemProperty obj : getOfy().get(propKeys).values()) { // outputBuffer.append(obj).append("<br/>"); // } if (delete) { getOfy().delete(propKeys); } List<Key<Vote>> voteKeys = new ArrayList<Key<Vote>>(); CollectionUtils.addAll(voteKeys, getOfy().query(Vote.class).fetchKeys().iterator()); // outputBuffer.append("<p>Votes (" + voteKeys.size() + "):</p>"); // for (Vote obj : getOfy().get(voteKeys).values()) { // outputBuffer.append(obj).append("<br/>"); // } if (delete) { getOfy().delete(voteKeys); } outputBuffer.append("<p><a href=\"/setup\">Setup page</a></p>"); return outputBuffer.toString(); }
From source file:com.charmyin.shiro.realm.jdbc.CustomJdbcRealm.java
/** * Get permission string set by menu ids * @param menuIdsSb/*from w w w .j a v a 2 s. co m*/ * @return */ private Set<String> getPermissionByMenuIds(Connection conn, StringBuilder menuIdsSb) throws SQLException { //if nomenuid exists, return null String menuIdsStr = menuIdsSb.toString(); if (menuIdsStr.trim().length() < 1) { return null; } String[] menuIdsArray = menuIdsStr.split(","); //Menu Ids set Set<String> set = new HashSet<String>(); CollectionUtils.addAll(set, menuIdsArray); Set<String> permissionSet = new HashSet<String>(); //Get menu permissions by menu ids PreparedStatement ps = null; try { ps = conn.prepareStatement(permissionsQueryByMenuId); for (String menuId : set) { int menuIdInt = 0; //no empty value try { menuIdInt = Integer.parseInt(menuId); } catch (Exception e) { log.warn("menuId:" + menuId + " is not integer!"); continue; } ps.setInt(1, menuIdInt); ResultSet rs = null; try { // Execute query rs = ps.executeQuery(); // Loop over results and add each returned role to a set while (rs.next()) { String permissionString = rs.getString(1); // Add the menu Permission to the set of menuPermissions permissionSet.add(permissionString); } } finally { JdbcUtils.closeResultSet(rs); } } } finally { JdbcUtils.closeStatement(ps); } return permissionSet; }
From source file:immf.SendMailBridge.java
private static List<InternetAddress> getRecipients(MimeMessage msg, String type) throws MessagingException { List<InternetAddress> r = new ArrayList<InternetAddress>(); String[] headers = msg.getHeader(type); if (headers == null) { return r; }// w ww .j av a 2 s . c o m for (String h : headers) { InternetAddress[] addrs = InternetAddress.parse(h); CollectionUtils.addAll(r, addrs); } return r; }
From source file:eu.finwest.dao.MockDataBuilder.java
public String iterateThroughDatastore(boolean delete, List<Object> dtoList) { StringBuffer outputBuffer = new StringBuffer(); outputBuffer.append("<a href=\"/setup\">Setup page</a>"); if (delete) { outputBuffer.append("<p>Deleted objects:</p>"); } else {// w ww. j a va 2 s . c om outputBuffer.append("<p>Datastore objects:</p>"); } List<Key<SBUser>> userKeys = new ArrayList<Key<SBUser>>(); CollectionUtils.addAll(userKeys, getOfy().query(SBUser.class).fetchKeys().iterator()); outputBuffer.append("<p>Users (" + userKeys.size() + "):</p>"); for (SBUser obj : getOfy().get(userKeys).values()) { outputBuffer.append(obj).append("<br/>"); } if (delete) { getOfy().delete(userKeys); } List<Key<UserStats>> userStatKeys = new ArrayList<Key<UserStats>>(); CollectionUtils.addAll(userStatKeys, getOfy().query(UserStats.class).fetchKeys().iterator()); outputBuffer.append("<p>User stats (" + userStatKeys.size() + "):</p>"); for (UserStats obj : getOfy().get(userStatKeys).values()) { outputBuffer.append(obj).append("<br/>"); } if (delete) { getOfy().delete(userStatKeys); } List<Key<Campaign>> campaignKeys = new ArrayList<Key<Campaign>>(); CollectionUtils.addAll(campaignKeys, getOfy().query(Campaign.class).fetchKeys().iterator()); outputBuffer.append("<p>Campaigns (" + campaignKeys.size() + "):</p>"); for (Campaign obj : getOfy().get(campaignKeys).values()) { outputBuffer.append(obj).append("<br/>"); } if (delete) { getOfy().delete(campaignKeys); } List<Key<Category>> catKeys = new ArrayList<Key<Category>>(); CollectionUtils.addAll(catKeys, getOfy().query(Category.class).fetchKeys().iterator()); outputBuffer.append("<p>Categories (" + catKeys.size() + "):</p>"); if (catKeys.size() > 0) { //for (Bid obj : getOfy().get(bidKeys).values()) { for (Key<Category> key : catKeys) { Category obj = getOfy().get(key); outputBuffer.append(obj).append("<br/>"); } if (delete) { getOfy().delete(catKeys); } } List<Key<Bid>> bidKeys = new ArrayList<Key<Bid>>(); CollectionUtils.addAll(bidKeys, getOfy().query(Bid.class).fetchKeys().iterator()); outputBuffer.append("<p>Bids (" + bidKeys.size() + "):</p>"); if (bidKeys.size() > 0) { //for (Bid obj : getOfy().get(bidKeys).values()) { for (Key<Bid> key : bidKeys) { Bid obj = getOfy().get(key); outputBuffer.append(obj).append("<br/>"); } if (delete) { getOfy().delete(bidKeys); } } List<Key<BidUser>> bidUserKeys = new ArrayList<Key<BidUser>>(); CollectionUtils.addAll(bidUserKeys, getOfy().query(BidUser.class).fetchKeys().iterator()); outputBuffer.append("<p>Bid users (" + bidUserKeys.size() + "):</p>"); if (bidUserKeys.size() > 0) { for (BidUser obj : getOfy().get(bidUserKeys).values()) { outputBuffer.append(obj).append("<br/>"); } if (delete) { getOfy().delete(bidUserKeys); } } List<Key<Comment>> comKeys = new ArrayList<Key<Comment>>(); CollectionUtils.addAll(comKeys, getOfy().query(Comment.class).fetchKeys().iterator()); outputBuffer.append("<p>Comments (" + comKeys.size() + "):</p>"); if (comKeys.size() > 0) { for (Comment obj : getOfy().get(comKeys).values()) { outputBuffer.append(obj).append("<br/>"); } if (delete) { getOfy().delete(comKeys); } } List<Key<Listing>> listingKeys = new ArrayList<Key<Listing>>(); CollectionUtils.addAll(listingKeys, getOfy().query(Listing.class).fetchKeys().iterator()); outputBuffer.append("<p>Listings (" + listingKeys.size() + "):</p>"); if (listingKeys.size() > 0) { // for (Listing obj : getOfy().get(listingKeys).values()) { // outputBuffer.append(obj).append("<br/>"); // } if (delete) { getOfy().delete(listingKeys); } } List<Key<ListingDoc>> listingDocKeys = new ArrayList<Key<ListingDoc>>(); CollectionUtils.addAll(listingDocKeys, getOfy().query(ListingDoc.class).fetchKeys().iterator()); outputBuffer.append("<p>Listing docs (" + listingDocKeys.size() + "):</p>"); if (listingDocKeys.size() > 0) { // for (ListingDoc obj : getOfy().get(listingDocKeys).values()) { // outputBuffer.append(obj).append("<br/>"); // } if (delete) { getOfy().delete(listingDocKeys); } } List<Key<ListingStats>> listingStatKeys = new ArrayList<Key<ListingStats>>(); CollectionUtils.addAll(listingStatKeys, getOfy().query(ListingStats.class).fetchKeys().iterator()); // outputBuffer.append("<p>Listing stats (" + listingStatKeys.size() + "):</p>"); // for (ListingStats obj : getOfy().get(listingStatKeys).values()) { // outputBuffer.append(obj).append("<br/>"); // } if (delete) { getOfy().delete(listingStatKeys); } List<Key<Rank>> rankKeys = new ArrayList<Key<Rank>>(); CollectionUtils.addAll(rankKeys, getOfy().query(Rank.class).fetchKeys().iterator()); // outputBuffer.append("<p>Listing stats (" + rankKeys.size() + "):</p>"); // for (Rank obj : getOfy().get(rankKeys).values()) { // outputBuffer.append(obj).append("<br/>"); // } if (delete) { getOfy().delete(rankKeys); } List<Key<SystemProperty>> propKeys = new ArrayList<Key<SystemProperty>>(); CollectionUtils.addAll(propKeys, getOfy().query(SystemProperty.class).fetchKeys().iterator()); // outputBuffer.append("<p>System properties (" + propKeys.size() + "):</p>"); // for (SystemProperty obj : getOfy().get(propKeys).values()) { // outputBuffer.append(obj).append("<br/>"); // } if (delete) { getOfy().delete(propKeys); } List<Key<Vote>> voteKeys = new ArrayList<Key<Vote>>(); CollectionUtils.addAll(voteKeys, getOfy().query(Vote.class).fetchKeys().iterator()); // outputBuffer.append("<p>Votes (" + voteKeys.size() + "):</p>"); // for (Vote obj : getOfy().get(voteKeys).values()) { // outputBuffer.append(obj).append("<br/>"); // } if (delete) { getOfy().delete(voteKeys); } outputBuffer.append("<p><a href=\"/setup\">Setup page</a></p>"); return outputBuffer.toString(); }
From source file:com.google.gdt.eclipse.designer.util.Utils.java
/** * Uses "htmlParser" library to parse given HTML and extract tags with given name. * //from w w w . j ava 2s . c o m * @return the {@link List} of found {@link TagNode}'s. */ private static List<TagNode> getHTMLFileTags(IFile htmlFile, String tagName) throws Exception { // find nodes Node[] tags; { String htmlContents = IOUtils2.readString(htmlFile); Lexer lexer = new Lexer(new Page(htmlContents)); Parser parser = new Parser(lexer, new DefaultParserFeedback(DefaultParserFeedback.QUIET)); TagFindingVisitor visitor = new TagFindingVisitor(new String[] { tagName }); parser.visitAllNodesWith(visitor); tags = visitor.getTags(0); } // convert into List<TagNode> List<TagNode> tagNodes = Lists.newArrayList(); CollectionUtils.addAll(tagNodes, tags); return tagNodes; }