Example usage for com.google.common.collect Multimaps unmodifiableMultimap

List of usage examples for com.google.common.collect Multimaps unmodifiableMultimap

Introduction

In this page you can find the example usage for com.google.common.collect Multimaps unmodifiableMultimap.

Prototype

@Deprecated
public static <K, V> Multimap<K, V> unmodifiableMultimap(ImmutableMultimap<K, V> delegate) 

Source Link

Document

Simply returns its argument.

Usage

From source file:ca.sqlpower.object.annotation.SPClassVisitor.java

/**
 * Returns the {@link Multimap} of JavaBean setter method names that mutate
 * persistable properties, mapped to the method's thrown types.
 *///from www.  j  av  a2s.c  o  m
public Multimap<String, Class<? extends Exception>> getMutatorThrownTypes() {
    return Multimaps.unmodifiableMultimap(mutatorThrownTypes);
}

From source file:org.cloudsmith.geppetto.validation.runner.AllModuleReferences.java

/**
 * Creates an empty instance.
 */
public AllModuleReferences() {
    restricted = Multimaps.unmodifiableMultimap(EmptyRestricted);
}

From source file:org.apache.tez.history.parser.datamodel.TaskInfo.java

/**
 * Get the set of containers on which the task attempts ran for this task
 *
 * @return Multimap<Container, TaskAttemptInfo> task attempt details at container level
 */// w ww  .  j av a  2s .  c om
public final Multimap<Container, TaskAttemptInfo> getContainersMapping() {
    Multimap<Container, TaskAttemptInfo> containerMapping = LinkedHashMultimap.create();
    for (TaskAttemptInfo attemptInfo : getTaskAttempts()) {
        containerMapping.put(attemptInfo.getContainer(), attemptInfo);
    }
    return Multimaps.unmodifiableMultimap(containerMapping);
}

From source file:org.apache.shindig.gadgets.http.HttpResponse.java

/**
 * Construct an HttpResponse from a builder (called by HttpResponseBuilder.create).
 *///from   w  w w .  ja v  a2 s .  c o m
HttpResponse(HttpResponseBuilder builder) {
    httpStatusCode = builder.getHttpStatusCode();
    Multimap<String, String> headerCopy = HttpResponse.newHeaderMultimap();

    // Always safe, HttpResponseBuilder won't modify the body.
    responseBytes = builder.getResponse();

    // Copy headers after builder.getResponse(), since that can modify Content-Type.
    headerCopy.putAll(builder.getHeaders());

    Map<String, String> metadataCopy = Maps.newHashMap(builder.getMetadata());
    metadata = Collections.unmodifiableMap(metadataCopy);

    // We want to modify the headers to ensure that the proper Content-Type and Date headers
    // have been set. This allows us to avoid these expensive calculations from the cache.
    date = getAndUpdateDate(headerCopy);
    encoding = getAndUpdateEncoding(headerCopy, responseBytes);
    headers = Multimaps.unmodifiableMultimap(headerCopy);
}

From source file:com.blurengine.blur.framework.ModuleManager.java

/**
 * Returns an unmodifiable map of all the registered module classes and their instances in this container.
 *
 * @return a map of classes and their module instances
 *///from w  w  w. ja v a2s. c o m
public Multimap<Class<? extends Module>, Module> getModules() {
    return Multimaps.unmodifiableMultimap(this.modules);
}

From source file:brooklyn.entity.network.bind.BindDnsServerImpl.java

public void update() {
    Lifecycle serverState = getAttribute(Attributes.SERVICE_STATE_ACTUAL);
    if (Lifecycle.STOPPED.equals(serverState) || Lifecycle.STOPPING.equals(serverState)
            || Lifecycle.DESTROYED.equals(serverState) || !getAttribute(Attributes.SERVICE_UP)) {
        LOG.debug("Skipped update of {} when service state is {} and running is {}",
                new Object[] { this, getAttribute(Attributes.SERVICE_STATE_ACTUAL), getAttribute(SERVICE_UP) });
        return;/*w  w  w  .ja  v a  2s  .c  o  m*/
    }
    synchronized (this) {
        Iterable<Entity> availableEntities = FluentIterable.from(getEntities().getMembers())
                .filter(new HasHostnameAndValidLifecycle());
        LOG.debug("{} updating with entities: {}", this, Iterables.toString(availableEntities));
        ImmutableListMultimap<String, Entity> hostnameToEntity = Multimaps.index(availableEntities,
                new HostnameTransformer());

        Map<String, String> octetToName = Maps.newHashMap();
        BiMap<String, String> ipToARecord = HashBiMap.create();
        Multimap<String, String> aRecordToCnames = MultimapBuilder.hashKeys().hashSetValues().build();
        Multimap<String, String> ipToAllNames = MultimapBuilder.hashKeys().hashSetValues().build();

        for (Map.Entry<String, Entity> e : hostnameToEntity.entries()) {
            String domainName = e.getKey();
            Maybe<SshMachineLocation> location = Machines
                    .findUniqueSshMachineLocation(e.getValue().getLocations());
            if (!location.isPresent()) {
                LOG.debug("Member {} of {} does not have an SSH location so will not be configured",
                        e.getValue(), this);
                continue;
            } else if (ipToARecord.inverse().containsKey(domainName)) {
                continue;
            }

            String address = location.get().getAddress().getHostAddress();
            ipToAllNames.put(address, domainName);
            if (!ipToARecord.containsKey(address)) {
                ipToARecord.put(address, domainName);
                if (getReverseLookupNetwork().contains(new Cidr(address + "/32"))) {
                    String octet = Iterables.get(Splitter.on('.').split(address), 3);
                    if (!octetToName.containsKey(octet))
                        octetToName.put(octet, domainName);
                }
            } else {
                aRecordToCnames.put(ipToARecord.get(address), domainName);
            }
        }
        setAttribute(A_RECORDS, ImmutableMap.copyOf(ipToARecord.inverse()));
        setAttribute(PTR_RECORDS, ImmutableMap.copyOf(octetToName));
        setAttribute(CNAME_RECORDS, Multimaps.unmodifiableMultimap(aRecordToCnames));
        setAttribute(ADDRESS_MAPPINGS, Multimaps.unmodifiableMultimap(ipToAllNames));

        // Update Bind configuration files and restart the service
        getDriver().updateBindConfiguration();
    }
}

From source file:org.apache.brooklyn.entity.network.bind.BindDnsServerImpl.java

public void update() {
    Lifecycle serverState = getAttribute(Attributes.SERVICE_STATE_ACTUAL);
    if (Lifecycle.STOPPED.equals(serverState) || Lifecycle.STOPPING.equals(serverState)
            || Lifecycle.DESTROYED.equals(serverState) || !getAttribute(Attributes.SERVICE_UP)) {
        LOG.debug("Skipped update of {} when service state is {} and running is {}",
                new Object[] { this, getAttribute(Attributes.SERVICE_STATE_ACTUAL), getAttribute(SERVICE_UP) });
        return;//from  w  w  w  .j  a v a 2  s .  c om
    }
    synchronized (this) {
        Iterable<Entity> availableEntities = FluentIterable.from(getEntities().getMembers())
                .filter(new HasHostnameAndValidLifecycle());
        LOG.debug("{} updating with entities: {}", this, Iterables.toString(availableEntities));
        ImmutableListMultimap<String, Entity> hostnameToEntity = Multimaps.index(availableEntities,
                new HostnameTransformer());

        Map<String, String> octetToName = Maps.newHashMap();
        BiMap<String, String> ipToARecord = HashBiMap.create();
        Multimap<String, String> aRecordToCnames = MultimapBuilder.hashKeys().hashSetValues().build();
        Multimap<String, String> ipToAllNames = MultimapBuilder.hashKeys().hashSetValues().build();

        for (Map.Entry<String, Entity> e : hostnameToEntity.entries()) {
            String domainName = e.getKey();
            Maybe<SshMachineLocation> location = Machines.findUniqueMachineLocation(e.getValue().getLocations(),
                    SshMachineLocation.class);
            if (!location.isPresent()) {
                LOG.debug("Member {} of {} does not have an SSH location so will not be configured",
                        e.getValue(), this);
                continue;
            } else if (ipToARecord.inverse().containsKey(domainName)) {
                continue;
            }

            String address = location.get().getAddress().getHostAddress();
            ipToAllNames.put(address, domainName);
            if (!ipToARecord.containsKey(address)) {
                ipToARecord.put(address, domainName);
                if (getReverseLookupNetwork().contains(new Cidr(address + "/32"))) {
                    String octet = Iterables.get(Splitter.on('.').split(address), 3);
                    if (!octetToName.containsKey(octet))
                        octetToName.put(octet, domainName);
                }
            } else {
                aRecordToCnames.put(ipToARecord.get(address), domainName);
            }
        }
        sensors().set(A_RECORDS, ImmutableMap.copyOf(ipToARecord.inverse()));
        sensors().set(PTR_RECORDS, ImmutableMap.copyOf(octetToName));
        sensors().set(CNAME_RECORDS, Multimaps.unmodifiableMultimap(aRecordToCnames));
        sensors().set(ADDRESS_MAPPINGS, Multimaps.unmodifiableMultimap(ipToAllNames));

        // Update Bind configuration files and restart the service
        getDriver().updateBindConfiguration();
    }
}

From source file:com.aestasit.markdown.slidery.configuration.SimpleConfiguration.java

@Override
public Multimap<String, String> getTransitionRules() {
    return Multimaps.unmodifiableMultimap(transitionRules);
}

From source file:com.aestasit.markdown.slidery.configuration.SimpleConfiguration.java

@Override
public Multimap<String, String> getStylingRules() {
    return Multimaps.unmodifiableMultimap(stylingRules);
}

From source file:org.eclipse.b3.backend.evaluator.JavaToB3Helper.java

/**
 * Loads static functions from a java class. Using (optional) B3Backend annotations to
 * direct the translation into B3 functions.
 * Returns a Multimap of each defined function (as key), and for each function one or more names (aliases).
 * //from   ww w . j  a  v  a 2s. c o  m
 */
public static Multimap<IFunction, String> loadFunctions(Class<? extends Object> clazz)
        throws B3EngineException {
    Multimap<IFunction, String> result = Multimaps.newHashMultimap();
    Map<String, BJavaFunction> systemFunctions = new HashMap<String, BJavaFunction>();
    Map<String, BJavaFunction> guards = new HashMap<String, BJavaFunction>();
    Map<String, BJavaFunction> typeCalculators = new HashMap<String, BJavaFunction>();

    Map<String, List<BJavaFunction>> systemProxies = new HashMap<String, List<BJavaFunction>>();
    Map<String, List<BJavaFunction>> guardedFunctions = new HashMap<String, List<BJavaFunction>>();
    Map<String, List<BJavaFunction>> typeCalculatedFunctions = new HashMap<String, List<BJavaFunction>>();

    // create and initialize a BJavaFunction to represent each public static function
    for (Method m : clazz.getDeclaredMethods()) {
        // the call type of the function may later change to system call
        BJavaFunction f = createJavaFunction(m, BJavaCallType.FUNCTION);

        if (f == null)
            continue;

        // check for annotations
        B3Backend annotation = m.getAnnotation(B3Backend.class);

        // take a shortcut if there is no annotation
        if (annotation == null) {
            result.put(f, m.getName());
            continue;
        }

        String[] names = annotation.funcNames();

        if (annotation.hideOriginal()) {
            if (names == null || names.length == 0)
                throw new B3FunctionLoadException(
                        "hideOriginal annotation specified but not funcNames annotation", m);
            f.setName(names[0]);
        }

        f.setExecutionMode(BackendHelper.getExecutionMode(annotation));
        f.setVisibility(BackendHelper.getVisibility(annotation));

        // If the function is a system function, set it aside and patch the functions proxying it later.
        if (annotation.system()) {
            systemFunctions.put(f.getName(), f);
            continue;
        }

        // If the function is a guard, set it aside and patch the functions using it later.
        if (annotation.guard()) {
            // guards are called using system calling convention
            f.setCallType(BJavaCallType.SYSTEM);
            guards.put(f.getName(), f);
            continue;
        }

        // If the function is a type calculator, set it aside and patch the functions using it later.
        if (annotation.typeCalculator()) {
            typeCalculators.put(f.getName(), f);
            continue;
        }

        // add defined function to the result
        if (!annotation.hideOriginal())
            result.put(f, m.getName());

        if (names != null) {
            for (String fname : names)
                result.put(f, fname);

        }

        // if a function is a proxy for a system function, remember it
        {
            String systemFunctionName = annotation.systemFunction();
            if (systemFunctionName != null && systemFunctionName.length() > 0) {
                List<BJavaFunction> fs = null;
                if ((fs = systemProxies.get(systemFunctionName)) == null)
                    systemProxies.put(systemFunctionName, fs = new ArrayList<BJavaFunction>());
                fs.add(f);
            }
        }

        // if a function is guarded, remember it
        {
            String guardFunctionName = annotation.guardFunction();
            if (guardFunctionName != null && guardFunctionName.length() > 0) {
                List<BJavaFunction> gf = null;
                if ((gf = guardedFunctions.get(guardFunctionName)) == null)
                    guardedFunctions.put(guardFunctionName, gf = new ArrayList<BJavaFunction>());
                gf.add(f);
            }
        }

        // if a function has a type calculator, remember it
        {
            // if it has a typeClass, use that instead of type function
            final Class<? extends BTypeCalculator> typeClass = annotation.typeClass();
            if (typeClass != null && typeClass != BTypeCalculator.class) {
                // Jump through EMF hoops to get an instance of the impl class.
                // BTypeCalculator typeCalculator = calculatorMap.get(typeClass);
                // if(typeCalculator == null) {
                BTypeCalculator typeCalculator = createInstanceUsingPackageFactory(typeClass);
                // calculatorMap.put(typeClass, typeCalculator);
                // }
                f.setTypeCalculator(typeCalculator);

            }
            String typeCalculatorFunctionName = annotation.typeFunction();
            if (typeCalculatorFunctionName != null && typeCalculatorFunctionName.length() > 0) {
                List<BJavaFunction> tf = null;
                if ((tf = typeCalculatedFunctions.get(typeCalculatorFunctionName)) == null)
                    typeCalculatedFunctions.put(typeCalculatorFunctionName,
                            tf = new ArrayList<BJavaFunction>());
                tf.add(f);
            }
        }
    }

    // patch system functions
    // ---
    // revisit all functions that reference a system function and replace their method
    // with the system method, and also indicate that the call should be made as a system
    // call.
    for (Entry<String, List<BJavaFunction>> e : systemProxies.entrySet()) {
        for (BJavaFunction s : e.getValue()) {
            BJavaFunction sys = systemFunctions.get(e.getKey());
            if (sys == null)
                throw new B3FunctionLoadException("reference to system function: " + e.getKey()
                        + " can not be satisfied - no such method found.", s.getMethod());
            // patch the method in the func store with values from the system function
            s.setCallType(BJavaCallType.SYSTEM);
            s.setMethod(sys.getMethod());
        }
    }

    // link guards
    // ---
    // revisit all functions that reference a guardFunction and set that function as a guard
    //
    for (Entry<String, List<BJavaFunction>> e : guardedFunctions.entrySet()) {
        for (BJavaFunction guarded : e.getValue()) {
            BJavaFunction g = guards.get(e.getKey());
            if (g == null)
                throw new B3FunctionLoadException("reference to guard function: " + e.getKey()
                        + " can not be satisfied - no such guard found.", guarded.getMethod());
            // set the guard function, wrapped in a guard
            BGuard gf = B3backendFactory.eINSTANCE.createBGuard();
            gf.setFunc(g);
            guarded.setGuard(gf);
        }
    }

    // link type calculators
    // ---
    // revisit all functions that reference a typeFunction and set that function as a typeCalculator
    //
    for (Entry<String, List<BJavaFunction>> e : typeCalculatedFunctions.entrySet()) {
        for (BJavaFunction typed : e.getValue()) {
            BJavaFunction tc = typeCalculators.get(e.getKey());
            if (tc == null)
                throw new B3FunctionLoadException("reference to type calculator function: " + e.getKey()
                        + " can not be satisfied - no such function found.", typed.getMethod());
            // set the type calculator function, wrapped in a BTypeCalculator
            BTCPluggable tcf = B3backendFactory.eINSTANCE.createBTCPluggable();
            tcf.setFunc(tc);
            typed.setTypeCalculator(tcf);
        }
    }
    return Multimaps.unmodifiableMultimap(result);
}