List of usage examples for com.google.common.collect Table row
Map<C, V> row(R rowKey);
From source file:es.upm.dit.xsdinferencer.datastructures.Schema.java
/** * This method tries to guess the main namespace of this schema if no one is configured or * returns the configured one, if any. //from w w w. j a va 2s. co m * That namespace will be the one which has more elements in the schema and is not skipped. * If more than one namespace has the greatest number of elements, then the one with most attributes * is chosen. If there also is more than one namespace in that situation, one of them is chosen. * @param configuration the inference configuration * @return a namespace URI of the main namespace */ public String guessMainNamespace(XSDInferenceConfiguration configuration) { String configurationMainNamespace = configuration.getMainNamespace(); if (configurationMainNamespace != null) return configurationMainNamespace; String namespaceCandidate = null; int elementMaxCount = Integer.MIN_VALUE; int attributeMaxCount = Integer.MIN_VALUE; Table<String, String, SchemaElement> schemaElements = this.getElements(); Table<String, String, SchemaAttribute> schemaAttributes = this.getAttributes(); for (String namespace : schemaElements.rowKeySet()) { Map<String, SchemaElement> elementsOfCurrentNamespace = schemaElements.row(namespace); Map<String, SchemaAttribute> attributesOfCurrentNamespace = schemaAttributes.row(namespace); if (elementsOfCurrentNamespace.keySet().size() > elementMaxCount || (elementsOfCurrentNamespace.keySet().size() == elementMaxCount && attributesOfCurrentNamespace.keySet().size() > attributeMaxCount)) { namespaceCandidate = namespace; elementMaxCount = elementsOfCurrentNamespace.keySet().size(); attributeMaxCount = attributesOfCurrentNamespace.keySet().size(); } } return namespaceCandidate; }
From source file:Model.Agents.Brains.Intersection_Brain.java
/** * Reasonning methods use to find a trajectory for the new vehicle. * /*from w w w. j a v a 2 s .co m*/ * @param pos postion of the new vehicle in the intersection. * @param goal destination of the new vehicle. * * @return the trajectory of the vehicle. */ private Trajectory findTrajectory(Cell pos, CardinalPoint goal) { //Get the good trajectory. Intersection_Body i_body = (Intersection_Body) this.body; Intersection inter = (Intersection) i_body.getInfrastructure(); Table<CardinalPoint, Integer, Trajectory> ways = inter.getTrajectories(); Trajectory trajectory = null; int t_id = -1; CardinalPoint t_cp = null; boolean ok = false; for (CardinalPoint c : ways.rowKeySet()) { for (Entry<Integer, Trajectory> entry : ways.row(c).entrySet()) { int _id = entry.getKey(); Trajectory w = entry.getValue(); //If the trajectory contains the position if (w.getCells().contains(pos)) { if (_id >= 0 && _id < inter.getNb_ways().get(Flow.IN, c)) { if (c.getFront() == goal) { trajectory = w; t_id = _id; t_cp = c; ok = true; } } else if (_id == inter.getNb_ways().get(Flow.IN, c)) { if (c.getRight() == goal) { trajectory = w; t_id = _id; t_cp = c; ok = true; } } else { if (c.getLeft() == goal) { trajectory = w; t_id = _id; t_cp = c; ok = true; } } } } if (ok) break; } if (ok) { //Get the first cell of the neighbor. //* if (i_body.getNeighbors().containsKey(goal)) { Infrastructure neighbor = i_body.getNeighbors().get(goal).getInfrastructure(); Trajectory w = neighbor.getTrajectories().get(goal.getFront(), t_id); if (w != null && !w.isEmpty()) { Cell next = w.getCells().get(0); if (next != null && trajectory != null) trajectory.addCell(next); } } //*/ //Determine the cell where the vehicle will wait Cell whereStop = null; if (t_cp != null) { Intersection i = (Intersection) i_body.getInfrastructure(); if (trajectory != null && trajectory.getCells() != null && !trajectory.getCells().isEmpty()) whereStop = trajectory.getCells().get(i.getWays_size().get(Flow.IN, t_cp) - 1); } if (trajectory != null) trajectory.setWhereToStop(whereStop); } return trajectory; }
From source file:org.pau.assetmanager.viewmodel.stocks.HistoricalStocksValuesDownloader.java
private static Table<Integer, Integer, Double> getYearToMonthToValueTable(String symbol, Integer startYear, Integer finalYear) {/*from w ww. j av a 2s. c om*/ try { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); Calendar calendar = GregorianCalendar.getInstance(); Table<Integer, Integer, Double> yearMonthValueTable = HashBasedTable.<Integer, Integer, Double>create(); Table<Integer, Integer, Integer> yearMonthTimesTable = HashBasedTable .<Integer, Integer, Integer>create(); List<Map<String, String>> csvContents = getContents(symbol, startYear, finalYear); for (Map<String, String> fieldToValueMap : csvContents) { Double open = Double.parseDouble(fieldToValueMap.get(OPEN)); Double close = Double.parseDouble(fieldToValueMap.get(OPEN)); Double averagePrice = (open + close) / 2.0; Date date = simpleDateFormat.parse(fieldToValueMap.get(DATE)); calendar.setTime(date); Integer year = calendar.get(Calendar.YEAR); Integer month = calendar.get(Calendar.MONTH); Integer day = calendar.get(Calendar.DAY_OF_MONTH); Double currentPrice = yearMonthValueTable.get(year, month); if (currentPrice == null) { currentPrice = averagePrice; } else { currentPrice += averagePrice; } yearMonthValueTable.put(year, month, currentPrice); Integer times = yearMonthTimesTable.get(year, month); if (times == null) { times = 1; } else { times++; } yearMonthTimesTable.put(year, month, times); } for (Integer year : yearMonthTimesTable.rowKeySet()) { for (Integer month : yearMonthTimesTable.row(year).keySet()) { yearMonthValueTable.put(year, month, yearMonthValueTable.get(year, month) / yearMonthTimesTable.get(year, month).doubleValue()); } } return yearMonthValueTable; } catch (ParseException e) { throw new AssetManagerRuntimeException("Error parsing date from CSV file for '" + symbol + "' between '" + startYear + "' and '" + finalYear + "'.", e); } }
From source file:io.github.jonestimd.swing.table.model.BufferedHeaderDetailTableModel.java
private void shiftErrors(int firstRow, int delta) { Table<Integer, Integer, String> updatedErrors = HashBasedTable.create(); Iterator<Entry<Integer, Map<Integer, String>>> iterator = errors.rowMap().entrySet().iterator(); while (iterator.hasNext()) { Entry<Integer, Map<Integer, String>> entry = iterator.next(); if (entry.getKey() >= firstRow) { updatedErrors.row(entry.getKey() + delta).putAll(entry.getValue()); iterator.remove();//w ww . j a v a 2 s. c o m } } errors.putAll(updatedErrors); }
From source file:Model.Agents.Brains.Vehicle_Brain.java
@Override public void setBody(A_Body body) { this.body = body; //Determine the infrastructure destination's coordinates Table<Integer, Integer, Infrastructure> map = this.body.getEnvironment().getMap(); int dest_x = 0; int dest_y = 0; int x = 0;/*www . j a v a2 s . c o m*/ int y = 0; CardinalPoint begin = null; boolean ok = false; for (int row : map.rowKeySet()) { for (Entry<Integer, Infrastructure> entry : map.row(row).entrySet()) { if (entry.getValue().haveCell(this.final_goal)) { dest_x = row; dest_y = entry.getKey(); ok = true; } if (entry.getValue().haveCell(this.body.getPosition())) { //Determine the position of the vehicule in the infrastructure x = row; y = entry.getKey(); Infrastructure i = entry.getValue(); for (CardinalPoint cp : i.getTrajectories().rowKeySet()) { for (Entry<Integer, Trajectory> e : i.getTrajectories().row(cp).entrySet()) { if (e.getValue().getCells().get(0).equals(this.body.getPosition())) begin = cp; } } } } } //Destination founded if (ok && begin != null) { System.out.println("Pos found in " + begin + " of : [" + x + ", " + y + "]"); System.out.println("Final goal found in : [" + dest_x + ", " + dest_y + "]"); System.out.println("\nVehicle " + this.id + " intermadiate goals determination : "); //Determine the intermediates goals this.intermediate_goals.clear(); this.intermediate_goals.addAll(determineIntermediateGoals(0, begin, x, y, dest_x, dest_y)); System.out.println("Vehicle " + this.id + " intermadiate goals : " + this.intermediate_goals); //Send the creation //* if (this.intermediate_goals != null && !this.intermediate_goals.isEmpty()) { Vehicle_Body v_body = (Vehicle_Body) this.body; M_Hello mess = new M_Hello(this.id, v_body.getInfrastructure().getId(), v_body.getPosition(), this.intermediate_goals.get(this.intermediate_goals.size() - 1)); this.body.sendMessage(mess); } //*/ } }
From source file:net.librec.math.structure.SparseStringMatrix.java
/** * Construct a sparse matrix//from w ww .j a v a 2 s.co m * * @param dataTable data table * @param columnStructure column structure */ private void construct(Table<Integer, Integer, ? extends String> dataTable, Multimap<Integer, Integer> columnStructure) { int nnz = dataTable.size(); // CRS rowPtr = new int[numRows + 1]; colInd = new int[nnz]; rowData = new String[nnz]; int j = 0; for (int i = 1; i <= numRows; ++i) { Set<Integer> cols = dataTable.row(i - 1).keySet(); rowPtr[i] = rowPtr[i - 1] + cols.size(); for (int col : cols) { colInd[j++] = col; if (col < 0 || col >= numColumns) throw new IllegalArgumentException( "colInd[" + j + "]=" + col + ", which is not a valid column index"); } Arrays.sort(colInd, rowPtr[i - 1], rowPtr[i]); } // CCS colPtr = new int[numColumns + 1]; rowInd = new int[nnz]; colData = new String[nnz]; j = 0; for (int i = 1; i <= numColumns; ++i) { // dataTable.col(i-1) is more time-consuming than columnStructure.get(i-1) Collection<Integer> rows = columnStructure != null ? columnStructure.get(i - 1) : dataTable.column(i - 1).keySet(); colPtr[i] = colPtr[i - 1] + rows.size(); for (int row : rows) { rowInd[j++] = row; if (row < 0 || row >= numRows) throw new IllegalArgumentException( "rowInd[" + j + "]=" + row + ", which is not a valid row index"); } Arrays.sort(rowInd, colPtr[i - 1], colPtr[i]); } // set data for (Cell<Integer, Integer, ? extends String> en : dataTable.cellSet()) { int row = en.getRowKey(); int col = en.getColumnKey(); String val = en.getValue().toString(); set(row, col, val); } }
From source file:eu.lp0.cursus.xml.scores.XMLScores.java
private void extractEventResults() { for (ScoresXMLEventResults eventResult : scoresXML.getEventResults()) { for (DataXMLEventRef event : eventResult.getEvents()) { resultsEvents.put(eventResult, dereference(event)); }// w ww.j ava 2 s . c om Table<Pilot, Race, ScoresXMLRaceScore> raceScores = HashBasedTable.create(); for (ScoresXMLEventRaceResults eventRaceResults : eventResult.getRaceResults()) { eventEventRaceResults.row(eventResult).put(dereference(eventRaceResults), eventRaceResults); Race race = dereference(eventRaceResults); resultsRaces.put(eventResult, race); for (ScoresXMLRaceScore raceScore : eventRaceResults.getRacePilots()) { raceScores.row(dereference(raceScore)).put(race, raceScore); } } resultsPilotRaceScores.put(eventResult, raceScores); for (ScoresXMLOverallScore overallScore : eventResult.getOverallPilots()) { Pilot pilot = dereference(overallScore); resultsPilotOverallScores.row(eventResult).put(pilot, overallScore); resultsPilots.put(eventResult, pilot); } } }
From source file:mtsar.processors.answer.KOSAggregator.java
private Map<Integer, Double> converge(Table<Integer, Integer, Short> graph, int kMax) { final RealDistribution distribution = new NormalDistribution(1, 1); Table<Integer, Integer, Double> ys = HashBasedTable.create(graph.rowKeySet().size(), graph.columnKeySet().size()); for (final Table.Cell<Integer, Integer, Short> cell : graph.cellSet()) { ys.put(cell.getRowKey(), cell.getColumnKey(), distribution.sample()); }/*w w w . j a va 2s . c om*/ for (int k = 1; k <= kMax; k++) { final Table<Integer, Integer, Double> xs = tasksUpdate(graph, ys); if (k < kMax) ys = workersUpdate(graph, xs); } final Map<Integer, Double> estimations = new HashMap<>(); for (final Integer taskId : graph.rowKeySet()) { double sumProduct = 0.0; final Map<Integer, Double> workers = ys.row(taskId); for (final Map.Entry<Integer, Double> worker : workers.entrySet()) { sumProduct += graph.get(taskId, worker.getKey()) * worker.getValue(); } estimations.put(taskId, sumProduct); } return estimations; }
From source file:edu.duke.cs.jflap.gui.grammar.parse.UnrestrictedTreePanel.java
/** * Paints the tree.//from w w w .ja va 2 s . com * * @param g * the graphics object */ private void paintTree(final Graphics2D g) { final Dimension d = getSize(); realWidth = d.width; realHeight = d.height; if (metaWidth == -1.0) { setMetaWidth(); } metaHeight = top.size(); final Point2D p = new Point2D.Double(); nodeToPoint = new HashMap<>(); for (int l = 0; l <= level; l++) { double total = 0.0; final Table<Integer, Integer, UnrestrictedTreeNode> GG = l < level ? bottom.get(l) : top.get(l); for (int gr = 0; gr < GG.rowKeySet().size() && (level != l || gr <= group); gr++) { final Map<Integer, UnrestrictedTreeNode> G = GG.row(gr); if (l <= level - 2 || (l == level - 1 && gr <= group)) { // Want the node on the bottom level. for (final UnrestrictedTreeNode element : G.values()) { if (l == element.lowest) { // This group is drawn on the bottom. // Draw the line. final Point2D point = getPoint(element.lowest, total + element.weight / 2.0, null); getPoint(element.highest, total + element.weight / 2.0, p); g.drawLine((int) point.getX(), (int) point.getY(), (int) p.getX(), (int) p.getY()); // Make the mapping. nodeToPoint.put(element, point); } if (l == element.highest) { // This group is just starting. final Point2D point = getPoint(element.highest, total + element.weight / 2.0, null); final Double D = nodeToParentWeights.get(element); if (D != null) { final double pweight = D.doubleValue(); getPoint(l - 1, pweight, p); g.drawLine((int) point.getX(), (int) point.getY(), (int) p.getX(), (int) p.getY()); } // Draw the brackets. final List<UnrestrictedTreeNode> parent = nodeToParentGroup.get(element); if (parent != null && parent.size() != 1) { final Point2D alpha = nodeToPoint.get(parent.get(0)); final Point2D beta = nodeToPoint.get(parent.get(parent.size() - 1)); g.setColor(BRACKET); final int radius = (int) DefaultNodeDrawer.NODE_RADIUS; final int ax = (int) (alpha.getX() - radius - 3); final int ay = (int) (alpha.getY() - radius - 3); g.fillRoundRect(ax, ay, (int) (beta.getX() + radius + 3) - ax, (int) (beta.getY() + radius + 3) - ay, 2 * radius + 6, 2 * radius + 6); g.setColor(BRACKET_OUT); g.drawRoundRect(ax, ay, (int) (beta.getX() + radius + 3) - ax, (int) (beta.getY() + radius + 3) - ay, 2 * radius + 6, 2 * radius + 6); g.setColor(Color.black); } // Make the map. nodeToPoint.put(element, point); } total += element.weight; } } else if (l <= level) { // We're going to get the top level. for (final UnrestrictedTreeNode element : G.values()) { if (l == element.highest) { // This node is just starting too. final Point2D point = getPoint(element.highest, total + element.weight / 2.0, null); final Double D = nodeToParentWeights.get(element); if (D != null) { final double pweight = D.doubleValue(); getPoint(l - 1, pweight, p); g.drawLine((int) point.getX(), (int) point.getY(), (int) p.getX(), (int) p.getY()); } // Draw the brackets. final List<UnrestrictedTreeNode> parent = nodeToParentGroup.get(element); if (parent != null && parent.size() != 1) { final Point2D alpha = nodeToPoint.get(parent.get(0)); final Point2D beta = nodeToPoint.get(parent.get(parent.size() - 1)); g.setColor(BRACKET); final int radius = (int) DefaultNodeDrawer.NODE_RADIUS; final int ax = (int) (alpha.getX() - radius - 3); final int ay = (int) (alpha.getY() - radius - 3); g.fillRoundRect(ax, ay, (int) (beta.getX() + radius + 3) - ax, (int) (beta.getY() + radius + 3) - ay, 2 * radius + 6, 2 * radius + 6); g.setColor(BRACKET_OUT); g.drawRoundRect(ax, ay, (int) (beta.getX() + radius + 3) - ax, (int) (beta.getY() + radius + 3) - ay, 2 * radius + 6, 2 * radius + 6); g.setColor(Color.black); } // Make the map. nodeToPoint.put(element, point); } total += element.weight; } } else { System.err.println("Badness in the drawer!"); } } } // Do the drawing of the nodes. final Iterator<Map.Entry<UnrestrictedTreeNode, Point2D>> it = nodeToPoint.entrySet().iterator(); while (it.hasNext()) { final Map.Entry<UnrestrictedTreeNode, Point2D> e = it.next(); paintNode(g, (e.getKey()), e.getValue()); } }
From source file:no.ssb.vtl.script.operations.join.AbstractJoinOperation.java
@Deprecated private Comparator<Map<Component, VTLObject>> createKeyComparator(Dataset rightDataset, Order order) { // Only check the values of the common identifiers. HashSet<Component> commonComponents = Sets.newHashSet(getCommonIdentifiers()); final Map<Component, Order.Direction> commonOrder = Maps.filterKeys(order, commonComponents::contains); final Table<Component, Dataset, Component> componentMap = getComponentMapping(); return (left, right) -> { if (left == null) return -1; if (right == null) return 1; if (left == right) return 0; int result; for (Map.Entry<Component, Order.Direction> entry : commonOrder.entrySet()) { Component component = entry.getKey(); Order.Direction direction = entry.getValue(); Map<Dataset, Component> map = componentMap.row(component); Component leftComponent = component; // kept for clarity Component rightComponent = map.get(rightDataset); VTLObject leftValue = left.get(leftComponent); VTLObject rightValue = right.get(rightComponent); result = Order.NULLS_FIRST.compare(leftValue, rightValue); if (result != 0) return direction == ASC ? result : -1 * result; }/* w ww. ja v a 2 s . c om*/ return 0; }; }