Example usage for com.google.common.collect BiMap get

List of usage examples for com.google.common.collect BiMap get

Introduction

In this page you can find the example usage for com.google.common.collect BiMap get.

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:org.usergrid.rest.RootResource.java

@Timed(name = "getApplicationByUuids_timer", group = "rest_timers")
@ExceptionMetered(group = "rest_exceptions", name = "getApplicationByUuids_exceptions")
@Path("{organizationId: [A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}}/{applicationId: [A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}}")
public ApplicationResource getApplicationByUuids(@PathParam("organizationId") String organizationIdStr,
        @PathParam("applicationId") String applicationIdStr)

        throws Exception {

    UUID applicationId = UUID.fromString(applicationIdStr);
    UUID organizationId = UUID.fromString(organizationIdStr);
    if (applicationId == null || organizationId == null) {
        return null;
    }/* w  ww  . j  a  v a 2 s . com*/
    BiMap<UUID, String> apps = management.getApplicationsForOrganization(organizationId);
    if (apps.get(applicationId) == null) {
        return null;
    }
    return appResourceFor(applicationId);
}

From source file:org.eclipse.viatra.query.tooling.localsearch.ui.debugger.provider.viewelement.SearchOperationViewerNode.java

private void setup() {
    matcherBased = searchOperation == null ? false : searchOperation instanceof IMatcherBasedOperation;
    operationStatus = OperationStatus.QUEUED;
    children = Lists.newArrayList();// ww  w. ja v a  2s  . c  o m

    try {
        if (searchOperation != null) {

            this.labelText = searchOperation.toString();

            this.labelText += "(";
            BiMap<Integer, PVariable> variableMapping = planExecutor.getVariableMapping();
            List<Integer> variablePositions = searchOperation.getVariablePositions();
            for (int i = 0; i < variablePositions.size(); i++) {
                PVariable pVariable = variableMapping.get(variablePositions.get(i));
                this.labelText += pVariable.getName();
                if (i != variablePositions.size() - 1) {
                    this.labelText += ", ";
                }
            }
            this.labelText += ")";
        } else {
            this.labelText = "Match found";
        }
    } catch (Exception e) {
        this.labelText = "Error while calculating label: " + e.getMessage() + "(" + e.getClass().getSimpleName()
                + ")";
    }

}

From source file:org.apache.usergrid.rest.RootResource.java

@Timed(name = "getApplicationByUuids_timer", group = "rest_timers")
@ExceptionMetered(group = "rest_exceptions", name = "getApplicationByUuids_exceptions")
@Path(ORGANIZATION_ID_PATH + "/" + APPLICATION_ID_PATH)
public ApplicationResource getApplicationByUuids(@PathParam("organizationId") String organizationIdStr,
        @PathParam("applicationId") String applicationIdStr)

        throws Exception {

    UUID applicationId = UUID.fromString(applicationIdStr);
    UUID organizationId = UUID.fromString(organizationIdStr);
    if (applicationId == null || organizationId == null) {
        return null;
    }/*from  ww w. j  av a2 s .  c o m*/
    BiMap<UUID, String> apps = management.getApplicationsForOrganization(organizationId);
    if (apps.get(applicationId) == null) {
        return null;
    }
    return appResourceFor(applicationId);
}

From source file:org.opencb.opencga.storage.hadoop.variant.converters.HBaseToVariantConverter.java

private Integer getSamplePosition(LinkedHashMap<String, Integer> returnedSamplesPosition,
        BiMap<Integer, String> mapSampleIds, Integer sampleId) {
    String sampleName = mapSampleIds.get(sampleId);
    Integer samplePosition = returnedSamplesPosition.get(sampleName);
    return samplePosition;
}

From source file:de.sep2011.funckit.model.graphmodel.implementations.ComponentImpl.java

@Override
public Pair<Brick, Map<AccessPoint, AccessPoint>> getUnconnectedCopy() {
    ComponentImpl copy = new ComponentImpl(getType());
    Map<AccessPoint, AccessPoint> oldNewMap = new LinkedHashMap<AccessPoint, AccessPoint>();

    // copy.accessPointMap = null; //
    copy.boundingRect = new Rectangle(boundingRect);
    copy.delay = delay;// w  w w  .  ja va2  s  . c o  m
    // copy.inputs = null; //
    copy.name = name;
    copy.orientation = orientation;
    // copy.outputs = null; //

    BiMap<AccessPoint, AccessPoint> oldApMapInv = accessPointMap.inverse();
    BiMap<AccessPoint, AccessPoint> newApMapInv = copy.accessPointMap.inverse();

    for (AccessPoint ap : oldApMapInv.keySet()) {
        oldNewMap.put(oldApMapInv.get(ap), newApMapInv.get(ap));
    }

    /* Adapt properties of copied inputs and outputs. */
    for (Input input : copy.getInputs()) {
        AccessPoint other = oldApMapInv.get(copy.accessPointMap.get(input));
        input.setName(other.getName());
        input.setPosition(other.getPosition());
    }
    for (Output output : copy.getOutputs()) {
        AccessPoint other = oldApMapInv.get(copy.accessPointMap.get(output));
        output.setName(other.getName());
        output.setPosition(other.getPosition());
    }

    return new Pair<Brick, Map<AccessPoint, AccessPoint>>(copy, oldNewMap);
}

From source file:net.automatalib.serialization.etf.writer.Mealy2ETFWriterAlternating.java

private <S, T> void writeETFInternal(PrintWriter pw, MealyMachine<S, I, T, O> mealy, Alphabet<I> inputs) {

    // create a bi-mapping from states to integers
    final BiMap<S, Integer> oldStates = HashBiMap.create();
    mealy.getStates().forEach(s -> oldStates.put(s, oldStates.size()));

    // write the initial state, using the bi-map
    pw.println("begin init");
    pw.printf("%d%n", oldStates.get(mealy.getInitialState()));
    pw.println("end init");

    // create a bi-map for transitions containing output
    final BiMap<Pair<O, S>, Integer> outputTransitions = HashBiMap.create();

    // create a bi-map that maps output to integers
    final BiMap<O, Integer> outputIndices = HashBiMap.create();

    /*// www . j a  va2 s.  com
     Write the transitions (here is where the horror begins).
     The key to writing transitions with alternating semantics is that one have of see if appropriate
     intermediate states, and output transitions have already been created. If this is the case, that state, and
     output transitions has to be reused.
     */
    pw.println("begin trans");
    for (S s : mealy.getStates()) {
        for (I i : inputs) {
            T t = mealy.getTransition(s, i);
            if (t != null) {
                final S n = mealy.getSuccessor(t);
                final O o = mealy.getTransitionOutput(t);

                // construct a triple that serves as a key in the outputTransitions bi-map
                final Pair<O, S> outputTransition = Pair.of(o, n);

                // compute the integer value of the intermediate state (this may be a new state)
                final Integer intermediateState = outputTransitions.computeIfAbsent(outputTransition, ii -> {

                    // the output may also be a new letter in the alphabet.
                    final Integer outputIndex = outputIndices.computeIfAbsent(o,
                            iii -> inputs.size() + outputIndices.size());

                    /*
                    Write the output transition. Note that this will only be done if the output
                    transition was not written before.
                    */
                    final Integer res = oldStates.size() + outputTransitions.size();
                    pw.printf("%d/%d %d%n", res, oldStates.get(n), outputIndex);
                    return res;
                });

                // always write the input transition to the output transition
                pw.printf("%d/%d %d%n", oldStates.get(s), intermediateState, inputs.getSymbolIndex(i));
            }
        }
    }
    pw.println("end trans");

    // write all state ids, including the newly created intermediate states
    pw.println("begin sort id");
    for (int i = 0; i < oldStates.size(); i++) {
        pw.printf("\"%s\"%n", oldStates.inverse().get(i));
    }

    final Map<Integer, Pair<O, S>> inverseTransitions = outputTransitions.inverse();
    for (int i = 0; i < outputTransitions.size(); i++) {
        final Pair<O, S> t = inverseTransitions.get(oldStates.size() + i);
        pw.printf("\"(%s,%s)\"%n", t.getFirst(), t.getSecond());
    }
    pw.println("end sort");

    // write all the letters in the new alphabet
    pw.println("begin sort letter");
    inputs.forEach(i -> pw.printf("\"%s\"%n", i));
    for (int i = 0; i < outputIndices.size(); i++) {
        pw.printf("\"%s\"%n", outputIndices.inverse().get(inputs.size() + i));
    }
    pw.println("end sort");
}

From source file:it.sayservice.platform.smartplanner.cache.AgencyCacheIndex.java

private CompressedCalendar compressCalendar(Map<String, String> cal) {
    CompressedCalendar ccal = new CompressedCalendar();
    int i = 0;/* w w  w  . ja v a2 s  . c o m*/
    Map<String, String> days = new TreeMap<String, String>();
    BiMap<String, String> map = HashBiMap.create();

    for (String key : cal.keySet()) {
        String value = cal.get(key);
        if (!map.containsKey(value)) {
            map.put(value, "" + i++);
        }
        days.put(key, map.get(value));
    }

    ccal.setEntries(days);
    ccal.setMapping(map.inverse());

    return ccal;
}

From source file:org.broadleafcommerce.core.search.dao.SolrIndexDaoImpl.java

@Override
public void populateProductCatalogStructure(List<Long> productIds, CatalogStructure catalogStructure) {
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    Boolean oldIgnoreFilters = context.getInternalIgnoreFilters();
    context.setInternalIgnoreFilters(false);
    try {/*  w w  w.jav a 2s.c o  m*/
        Map<Long, Set<Long>> parentCategoriesByProduct = new HashMap<Long, Set<Long>>();
        Map<Long, Set<Long>> parentCategoriesByCategory = new HashMap<Long, Set<Long>>();

        Long[] products = productIds.toArray(new Long[productIds.size()]);
        BiMap<Long, Long> sandBoxProductToOriginalMap = sandBoxHelper.getSandBoxToOriginalMap(ProductImpl.class,
                products);
        int batchSize = 800;
        int count = 0;
        int pos = 0;
        while (pos < products.length) {
            int remaining = products.length - pos;
            int mySize = remaining > batchSize ? batchSize : remaining;
            Long[] temp = new Long[mySize];
            System.arraycopy(products, pos, temp, 0, mySize);

            //context.getAdditionalProperties().put("constrainedFilterGroups", Arrays.asList("archivedFilter"));
            TypedQuery<ParentCategoryByProduct> query = em
                    .createNamedQuery("BC_READ_PARENT_CATEGORY_IDS_BY_PRODUCTS", ParentCategoryByProduct.class);
            query.setParameter("productIds", sandBoxHelper.mergeCloneIds(ProductImpl.class, temp));

            List<ParentCategoryByProduct> results = query.getResultList();
            //context.getAdditionalProperties().remove("constrainedFilterGroups");
            for (ParentCategoryByProduct item : results) {
                Long sandBoxProductVal = item.getProduct();
                BiMap<Long, Long> reverse = sandBoxProductToOriginalMap.inverse();
                if (reverse.containsKey(sandBoxProductVal)) {
                    sandBoxProductVal = reverse.get(sandBoxProductVal);
                }
                if (!catalogStructure.getParentCategoriesByProduct().containsKey(sandBoxProductVal)) {
                    if (!parentCategoriesByProduct.containsKey(sandBoxProductVal)) {
                        parentCategoriesByProduct.put(sandBoxProductVal, new HashSet<Long>());
                    }
                    //We only want the sandbox parent - if applicable
                    //Long sandBoxVal = sandBoxHelper.getCombinedSandBoxVersionId(CategoryImpl.class, item.getParent());
                    Long sandBoxVal = sandBoxHelper.getSandBoxVersionId(CategoryImpl.class, item.getParent());
                    if (sandBoxVal == null) {
                        sandBoxVal = item.getParent();
                    }
                    parentCategoriesByProduct.get(sandBoxProductVal).add(sandBoxVal);
                }
            }
            for (Map.Entry<Long, Set<Long>> entry : parentCategoriesByProduct.entrySet()) {
                for (Long categoryId : entry.getValue()) {
                    if (!catalogStructure.getParentCategoriesByCategory().containsKey(categoryId)) {
                        Set<Long> hierarchy = new HashSet<Long>();
                        parentCategoriesByCategory.put(categoryId, hierarchy);
                    }
                    if (!catalogStructure.getProductsByCategory().containsKey(categoryId)) {
                        List<ProductsByCategoryWithOrder> categoryChildren = readProductIdsByCategory(
                                categoryId);

                        // Cache the display order bigdecimals
                        BigDecimal displayOrder = new BigDecimal("1.00000");
                        for (ProductsByCategoryWithOrder child : categoryChildren) {
                            catalogStructure.getDisplayOrdersByCategoryProduct().put(
                                    categoryId + "-" + child.getProductId(),
                                    child.getDisplayOrder() == null ? displayOrder : child.getDisplayOrder());
                            if (child.getDisplayOrder() != null) {
                                displayOrder = child.displayOrder;
                            }
                            displayOrder = displayOrder.add(new BigDecimal("1.00000"));
                        }

                        //filter the list for sandbox values
                        for (Map.Entry<Long, Long> sandBoxProduct : sandBoxProductToOriginalMap.entrySet()) {
                            for (ProductsByCategoryWithOrder child : categoryChildren) {
                                if (child.getProductId().equals(sandBoxProduct.getValue())) {
                                    child.setProductId(sandBoxProduct.getKey());
                                }
                            }
                        }

                        List<Long> categoryChildProductIds = BLCCollectionUtils.collectList(categoryChildren,
                                new TypedTransformer<Long>() {
                                    @Override
                                    public Long transform(Object input) {
                                        return ((ProductsByCategoryWithOrder) input).getProductId();
                                    }
                                });
                        catalogStructure.getProductsByCategory().put(categoryId, categoryChildProductIds);
                    }
                }
            }
            count++;
            pos = (count * batchSize) < products.length ? (count * batchSize) : products.length;
        }
        readFullCategoryHierarchy(parentCategoriesByCategory, new HashSet<Long>());
        catalogStructure.getParentCategoriesByProduct().putAll(parentCategoriesByProduct);
        catalogStructure.getParentCategoriesByCategory().putAll(parentCategoriesByCategory);
    } finally {
        context.setInternalIgnoreFilters(oldIgnoreFilters);
    }
}

From source file:io.prestosql.sql.planner.NodePartitioningManager.java

public NodePartitionMap getNodePartitioningMap(Session session, PartitioningHandle partitioningHandle) {
    requireNonNull(session, "session is null");
    requireNonNull(partitioningHandle, "partitioningHandle is null");

    if (partitioningHandle.getConnectorHandle() instanceof SystemPartitioningHandle) {
        return ((SystemPartitioningHandle) partitioningHandle.getConnectorHandle()).getNodePartitionMap(session,
                nodeScheduler);/*from w  w w .j  a  v  a  2 s.  c o  m*/
    }

    ConnectorId connectorId = partitioningHandle.getConnectorId()
            .orElseThrow(() -> new IllegalArgumentException(
                    "No connector ID for partitioning handle: " + partitioningHandle));
    ConnectorNodePartitioningProvider partitioningProvider = partitioningProviders.get(connectorId);
    checkArgument(partitioningProvider != null, "No partitioning provider for connector %s", connectorId);

    ConnectorBucketNodeMap connectorBucketNodeMap = getConnectorBucketNodeMap(session, partitioningHandle);
    // safety check for crazy partitioning
    checkArgument(connectorBucketNodeMap.getBucketCount() < 1_000_000, "Too many buckets in partitioning: %s",
            connectorBucketNodeMap.getBucketCount());

    List<Node> bucketToNode;
    if (connectorBucketNodeMap.hasFixedMapping()) {
        bucketToNode = connectorBucketNodeMap.getFixedMapping();
    } else {
        bucketToNode = createArbitraryBucketToNode(nodeScheduler.createNodeSelector(connectorId).allNodes(),
                connectorBucketNodeMap.getBucketCount());
    }

    int[] bucketToPartition = new int[connectorBucketNodeMap.getBucketCount()];
    BiMap<Node, Integer> nodeToPartition = HashBiMap.create();
    int nextPartitionId = 0;
    for (int bucket = 0; bucket < bucketToNode.size(); bucket++) {
        Node node = bucketToNode.get(bucket);
        Integer partitionId = nodeToPartition.get(node);
        if (partitionId == null) {
            partitionId = nextPartitionId++;
            nodeToPartition.put(node, partitionId);
        }
        bucketToPartition[bucket] = partitionId;
    }

    List<Node> partitionToNode = IntStream.range(0, nodeToPartition.size())
            .mapToObj(partitionId -> nodeToPartition.inverse().get(partitionId)).collect(toImmutableList());

    return new NodePartitionMap(partitionToNode, bucketToPartition,
            getSplitToBucket(session, partitioningHandle));
}

From source file:org.napile.compiler.lang.types.checker.NapileTypeChecker.java

public boolean equalTypes(@NotNull NapileType a, @NotNull NapileType b,
        @NotNull final BiMap<TypeConstructor, TypeConstructor> equalityAxioms) {
    return new TypeCheckingProcedure(new TypeCheckerTypingConstraints() {
        @Override//www .j  ava  2 s  .  c  o  m
        public boolean assertEqualTypeConstructors(@NotNull TypeConstructor constructor1,
                @NotNull TypeConstructor constructor2) {
            if (!constructor1.equals(constructor2)) {
                TypeConstructor img1 = equalityAxioms.get(constructor1);
                TypeConstructor img2 = equalityAxioms.get(constructor2);
                if (!(img1 != null && img1.equals(constructor2))
                        && !(img2 != null && img2.equals(constructor1))) {
                    return false;
                }
            }
            return true;
        }
    }).equalTypes(a, b);
}