List of usage examples for com.google.common.collect Iterators forArray
public static <T> UnmodifiableIterator<T> forArray(final T... array)
From source file:org.locationtech.geogig.plumbing.diff.LCSGeometryDiffImpl.java
private String geomToStringOfCoordinates(@Nullable Geometry geom) { if (null == geom) { return ""; }/*from w w w .ja v a 2s . c om*/ final Function<Coordinate, String> printCoords = (c) -> Double.toString(c.x) + "," + Double.toString(c.y); StringBuilder sb = new StringBuilder(); sb.append(geom.getGeometryType() + " "); int n = geom.getNumGeometries(); for (int i = 0; i < n; i++) { Geometry subgeom = geom.getGeometryN(i); if (subgeom instanceof Polygon) { Polygon polyg = (Polygon) subgeom; Coordinate[] coords = polyg.getExteriorRing().getCoordinates(); Iterator<String> iter = Iterators.transform(Iterators.forArray(coords), printCoords); sb.append(Joiner.on(' ').join(iter)); for (int j = 0; j < polyg.getNumInteriorRing(); j++) { coords = polyg.getInteriorRingN(j).getCoordinates(); iter = Iterators.transform(Iterators.forArray(coords), printCoords); sb.append(" " + INNER_RING_SEPARATOR + " "); sb.append(Joiner.on(' ').join(iter)); } if (i < n - 1) { sb.append(" " + SUBGEOM_SEPARATOR + " "); } } else { Coordinate[] coords = subgeom.getCoordinates(); Iterator<String> iter = Iterators.transform(Iterators.forArray(coords), printCoords); sb.append(Joiner.on(' ').join(iter)); sb.append(" " + SUBGEOM_SEPARATOR + " "); } } String s = sb.toString().trim(); return s; }
From source file:org.commoncrawl.mapred.pipelineV3.domainmeta.DomainMetadataTask.java
@Override protected void parseArgs() throws IOException { CommandLineParser parser = new GnuParser(); try {//from www . j av a 2s . c o m // parse the command line arguments CommandLine line = parser.parse(options, _args); // default to single partition - partition zero ImmutableList<Integer> partitions = ImmutableList.of(0); if (line.hasOption("partitions")) { partitions = ImmutableList.copyOf( Iterators.transform(Iterators.forArray(line.getOptionValue("partitions").split(",")), new Function<String, Integer>() { @Override public Integer apply(String arg0) { return Integer.parseInt(arg0); } })); } if (partitions.size() == 0) { throw new IOException("One Parition Required At a Minimum!"); } _partitionList = partitions; if (line.hasOption("rebuild")) { LOG.info("Rebuild Option Specified. Deleting Outputs"); for (CrawlPipelineStep step : getSteps()) { LOG.info("Deleting Output Dir:" + step.getOutputDir() + " for Step:" + step.getName()); getFileSystem().delete(step.getOutputDir(), true); } } } catch (Exception e) { LOG.error(StringUtils.stringifyException(e)); throw new IOException(e); } }
From source file:net.tridentsdk.reflect.Injector.java
private static boolean checkArray(Object[] args, Class<?>[] params) { Iterator<Class<?>> iterator = Iterators.forArray(params); for (Object o : args) { if (!Iterators.contains(iterator, o.getClass())) return false; }/* w ww.j a v a2s. c om*/ return true; }
From source file:de.unijena.bioinf.ChemistryBase.chem.ChemicalAlphabet.java
@Override public Iterator<Element> iterator() { return Iterators.forArray(allowedElements); }
From source file:org.pshdl.model.impl.AbstractHDLDeclaration.java
@Override public Iterator<IHDLObject> deepIterator() { return new Iterator<IHDLObject>() { private int pos = 0; private Iterator<? extends IHDLObject> current; @Override/*w w w . j a v a 2s.c om*/ public boolean hasNext() { if ((current != null) && !current.hasNext()) { current = null; } while (current == null) { switch (pos++) { case 0: if ((annotations != null) && (annotations.size() != 0)) { final List<Iterator<? extends IHDLObject>> iters = Lists .newArrayListWithCapacity(annotations.size()); for (final HDLAnnotation o : annotations) { iters.add(Iterators.forArray(o)); iters.add(o.deepIterator()); } current = Iterators.concat(iters.iterator()); } break; default: return false; } } return (current != null) && current.hasNext(); } @Override public IHDLObject next() { return current.next(); } @Override public void remove() { throw new IllegalArgumentException("Not supported"); } }; }
From source file:org.jeo.nano.MockServer.java
MockServer withMoreDetails() throws Exception { Dataset active = vectorLayer == null ? tileLayer : vectorLayer; assert active != null : "expected a tile or vector layer"; expect(active.getName()).andReturn("emptylayer").anyTimes(); expect(active.bounds()).andReturn(new Envelope(-180, 180, -90, 90)).anyTimes(); expect(active.crs()).andReturn(Proj.EPSG_4326).anyTimes(); Driver driver = createMock(Driver.class); expect(driver.getName()).andReturn("mockDriver").anyTimes(); expect(active.getDriver()).andReturn(driver).anyTimes(); if (vectorLayer != null) { expect(vectorLayer.count((Query) anyObject())).andReturn(42L).anyTimes(); Schema schema = createMock(Schema.class); Iterator<Field> fields = Iterators.forArray(new Field("name", String.class)); expect(schema.iterator()).andReturn(fields).anyTimes(); expect(vectorLayer.schema()).andReturn(schema).anyTimes(); }/*from ww w .ja v a 2 s . co m*/ return this; }
From source file:org.pshdl.model.impl.AbstractHDLOpExpression.java
@Override public Iterator<IHDLObject> deepIterator() { return new Iterator<IHDLObject>() { private int pos = 0; private Iterator<? extends IHDLObject> current; @Override//w w w. j av a 2 s .c o m public boolean hasNext() { if ((current != null) && !current.hasNext()) { current = null; } while (current == null) { switch (pos++) { case 0: if (left != null) { current = Iterators.concat(Iterators.forArray(left), left.deepIterator()); } break; case 1: if (right != null) { current = Iterators.concat(Iterators.forArray(right), right.deepIterator()); } break; default: return false; } } return (current != null) && current.hasNext(); } @Override public IHDLObject next() { return current.next(); } @Override public void remove() { throw new IllegalArgumentException("Not supported"); } }; }
From source file:org.pshdl.model.impl.AbstractHDLExport.java
@Override public Iterator<IHDLObject> deepIterator() { return new Iterator<IHDLObject>() { private int pos = 0; private Iterator<? extends IHDLObject> current; @Override/*from w w w. j a v a 2s . c o m*/ public boolean hasNext() { if ((current != null) && !current.hasNext()) { current = null; } while (current == null) { switch (pos++) { case 0: if (exportRef != null) { current = Iterators.concat(Iterators.forArray(exportRef), exportRef.deepIterator()); } break; default: return false; } } return (current != null) && current.hasNext(); } @Override public IHDLObject next() { return current.next(); } @Override public void remove() { throw new IllegalArgumentException("Not supported"); } }; }
From source file:org.pshdl.model.impl.AbstractHDLType.java
@Override public Iterator<IHDLObject> deepIterator() { return new Iterator<IHDLObject>() { private int pos = 0; private Iterator<? extends IHDLObject> current; @Override//ww w. ja v a 2 s . c o m public boolean hasNext() { if ((current != null) && !current.hasNext()) { current = null; } while (current == null) { switch (pos++) { case 0: if ((dim != null) && (dim.size() != 0)) { final List<Iterator<? extends IHDLObject>> iters = Lists .newArrayListWithCapacity(dim.size()); for (final HDLExpression o : dim) { iters.add(Iterators.forArray(o)); iters.add(o.deepIterator()); } current = Iterators.concat(iters.iterator()); } break; default: return false; } } return (current != null) && current.hasNext(); } @Override public IHDLObject next() { return current.next(); } @Override public void remove() { throw new IllegalArgumentException("Not supported"); } }; }
From source file:org.protelis.lang.datatype.impl.ArrayTupleImpl.java
@Override public Iterator<Object> iterator() { return Iterators.forArray(arrayContents); }