List of usage examples for java.lang Iterable iterator
Iterator<T> iterator();
From source file:io.orchestrate.client.integration.FetchTest.java
@Test public void fetchNonUrlFriendlyEventTypeForObject() throws InterruptedException, ExecutionException, TimeoutException { final String key = generateString(); final String value = "{}"; final String eventType = generateString() + "/ !"; KvStoreOperation kvStoreOp = new KvStoreOperation(TEST_COLLECTION, key, value); Future<KvMetadata> future_1 = client().execute(kvStoreOp); KvMetadata kvMetadata = future_1.get(3, TimeUnit.SECONDS); EventStoreOperation eventStoreOp = new EventStoreOperation(TEST_COLLECTION, key, eventType, value); Future<Boolean> future_2 = client().execute(eventStoreOp); Boolean success = future_2.get(3, TimeUnit.SECONDS); EventFetchOperation<String> eventFetchOp = new EventFetchOperation<String>(TEST_COLLECTION, key, eventType, String.class); Iterable<Event<String>> results = result(eventFetchOp); assertNotNull(kvMetadata);/* ww w .j av a2s . c om*/ assertNotNull(success); assertTrue(success); assertNotNull(results); Iterator<Event<String>> iter = results.iterator(); assertTrue(iter.hasNext()); Event<String> event = iter.next(); assertEquals(value, event.getValue()); }
From source file:com.auditbucket.test.functional.TestTags.java
@org.junit.Test @Transactional/* w ww . j av a2 s. c o m*/ public void secureMultiTenantedTags() throws Exception { engineAdmin.setMultiTenanted(true); SystemUser iSystemUser = regService.registerSystemUser(new RegistrationBean(company, mike, "bah")); assertNotNull(iSystemUser); List<TagInputBean> tags = new ArrayList<>(); TagInputBean tagInput = new TagInputBean("FLOP"); tags.add(tagInput); Iterable<TagInputBean> tagResult = tagService.processTags(tags); assertNotNull(tagResult); assertFalse(tagResult.iterator().hasNext()); // No errors were detected regService.registerSystemUser(new RegistrationBean("ABC", "gina", "bah")); Authentication authGina = new UsernamePasswordAuthenticationToken("gina", "user1"); SecurityContextHolder.getContext().setAuthentication(authGina); assertNull(tagService.findTag("FLOP")); // Can't see the Monowai company tag tagInput = new TagInputBean("FLOP"); assertNotNull(tagService.processTag(tagInput)); assertNull(tagService.findTag("ABC")); assertNotNull(tagService.findTag("FLOP")); }
From source file:computech.model.VideoCatalogIntegrationTests.java
@Test public void lazyLoadExceptionTest() { Iterable<Article> result = catalog2.findByType(ArticleType.NOTEBOOK); assertThat(result, is(iterableWithSize(2))); Article comp = new Article("TestPC", "Image", Money.of(BigDecimal.TEN, Currencies.EURO), "d2", ArticleType.NOTEBOOK);/*from w ww. jav a2 s . com*/ catalog2.save(comp); result = catalog2.findByType(ArticleType.NOTEBOOK); assertThat(result, is(iterableWithSize(3))); Iterator<Article> it = result.iterator(); while (it.hasNext()) { Article d = it.next(); assertThat(d.getType(), is(ArticleType.NOTEBOOK)); Iterable<String> iterable = d.getCategories(); assertThat(iterable, is(iterableWithSize(0))); } assertThat(result, hasItem(comp)); }
From source file:ltistarter.JPATests.java
@Test public void testJPA() { Iterable<LtiKeyEntity> keys; LtiKeyEntity key;/*from w ww .j a v a 2 s.com*/ int result; assertNotNull(ltiKeyRepository); keys = ltiKeyRepository.findAll(); assertFalse(keys.iterator().hasNext()); ltiKeyRepository.save(new LtiKeyEntity("key", "secret")); ltiKeyRepository.save(new LtiKeyEntity("AZkey", "AZsecret")); keys = ltiKeyRepository.findAll(); assertTrue(keys.iterator().hasNext()); assertEquals(2, CollectionUtils.size(keys.iterator())); key = ltiKeyRepository.findByKeyKey("not_real_key"); assertNull(key); key = ltiKeyRepository.findByKeyKey("key"); assertNotNull(key); assertEquals("secret", key.getSecret()); LtiKeyEntity key2 = ltiKeyRepository.findOne(key.getKeyId()); assertNotNull(key2); assertEquals(key, key2); key = ltiKeyRepository.findOne(key.getKeyId()); assertNotNull(key); ltiKeyRepository.delete(key); keys = ltiKeyRepository.findAll(); assertTrue(keys.iterator().hasNext()); assertEquals(1, CollectionUtils.size(keys.iterator())); result = ltiKeyRepository.deleteByKeyKey("not_real_key"); assertEquals(0, result); result = ltiKeyRepository.deleteByKeyKey("AZkey"); assertEquals(1, result); keys = ltiKeyRepository.findAll(); assertFalse(keys.iterator().hasNext()); assertEquals(0, CollectionUtils.size(keys.iterator())); }
From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java
@Test public void publicMethods() { memberCriteria.membersOfType(Method.class); memberCriteria.withAccess(AccessType.PUBLIC); ClassCriteria classCriteria = new ClassCriteria(); Iterable<Class<?>> classIterable = classCriteria.getIterable(ArrayList.class); Iterable<Member> memberIterable = memberCriteria.getIterable(classIterable); assertTrue(memberIterable.iterator().hasNext()); for (Member member : memberIterable) { assertTrue("member must be a method", member instanceof Method); int modifiers = member.getModifiers(); assertTrue(Modifier.isPublic(modifiers)); assertFalse(Modifier.isProtected(modifiers)); assertFalse(Modifier.isPrivate(modifiers)); }//from w w w . j a v a 2s . c o m }
From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java
@Test public void defaultAccessMethods() { memberCriteria.membersOfType(Method.class); memberCriteria.withAccess(AccessType.DEFAULT); ClassCriteria classCriteria = new ClassCriteria(); Iterable<Class<?>> classIterable = classCriteria.getIterable(Class.class); Iterable<Member> memberIterable = memberCriteria.getIterable(classIterable); assertTrue(memberIterable.iterator().hasNext()); for (Member member : memberIterable) { assertTrue("member must be a method", member instanceof Method); int modifiers = member.getModifiers(); assertFalse(Modifier.isPublic(modifiers)); assertFalse(Modifier.isProtected(modifiers)); assertFalse(Modifier.isPrivate(modifiers)); }/*from www . j a v a 2 s . c o m*/ }
From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java
@Test public void protecedConstructors() { memberCriteria.membersOfType(Constructor.class); memberCriteria.withAccess(AccessType.PROTECTED); ClassCriteria classCriteria = new ClassCriteria(); Iterable<Class<?>> classIterable = classCriteria.getIterable(ArrayList.class); Iterable<Member> memberIterable = memberCriteria.getIterable(classIterable); assertTrue(memberIterable.iterator().hasNext()); for (Member member : memberIterable) { assertTrue("member must be a constructor", member instanceof Constructor<?>); int modifiers = member.getModifiers(); assertFalse(Modifier.isPublic(modifiers)); assertTrue(Modifier.isProtected(modifiers)); assertFalse(Modifier.isPrivate(modifiers)); }//from w ww . j ava2 s . c om }
From source file:de.tudarmstadt.ukp.wikipedia.api.WikipediaInfo.java
/** Computes the average fan out of the page set. * Fan out is the number of outgoing links per page. * @param pageIDs The IDs of the pages./*from w ww.j a v a2 s . co m*/ * @return The average fan out. */ private double computeAverageFanOut(Iterable<Page> pages) { Set<Integer> pageIDs = new HashSet<Integer>(); while (pages.iterator().hasNext()) { pageIDs.add(pages.iterator().next().getPageId()); } if (pageIDs == null) { logger.error("Cannot compute average fan-out of an empty page set."); return 0.0; } int fanOutCounter = 0; Session session = this.wiki.__getHibernateSession(); session.beginTransaction(); Iterator results = session.createQuery("select page.outLinks, page.pageId from Page as page").list() .iterator(); while (results.hasNext()) { Object[] row = (Object[]) results.next(); Set outLinks = (Set) row[0]; Integer pageId = (Integer) row[1]; // if the current page ID is in the desired result set => add outlink value if (pageIDs.contains(pageId)) { fanOutCounter += outLinks.size(); } } session.getTransaction().commit(); return (double) fanOutCounter / this.getNumberOfPages(); }
From source file:edu.usc.pgroup.louvain.hadoop.ReduceCommunity.java
private Graph reconstructGraph(Iterable<BytesWritable> values) throws Exception { Iterator<BytesWritable> it = values.iterator(); SortedMap<Integer, GraphMessage> map = new TreeMap<Integer, GraphMessage>(); //Load data/*from w ww .jav a2 s . c o m*/ while (it.hasNext()) { BytesWritable bytesWritable = it.next(); ByteArrayInputStream inputStream = new ByteArrayInputStream(bytesWritable.getBytes()); try { ObjectInputStream objectInputStream = new ObjectInputStream(inputStream); GraphMessage msg = (GraphMessage) objectInputStream.readObject(); map.put(msg.getCurrentPartition(), msg); } catch (IOException e) { e.printStackTrace(); throw new Exception(e); } } // Renumber int gap = 0; int degreeGap = 0; Path pt = new Path(outpath + File.separator + "Map-Partition-Sizes"); FileSystem fs = FileSystem.get(new Configuration()); if (fs.exists(pt)) { fs.delete(pt, true); } BufferedWriter br = new BufferedWriter(new OutputStreamWriter(fs.create(pt, true))); PrintWriter out = new PrintWriter(br); for (int i = 0; i < map.keySet().size(); i++) { GraphMessage msg = map.get(i); long currentDegreelen = msg.getDegrees()[msg.getDegrees().length - 1]; if (i != 0) { for (int j = 0; j < msg.getLinks().length; j++) { msg.getLinks()[j] += gap; } for (int j = 0; j < msg.getRemoteMap().length; j++) { msg.getRemoteMap()[j].source += gap; } for (int j = 0; j < msg.getN2c().length; j++) { msg.getN2c()[j] += gap; } for (int j = 0; j < msg.getDegrees().length; j++) { msg.getDegrees()[j] += degreeGap; } } out.println("" + i + "," + msg.getNb_nodes()); gap += msg.getNb_nodes(); degreeGap += currentDegreelen; } out.flush(); out.close(); //Integrate Graph graph = new Graph(); for (int i = 0; i < map.keySet().size(); i++) { GraphMessage msg = map.get(i); Collections.addAll(graph.getDegrees().getList(), msg.getDegrees()); Collections.addAll(graph.getLinks().getList(), msg.getLinks()); Collections.addAll(graph.getWeights().getList(), msg.getWeights()); graph.setNb_links(graph.getNb_links() + msg.getNb_links()); graph.setNb_nodes((int) (graph.getNb_nodes() + msg.getNb_nodes())); graph.setTotal_weight(graph.getTotal_weight() + msg.getTotal_weight()); } //Merge local done. Map<Integer, Vector<Integer>> remoteEdges = new HashMap<Integer, Vector<Integer>>(); Map<Integer, Vector<Float>> remoteWeighs = new HashMap<Integer, Vector<Float>>(); for (int i = 0; i < map.keySet().size(); i++) { Map<HashMap.SimpleEntry<Integer, Integer>, Float> m = new HashMap<AbstractMap.SimpleEntry<Integer, Integer>, Float>(); GraphMessage msg = map.get(i); for (int j = 0; j < msg.getRemoteMap().length; j++) { RemoteMap remoteMap = msg.getRemoteMap()[j]; int sink = remoteMap.sink; int sinkPart = remoteMap.sinkPart; int target = map.get(sinkPart).getN2c()[sink]; HashMap.SimpleEntry<Integer, Integer> key = new HashMap.SimpleEntry<Integer, Integer>( remoteMap.source, target); if (m.containsKey(key)) { m.put(key, m.get(key) + 1.0f); } else { m.put(key, 1.0f); } } graph.setNb_links(graph.getNb_links() + m.size()); Iterator<HashMap.SimpleEntry<Integer, Integer>> itr = m.keySet().iterator(); while (itr.hasNext()) { HashMap.SimpleEntry<Integer, Integer> key = itr.next(); float w = m.get(key); if (remoteEdges.containsKey(key.getKey())) { remoteEdges.get(key.getKey()).getList().add(key.getValue()); if (remoteWeighs.containsKey(key.getKey())) { remoteWeighs.get(key.getKey()).getList().add(w); } } else { Vector<Integer> list = new Vector<Integer>(); list.getList().add(key.getValue()); remoteEdges.put(key.getKey(), list); Vector<Float> wList = new Vector<Float>(); wList.getList().add(w); remoteWeighs.put(key.getKey(), wList); } } } graph.addRemoteEdges(remoteEdges, remoteWeighs); //Merge Remote Done return graph; }
From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java
@Test public void privateStaticFields() { memberCriteria.membersOfType(Field.class); memberCriteria.withAccess(AccessType.PRIVATE); memberCriteria.withModifiers(Modifier.STATIC); ClassCriteria classCriteria = new ClassCriteria(); Iterable<Class<?>> classIterable = classCriteria.getIterable(Class.class); Iterable<Member> memberIterable = memberCriteria.getIterable(classIterable); assertTrue(memberIterable.iterator().hasNext()); for (Member member : memberIterable) { assertTrue("member must be a field", member instanceof Field); int modifiers = member.getModifiers(); assertFalse(Modifier.isPublic(modifiers)); assertFalse(Modifier.isProtected(modifiers)); assertTrue(Modifier.isPrivate(modifiers)); assertTrue(Modifier.isStatic(modifiers)); }//from w ww . j av a2s .c o m }