当前位置: 首页>>代码示例>>Java>>正文


Java Maps.immutableEntry方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:line,项目名称:centraldogma,代码行数:24,代码来源:RepositoryService.java

示例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>
 * &lt;type
 * xmlns:th-java="urn:opendaylight:params:xml:ns:yang:controller:threadpool:impl"&gt;th-java:threadfactory-naming&lt;/type&gt;
 * </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));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:30,代码来源:XmlElement.java

示例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>>");
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:SourceTypeTest.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:TypeStringProvider.java

示例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);
}
 
开发者ID:airlift,项目名称:drift,代码行数:12,代码来源:ReflectionThriftUnionCodec.java

示例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);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:21,代码来源:TestSizeFailures.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:48,代码来源:SourceTypes.java

示例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();
    }
}
 
开发者ID:lucko,项目名称:helper,代码行数:53,代码来源:SimpleMetadataMap.java

示例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();
    }
}
 
开发者ID:lucko,项目名称:helper,代码行数:58,代码来源:SimpleMetadataMap.java

示例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();
    }
}
 
开发者ID:lucko,项目名称:helper,代码行数:63,代码来源:SimpleMetadataMap.java

示例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));
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:5,代码来源:ApplyQuoteFilter.java

示例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);
}
 
开发者ID:airlift,项目名称:drift,代码行数:42,代码来源:ReflectionThriftUnionCodec.java

示例13: entryOf

import com.google.common.collect.Maps; //导入方法依赖的package包/类
private Entry<Object, Object> entryOf(Object key, Object value) {
  return Maps.immutableEntry(key, value);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:4,代码来源:EmptyCachesTest.java

示例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());
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:4,代码来源:MetricsListener.java

示例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);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:5,代码来源:TestSegmentRecoveryComparator.java


注:本文中的com.google.common.collect.Maps.immutableEntry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。