List of usage examples for java.util SortedSet isEmpty
boolean isEmpty();
From source file:net.sourceforge.fenixedu.domain.Lesson.java
private Summary getLastSummary() { SortedSet<Summary> summaries = getSummariesSortedByNewestDate(); return (summaries.isEmpty()) ? null : summaries.first(); }
From source file:org.apache.accumulo.core.util.shell.commands.TableOperation.java
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception { // populate the tableSet set with the tables you want to operate on final SortedSet<String> tableSet = new TreeSet<String>(); if (cl.hasOption(optTablePattern.getOpt())) { for (String table : shellState.getConnector().tableOperations().list()) if (table.matches(cl.getOptionValue(optTablePattern.getOpt()))) { tableSet.add(table);//from w w w . j av a2s . co m } } else if (cl.hasOption(optTableName.getOpt())) { tableSet.add(cl.getOptionValue(optTableName.getOpt())); } else if (cl.hasOption(optNamespace.getOpt())) { Instance instance = shellState.getInstance(); String namespaceId = Namespaces.getNamespaceId(instance, cl.getOptionValue(optNamespace.getOpt())); for (String tableId : Namespaces.getTableIds(instance, namespaceId)) { tableSet.add(Tables.getTableName(instance, tableId)); } } else if (useCommandLine && cl.getArgs().length > 0) { for (String tableName : cl.getArgs()) { tableSet.add(tableName); } } else { shellState.checkTableState(); tableSet.add(shellState.getTableName()); } if (tableSet.isEmpty()) Shell.log.warn("No tables found that match your criteria"); boolean more = true; // flush the tables for (String tableName : tableSet) { if (!more) { break; } if (!shellState.getConnector().tableOperations().exists(tableName)) { throw new TableNotFoundException(null, tableName, null); } boolean operate = true; if (!force) { shellState.getReader().flush(); String line = shellState.getReader().readLine(getName() + " { " + tableName + " } (yes|no)? "); more = line != null; operate = line != null && (line.equalsIgnoreCase("y") || line.equalsIgnoreCase("yes")); } if (operate) { doTableOp(shellState, tableName); } } return 0; }
From source file:net.sourceforge.fenixedu.domain.Lesson.java
public boolean isDateValidToInsertSummary(YearMonthDay date) { YearMonthDay currentDate = new YearMonthDay(); SortedSet<YearMonthDay> allLessonDatesEvenToday = getAllLessonDatesUntil(currentDate); return (allLessonDatesEvenToday.isEmpty() || date == null) ? false : allLessonDatesEvenToday.contains(date); }
From source file:net.sourceforge.fenixedu.presentationTier.Action.administrativeOffice.scholarship.utl.report.StudentLine.java
public Integer getCountNumberOfDegreeChanges() { int numberOfDegreeChanges = 0; if (student == null) { return 0; }/*w w w .j a v a 2s. co m*/ List<Registration> registrations = new ArrayList<Registration>(student.getRegistrationsSet()); Collections.sort(registrations, Registration.COMPARATOR_BY_START_DATE); for (final Registration iter : registrations) { final SortedSet<RegistrationState> states = new TreeSet<RegistrationState>( RegistrationState.DATE_COMPARATOR); states.addAll(iter.getRegistrationStates(RegistrationStateType.INTERNAL_ABANDON)); if (!states.isEmpty()) { numberOfDegreeChanges++; } } return numberOfDegreeChanges; }
From source file:net.sourceforge.fenixedu.domain.Lesson.java
public YearMonthDay getNextPossibleLessonInstanceDate() { SortedSet<YearMonthDay> allLessonDates = getAllLessonDates(); LessonInstance lastLessonInstance = getLastLessonInstance(); if (lastLessonInstance != null) { YearMonthDay day = lastLessonInstance.getDay(); SortedSet<YearMonthDay> nextLessonDates = allLessonDates.tailSet(day); nextLessonDates.remove(day);// w ww. j a va2 s .c o m return nextLessonDates.isEmpty() ? null : nextLessonDates.first(); } return allLessonDates.isEmpty() ? null : allLessonDates.first(); }
From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.department.PublicDepartmentSiteDA.java
public ActionForward employees(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) {//from ww w . ja va 2 s . co m Unit unit = getUnit(request); BeanComparator employeeComparator = new BeanComparator("person", Party.COMPARATOR_BY_NAME_AND_ID); SortedSet<Unit> workingUnits = new TreeSet<Unit>(Unit.COMPARATOR_BY_NAME_AND_ID); SortedSet<Employee> noUnitAvailable = new TreeSet<Employee>(employeeComparator); Map<String, SortedSet<Employee>> employeesMap = new Hashtable<String, SortedSet<Employee>>(); for (Employee employee : unit.getAllCurrentNonTeacherEmployees()) { if (employee.getPerson().hasRole(RoleType.TEACHER)) { continue; } Unit workingUnit = employee.getCurrentWorkingPlace(); if (workingUnit != null) { workingUnits.add(workingUnit); String areaKey = workingUnit.getExternalId().toString(); SortedSet<Employee> employees = employeesMap.get(areaKey); if (employees == null) { employees = new TreeSet<Employee>(employeeComparator); employeesMap.put(areaKey, employees); } employees.add(employee); } else { noUnitAvailable.add(employee); } } if (workingUnits.isEmpty()) { request.setAttribute("ignoreAreas", true); } request.setAttribute("areas", workingUnits); request.setAttribute("employees", employeesMap); request.setAttribute("employeesNoArea", noUnitAvailable); return mapping.findForward("department-employees"); }
From source file:org.apache.accumulo.core.util.shell.commands.DUCommand.java
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws IOException, TableNotFoundException, NamespaceNotFoundException { final SortedSet<String> tables = new TreeSet<String>(Arrays.asList(cl.getArgs())); if (cl.hasOption(Shell.tableOption)) { String tableName = cl.getOptionValue(Shell.tableOption); if (!shellState.getConnector().tableOperations().exists(tableName)) { throw new TableNotFoundException(tableName, tableName, "specified table that doesn't exist"); }/*w w w. j a va 2 s . co m*/ tables.add(tableName); } if (cl.hasOption(optNamespace.getOpt())) { Instance instance = shellState.getInstance(); String namespaceId = Namespaces.getNamespaceId(instance, cl.getOptionValue(optNamespace.getOpt())); tables.addAll(Namespaces.getTableNames(instance, namespaceId)); } boolean prettyPrint = cl.hasOption(optHumanReadble.getOpt()) ? true : false; // Add any patterns if (cl.hasOption(optTablePattern.getOpt())) { for (String table : shellState.getConnector().tableOperations().list()) { if (table.matches(cl.getOptionValue(optTablePattern.getOpt()))) { tables.add(table); } } } // If we didn't get any tables, and we have a table selected, add the current table if (tables.isEmpty() && !shellState.getTableName().isEmpty()) { tables.add(shellState.getTableName()); } try { String valueFormat = prettyPrint ? "%9s" : "%,24d"; for (DiskUsage usage : shellState.getConnector().tableOperations().getDiskUsage(tables)) { Object value = prettyPrint ? NumUtil.bigNumberForSize(usage.getUsage()) : usage.getUsage(); shellState.getReader().println(String.format(valueFormat + " %s", value, usage.getTables())); } } catch (Exception ex) { throw new RuntimeException(ex); } return 0; }
From source file:com.fluidops.iwb.server.SparqlServlet.java
/** * Handle legacy aggregation of tuple queries. Prints the aggregated result as CSV! * //w w w. j a v a 2 s .c o m * Condition: tuple query + parameter "input" and "output" are set * * Also deals with (optional) parameter "datasets" * * This method MUST return true, if SPARQL processing shall continue. If legacy code * is applied, results may be written to the outputstream directly (and false is returned) * * @param res * @param req * @return * true if the standard SPARQL processing should continue, false otherwise * @throws QueryEvaluationException * @throws IOException */ private boolean handleAggregationLegacy(TupleQueryResult res, HttpServletRequest req, ReadDataManager queryDM, OutputStream outputStream) throws QueryEvaluationException, IOException { String input = req.getParameter("input"); String output = req.getParameter("output"); // check the condition if (StringUtil.isNullOrEmpty(input) || StringUtil.isNullOrEmpty(output)) return true; String datasets = req.getParameter("datasets"); String aggregation = req.getParameter("aggregation"); String[] outputs = output.split(","); AggregationType aggType = AggregationType.NONE; // DEFAULT if (aggregation != null) { if (aggregation.equals("COUNT")) aggType = AggregationType.COUNT; else if (aggregation.equals("SUM")) aggType = AggregationType.SUM; else if (aggregation.equals("NONE")) aggType = AggregationType.NONE; else if (aggregation.equals("AVG")) aggType = AggregationType.AVG; } Map<Value, Vector<Number>> valueMap; if (datasets == null) { valueMap = queryDM.aggregateQueryResult(res, aggType, input, outputs); } else { // special handling: we must first group by the values // of the datasets parameter before aggregating; this // processing scheme supports only a single output variable String[] splittedDatasets = datasets.split(","); valueMap = queryDM.aggregateQueryResultWrtDatasets(res, aggType, input, outputs[0], splittedDatasets); } // We need to sort the input again, as the order gets lost when accessing the valueMap Set<Value> keySet = valueMap.keySet(); SortedSet<Value> sortedSet = new TreeSet<Value>(new ValueComparator()); sortedSet.addAll(keySet); // need to write at least one space, as empty results cause errors in charts if (sortedSet.isEmpty()) outputStream.write(" ".getBytes("UTF-8")); for (Value val : sortedSet) { Vector<Number> vals = valueMap.get(val); outputStream.write(val.stringValue().getBytes("UTF-8")); for (int i = 0; i < vals.size(); i++) { Number n = vals.elementAt(i); if (n == null || n.toString() == null) outputStream.write(";".getBytes("UTF-8")); else outputStream.write((";" + n.toString()).getBytes("UTF-8")); } outputStream.write("\n".getBytes("UTF-8")); } return false; }
From source file:org.apache.hadoop.hbase.regionserver.Memcache.java
private void getRowKeyAtOrBefore(final ConcurrentSkipListSet<KeyValue> set, final KeyValue kv, final NavigableSet<KeyValue> candidates, final NavigableSet<KeyValue> deletes, final long now) { if (set.isEmpty()) { return;//from w ww . j ava 2 s . c o m } // We want the earliest possible to start searching from. Start before // the candidate key in case it turns out a delete came in later. KeyValue search = candidates.isEmpty() ? kv : candidates.first(); // Get all the entries that come equal or after our search key SortedSet<KeyValue> tailset = set.tailSet(search); // if there are items in the tail map, there's either a direct match to // the search key, or a range of values between the first candidate key // and the ultimate search key (or the end of the cache) if (!tailset.isEmpty() && this.comparator.compareRows(tailset.first(), search) <= 0) { // Keep looking at cells as long as they are no greater than the // ultimate search key and there's still records left in the map. KeyValue deleted = null; KeyValue found = null; for (Iterator<KeyValue> iterator = tailset.iterator(); iterator.hasNext() && (found == null || this.comparator.compareRows(found, kv) <= 0);) { found = iterator.next(); if (this.comparator.compareRows(found, kv) <= 0) { if (found.isDeleteType()) { Store.handleDeletes(found, candidates, deletes); if (deleted == null) { deleted = found; } } else { if (Store.notExpiredAndNotInDeletes(this.ttl, found, now, deletes)) { candidates.add(found); } else { if (deleted == null) { deleted = found; } // TODO: Check this removes the right key. // Its expired. Remove it. iterator.remove(); } } } } if (candidates.isEmpty() && deleted != null) { getRowKeyBefore(set, deleted, candidates, deletes, now); } } else { // The tail didn't contain any keys that matched our criteria, or was // empty. Examine all the keys that proceed our splitting point. getRowKeyBefore(set, search, candidates, deletes, now); } }
From source file:net.sourceforge.fenixedu.domain.Lesson.java
public LessonInstance getLastLessonInstance() { SortedSet<LessonInstance> result = new TreeSet<LessonInstance>( LessonInstance.COMPARATOR_BY_BEGIN_DATE_TIME); result.addAll(getLessonInstancesSet()); return !result.isEmpty() ? result.last() : null; }