List of usage examples for com.google.common.collect Maps newEnumMap
public static <K extends Enum<K>, V> EnumMap<K, V> newEnumMap(Map<K, ? extends V> map)
From source file:org.terasology.world.block.loader.BlockLoader.java
private Map<BlockPart, Vector4f> prepareColorOffsets(BlockDefinition blockDef) { Map<BlockPart, Vector4f> result = Maps.newEnumMap(BlockPart.class); for (BlockPart part : BlockPart.values()) { result.put(part, blockDef.colorOffset); }// w w w . j a v a 2s. com if (blockDef.colorOffsets != null) { for (BlockPart part : BlockPart.values()) { if (blockDef.colorOffsets.map.get(part) != null) { result.put(part, blockDef.colorOffsets.map.get(part)); } } } return result; }
From source file:com.google.cloud.storage.StorageImpl.java
@Override public URL signUrl(BlobInfo blobInfo, long duration, TimeUnit unit, SignUrlOption... options) { EnumMap<SignUrlOption.Option, Object> optionMap = Maps.newEnumMap(SignUrlOption.Option.class); for (SignUrlOption option : options) { optionMap.put(option.getOption(), option.getValue()); }/*from w w w . j a v a 2s . co m*/ ServiceAccountSigner credentials = (ServiceAccountSigner) optionMap .get(SignUrlOption.Option.SERVICE_ACCOUNT_CRED); if (credentials == null) { checkState(this.getOptions().getCredentials() instanceof ServiceAccountSigner, "Signing key was not provided and could not be derived"); credentials = (ServiceAccountSigner) this.getOptions().getCredentials(); } long expiration = TimeUnit.SECONDS.convert(getOptions().getClock().millisTime() + unit.toMillis(duration), TimeUnit.MILLISECONDS); StringBuilder stPath = new StringBuilder(); if (!blobInfo.getBucket().startsWith(PATH_DELIMITER)) { stPath.append(PATH_DELIMITER); } stPath.append(blobInfo.getBucket()); if (!blobInfo.getBucket().endsWith(PATH_DELIMITER)) { stPath.append(PATH_DELIMITER); } if (blobInfo.getName().startsWith(PATH_DELIMITER)) { stPath.setLength(stPath.length() - 1); } String escapedName = UrlEscapers.urlFragmentEscaper().escape(blobInfo.getName()); stPath.append(escapedName.replace("?", "%3F")); URI path = URI.create(stPath.toString()); try { SignatureInfo signatureInfo = buildSignatureInfo(optionMap, blobInfo, expiration, path); byte[] signatureBytes = credentials.sign(signatureInfo.constructUnsignedPayload().getBytes(UTF_8)); StringBuilder stBuilder = new StringBuilder("https://storage.googleapis.com").append(path); String signature = URLEncoder.encode(BaseEncoding.base64().encode(signatureBytes), UTF_8.name()); stBuilder.append("?GoogleAccessId=").append(credentials.getAccount()); stBuilder.append("&Expires=").append(expiration); stBuilder.append("&Signature=").append(signature); return new URL(stBuilder.toString()); } catch (MalformedURLException | UnsupportedEncodingException ex) { throw new IllegalStateException(ex); } }
From source file:com.android.tools.lint.checks.ResourceCycleDetector.java
private void findCycles(@NonNull Context context, @NonNull ResourceType type, @NonNull Multimap<String, String> map) { Set<String> visiting = Sets.newHashSetWithExpectedSize(map.size()); Set<String> seen = Sets.newHashSetWithExpectedSize(map.size()); for (String from : map.keySet()) { if (seen.contains(from)) { continue; }/*w w w . j ava 2 s.com*/ List<String> chain = dfs(map, from, visiting); if (chain != null && chain.size() > 2) { // size 1 chains are handled directly seen.addAll(chain); Collections.reverse(chain); if (mChains == null) { mChains = Maps.newEnumMap(ResourceType.class); mLocations = Maps.newEnumMap(ResourceType.class); context.getDriver().requestRepeat(this, Scope.RESOURCE_FILE_SCOPE); } List<List<String>> list = mChains.get(type); if (list == null) { list = Lists.newArrayList(); mChains.put(type, list); } list.add(chain); } } }
From source file:org.terasology.world.block.loader.BlockLoader.java
private Map<BlockPart, Block.ColorSource> prepareColorSources(BlockDefinition blockDef) { Map<BlockPart, Block.ColorSource> result = Maps.newEnumMap(BlockPart.class); for (BlockPart part : BlockPart.values()) { result.put(part, blockDef.colorSource); }/*from www . j a v a 2 s . co m*/ if (blockDef.colorSources != null) { for (BlockPart part : BlockPart.values()) { if (blockDef.colorSources.map.get(part) != null) { result.put(part, blockDef.colorSources.map.get(part)); } } } return result; }
From source file:com.google.gcloud.storage.StorageImpl.java
@Override public URL signUrl(BlobInfo blobInfo, long duration, TimeUnit unit, SignUrlOption... options) { EnumMap<SignUrlOption.Option, Object> optionMap = Maps.newEnumMap(SignUrlOption.Option.class); for (SignUrlOption option : options) { optionMap.put(option.option(), option.value()); }//from www . j a v a 2 s . com ServiceAccountAuthCredentials authCred = (ServiceAccountAuthCredentials) optionMap .get(SignUrlOption.Option.SERVICE_ACCOUNT_CRED); ServiceAccountCredentials cred = authCred != null ? authCred.credentials() : null; if (authCred == null) { checkArgument( this.options().authCredentials() != null && this.options().authCredentials().credentials() instanceof ServiceAccountCredentials, "Signing key was not provided and could not be derived"); cred = (ServiceAccountCredentials) this.options().authCredentials().credentials(); } // construct signature - see https://cloud.google.com/storage/docs/access-control#Signed-URLs StringBuilder stBuilder = new StringBuilder(); if (optionMap.containsKey(SignUrlOption.Option.HTTP_METHOD)) { stBuilder.append(optionMap.get(SignUrlOption.Option.HTTP_METHOD)); } else { stBuilder.append(HttpMethod.GET); } stBuilder.append('\n'); if (firstNonNull((Boolean) optionMap.get(SignUrlOption.Option.MD5), false)) { checkArgument(blobInfo.md5() != null, "Blob is missing a value for md5"); stBuilder.append(blobInfo.md5()); } stBuilder.append('\n'); if (firstNonNull((Boolean) optionMap.get(SignUrlOption.Option.CONTENT_TYPE), false)) { checkArgument(blobInfo.contentType() != null, "Blob is missing a value for content-type"); stBuilder.append(blobInfo.contentType()); } stBuilder.append('\n'); long expiration = TimeUnit.SECONDS.convert(options().clock().millis() + unit.toMillis(duration), TimeUnit.MILLISECONDS); stBuilder.append(expiration).append('\n'); StringBuilder path = new StringBuilder(); if (!blobInfo.bucket().startsWith("/")) { path.append('/'); } path.append(blobInfo.bucket()); if (!blobInfo.bucket().endsWith("/")) { path.append('/'); } if (blobInfo.name().startsWith("/")) { path.setLength(stBuilder.length() - 1); } path.append(blobInfo.name()); stBuilder.append(path); try { Signature signer = Signature.getInstance("SHA256withRSA"); signer.initSign(cred.getPrivateKey()); signer.update(stBuilder.toString().getBytes(UTF_8)); stBuilder = new StringBuilder("https://storage.googleapis.com").append(path); String signature = URLEncoder.encode(BaseEncoding.base64().encode(signer.sign()), UTF_8.name()); stBuilder.append("?GoogleAccessId=").append(cred.getClientEmail()); stBuilder.append("&Expires=").append(expiration); stBuilder.append("&Signature=").append(signature); return new URL(stBuilder.toString()); } catch (MalformedURLException | NoSuchAlgorithmException | UnsupportedEncodingException e) { throw new IllegalStateException(e); } catch (SignatureException | InvalidKeyException e) { throw new IllegalArgumentException("Invalid service account private key"); } }
From source file:org.terasology.world.block.loader.BlockLoader.java
private Map<BlockPart, AssetUri> prepareTiles(BlockDefinition blockDef, AssetUri uri) { AssetUri tileUri = getDefaultTile(blockDef, uri); Map<BlockPart, AssetUri> tileUris = Maps.newEnumMap(BlockPart.class); for (BlockPart part : BlockPart.values()) { tileUris.put(part, tileUri);/*w w w . j av a 2s . c o m*/ } if (blockDef.tiles != null) { for (BlockPart part : BlockPart.values()) { String partTile = blockDef.tiles.map.get(part); if (partTile != null) { tileUri = new AssetUri(AssetType.BLOCK_TILE, blockDef.tiles.map.get(part)); tileUris.put(part, tileUri); } } } return tileUris; }
From source file:com.google.gcloud.bigquery.BigQueryImpl.java
private Map<BigQueryRpc.Option, ?> optionMap(Option... options) { Map<BigQueryRpc.Option, Object> optionMap = Maps.newEnumMap(BigQueryRpc.Option.class); for (Option option : options) { Object prev = optionMap.put(option.rpcOption(), option.value()); checkArgument(prev == null, "Duplicate option %s", option); }// w w w .ja va2 s .co m return optionMap; }
From source file:com.google.cloud.bigquery.BigQueryImpl.java
@VisibleForTesting static Map<BigQueryRpc.Option, ?> optionMap(Option... options) { Map<BigQueryRpc.Option, Object> optionMap = Maps.newEnumMap(BigQueryRpc.Option.class); for (Option option : options) { Object prev = optionMap.put(option.getRpcOption(), option.getValue()); checkArgument(prev == null, "Duplicate option %s", option); }//from w w w. j a v a 2 s . c o m return optionMap; }
From source file:org.carrot2.workbench.core.ui.SearchEditor.java
/** * Create internal panels and hook up listener infrastructure. */// w w w . j a v a 2s. com private void createControls(SashForm parent) { /* * Create and add panels in order of their declaration in the enum type. */ this.panels = Maps.newEnumMap(PanelName.class); int index = 0; for (final PanelName s : EnumSet.allOf(PanelName.class)) { final Section section; switch (s) { case CLUSTERS: section = createClustersPart(parent, getSite()); break; case DOCUMENTS: section = createDocumentsPart(parent, getSite()); break; case ATTRIBUTES: section = createAttributesPart(parent, getSite()); break; default: throw new RuntimeException("Unknown section: " + s); } final PanelReference sr = new PanelReference(section, index++); panels.put(s, sr); } /* * Set up selection event forwarding. */ this.selectionProvider = new SearchEditorSelectionProvider(this); this.getSite().setSelectionProvider(selectionProvider); final ClusterTree tree = (ClusterTree) panels.get(PanelName.CLUSTERS).section.getClient(); /* Link bidirectional selection synchronization. */ new ClusterTreeSelectionAdapter(selectionProvider, tree); /* * Set up an event callback making editor dirty when attributes change. */ this.getSearchResult().getInput().addAttributeListener(new AttributeListenerAdapter() { public void valueChanged(AttributeEvent event) { setDirty(true); } }); /* * Set up an event callback to spawn auto-update jobs on changes to attributes. */ resources.registerAttributeChangeListener(this.getSearchResult().getInput(), autoUpdateListener); /* * Set up an event callback to restart processing after auto-update is enabled and * the editor is dirty. */ resources.registerPropertyChangeListener(WorkbenchCorePlugin.getDefault().getPreferenceStore(), autoUpdateListener2); /* * Install a synchronization agent between the current selection in the editor and * the document list panel. */ final DocumentList documentList = (DocumentList) panels.get(PanelName.DOCUMENTS).section.getClient(); new DocumentListSelectionAdapter(selectionProvider, documentList, this); /* * Restore state information. */ restoreState(); }
From source file:com.google.gcloud.storage.StorageImpl.java
private Map<StorageRpc.Option, ?> optionMap(Long generation, Long metaGeneration, Iterable<? extends Option> options, boolean useAsSource) { Map<StorageRpc.Option, Object> temp = Maps.newEnumMap(StorageRpc.Option.class); for (Option option : options) { Object prev = temp.put(option.rpcOption(), option.value()); checkArgument(prev == null, "Duplicate option %s", option); }/*from w w w . j a va2 s . c o m*/ Boolean value = (Boolean) temp.remove(DELIMITER); if (Boolean.TRUE.equals(value)) { temp.put(DELIMITER, options().pathDelimiter()); } if (useAsSource) { addToOptionMap(IF_GENERATION_MATCH, IF_SOURCE_GENERATION_MATCH, generation, temp); addToOptionMap(IF_GENERATION_NOT_MATCH, IF_SOURCE_GENERATION_NOT_MATCH, generation, temp); addToOptionMap(IF_METAGENERATION_MATCH, IF_SOURCE_METAGENERATION_MATCH, metaGeneration, temp); addToOptionMap(IF_METAGENERATION_NOT_MATCH, IF_SOURCE_METAGENERATION_NOT_MATCH, metaGeneration, temp); } else { addToOptionMap(IF_GENERATION_MATCH, generation, temp); addToOptionMap(IF_GENERATION_NOT_MATCH, generation, temp); addToOptionMap(IF_METAGENERATION_MATCH, metaGeneration, temp); addToOptionMap(IF_METAGENERATION_NOT_MATCH, metaGeneration, temp); } return ImmutableMap.copyOf(temp); }