List of usage examples for org.apache.commons.collections4 IteratorUtils toList
public static <E> List<E> toList(final Iterator<? extends E> iterator)
From source file:com.link_intersystems.lang.reflect.criteria.ClassCriteriaTest.java
@SuppressWarnings("unchecked") @Test//from w ww .j a v a2 s.co m public void visitAllFilter() { classCriteria.setTraverseStrategy(TraverseStrategy.DEPTH_FIRST); classCriteria.setSelection(ClassType.INTERFACES); classCriteria.add(ReflectFacade.getIsInterfacePredicate()); classCriteria.add(NotPredicate .notPredicate(EqualPredicate.equalPredicate(GenericSubSubWithMultipleInterfaces.class))); classCriteria.setTraverseClassesUniquely(false); Iterator<Class<?>> iterator = classCriteria.getIterable(GenericSubSubWithMultipleInterfaces.class) .iterator(); List<Class<?>> interfaces = IteratorUtils.toList(iterator); Collection<Class<?>> expectedInterfaces = new ArrayList<Class<?>>(Arrays.asList(GenericSubInterface.class, GenericInterface_Types_A_B_C.class, GenericInterface_Types_A_B_C.class)); for (Class<?> interf : interfaces) { assertTrue("Unexpected " + interf + " in interator", expectedInterfaces.remove(interf)); } assertTrue("Iterator does not iterator over the interfaces " + expectedInterfaces, expectedInterfaces.isEmpty()); }
From source file:com.feilong.tools.jsonlib.JsonUtil.java
/** * Bean?Map?????Json./*from w ww .ja va 2 s. c o m*/ * * <p> * <code>null==jsonConfig</code>, {@link #DEFAULT_JSON_CONFIG} * </p> * * @param obj * the obj * @param jsonConfig * the json config * @return the jSON * @see net.sf.json.JSONArray#fromObject(Object, JsonConfig) * @see net.sf.json.JSONObject#fromObject(Object, JsonConfig) * @see net.sf.json.util.JSONUtils#isArray(Object) * @see java.lang.Class#isEnum() * @see net.sf.json.JsonConfig#registerJsonValueProcessor(Class, JsonValueProcessor) * @see org.apache.commons.collections4.IteratorUtils#toList(Iterator) * @see org.apache.commons.collections4.IteratorUtils#toList(Iterator, int) * @see net.sf.json.JSONSerializer#toJSON(Object) */ static JSON toJSON(Object obj, JsonConfig jsonConfig) { JsonConfig useJsonConfig = ObjectUtils.defaultIfNull(jsonConfig, DEFAULT_JSON_CONFIG); registerDefaultJsonValueProcessor(useJsonConfig); if (isNeedConvertToJSONArray(obj)) { Object arrayJsonObject = obj instanceof Iterator ? IteratorUtils.toList((Iterator<?>) obj) : obj; return toJSONArray(arrayJsonObject, useJsonConfig); } return toJSONObject(obj, useJsonConfig); }
From source file:com.shampan.model.UserModel.java
/** * This method will get user info list// www. ja v a 2s.c om * * @param userIdList user id list of users */ public List<UserDAO> getUserInfoList(String userIdList) { MongoCollection<UserDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.USERS.toString(), UserDAO.class); String attrUserId = PropertyProvider.get("USER_ID"); String attrFirstName = PropertyProvider.get("FIRST_NAME"); String attrLastName = PropertyProvider.get("LAST_NAME"); JSONArray userIds = new JSONArray(userIdList); int userIdsSize = userIds.length(); List<Document> orSelectionDocument = new ArrayList<Document>(); List<UserDAO> userList = null; if (userIdsSize > 0) { for (int i = 0; i < userIdsSize; i++) { Document userSelectionDocument = new Document(); userSelectionDocument.put(attrUserId, userIds.get(i)); orSelectionDocument.add(userSelectionDocument); } Document selectDocument = new Document(); selectDocument.put("$or", orSelectionDocument); Document pQueryDocument = new Document(); pQueryDocument.put(attrUserId, "$all"); pQueryDocument.put(attrFirstName, "$all"); pQueryDocument.put(attrLastName, "$all"); pQueryDocument.put("gender", "$all"); MongoCursor<UserDAO> userInfoList = mongoCollection.find(selectDocument).projection(pQueryDocument) .iterator(); userList = IteratorUtils.toList(userInfoList); } return userList; }
From source file:com.shampan.model.PageModel.java
public List<PageAlbumDAO> getAlbums(String pageId) { MongoCollection<PageAlbumDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.PAGEALBUMS.toString(), PageAlbumDAO.class); BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start("pageId").is(pageId).get(); Document pQuery = new Document(); pQuery.put("albumId", "$all"); pQuery.put("title", "$all"); pQuery.put("totalImg", "$all"); pQuery.put("defaultImg", "$all"); MongoCursor<PageAlbumDAO> cursorAlbumList = mongoCollection.find(selectQuery).projection(pQuery).iterator(); List<PageAlbumDAO> albumList = IteratorUtils.toList(cursorAlbumList); return albumList; }
From source file:com.github.rvesse.airline.model.MetadataLoader.java
private static List<OptionMetadata> overrideOptionSet(List<OptionMetadata> options) { options = ListUtils.unmodifiableList(options); Map<Set<String>, OptionMetadata> optionIndex = new HashMap<>(); for (OptionMetadata option : options) { Set<String> names = option.getOptions(); if (optionIndex.containsKey(names)) { // Multiple classes in the hierarchy define this option // Determine if we can successfully override this option tryOverrideOptions(optionIndex, names, option); } else {/*from w w w . j a va 2 s . c om*/ // Need to check there isn't another option with partial overlap // of names, this is considered an illegal override for (Set<String> existingNames : optionIndex.keySet()) { Set<String> intersection = AirlineUtils.intersection(names, existingNames); if (intersection.size() > 0) { throw new IllegalArgumentException(String.format( "Fields %s and %s have overlapping definitions of option %s, options can only be overridden if they have precisely the same set of option names", option.getAccessors().iterator().next(), optionIndex.get(existingNames).getAccessors().iterator().next(), intersection)); } } optionIndex.put(names, option); } } return ListUtils.unmodifiableList(IteratorUtils.toList(optionIndex.values().iterator())); }
From source file:com.shampan.model.PageModel.java
public ResultEvent getTimelinePhotos(String pageId) { try {/*from ww w . j a va 2s. c o m*/ MongoCollection<PagePhotoDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.PAGEPHOTOS.toString(), PagePhotoDAO.class); Document selectionDocument = new Document(); selectionDocument.put("pageId", pageId); selectionDocument.put("albumId", PropertyProvider.get("TIMELINE_PHOTOS_ALBUM_ID")); MongoCursor<PagePhotoDAO> photoList = mongoCollection.find(selectionDocument).iterator(); List<PagePhotoDAO> photoInfoList = IteratorUtils.toList(photoList); this.getResultEvent().setResult(photoInfoList); this.getResultEvent().setResponseCode(PropertyProvider.get("SUCCESSFUL_OPERATION")); } catch (Exception ex) { this.getResultEvent().setResponseCode(PropertyProvider.get("ERROR_EXCEPTION")); } return this.resultEvent; }
From source file:com.shampan.model.PageModel.java
public List<PagePhotoDAO> getPhotos(String mappingId, String albumId) { MongoCollection<PagePhotoDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.ALBUMPHOTOS.toString(), PagePhotoDAO.class); Document selectDocument = new Document(); selectDocument.put("pageId", mappingId); selectDocument.put("albumId", albumId); Document pQurey = new Document(); pQurey.put("photoId", "$all"); pQurey.put("albumId", "$all"); pQurey.put("pageId", "$all"); pQurey.put("image", "$all"); MongoCursor<PagePhotoDAO> cursorStatusInfoList = mongoCollection.find(selectDocument).projection(pQurey) .iterator();/*from ww w. jav a 2s . co m*/ List<PagePhotoDAO> photoList = IteratorUtils.toList(cursorStatusInfoList); return photoList; }
From source file:org.apache.metron.profiler.spark.function.HBaseWriterFunction.java
/** * Writes a set of measurements to HBase. * * @param iterator The measurements to write. * @return The number of measurements written to HBase. *///from w ww .j a v a 2s . com @Override public Iterator<Integer> call(Iterator<ProfileMeasurementAdapter> iterator) throws Exception { int count = 0; LOG.debug("About to write profile measurement(s) to HBase"); // do not open hbase connection, if nothing to write List<ProfileMeasurementAdapter> measurements = IteratorUtils.toList(iterator); if (measurements.size() > 0) { // open an HBase connection Configuration config = HBaseConfiguration.create(); try (HBaseClient client = new HBaseClient(tableProvider, config, tableName)) { for (ProfileMeasurementAdapter adapter : measurements) { ProfileMeasurement m = adapter.toProfileMeasurement(); client.addMutation(rowKeyBuilder.rowKey(m), columnBuilder.columns(m), durability); } count = client.mutate(); } catch (IOException e) { LOG.error("Unable to open connection to HBase", e); throw new RuntimeException(e); } } LOG.debug("{} profile measurement(s) written to HBase", count); return IteratorUtils.singletonIterator(count); }
From source file:org.apache.metron.profiler.spark.function.HBaseWriterFunctionTest.java
@Test public void testWrite() throws Exception { JSONObject message = getMessage();//from w w w . ja v a2 s .c o m String entity = (String) message.get("ip_src_addr"); long timestamp = (Long) message.get("timestamp"); ProfileConfig profile = getProfile(); // setup the profile measurements that will be written List<ProfileMeasurementAdapter> measurements = createMeasurements(1, entity, timestamp, profile); // setup the function to test HBaseWriterFunction function = new HBaseWriterFunction(profilerProperties); function.withTableProviderImpl(MockHBaseTableProvider.class.getName()); // write the measurements Iterator<Integer> results = function.call(measurements.iterator()); // validate the result List<Integer> counts = IteratorUtils.toList(results); Assert.assertEquals(1, counts.size()); Assert.assertEquals(1, counts.get(0).intValue()); }
From source file:org.apache.metron.profiler.spark.function.HBaseWriterFunctionTest.java
@Test public void testWriteMany() throws Exception { JSONObject message = getMessage();//from www. j a va 2s .co m String entity = (String) message.get("ip_src_addr"); long timestamp = (Long) message.get("timestamp"); ProfileConfig profile = getProfile(); // setup the profile measurements that will be written List<ProfileMeasurementAdapter> measurements = createMeasurements(10, entity, timestamp, profile); // setup the function to test HBaseWriterFunction function = new HBaseWriterFunction(profilerProperties); function.withTableProviderImpl(MockHBaseTableProvider.class.getName()); // write the measurements Iterator<Integer> results = function.call(measurements.iterator()); // validate the result List<Integer> counts = IteratorUtils.toList(results); Assert.assertEquals(1, counts.size()); Assert.assertEquals(10, counts.get(0).intValue()); }