List of usage examples for com.google.common.collect BiMap put
@Override @Nullable V put(@Nullable K key, @Nullable V value);
From source file:de.keyle.knbte.Gui.java
@SuppressWarnings("unchecked") public void addToNode(TagBaseNode parent, TagBaseNode newNode) { if (parent instanceof TagCompoundNode) { TagCompoundNode node = (TagCompoundNode) parent; int i = 1; while (true) { if (node.getNodeByKey("property" + i) == null) { break; }/*from w w w. ja v a 2 s .c om*/ i++; } BiMap<String, TagBaseNode> key2Node = (BiMap<String, TagBaseNode>) node.getData(); key2Node.put("property" + i, newNode); node.add(newNode); } else if (parent instanceof TagListNode) { TagListNode list = (TagListNode) parent; java.util.List<TagBaseNode> data = (List<TagBaseNode>) list.getData(); data.add(newNode); parent.add(newNode); } parent.updateUserObject(); newNode.updateUserObject(); tagTree.expandPath(new TreePath(parent)); tagTree.updateUI(); }
From source file:de.iteratec.iteraplan.elasticeam.util.I18nMap.java
/** * Adds a new metamodel element and name to the map. * //from www .j av a 2 s. c om * @param locale * The locale of the name. * @param key * The name. * @param value * The metamodel element. */ public void set(Locale locale, String key, N value) { if (!this.valueByLocalizedName.containsKey(locale)) { BiMap<String, N> localeValues = HashBiMap.create(); this.valueByLocalizedName.put(locale, localeValues); } BiMap<String, N> localeValues = this.valueByLocalizedName.get(locale); if (localeValues.containsKey(key) && !value.equals(localeValues.get(key))) { throw new MetamodelException(ElasticeamException.GENERAL_ERROR, "Duplicate locale name " + key + " in locale " + locale + "."); } if (key == null) { localeValues.inverse().remove(value); } else { if (localeValues.inverse().containsKey(value)) { localeValues.inverse().remove(value); } localeValues.put(key, value); } }
From source file:com.google.security.zynamics.binnavi.Database.PostgreSQL.Savers.PostgreSQLNodeSaver.java
/** * Saves the nodes to the nodes table. As a side effect, this function also fills index lists that * store the indices into the nodes list for all node types. TODO: This method should probably be * split into two methods.//from ww w .j ava 2 s.c om * * @param provider Provides the connection to the database. * @param newViewId ID of the new view that is being saved. * @param nodes The nodes to save. * @param functionNodeIndices Index into the nodes list that identifies the function nodes. * @param codeNodeIndices Index into the nodes list that identifies the code nodes. * @param textNodeIndices Index into the nodes list that identifies the text nodes. * @param groupNodeIndices Index into the nodes list that identifies the group nodes. * @param groupNodeMap Maps between node IDs and group node objects. * @return The ID of the first node saved to the database. * @throws SQLException Thrown if saving the nodes failed. */ private static int saveNodes(final AbstractSQLProvider provider, final int newViewId, final List<INaviViewNode> nodes, final List<Integer> functionNodeIndices, final List<Integer> codeNodeIndices, final List<Integer> textNodeIndices, final List<Integer> groupNodeIndices, final BiMap<Integer, INaviGroupNode> groupNodeMap) throws SQLException { final String query = "INSERT INTO " + CTableNames.NODES_TABLE + "( view_id, parent_id, type, x, y, width, height, color, bordercolor, " + " selected, visible) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; final PreparedStatement preparedStatement = provider.getConnection().getConnection().prepareStatement(query, java.sql.Statement.RETURN_GENERATED_KEYS); int counter = 0; for (final INaviViewNode node : nodes) { String nodeType = null; if (node instanceof CCodeNode) { nodeType = CODE; codeNodeIndices.add(counter); } else if (node instanceof CFunctionNode) { nodeType = FUNCTION; functionNodeIndices.add(counter); } else if (node instanceof INaviGroupNode) { nodeType = GROUP; groupNodeIndices.add(counter); groupNodeMap.put(counter, (INaviGroupNode) node); } else if (node instanceof CTextNode) { nodeType = TEXT; textNodeIndices.add(counter); } counter++; preparedStatement.setInt(1, newViewId); preparedStatement.setNull(2, Types.INTEGER); preparedStatement.setObject(3, nodeType, Types.OTHER); preparedStatement.setDouble(4, node.getX()); preparedStatement.setDouble(5, node.getY()); preparedStatement.setDouble(6, node.getWidth()); preparedStatement.setDouble(7, node.getHeight()); preparedStatement.setInt(8, node.getColor().getRGB()); preparedStatement.setInt(9, node.getBorderColor().getRGB()); preparedStatement.setBoolean(10, node.isSelected()); preparedStatement.setBoolean(11, node.isVisible()); preparedStatement.addBatch(); } preparedStatement.executeBatch(); final ResultSet resultSet = preparedStatement.getGeneratedKeys(); int lastId = 0; try { while (resultSet.next()) { if (resultSet.isFirst()) { lastId = resultSet.getInt(1); break; } } } finally { preparedStatement.close(); resultSet.close(); } return lastId; }
From source file:edu.umd.cs.psl.evaluation.debug.CmdDebugger.java
private void printGroundKernels(Collection<GroundKernel> evidences) { BiMap<Integer, Atom> biatomHandles = HashBiMap.create(); int counter = 1; for (GroundKernel e : evidences) { String str = printGroundKernels(e); StringBuilder dep = new StringBuilder(); dep.append("--> Affected Atoms: "); Collection<Atom> atoms = e.getAtoms(); for (Atom a : atoms) { int atomNr = -1; if (biatomHandles.containsValue(a)) { atomNr = biatomHandles.inverse().get(a); } else { atomNr = counter;/*w ww.ja v a 2s . c o m*/ counter++; biatomHandles.put(atomNr, a); } str.replace(a.toString(), a.toString() + " [" + atomNr + "]"); dep.append(AtomPrinter.atomDetails(a)).append(" [" + atomNr + "]").append(" , "); } println(str); println(dep.toString()); } atomHandles = biatomHandles; }
From source file:de.iteratec.iteraplan.elasticeam.model.compare.impl.DiffBuilderImpl.java
private void processMatches(DiffBuilderResultImpl result) { //Prepare instance map BiMap<UniversalModelExpression, UniversalModelExpression> left2right = HashBiMap.create(); for (Entry<UniversalTypeExpression, Set<MatchingPair>> matched : matchResult.getMatches().entrySet()) { for (MatchingPair pair : matched.getValue()) { left2right.put(pair.getLeftExpression(), pair.getRightExpression()); }/* w w w . ja v a2s.c o m*/ } // process matches for (Entry<UniversalTypeExpression, Set<MatchingPair>> matched : matchResult.getMatches().entrySet()) { for (MatchingPair pair : matched.getValue()) { TwoSidedDiffImpl diff = new TwoSidedDiffImpl(matched.getKey(), pair.getLeftExpression(), pair.getRightExpression()); for (PropertyExpression<?> property : matched.getKey().getProperties()) { diffProperty(property, pair.getLeftExpression(), pair.getRightExpression(), diff); } for (RelationshipEndExpression re : matched.getKey().getRelationshipEnds()) { diffRelationshipEnd(re, pair, left2right, diff, result); } if (!diff.getDiffParts().isEmpty()) { result.addDiff(diff); } } } }
From source file:haven.Inventory.java
public void sortItemsLocally(Comparator<WItem> comp) { isTranslated = true;/* w w w . j a va 2 s . c o m*/ //if we can't sort the inventory due to items being updated while we're sorting //just abort List<WItem> array = new ArrayList<WItem>(wmap.values()); try { Collections.sort(array, comp); } catch (IllegalArgumentException e) { return; } //deciding the size of the sorted inventory int width = this.isz.x; int height = this.isz.y; if (this.equals(this.ui.gui.maininv)) { //flexible size int nr_items = wmap.size(); float aspect_ratio = 8 / 4; height = 4; width = 4; while (nr_items > height * width) { if (width == height * 2 || width == 32) { height++; } else { width++; } } } //assign the new locations to each of the items and add new translations int index = 0; BiMap<Coord, Coord> newdictionary = HashBiMap.create(); try { for (WItem w : array) { Coord newclientloc = new Coord((index % (width)), (int) (index / (width))); //adding the translation to the dictionary Coord serverloc = w.server_c; newdictionary.put(newclientloc, serverloc); //moving the widget to its ordered place w.c = sqoff(newclientloc); //on to the next location index++; } dictionaryClientServer = newdictionary; } catch (IllegalArgumentException iae) { //duplicate server coordinates, probably because we are swapping //no problem, we'll resort upon cdestroy of the old WItem } //resize the inventory to the new set-up this.updateClientSideSize(); }
From source file:uk.ac.ebi.mdk.domain.matrix.AbstractReactionMatrix.java
/** * * Assigns the values from the specified 'other' matrix to this one. Note: * the values are not deep copied/*w w w .ja v a 2 s . c o m*/ * * @return reaction indices (of those added) * */ public BiMap<Integer, Integer> assign(AbstractReactionMatrix<T, M, R> other) { // ensure there is enough space this.ensure(getMoleculeCount() + other.getReactionCount(), getReactionCount() + other.getReactionCount()); BiMap<Integer, Integer> map = HashBiMap.create(); for (int j = 0; j < other.getReactionCount(); j++) { map.put(j, this.addReaction(other.getReaction(j), other.getReactionMolecules(j), other.getReactionValues(j))); } return map; }
From source file:org.artifactory.storage.db.build.service.BuildStoreServiceImpl.java
/** * Locates and fills in missing checksums of a build file bean * * @param buildFiles List of build files to populate *//*from w w w . j a v a 2 s . c o m*/ private void handleBeanPopulation(List<? extends BuildFileBean> buildFiles) { if (buildFiles != null && !buildFiles.isEmpty()) { Set<String> checksums = Sets.newHashSet(); for (BuildFileBean buildFile : buildFiles) { boolean sha1Exists = StringUtils.isNotBlank(buildFile.getSha1()); boolean md5Exists = StringUtils.isNotBlank(buildFile.getMd5()); //If the bean has both or none of the checksums, return if ((sha1Exists && md5Exists) || ((!sha1Exists && !md5Exists))) { continue; } if (!sha1Exists) { checksums.add(buildFile.getMd5()); } else { checksums.add(buildFile.getSha1()); } } Set<BinaryInfo> binaryInfos = binaryStore.findBinaries(checksums); BiMap<String, String> found = HashBiMap.create(binaryInfos.size()); for (BinaryInfo binaryInfo : binaryInfos) { found.put(binaryInfo.getSha1(), binaryInfo.getMd5()); } for (BuildFileBean buildFile : buildFiles) { boolean sha1Exists = StringUtils.isNotBlank(buildFile.getSha1()); boolean md5Exists = StringUtils.isNotBlank(buildFile.getMd5()); //If the bean has both or none of the checksums, return if ((sha1Exists && md5Exists) || ((!sha1Exists && !md5Exists))) { continue; } if (!sha1Exists) { String newSha1 = found.inverse().get(buildFile.getMd5()); if (ChecksumType.sha1.isValid(newSha1)) { buildFile.setSha1(newSha1); } } else { String newMd5 = found.get(buildFile.getSha1()); if (ChecksumType.md5.isValid(newMd5)) { buildFile.setMd5(newMd5); } } } } }
From source file:eu.esdihumboldt.hale.ui.service.align.internal.AlignmentServiceUndoSupport.java
/** * @see eu.esdihumboldt.hale.ui.service.align.AlignmentService#replaceCells(java.util.Map) *//*from www. j av a2 s.co m*/ @Override public void replaceCells(Map<? extends Cell, MutableCell> cells) { BiMap<MutableCell, MutableCell> map = HashBiMap.create(cells.size()); for (Entry<? extends Cell, MutableCell> e : cells.entrySet()) { if (e.getKey() instanceof MutableCell && e.getValue() != null && getAlignment().getCells().contains(e.getKey())) map.put((MutableCell) e.getKey(), e.getValue()); else { log.warn("Replaced cells contains at least one cell which " + "is either not mutable or not in the alignment. " + "No undo/redo possible."); super.replaceCells(cells); return; } } IUndoableOperation operation = new ReplaceOperation(map); executeOperation(operation); }
From source file:com.opengamma.core.historicaltimeseries.impl.NonVersionedRedisHistoricalTimeSeriesSource.java
protected void updateTimeSeries(String redisKey, LocalDateDoubleTimeSeries timeseries) { try (Timer.Context context = _updateSeriesTimer.time()) { Jedis jedis = getJedisPool().getResource(); try {/*from w w w.j av a2 s .c o m*/ Map<String, String> htsMap = Maps.newHashMap(); BiMap<Double, String> dates = HashBiMap.create(); for (Entry<LocalDate, Double> entry : timeseries) { String dateAsIntText = Integer.toString(LocalDateToIntConverter.convertToInt(entry.getKey())); htsMap.put(dateAsIntText, Double.toString(entry.getValue())); dates.put(Double.valueOf(dateAsIntText), dateAsIntText); } Pipeline pipeline = jedis.pipelined(); pipeline.multi(); String redisHtsDatapointKey = toRedisHtsDatapointKey(redisKey); pipeline.hmset(redisHtsDatapointKey, htsMap); String redisHtsDaysKey = toRedisHtsDaysKey(redisKey); for (String dateAsIntText : dates.inverse().keySet()) { pipeline.zrem(redisHtsDaysKey, dateAsIntText); } for (Entry<Double, String> entry : dates.entrySet()) { pipeline.zadd(redisHtsDaysKey, entry.getKey(), entry.getValue()); } pipeline.exec(); pipeline.sync(); getJedisPool().returnResource(jedis); } catch (Exception e) { s_logger.error("Unable to put timeseries with id: " + redisKey, e); getJedisPool().returnBrokenResource(jedis); throw new OpenGammaRuntimeException("Unable to put timeseries with id: " + redisKey, e); } } }