本文整理汇总了Java中com.google.common.collect.Maps.newEnumMap方法的典型用法代码示例。如果您正苦于以下问题:Java Maps.newEnumMap方法的具体用法?Java Maps.newEnumMap怎么用?Java Maps.newEnumMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.Maps
的用法示例。
在下文中一共展示了Maps.newEnumMap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createQrcodeMatrix
import com.google.common.collect.Maps; //导入方法依赖的package包/类
/**
* 根据内容生成二维码数据
*
* @param content 二维码文字内容[为了信息安全性,一般都要先进行数据加密]
* @param length 二维码图片宽度和高度
*/
private static BitMatrix createQrcodeMatrix(String content, int length) {
Map<EncodeHintType, Object> hints = Maps.newEnumMap(EncodeHintType.class);
// 设置字符编码
hints.put(EncodeHintType.CHARACTER_SET, Charsets.UTF_8.name());
// 指定纠错等级
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
try {
return new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, length, length, hints);
} catch (Exception e) {
logger.warn("内容为:【" + content + "】的二维码生成失败!", e);
return null;
}
}
示例2: createNodes
import com.google.common.collect.Maps; //导入方法依赖的package包/类
/**
* For a given Enum type, creates an immutable map from each of the Enum's values to a
* corresponding LockGraphNode, with the {@code allowedPriorLocks} and
* {@code disallowedPriorLocks} prepopulated with nodes according to the natural ordering of the
* associated Enum values.
*/
@VisibleForTesting
static <E extends Enum<E>> Map<E, LockGraphNode> createNodes(Class<E> clazz) {
EnumMap<E, LockGraphNode> map = Maps.newEnumMap(clazz);
E[] keys = clazz.getEnumConstants();
final int numKeys = keys.length;
ArrayList<LockGraphNode> nodes = Lists.newArrayListWithCapacity(numKeys);
// Create a LockGraphNode for each enum value.
for (E key : keys) {
LockGraphNode node = new LockGraphNode(getLockName(key));
nodes.add(node);
map.put(key, node);
}
// Pre-populate all allowedPriorLocks with nodes of smaller ordinal.
for (int i = 1; i < numKeys; i++) {
nodes.get(i).checkAcquiredLocks(Policies.THROW, nodes.subList(0, i));
}
// Pre-populate all disallowedPriorLocks with nodes of larger ordinal.
for (int i = 0; i < numKeys - 1; i++) {
nodes.get(i).checkAcquiredLocks(Policies.DISABLED, nodes.subList(i + 1, numKeys));
}
return Collections.unmodifiableMap(map);
}
示例3: ShardedDOMDataBrokerDelegatingReadWriteTransaction
import com.google.common.collect.Maps; //导入方法依赖的package包/类
public ShardedDOMDataBrokerDelegatingReadWriteTransaction(final Object readWriteTxId, final SchemaContext ctx,
final DOMDataReadOnlyTransaction readTxDelegate,
final DOMDataWriteTransaction writeTxDelegate) {
this.readTxDelegate = checkNotNull(readTxDelegate);
this.writeTxDelegate = checkNotNull(writeTxDelegate);
this.txIdentifier = checkNotNull(readWriteTxId);
this.initialReadMap = Maps.newEnumMap(LogicalDatastoreType.class);
final InMemoryDataTreeFactory treeFactory = InMemoryDataTreeFactory.getInstance();
final ImmutableMap.Builder<LogicalDatastoreType, DataTreeSnapshot> snapshotMapBuilder = ImmutableMap.builder();
final ImmutableMap.Builder<LogicalDatastoreType, Queue<Modification>> modificationHistoryMapBuilder =
ImmutableMap.builder();
for (final LogicalDatastoreType store : LogicalDatastoreType.values()) {
final DataTree tree = treeFactory.create(treeTypeForStore(store));
tree.setSchemaContext(ctx);
snapshotMapBuilder.put(store, tree.takeSnapshot());
modificationHistoryMapBuilder.put(store, Lists.newLinkedList());
}
modificationHistoryMap = modificationHistoryMapBuilder.build();
snapshotMap = snapshotMapBuilder.build();
}
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:24,代码来源:ShardedDOMDataBrokerDelegatingReadWriteTransaction.java
示例4: getConfiguredResources
import com.google.common.collect.Maps; //导入方法依赖的package包/类
/**
* Returns the resources values matching a given {@link FolderConfiguration}.
*
* @param referenceConfig the configuration that each value must match.
* @return a map with guaranteed to contain an entry for each {@link ResourceType}
*/
@NonNull
public Map<ResourceType, Map<String, ResourceValue>> getConfiguredResources(
@NonNull FolderConfiguration referenceConfig) {
Map<ResourceType, Map<String, ResourceValue>> map = Maps.newEnumMap(ResourceType.class);
synchronized (ITEM_MAP_LOCK) {
Map<ResourceType, ListMultimap<String, ResourceItem>> itemMap = getMap();
for (ResourceType key : ResourceType.values()) {
// get the local results and put them in the map
map.put(key, getConfiguredResources(itemMap, key, referenceConfig));
}
}
return map;
}
示例5: newChannel
import com.google.common.collect.Maps; //导入方法依赖的package包/类
/**
* INTERNAL Create a new channel pair with the specified name and channel handlers.
* This is used internally in forge and FML
*
* @param container The container to associate the channel with
* @param name The name for the channel
* @param handlers Some {@link ChannelHandler} for the channel
* @return an {@link EnumMap} of the pair of channels. keys are {@link Side}. There will always be two entries.
*/
public EnumMap<Side,FMLEmbeddedChannel> newChannel(ModContainer container, String name, ChannelHandler... handlers)
{
if (channels.get(Side.CLIENT).containsKey(name) || channels.get(Side.SERVER).containsKey(name) || name.startsWith("MC|") || name.startsWith("\u0001") || (name.startsWith("FML") && !("FML".equals(container.getModId()))))
{
throw new RuntimeException("That channel is already registered");
}
EnumMap<Side,FMLEmbeddedChannel> result = Maps.newEnumMap(Side.class);
for (Side side : Side.values())
{
FMLEmbeddedChannel channel = new FMLEmbeddedChannel(container, name, side, handlers);
channels.get(side).put(name,channel);
result.put(side, channel);
}
return result;
}
示例6: decodeQrcode
import com.google.common.collect.Maps; //导入方法依赖的package包/类
/**
* 解析二维码
*
* @param file 二维码文件内容
* @return 二维码的内容
*/
public static String decodeQrcode(File file) throws IOException, NotFoundException {
BufferedImage image = ImageIO.read(file);
LuminanceSource source = new BufferedImageLuminanceSource(image);
Binarizer binarizer = new HybridBinarizer(source);
BinaryBitmap binaryBitmap = new BinaryBitmap(binarizer);
Map<DecodeHintType, Object> hints = Maps.newEnumMap(DecodeHintType.class);
hints.put(DecodeHintType.CHARACTER_SET, Charsets.UTF_8.name());
return new MultiFormatReader().decode(binaryBitmap, hints).getText();
}
示例7: EventSinkHubEvent
import com.google.common.collect.Maps; //导入方法依赖的package包/类
public EventSinkHubEvent(ServiceInfoConfiguration serviceInfo, SessionId sessionId, String eventType, Map<EventDetailsKey, String> details) {
this.eventId = UUID.randomUUID();
this.originatingService = serviceInfo.getName();
this.sessionId = sessionId.getSessionId();
this.eventType = eventType;
this.details = Maps.newEnumMap(details);
}
示例8: parseFaces
import com.google.common.collect.Maps; //导入方法依赖的package包/类
private Map<EnumFacing, BlockPartFace> parseFaces(JsonDeserializationContext p_178253_1_, JsonObject p_178253_2_)
{
Map<EnumFacing, BlockPartFace> map = Maps.newEnumMap(EnumFacing.class);
JsonObject jsonobject = JsonUtils.getJsonObject(p_178253_2_, "faces");
for (Entry<String, JsonElement> entry : jsonobject.entrySet())
{
EnumFacing enumfacing = this.parseEnumFacing((String)entry.getKey());
map.put(enumfacing, (BlockPartFace)p_178253_1_.deserialize((JsonElement)entry.getValue(), BlockPartFace.class));
}
return map;
}
示例9: filterAclEntriesByAclSpec
import com.google.common.collect.Maps; //导入方法依赖的package包/类
/**
* Filters (discards) any existing ACL entries that have the same scope, type
* and name of any entry in the ACL spec. If necessary, recalculates the mask
* entries. If necessary, default entries may be inferred by copying the
* permissions of the corresponding access entries. It is invalid to request
* removal of the mask entry from an ACL that would otherwise require a mask
* entry, due to existing named entries or an unnamed group entry.
*
* @param existingAcl List<AclEntry> existing ACL
* @param inAclSpec List<AclEntry> ACL spec describing entries to filter
* @return List<AclEntry> new ACL
* @throws AclException if validation fails
*/
public static List<AclEntry> filterAclEntriesByAclSpec(
List<AclEntry> existingAcl, List<AclEntry> inAclSpec) throws AclException {
ValidatedAclSpec aclSpec = new ValidatedAclSpec(inAclSpec);
ArrayList<AclEntry> aclBuilder = Lists.newArrayListWithCapacity(MAX_ENTRIES);
EnumMap<AclEntryScope, AclEntry> providedMask =
Maps.newEnumMap(AclEntryScope.class);
EnumSet<AclEntryScope> maskDirty = EnumSet.noneOf(AclEntryScope.class);
EnumSet<AclEntryScope> scopeDirty = EnumSet.noneOf(AclEntryScope.class);
for (AclEntry existingEntry: existingAcl) {
if (aclSpec.containsKey(existingEntry)) {
scopeDirty.add(existingEntry.getScope());
if (existingEntry.getType() == MASK) {
maskDirty.add(existingEntry.getScope());
}
} else {
if (existingEntry.getType() == MASK) {
providedMask.put(existingEntry.getScope(), existingEntry);
} else {
aclBuilder.add(existingEntry);
}
}
}
copyDefaultsIfNeeded(aclBuilder);
calculateMasks(aclBuilder, providedMask, maskDirty, scopeDirty);
return buildAndValidateAcl(aclBuilder);
}
示例10: replaceAclEntries
import com.google.common.collect.Maps; //导入方法依赖的package包/类
/**
* Completely replaces the ACL with the entries of the ACL spec. If
* necessary, recalculates the mask entries. If necessary, default entries
* are inferred by copying the permissions of the corresponding access
* entries. Replacement occurs separately for each of the access ACL and the
* default ACL. If the ACL spec contains only access entries, then the
* existing default entries are retained. If the ACL spec contains only
* default entries, then the existing access entries are retained. If the ACL
* spec contains both access and default entries, then both are replaced.
*
* @param existingAcl List<AclEntry> existing ACL
* @param inAclSpec List<AclEntry> ACL spec containing replacement entries
* @return List<AclEntry> new ACL
* @throws AclException if validation fails
*/
public static List<AclEntry> replaceAclEntries(List<AclEntry> existingAcl,
List<AclEntry> inAclSpec) throws AclException {
ValidatedAclSpec aclSpec = new ValidatedAclSpec(inAclSpec);
ArrayList<AclEntry> aclBuilder = Lists.newArrayListWithCapacity(MAX_ENTRIES);
// Replacement is done separately for each scope: access and default.
EnumMap<AclEntryScope, AclEntry> providedMask =
Maps.newEnumMap(AclEntryScope.class);
EnumSet<AclEntryScope> maskDirty = EnumSet.noneOf(AclEntryScope.class);
EnumSet<AclEntryScope> scopeDirty = EnumSet.noneOf(AclEntryScope.class);
for (AclEntry aclSpecEntry: aclSpec) {
scopeDirty.add(aclSpecEntry.getScope());
if (aclSpecEntry.getType() == MASK) {
providedMask.put(aclSpecEntry.getScope(), aclSpecEntry);
maskDirty.add(aclSpecEntry.getScope());
} else {
aclBuilder.add(aclSpecEntry);
}
}
// Copy existing entries if the scope was not replaced.
for (AclEntry existingEntry: existingAcl) {
if (!scopeDirty.contains(existingEntry.getScope())) {
if (existingEntry.getType() == MASK) {
providedMask.put(existingEntry.getScope(), existingEntry);
} else {
aclBuilder.add(existingEntry);
}
}
}
copyDefaultsIfNeeded(aclBuilder);
calculateMasks(aclBuilder, providedMask, maskDirty, scopeDirty);
return buildAndValidateAcl(aclBuilder);
}
示例11: parseFaces
import com.google.common.collect.Maps; //导入方法依赖的package包/类
private Map<EnumFacing, BlockPartFace> parseFaces(JsonDeserializationContext deserializationContext, JsonObject object)
{
Map<EnumFacing, BlockPartFace> map = Maps.newEnumMap(EnumFacing.class);
JsonObject jsonobject = JsonUtils.getJsonObject(object, "faces");
for (Entry<String, JsonElement> entry : jsonobject.entrySet())
{
EnumFacing enumfacing = this.parseEnumFacing((String)entry.getKey());
map.put(enumfacing, (BlockPartFace)deserializationContext.deserialize((JsonElement)entry.getValue(), BlockPartFace.class));
}
return map;
}
示例12: Builder
import com.google.common.collect.Maps; //导入方法依赖的package包/类
private Builder(boolean ambientOcclusion, boolean gui3d, ItemCameraTransforms transforms, ItemOverrideList overrides)
{
this.builderGeneralQuads = Lists.<BakedQuad>newArrayList();
this.builderFaceQuads = Maps.newEnumMap(EnumFacing.class);
for (EnumFacing enumfacing : EnumFacing.values())
{
this.builderFaceQuads.put(enumfacing, Lists.<BakedQuad>newArrayList());
}
this.builderItemOverrideList = overrides;
this.builderAmbientOcclusion = ambientOcclusion;
this.builderGui3d = gui3d;
this.builderCameraTransforms = transforms;
}
示例13: ModelPropertyExtractionContext
import com.google.common.collect.Maps; //导入方法依赖的package包/类
public ModelPropertyExtractionContext(String propertyName) {
this.propertyName = propertyName;
this.accessors = Maps.newEnumMap(PropertyAccessorType.class);
}
示例14: mergeAclEntries
import com.google.common.collect.Maps; //导入方法依赖的package包/类
/**
* Merges the entries of the ACL spec into the existing ACL. If necessary,
* recalculates the mask entries. If necessary, default entries may be
* inferred by copying the permissions of the corresponding access entries.
*
* @param existingAcl List<AclEntry> existing ACL
* @param inAclSpec List<AclEntry> ACL spec containing entries to merge
* @return List<AclEntry> new ACL
* @throws AclException if validation fails
*/
public static List<AclEntry> mergeAclEntries(List<AclEntry> existingAcl,
List<AclEntry> inAclSpec) throws AclException {
ValidatedAclSpec aclSpec = new ValidatedAclSpec(inAclSpec);
ArrayList<AclEntry> aclBuilder = Lists.newArrayListWithCapacity(MAX_ENTRIES);
List<AclEntry> foundAclSpecEntries =
Lists.newArrayListWithCapacity(MAX_ENTRIES);
EnumMap<AclEntryScope, AclEntry> providedMask =
Maps.newEnumMap(AclEntryScope.class);
EnumSet<AclEntryScope> maskDirty = EnumSet.noneOf(AclEntryScope.class);
EnumSet<AclEntryScope> scopeDirty = EnumSet.noneOf(AclEntryScope.class);
for (AclEntry existingEntry: existingAcl) {
AclEntry aclSpecEntry = aclSpec.findByKey(existingEntry);
if (aclSpecEntry != null) {
foundAclSpecEntries.add(aclSpecEntry);
scopeDirty.add(aclSpecEntry.getScope());
if (aclSpecEntry.getType() == MASK) {
providedMask.put(aclSpecEntry.getScope(), aclSpecEntry);
maskDirty.add(aclSpecEntry.getScope());
} else {
aclBuilder.add(aclSpecEntry);
}
} else {
if (existingEntry.getType() == MASK) {
providedMask.put(existingEntry.getScope(), existingEntry);
} else {
aclBuilder.add(existingEntry);
}
}
}
// ACL spec entries that were not replacements are new additions.
for (AclEntry newEntry: aclSpec) {
if (Collections.binarySearch(foundAclSpecEntries, newEntry,
ACL_ENTRY_COMPARATOR) < 0) {
scopeDirty.add(newEntry.getScope());
if (newEntry.getType() == MASK) {
providedMask.put(newEntry.getScope(), newEntry);
maskDirty.add(newEntry.getScope());
} else {
aclBuilder.add(newEntry);
}
}
}
copyDefaultsIfNeeded(aclBuilder);
calculateMasks(aclBuilder, providedMask, maskDirty, scopeDirty);
return buildAndValidateAcl(aclBuilder);
}
示例15: calculateMasks
import com.google.common.collect.Maps; //导入方法依赖的package包/类
/**
* Calculates mask entries required for the ACL. Mask calculation is performed
* separately for each scope: access and default. This method is responsible
* for handling the following cases of mask calculation:
* 1. Throws an exception if the caller attempts to remove the mask entry of an
* existing ACL that requires it. If the ACL has any named entries, then a
* mask entry is required.
* 2. If the caller supplied a mask in the ACL spec, use it.
* 3. If the caller did not supply a mask, but there are ACL entry changes in
* this scope, then automatically calculate a new mask. The permissions of
* the new mask are the union of the permissions on the group entry and all
* named entries.
*
* @param aclBuilder ArrayList<AclEntry> containing entries to build
* @param providedMask EnumMap<AclEntryScope, AclEntry> mapping each scope to
* the mask entry that was provided for that scope (if provided)
* @param maskDirty EnumSet<AclEntryScope> which contains a scope if the mask
* entry is dirty (added or deleted) in that scope
* @param scopeDirty EnumSet<AclEntryScope> which contains a scope if any entry
* is dirty (added or deleted) in that scope
* @throws AclException if validation fails
*/
private static void calculateMasks(List<AclEntry> aclBuilder,
EnumMap<AclEntryScope, AclEntry> providedMask,
EnumSet<AclEntryScope> maskDirty, EnumSet<AclEntryScope> scopeDirty)
throws AclException {
EnumSet<AclEntryScope> scopeFound = EnumSet.noneOf(AclEntryScope.class);
EnumMap<AclEntryScope, FsAction> unionPerms =
Maps.newEnumMap(AclEntryScope.class);
EnumSet<AclEntryScope> maskNeeded = EnumSet.noneOf(AclEntryScope.class);
// Determine which scopes are present, which scopes need a mask, and the
// union of group class permissions in each scope.
for (AclEntry entry: aclBuilder) {
scopeFound.add(entry.getScope());
if (entry.getType() == GROUP || entry.getName() != null) {
FsAction scopeUnionPerms = Objects.firstNonNull(
unionPerms.get(entry.getScope()), FsAction.NONE);
unionPerms.put(entry.getScope(),
scopeUnionPerms.or(entry.getPermission()));
}
if (entry.getName() != null) {
maskNeeded.add(entry.getScope());
}
}
// Add mask entry if needed in each scope.
for (AclEntryScope scope: scopeFound) {
if (!providedMask.containsKey(scope) && maskNeeded.contains(scope) &&
maskDirty.contains(scope)) {
// Caller explicitly removed mask entry, but it's required.
throw new AclException(
"Invalid ACL: mask is required and cannot be deleted.");
} else if (providedMask.containsKey(scope) &&
(!scopeDirty.contains(scope) || maskDirty.contains(scope))) {
// Caller explicitly provided new mask, or we are preserving the existing
// mask in an unchanged scope.
aclBuilder.add(providedMask.get(scope));
} else if (maskNeeded.contains(scope) || providedMask.containsKey(scope)) {
// Otherwise, if there are maskable entries present, or the ACL
// previously had a mask, then recalculate a mask automatically.
aclBuilder.add(new AclEntry.Builder()
.setScope(scope)
.setType(MASK)
.setPermission(unionPerms.get(scope))
.build());
}
}
}