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

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

Introduction

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

Prototype

boolean containsKey(Object key);

Source Link

Document

Returns true if this map contains a mapping for the specified key.

Usage

From source file:suneido.compiler.ClassGen.java

SuCompiledCallable end(SuClass suClass) {
    if (blockReturnCatcher != null)
        finishBlockReturnCatcher();//from   w w w  .  j ava 2 s  .com
    if (dynamicFinally != null)
        finishDynamicPushPop();

    Label endLabel = placeLabel();
    BiMap<Integer, String> bm = javaLocals.inverse();
    for (int i = 0; i < nextJavaLocal; ++i)
        if (bm.containsKey(i))
            mv.visitLocalVariable(javify(bm.get(i)), "[Ljava/lang/Object;", null, startLabel, endLabel, i);

    mv.visitMaxs(0, 0);
    mv.visitEnd();

    if (!constants.isEmpty())
        genClinit();

    cv.visitEnd();

    SuCompiledCallable callable;
    shareConstants.set(constants);
    final byte[] byteCode = cw.toByteArray();
    try {
        // FIXME: Is it a good idea to have a separate new ClassLoader for
        //        each of potentially thousands of new classes?
        Loader loader = new Loader();
        Class<?> sc = loader.defineClass(COMPILED_CODE_PACKAGE_DOTS + name, byteCode);
        try {
            callable = (SuCompiledCallable) sc.getDeclaredConstructor().newInstance();
        } catch (InstantiationException | IllegalAccessException | NoSuchMethodException
                | InvocationTargetException e) {
            throw new SuException("newInstance error: " + e);
        }
    } finally {
        shareConstants.set(null);
    }

    return callable.finishInit(suClass, functionSpec(bm), context, callableType, byteCode);
}

From source file:org.diorite.impl.connection.EnumProtocol.java

public synchronized <T extends Packet<?>> void init(final EnumProtocolDirection enumProtocolDirection,
        final int id, final Class<T> clazz, final Supplier<T> supplier) {
    BiMap<Integer, Class<?>> create = this.packetsMap.get(enumProtocolDirection);
    final Int2ObjectMap<Supplier<? extends Packet<?>>> suppMap;
    if (create == null) {
        create = HashBiMap.create();/* w  ww.  j a va 2  s  . co m*/
        suppMap = new Int2ObjectOpenHashMap<>((this == PLAY) ? PLAY_PACKETS_SIZE : OTHER_PACKETS_SIZE, .1f);
        this.packetsMap.put(enumProtocolDirection, create);
        this.packetsSupplierMap.put(enumProtocolDirection, suppMap);
    } else {
        suppMap = this.packetsSupplierMap.get(enumProtocolDirection);
    }
    if (create.containsValue(clazz)) {
        throw new IllegalArgumentException(
                enumProtocolDirection + " packet " + clazz.getName() + " is already known to ID "
                        + Integer.toHexString(create.inverse().get(clazz)) + " (" + create.get(id) + ")");
    }
    if (create.containsKey(id)) {
        throw new IllegalArgumentException(enumProtocolDirection + " packet (" + clazz.getName() + ") with id "
                + Integer.toHexString(id) + " is already known to packet " + create.get(id));
    }
    classEnumProtocolMap.put(clazz, this);
    create.put(id, clazz);
    suppMap.put(id, supplier);
}

From source file:ca.wumbo.wdl.parser.events.Event.java

/**
 * Gets the insertion query statement for this event.
 * //from  w  ww .ja  va2 s.  c  o  m
 * @param database
 *       The database this belongs to. This should not be empty.
 * 
 * @param table
 *       The table for this event.
 * 
 * @param nameToPlayerIdMap
 *       The name to player ID map.
 * @param eventLogId 
 * 
 * @return
 *       A query statement that can be issued to the database.
 * 
 * @throws NullPointerException
 *       If any argument is null.
 * 
 * @throws IllegalArgumentException
 *       If any string or table has zero characters/elements, or the log id
 *       is negative.
 * 
 * @throws RuntimeException
 *       If neither an activator nor target ID can be found (both parts
 *       of the query for the ID's would be 'NULL').
 */
public String getSqlInsertionQuery(String database, String table, BiMap<String, Integer> nameToPlayerIdMap,
        int eventLogId) {
    checkNotNull(database);
    checkNotNull(table);
    checkNotNull(nameToPlayerIdMap);
    checkArgument(database.length() > 0);
    checkArgument(table.length() > 0);
    checkArgument(nameToPlayerIdMap.size() > 0);
    checkArgument(eventLogId >= 0);

    String tblArgs = "fk_event_log_id, type, nfk_activator_player_id, nfk_target_player_id, "
            + "gametic, activator_x, activator_y, activator_z, "
            + "target_x, target_y, target_z, arg0, arg1, arg2";
    String valueArgs = "%d, %d, %s, %s, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d";
    String activatorIdOrNullSqlStr = activator != null && nameToPlayerIdMap.containsKey(activator.getName())
            ? Integer.toString(nameToPlayerIdMap.get(activator.getName()))
            : "NULL";
    String targetIdOrNullSqlStr = target.isPresent() && nameToPlayerIdMap.containsKey(target.get().getName())
            ? Integer.toString(nameToPlayerIdMap.get(target.get().getName()))
            : "NULL";

    // If both are null, something is critically wrong.
    if (activatorIdOrNullSqlStr.equals("NULL") && targetIdOrNullSqlStr.equals("NULL")) {
        throw new RuntimeException(
                "Both activator and target are 'NULL', malformed event or corrupt name to ID map.");
    }

    return String.format("INSERT INTO `%s`.`%s`(%s) VALUES(" + valueArgs + ")", database, table, tblArgs,
            eventLogId, getEventTypeNumber(), activatorIdOrNullSqlStr, targetIdOrNullSqlStr, getGametic(),
            getActivatorX(), getActivatorY(), getActivatorZ(), getTargetX(), getTargetY(), getTargetZ(),
            getArg0(), getArg1(), getArg2());
}

From source file:com.android.tools.idea.editors.navigation.NavigationView.java

private void syncTransitionCache(BiMap<Transition, Component> assoc) {
    if (DEBUG)//from w w  w . j a  v a2s .  co  m
        LOG.info("NavigationView: syncTransitionCache");
    // add anything that is in the model but not in our cache
    for (Transition transition : myNavigationModel.getTransitions()) {
        if (!assoc.containsKey(transition)) {
            Component editor = createEditorFor(transition);
            add(editor);
            assoc.put(transition, editor);
        }
    }
    // remove anything that is in our cache but not in the model
    removeLeftovers(assoc, myNavigationModel.getTransitions());
}

From source file:org.wrml.runtime.schema.DefaultSchemaLoader.java

@Override
public final String getNativeTypeName(final URI typeUri) {

    final BiMap<URI, String> uriToNativeTypeNameBiMapView = _NativeTypeNameToUriBiMap.inverse();
    if (!uriToNativeTypeNameBiMapView.containsKey(typeUri)) {

        final UniqueName uniqueName = getTypeUniqueName(typeUri);
        if (uniqueName == null) {
            throw new SchemaLoaderException("The type's uniqueName could not be determined from: " + typeUri,
                    null, this);
        }//from  w w w  .j a  v  a2s .  co m

        String localName = uniqueName.getLocalName();
        if (localName != null) {
            int indexOfLastDot = localName.lastIndexOf(".");

            if (indexOfLastDot > 0) {
                localName = localName.substring(0, indexOfLastDot);
            } else if (indexOfLastDot == 0) {
                localName = localName.substring(1);
            }
        }

        String namespace = uniqueName.getNamespace();
        if (namespace != null) {
            namespace = StringUtils.replaceChars(namespace, ".", "_");
        }

        String internalTypeName;
        if (namespace != null && localName != null) {
            String suffix = localName.trim();
            if (!suffix.isEmpty()) {
                suffix = UniqueName.NAME_SEPARATOR + suffix;
            }

            internalTypeName = namespace + suffix;
        } else if (namespace == null && localName == null) {
            internalTypeName = "unnamed";
        } else if (namespace == null && localName != null) {
            internalTypeName = localName;
        } else {
            internalTypeName = namespace;
        }

        internalTypeName = StringUtils.replaceChars(internalTypeName, ".", "_");
        final String schemaInterfaceName = SchemaGenerator.internalTypeNameToExternalTypeName(internalTypeName);

        _NativeTypeNameToUriBiMap.put(schemaInterfaceName, typeUri);
    }

    return uriToNativeTypeNameBiMapView.get(typeUri);

}

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

@SuppressWarnings("rawtypes")
private void checkDoubleOidsPlusReferences(BiMap<IdEObject, Long> done, IdEObject idEObject) {
    if (idEObject == null) {
        return;//from ww w. j  a v  a2s.co m
    }
    if (idEObject.eClass().getEAnnotation("wrapped") != null) {
        return;
    }
    if (done.containsKey(idEObject)) {
        return;
    }
    if (done.containsValue(idEObject.getOid())) {
        showBackReferences(idEObject);
        IdEObject existing = done.inverse().get(idEObject.getOid());
        showBackReferences(existing);
        throw new RuntimeException("Double oid: " + idEObject.getOid() + " " + idEObject + ", " + existing);
    }
    done.put(idEObject, idEObject.getOid());
    for (EReference eReference : idEObject.eClass().getEAllReferences()) {
        if (eReference.isMany()) {
            List list = (List) idEObject.eGet(eReference);
            for (Object o : list) {
                checkDoubleOidsPlusReferences(done, (IdEObject) o);
            }
        } else {
            checkDoubleOidsPlusReferences(done, (IdEObject) idEObject.eGet(eReference));
        }
    }
}

From source file:com.android.tools.idea.editors.navigation.NavigationView.java

private void syncStateCache(BiMap<State, AndroidRootComponent> assoc) {
    if (DEBUG)/*from  www .  j  a  v  a  2s .co  m*/
        LOG.info("NavigationView: syncStateCache");
    assoc.clear();
    removeAll();
    //repaint();

    // add anything that is in the model but not in our cache
    for (State state : myNavigationModel.getStates()) {
        if (!assoc.containsKey(state)) {
            AndroidRootComponent root = createRootComponentFor(state);
            assoc.put(state, root);
            add(root);
        }
    }

    setPreferredSize();
}

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;/*from w ww .j ava  2  s  .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;// w ww  .  j  a va2  s  . 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.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:org.sosy_lab.cpachecker.cpa.smg.SMGIntersectStates.java

private static boolean intersectValues(int pValue1, int pValue2, CLangSMG pSmg1, CLangSMG pSmg2,
        CLangSMG pDestSMG, SMGNodeMapping pMapping1, SMGNodeMapping pMapping2,
        Set<SMGEdgeHasValue> pSingleHveEdge1, Set<SMGEdgeHasValue> pSingleHveEdge2,
        BiMap<SMGKnownSymValue, SMGKnownExpValue> pExplicitValues,
        BiMap<SMGKnownSymValue, SMGKnownExpValue> pExplicitValues2,
        BiMap<SMGKnownSymValue, SMGKnownExpValue> pDestExplicitValues) {

    boolean containsValue1 = pMapping1.containsKey(pValue1);
    boolean containsValue2 = pMapping2.containsKey(pValue2);

    /*Already intersected*/
    if (containsValue1 && containsValue2) {
        return pMapping1.get(pValue1).equals(pMapping2.get(pValue2));
    }/*from   w w  w  .  j  a v  a  2s  .c  om*/

    /*Intesect is null due to different values.*/
    if (containsValue1 || containsValue2) {
        return false;
    }

    int destValue = pValue1;

    pMapping1.map(pValue1, destValue);
    pMapping2.map(pValue2, destValue);
    pDestSMG.addValue(destValue);

    boolean isPointer1 = pSmg1.isPointer(pValue1);
    boolean isPointer2 = pSmg2.isPointer(pValue2);

    if ((isPointer1 && !isPointer2) || (!isPointer1 && isPointer2)) {
        return false;
    }

    if (isPointer1 && isPointer2) {
        SMGEdgePointsTo pte1 = pSmg1.getPointer(pValue1);
        SMGEdgePointsTo pte2 = pSmg2.getPointer(pValue2);

        boolean defined = intersectPairPointsToEdges(pte1, pte2, destValue, pSmg1, pSmg2, pDestSMG, pMapping1,
                pMapping2, pSingleHveEdge1, pSingleHveEdge2, pExplicitValues, pExplicitValues2,
                pDestExplicitValues);

        if (!defined) {
            return false;
        }
    }

    SMGKnownSymValue symVal1 = SMGKnownSymValue.valueOf(pValue1);
    SMGKnownSymValue symVal2 = SMGKnownSymValue.valueOf(pValue2);
    SMGKnownSymValue symDestVal = symVal1;

    SMGExplicitValue expVal1 = SMGUnknownValue.getInstance();
    SMGExplicitValue expVal2 = SMGUnknownValue.getInstance();

    if (pExplicitValues.containsKey(symVal1)) {
        expVal1 = pExplicitValues.get(symVal1);
    }

    if (pExplicitValues.containsKey(symVal2)) {
        expVal2 = pExplicitValues.get(symVal2);
    }

    if (!expVal1.isUnknown() && !expVal2.isUnknown()) {
        if (expVal1.equals(expVal2)) {
            pDestExplicitValues.put(symDestVal, (SMGKnownExpValue) expVal1);
        } else {
            return false;
        }
    } else if (!expVal1.isUnknown()) {
        pDestExplicitValues.put(symDestVal, (SMGKnownExpValue) expVal1);
    } else if (!expVal2.isUnknown()) {
        pDestExplicitValues.put(symDestVal, (SMGKnownExpValue) expVal2);
    }

    return true;
}