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:net.exclaimindustries.geohashdroid.activities.KnownLocationsPicker.java

private boolean doReadyChecks() {
    if (mMapIsReady && mGoogleClient != null && mGoogleClient.isConnected()) {
        // The map should be centered on the currently-known locations.
        // Otherwise, well, default to dead zero, I guess.
        Log.d(DEBUG_TAG, "There are " + mLocations.size() + " known location(s).");

        // Throw any search addresses back on the map.
        if (mActiveAddresses != null)
            doAddressMarkers(mActiveAddresses);
        else/* w ww  .ja v  a 2 s  . c o  m*/
            mActiveAddressMap = HashBiMap.create();

        // Known locations also ought to be initialized.
        initKnownLocations();

        if (!mReloaded) {
            // If we're reloading, I think the map fragment knows to restore
            // itself.  If not, we default to the current KnownLocations.
            if (!mLocations.isEmpty()) {
                CameraUpdate cam;

                LatLngBounds.Builder builder = LatLngBounds.builder();

                for (KnownLocation kl : mLocations) {
                    // Now, we want to include the range of each location,
                    // too.  Unfortunately, Android doesn't supply us with
                    // a method for "calculate point that is X distance at Y
                    // heading from another point" (or, the inverse geodetic
                    // problem, as it's better known).  So for this, we turn
                    // to the OpenSextant library!
                    Geodetic2DPoint gPoint = new Geodetic2DPoint(
                            new Longitude(kl.getLatLng().longitude, Angle.DEGREES),
                            new Latitude(kl.getLatLng().latitude, Angle.DEGREES));

                    // Start at due north and include it.
                    Geodetic2DArc gArc = new Geodetic2DArc(gPoint, kl.getRange(), new Angle(0, Angle.DEGREES));

                    builder.include(new LatLng(gArc.getPoint2().getLatitudeAsDegrees(),
                            gArc.getPoint2().getLongitudeAsDegrees()));

                    // Repeat for the other cardinal directions.  That'll
                    // give us what we need to fit the circle.
                    gArc.setForwardAzimuth(new Angle(90, Angle.DEGREES));
                    builder.include(new LatLng(gArc.getPoint2().getLatitudeAsDegrees(),
                            gArc.getPoint2().getLongitudeAsDegrees()));

                    gArc.setForwardAzimuth(new Angle(180, Angle.DEGREES));
                    builder.include(new LatLng(gArc.getPoint2().getLatitudeAsDegrees(),
                            gArc.getPoint2().getLongitudeAsDegrees()));

                    gArc.setForwardAzimuth(new Angle(270, Angle.DEGREES));
                    builder.include(new LatLng(gArc.getPoint2().getLatitudeAsDegrees(),
                            gArc.getPoint2().getLongitudeAsDegrees()));
                }

                LatLngBounds bounds = builder.build();
                cam = CameraUpdateFactory.newLatLngBounds(bounds,
                        getResources().getDimensionPixelSize(R.dimen.map_zoom_padding));
                mMap.animateCamera(cam);
            }
        }

        return true;
    } else {
        return false;
    }
}

From source file:org.bimserver.ifc.IfcModel.java

public void checkDoubleOidsPlusReferences() {
    BiMap<IdEObject, Long> done = HashBiMap.create();
    for (IdEObject idEObject : objects.values()) {
        checkDoubleOidsPlusReferences(done, idEObject);
    }//from  w w  w  . j a  v  a 2  s.com
}

From source file:org.apache.tajo.plan.rewrite.rules.FilterPushDownRule.java

private BiMap<EvalNode, EvalNode> findCanPushdownAndTransform(FilterPushDownContext context,
        LogicalPlan.QueryBlock block, Projectable node, LogicalNode childNode, List<EvalNode> notMatched,
        Set<String> partitionColumns, int columnOffset) throws TajoException {
    // canonical name -> target
    Map<String, Target> nodeTargetMap = new HashMap<>();
    for (Target target : node.getTargets()) {
        nodeTargetMap.put(target.getCanonicalName(), target);
    }/*from ww  w.java  2s. c om*/

    // copy -> origin
    BiMap<EvalNode, EvalNode> matched = HashBiMap.create();

    for (EvalNode eval : context.pushingDownFilters) {
        // If all column is field eval, can push down.
        Set<Column> evalColumns = EvalTreeUtil.findUniqueColumns(eval);
        boolean columnMatched = true;
        for (Column c : evalColumns) {
            Target target = nodeTargetMap.get(c.getQualifiedName());
            if (target == null) {
                columnMatched = false;
                break;
            }
            if (target.getEvalTree().getType() != EvalType.FIELD) {
                columnMatched = false;
                break;
            }
        }

        if (columnMatched) {
            // transform eval column to child's output column
            EvalNode copyEvalNode = transformEval(node, childNode, eval, nodeTargetMap, partitionColumns,
                    columnOffset);
            if (copyEvalNode != null) {
                matched.put(copyEvalNode, eval);
            } else {
                notMatched.add(eval);
            }
        } else {
            notMatched.add(eval);
        }
    }

    return matched;
}

From source file:org.jpmml.evaluator.general_regression.GeneralRegressionModelEvaluator.java

static private BiMap<String, Parameter> parseParameterRegistry(ParameterList parameterList) {
    BiMap<String, Parameter> result = HashBiMap.create();

    if (!parameterList.hasParameters()) {
        return result;
    }/*ww  w  .j a  v a 2  s .co m*/

    List<Parameter> parameters = parameterList.getParameters();
    for (Parameter parameter : parameters) {
        result.put(parameter.getName(), parameter);
    }

    return result;
}

From source file:ptolemy.vergil.basic.layout.kieler.KielerLayout.java

/**
 * Creates a graph for the KIELER API from a Ptolemy model. Will traverse
 * the low level GraphModel given by the composite and record all found
 * elements in the mapping fields of this object that keep a mapping between
 * Ptolemy/Diva objects and KIELER objects. New KIELER objects (KEdge,
 * KNode, KPort) are created for their respective Ptolemy counterparts and
 * initialized with the initial sizes and positions and are put in a
 * composite KNode (the graph KIELER will perform the layout on later). To
 * obtain the right mappings, multiple abstraction levels of Ptolemy are
 * considered here: Diva, as this was the intended original way to do
 * automatic layout (e.g. by GlobalAbstractLayout) and Ptolemy, since Diva
 * lacks certain concepts that are relevant for a proper layout, such
 * as exact port locations for considering port constraints in the
 * model, which are supported by KIELER.
 *
 * @param composite The GraphModel composite object to retrieve the model
 *            information from/*  w ww  .j  a v  a2s  .c om*/
 * @param parentNode KIELER subgraph to receive all connected
 *            model elements
 */
private void _createGraph(Object composite, KNode parentNode) {
    _kieler2ptolemyDivaNodes = HashBiMap.create();
    _ptolemy2KielerPorts = LinkedListMultimap.create();
    _divaEdgeSource = Maps.newHashMap();
    _divaEdgeTarget = Maps.newHashMap();
    _divaLabel = Maps.newHashMap();
    _edgeList = Lists.newLinkedList();
    KShapeLayout parentLayout = parentNode.getData(KShapeLayout.class);

    // Determine whether to include unconnected nodes.
    boolean doBoxLayout = parentLayout.getProperty(Parameters.DECORATIONS);

    // On-the-fly find upper left corner for bounding box of parent node.
    float globalX = Float.MAX_VALUE, globalY = Float.MAX_VALUE;

    // Traverse the ptolemy graph.
    ExternalPortModel externalPortModel = null;
    if (_graphModel instanceof ActorGraphModel) {
        externalPortModel = ((ActorGraphModel) _graphModel).getExternalPortModel();
    }
    List<Link> unprocessedEdges = new LinkedList<Link>();
    List<NamedObj> unprocessedRelatives = new LinkedList<NamedObj>();

    // Process nodes.
    for (Iterator iterator = _graphModel.nodes(composite); iterator.hasNext();) {
        Object node = iterator.next();
        if (!(node instanceof Locatable)) {
            continue;
        }
        Iterator portIter = null;

        // Here we get the corresponding Ptolemy object.
        // This breaks with Ptolemy/Diva abstraction; for now we need
        // the ptolemy actor to get the ports and port positions
        // and to distinguish actors and relation vertices.
        NamedObj semanticNode = (NamedObj) _graphModel.getSemanticObject(node);

        if (doBoxLayout || PtolemyModelUtil._isConnected(semanticNode)) {
            // Temporary variable for the new KNode corresponding to one of
            // the following cases depending on what the semantic object is.
            KNode knode = null;

            // Handle actors, text, and directors.
            if (semanticNode instanceof Actor || semanticNode instanceof Attribute) {

                // Create a KIELER node for a ptolemy node.
                knode = _createKNode(node, semanticNode);

                // Handle the ports of this node.
                if (semanticNode instanceof Actor && semanticNode instanceof Entity) {
                    Actor actor = (Actor) semanticNode;
                    List<Port> inputs = actor.inputPortList();
                    List<Port> outputs = actor.outputPortList();

                    // create ports
                    _createKPorts(knode, inputs);
                    _createKPorts(knode, outputs);
                    portIter = _graphModel.nodes(node);
                } else if (semanticNode instanceof RelativeLocatable) {
                    unprocessedRelatives.add(semanticNode);
                }
            }

            // Handle relation vertices.
            else if (semanticNode instanceof Relation) {
                // Regard a relation vertex as a KIELER KNode.
                knode = _createKNodeForVertex((Vertex) node);
                portIter = Iterators.singletonIterator(node);
            }

            // Handle internal ports.
            else if (semanticNode instanceof ComponentPort) {
                knode = _createKNodeForPort(node, (ComponentPort) semanticNode);
                portIter = Iterators.singletonIterator(node);
            }

            // Handle modal model states.
            else if (semanticNode instanceof State) {
                knode = _createKNodeForState(node, (State) semanticNode);
                portIter = Iterators.singletonIterator(node);
            }

            // Now do some common bookkeeping for all kinds of nodes.
            if (knode != null) {
                // some nodes, such as FSM's ports may already 
                // be assigned to a node other than the parent node
                if (knode.getParent() == null) {
                    knode.setParent(parentNode);
                }
                // Get check bounds for global bounding box.
                KShapeLayout layout = knode.getData(KShapeLayout.class);
                if (layout.getXpos() < globalX) {
                    globalX = layout.getXpos();
                }
                if (layout.getYpos() < globalY) {
                    globalY = layout.getYpos();
                }

                // Store node for later applying layout back.
                _kieler2ptolemyDivaNodes.put(knode, (Locatable) node);
            }
        }

        if (portIter != null) {
            while (portIter.hasNext()) {
                Object divaPort = portIter.next();
                // Iterate all outgoing edges.
                Iterator edgeIterator;
                if (semanticNode instanceof Port && externalPortModel != null) { // internal ports
                    edgeIterator = externalPortModel.outEdges(divaPort);
                } else {
                    edgeIterator = _graphModel.outEdges(divaPort);
                }
                while (edgeIterator.hasNext()) {
                    Object next = edgeIterator.next();
                    if (next instanceof Link) {
                        unprocessedEdges.add((Link) next);
                    }
                }
            }
        }
    }

    // Create KIELER edges for Diva edges.
    if (_graphModel instanceof ActorGraphModel) {
        _storeEndpoints(unprocessedEdges);
    }
    for (Link divaEdge : unprocessedEdges) {
        _createKEdge(divaEdge);
    }

    // Create edges for associations of relative locatables to their reference objects.
    for (NamedObj relativeObj : unprocessedRelatives) {
        _createKEdgeForAttribute(relativeObj);
    }

    // Set graph offset.
    parentLayout.setXpos(globalX);
    parentLayout.setYpos(globalY);
}

From source file:org.jpmml.evaluator.general_regression.GeneralRegressionModelEvaluator.java

static private BiMap<FieldName, Predictor> parsePredictorRegistry(PredictorList predictorList) {
    BiMap<FieldName, Predictor> result = HashBiMap.create();

    if (predictorList == null || !predictorList.hasPredictors()) {
        return result;
    }/*from  w  w w. jav  a2 s. c o  m*/

    List<Predictor> predictors = predictorList.getPredictors();
    for (Predictor predictor : predictors) {
        result.put(predictor.getName(), predictor);
    }

    return result;
}

From source file:org.opencb.opencga.storage.mongodb.variant.converters.DocumentToSamplesConverter.java

/**
 * Lazy usage of loaded samplesIdMap.//from  w  w w .j a va2 s .co  m
 **/
private BiMap<String, Integer> getIndexedSamplesIdMap(int studyId) {
    BiMap<String, Integer> sampleIds;
    if (this.__studySamplesId.get(studyId) == null) {
        StudyConfiguration studyConfiguration = studyConfigurations.get(studyId);
        sampleIds = StudyConfiguration.getIndexedSamples(studyConfiguration);
        if (!returnedSamples.isEmpty()) {
            BiMap<String, Integer> returnedSampleIds = HashBiMap.create();
            sampleIds.entrySet().stream()
                    //ReturnedSamples could be sampleNames or sampleIds as a string
                    .filter(e -> returnedSamples.contains(e.getKey())
                            || returnedSamples.contains(e.getValue().toString()))
                    .forEach(stringIntegerEntry -> returnedSampleIds.put(stringIntegerEntry.getKey(),
                            stringIntegerEntry.getValue()));
            sampleIds = returnedSampleIds;
        }
        this.__studySamplesId.put(studyId, sampleIds);
    } else {
        sampleIds = this.__studySamplesId.get(studyId);
    }

    return sampleIds;
}

From source file:org.apache.ctakes.ytex.uima.mapper.DocumentMapperServiceImpl.java

private BiMap<Annotation, Integer> saveAnnoBase(final JCas jcas, final Set<String> setTypesToIgnore,
        final int docId) {
    final AnnotationIndex<Annotation> annoIdx = jcas.getAnnotationIndex(Annotation.typeIndexID);
    final List<Annotation> listAnno = new ArrayList<Annotation>(annoIdx.size());
    final BiMap<Annotation, Integer> mapAnnoToId = HashBiMap.create();
    final FSIterator<Annotation> annoIterator = annoIdx.iterator();
    this.sessionFactory.getCurrentSession().doWork(new Work() {

        @Override/* w  w w. j a va2  s  .co m*/
        public void execute(Connection conn) throws SQLException {
            PreparedStatement ps = null;
            ResultSet rs = null;
            try {
                ps = conn.prepareStatement("insert into " + getTablePrefix()
                        + "anno_base (document_id, span_begin, span_end, uima_type_id) values (?, ?, ?, ?)",
                        Statement.RETURN_GENERATED_KEYS);
                while (annoIterator.hasNext()) {
                    Annotation anno = (Annotation) annoIterator.next();
                    String annoClass = anno.getClass().getName();
                    if (!setTypesToIgnore.contains(annoClass) && uimaTypeMap.containsKey(annoClass)) {
                        // should not ignore, and we know how to map this
                        // annotation
                        listAnno.add(anno);
                        ps.setInt(1, docId);
                        ps.setInt(2, anno.getBegin());
                        ps.setInt(3, anno.getEnd());
                        ps.setInt(4, uimaTypeMap.get(annoClass).getUimaTypeID());
                        ps.addBatch();
                    }
                }
                ps.executeBatch();
                rs = ps.getGeneratedKeys();
                int annoIndex = 0;
                while (rs.next()) {
                    mapAnnoToId.put(listAnno.get(annoIndex), rs.getInt(1));
                    annoIndex++;
                }
            } catch (SQLException e) {
                throw new RuntimeException(e);
            } finally {
                if (rs != null) {
                    try {
                        rs.close();
                    } catch (SQLException e) {
                    }
                }
                if (ps != null) {
                    try {
                        ps.close();
                    } catch (SQLException e) {
                    }
                }
            }
        }
    });
    return mapAnnoToId;
}

From source file:org.usergrid.management.cassandra.ManagementServiceImpl.java

@Override
public List<OrganizationInfo> getOrganizations(UUID startResult, int count) throws Exception {
    // still need the bimap to search for existing
    BiMap<UUID, String> organizations = HashBiMap.create();
    EntityManager em = emf.getEntityManager(MANAGEMENT_APPLICATION_ID);
    Results results = em.getCollection(em.getApplicationRef(), "groups", startResult, count,
            Level.ALL_PROPERTIES, false);
    List<OrganizationInfo> orgs = new ArrayList<OrganizationInfo>(results.size());
    OrganizationInfo orgInfo;//from  w w  w.  j  a  v  a2  s  .  co m
    for (Entity entity : results.getEntities()) {
        // TODO T.N. temporary hack to deal with duplicate orgs. Revert this
        // commit after migration
        String path = (String) entity.getProperty("path");

        if (organizations.containsValue(path)) {
            path += "DUPLICATE";
        }
        orgInfo = new OrganizationInfo(entity.getUuid(), path);
        orgs.add(orgInfo);
        organizations.put(entity.getUuid(), path);
    }
    return orgs;
}

From source file:org.usergrid.management.cassandra.ManagementServiceImpl.java

private BiMap<UUID, String> buildOrgBiMap(List<OrganizationInfo> orgs) {
    BiMap<UUID, String> organizations = HashBiMap.create();
    for (OrganizationInfo orgInfo : orgs) {
        organizations.put(orgInfo.getUuid(), orgInfo.getName());
    }/*from   w  w w .j a  v a 2 s.  c  om*/
    return organizations;
}