Example usage for com.google.common.collect Sets newHashSetWithExpectedSize

List of usage examples for com.google.common.collect Sets newHashSetWithExpectedSize

Introduction

In this page you can find the example usage for com.google.common.collect Sets newHashSetWithExpectedSize.

Prototype

public static <E> HashSet<E> newHashSetWithExpectedSize(int expectedSize) 

Source Link

Document

Creates a HashSet instance, with a high enough initial table size that it should hold expectedSize elements without resizing.

Usage

From source file:org.zenoss.zep.dao.impl.EventSummaryDaoImpl.java

@Override
@TransactionalReadOnly/*  w ww .  j av  a 2s.  co m*/
@Timed
/**
 * This implementation only makes use of the UUID field to lookup the events.
 */
public List<EventSummary> findByKey(final Collection<EventSummary> toLookup) throws ZepException {
    if (toLookup == null || toLookup.isEmpty())
        return Collections.emptyList();
    Set<String> uuids = Sets.newHashSetWithExpectedSize(toLookup.size());
    for (EventSummary event : toLookup)
        uuids.add(event.getUuid());
    return findByUuids(uuids);
}

From source file:org.apache.tephra.TransactionManager.java

/**
 * Validate the number of changes and the total size of changes. Log a warning if either of them exceeds the
 * configured threshold, or log a warning and throw an exception if it exceeds the configured limit.
 *
 * We log here because application developers may ignore warnings. Logging here gives us a single point
 * (the tx manager log) to identify all clients that send excessively large change sets.
 *
 * @return the same set of changes, transformed into a set of {@link ChangeId}s.
 * @throws TransactionSizeException if the number or total size of the changes exceed the limit.
 *///from w w  w.j  a v  a  2 s  . c o m
private Set<ChangeId> validateChangeSet(long txId, Collection<byte[]> changeIds, String clientId)
        throws TransactionSizeException {
    if (changeIds.size() > changeSetCountLimit) {
        LOG.warn("Change set for transaction {} belonging to client '{}' has {} entries and exceeds "
                + "the allowed size of {}. Limit the number of changes, or use a long-running transaction. ",
                txId, clientId, changeIds.size(), changeSetCountLimit);
        throw new TransactionSizeException(
                String.format("Change set for transaction %d has %d entries and exceeds the limit of %d", txId,
                        changeIds.size(), changeSetCountLimit));
    } else if (changeIds.size() > changeSetCountThreshold) {
        LOG.warn("Change set for transaction {} belonging to client '{}' has {} entries. "
                + "It is recommended to limit the number of changes to {}, or to use a long-running transaction. ",
                txId, clientId, changeIds.size(), changeSetCountThreshold);
    }
    long byteCount = 0L;
    Set<ChangeId> set = Sets.newHashSetWithExpectedSize(changeIds.size());
    for (byte[] change : changeIds) {
        set.add(new ChangeId(change));
        byteCount += change.length;
    }
    if (byteCount > changeSetSizeLimit) {
        LOG.warn(
                "Change set for transaction {} belonging to client '{}' has total size of {} bytes and exceeds "
                        + "the allowed size of {} bytes. Limit the total size of changes, or use a long-running transaction. ",
                txId, clientId, byteCount, changeSetSizeLimit);
        throw new TransactionSizeException(String.format(
                "Change set for transaction %d has total size of %d bytes and exceeds the limit of %d bytes",
                txId, byteCount, changeSetSizeLimit));
    } else if (byteCount > changeSetSizeThreshold) {
        LOG.warn("Change set for transaction {} belonging to client '{}' has total size of {} bytes. "
                + "It is recommended to limit the total size to {} bytes, or to use a long-running transaction. ",
                txId, clientId, byteCount, changeSetSizeThreshold);
    }
    return set;
}

From source file:com.android.builder.core.VariantConfiguration.java

/**
 * Returns the compile classpath for this config. If the config tests a library, this
 * will include the classpath of the tested config
 *
 * @return a non null, but possibly empty set.
 *//*w  w w . j a va 2 s .c  o m*/
@NonNull
public Set<File> getCompileClasspath() {
    Set<File> classpath = Sets
            .newHashSetWithExpectedSize(mExternalJars.size() + mLocalJars.size() + mFlatLibraries.size());

    for (LibraryDependency lib : mFlatLibraries) {
        classpath.add(lib.getJarFile());
        for (File jarFile : lib.getLocalJars()) {
            classpath.add(jarFile);
        }
    }

    for (JarDependency jar : mExternalJars) {
        if (jar.isCompiled()) {
            classpath.add(jar.getJarFile());
        }
    }

    for (JarDependency jar : mLocalJars) {
        if (jar.isCompiled()) {
            classpath.add(jar.getJarFile());
        }
    }

    return classpath;
}

From source file:org.apache.phoenix.util.UpgradeUtil.java

/**
 * Identify the tables that need to be upgraded due to PHOENIX-2067
 *///from   w  ww . j  ava2s .  co  m
private static List<String> getPhysicalTablesWithDescRowKey(String query, PhoenixConnection conn)
        throws SQLException {
    // First query finds column rows of tables that need to be upgraded.
    // We cannot tell if the column is from a table, view, or index however.
    ResultSet rs = conn.createStatement().executeQuery(query);
    Set<String> physicalTables = Sets.newHashSetWithExpectedSize(1024);
    List<String> remainingTableNames = addPhysicalTables(conn, rs, PTableType.INDEX, physicalTables);
    if (!remainingTableNames.isEmpty()) {
        // Find tables/views for index
        String indexLinkQuery = "SELECT TENANT_ID,TABLE_SCHEM,TABLE_NAME\n" + "FROM SYSTEM.CATALOG\n"
                + "WHERE COLUMN_NAME IS NULL\n" + "AND (TENANT_ID, TABLE_SCHEM, COLUMN_FAMILY) IN "
                + getTableRVC(remainingTableNames) + "\n" + "AND LINK_TYPE = "
                + LinkType.INDEX_TABLE.getSerializedValue();
        rs = conn.createStatement().executeQuery(indexLinkQuery);
        remainingTableNames = addPhysicalTables(conn, rs, PTableType.VIEW, physicalTables);
        if (!remainingTableNames.isEmpty()) {
            // Find physical table name from views, splitting on '.' to get schema name and table name
            String physicalLinkQuery = "SELECT null, "
                    + " CASE WHEN INSTR(COLUMN_FAMILY,'.') = 0 THEN NULL ELSE SUBSTR(COLUMN_FAMILY,1,INSTR(COLUMN_FAMILY,'.')) END,\n"
                    + " CASE WHEN INSTR(COLUMN_FAMILY,'.') = 0 THEN COLUMN_FAMILY ELSE SUBSTR(COLUMN_FAMILY,INSTR(COLUMN_FAMILY,'.')+1) END\n"
                    + "FROM SYSTEM.CATALOG\n" + "WHERE COLUMN_NAME IS NULL\n"
                    + "AND COLUMN_FAMILY IS NOT NULL\n" + "AND (TENANT_ID, TABLE_SCHEM, TABLE_NAME) IN "
                    + getTableRVC(remainingTableNames) + "\n" + "AND LINK_TYPE = "
                    + LinkType.PHYSICAL_TABLE.getSerializedValue();
            rs = conn.createStatement().executeQuery(physicalLinkQuery);
            // Add any tables (which will all be physical tables) which have not already been upgraded.
            addPhysicalTables(conn, rs, PTableType.TABLE, physicalTables);
        }
    }
    List<String> sortedPhysicalTables = new ArrayList<String>(physicalTables);
    Collections.sort(sortedPhysicalTables);
    return sortedPhysicalTables;
}

From source file:com.android.builder.core.VariantConfiguration.java

/**
 * Returns the list of packaged jars for this config. If the config tests a library, this
 * will include the jars of the tested config
 *
 * @return a non null, but possibly empty list.
 */// w  ww.  j a  va  2 s  .co  m
@NonNull
public Set<File> getPackagedJars() {
    Set<File> jars = Sets
            .newHashSetWithExpectedSize(mExternalJars.size() + mLocalJars.size() + mFlatLibraries.size());

    for (JarDependency jar : mExternalJars) {
        File jarFile = jar.getJarFile();
        if (jar.isPackaged() && jarFile.exists()) {
            jars.add(jarFile);
        }
    }

    for (JarDependency jar : mLocalJars) {
        File jarFile = jar.getJarFile();
        if (jar.isPackaged() && jarFile.exists()) {
            jars.add(jarFile);
        }
    }

    for (LibraryDependency libraryDependency : mFlatLibraries) {
        if (!libraryDependency.isOptional()) {
            File libJar = libraryDependency.getJarFile();
            if (libJar.exists()) {
                jars.add(libJar);
            }
            for (File jarFile : libraryDependency.getLocalJars()) {
                if (jarFile.isFile()) {
                    jars.add(jarFile);
                }
            }
        }
    }

    return jars;
}

From source file:com.android.tools.klint.checks.IconDetector.java

private void checkDensities(Context context, File res, Map<File, Set<String>> folderToNames,
        Map<File, Set<String>> nonDpiFolderNames) {
    // TODO: Is there a way to look at the manifest and figure out whether
    // all densities are expected to be needed?
    // Note: ldpi is probably not needed; it has very little usage
    // (about 2%; http://developer.android.com/resources/dashboard/screens.html)
    // TODO: Use the matrix to check out if we can eliminate densities based
    // on the target screens?

    Set<String> definedDensities = new HashSet<String>();
    for (File f : folderToNames.keySet()) {
        definedDensities.add(f.getName());
    }//from   w  ww  . ja v a 2  s .c  o  m

    // Look for missing folders -- if you define say drawable-mdpi then you
    // should also define -hdpi and -xhdpi.
    if (context.isEnabled(ICON_MISSING_FOLDER)) {
        List<String> missing = new ArrayList<String>();
        for (String density : getRequiredDensityFolders(context)) {
            if (!definedDensities.contains(density)) {
                missing.add(density);
            }
        }
        if (!missing.isEmpty()) {
            context.report(ICON_MISSING_FOLDER, Location.create(res),
                    String.format("Missing density variation folders in `%1$s`: %2$s",
                            context.getProject().getDisplayPath(res), LintUtils.formatList(missing, -1)));
        }
    }

    if (context.isEnabled(ICON_NODPI)) {
        Set<String> noDpiNames = new HashSet<String>();
        for (Map.Entry<File, Set<String>> entry : folderToNames.entrySet()) {
            if (isNoDpiFolder(entry.getKey())) {
                noDpiNames.addAll(entry.getValue());
            }
        }
        if (!noDpiNames.isEmpty()) {
            // Make sure that none of the nodpi names appear in a non-nodpi folder
            Set<String> inBoth = new HashSet<String>();
            List<File> files = new ArrayList<File>();
            for (Map.Entry<File, Set<String>> entry : folderToNames.entrySet()) {
                File folder = entry.getKey();
                String folderName = folder.getName();
                if (!isNoDpiFolder(folder)) {
                    assert DENSITY_PATTERN.matcher(folderName).matches();
                    Set<String> overlap = nameIntersection(noDpiNames, entry.getValue());
                    inBoth.addAll(overlap);
                    for (String name : overlap) {
                        files.add(new File(folder, name));
                    }
                }
            }

            if (!inBoth.isEmpty()) {
                List<String> list = new ArrayList<String>(inBoth);
                Collections.sort(list);

                // Chain locations together
                Location location = chainLocations(files);

                context.report(ICON_NODPI, location,
                        String.format(
                                "The following images appear in both `-nodpi` and in a density folder: %1$s",
                                LintUtils.formatList(list, context.getDriver().isAbbreviating() ? 10 : -1)));
            }
        }
    }

    if (context.isEnabled(ICON_MIX_9PNG)) {
        checkMixedNinePatches(context, folderToNames);
    }

    if (context.isEnabled(ICON_XML_AND_PNG)) {
        Map<File, Set<String>> folderMap = Maps.newHashMap(folderToNames);
        folderMap.putAll(nonDpiFolderNames);
        Set<String> xmlNames = Sets.newHashSetWithExpectedSize(100);
        Set<String> bitmapNames = Sets.newHashSetWithExpectedSize(100);

        for (Map.Entry<File, Set<String>> entry : folderMap.entrySet()) {
            Set<String> names = entry.getValue();
            for (String name : names) {
                if (endsWith(name, DOT_XML)) {
                    xmlNames.add(name);
                } else if (isDrawableFile(name)) {
                    bitmapNames.add(name);
                }
            }
        }
        if (!xmlNames.isEmpty() && !bitmapNames.isEmpty()) {
            // Make sure that none of the nodpi names appear in a non-nodpi folder
            Set<String> overlap = nameIntersection(xmlNames, bitmapNames);
            if (!overlap.isEmpty()) {
                Multimap<String, File> map = ArrayListMultimap.create();
                Set<String> bases = Sets.newHashSetWithExpectedSize(overlap.size());
                for (String name : overlap) {
                    bases.add(LintUtils.getBaseName(name));
                }

                for (String base : bases) {
                    for (Map.Entry<File, Set<String>> entry : folderMap.entrySet()) {
                        File folder = entry.getKey();
                        for (String n : entry.getValue()) {
                            if (base.equals(LintUtils.getBaseName(n))) {
                                map.put(base, new File(folder, n));
                            }
                        }
                    }
                }
                List<String> sorted = new ArrayList<String>(map.keySet());
                Collections.sort(sorted);
                for (String name : sorted) {
                    List<File> lists = Lists.newArrayList(map.get(name));
                    Location location = chainLocations(lists);

                    List<String> fileNames = Lists.newArrayList();
                    boolean seenXml = false;
                    boolean seenNonXml = false;
                    for (File f : lists) {
                        boolean isXml = endsWith(f.getPath(), DOT_XML);
                        if (isXml && !seenXml) {
                            fileNames.add(context.getProject().getDisplayPath(f));
                            seenXml = true;
                        } else if (!isXml && !seenNonXml) {
                            fileNames.add(context.getProject().getDisplayPath(f));
                            seenNonXml = true;
                        }
                    }

                    context.report(ICON_XML_AND_PNG, location, String.format(
                            "The following images appear both as density independent `.xml` files and as bitmap files: %1$s",
                            LintUtils.formatList(fileNames, context.getDriver().isAbbreviating() ? 10 : -1)));
                }
            }
        }
    }

    if (context.isEnabled(ICON_DENSITIES)) {
        // Look for folders missing some of the specific assets
        Set<String> allNames = new HashSet<String>();
        for (Entry<File, Set<String>> entry : folderToNames.entrySet()) {
            if (!isNoDpiFolder(entry.getKey())) {
                Set<String> names = entry.getValue();
                allNames.addAll(names);
            }
        }

        for (Map.Entry<File, Set<String>> entry : folderToNames.entrySet()) {
            File file = entry.getKey();
            if (isNoDpiFolder(file)) {
                continue;
            }
            Set<String> names = entry.getValue();
            if (names.size() != allNames.size()) {
                List<String> delta = new ArrayList<String>(nameDifferences(allNames, names));
                if (delta.isEmpty()) {
                    continue;
                }
                Collections.sort(delta);
                String foundIn = "";
                if (delta.size() == 1) {
                    // Produce list of where the icon is actually defined
                    List<String> defined = new ArrayList<String>();
                    String name = delta.get(0);
                    for (Map.Entry<File, Set<String>> e : folderToNames.entrySet()) {
                        if (e.getValue().contains(name)) {
                            defined.add(e.getKey().getName());
                        }
                    }
                    if (!defined.isEmpty()) {
                        foundIn = String.format(" (found in %1$s)",
                                LintUtils.formatList(defined, context.getDriver().isAbbreviating() ? 5 : -1));
                    }
                }

                // Irrelevant folder?
                String folder = file.getName();
                if (!getRequiredDensityFolders(context).contains(folder)) {
                    continue;
                }

                context.report(ICON_DENSITIES, Location.create(file),
                        String.format("Missing the following drawables in `%1$s`: %2$s%3$s", folder,
                                LintUtils.formatList(delta, context.getDriver().isAbbreviating() ? 5 : -1),
                                foundIn));
            }
        }
    }
}

From source file:com.android.builder.core.VariantConfiguration.java

/**
 * Returns the list of provided-only jars for this config.
 *
 * @return a non null, but possibly empty list.
 *///from  w w  w.j  av a 2s . c  o  m
@NonNull
public List<File> getProvidedOnlyJars() {
    Set<File> jars = Sets.newHashSetWithExpectedSize(mExternalJars.size() + mLocalJars.size());

    for (JarDependency jar : mExternalJars) {
        File jarFile = jar.getJarFile();
        if (jar.isCompiled() && !jar.isPackaged() && jarFile.exists()) {
            jars.add(jarFile);
        }
    }

    for (JarDependency jar : mLocalJars) {
        File jarFile = jar.getJarFile();
        if (jar.isCompiled() && !jar.isPackaged() && jarFile.exists()) {
            jars.add(jarFile);
        }
    }

    for (LibraryDependency libraryDependency : mFlatLibraries) {
        if (libraryDependency.isOptional()) {
            File libJar = libraryDependency.getJarFile();
            if (libJar.exists()) {
                jars.add(libJar);
            }
            for (File jarFile : libraryDependency.getLocalJars()) {
                if (jarFile.isFile()) {
                    jars.add(jarFile);
                }
            }
        }
    }

    return Lists.newArrayList(jars);
}

From source file:org.apache.phoenix.query.ConnectionQueryServicesImpl.java

private void checkClientServerCompatibility() throws SQLException {
    StringBuilder buf = new StringBuilder("The following servers require an updated "
            + QueryConstants.DEFAULT_COPROCESS_PATH + " to be put in the classpath of HBase: ");
    boolean isIncompatible = false;
    int minHBaseVersion = Integer.MAX_VALUE;
    try {//from   ww  w . ja va 2  s . c  om
        List<HRegionLocation> locations = this.getAllTableRegions(SYSTEM_CATALOG_NAME_BYTES);
        Set<HRegionLocation> serverMap = Sets.newHashSetWithExpectedSize(locations.size());
        TreeMap<byte[], HRegionLocation> regionMap = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
        List<byte[]> regionKeys = Lists.newArrayListWithExpectedSize(locations.size());
        for (HRegionLocation entry : locations) {
            if (!serverMap.contains(entry)) {
                regionKeys.add(entry.getRegionInfo().getStartKey());
                regionMap.put(entry.getRegionInfo().getRegionName(), entry);
                serverMap.add(entry);
            }
        }

        HTableInterface ht = this.getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES);
        final Map<byte[], Long> results = ht.coprocessorService(MetaDataService.class, null, null,
                new Batch.Call<MetaDataService, Long>() {
                    @Override
                    public Long call(MetaDataService instance) throws IOException {
                        ServerRpcController controller = new ServerRpcController();
                        BlockingRpcCallback<GetVersionResponse> rpcCallback = new BlockingRpcCallback<GetVersionResponse>();
                        GetVersionRequest.Builder builder = GetVersionRequest.newBuilder();
                        builder.setClientVersion(VersionUtil.encodeVersion(PHOENIX_MAJOR_VERSION,
                                PHOENIX_MINOR_VERSION, PHOENIX_PATCH_NUMBER));
                        instance.getVersion(controller, builder.build(), rpcCallback);
                        if (controller.getFailedOn() != null) {
                            throw controller.getFailedOn();
                        }
                        return rpcCallback.get().getVersion();
                    }
                });
        for (Map.Entry<byte[], Long> result : results.entrySet()) {
            // This is the "phoenix.jar" is in-place, but server is out-of-sync with client case.
            if (!isCompatible(result.getValue())) {
                isIncompatible = true;
                HRegionLocation name = regionMap.get(result.getKey());
                buf.append(name);
                buf.append(';');
            }
            hasInvalidIndexConfiguration |= isInvalidMutableIndexConfig(result.getValue());
            if (minHBaseVersion > MetaDataUtil.decodeHBaseVersion(result.getValue())) {
                minHBaseVersion = MetaDataUtil.decodeHBaseVersion(result.getValue());
            }
        }
        lowestClusterHBaseVersion = minHBaseVersion;
    } catch (SQLException e) {
        throw e;
    } catch (Throwable t) {
        // This is the case if the "phoenix.jar" is not on the classpath of HBase on the region server
        throw new SQLExceptionInfo.Builder(SQLExceptionCode.INCOMPATIBLE_CLIENT_SERVER_JAR).setRootCause(t)
                .setMessage("Ensure that " + QueryConstants.DEFAULT_COPROCESS_PATH
                        + " is put on the classpath of HBase in every region server: " + t.getMessage())
                .build().buildException();
    }
    if (isIncompatible) {
        buf.setLength(buf.length() - 1);
        throw new SQLExceptionInfo.Builder(SQLExceptionCode.OUTDATED_JARS).setMessage(buf.toString()).build()
                .buildException();
    }
}

From source file:com.cinchapi.concourse.server.ConcourseServer.java

@Override
@ThrowsThriftExceptions//  w  w  w  .j av a2 s.c o m
public Map<Diff, Set<TObject>> diffKeyRecordStartEnd(String key, long record, long start, long end,
        AccessToken creds, TransactionToken transaction, String environment) throws TException {
    checkAccess(creds, transaction);
    AtomicSupport store = getStore(transaction, environment);
    AtomicOperation atomic = null;
    Set<TObject> startValues = null;
    Set<TObject> endValues = null;
    while (atomic == null || !atomic.commit()) {
        atomic = store.startAtomicOperation();
        try {
            startValues = store.select(key, record, start);
            endValues = store.select(key, record, end);
        } catch (AtomicStateException e) {
            atomic = null;
        }
    }
    Map<Diff, Set<TObject>> result = Maps.newHashMapWithExpectedSize(2);
    Set<TObject> xor = Sets.symmetricDifference(startValues, endValues);
    int expectedSize = xor.size() / 2;
    Set<TObject> added = Sets.newHashSetWithExpectedSize(expectedSize);
    Set<TObject> removed = Sets.newHashSetWithExpectedSize(expectedSize);
    for (TObject current : xor) {
        if (!startValues.contains(current))
            added.add(current);
        else {
            removed.add(current);
        }
    }
    if (!added.isEmpty()) {
        result.put(Diff.ADDED, added);
    }
    if (!removed.isEmpty()) {
        result.put(Diff.REMOVED, removed);
    }
    return result;
}

From source file:de.iteratec.iteraplan.businesslogic.service.legacyExcel.ExcelImportServiceImpl.java

@SuppressWarnings("PMD.ExcessiveMethodLength")
void createBuildingBlockRelations(InformationSystemRelease isr, Map<String, CellValueHolder> relations,
        Locale locale) {/*from   w w w  .jav a2s  .  c  om*/
    // Parent
    CellValueHolder hierarchyNameCellValueHolder = relations
            .get(getHierarchyHeaderFor(Constants.BB_INFORMATIONSYSTEMRELEASE_PLURAL, locale));
    // cannot use setParentRelation(isr, hierarchyNameCellValueHolder) here, because of type incompatibility
    if (hierarchyNameCellValueHolder != null) {
        String hierarchyName = hierarchyNameCellValueHolder.getAttributeValue();
        String hierarchyCellRef = ExcelImportUtilities.getCellRef(hierarchyNameCellValueHolder.getOriginCell());
        String parentNameFromHierarchicalName = getParentNameFromHierarchicalName(hierarchyName,
                isr.getNonHierarchicalName(), hierarchyCellRef);
        BuildingBlock parentNew = getBuildingBlockByName(isr.getTypeOfBuildingBlock(),
                parentNameFromHierarchicalName,
                ExcelImportUtilities.getCellRef(hierarchyNameCellValueHolder.getOriginCell()));
        if (parentNew != null) {
            isr.addParent((InformationSystemRelease) parentNew);
        }
    }

    CellValueHolder predecessorsCellValueHolder = relations
            .get(MessageAccess.getStringOrNull(Constants.ASSOC_PREDECESSORS, locale));
    if (predecessorsCellValueHolder != null) {
        Set<InformationSystemRelease> preds = loadBuildingBlocksAsSet(
                TypeOfBuildingBlock.INFORMATIONSYSTEMRELEASE, predecessorsCellValueHolder);
        isr.removePredecessors();
        isr.addPredecessors(preds);
    }

    CellValueHolder successorsCellValueHolder = relations
            .get(MessageAccess.getStringOrNull(Constants.ASSOC_SUCCESSORS, locale));
    if (successorsCellValueHolder != null) {
        Set<InformationSystemRelease> succs = loadBuildingBlocksAsSet(
                TypeOfBuildingBlock.INFORMATIONSYSTEMRELEASE, successorsCellValueHolder);
        isr.removeSuccessors();
        isr.addSuccessors(succs);
    }

    CellValueHolder bfCellValueHolder = relations
            .get(MessageAccess.getStringOrNull(Constants.BB_BUSINESSFUNCTION_PLURAL, locale));
    if (bfCellValueHolder != null) {
        Set<BusinessFunction> bfs = loadBuildingBlocksAsSet(TypeOfBuildingBlock.BUSINESSFUNCTION,
                bfCellValueHolder);
        isr.removeBusinessFunctions();
        isr.addBusinessFunctions(bfs);
    }

    // Interfaces (not imported, just warn user)
    // Reason: We can't uniquely identify an Interface by its "name", since multiple ISIs with the same 2 ISRs can exist
    CellValueHolder interfacesCellValueHolder = relations.get(MessageAccess
            .getStringOrNull("reporting.excel.header.informationSystemRelease.interfacesTo", locale));
    if (interfacesCellValueHolder != null) {
        String interfaces = interfacesCellValueHolder.getAttributeValue();
        String ifaceCellRef = ExcelImportUtilities.getCellRef(interfacesCellValueHolder.getOriginCell());
        if (!StringUtils.isEmpty(interfaces)) {
            getProcessingLog().warn(
                    "{0} has interfaces specified in cell [{1}] in the InformationSystemRelease sheet. These were not imported. Only Interfaces listed in the Interfaces sheet are imported.",
                    isr.getNonHierarchicalName(), ifaceCellRef);
        }
    }

    CellValueHolder boCellValueHolder = relations
            .get(MessageAccess.getStringOrNull(Constants.BB_BUSINESSOBJECT_PLURAL, locale));
    if (boCellValueHolder != null) {
        Set<BusinessObject> bos = loadBuildingBlocksAsSet(TypeOfBuildingBlock.BUSINESSOBJECT,
                boCellValueHolder);
        Set<Isr2BoAssociation> associations = Sets.newHashSetWithExpectedSize(bos.size());
        Set<Isr2BoAssociation> existentAssociations = isr.getBusinessObjectAssociations();
        for (BusinessObject bo : bos) {
            Isr2BoAssociation assoc = BuildingBlockFactory.createIsr2BoAssociation(isr, bo);
            // try to find out whether that association exists already, and if yes, use the existing object
            for (Isr2BoAssociation connectedAssoc : existentAssociations) {
                if (assoc.equals(connectedAssoc)) {
                    assoc = connectedAssoc;
                    break;
                }
            }
            associations.add(assoc);
        }
        buildingBlockServiceLocator.getIsr2BoAssociationService().saveAssociations(associations);
        isr.connectIsr2BoAssociations(associations);
    }

    // Business Mapping
    TypeOfBuildingBlock[] orderOfBMContent = { TypeOfBuildingBlock.BUSINESSPROCESS, TypeOfBuildingBlock.PRODUCT,
            TypeOfBuildingBlock.BUSINESSUNIT };
    CellValueHolder allBMCellValueHolder = relations.get(getBusinessMappingHeaderKey(orderOfBMContent, locale));
    if (allBMCellValueHolder != null) {
        String allBMs = allBMCellValueHolder.getAttributeValue();
        String bmCellRef = ExcelImportUtilities.getCellRef(allBMCellValueHolder.getOriginCell());
        if (StringUtils.isNotEmpty(allBMs)) {
            getProcessingLog().warn(
                    "Information System {0} has business mappings specified in cell [{1}]. These were not imported. Only Business Mappings listed in the Business Mappings sheet are imported.",
                    isr.getNonHierarchicalName(), bmCellRef);
        }
    }

    CellValueHolder isdCellValueHolder = relations
            .get(MessageAccess.getStringOrNull(Constants.BB_INFORMATIONSYSTEMDOMAIN_PLURAL, locale));
    if (isdCellValueHolder != null) {
        Set<InformationSystemDomain> isds = loadBuildingBlocksAsSet(TypeOfBuildingBlock.INFORMATIONSYSTEMDOMAIN,
                isdCellValueHolder);
        isr.removeInformationSystemDomains();
        isr.addInformationSystemDomains(isds);
    }

    CellValueHolder ieCellValueHolder = relations
            .get(MessageAccess.getStringOrNull(Constants.BB_INFRASTRUCTUREELEMENT_PLURAL, locale));
    if (ieCellValueHolder != null) {
        Set<InfrastructureElement> ies = loadBuildingBlocksAsSet(TypeOfBuildingBlock.INFRASTRUCTUREELEMENT,
                ieCellValueHolder);
        isr.removeInfrastructureElements();
        isr.addInfrastructureElements(ies);
    }

    CellValueHolder projectsCellValueHolder = relations
            .get(MessageAccess.getStringOrNull(Constants.BB_PROJECT_PLURAL, locale));
    if (projectsCellValueHolder != null) {
        Set<Project> projs = loadBuildingBlocksAsSet(TypeOfBuildingBlock.PROJECT, projectsCellValueHolder);
        isr.removeProjects();
        isr.addProjects(projs);
    }

    CellValueHolder tcrCellValueHolder = relations
            .get(MessageAccess.getStringOrNull(Constants.BB_TECHNICALCOMPONENTRELEASE_PLURAL, locale));
    if (tcrCellValueHolder != null) {
        Set<TechnicalComponentRelease> tcrs = loadBuildingBlocksAsSet(
                TypeOfBuildingBlock.TECHNICALCOMPONENTRELEASE, tcrCellValueHolder);
        isr.removeTechnicalComponentReleases();
        isr.addTechnicalComponentReleases(tcrs);
    }

    // Uses ISs
    CellValueHolder isCellValueHolder = relations.get(MessageAccess.getStringOrNull(
            ExcelConstants.HEADER_INFORMATIONSYSTEMRELEASE_SHEET_BASECOMPONENTS_COLUMN, locale));
    if (isCellValueHolder != null) {
        Set<InformationSystemRelease> iss = loadBuildingBlocksAsSet(
                TypeOfBuildingBlock.INFORMATIONSYSTEMRELEASE, isCellValueHolder);
        isr.removeBaseComponents();
        isr.addBaseComponents(iss);
    }

    getInformationSystemReleaseService().saveOrUpdate(isr);
}