List of usage examples for com.google.common.collect BiMap size
int size();
From source file:edu.rit.flick.genetics.ByteConverterBiMapFactory.java
public static void main(final String[] args) { final BiMap<String, Byte> byteConverter = new ByteConverterBiMapFactory().getByteConverter(4); System.out.println(byteConverter.size()); System.out.println("A : " + byteConverter.get("A")); System.out.println("AT : " + byteConverter.get("AT")); System.out.println("TNAG : " + byteConverter.get("TNAG")); }
From source file:com.google.cloud.genomics.dataflow.pipelines.VariantSimilarity.java
public static void main(String[] args) throws IOException, GeneralSecurityException { // Register the options so that they show up via --help PipelineOptionsFactory.register(Options.class); Options options = PipelineOptionsFactory.fromArgs(args).withValidation().as(Options.class); // Option validation is not yet automatic, we make an explicit call here. Options.Methods.validateOptions(options); OfflineAuth auth = GenomicsOptions.Methods.getGenomicsAuth(options); List<String> callSetNames = GenomicsUtils.getCallSetsNames(options.getVariantSetId(), auth); Collections.sort(callSetNames); // Ensure a stable sort order for reproducible results. BiMap<String, Integer> dataIndices = HashBiMap.create(); for (String callSetName : callSetNames) { dataIndices.put(callSetName, dataIndices.size()); }//from w ww . ja v a2s .co m Pipeline p = Pipeline.create(options); p.begin(); PCollection<StreamVariantsRequest> requests; if (null != options.getSitesFilepath()) { // Compute PCA on a list of sites. requests = p.apply(TextIO.Read.named("ReadSites").from(options.getSitesFilepath())) .apply(new SitesToShards.SitesToStreamVariantsShardsTransform(options.getVariantSetId())); } else { List<StreamVariantsRequest> shardRequests = options.isAllReferences() ? ShardUtils.getVariantRequests(options.getVariantSetId(), ShardUtils.SexChromosomeFilter.EXCLUDE_XY, options.getBasesPerShard(), auth) : ShardUtils.getVariantRequests(options.getVariantSetId(), options.getReferences(), options.getBasesPerShard()); requests = p.apply(Create.of(shardRequests)); } requests.apply(new VariantStreamer(auth, ShardBoundary.Requirement.STRICT, VARIANT_FIELDS)) .apply(ParDo.of(new ExtractSimilarCallsets())) .apply(new OutputPCoAFile(dataIndices, options.getOutput())); p.run(); }
From source file:com.facebook.buck.distributed.DistributedBuildTargetGraphCodec.java
private static <T> int getIndex(T value, BiMap<Integer, T> index) { Integer i = index.inverse().get(value); if (i == null) { i = index.size(); index.put(i, value);// w w w . j a v a2 s . c o m } return i; }
From source file:org.apache.druid.indexing.firehose.IngestSegmentFirehoseFactory.java
@VisibleForTesting static List<String> getUniqueDimensions(List<TimelineObjectHolder<String, DataSegment>> timelineSegments, @Nullable Set<String> excludeDimensions) { final BiMap<String, Integer> uniqueDims = HashBiMap.create(); // Here, we try to retain the order of dimensions as they were specified since the order of dimensions may be // optimized for performance. // Dimensions are extracted from the recent segments to olders because recent segments are likely to be queried more // frequently, and thus the performance should be optimized for recent ones rather than old ones. // timelineSegments are sorted in order of interval int index = 0; for (TimelineObjectHolder<String, DataSegment> timelineHolder : Lists.reverse(timelineSegments)) { for (PartitionChunk<DataSegment> chunk : timelineHolder.getObject()) { for (String dimension : chunk.getObject().getDimensions()) { if (!uniqueDims.containsKey(dimension) && (excludeDimensions == null || !excludeDimensions.contains(dimension))) { uniqueDims.put(dimension, index++); }//from w w w .j a v a 2 s. com } } } final BiMap<Integer, String> orderedDims = uniqueDims.inverse(); return IntStream.range(0, orderedDims.size()).mapToObj(orderedDims::get).collect(Collectors.toList()); }
From source file:org.apache.druid.indexing.firehose.IngestSegmentFirehoseFactory.java
@VisibleForTesting static List<String> getUniqueMetrics(List<TimelineObjectHolder<String, DataSegment>> timelineSegments) { final BiMap<String, Integer> uniqueMetrics = HashBiMap.create(); // Here, we try to retain the order of metrics as they were specified. Metrics are extracted from the recent // segments to olders. // timelineSegments are sorted in order of interval int index = 0; for (TimelineObjectHolder<String, DataSegment> timelineHolder : Lists.reverse(timelineSegments)) { for (PartitionChunk<DataSegment> chunk : timelineHolder.getObject()) { for (String metric : chunk.getObject().getMetrics()) { if (!uniqueMetrics.containsKey(metric)) { uniqueMetrics.put(metric, index++); }/* w w w . jav a2 s.c o m*/ } } } final BiMap<Integer, String> orderedMetrics = uniqueMetrics.inverse(); return IntStream.range(0, orderedMetrics.size()).mapToObj(orderedMetrics::get).collect(Collectors.toList()); }
From source file:com.cloudera.oryx.rdf.serving.web.AbstractRDFServlet.java
private static int categoricalFromString(int columnNumber, String value, Map<Integer, BiMap<String, Integer>> columnToCategoryNameToIDMapping) { BiMap<String, Integer> categoryNameToID = columnToCategoryNameToIDMapping.get(columnNumber); if (categoryNameToID == null) { categoryNameToID = HashBiMap.create(); columnToCategoryNameToIDMapping.put(columnNumber, categoryNameToID); }/*from w w w. j av a 2 s. c o m*/ Integer mapped = categoryNameToID.get(value); if (mapped != null) { return mapped; } int newCategory = categoryNameToID.size(); categoryNameToID.put(value, newCategory); return newCategory; }
From source file:io.druid.indexing.common.task.CompactionTask.java
private static DimensionsSpec createDimensionsSpec(List<QueryableIndex> queryableIndices) { final BiMap<String, Integer> uniqueDims = HashBiMap.create(); final Map<String, DimensionSchema> dimensionSchemaMap = new HashMap<>(); // Here, we try to retain the order of dimensions as they were specified since the order of dimensions may be // optimized for performance. // Dimensions are extracted from the recent segments to olders because recent segments are likely to be queried more // frequently, and thus the performance should be optimized for recent ones rather than old ones. // timelineSegments are sorted in order of interval int index = 0; for (QueryableIndex queryableIndex : Lists.reverse(queryableIndices)) { final Map<String, DimensionHandler> dimensionHandlerMap = queryableIndex.getDimensionHandlers(); for (String dimension : queryableIndex.getAvailableDimensions()) { final Column column = Preconditions.checkNotNull(queryableIndex.getColumn(dimension), "Cannot find column for dimension[%s]", dimension); if (!uniqueDims.containsKey(dimension)) { final DimensionHandler dimensionHandler = Preconditions.checkNotNull( dimensionHandlerMap.get(dimension), "Cannot find dimensionHandler for dimension[%s]", dimension);/*from w ww.j av a 2 s . co m*/ uniqueDims.put(dimension, index++); dimensionSchemaMap.put(dimension, createDimensionSchema(column.getCapabilities().getType(), dimension, dimensionHandler.getMultivalueHandling())); } } } final BiMap<Integer, String> orderedDims = uniqueDims.inverse(); final List<DimensionSchema> dimensionSchemas = IntStream.range(0, orderedDims.size()).mapToObj(i -> { final String dimName = orderedDims.get(i); return Preconditions.checkNotNull(dimensionSchemaMap.get(dimName), "Cannot find dimension[%s] from dimensionSchemaMap", dimName); }).collect(Collectors.toList()); return new DimensionsSpec(dimensionSchemas, null, null); }
From source file:com.cloudera.oryx.common.pmml.PMMLUtils.java
public static Map<Integer, BiMap<String, Integer>> buildColumnCategoryMapping(DataDictionary dictionary) { Preconditions.checkNotNull(dictionary); InboundSettings settings = InboundSettings.create(ConfigUtils.getDefaultConfig()); List<String> columnNames = settings.getColumnNames(); Preconditions.checkNotNull(dictionary); Map<Integer, BiMap<String, Integer>> columnToCategoryNameToIDMapping = Maps.newHashMap(); for (TypeDefinitionField field : dictionary.getDataFields()) { Collection<Value> values = field.getValues(); if (values != null && !values.isEmpty()) { String columnName = field.getName().getValue(); int columnNumber = columnNames.indexOf(columnName); BiMap<String, Integer> categoryNameToID = columnToCategoryNameToIDMapping.get(columnNumber); if (categoryNameToID == null) { categoryNameToID = HashBiMap.create(); columnToCategoryNameToIDMapping.put(columnNumber, categoryNameToID); }//from w ww .j ava 2s.c o m for (Value value : values) { categoryNameToID.put(value.getValue(), categoryNameToID.size()); } } } return columnToCategoryNameToIDMapping; }
From source file:com.torodb.torod.db.postgresql.query.QueryStructureFilter.java
public static Multimap<Integer, QueryCriteria> filterStructures(StructuresCache cache, QueryCriteria queryCriteria) throws UndecidableCaseException { Processor.Result processorResult = PROCESSOR.process(queryCriteria); List<ProcessedQueryCriteria> processedQueryCriterias = processorResult.getProcessedQueryCriterias(); ExistRelation existRelation = processorResult.getExistRelation(); BiMap<Integer, DocStructure> allStructures = cache.getAllStructures(); Multimap<Integer, QueryCriteria> result = HashMultimap.create(allStructures.size(), processedQueryCriterias.size()); StructureQueryEvaluator structureQueryEvaluator = new StructureQueryEvaluator(); for (ProcessedQueryCriteria processedQueryCriteria : processedQueryCriterias) { for (Map.Entry<Integer, DocStructure> entry : allStructures.entrySet()) { if (structureConforms(structureQueryEvaluator, entry.getValue(), processedQueryCriteria.getStructureQuery())) { QueryCriteria dataQuery = getDataQuery(processedQueryCriteria, structureQueryEvaluator.getCandidateProvider(), existRelation); result.put(entry.getKey(), dataQuery); LOGGER.debug("Structure {} fulfil structure query {}. Data query: {}", entry.getKey(), processedQueryCriteria.getStructureQuery(), dataQuery); }/*from w w w . jav a 2 s . co m*/ } } return result; }
From source file:org.opencb.opencga.storage.core.metadata.StudyConfiguration.java
public static LinkedHashMap<String, Integer> getReturnedSamplesPosition(StudyConfiguration studyConfiguration, LinkedHashSet<String> returnedSamples, Function<StudyConfiguration, BiMap<String, Integer>> getIndexedSamplesPosition) { LinkedHashMap<String, Integer> samplesPosition; if (returnedSamples == null || returnedSamples.isEmpty()) { BiMap<Integer, String> unorderedSamplesPosition = getIndexedSamplesPosition(studyConfiguration) .inverse();//from w w w. j a v a 2 s . c om samplesPosition = new LinkedHashMap<>(unorderedSamplesPosition.size()); for (int i = 0; i < unorderedSamplesPosition.size(); i++) { samplesPosition.put(unorderedSamplesPosition.get(i), i); } } else { samplesPosition = new LinkedHashMap<>(returnedSamples.size()); int index = 0; BiMap<String, Integer> indexedSamplesId = getIndexedSamplesPosition.apply(studyConfiguration); for (String returnedSample : returnedSamples) { if (!returnedSample.isEmpty() && StringUtils.isNumeric(returnedSample)) { returnedSample = studyConfiguration.getSampleIds().inverse() .get(Integer.parseInt(returnedSample)); } if (!samplesPosition.containsKey(returnedSample)) { if (indexedSamplesId.containsKey(returnedSample)) { samplesPosition.put(returnedSample, index++); } } } // for (String sample : indexedSamplesId.keySet()) { // samplesPosition.put(sample, index++); // } } return samplesPosition; }