Example usage for com.google.common.collect ArrayListMultimap create

List of usage examples for com.google.common.collect ArrayListMultimap create

Introduction

In this page you can find the example usage for com.google.common.collect ArrayListMultimap create.

Prototype

public static <K, V> ArrayListMultimap<K, V> create() 

Source Link

Document

Creates a new, empty ArrayListMultimap with the default initial capacities.

Usage

From source file:eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.TargetNodeImpl.java

/**
 * Create a target node that is populated with assignments and children
 * according to the given parameters.//from ww  w  .ja v  a2 s.  c  o  m
 * 
 * @param entity the associated definition
 * @param cells the cells associated with this node or its children
 * @param parentType the type representing the root
 * @param depth the depth down from the root node
 * @param parent the parent node
 */
public TargetNodeImpl(EntityDefinition entity, Collection<CellNode> cells, TypeDefinition parentType, int depth,
        GroupNode parent) {
    super(parent);
    this.entity = entity;

    // partition cells by child
    ListMultimap<EntityDefinition, CellNode> childCells = ArrayListMultimap.create();
    // ... and for this node
    SetMultimap<CellNode, String> assignSet = HashMultimap.create();
    for (CellNode cell : cells) {
        for (Entry<String, ?> entry : cell.getCell().getTarget().asMap().entrySet()) {
            String name = entry.getKey();
            @SuppressWarnings("unchecked")
            Collection<? extends Entity> entities = (Collection<? extends Entity>) entry.getValue();

            for (Entity target : entities) {
                if (target.getDefinition().getType().equals(parentType)) {
                    List<ChildContext> path = target.getDefinition().getPropertyPath();
                    if (path.get(depth - 1).getChild().equals(entity.getDefinition())) {
                        if (path.size() <= depth) {
                            // this cell belongs to this node
                            assignSet.put(cell, name);
                            cell.addTarget(this);
                        } else {
                            // this cell belongs to a child node
                            childCells.put(AlignmentUtil.deriveEntity(target.getDefinition(), depth + 1), cell);
                        }
                    }
                }
            }
        }
    }

    assignments = Multimaps.unmodifiableSetMultimap(assignSet);

    // create child cells
    List<TargetNode> childList = new ArrayList<TargetNode>();
    for (Entry<EntityDefinition, Collection<CellNode>> childEntry : childCells.asMap().entrySet()) {
        TargetNode childNode = new TargetNodeImpl(childEntry.getKey(), childEntry.getValue(), parentType,
                depth + 1, this);
        childList.add(childNode);
    }

    children = Collections.unmodifiableList(childList);
}

From source file:com.github.rinde.logistics.pdptw.solver.optaplanner.ScoreCalculator.java

@Override
public void resetWorkingSolution(@SuppressWarnings("null") PDPSolution workingSolution) {
    // System.out.println("resetWorkingSolution: \n" + workingSolution);
    solution = workingSolution;//from   ww  w. jav a2  s  .c  o m

    unplannedParcelVisits = new LinkedHashSet<>(workingSolution.parcelList);
    changedVehicles = new LinkedHashSet<>();
    routes = ArrayListMultimap.create();
    routeHardScores = new Object2LongOpenHashMap<>();
    routeSoftScores = new Object2LongOpenHashMap<>();
    startTime = workingSolution.getStartTime();

    final int numVisits = workingSolution.parcelList.size();
    final int numVehicles = workingSolution.vehicleList.size();
    final int size = numVisits + numVehicles;
    doneTimes = new Object2LongOpenHashMap<>(size);
    travelTimes = new Object2LongOpenHashMap<>(size);
    tardiness = new Object2LongOpenHashMap<>(size);

    pickupOwner = new LinkedHashMap<>(numVisits);
    deliveryOwner = new LinkedHashMap<>(numVisits);

    hardScore = -MISSING_VISIT_PENALTY * unplannedParcelVisits.size();
    softScore = 0;
    for (final Vehicle v : workingSolution.vehicleList) {
        updateCurRoute(v);
        updateRoute(v, v.getNextVisit());
    }

    // System.out.println(" > " + softScore);
}

From source file:com.mgmtp.perfload.perfalyzer.reportpreparation.PerfMonReportPreparationStrategy.java

@Override
public void processFiles(final File sourceDir, final File destDir, final List<PerfAlyzerFile> files)
        throws IOException {

    ListMultimap<String, PerfAlyzerFile> byTypeAndHostMultimapAggregated = ArrayListMultimap.create();
    ListMultimap<String, PerfAlyzerFile> byTypeAndHostMultimap = ArrayListMultimap.create();

    for (PerfAlyzerFile f : files) {
        log.info("Processing file '{}'...", f);

        // strip all numbers in order to group by type, e. g.
        // java_0_ --> java
        // java_1_ --> java
        // io_0_w --> io_w
        // io_0_r --> io_r
        String tmp = f.getFileNameParts().get(1).replaceAll("_\\d+", "");
        PerfAlyzerFile destFile = f.copy();
        destFile.getFileNameParts().set(1, tmp);

        String key = destFile.getFile().getPath();

        if ("aggregated".equals(getLast(f.getFileNameParts()))) {
            // CSV for HTML tables
            key = key.replace("[aggregated]", "");
            byTypeAndHostMultimapAggregated.put(key, f);
        } else {//from w  ww.  ja  v a2 s .com
            // PNGs
            // already change extension here
            key = removeExtension(key) + ".png";
            byTypeAndHostMultimap.put(key, f);
        }
    }

    createCsvFiles(sourceDir, destDir, byTypeAndHostMultimapAggregated);
    createPlots(sourceDir, destDir, byTypeAndHostMultimap);
}

From source file:com.google.devtools.build.lib.rules.platform.Platform.java

private ImmutableMap<ConstraintSettingInfo, ConstraintValueInfo> validateConstraints(RuleContext ruleContext,
        Iterable<ConstraintValueInfo> constraintValues) {
    Multimap<ConstraintSettingInfo, ConstraintValueInfo> constraints = ArrayListMultimap.create();

    for (ConstraintValueInfo constraintValue : constraintValues) {
        constraints.put(constraintValue.constraint(), constraintValue);
    }//from w  w  w  .ja va2s  . c  om

    // Are there any settings with more than one value?
    boolean foundError = false;
    for (ConstraintSettingInfo constraintSetting : constraints.keySet()) {
        if (constraints.get(constraintSetting).size() > 1) {
            foundError = true;
            // error
            StringBuilder constraintValuesDescription = new StringBuilder();
            for (ConstraintValueInfo constraintValue : constraints.get(constraintSetting)) {
                if (constraintValuesDescription.length() > 0) {
                    constraintValuesDescription.append(", ");
                }
                constraintValuesDescription.append(constraintValue.label());
            }
            ruleContext.attributeError(PlatformRule.CONSTRAINT_VALUES_ATTR,
                    String.format("Duplicate constraint_values for constraint_setting %s: %s",
                            constraintSetting.label(), constraintValuesDescription.toString()));
        }
    }

    if (foundError) {
        return null;
    }

    // Convert to a flat map.
    ImmutableMap.Builder<ConstraintSettingInfo, ConstraintValueInfo> builder = new ImmutableMap.Builder<>();
    for (ConstraintSettingInfo constraintSetting : constraints.keySet()) {
        ConstraintValueInfo constraintValue = Iterables.getOnlyElement(constraints.get(constraintSetting));
        builder.put(constraintSetting, constraintValue);
    }

    return builder.build();
}

From source file:uk.ac.ebi.metabolomes.webservices.eutils.ELinkXMLResponseParser.java

private ListMultimap<String, String> parseLinkSetEntry(XMLStreamReader2 xmlr) throws XMLStreamException {
    int event;/*from  w  w w  . j  a v a  2s  .c o  m*/
    ListMultimap<String, String> multiMap = ArrayListMultimap.create();
    String pchemcompID = null;
    loop1: while (xmlr.hasNext()) {
        event = xmlr.next();

        switch (event) {
        case XMLEvent.START_DOCUMENT:
            break;
        case XMLEvent.START_ELEMENT:
            if (xmlr.getLocalName().equalsIgnoreCase("IdList")) {
                pchemcompID = parseIDFollowingIDTag(xmlr);
            } else if (xmlr.getLocalName().equalsIgnoreCase("LinkSetDb")) {
                List<String> pchemSubs = parseLinkSetDB(xmlr);
                if (pchemcompID != null && pchemcompID.length() > 0) {
                    for (String substance : pchemSubs) {
                        multiMap.put(pchemcompID, substance);
                    }
                    //pchemcompID = null;
                } else {
                    LOGGER.warn("Got substance ids but compound id is null or empty and it shouldn't!!!");
                }
            }
            break;
        case XMLEvent.END_ELEMENT:
            if (xmlr.getLocalName().equalsIgnoreCase("LinkSet"))
                break loop1;
            break;
        }
    }
    return multiMap;
}

From source file:com.jivesoftware.os.miru.plugin.index.BloomIndex.java

public <V extends HasValue> List<Mights<V>> wantBits(List<V> keys) {
    ListMultimap<Integer, Might<V>> valueBitIndexes = ArrayListMultimap.create();
    for (V key : keys) {
        Might<V> might = new Might<>(key, numHashFunctions);
        int[] bitIndexes = new int[numHashFunctions];
        createBitIndexesForValue(key.getBloomValue(), numHashFunctions, bitIndexes, 0);
        Arrays.sort(bitIndexes);//w  w w.  j  a  va 2  s . c o m
        for (Integer bitIndex : bitIndexes) {
            valueBitIndexes.put(bitIndex, might);
        }
    }

    List<Mights<V>> mights = new ArrayList<>();
    for (Integer key : valueBitIndexes.keySet()) {
        mights.add(new Mights<>(key, valueBitIndexes.get(key)));
    }
    Collections.sort(mights);
    return mights;
}

From source file:eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.TransformationTreeImpl.java

/**
 * Create a transformation tree based on a type cell.
 * /*from  w  w w  .j  a  va2s  .c  om*/
 * @param alignment the alignment holding the cells
 * @param typeCell the type cell this tree is representing
 */
public TransformationTreeImpl(Alignment alignment, Cell typeCell) {
    super(null);
    this.typeCell = typeCell;
    this.type = ((Type) CellUtil.getFirstEntity(typeCell.getTarget())).getDefinition().getDefinition();

    sourceNodes = new SourceNodeFactory();

    Collection<? extends Cell> cells = getRelevantPropertyCells(alignment, typeCell);

    // partition cells by child
    ListMultimap<EntityDefinition, CellNode> childCells = ArrayListMultimap.create();
    for (Cell cell : cells) {
        cell = AlignmentUtil.reparentCell(cell, typeCell, true);
        if (cell == null)
            throw new IllegalStateException("Illegal cell found.");
        CellNode node = new CellNodeImpl(cell, sourceNodes);
        for (Entity target : cell.getTarget().values()) {
            EntityDefinition targetDef = target.getDefinition();
            List<ChildContext> path = targetDef.getPropertyPath();
            if (path != null && !path.isEmpty()) {
                // store cell with child
                childCells.put(AlignmentUtil.deriveEntity(targetDef, 1), node);
            }
        }
    }

    // create child cells
    List<TargetNode> childList = new ArrayList<TargetNode>();
    for (Entry<EntityDefinition, Collection<CellNode>> childEntry : childCells.asMap().entrySet()) {
        TargetNode childNode = new TargetNodeImpl(childEntry.getKey(), childEntry.getValue(), type, 1, this);
        childList.add(childNode);
    }

    children = Collections.unmodifiableList(childList);
}

From source file:org.codice.ddf.internal.country.converter.local.LocalCountryCodeConverter.java

public void setCountryCodeMappingsFile(String countryCodeMappingFile) {
    if (StringUtils.isNotBlank(countryCodeMappingFile)) {
        fipsToIso3Map = ArrayListMultimap.create();
        iso3ToFipsMap = ArrayListMultimap.create();
        Map<String, String> countryCodesMap = PropertiesLoader
                .toMap(PropertiesLoader.loadProperties(countryCodeMappingFile));
        for (Map.Entry<String, String> countryMappingEntry : countryCodesMap.entrySet()) {
            List<String> mappedCountries = Splitter.on(',').splitToList(countryMappingEntry.getValue());
            for (String isoCountry : mappedCountries) {
                String newCountry = countryMappingEntry.getKey();
                fipsToIso3Map.put(newCountry, isoCountry);
                iso3ToFipsMap.put(isoCountry, newCountry);
            }//from   w  w w.  ja v  a2  s . c om
        }
    }
    if (fipsToIso3Map.isEmpty() || iso3ToFipsMap.isEmpty()) {
        LOGGER.warn("Country code maps are empty. Verify the 'fipsToIso.properties' file is "
                + "located in the $DDF_HOME/etc/ directory and contains valid country code " + "mappings.");
    }
}

From source file:org.wso2.carbon.jaas.authinterceptor.BasicAuthInterceptor.java

@Override
public boolean preCall(HttpRequest request, HttpResponder responder, ServiceMethodInfo serviceMethodInfo) {

    HttpHeaders headers = request.headers();
    if (headers != null) {
        String authHeader = headers.get(HttpHeaders.Names.AUTHORIZATION);
        if (authHeader != null) {
            String authType = authHeader.substring(0, AUTH_TYPE_BASIC_LENGTH);
            String authEncoded = authHeader.substring(AUTH_TYPE_BASIC_LENGTH).trim();
            if (AUTH_TYPE_BASIC.equals(authType) && !authEncoded.isEmpty()) {
                byte[] decodedByte = authEncoded.getBytes(Charset.forName("UTF-8"));
                String authDecoded = new String(Base64.getDecoder().decode(decodedByte),
                        Charset.forName("UTF-8"));
                String[] authParts = authDecoded.split(":");

                String username = authParts[0];
                char[] password;
                if (authParts[1] != null && !authParts[1].isEmpty()) {
                    password = authParts[1].toCharArray();
                } else {
                    password = new char[0];
                }//from  w  w w  .  j  a  va2s. com

                if (authenticate(username, password)) {
                    return true;
                }
            }
        }
    }
    Multimap<String, String> map = ArrayListMultimap.create();
    map.put(HttpHeaders.Names.WWW_AUTHENTICATE, AUTH_TYPE_BASIC);
    responder.sendStatus(HttpResponseStatus.UNAUTHORIZED, map);
    return false;
}

From source file:org.apache.drill.exec.physical.impl.broadcastsender.BroadcastSenderRootExec.java

public BroadcastSenderRootExec(FragmentContext context, RecordBatch incoming, BroadcastSender config)
        throws OutOfMemoryException {
    super(context, context.newOperatorContext(config, null, false), config);
    this.ok = true;
    this.context = context;
    this.incoming = incoming;
    this.config = config;
    this.handle = context.getHandle();
    List<MinorFragmentEndpoint> destinations = config.getDestinations();
    ArrayListMultimap<DrillbitEndpoint, Integer> dests = ArrayListMultimap.create();

    for (MinorFragmentEndpoint destination : destinations) {
        dests.put(destination.getEndpoint(), destination.getId());
    }//from w  ww .j  a va  2  s .c o m

    int destCount = dests.keySet().size();
    int i = 0;

    this.tunnels = new AccountingDataTunnel[destCount];
    this.receivingMinorFragments = new int[destCount][];
    for (DrillbitEndpoint ep : dests.keySet()) {
        List<Integer> minorsList = dests.get(ep);
        int[] minorsArray = new int[minorsList.size()];
        int x = 0;
        for (Integer m : minorsList) {
            minorsArray[x++] = m;
        }
        receivingMinorFragments[i] = minorsArray;
        tunnels[i] = context.getDataTunnel(ep);
        i++;
    }
}