Example usage for com.google.common.collect HashBiMap create

List of usage examples for com.google.common.collect HashBiMap create

Introduction

In this page you can find the example usage for com.google.common.collect HashBiMap create.

Prototype

public static <K, V> HashBiMap<K, V> create() 

Source Link

Document

Returns a new, empty HashBiMap with the default initial capacity (16).

Usage

From source file:org.killbill.billing.plugin.meter.timeline.persistent.DefaultTimelineDao.java

@Override
public BiMap<Integer, String> getEventCategories(final TenantContext context)
        throws UnableToObtainConnectionException, CallbackFailedException {
    final HashBiMap<Integer, String> accumulator = HashBiMap.create();
    for (final Map<String, Object> eventCategory : delegate
            .getCategories(createInternalTenantContext(context))) {
        accumulator.put(Integer.valueOf(eventCategory.get("record_id").toString()),
                eventCategory.get("category").toString());
    }/*w  ww.j  av  a 2  s  .  co m*/
    return accumulator;
}

From source file:org.charvolant.dossier.Generator.java

/**
 * Create a generator for a configuration.
 *
 * @param configuration The configuration
 *///from  ww w .  ja va 2s. co  m
public Generator(Configuration configuration) {
    super();
    this.configuration = configuration;
    this.languageOrder = this.chooseLanguageOrder();
    this.ids = HashBiMap.create();
}

From source file:org.eclipse.elk.graphviz.dot.transform.DotExporter.java

/**
 * Transforms the KGraph instance to a Dot instance using the given command.
 * /*from  w  w w.  j  a  v a2s. co m*/
 * @param transData the transformation data instance
 */
public void transform(final IDotTransformationData<KNode, GraphvizModel> transData) {
    BiMap<String, KGraphElement> graphElems = HashBiMap.create();
    transData.setProperty(GRAPH_ELEMS, graphElems);
    KNode kgraph = transData.getSourceGraph();
    GraphvizModel graphvizModel = DotFactory.eINSTANCE.createGraphvizModel();
    Graph graph = DotFactory.eINSTANCE.createGraph();
    graph.setType(GraphType.DIGRAPH);
    graphvizModel.getGraphs().add(graph);
    Command command = transData.getProperty(COMMAND);
    boolean layoutHierarchy = transData.getProperty(FULL_EXPORT)
            || kgraph.getData(KShapeLayout.class).getProperty(LayoutOptions.LAYOUT_HIERARCHY)
                    && (command == Command.DOT || command == Command.FDP);
    transformNodes(kgraph, graph.getStatements(), layoutHierarchy, new KVector(), transData);
    transformEdges(kgraph, graph.getStatements(), layoutHierarchy, transData);
    transData.getTargetGraphs().add(graphvizModel);
}

From source file:org.ldp4j.application.lifecycle.EnvironmentImpl.java

private BiMap<ResourceId, String> getRootResourceMap() throws ApplicationConfigurationException {
    BiMap<ResourceId, String> rootResourceMap = HashBiMap.create();
    for (RootResource candidateResource : this.candidates) {
        addPublication(rootResourceMap, candidateResource);
    }//  w w w  . j av a  2s .c  o  m
    return rootResourceMap;
}

From source file:it.sayservice.platform.smartplanner.cache.AgencyCacheIndex.java

private CompressedCalendar compressCalendar(Map<String, String> cal) {
    CompressedCalendar ccal = new CompressedCalendar();
    int i = 0;//  w ww  . j  a v a2 s  .  c  o  m
    Map<String, String> days = new TreeMap<String, String>();
    BiMap<String, String> map = HashBiMap.create();

    for (String key : cal.keySet()) {
        String value = cal.get(key);
        if (!map.containsKey(value)) {
            map.put(value, "" + i++);
        }
        days.put(key, map.get(value));
    }

    ccal.setEntries(days);
    ccal.setMapping(map.inverse());

    return ccal;
}

From source file:org.sonar.java.resolve.Symbols.java

public Symbols(BytecodeCompleter bytecodeCompleter) {
    defaultPackage = new JavaSymbol.PackageJavaSymbol("", rootPackage);

    predefClass = new JavaSymbol.TypeJavaSymbol(Flags.PUBLIC, "", rootPackage);
    predefClass.members = new Scope(predefClass);
    ((ClassJavaType) predefClass.type).interfaces = ImmutableList.of();

    // TODO should have type "noType":
    noSymbol = new JavaSymbol.TypeJavaSymbol(0, "", rootPackage);

    methodClass = new JavaSymbol.TypeJavaSymbol(Flags.PUBLIC, "", noSymbol);

    // builtin types
    byteType = initType(JavaType.BYTE, "byte");
    charType = initType(JavaType.CHAR, "char");
    shortType = initType(JavaType.SHORT, "short");
    intType = initType(JavaType.INT, "int");
    longType = initType(JavaType.LONG, "long");
    floatType = initType(JavaType.FLOAT, "float");
    doubleType = initType(JavaType.DOUBLE, "double");
    booleanType = initType(JavaType.BOOLEAN, "boolean");
    nullType = initType(JavaType.BOT, "<nulltype>");
    voidType = initType(JavaType.VOID, "void");

    bytecodeCompleter.init(this);

    // predefined types for java lang
    JavaSymbol.PackageJavaSymbol javalang = bytecodeCompleter.enterPackage("java.lang");
    // define a star import scope to let resolve types to java.lang when needed.
    javalang.members = new Scope.StarImportScope(javalang, bytecodeCompleter);
    javalang.members.enter(javalang);// w w  w  . j av  a  2s . c o m

    objectType = bytecodeCompleter.loadClass("java.lang.Object").type;
    classType = bytecodeCompleter.loadClass("java.lang.Class").type;
    stringType = bytecodeCompleter.loadClass("java.lang.String").type;
    cloneableType = bytecodeCompleter.loadClass("java.lang.Cloneable").type;
    serializableType = bytecodeCompleter.loadClass("java.io.Serializable").type;
    annotationType = bytecodeCompleter.loadClass("java.lang.annotation.Annotation").type;
    enumType = bytecodeCompleter.loadClass("java.lang.Enum").type;

    unboundedWildcard = new WildCardType(objectType, WildCardType.BoundType.UNBOUNDED);

    // Associate boxed types
    boxedTypes = HashBiMap.create();
    boxedTypes.put(byteType, bytecodeCompleter.loadClass("java.lang.Byte").type);
    boxedTypes.put(charType, bytecodeCompleter.loadClass("java.lang.Character").type);
    boxedTypes.put(shortType, bytecodeCompleter.loadClass("java.lang.Short").type);
    boxedTypes.put(intType, bytecodeCompleter.loadClass("java.lang.Integer").type);
    boxedTypes.put(longType, bytecodeCompleter.loadClass("java.lang.Long").type);
    boxedTypes.put(floatType, bytecodeCompleter.loadClass("java.lang.Float").type);
    boxedTypes.put(doubleType, bytecodeCompleter.loadClass("java.lang.Double").type);
    boxedTypes.put(booleanType, bytecodeCompleter.loadClass("java.lang.Boolean").type);

    for (Entry<JavaType, JavaType> entry : boxedTypes.entrySet()) {
        entry.getKey().primitiveWrapperType = entry.getValue();
        entry.getValue().primitiveType = entry.getKey();
    }

    // TODO comment me
    arrayClass = new JavaSymbol.TypeJavaSymbol(Flags.PUBLIC, "Array", noSymbol);
    ClassJavaType arrayClassType = (ClassJavaType) arrayClass.type;
    arrayClassType.supertype = objectType;
    arrayClassType.interfaces = ImmutableList.of(cloneableType, serializableType);
    arrayClass.members = new Scope(arrayClass);
    arrayClass.members().enter(
            new JavaSymbol.VariableJavaSymbol(Flags.PUBLIC | Flags.FINAL, "length", intType, arrayClass));
    // TODO arrayClass implements clone() method

    // java.lang.Synthetic is a virtual annotation added by ASM to workaround a bug in javac on inner classes parameter numbers.
    // Predefining this type avoids to look it up in classpath where it will not be found. We rely on this to detect synthetic parameters on some enum constructor for instance.
    JavaSymbol.TypeJavaSymbol syntheticAnnotation = new JavaSymbol.TypeJavaSymbol(
            Flags.PUBLIC | Flags.ANNOTATION, "Synthetic", javalang);
    javalang.members.enter(syntheticAnnotation);
    bytecodeCompleter.registerClass(syntheticAnnotation);
    enterOperators();
}

From source file:net.sourcedestination.sai.comparison.matching.MatchingGenerator.java

/** given a matching of nodes, extends the matching to pair up all edges which
 * have isomorphically matched incident nodes. In the case of a multigraph, 
 * edges are matched arbitrarily.//from www .jav a2 s  .c om
 * 
 * @param nodeMatching
 * @param fscc
 * @return
 */
public static GraphMatching induceEdgeMatching(GraphMatching nodeMatching,
        FeatureSetCompatibilityChecker fscc) {

    // if they're not directed, we need to treat edge compatibility differently:
    if (nodeMatching.getGraph1().getFeatures().anyMatch(f -> f.equals(DIRECTED))
            && nodeMatching.getGraph2().getFeatures().anyMatch(f -> f.equals(DIRECTED)))
        return induceEdgeMatchingUndirected(nodeMatching, fscc);

    final Graph g1 = nodeMatching.getGraph1();
    final Graph g2 = nodeMatching.getGraph2();
    BiMap<Integer, Integer> edgeMatch = HashBiMap.create();

    Multimap<Pair<Integer>, Integer> g2Edges = HashMultimap.create();
    g2.getEdgeIDs().forEach(
            g2e -> g2Edges.put(Pair.makePair(g2.getEdgeSourceNodeID(g2e), g2.getEdgeTargetNodeID(g2e)), g2e));

    g1.getEdgeIDs().forEach(eid -> {
        int g1n1 = g1.getEdgeSourceNodeID(eid);
        int g1n2 = g1.getEdgeTargetNodeID(eid);
        int g2n1 = nodeMatching.getMatchedNodeInGraph2(g1n1);
        int g2n2 = nodeMatching.getMatchedNodeInGraph2(g1n2);
        if (g2n1 == -1 || g2n2 == -1)
            return; //skip edges with unmapped nodes in graph 2      

        if (g2Edges.get(Pair.makePair(g2n1, g2n2)).size() == 0)
            return; //skip if it can't be matched to a graph 2 edge

        int g2MatchedEdge = -1; // make sure the edges are compatible
        for (int g2e : g2Edges.get(Pair.makePair(g2n1, g2n2)))
            if (fscc.apply(g1.getEdgeFeatures(eid).collect(toSet()), g2.getEdgeFeatures(g2e).collect(toSet())))
                g2MatchedEdge = g2e;

        if (g2MatchedEdge != -1) //if we found a match, record it
            edgeMatch.put(eid, g2MatchedEdge);
    });
    return includeEdgeMatching(nodeMatching, edgeMatch);
}

From source file:com.github.jsdossier.jscomp.NodeLibrary.java

private static ExternCollection loadDirectory(Path directory) throws IOException {
    log.fine("Loading node core library externs from " + directory);

    final Set<String> externIds = new HashSet<>();
    final List<SourceFile> externFiles = new ArrayList<>();
    final Map<String, SourceFile> modulesByPath = new HashMap<>();
    final BiMap<String, String> modulePathsById = HashBiMap.create();

    Files.walkFileTree(directory, new FileVisitor<Path>() {
        @Override//from   www  .j  a v  a  2s  . c  om
        public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            if (file.getFileName().toString().endsWith(".js")) {
                String id = toSafeName(getNameWithoutExtension(file.getFileName().toString()));
                if ("globals".equals(id)) {
                    externFiles.add(SourceFile.fromInputStream(FILE_NAME_PREFIX + file.getFileName(),
                            Files.newInputStream(file), UTF_8));
                } else {
                    externIds.add(id);

                    SourceFile source = loadSource(file, true);
                    modulesByPath.put(source.getName(), source);
                    modulePathsById.put(id, source.getName());
                }
            }
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFileFailed(Path file, IOException exc) {
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
            return FileVisitResult.CONTINUE;
        }
    });

    return new ExternCollection(ImmutableSet.copyOf(externIds), ImmutableList.copyOf(externFiles),
            ImmutableMap.copyOf(modulesByPath), ImmutableMap.copyOf(modulePathsById.inverse()));
}

From source file:com.zimbra.cs.account.callback.CheckPortConflict.java

private void checkConfig(Config config, Map<String, Object> configAttrsToModify) throws ServiceException {
    BiMap<String, String> newDefaults = HashBiMap.create();

    /*//from w w w. j  a v  a 2s  . co m
     * First, make sure there is no conflict in the Config entry, even
     * if the value on the config entry might not be effective on a server.
     */
    for (String attrName : sPortAttrs) {
        if (!configAttrsToModify.containsKey(attrName))
            newDefaults.put(config.getAttr(attrName), attrName);
    }

    // check conflict for attrs being changed
    for (Map.Entry<String, Object> attrToModify : configAttrsToModify.entrySet()) {
        String attrName = attrToModify.getKey();

        if (!sPortAttrs.contains(attrName))
            continue;

        SingleValueMod mod = singleValueMod(configAttrsToModify, attrName);
        String newValue = null;
        if (mod.setting())
            newValue = mod.value();

        if (conflict(null, newDefaults, newValue, attrName)) {
            throw ServiceException.INVALID_REQUEST("port " + newValue + " conflict between " + attrName
                    + " and " + newDefaults.get(newValue) + " on global config", null);
        } else
            newDefaults.put(newValue, attrName);
    }

    /*
     * Then, iterate through all servers see if this port change on the Config
     * entry has impact on a server.
     */
    List<Server> servers = Provisioning.getInstance().getAllServers();
    for (Server server : servers) {
        checkServerWithNewDefaults(server, newDefaults, configAttrsToModify);
    }
}

From source file:de.bund.bfr.knime.pmmlite.io.modelcreator.ModelCreatorNodeDialog.java

private JPanel createConfigPanel(ModelFormula formula) {
    idField = new StringTextField(false, 20);
    idField.setValue(set.getId());//from w ww.j av  a  2  s  . c  o m
    organismField = new StringTextField(true, 20);
    organismField.setValue(set.getOrganism());
    matrixField = new StringTextField(true, 20);
    matrixField.setValue(set.getMatrix());
    paramFields = HashBiMap.create();
    conditions = mapToConditions(set.getConditions());
    conditionsList = new JList<>(new Vector<>(conditions));
    conditionsList.setCellRenderer(new ConditionListCellRenderer());
    unitTable = new UnitTable<>(new ArrayList<>(0));
    unitTable.getColumn(UnitTable.UNIT_COLUMN).getCellEditor().addCellEditorListener(this);
    updateUnitTable();
    addButton = new JButton("Add");
    addButton.addActionListener(this);
    removeButton = new JButton("Remove");
    removeButton.addActionListener(this);

    JPanel mandatoryPanel = new JPanel();

    mandatoryPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    mandatoryPanel.setLayout(new BoxLayout(mandatoryPanel, BoxLayout.X_AXIS));
    mandatoryPanel.add(new JLabel(PmmUtils.DATA + ":"));
    mandatoryPanel.add(idField);

    JPanel optionalPanel = new JPanel();

    optionalPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    optionalPanel.setLayout(new BoxLayout(optionalPanel, BoxLayout.X_AXIS));
    optionalPanel.add(new JLabel(PmmUtils.ORGANISM + ":"));
    optionalPanel.add(organismField);
    optionalPanel.add(Box.createHorizontalStrut(5));
    optionalPanel.add(new JLabel(PmmUtils.MATRIX_TYPE + ":"));
    optionalPanel.add(matrixField);

    JPanel paramPanel = new JPanel();

    paramPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    paramPanel.setLayout(new BoxLayout(paramPanel, BoxLayout.X_AXIS));

    for (Parameter param : formula.getParams()) {
        DoubleTextField field = new DoubleTextField(false, 5);

        field.setValue(set.getParameters().get(param.getName()));
        paramPanel.add(Box.createHorizontalStrut(5));
        paramPanel.add(new JLabel(param.getName() + ":"));
        paramPanel.add(field);
        paramFields.put(param.getName(), field);
    }

    JPanel buttonPanel = new JPanel();

    buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    buttonPanel.add(addButton);
    buttonPanel.add(Box.createRigidArea(new Dimension(5, 0)));
    buttonPanel.add(removeButton);

    JPanel panel = new JPanel();

    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.add(UI.createTitledPanel(UI.createWestPanel(mandatoryPanel), "Mandatory Columns"));
    panel.add(UI.createTitledPanel(UI.createWestPanel(optionalPanel), "Optional Columns"));
    panel.add(UI.createTitledPanel(UI.createWestPanel(paramPanel), "Parameter Columns"));

    if (formula instanceof PrimaryModelFormula) {
        JPanel conditionsPanel = new JPanel();

        conditionsPanel.setBorder(BorderFactory.createTitledBorder("Conditions"));
        conditionsPanel.setLayout(new BorderLayout());
        conditionsPanel.add(buttonPanel, BorderLayout.NORTH);
        conditionsPanel.add(new JScrollPane(conditionsList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);

        JPanel unitPanel = new JPanel();

        unitPanel.setBorder(BorderFactory.createTitledBorder("Units"));
        unitPanel.setLayout(new BorderLayout());
        unitPanel.add(UI.createTablePanel(unitTable), BorderLayout.CENTER);

        JPanel splitPanel = new JPanel();

        splitPanel.setLayout(new BorderLayout());
        splitPanel.add(conditionsPanel, BorderLayout.WEST);
        splitPanel.add(unitPanel, BorderLayout.CENTER);

        panel.add(splitPanel);
    }

    return panel;
}