List of usage examples for com.google.common.collect BiMap containsKey
boolean containsKey(Object key);
From source file:com.wolvereness.overmapped.MembersSubRoutine.java
private static void performParentChecks(final Store store, final BiMap<String, String> nameMaps, final BiMap<Signature, Signature> inverseSignatureMaps, final MutableSignature mutableSignature, Object className_s, final String newName, final String oldName, final String description, final String originalDescription) { final Set<String> parents = store.parents; if (parents != null) { parents.removeAll(store.searchCache); if (parents.isEmpty()) return; if (className_s instanceof String) { className_s = nameMaps.get(className_s); } else {/*from ww w. j a v a 2 s . co m*/ final Collection<String> originalClassNames = newArrayList(); for (final Object className : (Iterable<?>) className_s) { originalClassNames.add(nameMaps.get(className)); } className_s = originalClassNames; } for (final String parent : parents) { if (inverseSignatureMaps.containsKey(mutableSignature.update(parent, oldName, description))) { store.instance.getLog() .info(String.format("Expected parent method mapping for `%s'->`%s' from mappings in %s", mutableSignature.update(nameMaps.get(parent), oldName, originalDescription), mutableSignature.forElementName(newName), className_s)); } } parents.clear(); } }
From source file:it.sayservice.platform.smartplanner.cache.AgencyCacheIndex.java
private CompressedCalendar compressCalendar(Map<String, String> cal) { CompressedCalendar ccal = new CompressedCalendar(); int i = 0;/*from w ww .j av a 2s .co 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.apache.gobblin.converter.filter.GobblinTrackingEventFlattenFilterConverter.java
@Override public Iterable<GenericRecord> convertRecord(Schema outputSchema, GenericRecord inputRecord, WorkUnitState workUnit) throws DataConversionException { GenericRecord genericRecord = new GenericData.Record(outputSchema); BiMap<String, String> inversedViewOfFieldsRenameMap = this.fieldsRenameMap.inverse(); for (Schema.Field field : outputSchema.getFields()) { String curFieldName = field.name(); String originalFieldName = inversedViewOfFieldsRenameMap.containsKey(curFieldName) ? inversedViewOfFieldsRenameMap.get(curFieldName) : curFieldName;/*from w w w . ja v a2 s.c o m*/ if (this.nonMapFields.contains(originalFieldName)) { genericRecord.put(curFieldName, inputRecord.get(originalFieldName)); } else { genericRecord.put(curFieldName, AvroUtils .getFieldValue(inputRecord, Joiner.on('.').join(this.mapFieldName, originalFieldName)) .or("")); } } return new SingleRecordIterable<>(genericRecord); }
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 . ja v a 2 s.co 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:gobblin.util.PortUtils.java
/** * Replaces any port tokens in the specified string. * * NOTE: Tokens can be in the following forms: * 1. ${PORT_123}/*from www .java 2s . co m*/ * 2. ${PORT_?123} * 3. ${PORT_123?} * 4. ${PORT_?} * * @param value The string in which to replace port tokens. * @return The replaced string. */ public String replacePortTokens(String value) { BiMap<String, Optional<Integer>> portMappings = HashBiMap.create(); Matcher regexMatcher = PORT_REGEX.matcher(value); while (regexMatcher.find()) { String token = regexMatcher.group(0); if (!portMappings.containsKey(token)) { Optional<Integer> portStart = Optional.absent(); Optional<Integer> portEnd = Optional.absent(); String unboundedStart = regexMatcher.group(1); if (unboundedStart != null) { int requestedEndPort = Integer.parseInt(unboundedStart); Preconditions.checkArgument(requestedEndPort <= PortUtils.MAXIMUM_PORT); portEnd = Optional.of(requestedEndPort); } else { String unboundedEnd = regexMatcher.group(2); if (unboundedEnd != null) { int requestedStartPort = Integer.parseInt(unboundedEnd); Preconditions.checkArgument(requestedStartPort >= PortUtils.MINIMUM_PORT); portStart = Optional.of(requestedStartPort); } else { String absolute = regexMatcher.group(3); if (!"?".equals(absolute)) { int requestedPort = Integer.parseInt(absolute); Preconditions.checkArgument(requestedPort >= PortUtils.MINIMUM_PORT && requestedPort <= PortUtils.MAXIMUM_PORT); portStart = Optional.of(requestedPort); portEnd = Optional.of(requestedPort); } } } Optional<Integer> port = takePort(portStart, portEnd); portMappings.put(token, port); } } for (Map.Entry<String, Optional<Integer>> port : portMappings.entrySet()) { if (port.getValue().isPresent()) { value = value.replace(port.getKey(), port.getValue().get().toString()); } } return value; }
From source file:org.wrml.runtime.syntax.DefaultSyntaxLoader.java
@Override public final URI getSyntaxUri(final Class<?> syntaxClass) { final BiMap<Class<?>, URI> javaClassToSyntaxUriMap = _SyntaxUriToJavaClassBiMap.inverse(); if (!javaClassToSyntaxUriMap.containsKey(syntaxClass)) { return null; }//w w w .j ava 2 s . c o m return javaClassToSyntaxUriMap.get(syntaxClass); }
From source file:de.matzefratze123.heavyspleef.core.flag.FlagRegistry.java
public boolean isChildFlag(Class<? extends AbstractFlag<?>> parent, Class<? extends AbstractFlag<?>> childCandidate) { Validate.notNull(parent, "parent cannot be null"); Validate.notNull(childCandidate, "child candidate cannot be null"); BiMap<Class<? extends AbstractFlag<?>>, DualKeyPair<String, Flag>> inverse = registeredFlagsMap.inverse(); Validate.isTrue(inverse.containsKey(childCandidate), "childCandidate flag " + childCandidate.getName() + " has not been registered"); Flag annotation = inverse.get(childCandidate).getSecondaryKey(); Validate.isTrue(annotation != null, "childCandidate has not been registered"); return annotation.parent() != null && annotation.parent() != NullFlag.class && annotation.parent() == childCandidate; }
From source file:uk.ac.susx.tag.method51.twitter.apikeystore.JsonApiKeyPersistenceImpl.java
private synchronized BiMap<String, ApiKey> deserialiseKeys() { if (!storeFile.exists()) { LOG.warn("non-existent api key file!"); serialiseKeys(HashBiMap.<String, ApiKey>create()); //shouldn't really have disappeared... }//from w ww.j a v a 2 s .c o m Map<String, Map<String, Object>> data; try (FileLock lock = new FileOutputStream(storeFile, true).getChannel().lock();) { data = new Gson().fromJson(Files.getText(storeFile).toString(), Map.class); } catch (IOException e) { throw new RuntimeException(e); } if (data == null) { LOG.warn("empty api key file!"); data = new HashMap<>(); } BiMap<String, ApiKey> keys = HashBiMap.create(); for (Map.Entry<String, Map<String, Object>> entry : data.entrySet()) { String id = entry.getKey(); if (!keys.containsKey(id)) { ApiKey key = mapToApiKey(entry.getValue()); if (key.displayName == null || (key.displayName != null && key.displayName.equals(""))) { key.displayName = id; } keys.put(id, key); } else { throw new ApiKeyStoreException("duplicate key ids!"); } } return keys; }
From source file:io.druid.indexing.common.task.CompactionTask.java
private static DimensionsSpec createDimensionsSpec(List<QueryableIndex> queryableIndices) { final BiMap<String, Integer> uniqueDims = HashBiMap.create(); final Map<String, DimensionSchema> dimensionSchemaMap = new HashMap<>(); // Here, we try to retain the order of dimensions as they were specified since the order of dimensions may be // optimized for performance. // Dimensions are extracted from the recent segments to olders because recent segments are likely to be queried more // frequently, and thus the performance should be optimized for recent ones rather than old ones. // timelineSegments are sorted in order of interval int index = 0; for (QueryableIndex queryableIndex : Lists.reverse(queryableIndices)) { final Map<String, DimensionHandler> dimensionHandlerMap = queryableIndex.getDimensionHandlers(); for (String dimension : queryableIndex.getAvailableDimensions()) { final Column column = Preconditions.checkNotNull(queryableIndex.getColumn(dimension), "Cannot find column for dimension[%s]", dimension); if (!uniqueDims.containsKey(dimension)) { final DimensionHandler dimensionHandler = Preconditions.checkNotNull( dimensionHandlerMap.get(dimension), "Cannot find dimensionHandler for dimension[%s]", dimension);//from w w w.j a v a 2 s . c o m uniqueDims.put(dimension, index++); dimensionSchemaMap.put(dimension, createDimensionSchema(column.getCapabilities().getType(), dimension, dimensionHandler.getMultivalueHandling())); } } } final BiMap<Integer, String> orderedDims = uniqueDims.inverse(); final List<DimensionSchema> dimensionSchemas = IntStream.range(0, orderedDims.size()).mapToObj(i -> { final String dimName = orderedDims.get(i); return Preconditions.checkNotNull(dimensionSchemaMap.get(dimName), "Cannot find dimension[%s] from dimensionSchemaMap", dimName); }).collect(Collectors.toList()); return new DimensionsSpec(dimensionSchemas, null, null); }
From source file:org.terasology.particles.updating.ParticleUpdaterImpl.java
@Override public void configureEmitter(final ParticleEmitterComponent emitter, final BiMap<Class<Component>, AffectorFunction> registeredAffectorFunctions, final BiMap<Class<Component>, GeneratorFunction> registeredGeneratorFunctions) { emitter.generatorFunctionMap.clear(); emitter.affectorFunctionMap.clear(); for (Component c : emitter.ownerEntity.iterateComponents()) { if (registeredGeneratorFunctions.containsKey(c.getClass())) { emitter.generatorFunctionMap.put(c, registeredGeneratorFunctions.get(c.getClass())); } else if (registeredAffectorFunctions.containsKey(c.getClass())) { emitter.affectorFunctionMap.put(c, registeredAffectorFunctions.get(c.getClass())); }/*w w w. java 2 s.co m*/ } }