List of usage examples for java.util SortedSet first
E first();
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.first()); }
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 w w w . j a v a 2 s . c om 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: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.cyberway.issue.net.PublicSuffixes.java
protected static void buildRegex(String stem, StringBuilder regex, SortedSet<String> prefixes) { if (prefixes.isEmpty()) { return;//from ww w . j a v a 2s. c o m } if (prefixes.size() == 1 && prefixes.first().equals(stem)) { // avoid unnecessary "(?:)" return; } regex.append("(?:"); if (stem.length() == 0) { regex.append("\n "); // linebreak-space before first character } Iterator<String> iter = prefixes.iterator(); char c = 0; while (iter.hasNext()) { String s = iter.next(); if (s.length() > stem.length()) { char d = s.charAt(stem.length()); if (d == '+') { // convert exception to zero-width-positive-lookahead regex.append("(?=" + s.substring(stem.length() + 1) + ")"); } else { if (d == c) { continue; } c = d; regex.append(c); String newStem = s.substring(0, stem.length() + 1); SortedSet<String> tail = prefixes.tailSet(newStem); SortedSet<String> range = null; successor: for (String candidate : tail) { if (!candidate.equals(newStem)) { range = prefixes.subSet(s, candidate); break successor; } } if (range == null) { range = prefixes.tailSet(s); } buildRegex(newStem, regex, range); } regex.append('|'); } else { // empty suffix; insert dummy to be eaten when loop exits regex.append('@'); } } // eat the trailing '|' (if no empty '@') or dummy regex.deleteCharAt(regex.length() - 1); regex.append(')'); if (stem.length() == 1) { regex.append('\n'); // linebreak for TLDs } }
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.ngdata.hbaseindexer.util.zookeeper.ZkLock.java
/** * Verifies that the specified lockId is the owner of the lock. *//*www.j av a2 s .c o m*/ public static boolean ownsLock(final ZooKeeperItf zk, final String lockId) throws ZkLockException { if (zk.isCurrentThreadEventThread()) { throw new RuntimeException("ZkLock should not be used from within the ZooKeeper event thread."); } try { int lastSlashPos = lockId.lastIndexOf('/'); final String lockPath = lockId.substring(0, lastSlashPos); String lockName = lockId.substring(lastSlashPos + 1); List<String> children = zk.retryOperation(new ZooKeeperOperation<List<String>>() { @Override public List<String> execute() throws KeeperException, InterruptedException { return zk.getChildren(lockPath, null); } }); if (children.isEmpty()) return false; SortedSet<String> sortedChildren = new TreeSet<String>(children); return sortedChildren.first().equals(lockName); } catch (Throwable t) { throw new ZkLockException("Error checking lock, path: " + lockId, t); } }
From source file:org.lilyproject.util.zookeeper.ZkLock.java
/** * Verifies that the specified lockId is the owner of the lock. *//*from w w w .j a v a2 s. c o m*/ public static boolean ownsLock(final ZooKeeperItf zk, final String lockId) throws ZkLockException { if (zk.isCurrentThreadEventThread()) { throw new RuntimeException("ZkLock should not be used from within the ZooKeeper event thread."); } try { int lastSlashPos = lockId.lastIndexOf('/'); final String lockPath = lockId.substring(0, lastSlashPos); String lockName = lockId.substring(lastSlashPos + 1); List<String> children = zk.retryOperation(new ZooKeeperOperation<List<String>>() { @Override public List<String> execute() throws KeeperException, InterruptedException { return zk.getChildren(lockPath, null); } }); if (children.isEmpty()) { return false; } SortedSet<String> sortedChildren = new TreeSet<String>(children); return sortedChildren.first().equals(lockName); } catch (Throwable t) { throw new ZkLockException("Error checking lock, path: " + lockId, t); } }
From source file:at.ac.ait.ubicity.fileloader.FileLoader.java
/** * //from w ww . j a v a 2s . co m * @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(); }
From source file:com.jakev.genaidl.App.java
private static int processDex(String outputDirectory) { int rtn = 0;// ww w . j a v a 2 s .co m int i = 0; Set<? extends DexBackedClassDef> classDefs = gDexFile.getClasses(); /* Find all IInterfaces first */ for (DexBackedClassDef classDef : classDefs) { String className = descriptorToDot(classDef.getType()); /* No support AIDL */ if (className.startsWith("android.support")) { continue; } SortedSet<String> interfaces = new TreeSet(classDef.getInterfaces()); if (interfaces.size() != 1) { continue; } if (descriptorToDot(interfaces.first()).equals(IINTERFACE_CLASS)) { /* Now grab the Stub.Proxy, to get the protocols */ String stubProxyName = className + ".Stub.Proxy"; DexBackedClassDef stubProxyDef = getStubProxy(classDefs, stubProxyName); if (stubProxyDef == null) { System.err.println( "[ERROR] Unable to find Stub.Proxy for class: " + stubProxyName + ", Skiping!"); continue; } AidlFile aidl = new AidlFile(className, outputDirectory); String shortClassName = Utils.getShort(className); /* Parse methods */ for (DexBackedMethod method : stubProxyDef.getVirtualMethods()) { String methodName = method.getName(); if (methodName.equals(GET_INT_DESC_METHOD_NAME) || methodName.equals(AS_BINDER_METHOD_NAME)) { continue; } String returnType = descriptorToDot(method.getReturnType()); /* Try to add returnType to imports */ aidl.addImport(returnType); String shortReturnType = Utils.getShort(returnType); StringBuilder paramStringBuilder = new StringBuilder(); int paramOffset = 0; for (MethodParameter param : method.getParameters()) { String dottedName = descriptorToDot(param.getType()); /* Try to add returnType to imports */ aidl.addImport(dottedName); String shortName = Utils.getShort(dottedName); String argName = ""; /* Is the name saved? */ if (param.getName() != null) { argName = param.getName(); } else { argName = "arg" + Integer.toString(paramOffset); } paramStringBuilder.append(shortName + " " + argName + ", "); paramOffset++; } String paramString = paramStringBuilder.toString().replaceAll(",\\s$", ""); /* Let's build the import list */ aidl.addMethod(" " + shortReturnType + " " + methodName + "(" + paramString + ");"); } /* Write it out. */ aidl.writeFile(); } } return rtn; }