List of usage examples for com.google.common.collect ImmutableMap containsKey
@Override public boolean containsKey(@Nullable Object key)
From source file:com.google.api.codegen.config.ResourceNameOneofConfig.java
@Nullable public static ResourceNameOneofConfig createResourceNameOneof(DiagCollector diagCollector, CollectionOneofProto collectionOneofProto, ImmutableMap<String, SingleResourceNameConfig> singleResourceNameConfigs, ImmutableMap<String, FixedResourceNameConfig> fixedResourceNameConfigs, ProtoFile file) { String oneofName = collectionOneofProto.getOneofName(); if (singleResourceNameConfigs.containsKey(oneofName)) { diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "oneof_name \"" + oneofName + "\" already exists in collection configs")); return null; }//from ww w . ja va 2s . c o m List<ResourceNameConfig> configList = new ArrayList<>(); boolean gotSingleResourceName = false; for (String entityName : collectionOneofProto.getCollectionNamesList()) { ResourceNameConfig resourceNameConfig = singleResourceNameConfigs.get(entityName); if (resourceNameConfig == null) { resourceNameConfig = fixedResourceNameConfigs.get(entityName); } else { gotSingleResourceName = true; } if (resourceNameConfig == null) { diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "entity_name \"" + entityName + "\" in collection oneof \"" + oneofName + "\" not found in collection configs")); return null; } configList.add(resourceNameConfig); } if (!gotSingleResourceName) { diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "At least one ResourceNameConfig with type SINGLE is required in oneof " + oneofName)); return null; } return new AutoValue_ResourceNameOneofConfig(oneofName, oneofName, configList, file); }
From source file:com.cognifide.aet.runner.conversion.SuiteMergeStrategy.java
private static void mergeStep(Step currentStep, Step patternStep) { updateComment(currentStep, patternStep); currentStep.updatePattern(patternStep.getPattern()); final ImmutableMap<String, Comparator> comparators = FluentIterable.from(currentStep.getComparators()) .uniqueIndex(COMPARATOR_TO_MAP); for (Comparator patternComparator : patternStep.getComparators()) { if (comparators.containsKey(patternComparator.getName())) { updateComment(comparators.get(patternComparator.getName()), patternComparator); }/*from w w w.jav a 2 s . co m*/ } }
From source file:com.cognifide.aet.runner.conversion.SuiteMergeStrategy.java
private static void mergeUrl(Url currentUrl, Url patternUrl) { updateComment(currentUrl, patternUrl); final ImmutableMap<String, Step> collectors = FluentIterable.from(currentUrl.getSteps()) .filter(COMPARATORS_FILTER).uniqueIndex(STEP_TO_MAP); for (Step patternStep : patternUrl.getSteps()) { if (isCollector(patternStep) && collectors.containsKey(patternStep.getName())) { mergeStep(collectors.get(patternStep.getName()), patternStep); }/*from w w w . ja v a 2 s .c o m*/ } }
From source file:com.spectralogic.ds3autogen.python.generators.type.BaseTypeGenerator.java
/** * Gets the type model name that describes the specified type, or 'None' if there * is no associated type model//w w w. j av a 2 s . c om */ protected static String getTypeModelName(final String type, final String componentType, final ImmutableMap<String, Ds3Type> typeMap) { if (isEmpty(typeMap)) { LOG.debug("Cannot find model type because TypeMap is empty"); return "None"; } if (hasContent(componentType) && typeMap.containsKey(componentType) && !isEnumType(componentType, typeMap)) { return getParserModelName(componentType); } else if (isEmpty(componentType) && typeMap.containsKey(type) && !isEnumType(type, typeMap)) { return getParserModelName(type); } return "None"; }
From source file:edu.buaa.satla.analysis.util.ImmutableMapMerger.java
/** * Join two maps taking the key into account, use {@code func} on duplicate values. * @param a input map//from w w w. jav a 2s .com * @param b input map * @param func function to merge two values from different maps. * @return map containing the union of keys in {@code a} and {@code b}, which * contains the value from {@code a} if it contains only in {@code a}, value * from {@code b} if it is contained only in {@code b} and {@code func} * applied on value from {@code a} and a value from {@code b} otherwise. */ public static <K, V> ImmutableMap<K, V> merge(ImmutableMap<K, V> a, ImmutableMap<K, V> b, MergeFunc<K, V> func) { Set<K> allKeys = new HashSet<>(); allKeys.addAll(a.keySet()); allKeys.addAll(b.keySet()); ImmutableMap.Builder<K, V> builder = ImmutableMap.builder(); for (K key : allKeys) { if (a.containsKey(key) && !b.containsKey(key)) { builder.put(key, a.get(key)); } else if (!a.containsKey(key) && b.containsKey(key)) { builder.put(key, b.get(key)); } else { builder.put(key, func.apply(key, a.get(key), b.get(key))); } } return builder.build(); }
From source file:org.apache.cassandra.hints.HintsDescriptor.java
/** * Create, if necessary, the required encryption components (for either decrpyt or encrypt operations). * Note that in the case of encyption (this is, when writing out a new hints file), we need to write * the cipher's IV out to the header so it can be used when decrypting. Thus, we need to add an additional * entry to the {@code params} map.//from w ww. java 2 s.c om * * @param params the base parameters into the descriptor. * @return null if not using encryption; else, the initialized {@link Cipher} and a possibly updated version * of the {@code params} map. */ @SuppressWarnings("unchecked") static EncryptionData createEncryption(ImmutableMap<String, Object> params) { if (params.containsKey(ENCRYPTION)) { Map<?, ?> encryptionConfig = (Map<?, ?>) params.get(ENCRYPTION); EncryptionContext encryptionContext = EncryptionContext.createFromMap(encryptionConfig, DatabaseDescriptor.getEncryptionContext()); try { Cipher cipher; if (encryptionConfig.containsKey(EncryptionContext.ENCRYPTION_IV)) { cipher = encryptionContext.getDecryptor(); } else { cipher = encryptionContext.getEncryptor(); ImmutableMap<String, Object> encParams = ImmutableMap.<String, Object>builder() .putAll(encryptionContext.toHeaderParameters()) .put(EncryptionContext.ENCRYPTION_IV, Hex.bytesToHex(cipher.getIV())).build(); Map<String, Object> map = new HashMap<>(params); map.put(ENCRYPTION, encParams); params = ImmutableMap.<String, Object>builder().putAll(map).build(); } return new EncryptionData(cipher, encryptionContext.getCompressor(), params); } catch (IOException ioe) { logger.warn("failed to create encyption context for hints file. ignoring encryption for hints.", ioe); return null; } } else { return null; } }
From source file:com.cognifide.aet.runner.conversion.SuiteMergeStrategy.java
/** * Merges current and pattern suite. All comments, version and patterns in current suite are overwritten from pattern suite. * * @param current - current run suite.//from w w w . j a va2 s . com * @param pattern - pattern suite, usually the last run. * @return merged suite. */ public static Suite merge(Suite current, Suite pattern) { final ImmutableMap<String, Test> tests = FluentIterable.from(current.getTests()).uniqueIndex(TEST_TO_MAP); if (pattern != null) { current.setVersion(pattern.getVersion() + 1); updateComment(current, pattern); for (Test patternTest : pattern.getTests()) { if (tests.containsKey(patternTest.getName())) { mergeTest(tests.get(patternTest.getName()), patternTest); } } } else { current.setVersion(1L); } return current; }
From source file:com.bigfatgun.fixjures.Strategies.java
/** * This source strategy does a simple lookup of type and name in a map that stores fixture data in raw byte arrays. A * defensive copy is made of the map argument, so only the fixtures in the map at the time this method is invoked can * be created.//from ww w .ja v a 2 s . c o m * * @param mem map that holds fixture data in memory * @return new source strategy */ public static SourceStrategy newInMemoryStrategy(final Map<? extends Class<?>, Map<String, String>> mem) { final ImmutableMap<Class<?>, Map<String, String>> copy = ImmutableMap.copyOf(mem); return new SourceStrategy() { public ReadableByteChannel findStream(final Class<?> type, final String name) throws IOException { assert type != null : "Type cannot be null."; assert name != null : "Name cannot be null."; if (!copy.containsKey(type)) { throw new IOException("Data for " + type + " not found."); } else if (!copy.get(type).containsKey(name)) { throw new IOException("Data for " + type.getName() + " named " + name + " not found."); } else { final byte[] bytes = copy.get(type).get(name).getBytes(Charsets.UTF_8); return Channels.newChannel(new ByteArrayInputStream(bytes)); } } }; }
From source file:mod.steamnsteel.structure.StructureDefinitionBuilder.java
private static void assignX(ImmutableMap<Character, ?> map, String[][] layers, TripleIterator itr, Object[][][] res) {/*from ww w. j a v a 2 s . c o m*/ while (itr.hasNext()) { final TripleCoord local = itr.next(); final char c = layers[local.y][local.z].charAt(local.x); if (!map.containsKey(c) && c != ' ') { throw new StructureDefinitionError("assignX.Map missing '" + c + "' @" + local); } res[local.x][local.y][local.z] = map.get(c); } }
From source file:ru.codeinside.gses.webui.executor.ArchiveFactory.java
static Component createForm(final Bid bid, ActivityImpl activity, ProcessEngine engine, ActivitiApp app, final Date toDate) { CommandExecutor commandExecutor = ((ServiceImpl) engine.getRuntimeService()).getCommandExecutor(); Map<String, String> historyValues = commandExecutor.execute(new Command<Map<String, String>>() { @Override// w ww . j ava 2 s.c om public Map<String, String> execute(CommandContext commandContext) { return getHistoryValues(bid, toDate); } }); FormValue formValue; String processDefinitionId = bid.getProcedureProcessDefinition().getProcessDefinitionId(); FormID formID = FormID.byProcessDefinitionId(processDefinitionId); if (isPropertyType(activity, "startEvent")) { formValue = commandExecutor.execute(new GetStartArchiveFormCmd(processDefinitionId, historyValues)); } else if (isPropertyType(activity, "userTask") && activity.getActivityBehavior() instanceof UserTaskActivityBehavior) { CustomTaskFormHandler taskFormHandler = (CustomTaskFormHandler) ((UserTaskActivityBehavior) activity .getActivityBehavior()).getTaskDefinition().getTaskFormHandler(); formValue = commandExecutor .execute(new GetTaskArchiveFormCmd(processDefinitionId, taskFormHandler, historyValues)); } else { formValue = null; } if (formValue == null) { return null; } if (StringUtils.isNotEmpty(formValue.getFormDefinition().getFormKey())) { return new EFormBuilder(formValue, formID).getForm(null, null); } ImmutableMap<String, PropertyNode> propertyNodes = formValue.getFormDefinition().getIndex(); if (propertyNodes.containsKey(API.JSON_FORM)) { String templateRef = null; String value = null; for (PropertyValue<?> propertyValue : formValue.getPropertyValues()) { if (propertyValue.getId().equals(API.JSON_FORM)) { templateRef = (String) propertyValue.getValue(); } else { if (propertyValue.getValue() instanceof byte[]) { try { value = new String((byte[]) propertyValue.getValue(), "UTF-8"); } catch (UnsupportedEncodingException e) { Logger.getAnonymousLogger().info("can't decode model!"); } } else { value = String.valueOf(propertyValue.getValue()); } } } if (value != null) { return JsonForm.createIntegration(formID, app, templateRef, value, true); } } FieldTree fieldTree = new FieldTree(formID); fieldTree.create(formValue); GridForm form = new GridForm(formID, fieldTree); form.setImmediate(true); return form; }