List of usage examples for java.util TreeSet last
public E last()
From source file:MainClass.java
public static void main(String args[]) throws Exception { String elements[] = { "A", "C", "D", "G", "F" }; TreeSet set = new TreeSet(Arrays.asList(elements)); System.out.println(set);//w w w . j av a 2 s . c o m System.out.println(set.first()); System.out.println(set.last()); }
From source file:Main.java
public static void main(String args[]) throws Exception { String elements[] = { "A", "C", "D", "G", "F" }; TreeSet<String> set = new TreeSet<String>(Arrays.asList(elements)); System.out.println(set);/*from w w w.j a v a2s.c o m*/ System.out.println(set.first()); System.out.println(set.last()); }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(1);/* w ww . j a v a 2s . co m*/ treeadd.add(13); treeadd.add(17); treeadd.add(2); System.out.println("Last highest element: " + treeadd.last()); }
From source file:Main.java
public static void main(String args[]) { Set<String> hs = new HashSet<String>(); hs.add("one"); hs.add("two"); hs.add("three"); System.out.println("Here is the HashSet: " + hs); if (!hs.add("three")) System.out.println("Attempt to add duplicate. " + "Set is unchanged: " + hs); TreeSet<Integer> ts = new TreeSet<Integer>(); ts.add(8);//from w w w.jav a 2s . c o m ts.add(19); ts.add(-2); ts.add(3); System.out.println(ts); System.out.println("First element in ts: " + ts.first()); System.out.println("Last element in ts: " + ts.last()); System.out.println("First element > 15: " + ts.higher(15)); System.out.println("First element < 15: " + ts.lower(15)); }
From source file:Main.java
public static void main(String[] args) { TreeSet<String> tSet = new TreeSet<String>(); tSet.add("1"); tSet.add("2"); tSet.add("3"); tSet.add("4"); tSet.add("5"); System.out.println("Lowest value Stored in Java TreeSet is : " + tSet.first()); System.out.println("Highest value Stored in Java TreeSet is : " + tSet.last()); }
From source file:com.metamx.druid.utils.ExposeS3DataSource.java
public static void main(String[] args) throws ServiceException, IOException, NoSuchAlgorithmException { CLI cli = new CLI(); cli.addOption(new RequiredOption(null, "s3Bucket", true, "s3 bucket to pull data from")); cli.addOption(new RequiredOption(null, "s3Path", true, "base input path in s3 bucket. Everything until the date strings.")); cli.addOption(new RequiredOption(null, "timeInterval", true, "ISO8601 interval of dates to index")); cli.addOption(new RequiredOption(null, "granularity", true, String.format( "granularity of index, supported granularities: [%s]", Arrays.asList(Granularity.values())))); cli.addOption(new RequiredOption(null, "zkCluster", true, "Cluster string to connect to ZK with.")); cli.addOption(new RequiredOption(null, "zkBasePath", true, "The base path to register index changes to.")); CommandLine commandLine = cli.parse(args); if (commandLine == null) { return;/* w w w .j av a 2 s . c o m*/ } String s3Bucket = commandLine.getOptionValue("s3Bucket"); String s3Path = commandLine.getOptionValue("s3Path"); String timeIntervalString = commandLine.getOptionValue("timeInterval"); String granularity = commandLine.getOptionValue("granularity"); String zkCluster = commandLine.getOptionValue("zkCluster"); String zkBasePath = commandLine.getOptionValue("zkBasePath"); Interval timeInterval = new Interval(timeIntervalString); Granularity gran = Granularity.valueOf(granularity.toUpperCase()); final RestS3Service s3Client = new RestS3Service(new AWSCredentials( System.getProperty("com.metamx.aws.accessKey"), System.getProperty("com.metamx.aws.secretKey"))); ZkClient zkClient = new ZkClient(new ZkConnection(zkCluster), Integer.MAX_VALUE, new StringZkSerializer()); zkClient.waitUntilConnected(); for (Interval interval : gran.getIterable(timeInterval)) { log.info("Processing interval[%s]", interval); String s3DatePath = JOINER.join(s3Path, gran.toPath(interval.getStart())); if (!s3DatePath.endsWith("/")) { s3DatePath += "/"; } StorageObjectsChunk chunk = s3Client.listObjectsChunked(s3Bucket, s3DatePath, "/", 2000, null, true); TreeSet<String> commonPrefixes = Sets.newTreeSet(); commonPrefixes.addAll(Arrays.asList(chunk.getCommonPrefixes())); if (commonPrefixes.isEmpty()) { log.info("Nothing at s3://%s/%s", s3Bucket, s3DatePath); continue; } String latestPrefix = commonPrefixes.last(); log.info("Latest segments at [s3://%s/%s]", s3Bucket, latestPrefix); chunk = s3Client.listObjectsChunked(s3Bucket, latestPrefix, "/", 2000, null, true); Integer partitionNumber; if (chunk.getCommonPrefixes().length == 0) { partitionNumber = null; } else { partitionNumber = -1; for (String partitionPrefix : chunk.getCommonPrefixes()) { String[] splits = partitionPrefix.split("/"); partitionNumber = Math.max(partitionNumber, Integer.parseInt(splits[splits.length - 1])); } } log.info("Highest segment partition[%,d]", partitionNumber); if (partitionNumber == null) { final S3Object s3Obj = new S3Object(new S3Bucket(s3Bucket), String.format("%sdescriptor.json", latestPrefix)); updateWithS3Object(zkBasePath, s3Client, zkClient, s3Obj); } else { for (int i = partitionNumber; i >= 0; --i) { final S3Object partitionObject = new S3Object(new S3Bucket(s3Bucket), String.format("%s%s/descriptor.json", latestPrefix, i)); updateWithS3Object(zkBasePath, s3Client, zkClient, partitionObject); } } } }
From source file:com.github.drbookings.LocalDates.java
public static Range<LocalDate> getDateRange(final Collection<? extends LocalDate> dates, final boolean oneMoreAtTheBeginning) { final TreeSet<LocalDate> set = new TreeSet<>(dates); if (set.isEmpty()) { return null; }//from www . j a v a 2 s. c o m final LocalDate d1; final LocalDate d2; d2 = set.last(); if (oneMoreAtTheBeginning) { d1 = set.first().minusDays(1); } else { d1 = set.first(); } return Range.closed(d1, d2); }
From source file:com.ettoremastrogiacomo.sktradingjava.starters.Temp.java
public static java.util.ArrayList<TreeSet<UDate>> timesegments(java.util.TreeSet<UDate> dates, long maxgapmsec) { java.util.TreeMap<Integer, TreeSet<UDate>> rank = new java.util.TreeMap<>(); java.util.TreeSet<UDate> t = new TreeSet<>(); java.util.ArrayList<TreeSet<UDate>> list = new ArrayList<>(); for (UDate d : dates) { if (t.isEmpty()) { t.add(d);//from w w w . ja va 2 s . c o m } else if (d.diffmills(t.last()) > maxgapmsec) { rank.put(t.size(), t); list.add(t); t = new TreeSet<>(); } else { t.add(d); } } return list; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.administrativeOffice.lists.StudentListByDegreeDA.java
private static List<RegistrationWithStateForExecutionYearBean> filterResults( SearchStudentsByDegreeParametersBean searchBean, final Set<Registration> registrations, final ExecutionYear executionYear) { final List<RegistrationWithStateForExecutionYearBean> result = new ArrayList<RegistrationWithStateForExecutionYearBean>(); for (final Registration registration : registrations) { if (searchBean.hasAnyRegistrationProtocol() && !searchBean.getRegistrationProtocols().contains(registration.getRegistrationProtocol())) { continue; }/*from www . j ava2 s .c o m*/ if (searchBean.hasAnyStudentStatuteType() && !hasStudentStatuteType(searchBean, registration)) { continue; } final RegistrationState lastRegistrationState = registration.getLastRegistrationState(executionYear); if (lastRegistrationState == null) { continue; } if (searchBean.hasAnyRegistrationStateTypes() && !searchBean.getRegistrationStateTypes().contains(lastRegistrationState.getStateType())) { continue; } if ((searchBean.isIngressedInChosenYear()) && (registration.getIngressionYear() != executionYear)) { continue; } if (searchBean.isConcludedInChosenYear()) { CycleType cycleType; if (searchBean.getDegreeType() != null) { final TreeSet<CycleType> orderedCycleTypes = searchBean.getDegreeType().getOrderedCycleTypes(); cycleType = orderedCycleTypes.isEmpty() ? null : orderedCycleTypes.last(); } else { cycleType = registration.getCycleType(executionYear); } RegistrationConclusionBean conclusionBean; if (registration.isBolonha()) { conclusionBean = new RegistrationConclusionBean(registration, cycleType); if (conclusionBean.getCycleCurriculumGroup() == null || !conclusionBean.isConcluded()) { continue; } } else { conclusionBean = new RegistrationConclusionBean(registration); if (!conclusionBean.isConclusionProcessed()) { continue; } } if (conclusionBean.getConclusionYear() != executionYear) { continue; } } if (searchBean.getActiveEnrolments() && !registration.hasAnyEnrolmentsIn(executionYear)) { continue; } if (searchBean.getStandaloneEnrolments() && !registration.hasAnyStandaloneEnrolmentsIn(executionYear)) { continue; } if ((searchBean.getRegime() != null) && (registration.getRegimeType(executionYear) != searchBean.getRegime())) { continue; } if ((searchBean.getNationality() != null) && (registration.getPerson().getCountry() != searchBean.getNationality())) { continue; } if ((searchBean.getIngression() != null) && (registration.getIngression() != searchBean.getIngression())) { continue; } result.add(new RegistrationWithStateForExecutionYearBean(registration, lastRegistrationState.getStateType(), executionYear)); } return result; }
From source file:com.chadekin.jadys.commons.expression.SqlExpressionHandler.java
/** * Add an argument to the expression to be included to the actual builder, after verifying it is a valid expression * @param arg//w w w . j a v a2 s . c o m * @return */ public default T addArgument(Object arg) { SqlExpressionItem expressionItem = getSqlExpressionItem(); if (expressionItem == null) { setSqlExpressionItem(new SqlExpressionItem()); } if (LOGICAL_OPERATORS.contains(arg)) { getSqlExpressionItem().appendLogicalOperator((JadysSqlOperation) arg); } else if (arg instanceof JadysSqlOperation) { JadysSqlOperation operator = (JadysSqlOperation) arg; TreeSet logicalOperators = getSqlExpressionItem().getLogicalOperator(); if (!logicalOperators.isEmpty() && logicalOperators.last() == JadysSqlOperation.NOT) { operator = operator.getOpposite(); getSqlExpressionItem().getLogicalOperator().remove(JadysSqlOperation.NOT); } getSqlExpressionItem().setOperator(operator); } else if (getSqlExpressionItem().getParam() == null) { String parameter = arg == null ? StringUtils.EMPTY : arg.toString(); getSqlExpressionItem().setParam(parameter); } else if (arg == null) { setSqlExpressionItem(null); } else if (getSqlExpressionItem().getValue() == null) { getSqlExpressionItem().setValue(arg); } if (getSqlExpressionItem() != null && getSqlExpressionItem().isReady()) { finalizeExpression(); setSqlExpressionItem(null); } return (T) this; }