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:org.eclipse.viatra.addon.querybasedfeatures.runtime.QueryBasedFeatureSettingDelegateFactory.java

public QueryBasedFeatureSettingDelegateFactory() {
    engineMap = new WeakHashMap<Notifier, WeakReference<AdvancedViatraQueryEngine>>();
    specificationMap = new HashMap<>();
    delayedFeatures = ArrayListMultimap.create();
}

From source file:com.github.cbismuth.fdupes.container.mutable.MultimapCollector.java

@Override
public Supplier<Multimap<K, V>> supplier() {
    return () -> synchronizedListMultimap(ArrayListMultimap.create());
}

From source file:org.sonar.plugins.pitest.Mutant.java

public static String toJSON(List<Mutant> mutants) {
    Multimap<Integer, String> mutantsByLine = ArrayListMultimap.create();

    for (Mutant mutant : mutants) {
        mutantsByLine.put(mutant.getLineNumber(), mutant.toJSON());
    }/*from  w  ww. j av  a 2s. co m*/

    StringBuilder builder = new StringBuilder();
    builder.append("{");
    boolean first = true;
    for (int line : mutantsByLine.keySet()) {
        if (!first) {
            builder.append(",");
        }
        first = false;
        builder.append("\"");
        builder.append(line);
        builder.append("\":[");
        builder.append(Joiner.on(",").join(mutantsByLine.get(line)));
        builder.append("]");
    }
    builder.append("}");

    return builder.toString();
}

From source file:org.opensaml.saml.common.profile.impl.ChainingNameIdentifierGenerator.java

/** Constructor. */
public ChainingNameIdentifierGenerator() {
    nameIdGeneratorMap = ArrayListMultimap.create();
}

From source file:com.android.build.gradle.integration.common.truth.NativeAndroidProjectSubject.java

@NonNull
private Multimap<String, NativeArtifact> getArtifactsGroupedByGroupName() {
    Multimap<String, NativeArtifact> groupToArtifacts = ArrayListMultimap.create();
    for (NativeArtifact artifact : getSubject().getArtifacts()) {
        groupToArtifacts.put(artifact.getGroupName(), artifact);
    }/* w ww .  ja v  a2 s .  c o  m*/
    return groupToArtifacts;
}

From source file:org.yakindu.sct.simulation.core.sexec.interpreter.DefaultOperationMockup.java

public void reset() {
    mockReturn = new MockReturnMap();
    verifyCalls = ArrayListMultimap.create();
}

From source file:me.abje.lingua.parser.expr.ClassExpr.java

@Override
public Obj evaluate(Interpreter interpreter) {
    ClassObj superClass = (ClassObj) interpreter.getEnv().get(superClassName);
    ListMultimap<String, FunctionObj> objs = ArrayListMultimap.create();
    for (Expr expr : functions) {
        FunctionObj obj = (FunctionObj) interpreter.next(expr);
        objs.put(obj.getName(), obj);//from  w  w  w. j  a  va 2 s . co  m
    }

    Map<String, Obj> flattened = new HashMap<>();
    for (Map.Entry<String, Collection<FunctionObj>> entry : objs.asMap().entrySet()) {
        String name = entry.getKey();
        Collection<FunctionObj> possibilities = entry.getValue();
        flattened.put(name, new SyntheticFunctionObj(FunctionObj.SYNTHETIC) {
            @Override
            public Obj call(Interpreter interpreter, List<Obj> args) {
                for (FunctionObj function : possibilities) {
                    Obj result;
                    interpreter.getEnv().pushFrame("<" + function.getName() + ":args>");
                    if (function.isApplicable(interpreter, args)) {
                        interpreter.getEnv().popFrame();
                        result = function.withSelf(getSelf()).call(interpreter, args);
                        return result;
                    } else {
                        interpreter.getEnv().popFrame();
                    }
                }

                if (superClass.getFunctionMap().containsKey(name) && !name.equals("init")) {
                    return superClass.getMember(interpreter, name).call(interpreter, args);
                } else {
                    throw new InterpreterException("CallException", "invalid arguments for function " + name);
                }
            }
        });
    }
    ClassObj clazz = new ClassObj(name, flattened, fields, superClass);
    interpreter.getEnv().define(name, clazz);
    return clazz;
}

From source file:org.elasticsearch.cassandra.cluster.routing.PrimaryFirstSearchStrategy.java

@Override
public AbstractSearchStrategy.Result topology(String ksName, Collection<InetAddress> startedShards) {

    Predicate<InetAddress> isLocalDC = new Predicate<InetAddress>() {
        String localDC = DatabaseDescriptor.getEndpointSnitch()
                .getDatacenter(FBUtilities.getBroadcastAddress());

        public boolean apply(InetAddress address) {
            String remoteDC = DatabaseDescriptor.getEndpointSnitch().getDatacenter(address);
            return remoteDC.equals(localDC);
        }/*from  w ww.ja  v a2  s .com*/
    };

    Set<InetAddress> localLiveNodes = Sets
            .newHashSet(Collections2.filter(Gossiper.instance.getLiveTokenOwners(), isLocalDC));
    Set<InetAddress> localUnreachableNodes = Sets
            .newHashSet(Collections2.filter(Gossiper.instance.getUnreachableTokenOwners(), isLocalDC));
    Map<Range<Token>, List<InetAddress>> allRanges = StorageService.instance
            .getRangeToAddressMapInLocalDC(ksName);

    Multimap<InetAddress, Range<Token>> topo = ArrayListMultimap.create();
    Set<Range<Token>> orphanRanges = new HashSet<Range<Token>>();
    boolean consistent = true;

    // get live primary token ranges
    for (InetAddress node : localLiveNodes) {
        if (startedShards.contains(node)) {
            topo.putAll(node, StorageService.instance.getPrimaryRangeForEndpointWithinDC(ksName, node));
        } else {
            localUnreachableNodes.add(node);
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("keyspace={} live nodes={}, primary ranges map = {}", ksName, localLiveNodes, topo);
    }

    // pickup random live replica for primary range owned by unreachable or not started nodes.
    if (localUnreachableNodes.size() > 0) {
        if (logger.isDebugEnabled()) {
            logger.debug("unreachableNodes = {} ", localUnreachableNodes);
        }
        Random rnd = new Random();
        for (InetAddress node : localUnreachableNodes) {
            for (Range<Token> orphanRange : StorageService.instance.getPrimaryRangeForEndpointWithinDC(ksName,
                    node)) {
                Set<InetAddress> replicaEndPoints = new HashSet<InetAddress>();
                for (Range range : allRanges.keySet()) {
                    if (range.contains(orphanRange)) {
                        replicaEndPoints.addAll(allRanges.get(range));
                    }
                }
                replicaEndPoints.removeAll(localUnreachableNodes);
                if (replicaEndPoints.size() == 0) {
                    consistent = false;
                    orphanRanges.add(orphanRange);
                    logger.warn("Inconsistent search for keyspace {}, no alive node having range {}", ksName,
                            orphanRange);
                } else {
                    InetAddress[] replicas = replicaEndPoints.toArray(new InetAddress[replicaEndPoints.size()]);
                    InetAddress liveReplica = replicas[rnd.nextInt(replicas.length)];
                    topo.put(liveReplica, orphanRange);
                    logger.debug("orphanRanges {} available on = {} ", orphanRanges, liveReplica);
                }
            }
        }
    }

    if (logger.isDebugEnabled()) {
        logger.debug("topology for keyspace {} = {}, consistent={} unreachableNodes={} orphanRanges={}", ksName,
                topo.asMap(), consistent, localUnreachableNodes, orphanRanges);
    }
    return new AbstractSearchStrategy.Result(topo.asMap(), orphanRanges, localUnreachableNodes, allRanges);
}

From source file:org.wso2.carbon.mss.example.hook.AbstractBasicAuthInterceptor.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];
                String password = authParts[1];
                if (authenticate(username, password)) {
                    return true;
                }// w ww  . j  a  v a  2 s  . co  m
            }

        }
    }
    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.opentestsystem.shared.security.service.RoleSpecificPermissionsService.java

@Override
protected Multimap<String, SbacRole> buildRolesFromParsedStrings(
        final Map<String, RoleToPermissionMapping> inRoleToPermissionMappings,
        final List<String[]> inRoleStrings) {
    Multimap<String, SbacRole> retRoles = ArrayListMultimap.create();
    Multimap<String, SbacPermission> roleNamesToLookFor = permissionResolver.getRoleBindings(componentName);
    if (inRoleStrings != null && roleNamesToLookFor != null) {
        for (String[] roleAttributes : inRoleStrings) {
            SbacRole role = extractRole(roleAttributes);
            if (roleNamesToLookFor.keySet().contains(role.getRoleName())) {
                role.setIsApplicableToTenant(true);
                role.setPermissions(roleNamesToLookFor.get(role.getRoleName()));
                retRoles.put(role.getRoleName(), role);
            }//from   w ww.j  av a  2s.  co  m
        }
    }
    return retRoles;
}