List of usage examples for com.google.common.collect ImmutableBiMap builder
public static <K, V> Builder<K, V> builder()
From source file:org.jpmml.evaluator.EntityUtil.java
static public <E extends PMMLObject & HasId> ImmutableBiMap<String, E> buildBiMap(List<E> entities) { ImmutableBiMap.Builder<String, E> builder = new ImmutableBiMap.Builder<String, E>(); builder = putAll(entities, builder); return builder.build(); }
From source file:org.jpmml.evaluator.EntityUtil.java
static public <E extends PMMLObject & HasId> ImmutableBiMap.Builder<String, E> put(E entity, ImmutableBiMap.Builder<String, E> builder) { String id = entity.getId();/*from www .j ava 2 s. co m*/ if (id == null) { throw new InvalidFeatureException(entity); } return builder.put(id, entity); }
From source file:org.jpmml.evaluator.EntityUtil.java
static public <E extends PMMLObject & HasId> ImmutableBiMap.Builder<String, E> putAll(List<E> entities, ImmutableBiMap.Builder<String, E> builder) { for (int i = 0, j = 1; i < entities.size(); i++, j++) { E entity = entities.get(i);//w w w. j av a 2 s .c o m String id = entity.getId(); // Generate an implicit identifier (ie. 1-based index) if the explicit identifier is missing if (id == null) { id = String.valueOf(j); } // End if builder = builder.put(id, entity); } return builder; }
From source file:org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil.java
public static void init() { // v1.0 ports final ImmutableBiMap<String, Long> OFv10 = new ImmutableBiMap.Builder<String, Long>() .put(OutputPortValues.MAX.toString(), Long.valueOf(PortNumberValuesV10.MAX.getIntValue())) //0xff00 .put(OutputPortValues.INPORT.toString(), Long.valueOf(PortNumberValuesV10.INPORT.getIntValue())) //0xfff8 .put(OutputPortValues.TABLE.toString(), Long.valueOf(PortNumberValuesV10.TABLE.getIntValue())) //0xfff9 .put(OutputPortValues.NORMAL.toString(), Long.valueOf(PortNumberValuesV10.NORMAL.getIntValue())) //0xfffa .put(OutputPortValues.FLOOD.toString(), Long.valueOf(PortNumberValuesV10.FLOOD.getIntValue())) //0xfffb .put(OutputPortValues.ALL.toString(), Long.valueOf(PortNumberValuesV10.ALL.getIntValue())) //0xfffc .put(OutputPortValues.CONTROLLER.toString(), Long.valueOf(PortNumberValuesV10.CONTROLLER.getIntValue())) //0xfffd .put(OutputPortValues.LOCAL.toString(), Long.valueOf(PortNumberValuesV10.LOCAL.getIntValue())) //0xfffe .put(OutputPortValues.NONE.toString(), Long.valueOf(PortNumberValuesV10.NONE.getIntValue())) //0xfffe .build();//from w ww. j a va2 s. c o m // openflow 1.3 reserved ports. // PortNumberValues are defined in OFJava yang. And yang maps an int to all enums. Hence we need to create longs from (-ve) ints // TODO: do we need to define these ports in yang? final ImmutableBiMap<String, Long> OFv13 = new ImmutableBiMap.Builder<String, Long>() .put(OutputPortValues.MAX.toString(), BinContent.intToUnsignedLong(PortNumberValues.MAX.getIntValue())) //0xffffff00 .put(OutputPortValues.INPORT.toString(), BinContent.intToUnsignedLong(PortNumberValues.INPORT.getIntValue())) //0xfffffff8 .put(OutputPortValues.TABLE.toString(), BinContent.intToUnsignedLong(PortNumberValues.TABLE.getIntValue())) //0xfffffff9 .put(OutputPortValues.NORMAL.toString(), BinContent.intToUnsignedLong(PortNumberValues.NORMAL.getIntValue())) //0xfffffffa .put(OutputPortValues.FLOOD.toString(), BinContent.intToUnsignedLong(PortNumberValues.FLOOD.getIntValue())) //0xfffffffb .put(OutputPortValues.ALL.toString(), BinContent.intToUnsignedLong(PortNumberValues.ALL.getIntValue())) //0xfffffffc .put(OutputPortValues.CONTROLLER.toString(), BinContent.intToUnsignedLong(PortNumberValues.CONTROLLER.getIntValue())) //0xfffffffd .put(OutputPortValues.LOCAL.toString(), BinContent.intToUnsignedLong(PortNumberValues.LOCAL.getIntValue())) //0xfffffffe .put(OutputPortValues.ANY.toString(), BinContent.intToUnsignedLong(PortNumberValues.ANY.getIntValue())) //0xffffffff .build(); versionPortMap = new ImmutableBiMap.Builder<OpenflowVersion, ImmutableBiMap<String, Long>>() .put(OpenflowVersion.OF10, OFv10).put(OpenflowVersion.OF13, OFv13).build(); }
From source file:org.kiji.schema.layout.IdentityColumnNameTranslator.java
/** * Constructs a mock table layout./*from ww w . ja v a 2 s. c o m*/ * * @return A mock table layout. */ private static KijiTableLayout createMockTableLayout() { KijiTableLayout mock = EasyMock.createMock(KijiTableLayout.class); EasyMock.expect(mock.getLocalityGroupIdNameMap()) .andReturn(new ImmutableBiMap.Builder<ColumnId, String>().build()); EasyMock.replay(mock); return mock; }
From source file:org.apache.beam.runners.flink.translation.utils.FlinkPipelineTranslatorUtils.java
/** Creates a mapping from PCollection id to output tag integer. */ public static BiMap<String, Integer> createOutputMap(Iterable<String> localOutputs) { ImmutableBiMap.Builder<String, Integer> builder = ImmutableBiMap.builder(); int outputIndex = 0; // sort localOutputs for stable indexing for (String tag : Sets.newTreeSet(localOutputs)) { builder.put(tag, outputIndex);//from w ww. j a v a 2s . com outputIndex++; } return builder.build(); }
From source file:org.opendaylight.yangtools.yang.data.api.schema.xpath.PrefixConverters.java
/** * Create a prefix {@link Converter} for {@link XPathExpressionException} defined in a particular YANG * {@link Module} .Instantiation requires establishing how a module's imports are mapped to actual modules * and their namespaces. This information is cached and used for improved lookups. * * @param ctx A SchemaContext/* w w w. j a v a 2 s . c o m*/ * @param module Module in which the XPath is defined * @return A new Converter */ public static @Nonnull Converter<String, QNameModule> create(final SchemaContext ctx, final Module module) { // Always check for null ctx Preconditions.checkNotNull(ctx, "Schema context may not be null"); // Use immutable map builder for detection of duplicates (which should never occur) final Builder<String, QNameModule> b = ImmutableBiMap.builder(); b.put(module.getPrefix(), module.getQNameModule()); for (ModuleImport i : module.getImports()) { final Module mod = ctx.findModuleByName(i.getModuleName(), i.getRevision()); Preconditions.checkArgument(mod != null, "Unsatisfied import of %s by module %s", i, module); b.put(i.getPrefix(), mod.getQNameModule()); } return Maps.asConverter(b.build()); }
From source file:com.google.caliper.bridge.LogMessageParser.java
private static ImmutableBiMap<Class<? extends CaliperControlLogMessage>, String> createMapForTypes( Set<Class<? extends CaliperControlLogMessage>> messageTypes) { ImmutableBiMap.Builder<Class<? extends CaliperControlLogMessage>, String> builder = ImmutableBiMap .builder();// w ww . j a v a2 s .c o m for (Class<? extends CaliperControlLogMessage> messageType : messageTypes) { builder.put(messageType, messageType.getSimpleName()); } return builder.build(); }
From source file:com.google.android.mobly.snippet.bundled.utils.RpcEnum.java
private RpcEnum(ImmutableBiMap.Builder<String, Integer> builder, int minSdk) {
mEnums = builder.build();
}
From source file:com.github.ferstl.maven.pomenforcers.model.functions.AbstractOneToOneMatcher.java
public final BiMap<V, V> match(Collection<U> superset, Collection<V> subset) { Builder<V, V> mapBuilder = ImmutableBiMap.builder(); // Transform the superset here in order not to do it in each nested loop Collection<V> transformedSuperset = transformSuperset(superset); for (V subsetItem : subset) { boolean itemMatched = false; for (V supersetItem : transformedSuperset) { if (matches(supersetItem, subsetItem)) { itemMatched = true;//from w w w . j a va 2 s . c o m mapBuilder.put(supersetItem, subsetItem); break; } } if (!itemMatched) { handleUnmatchedItem(mapBuilder, subsetItem); } } return mapBuilder.build(); }