本文整理汇总了Java中com.google.common.collect.Maps.immutableEntry方法的典型用法代码示例。如果您正苦于以下问题:Java Maps.immutableEntry方法的具体用法?Java Maps.immutableEntry怎么用?Java Maps.immutableEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.Maps
的用法示例。
在下文中一共展示了Maps.immutableEntry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: commitMessageAndChange
import com.google.common.collect.Maps; //导入方法依赖的package包/类
private static Entry<CommitMessageDto, Change<?>> commitMessageAndChange(AggregatedHttpMessage message) {
try {
final JsonNode node = Jackson.readTree(message.content().toStringUtf8());
final CommitMessageDto commitMessage =
Jackson.convertValue(node.get("commitMessage"), CommitMessageDto.class);
final EntryDto file = Jackson.convertValue(node.get("file"), EntryDto.class);
final Change<?> change;
switch (file.getType()) {
case "JSON":
change = Change.ofJsonUpsert(file.getPath(), file.getContent());
break;
case "TEXT":
change = Change.ofTextUpsert(file.getPath(), file.getContent());
break;
default:
throw new IllegalArgumentException("unsupported file type: " + file.getType());
}
return Maps.immutableEntry(commitMessage, change);
} catch (IOException e) {
throw new BadRequestException("invalid data to be parsed", e);
}
}
示例2: findNamespaceOfTextContent
import com.google.common.collect.Maps; //导入方法依赖的package包/类
/**
* Search for element's attributes defining namespaces. Look for the one
* namespace that matches prefix of element's text content. E.g.
*
* <pre>
* <type
* xmlns:th-java="urn:opendaylight:params:xml:ns:yang:controller:threadpool:impl">th-java:threadfactory-naming</type>
* </pre>
*
* returns {"th-java","urn:.."}. If no prefix is matched, then default
* namespace is returned with empty string as key. If no default namespace
* is found value will be null.
*/
public Map.Entry<String/* prefix */, String/* namespace */> findNamespaceOfTextContent() throws DocumentedException {
Map<String, String> namespaces = extractNamespaces();
String textContent = getTextContent();
int indexOfColon = textContent.indexOf(':');
String prefix;
if (indexOfColon > -1) {
prefix = textContent.substring(0, indexOfColon);
} else {
prefix = DEFAULT_NAMESPACE_PREFIX;
}
if (!namespaces.containsKey(prefix)) {
throw new IllegalArgumentException("Cannot find namespace for " + XmlUtil.toString(element) + ". Prefix from content is "
+ prefix + ". Found namespaces " + namespaces);
}
return Maps.immutableEntry(prefix, namespaces.get(prefix));
}
示例3: stringify
import com.google.common.collect.Maps; //导入方法依赖的package包/类
public void stringify() {
Entry<String, List<String>> entry =
Maps.<String, List<String>>immutableEntry("Map",
ImmutableList.of("String<X>", "Map<Int, B>"));
check(SourceTypes.stringify(entry)).is("Map<String<X>, Map<Int, B>>");
}
示例4: resolveTypes
import com.google.common.collect.Maps; //导入方法依赖的package包/类
private Entry<String, List<String>> resolveTypes(Entry<String, List<String>> sourceTypes) {
String typeName = sourceTypes.getKey();
typeName = importsResolver.apply(typeName);
hasMaybeUnresolvedYetAfter |= importsResolver.unresolved;
List<String> typeArguments = Lists.newArrayListWithCapacity(sourceTypes.getValue().size());
for (String typeArgument : sourceTypes.getValue()) {
String resolvedTypeArgument = SourceTypes.stringify(resolveTypes(SourceTypes.extract(typeArgument)));
typeArguments.add(resolvedTypeArgument);
}
return Maps.immutableEntry(typeName, typeArguments);
}
示例5: ReflectionThriftUnionCodec
import com.google.common.collect.Maps; //导入方法依赖的package包/类
public ReflectionThriftUnionCodec(ThriftCodecManager manager, ThriftStructMetadata metadata)
{
super(manager, metadata);
ThriftFieldMetadata idField = getOnlyElement(metadata.getFields(FieldKind.THRIFT_UNION_ID));
this.idField = Maps.immutableEntry(idField, manager.getCodec(idField.getThriftType()));
requireNonNull(this.idField.getValue(), () -> "No codec for ID field found: " + idField);
this.metadataMap = uniqueIndex(metadata.getFields(), ThriftFieldMetadata::getId);
}
示例6: sumTable
import com.google.common.collect.Maps; //导入方法依赖的package包/类
/**
* Count the number of rows and the number of entries from a scanner
*
* @param scanner
* The Scanner
* @return An entry where the first item is rows observed and the second is entries observed.
*/
private Entry<Long,Long> sumTable(ResultScanner scanner) {
long rowsObserved = 0l;
long entriesObserved = 0l;
// Read all the records in the table
for (Result result : scanner) {
rowsObserved++;
while (result.advance()) {
entriesObserved++;
}
}
return Maps.immutableEntry(rowsObserved,entriesObserved);
}
示例7: extract
import com.google.common.collect.Maps; //导入方法依赖的package包/类
public static Entry<String, List<String>> extract(CharSequence typeString) {
StringBuilder typeName = new StringBuilder();
StringBuilder typeArgument = new StringBuilder();
List<String> typeArguments = Lists.newArrayList();
int anglesOpened = 0;
chars: for (int i = 0; i < typeString.length(); i++) {
char c = typeString.charAt(i);
switch (c) {
case '<':
if (++anglesOpened > 1) {
typeArgument.append(c);
}
break;
case '>':
if (--anglesOpened > 0) {
typeArgument.append(c);
} else {
break chars;
}
break;
case ',':
if (anglesOpened == 1) {
typeArguments.add(typeArgument.toString());
typeArgument = new StringBuilder();
} else {
typeArgument.append(c);
}
break;
case ' ':// not sure about this one
if (anglesOpened > 1) {
typeArgument.append(c);
}
break;
default:
if (anglesOpened == 0) {
typeName.append(c);
} else {
typeArgument.append(c);
}
}
}
String lastArgument = typeArgument.toString();
if (!lastArgument.isEmpty()) {
typeArguments.add(lastArgument);
}
return Maps.immutableEntry(typeName.toString(), typeArguments);
}
示例8: get
import com.google.common.collect.Maps; //导入方法依赖的package包/类
@Nonnull
@Override
public <T> Optional<T> get(@Nonnull MetadataKey<T> key) {
Preconditions.checkNotNull(key, "key");
lock.lock();
try {
Map.Entry<MetadataKey<?>, Object> existing = null;
// try to locate an existing entry, and expire any values at the same time.
Iterator<Map.Entry<MetadataKey<?>, Object>> it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<MetadataKey<?>, Object> kv = it.next();
if (kv.getValue() instanceof TransientValue<?>) {
TransientValue<?> transientValue = ((TransientValue) kv.getValue());
Object unboxed = transientValue.getOrNull();
// if it has expired
if (unboxed == null) {
it.remove();
continue;
}
// copy out the unboxed value
if (kv.getKey().equals(key)) {
existing = Maps.immutableEntry(kv.getKey(), unboxed);
break;
}
} else {
if (kv.getKey().equals(key)) {
existing = kv;
break;
}
}
}
if (existing == null) {
return Optional.empty();
}
if (!existing.getKey().getType().equals(key.getType())) {
throw new ClassCastException("Cannot cast key with id " + key.getId() + " with type " + key.getType().getRawType() + " to existing stored type " + existing.getKey().getType().getRawType());
}
return Optional.of(key.cast(existing.getValue()));
} finally {
lock.unlock();
}
}
示例9: getOrPut
import com.google.common.collect.Maps; //导入方法依赖的package包/类
@Nonnull
@Override
public <T> T getOrPut(@Nonnull MetadataKey<T> key, @Nonnull Supplier<? extends T> def) {
Preconditions.checkNotNull(key, "key");
Preconditions.checkNotNull(def, "def");
lock.lock();
try {
Map.Entry<MetadataKey<?>, Object> existing = null;
// try to locate an existing entry, and expire any values at the same time.
Iterator<Map.Entry<MetadataKey<?>, Object>> it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<MetadataKey<?>, Object> kv = it.next();
if (kv.getValue() instanceof TransientValue<?>) {
TransientValue<?> transientValue = ((TransientValue) kv.getValue());
Object unboxed = transientValue.getOrNull();
// if it has expired
if (unboxed == null) {
it.remove();
continue;
}
// copy out the unboxed value
if (kv.getKey().equals(key)) {
existing = Maps.immutableEntry(kv.getKey(), unboxed);
break;
}
} else {
if (kv.getKey().equals(key)) {
existing = kv;
break;
}
}
}
if (existing == null) {
T t = def.get();
Preconditions.checkNotNull(t, "supplied def");
map.put(key, t);
return t;
}
if (!existing.getKey().getType().equals(key.getType())) {
throw new ClassCastException("Cannot cast key with id " + key.getId() + " with type " + key.getType().getRawType() + " to existing stored type " + existing.getKey().getType().getRawType());
}
return key.cast(existing.getValue());
} finally {
lock.unlock();
}
}
示例10: getOrPutExpiring
import com.google.common.collect.Maps; //导入方法依赖的package包/类
@Nonnull
@Override
public <T> T getOrPutExpiring(@Nonnull MetadataKey<T> key, @Nonnull Supplier<? extends TransientValue<T>> def) {
Preconditions.checkNotNull(key, "key");
Preconditions.checkNotNull(def, "def");
lock.lock();
try {
Map.Entry<MetadataKey<?>, Object> existing = null;
// try to locate an existing entry, and expire any values at the same time.
Iterator<Map.Entry<MetadataKey<?>, Object>> it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<MetadataKey<?>, Object> kv = it.next();
if (kv.getValue() instanceof TransientValue<?>) {
TransientValue<?> transientValue = ((TransientValue) kv.getValue());
Object unboxed = transientValue.getOrNull();
// if it has expired
if (unboxed == null) {
it.remove();
continue;
}
// copy out the unboxed value
if (kv.getKey().equals(key)) {
existing = Maps.immutableEntry(kv.getKey(), unboxed);
break;
}
} else {
if (kv.getKey().equals(key)) {
existing = kv;
break;
}
}
}
if (existing == null) {
TransientValue<T> t = def.get();
Preconditions.checkNotNull(t, "supplied def");
T value = t.getOrNull();
if (value == null) {
throw new IllegalArgumentException("Transient value already expired: " + t);
}
map.put(key, t);
return value;
}
if (!existing.getKey().getType().equals(key.getType())) {
throw new ClassCastException("Cannot cast key with id " + key.getId() + " with type " + key.getType().getRawType() + " to existing stored type " + existing.getKey().getType().getRawType());
}
return key.cast(existing.getValue());
} finally {
lock.unlock();
}
}
示例11: storeFor
import com.google.common.collect.Maps; //导入方法依赖的package包/类
private static Map.Entry<SystemOutputStore, SystemOutputStore> storeFor(File inputPath,
File outputPath, SystemOutputLayout layout) throws IOException {
return Maps.immutableEntry(layout.open(inputPath), layout.openOrCreate(outputPath));
}
示例12: read
import com.google.common.collect.Maps; //导入方法依赖的package包/类
@Override
public T read(TProtocolReader protocol)
throws Exception
{
ProtocolReader reader = new ProtocolReader(protocol);
reader.readStructBegin();
Map.Entry<Short, Object> data = null;
Short fieldId = null;
while (reader.nextField()) {
checkState(fieldId == null, "Received Union with more than one value (seen id %s, now id %s)", fieldId, reader.getFieldId());
fieldId = reader.getFieldId();
// do we have a codec for this field
ThriftCodec<?> codec = fields.get(fieldId);
if (codec == null) {
reader.skipFieldData();
}
else {
// is this field readable
ThriftFieldMetadata field = metadata.getField(fieldId);
if (field.isWriteOnly() || field.getType() != THRIFT_FIELD) {
reader.skipFieldData();
continue;
}
// read the value
Object value = reader.readField(codec);
if (value == null) {
continue;
}
data = Maps.immutableEntry(fieldId, value);
}
}
reader.readStructEnd();
// build the struct
return constructStruct(data);
}
示例13: entryOf
import com.google.common.collect.Maps; //导入方法依赖的package包/类
private Entry<Object, Object> entryOf(Object key, Object value) {
return Maps.immutableEntry(key, value);
}
示例14: bytesReplicated
import com.google.common.collect.Maps; //导入方法依赖的package包/类
private Entry<String, Long> bytesReplicated(String target, Metrics metrics) {
return Maps.immutableEntry(DotJoiner.join(target, "bytes_replicated"), metrics.getBytesReplicated());
}
示例15: makeEntry
import com.google.common.collect.Maps; //导入方法依赖的package包/类
private static Map.Entry<AsyncLogger, PrepareRecoveryResponseProto> makeEntry(
PrepareRecoveryResponseProto proto) {
return Maps.immutableEntry(Mockito.mock(AsyncLogger.class), proto);
}