List of usage examples for com.google.common.collect ImmutableList iterator
@Override
public UnmodifiableIterator<E> iterator()
From source file:org.joda.railmodel.Crossrail2BalhamSWLondonModel.java
public static void main(String[] args) throws Exception { Crossrail2BalhamSWLondonModel model = new Crossrail2BalhamSWLondonModel(); ImmutableList<Station> starts = ImmutableList.of(CSS, LHD, EPS, SNL, WCP, MOT, SHP, FLW, KNG, HMC, SUR, NEM, RAY, WIM, EAD, UMD, USW, UTB, BAL, SRH, STE); ImmutableList<Station> ends = ImmutableList.of(VIC, TCR, EUS, AGL, WAT, UGP, UOX, BDS, CHX, ULS, UGS, UWS, UBS, UWM, UTM, ZFD, UBH, LBG, UBK, MOG, UOS, UHL, UCL, USP, CWF); List<String> output = new ArrayList<>(); output.add("Modelling for SW London with Crossrail 2 via Balham" + NEWLINE); output.add("===================================================" + NEWLINE); output.add("This uses CR2 via Balham, with best efforts guesses of interchange times." + NEWLINE); output.add(NEWLINE);/*from w w w . j ava2s .c o m*/ appendDocs(output); appendTotals(output, starts, ends, model); appendSeparator(output); for (Iterator<Station> it = starts.iterator(); it.hasNext();) { Station start = it.next(); for (Station end : ends) { String explain = model.explain(start, end); output.add(explain); output.add(NEWLINE); } if (it.hasNext()) { appendSeparator(output); } } appendStations(output); output.add(NEWLINE); output.add("Feel free to send a pull request for errors and enhancments!" + NEWLINE); File file = new File("CR2-SWLondon.md"); String result = Joiner.on("").join(output); Files.write(result, file, StandardCharsets.UTF_8); System.out.println(result); }
From source file:org.joda.railmodel.Crossrail2TootingSWLondonModel.java
public static void main(String[] args) throws Exception { Crossrail2TootingSWLondonModel model = new Crossrail2TootingSWLondonModel(); ImmutableList<Station> starts = ImmutableList.of(CSS, LHD, EPS, SNL, WCP, MOT, SHP, FLW, KNG, HMC, SUR, NEM, RAY, WIM, EAD, UMD, USW, UTB, BAL, SRH, STE); ImmutableList<Station> ends = ImmutableList.of(VIC, TCR, EUS, AGL, WAT, UGP, UOX, BDS, CHX, ULS, UGS, UWS, UBS, UWM, UTM, ZFD, UBH, LBG, UBK, MOG, UOS, UHL, UCL, USP, CWF); List<String> output = new ArrayList<>(); output.add("Modelling for SW London with Crossrail 2 via Tooting Broadway" + NEWLINE); output.add("=============================================================" + NEWLINE); output.add("This uses CR2 via Tooting Broadway, with best efforts guesses of interchange times." + NEWLINE); output.add(NEWLINE);/* www . ja v a 2s.c o m*/ appendDocs(output); appendTotals(output, starts, ends, model); appendSeparator(output); for (Iterator<Station> it = starts.iterator(); it.hasNext();) { Station start = it.next(); for (Station end : ends) { String explain = model.explain(start, end); output.add(explain); output.add(NEWLINE); } if (it.hasNext()) { appendSeparator(output); } } appendStations(output); output.add(NEWLINE); output.add("Feel free to send a pull request for errors and enhancments!" + NEWLINE); File file = new File("CR2-Tooting-SWLondon.md"); String result = Joiner.on("").join(output); Files.write(result, file, StandardCharsets.UTF_8); System.out.println(result); }
From source file:org.joda.railmodel.Crossrail2EarlsfieldSWLondonModel.java
public static void main(String[] args) throws Exception { Crossrail2EarlsfieldSWLondonModel model = new Crossrail2EarlsfieldSWLondonModel(); ImmutableList<Station> starts = ImmutableList.of(CSS, LHD, EPS, SNL, WCP, MOT, SHP, FLW, KNG, HMC, SUR, NEM, RAY, WIM, EAD, UMD, USW, UTB, BAL, SRH, STE); ImmutableList<Station> ends = ImmutableList.of(VIC, TCR, EUS, AGL, WAT, UGP, UOX, BDS, CHX, ULS, UGS, UWS, UBS, UWM, UTM, ZFD, UBH, LBG, UBK, MOG, UOS, UHL, UCL, USP, CWF); List<String> output = new ArrayList<>(); output.add("Modelling for SW London with Crossrail 2 Swirl" + NEWLINE); output.add("==============================================" + NEWLINE); output.add(//w ww . j a v a 2 s .co m "This uses CR2 via Earlsfield based on the [Swirl plan](http://ukrail.blogspot.co.uk/2015/11/crossrail-2-swirl.html)," + " with best efforts guesses of interchange times." + NEWLINE); output.add(NEWLINE); appendDocs(output); appendTotals(output, starts, ends, model); appendSeparator(output); for (Iterator<Station> it = starts.iterator(); it.hasNext();) { Station start = it.next(); for (Station end : ends) { String explain = model.explain(start, end); output.add(explain); output.add(NEWLINE); } if (it.hasNext()) { appendSeparator(output); } } appendStations(output); output.add(NEWLINE); output.add("Feel free to send a pull request for errors and enhancments!" + NEWLINE); File file = new File("CR2-Swirl-SWLondon.md"); String result = Joiner.on("").join(output); Files.write(result, file, StandardCharsets.UTF_8); System.out.println(result); }
From source file:org.joda.railmodel.Crossrail2SwirlMaxSWLondonModel.java
public static void main(String[] args) throws Exception { Crossrail2SwirlMaxSWLondonModel model = new Crossrail2SwirlMaxSWLondonModel(); ImmutableList<Station> starts = ImmutableList.of(CSS, LHD, EPS, SNL, WCP, MOT, SHP, FLW, KNG, HMC, SUR, NEM, RAY, WIM, EAD, UMD, USW, UTB, BAL, SRH, STE); ImmutableList<Station> ends = ImmutableList.of(VIC, TCR, EUS, AGL, WAT, UGP, UOX, BDS, CHX, ULS, UGS, UWS, UBS, UWM, UTM, ZFD, UBH, LBG, UBK, MOG, UOS, UHL, UCL, USP, CWF); List<String> output = new ArrayList<>(); output.add("Modelling for SW London with Crossrail 2 Swirl-Max" + NEWLINE); output.add("==================================================" + NEWLINE); output.add(// w w w .j ava 2 s . c o m "This uses CR2 via Earlsfield based on the [Swirl plan](http://ukrail.blogspot.co.uk/2015/11/crossrail-2-swirl.html), " + NEWLINE); output.add("with a separate branch to Balham, Streatham and on to Wimbledon via Haydons Road." + NEWLINE); output.add("It uses best efforts guesses for interchange times." + NEWLINE); output.add(NEWLINE); appendDocs(output); appendTotals(output, starts, ends, model); appendSeparator(output); for (Iterator<Station> it = starts.iterator(); it.hasNext();) { Station start = it.next(); for (Station end : ends) { String explain = model.explain(start, end); output.add(explain); output.add(NEWLINE); } if (it.hasNext()) { appendSeparator(output); } } appendStations(output); output.add(NEWLINE); output.add("Feel free to send a pull request for errors and enhancments!" + NEWLINE); File file = new File("CR2-SwirlMax-SWLondon.md"); String result = Joiner.on("").join(output); Files.write(result, file, StandardCharsets.UTF_8); System.out.println(result); }
From source file:org.joda.railmodel.Crossrail2StreathamSWLondonModel.java
public static void main(String[] args) throws Exception { Crossrail2StreathamSWLondonModel model = new Crossrail2StreathamSWLondonModel(); ImmutableList<Station> starts = ImmutableList.of(CSS, LHD, EPS, SNL, WCP, MOT, SHP, FLW, KNG, HMC, SUR, NEM, RAY, WIM, EAD, UMD, USW, UTB, BAL, SRH, STE); ImmutableList<Station> ends = ImmutableList.of(VIC, TCR, EUS, AGL, WAT, UGP, UOX, BDS, CHX, ULS, UGS, UWS, UBS, UWM, UTM, ZFD, UBH, LBG, UBK, MOG, UOS, UHL, UCL, USP, CWF); List<String> output = new ArrayList<>(); output.add("Modelling for SW London with Crossrail 2 via Streatham" + NEWLINE); output.add("======================================================" + NEWLINE); output.add(//from www . j a va2 s . co m "This uses CR2 via Tooting (mainline) and Streatham, with best efforts guesses of interchange times." + NEWLINE); output.add("This route is promoted by various groups in Streatham." + NEWLINE); output.add( "It adds at least 6 minutes to all journeys on Crossrail 2 between Wimbledon and Clapham Junction." + NEWLINE); output.add("As such, no matter what benefits it gives Streatham, it simply will not happen." + NEWLINE); output.add(NEWLINE); appendDocs(output); appendTotals(output, starts, ends, model); appendSeparator(output); for (Iterator<Station> it = starts.iterator(); it.hasNext();) { Station start = it.next(); for (Station end : ends) { String explain = model.explain(start, end); output.add(explain); output.add(NEWLINE); } if (it.hasNext()) { appendSeparator(output); } } appendStations(output); output.add(NEWLINE); output.add("Feel free to send a pull request for errors and enhancments!" + NEWLINE); File file = new File("CR2-Streatham-SWLondon.md"); String result = Joiner.on("").join(output); Files.write(result, file, StandardCharsets.UTF_8); System.out.println(result); }
From source file:org.joda.railmodel.Crossrail2SwirlNorthernSWLondonModel.java
public static void main(String[] args) throws Exception { Crossrail2SwirlNorthernSWLondonModel model = new Crossrail2SwirlNorthernSWLondonModel(); ImmutableList<Station> starts = ImmutableList.of(CSS, LHD, EPS, SNL, WCP, MOT, SHP, FLW, KNG, HMC, SUR, NEM, RAY, WIM, EAD, UMD, USW, UTB, BAL, SRH, STE); ImmutableList<Station> ends = ImmutableList.of(VIC, TCR, EUS, AGL, WAT, UGP, UOX, BDS, CHX, ULS, UGS, UWS, UBS, UWM, UTM, ZFD, UBH, LBG, UBK, MOG, UOS, UHL, UCL, USP, CWF); List<String> output = new ArrayList<>(); output.add("Modelling for SW London with Crossrail 2 Swirl plus Northern Line extension" + NEWLINE); output.add("===========================================================================" + NEWLINE); output.add(//from w w w. j a va2 s . com "This uses CR2 via Earlsfield based on the [Swirl plan](http://ukrail.blogspot.co.uk/2015/11/crossrail-2-swirl.html)," + " with best efforts guesses of interchange times." + NEWLINE); output.add("It then changes Chelsea to Battersea Power, and adds a Northern Line extension from " + "Battersea Power to Balham with one intermediate stop." + NEWLINE); output.add("Trains from Morden run via Battersea Power to the West End." + NEWLINE); output.add("Trains from Balham run via Stockwell to the City." + NEWLINE); output.add(NEWLINE); appendDocs(output); appendTotals(output, starts, ends, model); appendSeparator(output); for (Iterator<Station> it = starts.iterator(); it.hasNext();) { Station start = it.next(); for (Station end : ends) { String explain = model.explain(start, end); output.add(explain); output.add(NEWLINE); } if (it.hasNext()) { appendSeparator(output); } } appendStations(output); output.add(NEWLINE); output.add("Feel free to send a pull request for errors and enhancments!" + NEWLINE); File file = new File("CR2-SwirlNorthern-SWLondon.md"); String result = Joiner.on("").join(output); Files.write(result, file, StandardCharsets.UTF_8); System.out.println(result); }
From source file:org.commoncrawl.mapred.ec2.postprocess.deduper.DeduperUtils.java
/** * //from w w w . ja v a2 s .c o m * @param args */ public static void main(String[] args) throws IOException { URLFPBloomFilter filter = new URLFPBloomFilter(JSONSetBuilder.NUM_ELEMENTS, JSONSetBuilder.NUM_HASH_FUNCTIONS, JSONSetBuilder.NUM_BITS); DescriptiveStatistics filterClearStats = new DescriptiveStatistics(); for (int i = 0; i < 1000; ++i) { long timeStart = System.nanoTime(); filter.clear(); long timeEnd = System.nanoTime(); filterClearStats.addValue(timeEnd - timeStart); } System.out.println("Mean Clear Time:" + filterClearStats.getMean()); System.out.println("size:" + BINOMIAL_COFF); for (int j = 0; j < BINOMIAL_COFF; ++j) { int value = patternArray[j]; System.out.print("value:" + value + " "); for (int i = 5; i >= 0; --i) { System.out.print(((value & (1 << i)) != 0) ? '1' : '0'); } System.out.print(" Key MSBLen:" + Integer.toString(patternKeyMSBits[j]) + "\n"); } validateGenerator(); long key1 = new BitBuilder().on(10).off(1).on(53).bits(); long key2 = new BitBuilder().on(10).off(4).on(50).bits(); long key3 = new BitBuilder().on(10).off(4).on(47).off(3).bits(); long key4 = new BitBuilder().off(10).on(4).off(47).on(3).bits(); long key5 = new BitBuilder().off(10).on(4).off(47).on(1).off(2).bits(); Assert.assertTrue(SimHash.hammingDistance(key1, key2) == 3); Assert.assertTrue(SimHash.hammingDistance(key1, key3) != 3); Assert.assertTrue(SimHash.hammingDistance(key2, key3) == 3); Assert.assertTrue(SimHash.hammingDistance(key1, key4) > 3); Assert.assertTrue(SimHash.hammingDistance(key2, key4) > 3); Assert.assertTrue(SimHash.hammingDistance(key3, key4) > 3); Assert.assertTrue(SimHash.hammingDistance(key4, key5) <= 3); ImmutableList<DeduperValue> values = new ImmutableList.Builder<DeduperValue>() .add(new DeduperValue(key1, 1000, 2000, IPAddressUtils.IPV4AddressStrToInteger("10.0.0.1"), 1000, new TextBytes("http://adomain.com/"))) .add(new DeduperValue(key2, 1001, 2001, IPAddressUtils.IPV4AddressStrToInteger("10.0.0.2"), 1000, new TextBytes("http://bdomain.com/"))) .add(new DeduperValue(key3, 1002, 2002, IPAddressUtils.IPV4AddressStrToInteger("10.0.0.3"), 1000, new TextBytes("http://cdomain.com/"))) .add(new DeduperValue(key4, 1003, 2003, IPAddressUtils.IPV4AddressStrToInteger("10.0.0.4"), 1000, new TextBytes("http://ddomain.com/"))) .add(new DeduperValue(key5, 1004, 2004, IPAddressUtils.IPV4AddressStrToInteger("10.0.0.5"), 1000, new TextBytes("http://edomain.com/"))) .build(); SimhashMatcher unionFinder = new SimhashMatcher(); final Multimap<String, Long> rootDomainToDupes = TreeMultimap.create(); // collect all json set representations ... final ArrayList<TextBytes> jsonSets = new ArrayList<TextBytes>(); unionFinder.emitMatches(3, values.iterator(), new OutputCollector<TextBytes, TextBytes>() { @Override public void collect(TextBytes key, TextBytes value) throws IOException { System.out.println("Root:" + key + " JSON: " + value.toString()); populateTestJSONSetData(rootDomainToDupes, key, value); // collect all json sets for later disjoint-set join jsonSets.add(value); } }, null); ImmutableList<Long> hashSuperSet1 = ImmutableList.of(2000L, 2001L, 2002L); ImmutableList<Long> hashSuperSet2 = ImmutableList.of(2003L, 2004L); Assert.assertTrue(rootDomainToDupes.get("adomain.com").containsAll(hashSuperSet1)); Assert.assertTrue(rootDomainToDupes.get("bdomain.com").containsAll(hashSuperSet1)); Assert.assertTrue(rootDomainToDupes.get("cdomain.com").containsAll(hashSuperSet1)); Assert.assertTrue(rootDomainToDupes.get("ddomain.com").containsAll(hashSuperSet2)); Assert.assertTrue(rootDomainToDupes.get("edomain.com").containsAll(hashSuperSet2)); ImmutableList<DeduperValue> secondSetValues = new ImmutableList.Builder<DeduperValue>() .add(new DeduperValue(key1, 1000, 2000, IPAddressUtils.IPV4AddressStrToInteger("10.0.0.2"), 1000, new TextBytes("http://adomain.com/"))) .add(new DeduperValue(key1, 1007, 2007, IPAddressUtils.IPV4AddressStrToInteger("10.0.0.2"), 1000, new TextBytes("http://z1domain.com/"))) .add(new DeduperValue(key2, 1008, 2008, IPAddressUtils.IPV4AddressStrToInteger("10.0.0.2"), 1000, new TextBytes("http://z2domain.com/"))) .add(new DeduperValue(key3, 1009, 2009, IPAddressUtils.IPV4AddressStrToInteger("10.0.0.2"), 1000, new TextBytes("http://z3domain.com/"))) .build(); unionFinder.emitMatches(3, secondSetValues.iterator(), new OutputCollector<TextBytes, TextBytes>() { @Override public void collect(TextBytes key, TextBytes value) throws IOException { System.out.println("Root:" + key + " JSON: " + value.toString()); // collect all json sets for later disjoint-set join jsonSets.add(value); } }, null); SetUnionFinder unionFinder2 = new SetUnionFinder(); // union all json sets ... unionFinder2.union(jsonSets.iterator()); // ok emit union of sets ... unionFinder2.emit(new TextBytes("test"), new OutputCollector<TextBytes, TextBytes>() { @Override public void collect(TextBytes key, TextBytes value) throws IOException { System.out.println("Root:" + key + " JSON: " + value.toString()); } }, null); }
From source file:org.joda.railmodel.CurrentSWLondonModel.java
public static void main(String[] args) throws Exception { CurrentSWLondonModel model = MODEL;// w w w . j a v a 2 s. co m ImmutableList<Station> starts = ImmutableList.of(CSS, LHD, EPS, SNL, WCP, MOT, SHP, FLW, KNG, HMC, SUR, NEM, RAY, WIM, EAD, UMD, USW, UTB, BAL, SRH, STE); ImmutableList<Station> ends = ImmutableList.of(VIC, TCR, EUS, AGL, WAT, UGP, UOX, BDS, CHX, ULS, UGS, UWS, UBS, UWM, UTM, ZFD, UBH, LBG, UBK, MOG, UOS, UHL, UCL, USP, CWF); List<String> output = new ArrayList<>(); output.add("Modelling for SW London without Crossrail 2" + NEWLINE); output.add("===========================================" + NEWLINE); output.add("This uses best efforts guesses of interchange times." + NEWLINE); output.add(NEWLINE); output.add( "A selection of interesting journeys is listed, together with calculated route options." + NEWLINE); output.add("A key for station codes is at the end." + NEWLINE); output.add("The route options are sorted, with the fastest first." + NEWLINE); output.add("The excess over the fastest route option is listed in brackets." + NEWLINE); output.add("If the fastest route is direct, then only limited alternatives are shown." + NEWLINE); output.add("No alternative that takes over 15 minutes longer is shown." + NEWLINE); output.add("The number of trains per hour (tph) is also shown." + NEWLINE); output.add(NEWLINE); output.add("Station entry/exit times, buses and walking times are not included." + NEWLINE); output.add("Walking may affect the faster route on occasion." + NEWLINE); output.add(NEWLINE); output.add("The 'effective time' adds some fudge factors to take into account low frequency " + "start service and an additional penalty per interchange. It is intended to be used as a rough metric " + "of what a more typical journey would be like (ie. a non-perfect one)." + NEWLINE); output.add("The 'total effective time' is the sum of all effective times modelled." + NEWLINE); output.add("It is a reasonable proxy for the total enhancement provided by the scheme." + NEWLINE); output.add(NEWLINE); output.add("Total effective times" + NEWLINE); output.add("---------------------" + NEWLINE); int totalTotal = 0; for (Iterator<Station> it = starts.iterator(); it.hasNext();) { Station start = it.next(); int totalPoints = 0; for (Station end : ends) { totalPoints += model.solve(start, end).points(); } totalTotal += totalPoints; output.add("From " + start.description() + ": " + totalPoints + NEWLINE); } output.add("TOTAL: " + totalTotal + NEWLINE); appendSeparator(output); for (Iterator<Station> it = starts.iterator(); it.hasNext();) { Station start = it.next(); for (Station end : ends) { String explain = model.explain(start, end); output.add(explain); output.add(NEWLINE); } if (it.hasNext()) { appendSeparator(output); } } appendSeparator(output); appendStations(output); output.add(NEWLINE); output.add("Feel free to send a pull request for errors and enhancments!" + NEWLINE); File file = new File("SWLondon.md"); String result = Joiner.on("").join(output); Files.write(result, file, StandardCharsets.UTF_8); System.out.println(result); }
From source file:org.locationtech.geogig.model.RevObjects.java
/** * Creates and returns an iterator of the joint lists of {@link RevTree#trees() trees} and * {@link RevTree#features() features} of the given {@code RevTree} whose iteration order is * given by the provided {@code comparator}. * // w ww. j av a 2 s.co m * @return an iterator over the <b>direct</b> {@link RevTree#trees() trees} and * {@link RevTree#features() feature} children collections, in the order mandated by the * provided {@code comparator} */ public static Iterator<Node> children(RevTree tree, Comparator<Node> comparator) { checkNotNull(comparator); ImmutableList<Node> trees = tree.trees(); ImmutableList<Node> features = tree.features(); if (trees.isEmpty()) { return features.iterator(); } if (features.isEmpty()) { return trees.iterator(); } return Iterators.mergeSorted(ImmutableList.of(trees.iterator(), features.iterator()), comparator); }
From source file:ru.rulex.conclusion.IteratorsFacade.java
/** * @param immutableAssertionUnit//from w ww.ja v a 2s . c o m * @param source * @param excepts * @param <T> * @return Iterator<T> */ public static <T> Iterator<T> whereIterator(final ImmutableAssertionUnit<T> immutableAssertionUnit, final ImmutableList<T> source, final ImmutableSet<T> excepts) { return new AbstractIterator<T>() { private final UnmodifiableIterator<T> iterator = source.iterator(); private final ConclusionStatePathTrace pathTrace = ConclusionStatePathTrace.defaultInstance(); private IterationState state = IterationState.Regular; @Override public boolean hasNext() { switch (state) { case Regular: while (iterator.hasNext()) { T event = iterator.next(); if (!excepts.contains(event) && immutableAssertionUnit.isSatisfies(pathTrace, event)) { state = IterationState.Exit; return computeNext(event); } } case Exit: { return interrupt; } } return interrupt; } }; }