List of usage examples for java.util SortedSet last
E last();
From source file:Main.java
public static void main(String[] argv) throws Exception { SortedSet<String> set = new TreeSet<String>(); set.add("b"); set.add("c"); set.add("a"); System.out.println(set.last()); }
From source file:Main.java
public static void main(String args[]) { Employee emps[] = { new Employee("Finance", "Degree, Debbie"), new Employee("Finance", "Grade, Geri"), new Employee("Finance", "Extent, Ester"), new Employee("Engineering", "Measure, Mary"), new Employee("Engineering", "Amount, Anastasia"), new Employee("Engineering", "Ratio, Ringo"), new Employee("Sales", "Stint, Sarah"), new Employee("Sales", "Pitch, Paula"), new Employee("Support", "Rate, Rhoda"), }; SortedSet set = new TreeSet(Arrays.asList(emps)); System.out.println(set);//from w w w . j av a 2 s . c om try { Object last = set.last(); boolean first = true; while (true) { if (!first) { System.out.print(", "); } System.out.println(last); last = set.headSet(last).last(); } } catch (NoSuchElementException e) { System.out.println(); } Set subset = set.headSet(emps[4]); subset.add(emps[5]); }
From source file:SortedSetDemo.java
public static void main(String[] args) { SortedSet sortedSet = new TreeSet(Arrays.asList("one two three four five six seven eight".split(" "))); System.out.println(sortedSet); Object low = sortedSet.first(), high = sortedSet.last(); System.out.println(low);//from www . j a va2 s . c o m System.out.println(high); Iterator it = sortedSet.iterator(); for (int i = 0; i <= 6; i++) { if (i == 3) low = it.next(); if (i == 6) high = it.next(); else it.next(); } System.out.println(low); System.out.println(high); System.out.println(sortedSet.subSet(low, high)); System.out.println(sortedSet.headSet(high)); System.out.println(sortedSet.tailSet(low)); }
From source file:Main.java
public static void main(String[] args) { SortedSet<String> names = new TreeSet<>(); names.add("HTML"); names.add("Java"); names.add("SQL"); names.add("CSS"); System.out.println("Sorted Set: " + names); System.out.println("First: " + names.first()); System.out.println("Last: " + names.last()); SortedSet<String> ssBeforeCSS = names.headSet("CSS"); System.out.println(ssBeforeCSS); SortedSet<String> ssBetwenCSSAndHTML = names.subSet("CSS", "HTML"); System.out.println(ssBetwenCSSAndHTML); SortedSet<String> ssBetwenCSSAndHTML2 = names.subSet("CSS", "HTML"); System.out.println(ssBetwenCSSAndHTML2); SortedSet<String> ssCSSAndAfter = names.tailSet("CSS"); System.out.println(ssCSSAndAfter); }
From source file:org.archive.util.PrefixFinder.java
private static String last(SortedSet<String> set) { return set.isEmpty() ? null : set.last(); }
From source file:com.rapleaf.hank.coordinator.Domains.java
public static DomainVersion getLatestVersion(Domain domain) throws IOException { SortedSet<DomainVersion> versions = domain.getVersions(); if (versions == null || versions.size() == 0) { return null; } else {//w w w .ja va 2s . c o m return versions.last(); } }
From source file:com.yahoo.pulsar.common.naming.NamespaceBundleFactory.java
public static void validateFullRange(SortedSet<String> partitions) { checkArgument(partitions.first().equals(FIRST_BOUNDARY) && partitions.last().equals(LAST_BOUNDARY)); }
From source file:com.github.sevntu.checkstyle.ordering.MethodOrder.java
private static <T> MinMax<T> minMax(Collection<T> elements) { final SortedSet<T> sortedSet = new TreeSet<>(elements); return new MinMax<>(sortedSet.first(), sortedSet.last()); }
From source file:com.rapleaf.hank.storage.curly.CurlyReader.java
public static CurlyFilePath getLatestBase(String partitionRoot) throws IOException { SortedSet<CurlyFilePath> bases = Curly.getBases(partitionRoot); if (bases == null || bases.size() == 0) { throw new IOException("Could not detect any Curly base in " + partitionRoot); }/*from w w w . ja v a 2 s . c om*/ return bases.last(); }
From source file:at.ac.ait.ubicity.fileloader.FileLoader.java
/** * /* ww w . jav a2s . c om*/ * @param _fileInfo A FileInformation object representing usage information on the file we are supposed to load: line count already ingested, last usage time... * @param _keySpace Cassandra key space into which to ingest * @param _host Cassandra host / server * @param _batchSize MutationBatch size * @throws Exception Shouldn't happen, although the Disruptor may throw an Exception under duress */ @SuppressWarnings("unchecked") public final static void load(final FileInformation _fileInfo, final String _keySpace, final String _host, final int _batchSize) throws Exception { if (!cassandraInitialized) { keySpace = AstyanaxInitializer.doInit("Test Cluster", _host, _keySpace); cassandraInitialized = true; } LongTimeStampSorter tsSorter = new LongTimeStampSorter(); Thread tTSSorter = new Thread(tsSorter); tTSSorter.setPriority(Thread.MAX_PRIORITY - 1); tTSSorter.setName("long timestamp sorter "); tTSSorter.start(); //get the log id from the file's URI final String log_id = _fileInfo.getURI().toString(); final MutationBatch batch = keySpace.prepareMutationBatch(); logger.info("got keyspace " + keySpace.getKeyspaceName() + " from Astyanax initializer"); final LineIterator onLines = FileUtils.lineIterator(new File(_fileInfo.getURI())); final ExecutorService exec = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2); ColumnFamily crawl_stats = null; AggregationJob aggregationJob = new AggregationJob(keySpace, crawl_stats); Thread tAggJob = new Thread(aggregationJob); tAggJob.setName("Monitrix loader / aggregation job "); tAggJob.setPriority(Thread.MIN_PRIORITY + 1); tAggJob.start(); logger.info("[FILELOADER] started aggregation job, ring buffer running"); final Disruptor<SingleLogLineAsString> disruptor = new Disruptor(SingleLogLineAsString.EVENT_FACTORY, (int) Math.pow(TWO, 17), exec); SingleLogLineAsStringEventHandler.batch = batch; SingleLogLineAsStringEventHandler.keySpace = keySpace; SingleLogLineAsStringEventHandler.batchSize = _batchSize; SingleLogLineAsStringEventHandler.LOG_ID = log_id; SingleLogLineAsStringEventHandler.tsSorter = tsSorter; SingleLogLineAsStringEventHandler.aggregationJob = aggregationJob; //The EventHandler contains the actual logic for ingesting final EventHandler<SingleLogLineAsString> handler = new SingleLogLineAsStringEventHandler(); disruptor.handleEventsWith(handler); //get our Aggregate job in place //we are almost ready to start final RingBuffer<SingleLogLineAsString> rb = disruptor.start(); int _lineCount = 0; long _start, _lapse; _start = System.nanoTime(); int _linesAlreadyProcessed = _fileInfo.getLineCount(); //cycle through the lines already processed while (_lineCount < _linesAlreadyProcessed) { onLines.nextLine(); _lineCount++; } //now get down to the work we actually must do, and fill the ring buffer logger.info("begin proccessing of file " + _fileInfo.getURI() + " @line #" + _lineCount); while (onLines.hasNext()) { final long _seq = rb.next(); final SingleLogLineAsString event = rb.get(_seq); event.setValue(onLines.nextLine()); rb.publish(_seq); _lineCount++; } _lapse = System.nanoTime() - _start; logger.info("ended proccessing of file " + _fileInfo.getURI() + " @line #" + _lineCount); //stop, waiting for last threads still busy to finish their work disruptor.shutdown(); //update the file info, this will land in the cache _fileInfo.setLineCount(_lineCount); _fileInfo.setLastAccess(System.currentTimeMillis()); int _usageCount = _fileInfo.getUsageCount(); _fileInfo.setUsageCount(_usageCount++); //make sure we release resources onLines.close(); logger.info( "handled " + (_lineCount - _linesAlreadyProcessed) + " log lines in " + _lapse + " nanoseconds"); //now go to aggregation step SortedSet<Long> timeStamps = new TreeSet(tsSorter.timeStamps); long _minTs = timeStamps.first(); long _maxTs = timeStamps.last(); logger.info("**** min TimeStamp = " + _minTs); logger.info("**** max TimeStamp = " + _maxTs); StatsTableActualizer.update(_fileInfo.getURI().toString(), _minTs, _maxTs, _lineCount); // AggregationJob aggJob = new AggregationJob( keySpace, _host, _batchSize ); // Thread tAgg = new Thread( aggJob ); // tAgg.setName( "aggregation job " ); // tAgg.setPriority( Thread.MAX_PRIORITY - 1 ); // tAgg.start(); }