List of usage examples for com.google.common.collect HashBiMap create
public static <K, V> HashBiMap<K, V> create()
From source file:uk.ac.ebi.mdk.domain.matrix.StoichiometricMatrixImpl.java
/** * Assigns the values and sets all reactions reversibility to that present * in the 'other' matrix//from w w w .jav a 2s. c o m * * @param other * * @return */ public BiMap<Integer, Integer> assign(StoichiometricMatrix<? extends M, ? extends R> other) { // ensure there is enough space this.ensure(getMoleculeCount() + other.getReactionCount(), getReactionCount() + other.getReactionCount()); BiMap<Integer, Integer> map = HashBiMap.create(); /** * Need whole loop as the called to this addReaction(R,M[],T[]) will set * reversible to true (default) leading to clash on checking for * duplicate reactions */ for (int j = 0; j < other.getReactionCount(); j++) { map.put(j, this.addReaction(other.getReaction(j), other.getReactionMolecules(j), other.getReactionValues(j), other.isReversible(j))); } return map; }
From source file:net.automatalib.serialization.etf.writer.Mealy2ETFWriterAlternating.java
private <S, T> void writeETFInternal(PrintWriter pw, MealyMachine<S, I, T, O> mealy, Alphabet<I> inputs) { // create a bi-mapping from states to integers final BiMap<S, Integer> oldStates = HashBiMap.create(); mealy.getStates().forEach(s -> oldStates.put(s, oldStates.size())); // write the initial state, using the bi-map pw.println("begin init"); pw.printf("%d%n", oldStates.get(mealy.getInitialState())); pw.println("end init"); // create a bi-map for transitions containing output final BiMap<Pair<O, S>, Integer> outputTransitions = HashBiMap.create(); // create a bi-map that maps output to integers final BiMap<O, Integer> outputIndices = HashBiMap.create(); /*//from ww w .ja va 2s. c o m Write the transitions (here is where the horror begins). The key to writing transitions with alternating semantics is that one have of see if appropriate intermediate states, and output transitions have already been created. If this is the case, that state, and output transitions has to be reused. */ pw.println("begin trans"); for (S s : mealy.getStates()) { for (I i : inputs) { T t = mealy.getTransition(s, i); if (t != null) { final S n = mealy.getSuccessor(t); final O o = mealy.getTransitionOutput(t); // construct a triple that serves as a key in the outputTransitions bi-map final Pair<O, S> outputTransition = Pair.of(o, n); // compute the integer value of the intermediate state (this may be a new state) final Integer intermediateState = outputTransitions.computeIfAbsent(outputTransition, ii -> { // the output may also be a new letter in the alphabet. final Integer outputIndex = outputIndices.computeIfAbsent(o, iii -> inputs.size() + outputIndices.size()); /* Write the output transition. Note that this will only be done if the output transition was not written before. */ final Integer res = oldStates.size() + outputTransitions.size(); pw.printf("%d/%d %d%n", res, oldStates.get(n), outputIndex); return res; }); // always write the input transition to the output transition pw.printf("%d/%d %d%n", oldStates.get(s), intermediateState, inputs.getSymbolIndex(i)); } } } pw.println("end trans"); // write all state ids, including the newly created intermediate states pw.println("begin sort id"); for (int i = 0; i < oldStates.size(); i++) { pw.printf("\"%s\"%n", oldStates.inverse().get(i)); } final Map<Integer, Pair<O, S>> inverseTransitions = outputTransitions.inverse(); for (int i = 0; i < outputTransitions.size(); i++) { final Pair<O, S> t = inverseTransitions.get(oldStates.size() + i); pw.printf("\"(%s,%s)\"%n", t.getFirst(), t.getSecond()); } pw.println("end sort"); // write all the letters in the new alphabet pw.println("begin sort letter"); inputs.forEach(i -> pw.printf("\"%s\"%n", i)); for (int i = 0; i < outputIndices.size(); i++) { pw.printf("\"%s\"%n", outputIndices.inverse().get(inputs.size() + i)); } pw.println("end sort"); }
From source file:org.nuxeo.box.api.service.BoxServiceImpl.java
public BoxServiceImpl() { nxBoxRole = HashBiMap.create(); nxBoxRole.put(SecurityConstants.EVERYTHING, BoxCollaborationRole.EDITOR); nxBoxRole.put(SecurityConstants.READ, BoxCollaborationRole.VIEWER); nxBoxRole.put(SecurityConstants.WRITE, BoxCollaborationRole.VIEWER_UPLOADER); }
From source file:com.techcavern.pircbotz.UserChannelDao.java
public UserChannelDao(PircBotZ bot, Configuration.BotFactory botFactory) { this.bot = bot; this.botFactory = botFactory; this.locale = bot.getConfiguration().getLocale(); this.mainMap = new UserChannelMap<U, C>(); this.userNickMap = HashBiMap.create(); this.channelNameMap = HashBiMap.create(); this.privateUsers = new HashSet<U>(); //Initialize levels map with a UserChannelMap for each level this.levelsMap = Maps.newEnumMap(UserLevel.class); for (UserLevel level : UserLevel.values()) levelsMap.put(level, new UserChannelMap<U, C>()); }
From source file:cuchaz.enigma.convert.ClassMatching.java
public BiMap<ClassEntry, ClassEntry> uniqueMatches() { BiMap<ClassEntry, ClassEntry> uniqueMatches = HashBiMap.create(); for (ClassMatch match : matches()) { if (match.isMatched() && !match.isAmbiguous()) { uniqueMatches.put(match.getUniqueSource(), match.getUniqueDest()); }//from ww w . j a v a 2 s . c om } return uniqueMatches; }
From source file:org.diorite.impl.connection.EnumProtocol.java
public synchronized <T extends Packet<?>> void init(final EnumProtocolDirection enumProtocolDirection, final int id, final Class<T> clazz, final Supplier<T> supplier) { BiMap<Integer, Class<?>> create = this.packetsMap.get(enumProtocolDirection); final Int2ObjectMap<Supplier<? extends Packet<?>>> suppMap; if (create == null) { create = HashBiMap.create(); suppMap = new Int2ObjectOpenHashMap<>((this == PLAY) ? PLAY_PACKETS_SIZE : OTHER_PACKETS_SIZE, .1f); this.packetsMap.put(enumProtocolDirection, create); this.packetsSupplierMap.put(enumProtocolDirection, suppMap); } else {//from w w w .j a v a 2s .com suppMap = this.packetsSupplierMap.get(enumProtocolDirection); } if (create.containsValue(clazz)) { throw new IllegalArgumentException( enumProtocolDirection + " packet " + clazz.getName() + " is already known to ID " + Integer.toHexString(create.inverse().get(clazz)) + " (" + create.get(id) + ")"); } if (create.containsKey(id)) { throw new IllegalArgumentException(enumProtocolDirection + " packet (" + clazz.getName() + ") with id " + Integer.toHexString(id) + " is already known to packet " + create.get(id)); } classEnumProtocolMap.put(clazz, this); create.put(id, clazz); suppMap.put(id, supplier); }
From source file:org.datavyu.views.VariableListV.java
/** * Creates new form ListVariablesView.//from w ww .java 2s .c o m * * @param parent The parent frame for this dialog. * @param modal Is this dialog to be modal (true), or not. * @param ds The Datastore containing the variables you wish to list. */ public VariableListV(final java.awt.Frame parent, final boolean modal, final Datastore ds) { super(parent, modal); tableModel = new VListTableModel(); dbToTableMap = HashBiMap.create(); initComponents(); setName(this.getClass().getSimpleName()); datastore = ds; // Set the names of the columns. tableModel.addColumn(rMap.getString("Table.visibleColumn")); tableModel.addColumn(rMap.getString("Table.nameColumn")); tableModel.addColumn(rMap.getString("Table.typeColumn")); //Use JTextfield to edit variable name cells variableList.getColumnModel().getColumn(NCOLUMN).setCellEditor(new DefaultCellEditor(new JTextField())); populateTable(); }
From source file:librec.intf.TagRecommender.java
/** * @param filename/*from w w w.jav a2 s.co m*/ * @param train * ??id ? * @return ? userid,tagid,itemid 2015430?1:20:31 * 2015430 ?1:20:31 */ public static Map<String, Map<String, Set<String>>> readTag(String filename, boolean train) { Map<String, Map<String, Set<String>>> result = new HashMap<String, Map<String, Set<String>>>(); try { List<String> list = FileIO.readAsList(filename); for (String oneline : list) { String[] split = oneline.split("\t"); if (!result.containsKey(split[0])) { Map<String, Set<String>> tempMap = new HashMap<>(); result.put(split[0], tempMap); } if (!result.get(split[0]).containsKey(split[1])) { Set<String> itemstr = new HashSet(); result.get(split[0]).put(split[1], itemstr); } result.get(split[0]).get(split[1]).add(split[2]); if (train) { if (tagids == null) { tagids = HashBiMap.create(); } // inner id starting from 0 int row = tagids.containsKey(split[1]) ? tagids.get(split[1]) : tagids.size(); tagids.put(split[1], row); } else { totalTest++; } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return result; }
From source file:com.temenos.ds.op.xtext.generator.ui.PluginsGeneratorsProvider.java
protected synchronized Iterable<GeneratorIdPair> initGenerators() { Iterable<GeneratorIdPair> result = generatorToId; if (result == null) { if (generatorToId == null) { HashBiMap<String, IGenerator> idToGenerator = HashBiMap.create(); NODslActivator activator = NODslActivator.getInstance(); if (activator != null) { String pluginID = activator.getBundle().getSymbolicName(); GeneratorReader<IGenerator> reader = new GeneratorReader<IGenerator>(extensionRegistry, pluginID, "multigenerator", idToGenerator); reader.readRegistry();/*from ww w . ja v a 2 s. c o m*/ } Builder<GeneratorIdPair> resultBuilder = ImmutableList.builder(); for (Entry<String, IGenerator> entry : idToGenerator.entrySet()) { resultBuilder.add(GeneratorIdPair.of(entry.getValue(), entry.getKey())); } generatorToId = resultBuilder.build(); } } return result; }
From source file:com.facebook.buck.distributed.DistributedBuildTargetGraphCodec.java
public BuildJobStateTargetGraph dump(Collection<TargetNode<?>> targetNodes) throws InterruptedException { BuildJobStateTargetGraph result = new BuildJobStateTargetGraph(); BiMap<Integer, ProjectFilesystem> filesystemIndex = HashBiMap.create(); for (TargetNode<?> targetNode : targetNodes) { Map<String, Object> rawTargetNode = nodeToRawNode.apply(targetNode); ProjectFilesystem projectFilesystem = targetNode.getRuleFactoryParams().getProjectFilesystem(); BuildJobStateTargetNode remoteNode = new BuildJobStateTargetNode(); remoteNode.setFileSystemRootIndex(getIndex(projectFilesystem, filesystemIndex)); remoteNode.setBuildTarget(encodeBuildTarget(targetNode.getBuildTarget())); try {/*w w w .ja v a2 s . c o m*/ remoteNode.setRawNode(objectMapper.writeValueAsString(rawTargetNode)); } catch (JsonProcessingException e) { throw new RuntimeException(e); } result.addToNodes(remoteNode); } result.setFileSystemRoots(Maps.transformValues(filesystemIndex, new Function<ProjectFilesystem, String>() { @Override public String apply(ProjectFilesystem input) { return input.getRootPath().toString(); } })); return result; }