Example usage for java.util SortedSet last

List of usage examples for java.util SortedSet last

Introduction

In this page you can find the example usage for java.util SortedSet last.

Prototype

E last();

Source Link

Document

Returns the last (highest) element currently in this set.

Usage

From source file:cerrla.Performance.java

/**
 * Outputs performance information and estimates convergence.
 * //from   w w  w. jav a2  s  .  co  m
 * @param convergence
 *            The convergence as given by the rule distributions.
 * @param numElites
 *            The minimum number of elites.
 * @param elites
 *            The current elites.
 * @param numSlots
 *            The number of slots in the distribution.
 * @param goalCondition
 *            The goal condition this performance is concerned with.
 */
public void estimateETA(double convergence, int numElites, SortedSet<PolicyValue> elites, int numSlots,
        GoalCondition goalCondition) {
    if (!ProgramArgument.SYSTEM_OUTPUT.booleanValue())
        return;

    boolean mainGoal = goalCondition.isMainGoal();

    if (mainGoal) {
        long currentTime = System.currentTimeMillis();
        long elapsedTime = currentTime - trainingStartTime_;
        String elapsed = "Elapsed: " + RRLExperiment.toTimeFormat(elapsedTime);
        System.out.println(elapsed);
    }

    boolean noUpdates = false;
    if (convergence == PolicyGenerator.NO_UPDATES_CONVERGENCE) {
        noUpdates = true;
        convergence = 0;
    }
    double totalRunComplete = (1.0 * runIndex_ + convergence) / Config.getInstance().getNumRepetitions();
    if (frozen_)
        totalRunComplete = 1.0 * (runIndex_ + 1) / Config.getInstance().getNumRepetitions();

    DecimalFormat formatter = new DecimalFormat("#0.0000");
    String modular = "";
    if (!goalCondition.isMainGoal())
        modular = "MODULAR: [" + goalCondition + "] ";
    // No updates yet, convergence unknown
    String percentStr = null;
    if (noUpdates) {
        percentStr = "Unknown convergence; No updates yet.";
    } else if (!frozen_) {
        percentStr = "~" + formatter.format(100 * convergence) + "% " + modular + "converged (" + numSlots
                + " slots).";
    } else {
        if (convergence <= 1)
            percentStr = formatter.format(100 * convergence) + "% " + modular + "test complete.";
        else
            percentStr = "---FULLY CONVERGED---";
    }
    System.out.println(percentStr);

    if (!frozen_) {
        // Adjust numElites if using bounded elites
        String best = (!elites.isEmpty()) ? "" + formatter.format(elites.first().getValue()) : "?";
        String worst = (!elites.isEmpty()) ? "" + formatter.format(elites.last().getValue()) : "?";
        String eliteString = "N_E: " + numElites + ", |E|: " + elites.size() + ", E_best: " + best
                + ", E_worst: " + worst;
        System.out.println(eliteString);
    }

    if (mainGoal) {
        String totalPercentStr = formatter.format(100 * totalRunComplete) + "% experiment complete.";
        System.out.println(totalPercentStr);
    }
}

From source file:org.apache.atlas.hive.hook.HiveHookIT.java

@Test
public void testInsertIntoTable() throws Exception {
    String inputTable1Name = createTable();
    String inputTable2Name = createTable();
    String insertTableName = createTable();
    assertTableIsRegistered(DEFAULT_DB, inputTable1Name);
    assertTableIsRegistered(DEFAULT_DB, insertTableName);

    String query = "insert into " + insertTableName + " select t1.id, t1.name from " + inputTable2Name
            + " as t2, " + inputTable1Name + " as t1 where t1.id=t2.id";

    runCommand(query);//from  w  ww  . java  2  s.com
    final Set<ReadEntity> inputs = getInputs(inputTable1Name, Entity.Type.TABLE);
    inputs.addAll(getInputs(inputTable2Name, Entity.Type.TABLE));

    Set<WriteEntity> outputs = getOutputs(insertTableName, Entity.Type.TABLE);
    (outputs.iterator().next()).setWriteType(WriteEntity.WriteType.INSERT);

    HiveHook.HiveEventContext event = constructEvent(query, HiveOperation.QUERY, inputs, outputs);

    Set<ReadEntity> expectedInputs = new TreeSet<ReadEntity>(entityComparator) {
        {
            addAll(inputs);
        }
    };
    assertTableIsRegistered(DEFAULT_DB, insertTableName);
    Referenceable processRef1 = validateProcess(event, expectedInputs, outputs);

    //Test sorting of tbl names
    SortedSet<String> sortedTblNames = new TreeSet<>();
    sortedTblNames.add(inputTable1Name.toLowerCase());
    sortedTblNames.add(inputTable2Name.toLowerCase());

    //Verify sorted order of inputs in qualified name
    Assert.assertEquals(processRef1.get(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME),

            Joiner.on(SEP).join("QUERY", getQualifiedTblName(sortedTblNames.first()),
                    HiveMetaStoreBridge.getTableCreatedTime(
                            hiveMetaStoreBridge.hiveClient.getTable(DEFAULT_DB, sortedTblNames.first()))
                            .getTime(),
                    getQualifiedTblName(sortedTblNames.last()),
                    HiveMetaStoreBridge
                            .getTableCreatedTime(
                                    hiveMetaStoreBridge.hiveClient.getTable(DEFAULT_DB, sortedTblNames.last()))
                            .getTime())
                    + IO_SEP + SEP
                    + Joiner.on(SEP).join(WriteEntity.WriteType.INSERT.name(),
                            getQualifiedTblName(insertTableName),
                            HiveMetaStoreBridge.getTableCreatedTime(
                                    hiveMetaStoreBridge.hiveClient.getTable(DEFAULT_DB, insertTableName))
                                    .getTime()));

    //Rerun same query. Should result in same process
    runCommandWithDelay(query, 1000);
    Referenceable processRef2 = validateProcess(event, expectedInputs, outputs);
    Assert.assertEquals(processRef1.getId()._getId(), processRef2.getId()._getId());

}

From source file:net.sf.jasperreports.engine.export.HtmlExporter.java

protected void exportTable(TableVisitor tableVisitor, Table table, boolean whiteBackground,
        boolean isMainReportTable) throws IOException {
    SortedSet<Column> columns = table.getColumns().getUserEntries();
    SortedSet<Row> rows = table.getRows().getUserEntries();
    if (columns.isEmpty() || rows.isEmpty()) {
        // TODO lucianc empty page
        return;//from   w  w  w . java  2  s .co  m
    }

    if (isMainReportTable) {
        int totalWidth = columns.last().getEndCoord() - columns.first().getStartCoord();
        writer.write(
                "<table class=\"jrPage\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"empty-cells: show; width: ");
        writer.write(toSizeUnit(totalWidth));
        writer.write(";");
    } else {
        writer.write(
                "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"empty-cells: show; width: 100%;");
    }

    HtmlBorderCollapseEnum borderCollapse = getCurrentItemConfiguration().getBorderCollapseValue();
    if (borderCollapse != null) {
        writer.write(" border-collapse: ");
        writer.write(borderCollapse.getName());
        writer.write(";");
    }

    if (whiteBackground) {
        writer.write(" background-color: white;");
    }
    writer.write("\">\n");

    // TODO lucianc check whether we can use the first row for setting col widths
    writer.write("<tr valign=\"top\" style=\"height:0\">\n");
    for (Column col : columns) {
        writer.write("<td style=\"width:");
        writer.write(toSizeUnit(col.getExtent()));
        writer.write("\"></td>\n");
    }
    writer.write("</tr>\n");

    for (Row row : rows) {
        writer.write("<tr valign=\"top\" style=\"height:");
        writer.write(toSizeUnit(row.getExtent()));
        writer.write("\">\n");

        int emptySpan = 0;
        for (Column col : columns) {
            Cell cell = row.getCell(col);
            if (cell == null) {
                ++emptySpan;
            } else {
                if (emptySpan > 0) {
                    writeEmptyCell(emptySpan, 1);
                }
                emptySpan = 0;

                TablePosition position = new TablePosition(table, col, row);
                cell.accept(tableVisitor, position);
            }
        }
        if (emptySpan > 0) {
            writeEmptyCell(emptySpan, 1);
        }

        writer.write("</tr>\n");
    }

    writer.write("</table>\n");
}

From source file:com.projity.pm.task.Project.java

public int getRowHeight(SortedSet baseLines) {
    for (Iterator i = getTaskOutlineIterator(); i.hasNext();) {
        Task task = (Task) i.next();// w  ww. j  a v  a 2  s .  c o  m
        int current = Snapshottable.CURRENT.intValue();
        for (int s = 0; s < Settings.numGanttBaselines(); s++) {
            if (s == current)
                continue;
            TaskSnapshot snapshot = (TaskSnapshot) task.getSnapshot(new Integer(s));
            if (snapshot != null)
                baseLines.add(new Integer(s));
        }
    }
    int num = (baseLines.size() == 0) ? 0 : (((Integer) baseLines.last()).intValue() + 1);
    int rowHeight = GraphicConfiguration.getInstance().getRowHeight()
            + num * GraphicConfiguration.getInstance().getBaselineHeight();
    return rowHeight;
}

From source file:net.sourceforge.fenixedu.domain.StudentCurricularPlan.java

final public ExecutionYear getApprovedCurriculumLinesLastExecutionYear() {
    if (getRoot() != null) {
        return getRoot().getApprovedCurriculumLinesLastExecutionYear();
    } else {//from www  .  j av a  2  s  .  c o m
        final SortedSet<ExecutionYear> executionYears = new TreeSet<ExecutionYear>(
                ExecutionYear.COMPARATOR_BY_YEAR);

        for (final CurriculumLine curriculumLine : getAprovedEnrolments()) {
            if (curriculumLine.hasExecutionPeriod()) {
                executionYears.add(curriculumLine.getExecutionPeriod().getExecutionYear());
            }
        }

        return executionYears.isEmpty() ? ExecutionYear.readCurrentExecutionYear() : executionYears.last();
    }
}

From source file:net.sourceforge.fenixedu.domain.StudentCurricularPlan.java

final public CurriculumLine getLastApprovement() {
    final SortedSet<CurriculumLine> curriculumLines = new TreeSet<CurriculumLine>(
            CurriculumLine.COMPARATOR_BY_APPROVEMENT_DATE_AND_ID);

    if (getRoot() != null) {
        for (final CurriculumModule module : getRoot().getCurriculumModulesSet()) {
            if (!module.isNoCourseGroupCurriculumGroup()) {
                module.addApprovedCurriculumLines(curriculumLines);
            }//from   ww  w.  j  ava  2 s .c  om
        }
    } else {
        curriculumLines.addAll(getAprovedEnrolments());
    }

    return curriculumLines.isEmpty() ? null : curriculumLines.last();
}

From source file:com.gtwm.pb.model.manageSchema.DatabaseDefn.java

public ModuleInfo addModule(HttpServletRequest request, CompanyInfo company)
        throws ObjectNotFoundException, DisallowedException {
    if (company == null) {
        company = this.authManager.getCompanyForLoggedInUser(request);
    }//from  w w  w .j  a v  a  2 s .c  om
    // Make sure module name is unique
    String baseModuleName = "New Module";
    String moduleName = baseModuleName;
    SortedSet<ModuleInfo> modules = company.getModules();
    Set<String> existingModuleNames = new HashSet<String>();
    int indexNumber = 0;
    for (ModuleInfo existingModule : modules) {
        existingModuleNames.add(existingModule.getModuleName());
    }
    if (modules.size() > 0) {
        ModuleInfo lastModule = modules.last();
        indexNumber = lastModule.getIndexNumber() + 10;
    } else {
        indexNumber = 10;
    }
    int moduleCount = 0;
    while (existingModuleNames.contains(moduleName)) {
        moduleCount++;
        moduleName = baseModuleName + " " + String.valueOf(moduleCount);
    }
    ModuleInfo newModule = new Module(moduleName, "actions/go-home.png", indexNumber);
    newModule.setColour("blue");
    HibernateUtil.currentSession().save(newModule);
    HibernateUtil.activateObject(company);
    company.addModule(newModule);
    UsageLogger usageLogger = new UsageLogger(this.relationalDataSource);
    AppUserInfo user = this.authManager.getUserByUserName(request, request.getRemoteUser());
    usageLogger.logReportSchemaChange(user, null, AppAction.ADD_MODULE, newModule.getModuleName());
    UsageLogger.startLoggingThread(usageLogger);
    return newModule;
}

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 {/*  www  . j  a  va 2 s  .  c o  m*/
        return null;
    }
}

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 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  a v  a2  s . com

    if (internalEnrolmentExamDate == null) {
        return externalEnrolmentExamDate;
    }

    if (externalEnrolmentExamDate == null) {
        return internalEnrolmentExamDate;
    }

    return internalEnrolmentExamDate.compareTo(externalEnrolmentExamDate) > 1 ? internalEnrolmentExamDate
            : externalEnrolmentExamDate;

}