List of usage examples for com.google.common.collect ImmutableMap get
V get(Object key);
From source file:com.facebook.buck.apple.AbstractProvisioningProfileMetadata.java
public ImmutableMap<String, NSObject> getMergeableEntitlements() { final ImmutableSet<String> excludedKeys = ImmutableSet.of( "com.apple.developer.icloud-container-development-container-identifiers", "com.apple.developer.icloud-container-environment", "com.apple.developer.icloud-container-identifiers", "com.apple.developer.icloud-services", "com.apple.developer.restricted-resource-mode", "com.apple.developer.ubiquity-container-identifiers", "com.apple.developer.ubiquity-kvstore-identifier", "inter-app-audio", "com.apple.developer.homekit", "com.apple.developer.healthkit", "com.apple.developer.in-app-payments", "com.apple.developer.maps", "com.apple.external-accessory.wireless-configuration"); ImmutableMap<String, NSObject> allEntitlements = getEntitlements(); ImmutableMap.Builder<String, NSObject> filteredEntitlementsBuilder = ImmutableMap.builder(); for (String key : allEntitlements.keySet()) { if (!excludedKeys.contains(key)) { filteredEntitlementsBuilder.put(key, allEntitlements.get(key)); }//from www .j a va 2 s . c o m } return filteredEntitlementsBuilder.build(); }
From source file:com.foudroyantfactotum.tool.structure.utility.StructureDefinitionBuilder.java
/** * Define what each character represents within the block map * @param representation char to unlocal.getZ()ed block name map * @exception NullPointerException thrown if block doesn't exist. *//*from w ww. ja va 2 s .c o m*/ public void assignConstructionDef(ImmutableMap<Character, String> representation) { Builder<Character, IBlockState> builder = ImmutableMap.builder(); for (final Character c : representation.keySet()) { final String blockName = representation.get(c); final Block block = Block.getBlockFromName(blockName); checkNotNull(block, "assignConstructionDef.Block does not exist " + blockName); builder.put(c, block.getDefaultState()); } //default builder.put(' ', Blocks.AIR.getDefaultState()); conDef = builder.build(); }
From source file:org.flockdata.search.service.ContentService.java
public ContentStructure getStructure(QueryParams queryParams) throws FlockException { try {//from w w w . j a v a 2 s . c om String[] indexes = indexManager.getIndexesToQuery(queryParams); GetFieldMappingsRequestBuilder fieldMappings = elasticSearchClient.admin().indices() .prepareGetFieldMappings(indexes); fieldMappings.setFields("data.*", "tag.*", "e.*", "up.*", SearchSchema.PROPS, SearchSchema.CREATED, SearchSchema.UPDATED, SearchSchema.DOC_TYPE); ListenableActionFuture<GetFieldMappingsResponse> future = fieldMappings.execute(); GetFieldMappingsResponse result = future.get(); ImmutableMap<String, ImmutableMap<String, ImmutableMap<String, GetFieldMappingsResponse.FieldMappingMetaData>>> mappings = result .mappings(); for (String index : mappings.keySet()) { ImmutableMap<String, ImmutableMap<String, GetFieldMappingsResponse.FieldMappingMetaData>> stringImmutableMapImmutableMap = mappings .get(index); for (String type : stringImmutableMapImmutableMap.keySet()) { ContentStructure contentStructure = new ContentStructure(index, type); ImmutableMap<String, GetFieldMappingsResponse.FieldMappingMetaData> fields = stringImmutableMapImmutableMap .get(type); for (String field : fields.keySet()) { handle(contentStructure, fields.get(field)); } return contentStructure; } } // logger.info(result.toString()); return null; } catch (FlockException e) { logger.error(e.getMessage()); throw (e); } catch (InterruptedException | ExecutionException e) { logger.error(e.getMessage()); throw new FlockException(e.getMessage()); } }
From source file:com.facebook.buck.versions.AbstractVersionedTargetGraphBuilder.java
protected final TargetNode<?> resolveVersions(TargetNode<?> node, ImmutableMap<BuildTarget, Version> selectedVersions) { Optional<TargetNode<VersionedAliasDescriptionArg>> versionedNode = TargetNodes.castArg(node, VersionedAliasDescriptionArg.class); if (versionedNode.isPresent()) { node = getNode(Preconditions.checkNotNull(versionedNode.get().getConstructorArg().getVersions() .get(selectedVersions.get(node.getBuildTarget())))); }//ww w .j ava 2 s .com return node; }
From source file:com.facebook.buck.cxx.AbstractElfRewriteDynStrSectionStep.java
/** @return a processor for the dynamic symbol table section. */ private SectionUsingDynamicStrings getDynSymProcessor(Elf elf) throws IOException { return new SectionUsingDynamicStrings() { private final ElfSection dynSymSection = elf.getMandatorySectionByName(getPath(), DYNSYM).getSection(); private final ElfSymbolTable dynSym = ElfSymbolTable.parse(elf.header.ei_class, dynSymSection.body); @Override//from w ww .j a v a2s.co m public ImmutableList<Long> getStringReferences() { return RichStream.from(dynSym.entries).map(e -> e.st_name).toImmutableList(); } @Override public void processNewStringReferences(long newSize, ImmutableMap<Long, Long> newStringIndices) { // Rewrite the dynamic symbol table. ElfSymbolTable newSymbolTable = new ElfSymbolTable(RichStream.from(dynSym.entries) .map(e -> new ElfSymbolTable.Entry(Objects.requireNonNull(newStringIndices.get(e.st_name)), e.st_info, e.st_other, e.st_shndx, e.st_value, e.st_size)) .toImmutableList()); dynSymSection.body.rewind(); newSymbolTable.write(elf.header.ei_class, dynSymSection.body); } }; }
From source file:org.apache.phoenix.log.TableLogWriter.java
@Override public void write(RingBufferEvent event) throws SQLException, IOException, ClassNotFoundException { if (isClosed()) { LOG.warn("Unable to commit query log as Log committer is already closed"); return;//from ww w. ja v a2 s . c o m } if (connection == null) { synchronized (this) { if (connection == null) { connection = QueryUtil.getConnectionForQueryLog(this.config); this.upsertStatement = buildUpsertStatement(connection); } } } ImmutableMap<QueryLogInfo, Object> queryInfoMap = event.getQueryInfo(); for (QueryLogInfo info : QueryLogInfo.values()) { if (queryInfoMap.containsKey(info) && info.logLevel.ordinal() <= event.getConnectionLogLevel().ordinal()) { upsertStatement.setObject(info.ordinal() + 1, queryInfoMap.get(info)); } else { upsertStatement.setObject(info.ordinal() + 1, null); } } Map<MetricType, Long> overAllMetrics = event.getOverAllMetrics(); Map<String, Map<MetricType, Long>> readMetrics = event.getReadMetrics(); for (MetricType metric : MetricType.values()) { if (overAllMetrics != null && overAllMetrics.containsKey(metric) && metric.isLoggingEnabled(event.getConnectionLogLevel())) { upsertStatement.setObject(metricOrdinals.get(metric), overAllMetrics.get(metric)); } else { if (metric.logLevel() != LogLevel.OFF) { upsertStatement.setObject(metricOrdinals.get(metric), null); } } } if (readMetrics != null && !readMetrics.isEmpty()) { for (Map.Entry<String, Map<MetricType, Long>> entry : readMetrics.entrySet()) { upsertStatement.setObject(QueryLogInfo.TABLE_NAME_I.ordinal() + 1, entry.getKey()); for (MetricType metric : entry.getValue().keySet()) { if (metric.isLoggingEnabled(event.getConnectionLogLevel())) { upsertStatement.setObject(metricOrdinals.get(metric), entry.getValue().get(metric)); } } upsertStatement.executeUpdate(); } } else { upsertStatement.executeUpdate(); } connection.commit(); }
From source file:org.ambraproject.wombat.service.remote.UserApiImpl.java
/** * This method fetches the NED user credentials. * * <ul>//ww w . j a v a 2 s .c om * <li>NED Server URL</li> * <li>User name</li> * <li>Password</li> * </ul> * * @return The {@link UserApiConfiguration} */ private UserApiConfiguration fetchApiConfiguration() { final Optional<RuntimeConfiguration.UserApiConfiguration> userApiConfig = runtimeConfiguration .getUserApiConfiguration(); final ImmutableMap<String, String> userConfigData = userApiConfig .map(config -> ImmutableMap.of("server", config.getServerUrl(), "authorizationAppName", config.getAppName(), "authorizationPassword", config.getPassword())) .orElseThrow(() -> new RuntimeException("userApi is not configured")); final String server = userConfigData.get("server"); if (server == null) { throw new RuntimeException("userApi is not configured"); } return new UserApiConfiguration(server, userConfigData.get("authorizationAppName"), userConfigData.get("authorizationPassword")); }
From source file:com.facebook.buck.rules.modern.impl.DefaultClassInfo.java
DefaultClassInfo(Class<?> clazz, Optional<ClassInfo<? super T>> superInfo) { this.type = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, clazz.getSimpleName()).intern(); this.superInfo = superInfo; Optional<Class<?>> immutableBase = findImmutableBase(clazz); ImmutableList.Builder<FieldInfo<?>> fieldsBuilder = ImmutableList.builder(); if (immutableBase.isPresent()) { ImmutableMap<Field, Boolean> parameterFields = parameterFieldsFromFields(clazz); ImmutableMap<Field, Method> parameterMethods = findMethodsForFields(parameterFields.keySet(), clazz); parameterFields.forEach((field, isLazy) -> { Method method = parameterMethods.get(field); if (method == null) { return; }/*from ww w . ja v a 2 s. c o m*/ AddToRuleKey addAnnotation = method.getAnnotation(AddToRuleKey.class); // TODO(cjhopman): Add @ExcludeFromRuleKey annotation and require that all fields are // either explicitly added or explicitly excluded. Optional<CustomFieldBehavior> customBehavior = Optional .ofNullable(method.getDeclaredAnnotation(CustomFieldBehavior.class)); if (addAnnotation != null && !addAnnotation.stringify()) { if (isLazy) { throw new RuntimeException( "@Value.Lazy fields cannot be @AddToRuleKey, change it to @Value.Derived."); } Nullable methodNullable = method.getAnnotation(Nullable.class); boolean methodOptional = Optional.class.isAssignableFrom(method.getReturnType()); fieldsBuilder.add( forFieldWithBehavior(field, methodNullable != null || methodOptional, customBehavior)); } else { fieldsBuilder.add(excludedField(field, customBehavior)); } }); } else { for (final Field field : clazz.getDeclaredFields()) { // TODO(cjhopman): Make this a Precondition. if (!Modifier.isFinal(field.getModifiers())) { LOG.warn("All fields of a Buildable must be final (%s.%s)", clazz.getSimpleName(), field.getName()); } if (Modifier.isStatic(field.getModifiers())) { continue; } field.setAccessible(true); Optional<CustomFieldBehavior> customBehavior = Optional .ofNullable(field.getDeclaredAnnotation(CustomFieldBehavior.class)); AddToRuleKey addAnnotation = field.getAnnotation(AddToRuleKey.class); // TODO(cjhopman): Add @ExcludeFromRuleKey annotation and require that all fields are either // explicitly added or explicitly excluded. if (addAnnotation != null && !addAnnotation.stringify()) { fieldsBuilder.add(forFieldWithBehavior(field, field.getAnnotation(Nullable.class) != null, customBehavior)); } else { fieldsBuilder.add(excludedField(field, customBehavior)); } } } if (clazz.isMemberClass()) { // TODO(cjhopman): This should also iterate over the outer class's class hierarchy. Class<?> outerClazz = clazz.getDeclaringClass(); // I don't think this can happen, but if it does, this needs to be updated to handle it // correctly. Preconditions.checkArgument( !outerClazz.isAnonymousClass() && !outerClazz.isMemberClass() && !outerClazz.isLocalClass()); for (final Field field : outerClazz.getDeclaredFields()) { field.setAccessible(true); if (!Modifier.isStatic(field.getModifiers())) { continue; } // TODO(cjhopman): Make this a Precondition. if (!Modifier.isFinal(field.getModifiers())) { LOG.warn("All static fields of a Buildable's outer class must be final (%s.%s)", outerClazz.getSimpleName(), field.getName()); } } } this.fields = fieldsBuilder.build(); }
From source file:com.opengamma.strata.pricer.calibration.CurveCalibrator.java
private static DoubleMatrix jacobianIndirect(DoubleMatrix res, DoubleMatrix pDmCurrentMatrix, int nbTrades, int totalParamsGroup, int totalParamsPrevious, ImmutableList<CurveParameterSize> orderPrevious, ImmutableMap<CurveName, JacobianCalibrationMatrix> jacobiansPrevious) { if (totalParamsPrevious == 0) { return DoubleMatrix.EMPTY; }/*from www. j a v a 2s .c o m*/ double[][] nonDirect = new double[totalParamsGroup][totalParamsPrevious]; for (int i = 0; i < nbTrades; i++) { System.arraycopy(res.rowArray(i), 0, nonDirect[i], 0, totalParamsPrevious); } DoubleMatrix pDpPreviousMatrix = (DoubleMatrix) MATRIX_ALGEBRA .scale(MATRIX_ALGEBRA.multiply(pDmCurrentMatrix, DoubleMatrix.copyOf(nonDirect)), -1d); // all curves: order and size int[] startIndexBefore = new int[orderPrevious.size()]; for (int i = 1; i < orderPrevious.size(); i++) { startIndexBefore[i] = startIndexBefore[i - 1] + orderPrevious.get(i - 1).getParameterCount(); } // transition Matrix: all curves from previous groups double[][] transition = new double[totalParamsPrevious][totalParamsPrevious]; for (int i = 0; i < orderPrevious.size(); i++) { int paramCountOuter = orderPrevious.get(i).getParameterCount(); JacobianCalibrationMatrix thisInfo = jacobiansPrevious.get(orderPrevious.get(i).getName()); DoubleMatrix thisMatrix = thisInfo.getJacobianMatrix(); int startIndexInner = 0; for (int j = 0; j < orderPrevious.size(); j++) { int paramCountInner = orderPrevious.get(j).getParameterCount(); if (thisInfo.containsCurve(orderPrevious.get(j).getName())) { // If not, the matrix stay with 0 for (int k = 0; k < paramCountOuter; k++) { System.arraycopy(thisMatrix.rowArray(k), startIndexInner, transition[startIndexBefore[i] + k], startIndexBefore[j], paramCountInner); } } startIndexInner += paramCountInner; } } DoubleMatrix transitionMatrix = DoubleMatrix.copyOf(transition); return (DoubleMatrix) MATRIX_ALGEBRA.multiply(pDpPreviousMatrix, transitionMatrix); }
From source file:se.sics.caracaldb.global.DefaultPolicy.java
private void switchSizeBalance(LUTWorkingBuffer lut, Address topAddr, Address bottomAddr, ImmutableMap<Address, Stats.Report> stats) { Stats.Report topRep = stats.get(topAddr); Stats.Report bottomRep = stats.get(bottomAddr); Map<Address, Integer> ids = lut.lut.getIdsForAddresses(ImmutableSet.of(topAddr, bottomAddr)); for (Key k : topRep.topKSize) { Integer repGroupId = lut.getRepGroup(k); if (repGroupId == null) { continue; }//from ww w .j a v a 2 s . c o m Integer[] repGroup = lut.getRepSet(repGroupId); int topPos = LookupTable.positionInSet(repGroup, ids.get(topAddr)); int bottomPos = LookupTable.positionInSet(repGroup, ids.get(bottomAddr)); if (bottomPos < 0) { // new address is not already part of the replication group Integer[] newRepGroup = Arrays.copyOf(repGroup, repGroup.length); newRepGroup[topPos] = ids.get(bottomAddr); lut.findGroupOrAddNew(k, newRepGroup); return; } } // if all of the topKSize vNodes already share a group with the bottomAddr there's nothing we can do }