List of usage examples for com.google.common.collect ImmutableTable of
@SuppressWarnings("unchecked") public static <R, C, V> ImmutableTable<R, C, V> of()
From source file:org.lanternpowered.server.block.state.LanternBlockStateMap.java
@SuppressWarnings("rawtypes") public LanternBlockStateMap(LanternBlockType blockType, Iterable<BlockTrait<?>> blockTraits) { this.blockType = blockType; // There are no block traits if (!blockTraits.iterator().hasNext()) { final LanternBlockState blockState = new LanternBlockState(this, ImmutableMap.of()); blockState.propertyValueTable = ImmutableTable.of(); this.blockStates = ImmutableList.of(blockState); this.blockTraits = ImmutableMap.of(); this.keys = ImmutableSet.of(); return;/* w w w. j av a2 s . c o m*/ } // Convert to a list so it can be sorted final List<BlockTrait<?>> list = Lists.newArrayList(blockTraits); // Sort the traits by the name list.sort(Comparator.comparing(BlockTrait::getName)); // The builder for the name to trait lookup final ImmutableMap.Builder<String, BlockTrait<?>> builder = ImmutableMap.builder(); final ImmutableSet.Builder<Key<?>> keys = ImmutableSet.builder(); // All the sets with all the allowed values final List<Set<Comparable<?>>> allowedValues = new ArrayList<>(); for (BlockTrait<?> trait : list) { allowedValues.add(new HashSet<>(trait.getPossibleValues())); keys.add(((LanternBlockTrait) trait).getKey()); builder.put(trait.getName(), trait); } // Build the lookups this.blockTraits = builder.build(); this.keys = keys.build(); // A map with as the key the trait values map and as value the state final LinkedHashMap<Map<?, ?>, BlockState> stateByValuesMap = new LinkedHashMap<>(); // The block states final ImmutableList.Builder<BlockState> blockStates = ImmutableList.builder(); // Do the cartesian product to get all the possible combinations for (List<Comparable<?>> comparables : Sets.cartesianProduct(allowedValues)) { final Iterator<Comparable<?>> objectsIt = comparables.iterator(); final ImmutableMap.Builder<BlockTrait<?>, Comparable<?>> traitValuesBuilder = ImmutableMap.builder(); for (BlockTrait<?> trait : list) { traitValuesBuilder.put(trait, objectsIt.next()); } final ImmutableMap<BlockTrait<?>, Comparable<?>> traitValues = traitValuesBuilder.build(); final LanternBlockState blockState = new LanternBlockState(this, traitValues); stateByValuesMap.put(traitValues, blockState); blockStates.add(blockState); } this.blockStates = blockStates.build(); this.blockStates.stream().map(state -> (LanternBlockState) state).forEach(state -> { final ImmutableTable.Builder<BlockTrait<?>, Comparable<?>, BlockState> tableBuilder = ImmutableTable .builder(); list.forEach(trait -> trait.getPossibleValues().stream() .filter(value -> value != state.getTraitValue(trait).get()).forEach(value -> { final Map<BlockTrait<?>, Comparable<?>> valueByTrait = new HashMap<>(); valueByTrait.putAll(state.traitValues); valueByTrait.put(trait, value); tableBuilder.put(trait, value, stateByValuesMap.get(valueByTrait)); })); state.propertyValueTable = tableBuilder.build(); }); int internalId = 0; for (BlockState blockState : this.blockStates) { final LanternBlockState blockState1 = (LanternBlockState) blockState; blockState1.extended = blockType.getExtendedBlockStateProvider().remove(blockState) != blockState; blockState1.internalId = internalId++; } }
From source file:com.android.tools.idea.uibuilder.property.NlProperties.java
@NotNull public Table<String, String, NlPropertyItem> getProperties(@NotNull List<NlComponent> components) { AndroidFacet facet = getFacet(components); if (facet == null) { return ImmutableTable.of(); }/*from w w w .ja va 2 s .com*/ GradleDependencyManager dependencyManager = GradleDependencyManager .getInstance(facet.getModule().getProject()); return getProperties(facet, components, dependencyManager); }
From source file:net.minecrell.quartz.launch.mappings.Mappings.java
protected Mappings(List<ClassNode> mappingClasses) { requireNonNull(mappingClasses, "mappingClasses"); if (mappingClasses.isEmpty()) { this.classes = ImmutableBiMap.of(); this.methods = ImmutableTable.of(); this.fields = ImmutableTable.of(); this.constructors = ImmutableMultimap.of(); this.accessMappings = ImmutableTable.of(); return;//from ww w. jav a2 s. co m } ImmutableBiMap.Builder<String, String> classes = ImmutableBiMap.builder(); for (ClassNode classNode : mappingClasses) { ParsedAnnotation annotation = MappingsParser.getAnnotation(classNode, MAPPING); checkState(annotation != null, "Class %s is missing the @Mapping annotation", classNode.name); String mapping = annotation.getString("value", ""); if (!mapping.isEmpty()) { classes.put(mapping, classNode.name); } } this.classes = classes.build(); // We need to remap the descriptors of the fields and methods, use ASM for convenience Remapper remapper = new Remapper() { @Override public String map(String className) { return unmap(className); } }; // Load field, method and access mappings ImmutableTable.Builder<String, String, String> methods = ImmutableTable.builder(); ImmutableTable.Builder<String, String, String> fields = ImmutableTable.builder(); ImmutableMultimap.Builder<String, MethodNode> constructors = ImmutableMultimap.builder(); ImmutableTable.Builder<String, String, AccessMapping> accessMappings = ImmutableTable.builder(); for (ClassNode classNode : mappingClasses) { String className = classNode.name.replace('/', '.'); String internalName = unmap(classNode.name); ParsedAnnotation annotation = MappingsParser.getAnnotation(classNode, ACCESSIBLE); if (annotation != null) { accessMappings.put(className, "", AccessMapping.of(classNode)); } for (MethodNode methodNode : classNode.methods) { Map<String, ParsedAnnotation> annotations = MappingsParser.getAnnotations(methodNode); annotation = annotations.get(CONSTRUCTOR); if (annotation != null) { // Generate constructor call code Methods.visitConstructor(methodNode, classNode.name); constructors.put(className, methodNode); continue; } // TODO: Validation annotation = annotations.get(MAPPING); if (annotation != null) { String mapping = annotation.getString("value", ""); if (!mapping.isEmpty()) { methods.put(internalName, mapping + remapper.mapMethodDesc(methodNode.desc), methodNode.name); } } annotation = annotations.get(ACCESSIBLE); if (annotation != null) { accessMappings.put(className, methodNode.name + methodNode.desc, AccessMapping.of(methodNode)); } } for (FieldNode fieldNode : classNode.fields) { Map<String, ParsedAnnotation> annotations = MappingsParser.getAnnotations(fieldNode); // TODO: Validation annotation = annotations.get(MAPPING); if (annotation != null) { String mapping = annotation.getString("value", ""); if (!mapping.isEmpty()) { fields.put(internalName, mapping + ':' + remapper.mapDesc(fieldNode.desc), fieldNode.name); } } annotation = annotations.get(ACCESSIBLE); if (annotation != null) { accessMappings.put(className, fieldNode.name, AccessMapping.of(fieldNode)); } } } this.methods = methods.build(); this.fields = fields.build(); this.constructors = constructors.build(); this.accessMappings = accessMappings.build(); }
From source file:com.android.tools.idea.uibuilder.property.NlProperties.java
@NotNull private Table<String, String, NlPropertyItem> getPropertiesWithReadLock(@NotNull AndroidFacet facet, @NotNull List<NlComponent> components, @NotNull GradleDependencyManager dependencyManager) { ResourceManager localResourceManager = facet.getLocalResourceManager(); ResourceManager systemResourceManager = facet.getSystemResourceManager(); if (systemResourceManager == null) { Logger.getInstance(NlProperties.class) .error("No system resource manager for module: " + facet.getModule().getName()); return ImmutableTable.of(); }/*from w w w .ja v a 2 s .c om*/ AttributeDefinitions localAttrDefs = localResourceManager.getAttributeDefinitions(); AttributeDefinitions systemAttrDefs = systemResourceManager.getAttributeDefinitions(); Table<String, String, NlPropertyItem> combinedProperties = null; for (NlComponent component : components) { XmlTag tag = component.getTag(); if (!tag.isValid()) { return ImmutableTable.of(); } XmlElementDescriptor elementDescriptor = myDescriptorProvider.getDescriptor(tag); if (elementDescriptor == null) { return ImmutableTable.of(); } XmlAttributeDescriptor[] descriptors = elementDescriptor.getAttributesDescriptors(tag); Table<String, String, NlPropertyItem> properties = HashBasedTable.create(3, descriptors.length); for (XmlAttributeDescriptor desc : descriptors) { String namespace = getNamespace(desc, tag); AttributeDefinitions attrDefs = NS_RESOURCES.equals(namespace) ? systemAttrDefs : localAttrDefs; AttributeDefinition attrDef = attrDefs == null ? null : attrDefs.getAttrDefByName(desc.getName()); NlPropertyItem property = NlPropertyItem.create(components, desc, namespace, attrDef); properties.put(StringUtil.notNullize(namespace), property.getName(), property); } // Exceptions: switch (tag.getName()) { case AUTO_COMPLETE_TEXT_VIEW: // An AutoCompleteTextView has a popup that is created at runtime. // Properties for this popup can be added to the AutoCompleteTextView tag. properties.put(ANDROID_URI, ATTR_POPUP_BACKGROUND, NlPropertyItem.create(components, new AndroidAnyAttributeDescriptor(ATTR_POPUP_BACKGROUND), ANDROID_URI, systemAttrDefs != null ? systemAttrDefs.getAttrDefByName(ATTR_POPUP_BACKGROUND) : null)); break; } combinedProperties = combine(properties, combinedProperties); } // The following properties are deprecated in the support library and can be ignored by tools: assert combinedProperties != null; combinedProperties.remove(AUTO_URI, ATTR_PADDING_START); combinedProperties.remove(AUTO_URI, ATTR_PADDING_END); combinedProperties.remove(AUTO_URI, ATTR_THEME); setUpDesignProperties(combinedProperties); setUpSrcCompat(combinedProperties, facet, components, dependencyManager); initStarState(combinedProperties); //noinspection ConstantConditions return combinedProperties; }
From source file:com.android.tools.idea.uibuilder.property.NlPropertiesManager.java
private void setSelectedComponents(@NotNull List<NlComponent> components, @Nullable Runnable postUpdateRunnable) { // Obtaining the properties, especially the first time around on a big project // can take close to a second, so we do it on a separate thread.. ApplicationManager.getApplication().executeOnPooledThread(() -> { Table<String, String, NlPropertyItem> properties = !components.isEmpty() ? NlProperties.getInstance().getProperties(components) : ImmutableTable.of(); UIUtil.invokeLaterIfNeeded(() -> { if (myProject.isDisposed()) { return; }//from w ww . jav a 2 s . c o m myPropertiesPanel.setItems(components, properties, this); if (postUpdateRunnable != null) { myLoading = false; postUpdateRunnable.run(); } }); }); }
From source file:edu.mit.streamjit.impl.common.AbstractDrainer.java
/** * @return Aggregated DrainData after the draining. *///from w w w . java2 s .c om public final DrainData getDrainData() { DrainData drainData = null; Map<Token, ImmutableList<Object>> boundaryInputData = new HashMap<>(); Map<Token, ImmutableList<Object>> boundaryOutputData = new HashMap<>(); for (BlobNode node : blobGraph.blobNodes.values()) { boundaryInputData.putAll(node.drainData.inputData); boundaryOutputData.putAll(node.drainData.outputData); if (drainData == null) drainData = node.drainData.drainData; else drainData = drainData.merge(node.drainData.drainData); } ImmutableMap.Builder<Token, ImmutableList<Object>> dataBuilder = ImmutableMap.builder(); for (Token t : Sets.union(boundaryInputData.keySet(), boundaryOutputData.keySet())) { ImmutableList<Object> in = boundaryInputData.get(t) != null ? boundaryInputData.get(t) : ImmutableList.of(); ImmutableList<Object> out = boundaryOutputData.get(t) != null ? boundaryOutputData.get(t) : ImmutableList.of(); dataBuilder.put(t, ImmutableList.builder().addAll(in).addAll(out).build()); } ImmutableTable<Integer, String, Object> state = ImmutableTable.of(); DrainData draindata1 = new DrainData(dataBuilder.build(), state); drainData = drainData.merge(draindata1); if (drainDataStatistics == null) { drainDataStatistics = new HashMap<>(); for (Token t : drainData.getData().keySet()) { drainDataStatistics.put(t, new ArrayList<Integer>()); } } for (Token t : drainData.getData().keySet()) { // System.out.print("Aggregated data: " + t.toString() + " - " // + drainData.getData().get(t).size() + " - "); // for (Object o : drainData.getData().get(t)) { // System.out.print(o.toString() + ", "); // } // System.out.print('\n'); drainDataStatistics.get(t).add(drainData.getData().get(t).size()); } return drainData; }