List of usage examples for java.lang Iterable iterator
Iterator<T> iterator();
From source file:com.galeoconsulting.leonardinius.api.impl.ServletVelocityHelperImpl.java
@Override public SessionBean getSessionBean(final String sessionId) { if (StringUtils.isBlank(sessionId)) { return null; }/* w w w . j a v a2s. c o m*/ Iterable<SessionBean> iterable = Iterables.filter(getAllSessionBeans(), new Predicate<SessionBean>() { @Override public boolean apply(@Nullable SessionBean input) { return StringUtils.equals(sessionId, input.getSessionId()); } }); return iterable.iterator().hasNext() ? iterable.iterator().next() : null; }
From source file:eu.stratosphere.util.dag.GraphModule.java
private List<Node> getUnmatchingNode(final Iterable<? extends Node> nodes1, final Iterable<? extends Node> nodes2, final IdentitySet<Node> seen) { final Iterator<? extends Node> iterator1 = nodes1.iterator(); final Iterator<? extends Node> iterator2 = nodes2.iterator(); while (iterator1.hasNext() && iterator2.hasNext()) { final Node node1 = iterator1.next(); final Node node2 = iterator2.next(); if (node1 == node2) continue; if (node1 == null || !node1.equals(node2)) return Arrays.asList(node1, node2); final List<Node> unmatching = this.getUnmatchingNode(this.navigator.getConnectedNodes(node1), this.navigator.getConnectedNodes(node2), seen); if (!unmatching.isEmpty()) return unmatching; }//from w w w . j a v a 2s . c o m return new ArrayList<Node>(); }
From source file:com.ailk.oci.ocnosql.tools.load.single.SingleColumnReducer.java
@Override protected void reduce(ImmutableBytesWritable row, Iterable<TextArrayWritable> texts, Context context) throws java.io.IOException, InterruptedException { //???//from w w w . j av a2 s . c om String columName = curTime; map.clear(); Put put = new Put(row.get()); Iterator<TextArrayWritable> iter = texts.iterator(); TextArrayWritable latterText = null; try { int i = 0; boolean isFirst = false; //? while (iter.hasNext()) { latterText = ((TextArrayWritable) iter.next()).clone(); if (i == 0) { isFirst = true; } else { isFirst = false; } String dealStr = compressor.compress(latterText, isFirst, context.getConfiguration()); if (!StringUtils.isEmpty(dealStr)) { sb.append(dealStr); } sb = sb.append(record_separator); i++; } //? sb.deleteCharAt(sb.lastIndexOf(record_separator)); put.add(family, columName.getBytes(), Bytes.toBytes(sb.toString())); sb.setLength(0); for (List<KeyValue> kvList : put.getFamilyMap().values()) { for (KeyValue kv : kvList) { map.add(kv); } } for (KeyValue kv : map) { context.write(row, kv); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.github.rvesse.airline.model.OptionMetadata.java
public OptionMetadata(Iterable<OptionMetadata> options) { if (options == null) throw new NullPointerException("options cannot be null"); if (!options.iterator().hasNext()) throw new IllegalArgumentException("options cannot be empty"); OptionMetadata option = options.iterator().next(); this.optionType = option.optionType; this.options = option.options; this.title = option.title; this.description = option.description; this.arity = option.arity; this.hidden = option.hidden; this.overrides = option.overrides; this.sealed = option.sealed; this.restrictions = option.restrictions; Set<Accessor> accessors = new LinkedHashSet<Accessor>(); for (OptionMetadata other : options) { if (!option.equals(other)) throw new IllegalArgumentException( String.format("Duplicate options definitions: %s, %s", option, other)); accessors.addAll(other.getAccessors()); }// w w w .j ava 2 s. c o m this.accessors = SetUtils.unmodifiableSet(accessors); }
From source file:com.google.gerrit.server.mail.OutgoingEmail.java
public String joinStrings(Iterable<Object> in, String joiner) { return joinStrings(in.iterator(), joiner); }
From source file:com.insightml.evaluation.simulation.CrossValidation.java
private <E, P> SimulationResults<E, P>[] runCv(final Iterable<I> instances, final SimulationSetup<I, E, P> setup) { final ILearnerPipeline<I, P>[] learner = setup.getLearner(); final IJobBatch<Predictions<E, P>[]> batch = ((SimulationSetupImpl) setup).createBatch(); final int numLabels = Check.num(instances.iterator().next().getExpected().length, 1, 10); final Integer labelIndex = ((SimulationSetupImpl) setup).getLabelIndex(); final FeaturesConfig<I, P> config = setup.getConfig(); for (int repetition = 0; repetition < repetitions; ++repetition) { // repetition == 0 ? instances : instances.randomize(random); final Iterable<I> shuffled = instances; for (int fold = 1; fold <= folds; ++fold) { final int actualFold = fold + repetition * folds; if (labelIndex == null) { for (int index = 0; index < numLabels; ++index) { batch.addJob(new Fold<I, E, P>(config, shuffled, learner, fold, actualFold, folds, index)); }/*from w w w . j a va2s . c o m*/ } else { batch.addJob(new Fold<I, E, P>(config, shuffled, learner, fold, actualFold, folds, labelIndex)); } } } final SimulationResultsBuilder<E, P>[] builders = new SimulationResultsBuilder[learner.length]; for (int i = 0; i < learner.length; ++i) { builders[i] = new SimulationResultsBuilder<>(learner[i].getName(), folds * repetitions, numLabels, setup); } for (final Predictions<E, P>[] preds : batch.run()) { for (int i = 0; i < preds.length; ++i) { builders[i].add(preds[i]); } } final SimulationResults<E, P>[] results = new SimulationResults[learner.length]; for (int i = 0; i < results.length; ++i) { results[i] = builders[i].build(); } return results; }
From source file:io.druid.query.timeboundary.TimeBoundaryQueryRunnerTest.java
@Test @SuppressWarnings("unchecked") public void testTimeBoundary() { TimeBoundaryQuery timeBoundaryQuery = Druids.newTimeBoundaryQueryBuilder().dataSource("testing").build(); Assert.assertFalse(timeBoundaryQuery.hasFilters()); HashMap<String, Object> context = new HashMap<String, Object>(); Iterable<Result<TimeBoundaryResultValue>> results = Sequences.toList(runner.run(timeBoundaryQuery, context), Lists.<Result<TimeBoundaryResultValue>>newArrayList()); TimeBoundaryResultValue val = results.iterator().next().getValue(); DateTime minTime = val.getMinTime(); DateTime maxTime = val.getMaxTime(); Assert.assertEquals(new DateTime("2011-01-12T00:00:00.000Z"), minTime); Assert.assertEquals(new DateTime("2011-04-15T00:00:00.000Z"), maxTime); }
From source file:io.druid.query.timeboundary.TimeBoundaryQueryRunnerTest.java
@Test @SuppressWarnings("unchecked") public void testTimeBoundaryMax() { TimeBoundaryQuery timeBoundaryQuery = Druids.newTimeBoundaryQueryBuilder().dataSource("testing") .bound(TimeBoundaryQuery.MAX_TIME).build(); Map<String, Object> context = new MapMaker().makeMap(); context.put(Result.MISSING_SEGMENTS_KEY, Lists.newArrayList()); Iterable<Result<TimeBoundaryResultValue>> results = Sequences.toList(runner.run(timeBoundaryQuery, context), Lists.<Result<TimeBoundaryResultValue>>newArrayList()); TimeBoundaryResultValue val = results.iterator().next().getValue(); DateTime minTime = val.getMinTime(); DateTime maxTime = val.getMaxTime(); Assert.assertNull(minTime);/*from ww w .j a v a 2s.c o m*/ Assert.assertEquals(new DateTime("2011-04-15T00:00:00.000Z"), maxTime); }
From source file:io.druid.query.timeboundary.TimeBoundaryQueryRunnerTest.java
@Test @SuppressWarnings("unchecked") public void testTimeBoundaryMin() { TimeBoundaryQuery timeBoundaryQuery = Druids.newTimeBoundaryQueryBuilder().dataSource("testing") .bound(TimeBoundaryQuery.MIN_TIME).build(); Map<String, Object> context = new MapMaker().makeMap(); context.put(Result.MISSING_SEGMENTS_KEY, Lists.newArrayList()); Iterable<Result<TimeBoundaryResultValue>> results = Sequences.toList(runner.run(timeBoundaryQuery, context), Lists.<Result<TimeBoundaryResultValue>>newArrayList()); TimeBoundaryResultValue val = results.iterator().next().getValue(); DateTime minTime = val.getMinTime(); DateTime maxTime = val.getMaxTime(); Assert.assertEquals(new DateTime("2011-01-12T00:00:00.000Z"), minTime); Assert.assertNull(maxTime);/*from w w w . j a v a 2 s . c o m*/ }
From source file:com.artistech.protobuf.TuioProtoConverter.java
@Override public GeneratedMessage.Builder convertToProtobuf(Object obj) { GeneratedMessage.Builder builder;//from ww w. j a v a 2s . c om if (obj.getClass().getName().equals(TUIO.TuioTime.class.getName())) { builder = TuioProtos.Time.newBuilder(); } else if (obj.getClass().getName().equals(TUIO.TuioCursor.class.getName())) { builder = TuioProtos.Cursor.newBuilder(); } else if (obj.getClass().getName().equals(TUIO.TuioObject.class.getName())) { builder = TuioProtos.Object.newBuilder(); } else if (obj.getClass().getName().equals(TUIO.TuioBlob.class.getName())) { builder = TuioProtos.Blob.newBuilder(); } else if (obj.getClass().getName().equals(TUIO.TuioPoint.class.getName())) { builder = TuioProtos.Point.newBuilder(); } else { return null; } try { PropertyDescriptor[] objProps = Introspector.getBeanInfo(obj.getClass()).getPropertyDescriptors(); BeanInfo beanInfo = Introspector.getBeanInfo(builder.getClass()); PropertyDescriptor[] builderProps = beanInfo.getPropertyDescriptors(); Method[] methods = builder.getClass().getMethods(); for (PropertyDescriptor prop1 : objProps) { for (PropertyDescriptor prop2 : builderProps) { if (prop1.getName().equals(prop2.getName())) { Method readMethod = prop1.getReadMethod(); ArrayList<Method> methodsToTry = new ArrayList<>(); for (Method m : methods) { if (m.getName().equals(readMethod.getName().replaceFirst("get", "set"))) { methodsToTry.add(m); } } for (Method setMethod : methodsToTry) { try { if (Iterable.class.isAssignableFrom(readMethod.getReturnType())) { if (DeepCopy) { ArrayList<Method> methodsToTry2 = new ArrayList<>(); for (Method m : methods) { if (m.getName() .equals(readMethod.getName().replaceFirst("get", "add"))) { methodsToTry2.add(m); } } boolean success = false; for (Method setMethod2 : methodsToTry2) { Iterable iter = (Iterable) readMethod.invoke(obj); Iterator it = iter.iterator(); while (it.hasNext()) { Object o = it.next(); //call set.. for (ProtoConverter converter : services) { if (converter.supportsConversion(o)) { try { GeneratedMessage.Builder convertToProtobuf = converter .convertToProtobuf(o); setMethod2.invoke(builder, convertToProtobuf); success = true; break; } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { } } } } if (success) { break; } } } } else { boolean primitiveOrWrapper = ClassUtils .isPrimitiveOrWrapper(readMethod.getReturnType()); if (primitiveOrWrapper) { setMethod.invoke(builder, readMethod.invoke(obj)); } else { Object invoke = readMethod.invoke(obj); com.google.protobuf.GeneratedMessage.Builder val = convertToProtobuf( invoke); setMethod.invoke(builder, val); break; } } } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { // Logger.getLogger(TuioProtoConverter.class.getName()).log(Level.SEVERE, null, ex); } break; } } } } } catch (IntrospectionException ex) { logger.fatal(ex); } return builder; }