com.google.common.collect.BiMap#containsValue ( )源码实例Demo

下面列出了com.google.common.collect.BiMap#containsValue ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: atlas   文件: HBaseStoreManager.java
public static String shortenCfName(BiMap<String, String> shortCfNameMap, String longName) throws PermanentBackendException {
    final String s;
    if (shortCfNameMap.containsKey(longName)) {
        s = shortCfNameMap.get(longName);
        Preconditions.checkNotNull(s);
        logger.debug("Substituted default CF name \"{}\" with short form \"{}\" to reduce HBase KeyValue size", longName, s);
    } else {
        if (shortCfNameMap.containsValue(longName)) {
            String fmt = "Must use CF long-form name \"%s\" instead of the short-form name \"%s\" when configured with %s=true";
            String msg = String.format(fmt, shortCfNameMap.inverse().get(longName), longName, SHORT_CF_NAMES.getName());
            throw new PermanentBackendException(msg);
        }
        s = longName;
        logger.debug("Kept default CF name \"{}\" because it has no associated short form", s);
    }
    return s;
}
 
private static Map<Set<User>, SortedSet<MessagePair>> groupRecipientsForMessagePairs(
    Map<User, SortedSet<MessagePair>> messagePairsPerUser )
{
    BiMap<Set<User>, SortedSet<MessagePair>> grouped = HashBiMap.create();

    for ( Map.Entry<User, SortedSet<MessagePair>> entry : messagePairsPerUser.entrySet() )
    {
        User user = entry.getKey();
        SortedSet<MessagePair> setOfPairs = entry.getValue();

        if ( grouped.containsValue( setOfPairs ) )
        {
            // Value exists -> Add user to the existing key set
            grouped.inverse().get( setOfPairs ).add( user );
        }
        else
        {
            // Value doesn't exist -> Add the [user, set] as a new entry
            grouped.put( Sets.newHashSet( user ), setOfPairs );
        }
    }

    return grouped;
}
 
源代码3 项目: BIMserver   文件: IfcModel.java
@SuppressWarnings("rawtypes")
private void fixOids(IdEObject idEObject, OidProvider oidProvider, BiMap<Long, IdEObject> temp) {
	if (idEObject == null) {
		return;
	}
	if (temp.containsValue(idEObject)) {
		return;
	}
	((IdEObjectImpl) idEObject).setOid(oidProvider.newOid(idEObject.eClass()));
	if (objects.containsValue(idEObject)) {
		temp.put(idEObject.getOid(), idEObject);
	}
	for (EReference eReference : idEObject.eClass().getEAllReferences()) {
		Object val = idEObject.eGet(eReference);
		if (eReference.isMany()) {
			List list = (List) val;
			for (Object o : list) {
				fixOids((IdEObject) o, oidProvider, temp);
			}
		} else {
			fixOids((IdEObject) val, oidProvider, temp);
		}
	}
}
 
源代码4 项目: usergrid   文件: 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(smf.getManagementAppId());
    Results results = em.getCollection(em.getApplicationRef(),
        Schema.COLLECTION_GROUPS, startResult, count, Level.ALL_PROPERTIES, false);
    List<OrganizationInfo> orgs = new ArrayList<>( results.size() );
    OrganizationInfo orgInfo;
    for ( Entity entity : results.getEntities() ) {

        String path = ( String ) entity.getProperty( PROPERTY_PATH );

        if ( organizations.containsValue( path ) ) {
            path += "DUPLICATE";
        }
        orgInfo = new OrganizationInfo( entity.getUuid(), path );
        orgs.add( orgInfo );
        organizations.put( entity.getUuid(), path );
    }
    return orgs;
}
 
源代码5 项目: immutables   文件: UniqueCachedNaming.java
private static <T> BiMap<T, String> buildBiMap(Iterable<T> values) {
  @SuppressWarnings("unchecked")
  Suggester<T> suggester = (Suggester<T>) PREFIX_SUGGESTER;
  final BiMap<T, String> map = HashBiMap.create();
  for (T value: values) {
    if (!map.containsKey(value)) {
      String name;
      for (int i = 0; ; i++) {
        name = suggester.suggest(value, i, map.size());
        if (!map.containsValue(name)) {
          map.put(value, name);
          break; // name found, break the loop
        }
      }
    }
  }

  return ImmutableBiMap.copyOf(map);
}
 
源代码6 项目: xtext-core   文件: KeywordHelper.java
private BiMap<CharSequence, String> createKeywordMap(Grammar grammar) {
	List<ParserRule> parserRules = GrammarUtil.allParserRules(grammar);
	List<EnumRule> enumRules = GrammarUtil.allEnumRules(grammar);
	Iterator<EObject> iter = Iterators.concat(
			EcoreUtil.<EObject>getAllContents(parserRules), EcoreUtil.<EObject>getAllContents(enumRules));
	Iterator<Keyword> filtered = Iterators.filter(iter, Keyword.class);
	Iterator<String> transformed = Iterators.transform(filtered, new Function<Keyword, String>() {
		@Override
		public String apply(Keyword from) {
			return from.getValue();
		}
	});
	TreeSet<String> treeSet = Sets.newTreeSet(new Comparator<String>() {
		@Override
		public int compare(String o1, String o2) {
			if (o1.length() == o2.length())
				return o1.compareTo(o2);
			return Integer.valueOf(o1.length()).compareTo(Integer.valueOf(o2.length()));
		}
	});
	Iterators.addAll(treeSet, transformed);
	BiMap<CharSequence, String> result = HashBiMap.create();
	for(String s: treeSet) {
		CharSequence key = createKey(s);
		String readableName = toAntlrTokenIdentifier(s);
		if (result.containsValue(readableName)) {
			int i = 1;
			String next = readableName + "_" + i;
			while(result.containsValue(next)) {
				i++;
				next = readableName + "_" + i;
			}
			readableName = next;
		}
		result.put(key, readableName);
	}
	return result;
}
 
源代码7 项目: mars-sim   文件: TaskSchedule.java
/**
 * Gets the ID of a BiMap
 * 
 * @param map
 * @param value
 * @return
 */
public int getID(BiMap<Integer, String> map, String value) {
	if (map.containsValue(value)) {
		return map.inverse().get(value);
	} else {
		int size = map.size();
		map.put(size + 1, value);
		return size + 1;
	}
}
 
源代码8 项目: BIMserver   文件: IfcModel.java
private void fixOidsFlat(IdEObject idEObject, OidProvider oidProvider, BiMap<Long, IdEObject> temp) {
	if (idEObject == null) {
		return;
	}
	if (temp.containsValue(idEObject)) {
		return;
	}
	((IdEObjectImpl) idEObject).setOid(oidProvider.newOid(idEObject.eClass()));
	if (objects.containsValue(idEObject)) {
		temp.put(idEObject.getOid(), idEObject);
	}
}
 
源代码9 项目: BIMserver   文件: IfcModel.java
@SuppressWarnings("rawtypes")
private void checkDoubleOidsPlusReferences(BiMap<IdEObject, Long> done, IdEObject idEObject) {
	if (idEObject == null) {
		return;
	}
	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));
		}
	}
}
 
/**
 * Validate that the record types have all been evolved in a legal way. In particular, this makes sure that
 * each record type defined in the union descriptor is in the new union descriptor in the correct
 * place. It will then verify that each message type has been updated in a legal way, i.e., that it only
 * includes new fields.
 *
 * @param oldUnionDescriptor the union descriptor for the existing meta-data for some record store
 * @param newUnionDescriptor the new proposed meta-data
 */
@SuppressWarnings("PMD.CompareObjectsWithEquals")
public void validateUnion(@Nonnull Descriptor oldUnionDescriptor, @Nonnull Descriptor newUnionDescriptor) {
    if (oldUnionDescriptor == newUnionDescriptor) {
        // Don't bother validating the record types if they are all the same.
        return;
    }
    final BiMap<Descriptor, Descriptor> updatedDescriptors = HashBiMap.create(oldUnionDescriptor.getFields().size());
    final Set<Pair<Descriptor, Descriptor>> seenDescriptors = new HashSet<>();

    for (FieldDescriptor oldUnionField : oldUnionDescriptor.getFields()) {
        if (!oldUnionField.getType().equals(FieldDescriptor.Type.MESSAGE)) {
            throw new MetaDataException("field in union is not a message type", LogMessageKeys.FIELD_NAME, oldUnionField.getName());
        }
        int fieldNumber = oldUnionField.getNumber();
        FieldDescriptor newUnionField = newUnionDescriptor.findFieldByNumber(fieldNumber);
        if (newUnionField != null) {
            if (!newUnionField.getType().equals(FieldDescriptor.Type.MESSAGE)) {
                throw new MetaDataException("field in new union is not a message type", LogMessageKeys.FIELD_NAME, newUnionField.getName());
            }
            Descriptor oldRecord = oldUnionField.getMessageType();
            Descriptor newRecord = newUnionField.getMessageType();

            // Verify that all fields of the same type in the old union are also of the same type
            // in the new union (i.e., that there are no "splits" or "merges" of record types).
            Descriptor alreadySeenNewRecord = updatedDescriptors.get(oldRecord);
            if (alreadySeenNewRecord != null) {
                if (alreadySeenNewRecord != newRecord) {
                    // A "split" -- the same type in the old union points to two different types in the new union
                    throw new MetaDataException("record type corresponds to multiple types in new meta-data",
                            LogMessageKeys.OLD_RECORD_TYPE, oldRecord.getName(),
                            LogMessageKeys.NEW_RECORD_TYPE, newRecord.getName() + " & " + alreadySeenNewRecord.getName());
                }
            } else {
                if (updatedDescriptors.containsValue(newRecord)) {
                    // A "merge" -- two different types in the old union point to the same type in the new union
                    final Descriptor alreadySeenOldRecord = updatedDescriptors.inverse().get(newRecord);
                    throw new MetaDataException("record type corresponds to multiple types in old meta-data",
                            LogMessageKeys.OLD_RECORD_TYPE, oldRecord.getName() + " & " + alreadySeenOldRecord.getName(),
                            LogMessageKeys.NEW_RECORD_TYPE, newRecord.getName());
                }
            }
            updatedDescriptors.put(oldRecord, newRecord);

            // Validate the form of the old and new record types
            validateMessage(oldRecord, newRecord, seenDescriptors);
        } else {
            throw new MetaDataException("record type removed from union", LogMessageKeys.RECORD_TYPE, oldUnionField.getMessageType());
        }
    }
}