List of usage examples for java.util SortedSet isEmpty
boolean isEmpty();
From source file:net.sourceforge.fenixedu.domain.student.Registration.java
final public ExecutionYear getLastEnrolmentExecutionYear() { SortedSet<ExecutionYear> sorted = getSortedEnrolmentsExecutionYears(); if (!sorted.isEmpty()) { return sorted.last(); } else {/*from w w w .j a v a 2 s . com*/ return null; } }
From source file:net.sourceforge.fenixedu.domain.student.Registration.java
public ExecutionYear getFirstCurriculumLineExecutionYear() { final SortedSet<ExecutionYear> executionYears = getSortedCurriculumLinesExecutionYears(); return executionYears.isEmpty() ? null : executionYears.first(); }
From source file:net.sourceforge.fenixedu.domain.student.Registration.java
final public CycleType getLastConcludedCycleType() { final SortedSet<CycleType> concludedCycles = new TreeSet<CycleType>(getConcludedCycles()); return concludedCycles.isEmpty() ? null : concludedCycles.last(); }
From source file:net.sourceforge.fenixedu.domain.student.Registration.java
final public ExecutionYear getFirstEnrolmentExecutionYear() { final SortedSet<ExecutionYear> sortedEnrolmentsExecutionYears = getSortedEnrolmentsExecutionYears(); return sortedEnrolmentsExecutionYears.isEmpty() ? null : sortedEnrolmentsExecutionYears.first(); }
From source file:net.sourceforge.fenixedu.domain.student.Registration.java
final public CycleType getCycleType(final ExecutionYear executionYear) { if (!isBolonha() || isEmptyDegree() || getDegreeType().isEmpty()) { return null; }// w w w.j ava 2 s . co m final SortedSet<CycleType> concludedCycles = new TreeSet<CycleType>(getConcludedCycles(executionYear)); if (concludedCycles.isEmpty()) { return getLastStudentCurricularPlan().getFirstOrderedCycleCurriculumGroup().getCycleType(); } else { CycleType result = null; for (CycleType cycleType : concludedCycles) { final CycleCurriculumGroup group = getLastStudentCurricularPlan().getCycle(cycleType); if (group.hasEnrolment(executionYear)) { result = cycleType; } } if (result != null) { return result; } final CycleType last = concludedCycles.last(); return last.hasNext() && getDegreeType().hasCycleTypes(last.getNext()) ? last.getNext() : last; } }
From source file:net.sourceforge.fenixedu.domain.student.Registration.java
final public YearMonthDay getLastApprovedEnrolmentEvaluationDate() { final SortedSet<Enrolment> enrolments = new TreeSet<Enrolment>( Enrolment.COMPARATOR_BY_LATEST_ENROLMENT_EVALUATION_AND_ID); enrolments.addAll(getApprovedEnrolments()); YearMonthDay internalEnrolmentExamDate = enrolments.isEmpty() ? null : enrolments.last().getLatestEnrolmentEvaluation().getExamDateYearMonthDay(); YearMonthDay externalEnrolmentExamDate = getExternalEnrolmentsSet().isEmpty() ? null : getLastExternalApprovedEnrolmentEvaluationDate(); if (internalEnrolmentExamDate == null && externalEnrolmentExamDate == null) { return null; }/*from w w w . j av a2 s. co m*/ if (internalEnrolmentExamDate == null) { return externalEnrolmentExamDate; } if (externalEnrolmentExamDate == null) { return internalEnrolmentExamDate; } return internalEnrolmentExamDate.compareTo(externalEnrolmentExamDate) > 1 ? internalEnrolmentExamDate : externalEnrolmentExamDate; }
From source file:org.wso2.carbon.apimgt.impl.utils.APIUtil.java
public static Set<APIStore> getExternalAPIStores(Set<APIStore> inputStores, int tenantId) throws APIManagementException { SortedSet<APIStore> apiStores = new TreeSet<APIStore>(new APIStoreNameComparator()); apiStores.addAll(getExternalStores(tenantId)); //Retains only the stores that contained in configuration inputStores.retainAll(apiStores);//from w w w .ja v a 2 s. c om boolean exists = false; if (!apiStores.isEmpty()) { for (APIStore store : apiStores) { for (APIStore inputStore : inputStores) { if (inputStore.getName().equals(store.getName())) { // If the configured apistore already stored in // db,ignore adding it again exists = true; } } if (!exists) { inputStores.add(store); } exists = false; } } return inputStores; }
From source file:org.torproject.ernie.db.BridgeSnapshotReader.java
public BridgeSnapshotReader(BridgeDescriptorParser bdp, String bridgeDirectoriesDir) { Logger logger = Logger.getLogger(BridgeSnapshotReader.class.getName()); SortedSet<String> parsed = new TreeSet<String>(); File bdDir = new File(bridgeDirectoriesDir); File pbdFile = new File("stats/parsed-bridge-directories"); boolean modified = false; if (bdDir.exists()) { if (pbdFile.exists()) { logger.fine("Reading file " + pbdFile.getAbsolutePath() + "..."); try { BufferedReader br = new BufferedReader(new FileReader(pbdFile)); String line = null; while ((line = br.readLine()) != null) { parsed.add(line);//from w w w .ja v a2s. c o m } br.close(); logger.fine("Finished reading file " + pbdFile.getAbsolutePath() + "."); } catch (IOException e) { logger.log(Level.WARNING, "Failed reading file " + pbdFile.getAbsolutePath() + "!", e); return; } } logger.fine("Importing files in directory " + bridgeDirectoriesDir + "/..."); Stack<File> filesInInputDir = new Stack<File>(); filesInInputDir.add(bdDir); while (!filesInInputDir.isEmpty()) { File pop = filesInInputDir.pop(); if (pop.isDirectory()) { for (File f : pop.listFiles()) { filesInInputDir.add(f); } } else if (!parsed.contains(pop.getName())) { try { FileInputStream in = new FileInputStream(pop); if (in.available() > 0) { GzipCompressorInputStream gcis = new GzipCompressorInputStream(in); TarArchiveInputStream tais = new TarArchiveInputStream(gcis); BufferedInputStream bis = new BufferedInputStream(tais); String fn = pop.getName(); String dateTime = fn.substring(11, 21) + " " + fn.substring(22, 24) + ":" + fn.substring(24, 26) + ":" + fn.substring(26, 28); while ((tais.getNextTarEntry()) != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int len; byte[] data = new byte[1024]; while ((len = bis.read(data, 0, 1024)) >= 0) { baos.write(data, 0, len); } byte[] allData = baos.toByteArray(); if (allData.length == 0) { continue; } String ascii = new String(allData, "US-ASCII"); BufferedReader br3 = new BufferedReader(new StringReader(ascii)); String firstLine = null; while ((firstLine = br3.readLine()) != null) { if (firstLine.startsWith("@")) { continue; } else { break; } } if (firstLine.startsWith("r ")) { bdp.parse(allData, dateTime, false); } else { int start = -1, sig = -1, end = -1; String startToken = firstLine.startsWith("router ") ? "router " : "extra-info "; String sigToken = "\nrouter-signature\n"; String endToken = "\n-----END SIGNATURE-----\n"; while (end < ascii.length()) { start = ascii.indexOf(startToken, end); if (start < 0) { break; } sig = ascii.indexOf(sigToken, start); if (sig < 0) { break; } sig += sigToken.length(); end = ascii.indexOf(endToken, sig); if (end < 0) { break; } end += endToken.length(); byte[] descBytes = new byte[end - start]; System.arraycopy(allData, start, descBytes, 0, end - start); bdp.parse(descBytes, dateTime, false); } } } } in.close(); /* Let's give some memory back, or we'll run out of it. */ System.gc(); parsed.add(pop.getName()); modified = true; } catch (IOException e) { logger.log(Level.WARNING, "Could not parse bridge snapshot " + pop.getName() + "!", e); continue; } } } logger.fine("Finished importing files in directory " + bridgeDirectoriesDir + "/."); if (!parsed.isEmpty() && modified) { logger.fine("Writing file " + pbdFile.getAbsolutePath() + "..."); try { pbdFile.getParentFile().mkdirs(); BufferedWriter bw = new BufferedWriter(new FileWriter(pbdFile)); for (String f : parsed) { bw.append(f + "\n"); } bw.close(); logger.fine("Finished writing file " + pbdFile.getAbsolutePath() + "."); } catch (IOException e) { logger.log(Level.WARNING, "Failed writing file " + pbdFile.getAbsolutePath() + "!", e); } } } }
From source file:org.torproject.collector.bridgedescs.BridgeSnapshotReader.java
/** * Reads the half-hourly snapshots of bridge descriptors from Bifroest. *///from w w w . j ava 2 s.c o m public BridgeSnapshotReader(BridgeDescriptorParser bdp, File bridgeDirectoriesDir, File statsDirectory) throws ConfigurationException { if (bdp == null || bridgeDirectoriesDir == null || statsDirectory == null) { throw new IllegalArgumentException(); } SortedSet<String> parsed = new TreeSet<String>(); File bdDir = bridgeDirectoriesDir; File pbdFile = new File(statsDirectory, "parsed-bridge-directories"); boolean modified = false; if (bdDir.exists()) { if (pbdFile.exists()) { logger.debug("Reading file " + pbdFile.getAbsolutePath() + "..."); try { BufferedReader br = new BufferedReader(new FileReader(pbdFile)); String line = null; while ((line = br.readLine()) != null) { parsed.add(line); } br.close(); logger.debug("Finished reading file " + pbdFile.getAbsolutePath() + "."); } catch (IOException e) { logger.warn("Failed reading file " + pbdFile.getAbsolutePath() + "!", e); return; } } logger.debug("Importing files in directory " + bridgeDirectoriesDir + "/..."); Set<String> descriptorImportHistory = new HashSet<String>(); int parsedFiles = 0; int skippedFiles = 0; int parsedStatuses = 0; int parsedServerDescriptors = 0; int skippedServerDescriptors = 0; int parsedExtraInfoDescriptors = 0; int skippedExtraInfoDescriptors = 0; Stack<File> filesInInputDir = new Stack<File>(); filesInInputDir.add(bdDir); while (!filesInInputDir.isEmpty()) { File pop = filesInInputDir.pop(); if (pop.isDirectory()) { for (File f : pop.listFiles()) { filesInInputDir.add(f); } } else if (!parsed.contains(pop.getName())) { try { FileInputStream in = new FileInputStream(pop); if (in.available() > 0) { TarArchiveInputStream tais = null; if (pop.getName().endsWith(".tar.gz")) { GzipCompressorInputStream gcis = new GzipCompressorInputStream(in); tais = new TarArchiveInputStream(gcis); } else if (pop.getName().endsWith(".tar")) { tais = new TarArchiveInputStream(in); } else { continue; } BufferedInputStream bis = new BufferedInputStream(tais); String fn = pop.getName(); String[] fnParts = fn.split("-"); if (fnParts.length != 5) { logger.warn("Invalid bridge descriptor tarball file name: " + fn + ". Skipping."); continue; } String authorityPart = String.format("%s-%s-", fnParts[0], fnParts[1]); String datePart = String.format("%s-%s-%s", fnParts[2], fnParts[3], fnParts[4]); String authorityFingerprint; switch (authorityPart) { case "from-tonga-": authorityFingerprint = "4A0CCD2DDC7995083D73F5D667100C8A5831F16D"; break; case "from-bifroest-": authorityFingerprint = "1D8F3A91C37C5D1C4C19B1AD1D0CFBE8BF72D8E1"; break; default: logger.warn("Did not recognize the bridge authority that " + "generated " + fn + ". Skipping."); continue; } String dateTime = datePart.substring(0, 10) + " " + datePart.substring(11, 13) + ":" + datePart.substring(13, 15) + ":" + datePart.substring(15, 17); while ((tais.getNextTarEntry()) != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int len; byte[] data = new byte[1024]; while ((len = bis.read(data, 0, 1024)) >= 0) { baos.write(data, 0, len); } byte[] allData = baos.toByteArray(); if (allData.length == 0) { continue; } String fileDigest = Hex.encodeHexString(DigestUtils.sha(allData)); String ascii = new String(allData, "US-ASCII"); BufferedReader br3 = new BufferedReader(new StringReader(ascii)); String firstLine = null; while ((firstLine = br3.readLine()) != null) { if (firstLine.startsWith("@")) { continue; } else { break; } } if (firstLine == null) { continue; } if (firstLine.startsWith("published ") || firstLine.startsWith("flag-thresholds ") || firstLine.startsWith("r ")) { bdp.parse(allData, dateTime, authorityFingerprint); parsedStatuses++; } else if (descriptorImportHistory.contains(fileDigest)) { /* Skip server descriptors or extra-info descriptors if * we parsed them before. */ skippedFiles++; continue; } else { int start = -1; int sig = -1; int end = -1; String startToken = firstLine.startsWith("router ") ? "router " : "extra-info "; String sigToken = "\nrouter-signature\n"; String endToken = "\n-----END SIGNATURE-----\n"; while (end < ascii.length()) { start = ascii.indexOf(startToken, end); if (start < 0) { break; } sig = ascii.indexOf(sigToken, start); if (sig < 0) { break; } sig += sigToken.length(); end = ascii.indexOf(endToken, sig); if (end < 0) { break; } end += endToken.length(); byte[] descBytes = new byte[end - start]; System.arraycopy(allData, start, descBytes, 0, end - start); String descriptorDigest = Hex.encodeHexString(DigestUtils.sha(descBytes)); if (!descriptorImportHistory.contains(descriptorDigest)) { bdp.parse(descBytes, dateTime, authorityFingerprint); descriptorImportHistory.add(descriptorDigest); if (firstLine.startsWith("router ")) { parsedServerDescriptors++; } else { parsedExtraInfoDescriptors++; } } else { if (firstLine.startsWith("router ")) { skippedServerDescriptors++; } else { skippedExtraInfoDescriptors++; } } } } descriptorImportHistory.add(fileDigest); parsedFiles++; } bis.close(); } in.close(); /* Let's give some memory back, or we'll run out of it. */ System.gc(); parsed.add(pop.getName()); modified = true; } catch (IOException e) { logger.warn("Could not parse bridge snapshot " + pop.getName() + "!", e); continue; } } } logger.debug("Finished importing files in directory " + bridgeDirectoriesDir + "/. In total, we parsed " + parsedFiles + " files (skipped " + skippedFiles + ") containing " + parsedStatuses + " statuses, " + parsedServerDescriptors + " server descriptors (skipped " + skippedServerDescriptors + "), and " + parsedExtraInfoDescriptors + " extra-info descriptors " + "(skipped " + skippedExtraInfoDescriptors + ")."); if (!parsed.isEmpty() && modified) { logger.debug("Writing file " + pbdFile.getAbsolutePath() + "..."); pbdFile.getParentFile().mkdirs(); try (BufferedWriter bw = new BufferedWriter(new FileWriter(pbdFile))) { for (String f : parsed) { bw.append(f + "\n"); } logger.debug("Finished writing file " + pbdFile.getAbsolutePath() + "."); } catch (IOException e) { logger.warn("Failed writing file " + pbdFile.getAbsolutePath() + "!", e); } } } }