本文整理汇总了Java中com.google.common.collect.ImmutableMap.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java ImmutableMap.Builder方法的具体用法?Java ImmutableMap.Builder怎么用?Java ImmutableMap.Builder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.ImmutableMap
的用法示例。
在下文中一共展示了ImmutableMap.Builder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractFrom
import com.google.common.collect.ImmutableMap; //导入方法依赖的package包/类
public static VariantsMetaData extractFrom(BinarySpec binarySpec, ModelSchema<?> binarySpecSchema) {
Map<String, Object> variants = Maps.newLinkedHashMap();
ImmutableMap.Builder<String, ModelType<?>> dimensionTypesBuilder = ImmutableMap.builder();
if (binarySpecSchema instanceof StructSchema) {
VariantAspect variantAspect = ((StructSchema<?>) binarySpecSchema).getAspect(VariantAspect.class);
if (variantAspect != null) {
for (ModelProperty<?> property : variantAspect.getDimensions()) {
// note: it's not the role of this class to validate that the annotation is properly used, that
// is to say only on a getter returning String or a Named instance, so we trust the result of
// the call
Object value = property.getPropertyValue(binarySpec);
variants.put(property.getName(), value);
dimensionTypesBuilder.put(property.getName(), property.getType());
}
}
}
return new DefaultVariantsMetaData(Collections.unmodifiableMap(variants), dimensionTypesBuilder.build());
}
示例2: MultiLayerBakedModel
import com.google.common.collect.ImmutableMap; //导入方法依赖的package包/类
public MultiLayerBakedModel(ImmutableMap<Optional<BlockRenderLayer>, IBakedModel> models, IBakedModel missing, ImmutableMap<TransformType, TRSRTransformation> cameraTransforms)
{
this.models = models;
this.cameraTransforms = cameraTransforms;
this.missing = missing;
if(models.containsKey(Optional.absent()))
{
base = models.get(Optional.absent());
}
else
{
base = missing;
}
ImmutableMap.Builder<Optional<EnumFacing>, ImmutableList<BakedQuad>> quadBuilder = ImmutableMap.builder();
quadBuilder.put(Optional.<EnumFacing>absent(), buildQuads(models, Optional.<EnumFacing>absent()));
for(EnumFacing side: EnumFacing.values())
{
quadBuilder.put(Optional.of(side), buildQuads(models, Optional.of(side)));
}
quads = quadBuilder.build();
}
示例3: loadDistributions
import com.google.common.collect.ImmutableMap; //导入方法依赖的package包/类
private static Map<String, Distribution> loadDistributions(Iterator<String> lines)
{
ImmutableMap.Builder<String, Distribution> distributions = ImmutableMap.builder();
while (lines.hasNext()) {
// advance to "begin"
String line = lines.next();
List<String> parts = ImmutableList.copyOf(Splitter.on(CharMatcher.WHITESPACE).omitEmptyStrings().split(line));
if (parts.size() != 2) {
continue;
}
if (parts.get(0).equalsIgnoreCase("BEGIN")) {
String name = parts.get(1);
Distribution distribution = loadDistribution(lines, name);
distributions.put(name.toLowerCase(), distribution);
}
}
return distributions.build();
}
示例4: buildStores
import com.google.common.collect.ImmutableMap; //导入方法依赖的package包/类
/**
* Create a map of stores defined in the provided scan using the provided factory.
* @param scan
* @param factory
* @return
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public static ImmutableMap<Class<? extends StoreCreationFunction<?>>, KVStore<?, ?>> buildStores(ScanResult scan, StoreBuildingFactory factory){
ImmutableMap.Builder builder = ImmutableMap.<Class<? extends StoreCreationFunction<?>>, KVStore<?, ?>>builder();
Set<Class<? extends StoreCreationFunction>> functions = scan.getImplementations(StoreCreationFunction.class);
for(Class<? extends StoreCreationFunction> functionClass : functions){
try {
final KVStore<?, ?> store = functionClass.newInstance().build(factory);
builder.put(functionClass, store);
} catch (Exception e) {
logger.warn("Unable to load StoreCreationFunction {}", functionClass.getSimpleName(), e);
}
}
final ImmutableMap<Class<? extends StoreCreationFunction<?>>, KVStore<?, ?>> map = builder.build();
logger.debug("Loaded the following StoreCreationFunctions: {}.", map.keySet());
return map;
}
示例5: saveCurrent
import com.google.common.collect.ImmutableMap; //导入方法依赖的package包/类
@Override
public void saveCurrent() {
final Map<String, FileCollectionSnapshot> outputFilesAfter = buildSnapshots(getTaskName(), getSnapshotterRegistry(), getTitle(), getFileProperties());
ImmutableMap.Builder<String, FileCollectionSnapshot> builder = ImmutableMap.builder();
for (TaskFilePropertySpec propertySpec : fileProperties) {
String propertyName = propertySpec.getPropertyName();
FileCollectionSnapshot beforeExecution = getCurrent().get(propertyName);
FileCollectionSnapshot afterExecution = outputFilesAfter.get(propertyName);
FileCollectionSnapshot afterPreviousExecution = getSnapshotAfterPreviousExecution(propertyName);
FileCollectionSnapshot outputSnapshot = outputSnapshotter.createOutputSnapshot(afterPreviousExecution, beforeExecution, afterExecution);
builder.put(propertyName, outputSnapshot);
}
current.setOutputFilesSnapshot(builder.build());
}
示例6: handleItemState
import com.google.common.collect.ImmutableMap; //导入方法依赖的package包/类
@Override
@Nonnull
public IBakedModel handleItemState(@Nonnull IBakedModel originalModel, @Nonnull ItemStack stack,
@Nullable World world, @Nullable EntityLivingBase entity) {
if (stack.getItem() != ModItems.sword) {
return originalModel;
}
BakedSwordModel model = (BakedSwordModel) originalModel;
String key = IBladeTool.getBladeMat(stack).getName() + "|"
+ ICrossguardTool.getCrossguardMat(stack).getName() + "|"
+ IHandleTool.getHandleMat(stack).getName() + "|"
+ IAdornedTool.getAdornmentMat(stack).getName();
if (!model.cache.containsKey(key)) {
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
builder.put("blade", IBladeTool.getBladeMat(stack).getName());
builder.put("crossguard", ICrossguardTool.getCrossguardMat(stack).getName());
builder.put("handle", IHandleTool.getHandleMat(stack).getName());
if (IAdornedTool.getAdornmentMat(stack) != ModMaterials.ADORNMENT_NULL) {
builder.put("adornment", IAdornedTool.getAdornmentMat(stack).getName());
}
IModel parent = model.parent.retexture(builder.build());
Function<ResourceLocation, TextureAtlasSprite> textureGetter;
textureGetter = new Function<ResourceLocation, TextureAtlasSprite>() {
public TextureAtlasSprite apply(ResourceLocation location) {
return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString());
}
};
IBakedModel bakedModel = parent.bake(new SimpleModelState(model.transforms), model.format,
textureGetter);
model.cache.put(key, bakedModel);
return bakedModel;
}
return model.cache.get(key);
}
示例7: retexture
import com.google.common.collect.ImmutableMap; //导入方法依赖的package包/类
@Override
public ModelWrapper retexture(ImmutableMap<String, String> textures)
{
ImmutableMap.Builder<String, ResourceLocation> builder = ImmutableMap.builder();
for(Map.Entry<String, ResourceLocation> e : this.textures.entrySet())
{
String path = e.getKey();
String loc = getLocation(path);
if(textures.containsKey(loc))
{
String newLoc = textures.get(loc);
if(newLoc == null) newLoc = getLocation(path);
builder.put(e.getKey(), new ResourceLocation(newLoc));
}
else
{
builder.put(e);
}
}
return new ModelWrapper(modelLocation, model, meshes, smooth, gui3d, defaultKey, builder.build());
}
示例8: toMap
import com.google.common.collect.ImmutableMap; //导入方法依赖的package包/类
public static <T, K, V> Collector<T, ImmutableMap.Builder<K, V>, ImmutableMap<K, V>> toMap(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends V> valueMapper) {
return Collector.of(
ImmutableMap.Builder<K, V>::new,
(r, t) -> r.put(keyMapper.apply(t), valueMapper.apply(t)),
(l, r) -> l.putAll(r.build()),
ImmutableMap.Builder::build
);
}
示例9: copyBindings
import com.google.common.collect.ImmutableMap; //导入方法依赖的package包/类
public void copyBindings(BinderImpl target){
synchronized(target){
ImmutableMap.Builder<Class<?>, Resolver> newMap = ImmutableMap.<Class<?>, Resolver>builder();
newMap.putAll(target.lookups);
newMap.putAll(lookups);
target.lookups = newMap.build();
}
}
示例10: Data
import com.google.common.collect.ImmutableMap; //导入方法依赖的package包/类
Data(final Map<String, StamtabelGegevens> stamgegevens) {
final ImmutableMap.Builder<String, StamtabelGegevens> stamtabelGegevensBuilder = ImmutableMap.builder();
for (Map.Entry<String, StamtabelGegevens> stringStamtabelGegevensEntry : stamgegevens.entrySet()) {
stamtabelGegevensBuilder.put(stringStamtabelGegevensEntry.getKey(), stringStamtabelGegevensEntry.getValue());
}
this.stamgegevens = stamtabelGegevensBuilder.build();
}
示例11: parseProperties
import com.google.common.collect.ImmutableMap; //导入方法依赖的package包/类
private Map<String, String> parseProperties(HierarchicalConfiguration driverCfg) {
ImmutableMap.Builder<String, String> properties = ImmutableMap.builder();
for (HierarchicalConfiguration b : driverCfg.configurationsAt(PROPERTY)) {
properties.put(b.getString(NAME), (String) b.getRootNode().getValue());
}
return properties.build();
}
示例12: handleResponseSetIDs
import com.google.common.collect.ImmutableMap; //导入方法依赖的package包/类
@Override
protected void handleResponseSetIDs(final ResponseLinking.Builder responseLinking,
final ImmutableSet<ResponseSet> responseSets,
final ImmutableMap<String, ResponseSet> responseIDs,
final Optional<ImmutableMap.Builder<String, String>> foreignLinkingIdToLocal)
throws IOException {
if (responseSets.size() == responseIDs.size()) {
responseLinking.responseSetIds(ImmutableBiMap.copyOf(responseIDs));
responseLinking.build();
} else if (responseSets.size() > responseIDs.size() || !foreignLinkingIdToLocal.isPresent()) {
throw new IOException("Read " + responseSets.size() + " response sets but "
+ responseIDs.size() + " ID assignments");
} else {
log.warn(
"Warning - converting ResponseSet IDs and saving them, this is almost definitely an error!");
final ImmutableMultimap<ResponseSet, String> responseSetToIds =
responseIDs.asMultimap().inverse();
final LaxImmutableMapBuilder<String, ResponseSet> idsMapB =
MapUtils.immutableMapBuilderAllowingSameEntryTwice();
for (final Map.Entry<ResponseSet, Collection<String>> setAndIds : responseSetToIds.asMap()
.entrySet()) {
final Collection<String> ids = setAndIds.getValue();
final String selectedID =
checkNotNull(getFirst(usingToString().immutableSortedCopy(ids), null));
for (final String oldId : ids) {
log.debug("Selecting id {} for cluster {}", selectedID, oldId);
foreignLinkingIdToLocal.get().put(oldId, selectedID);
idsMapB.put(selectedID, responseIDs.get(oldId));
}
}
responseLinking.responseSetIds(ImmutableBiMap.copyOf(idsMapB.build()));
}
}
示例13: addVictory
import com.google.common.collect.ImmutableMap; //导入方法依赖的package包/类
void addVictory(UserName userName) {
ImmutableMap<UserName, Integer> currentScores = scoresRelay.getValue();
ImmutableMap.Builder<UserName, Integer> newScoreMapBuilder = new ImmutableMap.Builder<>();
for (Map.Entry<UserName, Integer> entry : currentScores.entrySet()) {
if (entry.getKey().equals(userName)) {
newScoreMapBuilder.put(entry.getKey(), entry.getValue() + 1);
} else {
newScoreMapBuilder.put(entry.getKey(), entry.getValue());
}
}
scoresRelay.accept(newScoreMapBuilder.build());
}
示例14: getAllSwitchMap
import com.google.common.collect.ImmutableMap; //导入方法依赖的package包/类
public Map<DatapathId, IOFSwitch> getAllSwitchMap(boolean showInvisible) {
if(showInvisible) {
return ImmutableMap.<DatapathId, IOFSwitch>copyOf(switches);
} else {
ImmutableMap.Builder<DatapathId, IOFSwitch> builder = ImmutableMap.builder();
for(IOFSwitch sw: switches.values()) {
if(sw.getStatus().isVisible())
builder.put(sw.getId(), sw);
}
return builder.build();
}
}
示例15: writeBootstrappedOutput
import com.google.common.collect.ImmutableMap; //导入方法依赖的package包/类
private void writeBootstrappedOutput(final List<EALScorer2015Style.Result> perDocResults,
final File baseOutputDir) throws IOException {
if (doBootstrapping) {
// boostrapped result writers are stateful, so we need to get new ones each time
final ImmutableMap.Builder<String, BootstrappedResultWriter> builder = ImmutableMap.builder();
for (final Map.Entry<String, BootstrappedResultWriterSource> source : bootstrappedResultWriterSources
.entrySet()) {
builder.put(source.getKey(), source.getValue().getResultWriter());
}
final ImmutableMap<String, BootstrappedResultWriter> bootstrappedWriters = builder.build();
// this will produce an infinite sequence of bootstrapped samples of the corpus
final Iterator<Collection<EALScorer2015Style.Result>>
bootstrapIt = BootstrapIterator.forData(perDocResults, new Random(bootstrapSeed));
// a bootstrap iterator always has .next()
for (int i = 0; i < numBootstrapSamples; ++i) {
// be sure to use the same sample for all observers
final Collection<EALScorer2015Style.Result> sample = bootstrapIt.next();
for (final KBP2015Scorer.BootstrappedResultWriter bootstrappedResultWriter : bootstrappedWriters
.values()) {
bootstrappedResultWriter.observeSample(sample);
}
}
for (final Map.Entry<String, BootstrappedResultWriter> resultWriterEntry : bootstrappedWriters
.entrySet()) {
final File outputDir = new File(baseOutputDir, resultWriterEntry.getKey());
outputDir.mkdirs();
resultWriterEntry.getValue().writeResult(outputDir);
}
}
}