Example usage for java.util SortedMap put

List of usage examples for java.util SortedMap put

Introduction

In this page you can find the example usage for java.util SortedMap put.

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:edu.umd.cfar.lamp.viper.util.Range.java

/**
 * @see edu.umd.cfar.lamp.viper.util.IntervalIndexList#remove(java.lang.Comparable, java.lang.Comparable)
 *//*  w ww .  j  a  va 2s  .com*/
public boolean remove(Comparable start, Comparable end) {
    boolean someFound = false;
    SortedMap head = spans.headMap(start);
    if (!head.isEmpty()) {
        Comparable oldStart = (Comparable) head.lastKey();
        Comparable oldEnd = (Comparable) head.get(oldStart);
        if (oldEnd.compareTo(start) > 0) {
            // if there is a span that goes into the span to
            // be removed, replace it.
            head.put(oldStart, start);
            someFound = true;
            double toCheck = oldEnd.compareTo(end);
            if (toCheck > 0) {
                // if the span to be removed is a strict subset 
                // of some existing span, you also have
                // to add back the end.
                spans.put(end, oldEnd);
                return true;
            } else if (toCheck == 0) {
                return true;
            }
        }
    }
    SortedMap sub = spans.subMap(start, end);
    if (!sub.isEmpty()) {
        someFound = true;
        Comparable oldStart = (Comparable) sub.lastKey();
        Comparable oldEnd = (Comparable) sub.get(oldStart);
        if (oldEnd.compareTo(end) > 0) {
            // if there is a span that starts during the
            // span to removed that goes past the end,
            // have to add back the difference.
            spans.put(end, oldEnd);
        }
        sub.clear();
    }
    return someFound;
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccRam.CFAccRamTopDomainTable.java

public void updateTopDomain(CFAccAuthorization Authorization, CFAccTopDomainBuff Buff) {
    schema.getTableDomainBase().updateDomainBase(Authorization, Buff);
    CFAccDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey();
    pkey.setRequiredTenantId(Buff.getRequiredTenantId());
    pkey.setRequiredId(Buff.getRequiredId());
    CFAccTopDomainBuff existing = dictByPKey.get(pkey);
    if (existing == null) {
        throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateTopDomain",
                "Existing record not found", "TopDomain", pkey);
    }// w  w w.j a  va  2 s.c  o m
    CFAccTopDomainByTLDIdxKey existingKeyTLDIdx = schema.getFactoryTopDomain().newTLDIdxKey();
    existingKeyTLDIdx.setRequiredTenantId(existing.getRequiredTenantId());
    existingKeyTLDIdx.setRequiredTLDId(existing.getRequiredTLDId());

    CFAccTopDomainByTLDIdxKey newKeyTLDIdx = schema.getFactoryTopDomain().newTLDIdxKey();
    newKeyTLDIdx.setRequiredTenantId(Buff.getRequiredTenantId());
    newKeyTLDIdx.setRequiredTLDId(Buff.getRequiredTLDId());

    CFAccTopDomainByNameIdxKey existingKeyNameIdx = schema.getFactoryTopDomain().newNameIdxKey();
    existingKeyNameIdx.setRequiredTenantId(existing.getRequiredTenantId());
    existingKeyNameIdx.setRequiredTLDId(existing.getRequiredTLDId());
    existingKeyNameIdx.setRequiredName(existing.getRequiredName());

    CFAccTopDomainByNameIdxKey newKeyNameIdx = schema.getFactoryTopDomain().newNameIdxKey();
    newKeyNameIdx.setRequiredTenantId(Buff.getRequiredTenantId());
    newKeyNameIdx.setRequiredTLDId(Buff.getRequiredTLDId());
    newKeyNameIdx.setRequiredName(Buff.getRequiredName());

    // Check unique indexes

    if (!existingKeyNameIdx.equals(newKeyNameIdx)) {
        if (dictByNameIdx.containsKey(newKeyNameIdx)) {
            throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                    "updateTopDomain", "TopDomainNameIdx", newKeyNameIdx);
        }
    }

    // Validate foreign keys

    {
        boolean allNull = true;

        if (allNull) {
            if (null == schema.getTableDomainBase().readDerivedByIdIdx(Authorization,
                    Buff.getRequiredTenantId(), Buff.getRequiredId())) {
                throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                        "updateTopDomain", "Superclass", "SuperClass", "DomainBase", null);
            }
        }
    }

    {
        boolean allNull = true;

        if (allNull) {
            if (null == schema.getTableTld().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId(),
                    Buff.getRequiredTLDId())) {
                throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                        "updateTopDomain", "Container", "TLD", "Tld", null);
            }
        }
    }

    // Update is valid

    SortedMap<CFAccDomainBasePKey, CFAccTopDomainBuff> subdict;

    dictByPKey.remove(pkey);
    dictByPKey.put(pkey, Buff);

    subdict = dictByTLDIdx.get(existingKeyTLDIdx);
    if (subdict != null) {
        subdict.remove(pkey);
    }
    if (dictByTLDIdx.containsKey(newKeyTLDIdx)) {
        subdict = dictByTLDIdx.get(newKeyTLDIdx);
    } else {
        subdict = new TreeMap<CFAccDomainBasePKey, CFAccTopDomainBuff>();
        dictByTLDIdx.put(newKeyTLDIdx, subdict);
    }
    subdict.put(pkey, Buff);

    dictByNameIdx.remove(existingKeyNameIdx);
    dictByNameIdx.put(newKeyNameIdx, Buff);

}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstRam.CFAstRamTopDomainTable.java

public void updateTopDomain(CFAstAuthorization Authorization, CFAstTopDomainBuff Buff) {
    schema.getTableDomainBase().updateDomainBase(Authorization, Buff);
    CFAstDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey();
    pkey.setRequiredTenantId(Buff.getRequiredTenantId());
    pkey.setRequiredId(Buff.getRequiredId());
    CFAstTopDomainBuff existing = dictByPKey.get(pkey);
    if (existing == null) {
        throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateTopDomain",
                "Existing record not found", "TopDomain", pkey);
    }//from  w w w .j a  v a2  s.  co  m
    CFAstTopDomainByTLDIdxKey existingKeyTLDIdx = schema.getFactoryTopDomain().newTLDIdxKey();
    existingKeyTLDIdx.setRequiredTenantId(existing.getRequiredTenantId());
    existingKeyTLDIdx.setRequiredTLDId(existing.getRequiredTLDId());

    CFAstTopDomainByTLDIdxKey newKeyTLDIdx = schema.getFactoryTopDomain().newTLDIdxKey();
    newKeyTLDIdx.setRequiredTenantId(Buff.getRequiredTenantId());
    newKeyTLDIdx.setRequiredTLDId(Buff.getRequiredTLDId());

    CFAstTopDomainByNameIdxKey existingKeyNameIdx = schema.getFactoryTopDomain().newNameIdxKey();
    existingKeyNameIdx.setRequiredTenantId(existing.getRequiredTenantId());
    existingKeyNameIdx.setRequiredTLDId(existing.getRequiredTLDId());
    existingKeyNameIdx.setRequiredName(existing.getRequiredName());

    CFAstTopDomainByNameIdxKey newKeyNameIdx = schema.getFactoryTopDomain().newNameIdxKey();
    newKeyNameIdx.setRequiredTenantId(Buff.getRequiredTenantId());
    newKeyNameIdx.setRequiredTLDId(Buff.getRequiredTLDId());
    newKeyNameIdx.setRequiredName(Buff.getRequiredName());

    // Check unique indexes

    if (!existingKeyNameIdx.equals(newKeyNameIdx)) {
        if (dictByNameIdx.containsKey(newKeyNameIdx)) {
            throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                    "updateTopDomain", "TopDomainNameIdx", newKeyNameIdx);
        }
    }

    // Validate foreign keys

    {
        boolean allNull = true;

        if (allNull) {
            if (null == schema.getTableDomainBase().readDerivedByIdIdx(Authorization,
                    Buff.getRequiredTenantId(), Buff.getRequiredId())) {
                throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                        "updateTopDomain", "Superclass", "SuperClass", "DomainBase", null);
            }
        }
    }

    {
        boolean allNull = true;

        if (allNull) {
            if (null == schema.getTableTld().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId(),
                    Buff.getRequiredTLDId())) {
                throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                        "updateTopDomain", "Container", "TLD", "Tld", null);
            }
        }
    }

    // Update is valid

    SortedMap<CFAstDomainBasePKey, CFAstTopDomainBuff> subdict;

    dictByPKey.remove(pkey);
    dictByPKey.put(pkey, Buff);

    subdict = dictByTLDIdx.get(existingKeyTLDIdx);
    if (subdict != null) {
        subdict.remove(pkey);
    }
    if (dictByTLDIdx.containsKey(newKeyTLDIdx)) {
        subdict = dictByTLDIdx.get(newKeyTLDIdx);
    } else {
        subdict = new TreeMap<CFAstDomainBasePKey, CFAstTopDomainBuff>();
        dictByTLDIdx.put(newKeyTLDIdx, subdict);
    }
    subdict.put(pkey, Buff);

    dictByNameIdx.remove(existingKeyNameIdx);
    dictByNameIdx.put(newKeyNameIdx, Buff);

}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccRam.CFAccRamAddressTable.java

public void createAddress(CFAccAuthorization Authorization, CFAccAddressBuff Buff) {
    CFAccAddressPKey pkey = schema.getFactoryAddress().newPKey();
    pkey.setRequiredTenantId(Buff.getRequiredTenantId());
    pkey.setRequiredAddressId(((CFAccRamTenantTable) schema.getTableTenant()).nextAddressIdGen(Authorization,
            Buff.getRequiredTenantId()));
    Buff.setRequiredTenantId(pkey.getRequiredTenantId());
    Buff.setRequiredAddressId(pkey.getRequiredAddressId());
    CFAccAddressByTenantIdxKey keyTenantIdx = schema.getFactoryAddress().newTenantIdxKey();
    keyTenantIdx.setRequiredTenantId(Buff.getRequiredTenantId());

    CFAccAddressByContactIdxKey keyContactIdx = schema.getFactoryAddress().newContactIdxKey();
    keyContactIdx.setRequiredTenantId(Buff.getRequiredTenantId());
    keyContactIdx.setRequiredContactId(Buff.getRequiredContactId());

    CFAccAddressByUDescrIdxKey keyUDescrIdx = schema.getFactoryAddress().newUDescrIdxKey();
    keyUDescrIdx.setRequiredTenantId(Buff.getRequiredTenantId());
    keyUDescrIdx.setRequiredContactId(Buff.getRequiredContactId());
    keyUDescrIdx.setRequiredDescription(Buff.getRequiredDescription());

    CFAccAddressByCountryIdxKey keyCountryIdx = schema.getFactoryAddress().newCountryIdxKey();
    keyCountryIdx.setOptionalCountryId(Buff.getOptionalCountryId());

    // Validate unique indexes

    if (dictByPKey.containsKey(pkey)) {
        throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createAddress",
                pkey);//  w  w  w  .  java  2s  .c om
    }

    if (dictByUDescrIdx.containsKey(keyUDescrIdx)) {
        throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "createAddress",
                "AddressUDescrIdx", keyUDescrIdx);
    }

    // Validate foreign keys

    {
        boolean allNull = true;
        allNull = false;
        if (!allNull) {
            if (null == schema.getTableTenant().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId())) {
                throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                        "createAddress", "Owner", "AddressTenant", "Tenant", null);
            }
        }
    }

    {
        boolean allNull = true;
        allNull = false;
        allNull = false;
        if (!allNull) {
            if (null == schema.getTableContact().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId(),
                    Buff.getRequiredContactId())) {
                throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                        "createAddress", "Container", "AddressContact", "Contact", null);
            }
        }
    }

    // Proceed with adding the new record

    dictByPKey.put(pkey, Buff);

    SortedMap<CFAccAddressPKey, CFAccAddressBuff> subdictTenantIdx;
    if (dictByTenantIdx.containsKey(keyTenantIdx)) {
        subdictTenantIdx = dictByTenantIdx.get(keyTenantIdx);
    } else {
        subdictTenantIdx = new TreeMap<CFAccAddressPKey, CFAccAddressBuff>();
        dictByTenantIdx.put(keyTenantIdx, subdictTenantIdx);
    }
    subdictTenantIdx.put(pkey, Buff);

    SortedMap<CFAccAddressPKey, CFAccAddressBuff> subdictContactIdx;
    if (dictByContactIdx.containsKey(keyContactIdx)) {
        subdictContactIdx = dictByContactIdx.get(keyContactIdx);
    } else {
        subdictContactIdx = new TreeMap<CFAccAddressPKey, CFAccAddressBuff>();
        dictByContactIdx.put(keyContactIdx, subdictContactIdx);
    }
    subdictContactIdx.put(pkey, Buff);

    dictByUDescrIdx.put(keyUDescrIdx, Buff);

    SortedMap<CFAccAddressPKey, CFAccAddressBuff> subdictCountryIdx;
    if (dictByCountryIdx.containsKey(keyCountryIdx)) {
        subdictCountryIdx = dictByCountryIdx.get(keyCountryIdx);
    } else {
        subdictCountryIdx = new TreeMap<CFAccAddressPKey, CFAccAddressBuff>();
        dictByCountryIdx.put(keyCountryIdx, subdictCountryIdx);
    }
    subdictCountryIdx.put(pkey, Buff);

}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccRam.CFAccRamISOTimezoneTable.java

public void updateISOTimezone(CFAccAuthorization Authorization, CFAccISOTimezoneBuff Buff) {
    CFAccISOTimezonePKey pkey = schema.getFactoryISOTimezone().newPKey();
    pkey.setRequiredISOTimezoneId(Buff.getRequiredISOTimezoneId());
    CFAccISOTimezoneBuff existing = dictByPKey.get(pkey);
    if (existing == null) {
        throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateISOTimezone",
                "Existing record not found", "ISOTimezone", pkey);
    }// w  ww  .j a v a 2  s.co  m
    if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
        throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "updateISOTimezone",
                pkey);
    }
    Buff.setRequiredRevision(Buff.getRequiredRevision() + 1);
    CFAccISOTimezoneByOffsetIdxKey existingKeyOffsetIdx = schema.getFactoryISOTimezone().newOffsetIdxKey();
    existingKeyOffsetIdx.setRequiredTZHourOffset(existing.getRequiredTZHourOffset());
    existingKeyOffsetIdx.setRequiredTZMinOffset(existing.getRequiredTZMinOffset());

    CFAccISOTimezoneByOffsetIdxKey newKeyOffsetIdx = schema.getFactoryISOTimezone().newOffsetIdxKey();
    newKeyOffsetIdx.setRequiredTZHourOffset(Buff.getRequiredTZHourOffset());
    newKeyOffsetIdx.setRequiredTZMinOffset(Buff.getRequiredTZMinOffset());

    CFAccISOTimezoneByUTZNameIdxKey existingKeyUTZNameIdx = schema.getFactoryISOTimezone().newUTZNameIdxKey();
    existingKeyUTZNameIdx.setRequiredTZName(existing.getRequiredTZName());

    CFAccISOTimezoneByUTZNameIdxKey newKeyUTZNameIdx = schema.getFactoryISOTimezone().newUTZNameIdxKey();
    newKeyUTZNameIdx.setRequiredTZName(Buff.getRequiredTZName());

    CFAccISOTimezoneByIso8601IdxKey existingKeyIso8601Idx = schema.getFactoryISOTimezone().newIso8601IdxKey();
    existingKeyIso8601Idx.setRequiredIso8601(existing.getRequiredIso8601());

    CFAccISOTimezoneByIso8601IdxKey newKeyIso8601Idx = schema.getFactoryISOTimezone().newIso8601IdxKey();
    newKeyIso8601Idx.setRequiredIso8601(Buff.getRequiredIso8601());

    // Check unique indexes

    if (!existingKeyUTZNameIdx.equals(newKeyUTZNameIdx)) {
        if (dictByUTZNameIdx.containsKey(newKeyUTZNameIdx)) {
            throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                    "updateISOTimezone", "ISOTimezoneUTZNameIdx", newKeyUTZNameIdx);
        }
    }

    // Validate foreign keys

    // Update is valid

    SortedMap<CFAccISOTimezonePKey, CFAccISOTimezoneBuff> subdict;

    dictByPKey.remove(pkey);
    dictByPKey.put(pkey, Buff);

    subdict = dictByOffsetIdx.get(existingKeyOffsetIdx);
    if (subdict != null) {
        subdict.remove(pkey);
    }
    if (dictByOffsetIdx.containsKey(newKeyOffsetIdx)) {
        subdict = dictByOffsetIdx.get(newKeyOffsetIdx);
    } else {
        subdict = new TreeMap<CFAccISOTimezonePKey, CFAccISOTimezoneBuff>();
        dictByOffsetIdx.put(newKeyOffsetIdx, subdict);
    }
    subdict.put(pkey, Buff);

    dictByUTZNameIdx.remove(existingKeyUTZNameIdx);
    dictByUTZNameIdx.put(newKeyUTZNameIdx, Buff);

    subdict = dictByIso8601Idx.get(existingKeyIso8601Idx);
    if (subdict != null) {
        subdict.remove(pkey);
    }
    if (dictByIso8601Idx.containsKey(newKeyIso8601Idx)) {
        subdict = dictByIso8601Idx.get(newKeyIso8601Idx);
    } else {
        subdict = new TreeMap<CFAccISOTimezonePKey, CFAccISOTimezoneBuff>();
        dictByIso8601Idx.put(newKeyIso8601Idx, subdict);
    }
    subdict.put(pkey, Buff);

}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstRam.CFAstRamISOTimezoneTable.java

public void updateISOTimezone(CFAstAuthorization Authorization, CFAstISOTimezoneBuff Buff) {
    CFAstISOTimezonePKey pkey = schema.getFactoryISOTimezone().newPKey();
    pkey.setRequiredISOTimezoneId(Buff.getRequiredISOTimezoneId());
    CFAstISOTimezoneBuff existing = dictByPKey.get(pkey);
    if (existing == null) {
        throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateISOTimezone",
                "Existing record not found", "ISOTimezone", pkey);
    }/*from  w w w  .jav  a 2s . c o m*/
    if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
        throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "updateISOTimezone",
                pkey);
    }
    Buff.setRequiredRevision(Buff.getRequiredRevision() + 1);
    CFAstISOTimezoneByOffsetIdxKey existingKeyOffsetIdx = schema.getFactoryISOTimezone().newOffsetIdxKey();
    existingKeyOffsetIdx.setRequiredTZHourOffset(existing.getRequiredTZHourOffset());
    existingKeyOffsetIdx.setRequiredTZMinOffset(existing.getRequiredTZMinOffset());

    CFAstISOTimezoneByOffsetIdxKey newKeyOffsetIdx = schema.getFactoryISOTimezone().newOffsetIdxKey();
    newKeyOffsetIdx.setRequiredTZHourOffset(Buff.getRequiredTZHourOffset());
    newKeyOffsetIdx.setRequiredTZMinOffset(Buff.getRequiredTZMinOffset());

    CFAstISOTimezoneByUTZNameIdxKey existingKeyUTZNameIdx = schema.getFactoryISOTimezone().newUTZNameIdxKey();
    existingKeyUTZNameIdx.setRequiredTZName(existing.getRequiredTZName());

    CFAstISOTimezoneByUTZNameIdxKey newKeyUTZNameIdx = schema.getFactoryISOTimezone().newUTZNameIdxKey();
    newKeyUTZNameIdx.setRequiredTZName(Buff.getRequiredTZName());

    CFAstISOTimezoneByIso8601IdxKey existingKeyIso8601Idx = schema.getFactoryISOTimezone().newIso8601IdxKey();
    existingKeyIso8601Idx.setRequiredIso8601(existing.getRequiredIso8601());

    CFAstISOTimezoneByIso8601IdxKey newKeyIso8601Idx = schema.getFactoryISOTimezone().newIso8601IdxKey();
    newKeyIso8601Idx.setRequiredIso8601(Buff.getRequiredIso8601());

    // Check unique indexes

    if (!existingKeyUTZNameIdx.equals(newKeyUTZNameIdx)) {
        if (dictByUTZNameIdx.containsKey(newKeyUTZNameIdx)) {
            throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                    "updateISOTimezone", "ISOTimezoneUTZNameIdx", newKeyUTZNameIdx);
        }
    }

    // Validate foreign keys

    // Update is valid

    SortedMap<CFAstISOTimezonePKey, CFAstISOTimezoneBuff> subdict;

    dictByPKey.remove(pkey);
    dictByPKey.put(pkey, Buff);

    subdict = dictByOffsetIdx.get(existingKeyOffsetIdx);
    if (subdict != null) {
        subdict.remove(pkey);
    }
    if (dictByOffsetIdx.containsKey(newKeyOffsetIdx)) {
        subdict = dictByOffsetIdx.get(newKeyOffsetIdx);
    } else {
        subdict = new TreeMap<CFAstISOTimezonePKey, CFAstISOTimezoneBuff>();
        dictByOffsetIdx.put(newKeyOffsetIdx, subdict);
    }
    subdict.put(pkey, Buff);

    dictByUTZNameIdx.remove(existingKeyUTZNameIdx);
    dictByUTZNameIdx.put(newKeyUTZNameIdx, Buff);

    subdict = dictByIso8601Idx.get(existingKeyIso8601Idx);
    if (subdict != null) {
        subdict.remove(pkey);
    }
    if (dictByIso8601Idx.containsKey(newKeyIso8601Idx)) {
        subdict = dictByIso8601Idx.get(newKeyIso8601Idx);
    } else {
        subdict = new TreeMap<CFAstISOTimezonePKey, CFAstISOTimezoneBuff>();
        dictByIso8601Idx.put(newKeyIso8601Idx, subdict);
    }
    subdict.put(pkey, Buff);

}

From source file:net.sourceforge.fenixedu.presentationTier.Action.scientificCouncil.credits.ViewTeacherCreditsReportDispatchAction.java

private SortedMap<Department, Map<ExecutionYear, PeriodCreditsReportDTO>> getGlobalDepartmentCreditsMap(
        HttpServletRequest request, User userView, String fromExecutionYearID, String untilExecutionYearID,
        String departmentID) throws ParseException, InvalidPeriodException, FenixServiceException {

    request.setAttribute("fromExecutionYearID", fromExecutionYearID);
    request.setAttribute("untilExecutionYearID", untilExecutionYearID);

    ExecutionYear fromExecutionYear = FenixFramework.getDomainObject(fromExecutionYearID);
    ExecutionYear untilExecutionYear = FenixFramework.getDomainObject(untilExecutionYearID);

    ExecutionSemester fromExecutionPeriod = null;
    if (fromExecutionYear.getPreviousExecutionYear()
            .equals(ExecutionSemester.readStartExecutionSemesterForCredits().getExecutionYear())) {
        fromExecutionPeriod = ExecutionSemester.readStartExecutionSemesterForCredits();
    } else {//  ww w  . jav a2 s.  c  o m
        fromExecutionPeriod = fromExecutionYear.getPreviousExecutionYear().getExecutionSemesterFor(1);
    }

    ExecutionSemester untilExecutionPeriod = untilExecutionYear.getExecutionSemesterFor(2);

    if (!validExecutionPeriodsChoice(fromExecutionPeriod, untilExecutionPeriod)) {
        throw new InvalidPeriodException();
    }

    Map<ExecutionYear, PeriodCreditsReportDTO> departmentPeriodTotalCredits = new HashMap<ExecutionYear, PeriodCreditsReportDTO>();
    SortedMap<Department, Map<ExecutionYear, PeriodCreditsReportDTO>> departmentTotalCredits = new TreeMap<Department, Map<ExecutionYear, PeriodCreditsReportDTO>>(
            new BeanComparator("code"));

    if (departmentID == null) {
        Collection<Department> departments = rootDomainObject.getDepartmentsSet();
        for (Department department : departments) {
            Unit unit = department.getDepartmentUnit();
            departmentPeriodTotalCredits = ReadDepartmentTotalCreditsByPeriod.run(unit, fromExecutionPeriod,
                    untilExecutionPeriod);
            departmentTotalCredits.put(department, departmentPeriodTotalCredits);
        }
        request.setAttribute("departmentID", null);
    } else {
        Department department = FenixFramework.getDomainObject(departmentID);
        Unit departmentUnit = department.getDepartmentUnit();
        departmentPeriodTotalCredits = ReadDepartmentTotalCreditsByPeriod.run(departmentUnit,
                fromExecutionPeriod, untilExecutionPeriod);

        departmentTotalCredits.put(department, departmentPeriodTotalCredits);
        request.setAttribute("department", department);
        request.setAttribute("departmentID", department.getExternalId());
    }

    setTotals(request, untilExecutionYear, departmentTotalCredits);
    request.setAttribute("departmentTotalCredits", departmentTotalCredits);
    return departmentTotalCredits;
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccRam.CFAccRamISOCountryCurrencyTable.java

public void updateISOCountryCurrency(CFAccAuthorization Authorization, CFAccISOCountryCurrencyBuff Buff) {
    CFAccISOCountryCurrencyPKey pkey = schema.getFactoryISOCountryCurrency().newPKey();
    pkey.setRequiredISOCountryId(Buff.getRequiredISOCountryId());
    pkey.setRequiredISOCurrencyId(Buff.getRequiredISOCurrencyId());
    CFAccISOCountryCurrencyBuff existing = dictByPKey.get(pkey);
    if (existing == null) {
        throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(),
                "updateISOCountryCurrency", "Existing record not found", "ISOCountryCurrency", pkey);
    }//from ww  w.  j  ava2s. c om
    if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
        throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(),
                "updateISOCountryCurrency", pkey);
    }
    Buff.setRequiredRevision(Buff.getRequiredRevision() + 1);
    CFAccISOCountryCurrencyByCountryIdxKey existingKeyCountryIdx = schema.getFactoryISOCountryCurrency()
            .newCountryIdxKey();
    existingKeyCountryIdx.setRequiredISOCountryId(existing.getRequiredISOCountryId());

    CFAccISOCountryCurrencyByCountryIdxKey newKeyCountryIdx = schema.getFactoryISOCountryCurrency()
            .newCountryIdxKey();
    newKeyCountryIdx.setRequiredISOCountryId(Buff.getRequiredISOCountryId());

    CFAccISOCountryCurrencyByCurrencyIdxKey existingKeyCurrencyIdx = schema.getFactoryISOCountryCurrency()
            .newCurrencyIdxKey();
    existingKeyCurrencyIdx.setRequiredISOCurrencyId(existing.getRequiredISOCurrencyId());

    CFAccISOCountryCurrencyByCurrencyIdxKey newKeyCurrencyIdx = schema.getFactoryISOCountryCurrency()
            .newCurrencyIdxKey();
    newKeyCurrencyIdx.setRequiredISOCurrencyId(Buff.getRequiredISOCurrencyId());

    // Check unique indexes

    // Validate foreign keys

    {
        boolean allNull = true;

        if (allNull) {
            if (null == schema.getTableISOCountry().readDerivedByIdIdx(Authorization,
                    Buff.getRequiredISOCountryId())) {
                throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                        "updateISOCountryCurrency", "Container", "ISOCountryCurrencyCountry", "ISOCountry",
                        null);
            }
        }
    }

    // Update is valid

    SortedMap<CFAccISOCountryCurrencyPKey, CFAccISOCountryCurrencyBuff> subdict;

    dictByPKey.remove(pkey);
    dictByPKey.put(pkey, Buff);

    subdict = dictByCountryIdx.get(existingKeyCountryIdx);
    if (subdict != null) {
        subdict.remove(pkey);
    }
    if (dictByCountryIdx.containsKey(newKeyCountryIdx)) {
        subdict = dictByCountryIdx.get(newKeyCountryIdx);
    } else {
        subdict = new TreeMap<CFAccISOCountryCurrencyPKey, CFAccISOCountryCurrencyBuff>();
        dictByCountryIdx.put(newKeyCountryIdx, subdict);
    }
    subdict.put(pkey, Buff);

    subdict = dictByCurrencyIdx.get(existingKeyCurrencyIdx);
    if (subdict != null) {
        subdict.remove(pkey);
    }
    if (dictByCurrencyIdx.containsKey(newKeyCurrencyIdx)) {
        subdict = dictByCurrencyIdx.get(newKeyCurrencyIdx);
    } else {
        subdict = new TreeMap<CFAccISOCountryCurrencyPKey, CFAccISOCountryCurrencyBuff>();
        dictByCurrencyIdx.put(newKeyCurrencyIdx, subdict);
    }
    subdict.put(pkey, Buff);

}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccRam.CFAccRamISOCountryLanguageTable.java

public void updateISOCountryLanguage(CFAccAuthorization Authorization, CFAccISOCountryLanguageBuff Buff) {
    CFAccISOCountryLanguagePKey pkey = schema.getFactoryISOCountryLanguage().newPKey();
    pkey.setRequiredISOCountryId(Buff.getRequiredISOCountryId());
    pkey.setRequiredISOLanguageId(Buff.getRequiredISOLanguageId());
    CFAccISOCountryLanguageBuff existing = dictByPKey.get(pkey);
    if (existing == null) {
        throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(),
                "updateISOCountryLanguage", "Existing record not found", "ISOCountryLanguage", pkey);
    }//w  w  w  . j a  v  a2s. c  om
    if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
        throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(),
                "updateISOCountryLanguage", pkey);
    }
    Buff.setRequiredRevision(Buff.getRequiredRevision() + 1);
    CFAccISOCountryLanguageByCountryIdxKey existingKeyCountryIdx = schema.getFactoryISOCountryLanguage()
            .newCountryIdxKey();
    existingKeyCountryIdx.setRequiredISOCountryId(existing.getRequiredISOCountryId());

    CFAccISOCountryLanguageByCountryIdxKey newKeyCountryIdx = schema.getFactoryISOCountryLanguage()
            .newCountryIdxKey();
    newKeyCountryIdx.setRequiredISOCountryId(Buff.getRequiredISOCountryId());

    CFAccISOCountryLanguageByLanguageIdxKey existingKeyLanguageIdx = schema.getFactoryISOCountryLanguage()
            .newLanguageIdxKey();
    existingKeyLanguageIdx.setRequiredISOLanguageId(existing.getRequiredISOLanguageId());

    CFAccISOCountryLanguageByLanguageIdxKey newKeyLanguageIdx = schema.getFactoryISOCountryLanguage()
            .newLanguageIdxKey();
    newKeyLanguageIdx.setRequiredISOLanguageId(Buff.getRequiredISOLanguageId());

    // Check unique indexes

    // Validate foreign keys

    {
        boolean allNull = true;

        if (allNull) {
            if (null == schema.getTableISOCountry().readDerivedByIdIdx(Authorization,
                    Buff.getRequiredISOCountryId())) {
                throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                        "updateISOCountryLanguage", "Container", "ISOCountryLanguageCountry", "ISOCountry",
                        null);
            }
        }
    }

    // Update is valid

    SortedMap<CFAccISOCountryLanguagePKey, CFAccISOCountryLanguageBuff> subdict;

    dictByPKey.remove(pkey);
    dictByPKey.put(pkey, Buff);

    subdict = dictByCountryIdx.get(existingKeyCountryIdx);
    if (subdict != null) {
        subdict.remove(pkey);
    }
    if (dictByCountryIdx.containsKey(newKeyCountryIdx)) {
        subdict = dictByCountryIdx.get(newKeyCountryIdx);
    } else {
        subdict = new TreeMap<CFAccISOCountryLanguagePKey, CFAccISOCountryLanguageBuff>();
        dictByCountryIdx.put(newKeyCountryIdx, subdict);
    }
    subdict.put(pkey, Buff);

    subdict = dictByLanguageIdx.get(existingKeyLanguageIdx);
    if (subdict != null) {
        subdict.remove(pkey);
    }
    if (dictByLanguageIdx.containsKey(newKeyLanguageIdx)) {
        subdict = dictByLanguageIdx.get(newKeyLanguageIdx);
    } else {
        subdict = new TreeMap<CFAccISOCountryLanguagePKey, CFAccISOCountryLanguageBuff>();
        dictByLanguageIdx.put(newKeyLanguageIdx, subdict);
    }
    subdict.put(pkey, Buff);

}