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

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

Introduction

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

Prototype

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

Source Link

Document

Returns a new, empty HashBiMap with the default initial capacity (16).

Usage

From source file:de.xaniox.heavyspleef.addon.AddOnManager.java

public AddOnManager(HeavySpleef heavySpleef) {
    this.addOnMap = HashBiMap.create();
    this.classContext = new SharedClassContext();
    this.heavySpleef = heavySpleef;
    this.logger = heavySpleef.getLogger();

    this.flagRegistryAccess = new FlagRegistryAccess(heavySpleef.getFlagRegistry());
    this.extensionRegistryAccess = new ExtensionRegistryAccess(heavySpleef.getExtensionRegistry());
    this.commandManagerAccess = new CommandManagerAccess(heavySpleef.getCommandManager());
}

From source file:org.apache.usergrid.security.shiro.principals.OrganizationPrincipal.java

@Override
public void grant(UsergridAuthorizationInfo info, EntityManagerFactory emf, ManagementService management,
        TokenService tokens) {//ww w. j av  a  2s  .c o  m

    // OrganizationPrincipals are usually only through OAuth
    // They have access to a single organization

    Map<UUID, String> organizationSet = HashBiMap.create();
    Map<UUID, String> applicationSet = HashBiMap.create();
    ApplicationInfo application = null;

    role(info, Realm.ROLE_ORGANIZATION_ADMIN);
    role(info, Realm.ROLE_APPLICATION_ADMIN);

    grant(info, "organizations:access:" + organization.getUuid());
    organizationSet.put(organization.getUuid(), organization.getName());

    Map<UUID, String> applications = null;

    try {
        applications = management.getApplicationsForOrganization(organization.getUuid());
    } catch (Exception e) {
        //todo seems to just be ignored, seems like a bad ida...
        logger.error("Error in OrganizationPrincipal.grant()", e);

    }

    if ((applications != null) && !applications.isEmpty()) {
        grant(info, "applications:admin,access,get,put,post,delete:"
                + StringUtils.join(applications.keySet(), ','));

        applicationSet.putAll(applications);
    }

    info.setOrganization(organization);
    info.addOrganizationSet(organizationSet);
    //todo application is always null here - never is set
    info.setApplication(application);
    info.addApplicationSet(applicationSet);
}

From source file:org.sosy_lab.cpachecker.cpa.smg.SMGIntersectStates.java

public static SMGIntersectionResult intersect(SMGState pSmgState1, CLangSMG pHeap1, SMGState pSmgState2,
        CLangSMG pHeap2, BiMap<SMGKnownSymValue, SMGKnownExpValue> pExplicitValues,
        BiMap<SMGKnownSymValue, SMGKnownExpValue> pExplicitValues2) {

    CLangSMG destSMG = new CLangSMG(pHeap1.getMachineModel());

    SMGNodeMapping mapping1 = new SMGNodeMapping();
    SMGNodeMapping mapping2 = new SMGNodeMapping();
    mapping1.map(pSmgState1.getNullObject(), destSMG.getNullObject());
    mapping2.map(pSmgState2.getNullObject(), destSMG.getNullObject());

    Map<String, SMGRegion> globals_in_smg1 = pHeap1.getGlobalObjects();
    Deque<CLangStackFrame> stack_in_smg1 = pHeap1.getStackFrames();
    Map<String, SMGRegion> globals_in_smg2 = pHeap2.getGlobalObjects();
    Deque<CLangStackFrame> stack_in_smg2 = pHeap2.getStackFrames();

    Set<SMGEdgeHasValue> singleHveEdge1 = new HashSet<>();
    Set<SMGEdgeHasValue> singleHveEdge2 = new HashSet<>();

    BiMap<SMGKnownSymValue, SMGKnownExpValue> destExplicitValues = HashBiMap.create();

    Set<String> globalVars = new HashSet<>();
    globalVars.addAll(globals_in_smg1.keySet());
    globalVars.addAll(globals_in_smg2.keySet());

    for (String globalVar : globalVars) {
        SMGRegion globalInSMG1 = globals_in_smg1.get(globalVar);
        SMGRegion globalInSMG2 = globals_in_smg2.get(globalVar);

        SMGRegion finalObject = globalInSMG1;
        destSMG.addGlobalObject(finalObject);
        mapping1.map(globalInSMG1, finalObject);
        mapping2.map(globalInSMG2, finalObject);
    }/*from w ww  . j a v  a 2 s.c o  m*/

    Iterator<CLangStackFrame> smg1stackIterator = stack_in_smg1.descendingIterator();
    Iterator<CLangStackFrame> smg2stackIterator = stack_in_smg2.descendingIterator();

    while (smg1stackIterator.hasNext() && smg2stackIterator.hasNext()) {
        CLangStackFrame frameInSMG1 = smg1stackIterator.next();
        CLangStackFrame frameInSMG2 = smg2stackIterator.next();

        destSMG.addStackFrame(frameInSMG1.getFunctionDeclaration());

        Set<String> localVars = new HashSet<>();
        localVars.addAll(frameInSMG1.getVariables().keySet());
        localVars.addAll(frameInSMG2.getVariables().keySet());

        for (String localVar : localVars) {
            SMGRegion localInSMG1 = frameInSMG1.getVariable(localVar);
            SMGRegion localInSMG2 = frameInSMG2.getVariable(localVar);
            SMGRegion finalObject = localInSMG1;
            destSMG.addStackObject(finalObject);
            mapping1.map(localInSMG1, finalObject);
            mapping2.map(localInSMG2, finalObject);
        }

        SMGObject returnSMG1 = frameInSMG1.getReturnObject();
        SMGObject returnSMG2 = frameInSMG2.getReturnObject();

        if (returnSMG1 == null) {
            continue;
        }

        SMGObject finalObject = destSMG.getFunctionReturnObject();
        mapping1.map(returnSMG1, finalObject);
        mapping2.map(returnSMG2, finalObject);
    }

    for (String globalVar : globalVars) {
        SMGRegion globalInSMG1 = globals_in_smg1.get(globalVar);
        SMGRegion globalInSMG2 = globals_in_smg2.get(globalVar);

        SMGObject finalObject = mapping1.get(globalInSMG1);
        boolean defined = intersectPairFields(pHeap1, pHeap2, globalInSMG1, globalInSMG2, finalObject, mapping1,
                mapping2, destSMG, singleHveEdge1, singleHveEdge2, pExplicitValues, pExplicitValues2,
                destExplicitValues);

        if (!defined) {
            return SMGIntersectionResult.getNotDefinedInstance();
        }
    }

    smg1stackIterator = stack_in_smg1.descendingIterator();
    smg2stackIterator = stack_in_smg2.descendingIterator();

    while (smg1stackIterator.hasNext() && smg2stackIterator.hasNext()) {
        CLangStackFrame frameInSMG1 = smg1stackIterator.next();
        CLangStackFrame frameInSMG2 = smg2stackIterator.next();

        Set<String> localVars = new HashSet<>();
        localVars.addAll(frameInSMG1.getVariables().keySet());
        localVars.addAll(frameInSMG2.getVariables().keySet());

        for (String localVar : localVars) {
            SMGRegion localInSMG1 = frameInSMG1.getVariable(localVar);
            SMGRegion localInSMG2 = frameInSMG2.getVariable(localVar);
            SMGObject finalObject = mapping1.get(localInSMG1);

            boolean defined = intersectPairFields(pHeap1, pHeap2, localInSMG1, localInSMG2, finalObject,
                    mapping1, mapping2, destSMG, singleHveEdge1, singleHveEdge2, pExplicitValues,
                    pExplicitValues2, destExplicitValues);

            if (!defined) {
                return SMGIntersectionResult.getNotDefinedInstance();
            }
        }

        SMGObject returnSMG1 = frameInSMG1.getReturnObject();
        SMGObject returnSMG2 = frameInSMG2.getReturnObject();

        if (returnSMG1 == null) {
            continue;
        }

        SMGObject finalObject = destSMG.getFunctionReturnObject();

        boolean defined = intersectPairFields(pHeap1, pHeap2, returnSMG1, returnSMG2, finalObject, mapping1,
                mapping2, destSMG, singleHveEdge1, singleHveEdge2, pExplicitValues, pExplicitValues2,
                destExplicitValues);

        if (!defined) {
            return SMGIntersectionResult.getNotDefinedInstance();
        }
    }

    for (SMGEdgeHasValue hve1 : singleHveEdge1) {
        intersectHveEdgeWithTop(hve1, pHeap1, destSMG, pExplicitValues, destExplicitValues, mapping1);
    }

    for (SMGEdgeHasValue hve2 : singleHveEdge2) {
        intersectHveEdgeWithTop(hve2, pHeap2, destSMG, pExplicitValues2, destExplicitValues, mapping2);
    }

    SMGState pIntersectResult = new SMGState(pSmgState1, destSMG, destExplicitValues);

    return new SMGIntersectionResult(pSmgState1, pSmgState2, pIntersectResult, true);
}

From source file:org.ow2.petals.camel.se.utils.PetalsCamelJBIHelper.java

/**
 * returns a Map of service-id <-> service/endpoint/operation
 * /*from w ww  . j a v  a2s  .  c o  m*/
 * @param suDH
 * @param jbiListener
 * @return
 * @throws InvalidJBIConfigurationException
 */
public static Map<String, ServiceEndpointOperation> extractServicesIdAndEndpointOperations(
        final ServiceUnitDataHandler suDH, final PetalsCamelSender sender)
        throws InvalidJBIConfigurationException {

    final Jbi jbiDescriptor = suDH.getDescriptor();

    // let's use a bimap to accelerate checking of containsValue()
    final Map<String, ServiceEndpointOperation> sid2seo = HashBiMap.create();

    // for provides, there is one serviceId per operation of each provides
    for (final Provides p : jbiDescriptor.getServices().getProvides()) {

        final Document wsdlDoc = suDH.getEndpointDescription(p);

        final List<OperationData> seos;
        try {
            seos = getOperationsAndServiceId(wsdlDoc, p);
        } catch (final URISyntaxException | XmlException e) {
            throw new InvalidJBIConfigurationException("Exception while parsing WSDL", e);
        }

        for (final OperationData od : seos) {
            if (sid2seo.containsKey(od.serviceId)) {
                throw new InvalidJBIConfigurationException("Duplicate " + ATTR_WSDL_OPERATION_SERVICEID + " ("
                        + od.serviceId + ") in the operation " + od.operation);
            }
            final ServiceEndpointOperation seo = new ServiceEndpointOperationProvides(od.operation, od.mep,
                    sender, p);
            if (sid2seo.containsValue(seo)) {
                throw new InvalidJBIConfigurationException("Duplicate service " + seo);
            }
            sid2seo.put(od.serviceId, seo);
        }
    }

    // for consumes, there is one serviceId per consumes (because it includes the operation)
    for (final Consumes c : jbiDescriptor.getServices().getConsumes()) {

        final ServiceEndpointOperation seo = new ServiceEndpointOperationConsumes(sender, c);

        final String serviceId = getServiceId(c, suDH);

        if (sid2seo.containsKey(serviceId)) {
            throw new InvalidJBIConfigurationException("Duplicate " + EL_CONSUMES_SERVICE_ID + " (" + serviceId
                    + ") in the consumes " + c.getServiceName());
        }

        sid2seo.put(serviceId, seo);
    }

    return sid2seo;
}

From source file:com.google.javascript.jscomp.IdMappingUtil.java

/**
 * The expected format looks like this:/* w  w  w .j a va 2  s. c o  m*/
 *
 * <p>[generatorName1]
 * someId1:someFile:theLine:theColumn
 * ...
 *
 * <p>[[generatorName2]
 * someId2:someFile:theLine:theColumn]
 * ...
 *
 * <p>The returned data is grouped by generator name (the map key). The inner map provides
 * mappings from id to content (file, line and column info). In a glimpse, the structure is
 * Map<geneartor name, BiMap<id, value>>.
 *
 * <p>@throws IllegalArgumentException malformed input where there it 1) has duplicate generator
 *     name, or 2) the line has no ':' for id and its content.
 */
public static Map<String, BiMap<String, String>> parseSerializedIdMappings(String idMappings) {
    if (Strings.isNullOrEmpty(idMappings)) {
        return Collections.emptyMap();
    }

    Map<String, BiMap<String, String>> resultMap = new HashMap<>();
    BiMap<String, String> currentSectionMap = null;

    int lineIndex = 0;
    for (String line : LINE_SPLITTER.split(idMappings)) {
        lineIndex++;
        if (line.isEmpty()) {
            continue;
        }
        if (line.charAt(0) == '[') {
            String currentSection = line.substring(1, line.length() - 1);
            currentSectionMap = resultMap.get(currentSection);
            if (currentSectionMap == null) {
                currentSectionMap = HashBiMap.create();
                resultMap.put(currentSection, currentSectionMap);
            } else {
                throw new IllegalArgumentException(SimpleFormat.format(
                        "Cannot parse id map: %s\n Line: $s, lineIndex: %s", idMappings, line, lineIndex));
            }
        } else {
            int split = line.indexOf(':');
            if (split != -1) {
                String name = line.substring(0, split);
                String location = line.substring(split + 1, line.length());
                currentSectionMap.put(name, location);
            } else {
                throw new IllegalArgumentException(SimpleFormat.format(
                        "Cannot parse id map: %s\n Line: $s, lineIndex: %s", idMappings, line, lineIndex));
            }
        }
    }
    return resultMap;
}

From source file:org.thingsboard.server.actors.tenant.TenantActor.java

private TenantActor(ActorSystemContext systemContext, TenantId tenantId) {
    super(systemContext, new TenantRuleChainManager(systemContext, tenantId));
    this.tenantId = tenantId;
    this.deviceActors = HashBiMap.create();
}

From source file:org.geoserver.gwc.layer.DefaultTileLayerCatalog.java

DefaultTileLayerCatalog(GeoServerResourceLoader resourceLoader, XStream configuredXstream) throws IOException {

    this.resourceLoader = resourceLoader;
    this.serializer = configuredXstream;
    this.baseDirectory = LAYERINFO_DIRECTORY;

    BiMap<String, String> baseBiMap = HashBiMap.create();
    this.layersById = Maps.synchronizedBiMap(baseBiMap);
    this.layersByName = layersById.inverse();
    this.initialized = false;
}

From source file:com.google.errorprone.bugpatterns.testdata.URLEqualsHashCodePositiveCases.java

public void hashBiMapOfURL() {
    // BUG: Diagnostic contains: java.net.URL
    BiMap<URL, String> urlBiMap = HashBiMap.create();

    // BUG: Diagnostic contains: java.net.URL
    BiMap<String, URL> toUrlBiMap = HashBiMap.create();
}

From source file:org.apache.usergrid.security.shiro.principals.ApplicationUserPrincipal.java

@Override
public void grant(UsergridAuthorizationInfo info, EntityManagerFactory emf, ManagementService management,
        TokenService tokens) {/*from  www.j  av a2s. c o  m*/

    Map<UUID, String> organizationSet = HashBiMap.create();
    Map<UUID, String> applicationSet = HashBiMap.create();
    OrganizationInfo organization = null;
    ApplicationInfo application = null;

    role(info, Realm.ROLE_APPLICATION_USER);

    UUID applicationId = getApplicationId();

    AccessTokenCredentials tokenCredentials = getAccessTokenCredentials();
    TokenInfo token = null;
    if (tokenCredentials != null) {
        try {
            token = tokens.getTokenInfo(tokenCredentials.getToken());
        } catch (Exception e) {
            logger.error("Unable to retrieve token info", e);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Token: {}", token);
        }
    }

    grant(info, getPermissionFromPath(applicationId, "access"));

    if (SubjectUtils.getUser() != null) {
        // ensure that the /org/app/users/me end-point always works for logged in user
        grant(info, "applications:get:" + applicationId + ":/users/" + SubjectUtils.getUser().getUuid());
    }

    EntityManager em = emf.getEntityManager(applicationId);
    try {
        String appName = (String) em.getProperty(em.getApplicationRef(), "name");
        applicationSet.put(applicationId, appName);
        application = new ApplicationInfo(applicationId, appName);
    } catch (Exception e) {
    }

    try {
        Set<String> permissions = em.getRolePermissions("default");
        grant(info, applicationId, permissions);
    } catch (Exception e) {
        logger.error("Unable to get user default role permissions", e);
    }

    UserInfo user = getUser();
    try {
        Set<String> permissions = em.getUserPermissions(user.getUuid());
        grant(info, applicationId, permissions);
    } catch (Exception e) {
        logger.error("Unable to get user permissions", e);
    }

    try {
        Set<String> rolenames = em.getUserRoles(user.getUuid());
        grantAppRoles(info, em, applicationId, token, rolenames);
    } catch (Exception e) {
        logger.error("Unable to get user role permissions", e);
    }

    try {

        // this is woefully inefficient, thankfully we cache the info object now

        Results r = em.getCollection(new SimpleEntityRef(User.ENTITY_TYPE, user.getUuid()), "groups", null,
                1000, Query.Level.IDS, false);
        if (r != null) {

            Set<String> rolenames = new HashSet<String>();

            for (UUID groupId : r.getIds()) {

                Results roleResults = em.getCollection(new SimpleEntityRef(Group.ENTITY_TYPE, groupId), "roles",
                        null, 1000, Query.Level.CORE_PROPERTIES, false);

                for (Entity entity : roleResults.getEntities()) {
                    rolenames.add(entity.getName());
                }
            }

            grantAppRoles(info, em, applicationId, token, rolenames);
        }
    } catch (Exception e) {
        logger.error("Unable to get user group role permissions", e);
    }

    info.setOrganization(organization);
    info.addOrganizationSet(organizationSet);
    info.setApplication(application);
    info.addApplicationSet(applicationSet);
}

From source file:org.eclipse.incquery.runtime.localsearch.plan.SearchPlanExecutor.java

public SearchPlanExecutor(SearchPlan plan, ISearchContext context, Map<PVariable, Integer> variableMapping) {
    Preconditions.checkArgument(context != null, "Context cannot be null");
    this.plan = plan;
    this.context = context;
    HashBiMap<PVariable, Integer> tmpMapping = HashBiMap.create();
    tmpMapping.putAll(variableMapping);//  w w  w . ja v  a  2  s  .  c om
    this.variableMapping = tmpMapping.inverse();
    operations = plan.getOperations();
    this.currentOperation = -1;
}