Example usage for java.util HashSet isEmpty

List of usage examples for java.util HashSet isEmpty

Introduction

In this page you can find the example usage for java.util HashSet isEmpty.

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if this set contains no elements.

Usage

From source file:org.eclipse.ecr.core.storage.sql.SessionImpl.java

/**
 * Send a core event about the merged invalidations (NXP-5808)
 *
 * @param pair/*w w  w  .j av a 2 s.c  om*/
 */
protected void sendInvalidationEvent(InvalidationsPair pair) {
    if (!repository.repositoryDescriptor.sendInvalidationEvents) {
        return;
    }
    // compute modified doc ids and parent ids
    HashSet<String> modifiedDocIds = new HashSet<String>();
    HashSet<String> modifiedParentIds = new HashSet<String>();

    // merge cache and events because of clustering (NXP-5808)
    collectModified(pair.cacheInvalidations, modifiedDocIds, modifiedParentIds);
    collectModified(pair.eventInvalidations, modifiedDocIds, modifiedParentIds);

    // TODO check what we can do about invalidations.deleted

    if (modifiedDocIds.isEmpty() && modifiedParentIds.isEmpty()) {
        return;
    }

    EventContext ctx = new EventContextImpl(null, null);
    ctx.setRepositoryName(repository.getName());
    ctx.setProperty(EventConstants.INVAL_MODIFIED_DOC_IDS, modifiedDocIds);
    ctx.setProperty(EventConstants.INVAL_MODIFIED_PARENT_IDS, modifiedParentIds);
    Event event = new EventImpl(EventConstants.EVENT_VCS_INVALIDATIONS, ctx);
    try {
        repository.eventService.fireEvent(event);
    } catch (ClientException e) {
        log.error("Failed to send invalidation event: " + e, e);
    }
}

From source file:cz.cas.lib.proarc.webapp.server.rest.DigitalObjectResource.java

/**
 * Deletes object members from digital object.
 * @param parentPid digital object ID/*from   ww  w . j  a v  a  2s.c o  m*/
 * @param toRemovePids member IDs to remove
 * @param batchId optional batch import ID
 * @return list of removed IDs
 */
@DELETE
@Path(DigitalObjectResourceApi.MEMBERS_PATH)
@Produces({ MediaType.APPLICATION_JSON })
public SmartGwtResponse<Item> deleteMembers(
        @QueryParam(DigitalObjectResourceApi.MEMBERS_ITEM_PARENT) String parentPid,
        @QueryParam(DigitalObjectResourceApi.MEMBERS_ITEM_PID) List<String> toRemovePids,
        @QueryParam(DigitalObjectResourceApi.MEMBERS_ITEM_BATCHID) Integer batchId)
        throws IOException, DigitalObjectException {

    if (parentPid == null) {
        throw RestException.plainText(Status.BAD_REQUEST, "Missing parent parameter!");
    }
    if (toRemovePids == null || toRemovePids.isEmpty()) {
        throw RestException.plainText(Status.BAD_REQUEST, "Missing pid parameter!");
    }
    if (toRemovePids.contains(parentPid)) {
        throw RestException.plainText(Status.BAD_REQUEST, "parent and pid are same!");
    }

    HashSet<String> toRemovePidSet = new HashSet<String>(toRemovePids);
    if (toRemovePidSet.isEmpty()) {
        return new SmartGwtResponse<Item>(Collections.<Item>emptyList());
    }

    DigitalObjectHandler parent = findHandler(parentPid, batchId, false);
    deleteMembers(parent, toRemovePidSet);
    parent.commit();

    ArrayList<Item> removed = new ArrayList<Item>(toRemovePidSet.size());
    for (String removePid : toRemovePidSet) {
        Item item = new Item(removePid);
        item.setParentPid(parentPid);
        removed.add(item);
    }

    return new SmartGwtResponse<Item>(removed);
}

From source file:edu.fullerton.timeseriesapp.TimeSeriesApp.java

private HashSet<Integer> getSelections() throws SQLException, LdvTableException, ViewConfigException {
    HashSet<Integer> ret = new HashSet<>();
    long strt = System.currentTimeMillis();
    getDbTables();//from   w  w  w  .ja v a  2  s . c  o  m

    {
        int n;
        if (channelNames == null || channelNames.length == 0) {
            throw new IllegalArgumentException("No Channel specified");
        }
        if ((server == null || server.isEmpty()) && (cType == null || cType.isEmpty())) {
            for (String channelName : channelNames) {
                n = chanTbl.getBestMatch(channelName);
                ret.add(n);
            }
        } else {
            if (cType == null || cType.isEmpty()) {
                cType = "raw";
            }
            for (String channelName : channelNames) {
                TreeSet<ChanInfo> chSet = chanTbl.getAsSet(server, channelName, cType, 10);
                if (chSet.size() > 1) {
                    System.err.println("Warning: more than one channel matches: " + channelName);
                }

                for (ChanInfo ci : chSet) {
                    Integer id = ci.getId();
                    ret.add(id);
                }
            }
        }
        if (ret.isEmpty()) {
            for (String channelName : channelNames) {
                System.err.println("Channel requested was not found: " + channelName);
            }
        }
    }
    return ret;

}

From source file:cz.cas.lib.proarc.webapp.server.rest.DigitalObjectResource.java

/**
 * Moves members from a source object to a destination object.
 * @param srcParentPid PID of source/* w w  w.  ja va  2 s. co m*/
 * @param dstParentPid PID of destination
 * @param batchId optional batch import ID
 * @param movePids member PIDs to move
 * @return the list of updated members
 */
@PUT
@Path(DigitalObjectResourceApi.MEMBERS_PATH + '/' + DigitalObjectResourceApi.MEMBERS_MOVE_PATH)
@Consumes({ MediaType.APPLICATION_FORM_URLENCODED })
@Produces({ MediaType.APPLICATION_JSON })
public SmartGwtResponse<Item> moveMembers(
        @FormParam(DigitalObjectResourceApi.MEMBERS_MOVE_SRCPID) String srcParentPid,
        @FormParam(DigitalObjectResourceApi.MEMBERS_MOVE_DSTPID) String dstParentPid,
        @FormParam(DigitalObjectResourceApi.MEMBERS_ITEM_BATCHID) Integer batchId,
        @FormParam(DigitalObjectResourceApi.MEMBERS_ITEM_PID) List<String> movePids)
        throws IOException, DigitalObjectException, FedoraClientException {

    if (srcParentPid == null) {
        throw RestException.plainText(Status.BAD_REQUEST, "Missing source PID!");
    }
    if (dstParentPid == null) {
        throw RestException.plainText(Status.BAD_REQUEST, "Missing target PID!");
    }
    if (srcParentPid.equals(dstParentPid)) {
        throw RestException.plainText(Status.BAD_REQUEST, "src == dst!");
    }
    if (movePids == null || movePids.isEmpty()) {
        throw RestException.plainText(Status.BAD_REQUEST, "Missing children PIDs!");
    }

    HashSet<String> movePidSet = new HashSet<String>(movePids);
    if (movePidSet.isEmpty()) {
        return new SmartGwtResponse<Item>(Collections.<Item>emptyList());
    } else if (movePidSet.size() != movePids.size()) {
        throw RestException.plainText(Status.BAD_REQUEST, "Duplicate children in the request!");
    }
    if (movePidSet.contains(dstParentPid)) {
        throw RestException.plainText(Status.BAD_REQUEST, "The target parent listed as child!");
    }

    Batch batch = batchId == null ? null : importManager.get(batchId);
    DigitalObjectHandler srcHandler = findHandler(srcParentPid, batch, false);
    deleteMembers(srcHandler, movePidSet);

    // XXX loadLocalSearchItems
    Map<String, Item> memberSearchMap = loadSearchItems(movePidSet);
    DigitalObjectHandler dstHandler = findHandler(dstParentPid, batch, false);
    List<Item> added = addMembers(dstHandler, movePids, memberSearchMap);

    srcHandler.commit();
    dstHandler.commit();
    SmartGwtResponse<Item> result = new SmartGwtResponse<Item>(added);
    return result;
}

From source file:org.apache.ambari.server.stack.StackManagerTest.java

@Test
public void testStackVersionInheritance_includeAllServices() {
    StackInfo stack = stackManager.getStack("HDP", "2.1.1");
    assertNotNull(stack);/* w  w w . j  a v  a  2  s .  c o  m*/
    assertEquals("HDP", stack.getName());
    assertEquals("2.1.1", stack.getVersion());
    Collection<ServiceInfo> services = stack.getServices();

    //should include all stacks in hierarchy
    assertEquals(16, services.size());
    HashSet<String> expectedServices = new HashSet<String>();
    expectedServices.add("GANGLIA");
    expectedServices.add("HBASE");
    expectedServices.add("HCATALOG");
    expectedServices.add("HDFS");
    expectedServices.add("HIVE");
    expectedServices.add("MAPREDUCE2");
    expectedServices.add("OOZIE");
    expectedServices.add("PIG");
    expectedServices.add("SQOOP");
    expectedServices.add("YARN");
    expectedServices.add("ZOOKEEPER");
    expectedServices.add("STORM");
    expectedServices.add("FLUME");
    expectedServices.add("FAKENAGIOS");
    expectedServices.add("TEZ");
    expectedServices.add("AMBARI_METRICS");

    ServiceInfo pigService = null;
    for (ServiceInfo service : services) {
        if (service.getName().equals("PIG")) {
            pigService = service;
        }
        assertTrue(expectedServices.remove(service.getName()));
    }
    assertTrue(expectedServices.isEmpty());

    // extended values
    assertNotNull(pigService);
    assertEquals("0.12.1.2.1.1", pigService.getVersion());
    assertEquals("Scripting platform for analyzing large datasets (Extended)", pigService.getComment());
    //base value
    ServiceInfo basePigService = stackManager.getStack("HDP", "2.0.5").getService("PIG");
    assertEquals("0.11.1.2.0.5.0", basePigService.getVersion());
    assertEquals(1, basePigService.getComponents().size());
    // new component added in extended version
    assertEquals(2, pigService.getComponents().size());
    // no properties in base service
    assertEquals(0, basePigService.getProperties().size());
    assertEquals(1, pigService.getProperties().size());
    assertEquals("content", pigService.getProperties().get(0).getName());
}

From source file:cz.cas.lib.proarc.webapp.server.rest.DigitalObjectResource.java

/**
 * Removes given children from a parent.
 * <p><b>Requires handler commit!</b>
 * @param parent parent PID/*  www. ja  v  a2  s  .  c om*/
 * @param toRemovePidSet PIDs of children to remove
 */
private void deleteMembers(DigitalObjectHandler parent, Set<String> toRemovePidSet)
        throws DigitalObjectException {
    RelationEditor editor = parent.relations();
    List<String> members = editor.getMembers();
    // check that PIDs being removed are members of parent object
    HashSet<String> toRemovePidSetCopy = new HashSet<String>(toRemovePidSet);
    toRemovePidSetCopy.removeAll(members);
    if (!toRemovePidSetCopy.isEmpty()) {
        String msg = String.format("Parent: %s does not contain members: %s", parent.getFedoraObject().getPid(),
                toRemovePidSetCopy.toString());
        throw RestException.plainText(Status.BAD_REQUEST, msg);
    }
    // remove
    if (members.removeAll(toRemovePidSet)) {
        editor.setMembers(members);
        editor.write(editor.getLastModified(), session.asFedoraLog());
    }
}

From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.BusStopMapFragment.java

/**
 * This method is called when the search Loader has finished loading and
 * data is to be populated on the map.//from   w ww  . j a v  a 2s  .com
 * 
 * @param result The data to be populated on the map.
 */
private void addGeoSearchResults(final HashSet<MarkerOptions> result) {
    if (!isAdded()) {
        return;
    }

    // If there is a progress Dialog, get rid of it.
    callbacks.onDismissSearchProgress();

    if (map == null) {
        return;
    }

    // Remove all of the existing search markers from the map.
    for (Marker m : geoSearchMarkers) {
        m.remove();
    }

    // ...and because they've been cleared from the map, remove them all
    // from the collection.
    geoSearchMarkers.clear();

    // If there are no results, show a Toast notification to the user.
    if (result == null || result.isEmpty()) {
        Toast.makeText(getActivity(), R.string.busstopmapfragment_nosearchresults, Toast.LENGTH_LONG).show();
        return;
    }

    Marker marker;
    boolean isFirst = true;

    for (MarkerOptions mo : result) {
        // Add the new marker to the map.
        marker = map.addMarker(mo);

        // Make sure the item does not already exist in the marker list. If
        // it does, remove it from the map again.
        if (!geoSearchMarkers.add(marker)) {
            marker.remove();
        } else if (isFirst) {
            // If it's the first icon to be added, move the camera to that
            // bus stop marker.
            isFirst = false;

            moveCameraToLocation(marker.getPosition(), DEFAULT_SEARCH_ZOOM, true);
            marker.showInfoWindow();
        }
    }
}

From source file:cz.cas.lib.proarc.webapp.server.rest.DigitalObjectResource.java

private List<Item> addMembers(DigitalObjectHandler parent, List<String> toAddPids,
        Map<String, Item> memberSearchMap) throws DigitalObjectException {

    String parentPid = parent.getFedoraObject().getPid();
    HashSet<String> toAddPidSet = new HashSet<String>(toAddPids);
    ArrayList<Item> added = new ArrayList<Item>(toAddPidSet.size());
    if (toAddPidSet.isEmpty()) {
        return added;
    }/*www .j a v a 2 s  .co  m*/
    RelationEditor editor = parent.relations();
    List<String> members = editor.getMembers();
    // add new members
    for (String addPid : toAddPids) {
        if (!members.contains(addPid)) {
            members.add(addPid);
            Item item = memberSearchMap.get(addPid);
            if (item == null) {
                throw RestException.plainNotFound("pid", toAddPidSet.toString());
            }
            item.setParentPid(parentPid);
            added.add(item);
        } else {
            throw RestException.plainText(Status.BAD_REQUEST, parentPid + " already contains: " + addPid);
        }
    }
    // write if any change
    if (!added.isEmpty()) {
        editor.setMembers(members);
        editor.write(editor.getLastModified(), session.asFedoraLog());
    }
    return added;
}

From source file:org.apache.hadoop.hdfs.tools.offlineImageViewer.OfflineImageReconstructor.java

/**
 * Processes the XML file back into an fsimage.
 *//*from   ww  w  .  ja v  a2 s.com*/
private void processXml() throws Exception {
    LOG.debug("Loading <fsimage>.");
    expectTag("fsimage", false);
    // Read the <version> tag.
    readVersion();
    // Write the HDFSIMG1 magic number which begins the fsimage file.
    out.write(FSImageUtil.MAGIC_HEADER);
    // Write a series of fsimage sections.
    sectionStartOffset = FSImageUtil.MAGIC_HEADER.length;
    final HashSet<String> unprocessedSections = new HashSet<>(sections.keySet());
    while (!unprocessedSections.isEmpty()) {
        XMLEvent ev = expectTag("[section header]", true);
        if (ev.getEventType() == XMLStreamConstants.END_ELEMENT) {
            if (ev.asEndElement().getName().getLocalPart().equals("fsimage")) {
                throw new IOException("FSImage XML ended prematurely, without " + "including section(s) "
                        + StringUtils.join(", ", unprocessedSections));
            }
            throw new IOException(
                    "Got unexpected tag end event for " + ev.asEndElement().getName().getLocalPart()
                            + " while looking " + "for section header tag.");
        } else if (ev.getEventType() != XMLStreamConstants.START_ELEMENT) {
            throw new IOException(
                    "Expected section header START_ELEMENT; " + "got event of type " + ev.getEventType());
        }
        String sectionName = ev.asStartElement().getName().getLocalPart();
        if (!unprocessedSections.contains(sectionName)) {
            throw new IOException("Unknown or duplicate section found for " + sectionName);
        }
        SectionProcessor sectionProcessor = sections.get(sectionName);
        if (sectionProcessor == null) {
            throw new IOException("Unknown FSImage section " + sectionName + ".  Valid section names are ["
                    + StringUtils.join(", ", sections.keySet()) + "]");
        }
        unprocessedSections.remove(sectionName);
        sectionProcessor.process();
    }

    // Write the StringTable section to disk.
    // This has to be done after the other sections, since some of them
    // add entries to the string table.
    writeStringTableSection();

    // Write the FileSummary section to disk.
    // This section is always last.
    long prevOffset = out.getCount();
    FileSummary fileSummary = fileSummaryBld.build();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Writing FileSummary: {" + TextFormat.printToString(fileSummary) + "}");
    }
    // Even though the last 4 bytes of the file gives the FileSummary length,
    // we still write a varint first that also contains the length.
    fileSummary.writeDelimitedTo(out);

    // Write the length of the FileSummary section as a fixed-size big
    // endian 4-byte quantity.
    int summaryLen = Ints.checkedCast(out.getCount() - prevOffset);
    byte[] summaryLenBytes = new byte[4];
    ByteBuffer.wrap(summaryLenBytes).asIntBuffer().put(summaryLen);
    out.write(summaryLenBytes);
}

From source file:de.interactive_instruments.ShapeChange.Transformation.Profiling.Profiler.java

/**
 * @see de.interactive_instruments.ShapeChange.Transformation.Transformer#process(de.interactive_instruments.ShapeChange.Model.Model,
 *      de.interactive_instruments.ShapeChange.Options,
 *      de.interactive_instruments.ShapeChange.TransformerConfiguration,
 *      de.interactive_instruments.ShapeChange.ShapeChangeResult)
 *//*from w  w  w.j  av a2 s  . c o m*/
public void process(GenericModel genModel, Options options, TransformerConfiguration trfConfig,
        ShapeChangeResult result) throws ShapeChangeAbortException {

    this.log = result;

    Map<String, ProcessRuleSet> ruleSets = trfConfig.getRuleSets();

    // Get and check required parameter(s)

    // 'profiles'
    String profilesParameterValue = trfConfig.getParameterValue(PROFILES_PARAMETER);

    // residual type removal - include subtypes for
    Pattern residualTypeRemoval_includeSubtypesFor = trfConfig
            .hasParameter(PROFILING_CFG_PARAM_RESIDUALTYPEREMOVAL_INCLUDESUBTYPESFOR)
                    ? Pattern.compile(trfConfig
                            .getParameterValue(PROFILING_CFG_PARAM_RESIDUALTYPEREMOVAL_INCLUDESUBTYPESFOR))
                    : null;

    boolean checkOk = true;

    try {
        this.profilesFromConfig = ProfileIdentifierMap.parse(profilesParameterValue, IdentifierPattern.strict,
                PROFILES_PARAMETER + "_configuration_parameter");
    } catch (MalformedProfileIdentifierException e) {
        checkOk = false;
        log.addError(null, 20206, PROFILES_PARAMETER, e.getMessage());
    }

    // 'constraintHandling'
    String constraintHandlingValue = trfConfig.getParameterValue(CONSTRAINTHANDLING_PARAMETER);
    if (constraintHandlingValue != null && constraintHandlingValue.length() > 0) {
        boolean validConstraintHandlingParameter = false;
        for (ConstraintHandling conHandlingEnum : ConstraintHandling.values()) {
            if (conHandlingEnum.name().equalsIgnoreCase(constraintHandlingValue)) {
                this.constraintHandling = conHandlingEnum;
                validConstraintHandlingParameter = true;
                break;
            }
        }
        if (!validConstraintHandlingParameter) {
            throw new ShapeChangeAbortException("Value of configuration parameter '"
                    + CONSTRAINTHANDLING_PARAMETER + "' does not match one of the defined values (was: "
                    + constraintHandlingValue + ")");
        }
    }

    // for now we simply get the set of all rules defined for the
    // transformation
    Set<String> rules = new HashSet<String>();
    if (!ruleSets.isEmpty()) {
        for (ProcessRuleSet ruleSet : ruleSets.values()) {
            if (ruleSet.getAdditionalRules() != null) {
                rules.addAll(ruleSet.getAdditionalRules());
            }
        }
    }

    // 0. Keep track of global rules
    this.isExplicitProfileSettingsRuleEnabled = rules
            .contains(RULE_TRF_PROFILING_PROCESSING_EXPLICITPROFILESETTINGS);

    // 1. Execute any preprocessing
    if (rules.contains(RULE_TRF_PROFILING_PREPROCESSING_PROFILESVALUECONSISTENCYCHECK)) {

        StatusBoard.getStatusBoard().statusChanged(STATUS_PREPROCESSING_PROFILESVALUECONSISTENCYCHECK);

        /*
         * Check that the values of the 'profiles' tagged value in classes
         * are consistent:
         * 
         * NOTE: Undefined or empty 'profiles' tagged values are allowed,
         * but the interpretation depends on the rules that are set
         * 
         * - future work: Ensure that profile identifiers are members of a
         * specific set (defined by enumeration in the model or a given list
         * of identifiers)
         */

        /*
         * Parse profile identifiers to check that they are correctly
         * formatted, that the version numbers/ranges are correct and that
         * information for a profile is not given twice.
         */
        for (GenericClassInfo ci : genModel.selectedSchemaClasses()) {

            String profiles = ci.taggedValue(PROFILES_TAGGED_VALUE);

            if (profiles == null || profiles.trim().length() == 0) {

                // No specific profiles declared, which is valid.
                this.classByIdProfileIdMap.put(ci.id(), null);

            } else {

                // check that the profile identifiers are well-formed
                try {

                    ProfileIdentifierMap piMap = ProfileIdentifierMap.parse(profiles, IdentifierPattern.loose,
                            ci.name());

                    this.classByIdProfileIdMap.put(ci.id(), piMap);

                } catch (MalformedProfileIdentifierException e) {
                    log.addWarning(null, 20201, profiles, ci.name(), e.getMessage());
                }
            }

        }

        for (GenericPropertyInfo pi : genModel.selectedSchemaProperties()) {

            String profiles = pi.taggedValue(PROFILES_TAGGED_VALUE);

            if (profiles == null || profiles.trim().length() == 0) {

                // No specific profiles declared, which is valid.

                this.propertyByIdProfileIdMap.put(pi.id(), null);

            } else {

                try {

                    ProfileIdentifierMap piMap = ProfileIdentifierMap.parse(profiles, IdentifierPattern.loose,
                            pi.name() + " (property of class " + pi.inClass().name() + ")");

                    this.propertyByIdProfileIdMap.put(pi.id(), piMap);

                } catch (MalformedProfileIdentifierException e) {
                    log.addWarning(null, 20202, profiles, pi.name(), pi.inClass().name(), e.getMessage());
                }
            }
        }
    }

    if (!checkOk) {
        throw new ShapeChangeAbortException(
                "One or more pre-conditions for executing the profiler were not met. Consult the log file for further information.");
    }

    if (rules.contains(RULE_TRF_PROFILING_PREPROCESSING_MODELCONSISTENCYCHECK)) {

        StatusBoard.getStatusBoard().statusChanged(STATUS_PREPROCESSING_MODELCONSISTENCYCHECK);

        // TBD This could be moved to a separate Transformer class
        /*
         * Check that the 'profiles' tagged value information is consistent
         * regarding the model:
         * 
         * NOTE: the creation of a generalization relationship between model
         * classes and versioning of this model change is currently not
         * taken into account via the profiling mechanism, because adding
         * the 'profiles' tagged value to generalization relationships is
         * currently not foreseen.
         */

        /*
         * Check that the profile set of a supertype contains the profile
         * set of its subtypes. Also check that the profile set of a class
         * contains the profile sets of its properties (unless the rule for
         * explicit profile settings is enabled and the class does not
         * belong to a profile).
         * 
         * In both cases, take into account undefined/empty 'profiles'
         * tagged values: profiler behavior is different depending upon
         * whether or not the rule on explicit profile settings is enabled.
         * If it is enabled, classes and properties without profile
         * information belong to no profile. If the rule is disabled
         * (default setting) then classes belong to all profiles and
         * properties inherit the profile set from their owner.
         * 
         * Non-navigable properties belonging to the class are ignored.
         */

        for (GenericClassInfo ci : genModel.selectedSchemaClasses()) {

            ProfileIdentifierMap ciPidMap = classByIdProfileIdMap.get(ci.id());

            // Test for subtypes
            if (ci.hasSubtypes()) {

                SortedSet<String> subtypeIds = ci.subtypes();

                for (String subtypeId : subtypeIds) {

                    ProfileIdentifierMap subtypePidMap = classByIdProfileIdMap.get(subtypeId);

                    // used for logging messages
                    List<String> messages = new ArrayList<String>();

                    if (!contains(ciPidMap, ci.name(), subtypePidMap, genModel.classById(subtypeId).name(),
                            false, messages)) {

                        /*
                         * This can be dangerous in case that the subtype
                         * has constraints from properties of its supertype.
                         * In such a case the constraints won't have a
                         * proper context (because the properties they are
                         * referring to may not exist in case that the
                         * supertype is omitted in a profile for which the
                         * subtype remains).
                         * 
                         * However, if all subtypes would be removed as well
                         * then it would be ok.
                         */

                        if (rules.contains(RULE_TRF_PROFILING_PROCESSING_CLASS_REMOVAL_INCLUDES_ALL_SUBTYPES)) {

                            /*
                             * as all subtypes will be removed this is not
                             * problematic - just log an info
                             */
                            log.addInfo(null, 20214, ci.name(), genModel.classById(subtypeId).name(),
                                    StringUtils.join(messages, PROFILER_ISSUE_LOG_MESSAGES_SEPARATOR));

                        } else {

                            log.addError(null, 20203, ci.name(), genModel.classById(subtypeId).name(),
                                    StringUtils.join(messages, PROFILER_ISSUE_LOG_MESSAGES_SEPARATOR));
                        }
                    }
                }
            }

            // Test for navigable properties
            for (PropertyInfo pi : ci.properties().values()) {

                if (pi.isNavigable()) {

                    ProfileIdentifierMap propertyPidMap = propertyByIdProfileIdMap.get(pi.id());

                    List<String> messages = new ArrayList<String>();

                    if (isExplicitProfileSettingsRuleEnabled && ciPidMap == null) {

                        // this is allowed

                    } else if (!contains(ciPidMap, ci.name(), propertyPidMap,
                            pi.name() + "(in class " + pi.inClass() + ")", true, messages)) {

                        log.addWarning(null, 20204, ci.name(), pi.name(),
                                StringUtils.join(messages, PROFILER_ISSUE_LOG_MESSAGES_SEPARATOR));
                    }
                }
            }
        }
    }

    // 2. Execute profiling

    StatusBoard.getStatusBoard().statusChanged(STATUS_PROCESSING_PROFILING);

    /*
     * For each class in the generic model:
     * 
     * If it does not have the 'profiles' tagged value or that value is
     * empty, keep it - unless the rule for explicit profile settings is
     * enabled; in that case the class shall be removed.
     * 
     * Otherwise, if the class does not contain the target profiles, remove
     * it. Each of its properties is removed as well.
     * 
     * If the rule to remove all subtypes of a class that is removed is
     * enabled, ensure that all direct and indirect subtypes are removed.
     * 
     * Consistency check for constraints in remaining classes and properties
     * is performed afterwards.
     * 
     * TBD: at the moment the complete association is removed if the class
     * is an association class
     */
    Set<GenericClassInfo> cisToRemove = new HashSet<GenericClassInfo>();

    for (GenericClassInfo ci : genModel.selectedSchemaClasses()) {

        if (cisToRemove.contains(ci)) {
            /* fine, the class is already marked for removal */
            continue;
        }

        ProfileIdentifierMap ciPidMap = classByIdProfileIdMap.get(ci.id());

        if (!contains(ciPidMap, null, profilesFromConfig, null, false, null)) {

            cisToRemove.add(ci);

            if (rules.contains(RULE_TRF_PROFILING_PROCESSING_CLASS_REMOVAL_INCLUDES_ALL_SUBTYPES)) {

                /*
                 * identify all direct and indirect subtypes of ci and add
                 * them to the list of classes to be removed
                 */
                cisToRemove.addAll(this.getAllSubtypes(ci));
            }
        }
    }

    for (GenericClassInfo ci : cisToRemove) {
        genModel.remove(ci);
    }

    /*
     * For each (remaining) property in the generic model:
     * 
     * If the property does not have the profiles tagged value or that value
     * is empty, set its value to the profile set of its class (profile set
     * inheritance) - unless the rule for explicit profile settings is
     * enabled (in that case the property does not belong to a profile).
     * 
     * If the property does not belong to any of the target profiles, remove
     * it unless a) it belongs to an association in which the other end is
     * navigable (in that case, set the property to be non-navigable) or b)
     * the rule to keep associations is enabled.
     * 
     * When removing properties, take into account constraint handling.
     */
    List<PropertyInfo> pisToRemove = new ArrayList<PropertyInfo>();

    for (GenericClassInfo ci : genModel.selectedSchemaClasses()) {

        for (PropertyInfo pi : ci.properties().values()) {

            if (!pi.isAttribute() && rules.contains(RULE_TRF_PROFILING_PROCESSING_KEEP_ASSOCIATION_AS_IS)) {

                /* ignore this property */
                continue;
            }

            if (!contains(pi, profilesFromConfig, null)) {

                pisToRemove.add(pi);
            }
        }
    }

    // now delete the properties that were marked for removal
    for (PropertyInfo pi : pisToRemove) {

        /*
         * Cast should be safe because the pis originate from
         * GenericClassInfos (see previous loop)
         */
        genModel.remove((GenericPropertyInfo) pi, true);

        /*
         * Cast should be safe: if pi is a GenericPropertyInfo then so
         * should be its inClass()
         */
        GenericClassInfo genCi = (GenericClassInfo) pi.inClass();

        if (constraintHandling.equals(ConstraintHandling.remove)) {

            if (!genCi.constraints().isEmpty()) {
                genCi.setConstraints(new Vector<Constraint>());
            }

        } else if (constraintHandling.equals(ConstraintHandling.removeByPropertyNameInConstraintName)) {

            // ensure that constraint is removed in inClass and all subtypes
            // of it, to the deepest level (currently required because
            // constraints from supertype are copied to all subtypes during
            // initial model load)

            removeConstraintByPropertyNameInTypeTree(genCi, pi.name(), genModel);

        } else {
            // then the constraints are kept as is
        }
    }

    for (GenericClassInfo genCi : genModel.selectedSchemaClasses()) {

        if (constraintHandling.equals(ConstraintHandling.remove)) {

            if (!genCi.constraints().isEmpty()) {
                genCi.setConstraints(new Vector<Constraint>());
            }

        } else {

            /*
             * Perform a consistency check for constraints in remaining
             * model elements
             */

            /*
             * Constraints in subtypes may be invalid if their context
             * points to properties of supertypes that no longer exist.
             * Check that context model element of constraints exists.
             */

            genCi.setConstraints(this.validateConstraintContext(genCi.constraints(), genCi, result, genModel));

            if (genCi.properties() != null) {

                for (PropertyInfo pi : genCi.properties().values()) {

                    /*
                     * cast should be safe because the properties of a
                     * GenericClassInfo should all be of type
                     * GenericPropertyInfo
                     */
                    GenericPropertyInfo genPi = (GenericPropertyInfo) pi;

                    List<Constraint> genPiConstraints = genPi.constraints();

                    genPi.setConstraints(
                            this.validateConstraintContext(genPiConstraints, genPi, result, genModel));
                }
            }

            if (constraintHandling.equals(ConstraintHandling.removeByPropertyNameInConstraintName)) {

                /*
                 * Class constraints may be invalid if they reference
                 * properties that have been removed during profiling
                 * 
                 * TBD - for now we try to identify such constraints by
                 * their name suffix '_Type'
                 */
                if (!genCi.constraints().isEmpty()) {

                    Vector<Constraint> newConstraints = new Vector<Constraint>();

                    for (Constraint con : genCi.constraints()) {

                        if (con.name().endsWith("_Type")) {
                            String targetPropertyName = con.name().replace("_Type", "");
                            if (genCi.property(targetPropertyName) == null) {

                                log.addInfo(null, 20207, con.name(), genCi.name());

                            } else {
                                newConstraints.add(con);
                            }

                        } else {
                            newConstraints.add(con);
                        }
                    }

                    genCi.setConstraints(newConstraints);
                }

            } else {
                // then the remaining constraints are kept as is
            }
        }
    }

    // 3. Execute any postprocessing
    if (rules.contains(RULE_TRF_PROFILING_POSTPROCESSING_REMOVERESIDUALTYPES)) {

        StatusBoard.getStatusBoard().statusChanged(STATUS_POSTPROCESSING_REMOVERESIDUALTYPES);

        // key: classid
        HashSet<GenericClassInfo> genCis = genModel.selectedSchemaClasses();

        if (genCis != null && !genCis.isEmpty()) {

            List<GenericClassInfo> featureTypes = new ArrayList<GenericClassInfo>();
            Map<String, GenericClassInfo> residualTypes = new TreeMap<String, GenericClassInfo>();

            // determine feature types and non feature types (which may be
            // residual types - to be determined later on)
            for (GenericClassInfo genCi : genCis) {

                if (genCi.category() == Options.FEATURE) {
                    featureTypes.add(genCi);
                } else {
                    residualTypes.put(genCi.id(), genCi);
                }
            }

            /*
             * remove all types used by feature types from the residual
             * types map; the remaining classes are not used by feature
             * types and can thus be removed from the model
             */
            Set<String> usedCisById = new HashSet<String>();

            for (GenericClassInfo ftCi : featureTypes) {

                this.deepSearchForTypesUsedByClass(ftCi, usedCisById, genModel,
                        residualTypeRemoval_includeSubtypesFor);
            }

            // remove all identified Cis from the residual types map
            for (String usedCiId : usedCisById) {
                residualTypes.remove(usedCiId);
            }

            // now remove the residual types from the model
            genModel.remove(residualTypes.values());
        }

    }

    if (rules.contains(RULE_TRF_PROFILING_POSTPROCESSING_REMOVEEMPTYPACKAGES)) {

        StatusBoard.getStatusBoard().statusChanged(STATUS_POSTPROCESSING_REMOVEEMPTYPACKAGES);

        // If, after profiling, there is no class in a package (or its
        // child-packages), remove it.

        Set<GenericPackageInfo> appSchemaPackages = genModel.selectedSchemas();

        for (GenericPackageInfo appSchemaPackage : appSchemaPackages) {

            Set<PackageInfo> emptyPackages = new HashSet<PackageInfo>();
            appSchemaPackage.getEmptyPackages(emptyPackages);

            if (emptyPackages.contains(appSchemaPackage)) {
                log.addWarning(null, 20205, appSchemaPackage.name());
                emptyPackages.remove(appSchemaPackage);
            }

            genModel.remove(emptyPackages);
        }
    }
}