List of usage examples for java.util TreeSet isEmpty
public boolean isEmpty()
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); System.out.println(treeadd.isEmpty()); treeadd.add(2);/*from w w w. j av a 2 s . c om*/ System.out.println(treeadd.isEmpty()); }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> tSet = new TreeSet<Integer>(); tSet.add(new Integer("1")); tSet.add(new Integer("2")); tSet.add(new Integer("3")); System.out.println("TreeSet before removal : " + tSet); tSet.clear();/*from w w w .ja v a 2s .co m*/ System.out.println("TreeSet after removal : " + tSet); System.out.println("Is TreeSet empty ? " + tSet.isEmpty()); }
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;/*ww w .j av a 2s. 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 om 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);/* ww w.java2s .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 ww w . j ava2s. co 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:org.apache.htrace.core.TracerId.java
/** * <p>Get the best IP address that represents this node.</p> * * This is complicated since nodes can have multiple network interfaces, * and each network interface can have multiple IP addresses. What we're * looking for here is an IP address that will serve to identify this node * to HTrace. So we prefer site-local addresess (i.e. private ones on the * LAN) to publicly routable interfaces. If there are multiple addresses * to choose from, we select the one which comes first in textual sort * order. This should ensure that we at least consistently call each node * by a single name.//from w ww. j a v a 2 s . c o m */ static String getBestIpString() { Enumeration<NetworkInterface> ifaces; try { ifaces = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e) { LOG.error("Error getting network interfaces", e); return "127.0.0.1"; } TreeSet<String> siteLocalCandidates = new TreeSet<String>(); TreeSet<String> candidates = new TreeSet<String>(); while (ifaces.hasMoreElements()) { NetworkInterface iface = ifaces.nextElement(); for (Enumeration<InetAddress> addrs = iface.getInetAddresses(); addrs.hasMoreElements();) { InetAddress addr = addrs.nextElement(); if (!addr.isLoopbackAddress()) { if (addr.isSiteLocalAddress()) { siteLocalCandidates.add(addr.getHostAddress()); } else { candidates.add(addr.getHostAddress()); } } } } if (!siteLocalCandidates.isEmpty()) { return siteLocalCandidates.first(); } if (!candidates.isEmpty()) { return candidates.first(); } return "127.0.0.1"; }
From source file:md.MangaDownloader.java
public static String automaticVolumeName(List<MangaChaptersInfo> selectedChapters) { TreeSet<Integer> chapterNumbers = new TreeSet<Integer>(); String alternative = ""; for (MangaChaptersInfo m : selectedChapters) { try {/*from w w w .ja va 2 s . c o m*/ if (!m.chapterNumber.equals("")) { int test = Integer.parseInt(m.chapterNumber); chapterNumbers.add(test); } } catch (NumberFormatException e) { //If more than one alternative chapter name then all renamed to "Extras" if (alternative.equals("")) { alternative = m.chapterNumber; } else { alternative = STRINGS.getString("NAME_EXTRAS"); } } } String result = ""; if (!chapterNumbers.isEmpty()) { int firstInSequence = Integer.MIN_VALUE; int lastInSequence; for (Iterator<Integer> i = chapterNumbers.iterator(); i.hasNext();) { int actualNumber = i.next(); if (firstInSequence == Integer.MIN_VALUE) firstInSequence = actualNumber; lastInSequence = actualNumber; int next; if (i.hasNext()) { next = chapterNumbers.higher(actualNumber); } else { next = Integer.MIN_VALUE; } if ((actualNumber + 1 != next) || (next == Integer.MIN_VALUE)) { //FIN DE SECUENCIA if (!result.equals("")) { result += ", "; } if (firstInSequence == lastInSequence) { result += String.format("%04d", firstInSequence); } else { result += String.format("%04d - %04d", firstInSequence, lastInSequence); } firstInSequence = Integer.MIN_VALUE; } } } if (!alternative.equals("")) { if (!result.equals("")) result += " & "; result += alternative; } return result; }
From source file:net.spfbl.core.Client.java
public static Client create(String cidr, String domain, String permission, String email) throws ProcessException { if (Subnet.isValidCIDR(cidr)) { TreeSet<Client> clientSet = Client.getSetByCIDR(cidr, permission); if (clientSet == null || clientSet.isEmpty()) { String first = Subnet.getFirstIP(cidr); String ip = Subnet.expandIP(first); Client client = new Client(cidr, domain, email); client.setPermission(permission); MAP.put(ip, client);/*from ww w.j a v a 2s.c om*/ CHANGED = true; return client; } else { return null; } } else { throw new ProcessException("INVALID CIDR"); } }
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 av a 2s . 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; }