Java Code Examples for com.google.common.collect.HashBiMap#put()
The following examples show how to use
com.google.common.collect.HashBiMap#put() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GqlInputConverter.java From rejoiner with Apache License 2.0 | 6 votes |
public GqlInputConverter build() { HashBiMap<String, Descriptor> mapping = HashBiMap.create(); HashBiMap<String, EnumDescriptor> enumMapping = HashBiMap.create(getEnumMap(enumDescriptors)); LinkedList<Descriptor> loop = new LinkedList<>(descriptors); Set<FileDescriptor> fileDescriptorSet = ProtoRegistry.extractDependencies(fileDescriptors); for (FileDescriptor fileDescriptor : fileDescriptorSet) { loop.addAll(fileDescriptor.getMessageTypes()); enumMapping.putAll(getEnumMap(fileDescriptor.getEnumTypes())); } while (!loop.isEmpty()) { Descriptor descriptor = loop.pop(); if (!mapping.containsKey(descriptor.getFullName())) { mapping.put(getReferenceName(descriptor), descriptor); loop.addAll(descriptor.getNestedTypes()); enumMapping.putAll(getEnumMap(descriptor.getEnumTypes())); } } return new GqlInputConverter( ImmutableBiMap.copyOf(mapping), ImmutableBiMap.copyOf(enumMapping)); }
Example 2
Source File: XlsxFormatter.java From yarg with Apache License 2.0 | 6 votes |
/** * XLSX document does not store empty cells and it might be an issue for formula calculations and etc. * So we need to create fake template cell for each empty cell. */ protected void createFakeTemplateCellsForEmptyOnes(Range oneRowRange, Map<CellReference, Cell> cellsForOneRowRange, List<Cell> templateCells) { if (oneRowRange.toCellReferences().size() != templateCells.size()) { final HashBiMap<CellReference, Cell> referencesToCells = HashBiMap.create(cellsForOneRowRange); for (CellReference cellReference : oneRowRange.toCellReferences()) { if (!cellsForOneRowRange.containsKey(cellReference)) { Cell newCell = Context.getsmlObjectFactory().createCell(); newCell.setV(null); newCell.setT(STCellType.STR); newCell.setR(cellReference.toReference()); templateCells.add(newCell); referencesToCells.put(cellReference, newCell); } } templateCells.sort((o1, o2) -> { CellReference cellReference1 = referencesToCells.inverse().get(o1); CellReference cellReference2 = referencesToCells.inverse().get(o2); return cellReference1.compareTo(cellReference2); }); } }
Example 3
Source File: GqlInputConverter.java From rejoiner with Apache License 2.0 | 5 votes |
private static BiMap<String, EnumDescriptor> getEnumMap(Iterable<EnumDescriptor> descriptors) { HashBiMap<String, EnumDescriptor> mapping = HashBiMap.create(); for (EnumDescriptor enumDescriptor : descriptors) { mapping.put(ProtoToGql.getReferenceName(enumDescriptor), enumDescriptor); } return mapping; }
Example 4
Source File: ProtoRegistry.java From rejoiner with Apache License 2.0 | 5 votes |
private static BiMap<String, GraphQLType> getMap( List<FileDescriptor> fileDescriptors, List<Descriptor> descriptors, List<EnumDescriptor> enumDescriptors, GraphQLInterfaceType nodeInterface, SchemaOptions schemaOptions) { HashBiMap<String, GraphQLType> mapping = HashBiMap.create(getEnumMap(enumDescriptors, schemaOptions)); LinkedList<Descriptor> loop = new LinkedList<>(descriptors); Set<FileDescriptor> fileDescriptorSet = extractDependencies(fileDescriptors); for (FileDescriptor fileDescriptor : fileDescriptorSet) { loop.addAll(fileDescriptor.getMessageTypes()); mapping.putAll(getEnumMap(fileDescriptor.getEnumTypes(), schemaOptions)); } while (!loop.isEmpty()) { Descriptor descriptor = loop.pop(); if (!mapping.containsKey(descriptor.getFullName())) { mapping.put( ProtoToGql.getReferenceName(descriptor), ProtoToGql.convert(descriptor, nodeInterface, schemaOptions)); GqlInputConverter inputConverter = GqlInputConverter.newBuilder().add(descriptor.getFile()).build(); mapping.put( GqlInputConverter.getReferenceName(descriptor), inputConverter.getInputType(descriptor, schemaOptions)); loop.addAll(descriptor.getNestedTypes()); mapping.putAll(getEnumMap(descriptor.getEnumTypes(), schemaOptions)); } } return ImmutableBiMap.copyOf(mapping); }
Example 5
Source File: ProtoRegistry.java From rejoiner with Apache License 2.0 | 5 votes |
private static BiMap<String, GraphQLType> getEnumMap( Iterable<EnumDescriptor> descriptors, SchemaOptions schemaOptions) { HashBiMap<String, GraphQLType> mapping = HashBiMap.create(); for (EnumDescriptor enumDescriptor : descriptors) { mapping.put( ProtoToGql.getReferenceName(enumDescriptor), ProtoToGql.convert(enumDescriptor, schemaOptions)); } return mapping; }
Example 6
Source File: BiMapGwtTest.java From gwt-jackson with Apache License 2.0 | 5 votes |
public void testDeserialization() { String input = "{" + "\"biMap\":{\"one\":1,\"two\":2,\"three\":3,\"four\":4}," + "\"hashBiMap\":{\"one\":1,\"two\":2,\"three\":3,\"four\":4}," + "\"enumHashBiMap\":{\"A\":1,\"B\":2,\"C\":3,\"D\":4}," + "\"enumBiMap\":{\"A\":\"ONE\",\"B\":\"TWO\",\"C\":\"THREE\",\"D\":\"FOUR\"}" + "}"; BeanWithBiMapTypes result = BeanWithBiMapTypesMapper.INSTANCE.read( input ); assertNotNull( result ); HashBiMap<String, Integer> expectedHashBiMap = HashBiMap.create(); expectedHashBiMap.put( "one", 1 ); expectedHashBiMap.put( "two", 2 ); expectedHashBiMap.put( "three", 3 ); expectedHashBiMap.put( "four", 4 ); assertNotNull( result.biMap ); assertEquals( expectedHashBiMap, result.biMap ); assertEquals( expectedHashBiMap, result.hashBiMap ); EnumHashBiMap<AlphaEnum, Integer> expectedEnumHashBiMap = EnumHashBiMap.create( AlphaEnum.class ); expectedEnumHashBiMap.put( AlphaEnum.A, 1 ); expectedEnumHashBiMap.put( AlphaEnum.D, 4 ); expectedEnumHashBiMap.put( AlphaEnum.C, 3 ); expectedEnumHashBiMap.put( AlphaEnum.B, 2 ); assertEquals( expectedEnumHashBiMap, result.enumHashBiMap ); EnumBiMap<AlphaEnum, NumericEnum> expectedEnumBiMap = EnumBiMap.create( AlphaEnum.class, NumericEnum.class ); expectedEnumBiMap.put( AlphaEnum.A, NumericEnum.ONE ); expectedEnumBiMap.put( AlphaEnum.D, NumericEnum.FOUR ); expectedEnumBiMap.put( AlphaEnum.C, NumericEnum.THREE ); expectedEnumBiMap.put( AlphaEnum.B, NumericEnum.TWO ); assertEquals( expectedEnumBiMap, result.enumBiMap ); }
Example 7
Source File: MapUtilUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void whenUsingBiMap_shouldReturnKey() { HashBiMap<String, String> capitalCountryMap = HashBiMap.create(); capitalCountryMap.put("Berlin", "Germany"); capitalCountryMap.put("Cape Town", "South Africa"); assertEquals("Berlin", capitalCountryMap.inverse().get("Germany")); }
Example 8
Source File: MapUtilUnitTest.java From tutorials with MIT License | 5 votes |
@Test(expected=IllegalArgumentException.class) public void whenUsingBiMapAddDuplicateValue_shouldThrowException() { HashBiMap<String, String> capitalCountryMap = HashBiMap.create(); capitalCountryMap.put("Berlin", "Germany"); capitalCountryMap.put("Cape Town", "South Africa"); capitalCountryMap.put("Pretoria", "South Africa"); assertEquals("Berlin", capitalCountryMap.inverse().get("Germany")); }
Example 9
Source File: TargetHashFileParser.java From buck with Apache License 2.0 | 5 votes |
/** * Parses the output of `buck targets --show-target-hash` from a filename * * @param filename The file to parse * @return A parsed targets file * @throws ParseException If the file could not be read, is malformed, or has duplicate * information within it */ public ParsedTargetsFile parseFile(Path filename) throws ParseException { long startNanos = System.nanoTime(); try (BufferedReader fileReader = Files.newBufferedReader(filename)) { int expectedSize = Math.toIntExact(Files.size(filename) / 150); HashBiMap<String, String> targetsToHash = HashBiMap.create(expectedSize); while (fileReader.ready()) { String line = fileReader.readLine(); String[] parts = line.split(" "); if (parts.length != 2) { throw new ParseException( filename, "Lines must be of the format 'TARGET HASH'. Got %s", line); } if (targetsToHash.containsKey(parts[0])) { throw new ParseException(filename, "Target %s has been seen multiple times", parts[0]); } if (targetsToHash.containsValue(parts[1])) { throw new ParseException( filename, "Hash collision! Hash %s has been seen for both %s and %s!", parts[1], targetsToHash.inverse().get(parts[1]), parts[0]); } targetsToHash.put(parts[0], parts[1]); } Duration runtime = Duration.ofNanos(System.nanoTime() - startNanos); return new ParsedTargetsFile(filename, targetsToHash, runtime); } catch (IOException e) { throw new ParseException(e, filename, "Error reading file: %s", e.getMessage()); } }
Example 10
Source File: AggregationPipelineQueryNodeTest.java From rya with Apache License 2.0 | 4 votes |
@Test public void testEquals() { final AggregationPipelineQueryNode node1 = new AggregationPipelineQueryNode( collection, new LinkedList<>(), Sets.newHashSet("x", "y"), Sets.newHashSet("x", "y", "opt"), HashBiMap.create()); final AggregationPipelineQueryNode node2 = new AggregationPipelineQueryNode( collection, new LinkedList<>(), Sets.newHashSet("x", "y"), Sets.newHashSet("x", "y", "opt"), HashBiMap.create()); Assert.assertEquals(node1, node2); Assert.assertEquals(node1.hashCode(), node2.hashCode()); final AggregationPipelineQueryNode diff1 = new AggregationPipelineQueryNode( collection, new LinkedList<>(), Sets.newHashSet("x", "y"), Sets.newHashSet("x", "y"), HashBiMap.create()); final AggregationPipelineQueryNode diff2 = new AggregationPipelineQueryNode( collection, Arrays.asList(new Document()), Sets.newHashSet("x", "y"), Sets.newHashSet("x", "y", "opt"), HashBiMap.create()); HashBiMap<String, String> varMapping = HashBiMap.create(); varMapping.put("field-x", "x"); final AggregationPipelineQueryNode diff3 = new AggregationPipelineQueryNode( collection, Arrays.asList(new Document()), Sets.newHashSet("x", "y"), Sets.newHashSet("x", "y", "opt"), varMapping); Assert.assertNotEquals(diff1, node1); Assert.assertNotEquals(diff2, node1); Assert.assertNotEquals(diff3, node1); node1.joinWith(new StatementPattern(new Var("x"), constant(TAKES), new Var("c"))); node2.joinWith(new StatementPattern(new Var("x"), constant(TAKES), new Var("c"))); Assert.assertEquals(node1, node2); node2.joinWith(new StatementPattern(new Var("x"), constant(TAKES), new Var("c"))); Assert.assertNotEquals(node1, node2); }