/** 当单击单元格出现CellEditor时应该显示什么值。由此方法决定, 返回单元格的当前值 返回某个属性的值 */ public Object getValue(Object element, String property) { Object result = null; Station station = (Station) element; if (station == null) return null; // 使用别名的方法 if (property.equals("name")) return station.getStation_name(); else if (property.equals("down")) return String.valueOf(station.getStation_downnumber()); else if (property.equals("up")) return String.valueOf(station.getStation_upnumber()); else if (property.equals("map")) // ComboBoxCellEditor要求返回下拉框中的索引值 return new Integer(getNameIndex(station.getStation_graph())); // 直接使用索引 /* List list = Arrays.asList(stationData.columnHeads); int columnIndex = list.indexOf(property); //再返回对应的数据 switch (columnIndex) { case 0://id return String.valueOf(station.getStation_id()); case 1://name return station.getStation_name(); case 2://down return String.valueOf(station.getStation_downnumber()); case 3://up return String.valueOf(station.getStation_upnumber()); case 4://map ,因为用的是下拉框,所以要返回一个Integer表示当前选中的index return new Integer(getNameIndex(station.getStation_graph())); } */ return result; }
/** * Get station with given id or null if no such station is found in this manager * * @param id the id of this station * @return station with given id or null if no such station is found */ public Station getStationWithId(String id) { Station station = null; for (Station this_station : stations) { if (this_station.getID().equals(id)) { station = this_station; } } return station; }
/** * Find nearest station to given point. Returns null if no station is closer than RADIUS metres. * If two or more stations are at an equal distance from the given point, any one of those * stations is returned. * * @param pt point to which nearest station is sought * @return station closest to pt but less than 10,000m away; null if no station is within RADIUS * metres of pt */ public Station findNearestTo(LatLon pt) { Station NearestStation = null; double NearestDistance = RADIUS; for (Station next_staion : stations) { double distance = SphericalGeometry.distanceBetween(next_staion.getLocn(), pt); if (distance <= RADIUS && distance < NearestDistance) { NearestDistance = distance; NearestStation = next_staion; } } return NearestStation; }
public void setAdvancedValues() { // get pretty ranges for the current parameters // get the range for the station value double min = 10000; double max = 0; for (int fc = 0; fc < mFileViewer.mNumOpenFiles; fc++) { OpenDataFile of = (OpenDataFile) mFileViewer.mOpenFiles.elementAt(fc); for (int sec = 0; sec < of.mNumSections; sec++) { Section sech = (Section) of.mSections.elementAt(sec); if (sech.mNumCasts == 0) { continue; } for (int stc = 0; stc < sech.mStations.size(); stc++) { Station sh = (Station) sech.mStations.elementAt(stc); if (!sh.mUseStn) { continue; } // get the station value double y = sh.getStnValue(mSelYParam); if (y == JOAConstants.MISSINGVALUE || y >= JOAConstants.EPICMISSINGVALUE) { continue; } else { min = y < min ? y : min; max = y > max ? y : max; } } } } Triplet newRange = JOAFormulas.GetPrettyRange(min, max); double yMinv = newRange.getVal1(); double yMaxv = newRange.getVal2(); double yIncv = newRange.getVal3(); yMin.setText(JOAFormulas.formatDouble(String.valueOf(yMinv), 3, false)); yMax.setText(JOAFormulas.formatDouble(String.valueOf(yMaxv), 3, false)); yInc.setText(JOAFormulas.formatDouble(String.valueOf(yIncv), 3, false)); yTics.setValue(new Integer(yTicsVal)); if (b1.isSelected()) { mOffset = JOAConstants.PROFSEQUENCE; setXRangeToSequence(); } else if (b2.isSelected()) { mOffset = JOAConstants.PROFDISTANCE; setXRangeToDistance(); } else if (b3.isSelected()) { mOffset = JOAConstants.PROFTIME; setXRangeToTime(); } }
/* 这里的element参数,其实就是我们二维数组中的每一个一维数组,其中保存的是 * 每一行的所有数据,通过column这个参数依次写入到表格中的各个字段上。 * column具体值是多少我们并不知道,因此需要我们来判断,并根据他里面的值 * 来决定我们要将哪个数据返回。同样,该方法是不能返回NULL的。必须先检查数有效性。 */ public String getColumnText(Object element, int columnIndex) { Station station = (Station) element; if (station == null) // 解决表中空数据出现的错误 return null; switch (columnIndex) { case 0: return station.getStation_name(); case 1: return String.valueOf(station.getStation_downnumber()); case 2: return String.valueOf(station.getStation_upnumber()); case 3: return station.getStation_graph(); } return null; }
/** * Remove station from line * * @param stn the station to remove from this line */ public void removeStation(Station stn) { if (stations.contains(stn)) { stations.remove(stn); // stn.removeLine(this); } }
/** * Add station to line, if it's not already there. * * @param stn the station to add to this line */ public void addStation(Station stn) { if (!stations.contains(stn)) { stations.add(stn); // stn.addLine(this); } }
public int compare(Viewer viewer, Object e1, Object e2) { Station info1 = (Station) e1; Station info2 = (Station) e2; switch (propertyIndex) { case 0: // return info1.name.compareTo(info2.name); return direction ? info1.getStation_name().compareTo(info2.getStation_name()) : info2.getStation_name().compareTo(info1.getStation_name()); /*case 3: 对于checkcell if (bug1.isSolved == bug2.isSolved) return 0; if (bug1.isSolved) return 1; else return -1;*/ default: return 0; } }
public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new FileReader(new File(args[0]))); BufferedWriter bw = new BufferedWriter(new FileWriter(args[1])); int T = Integer.parseInt(br.readLine()); for (int t = 1; t <= T; t++) { br.readLine(); List<List<Station>> graph = new ArrayList<>(); int N = Integer.parseInt(br.readLine()); for (int i = 0; i < N; i++) { graph.add(new ArrayList<>()); String[] line1 = br.readLine().split(" "); int SN = Integer.parseInt(line1[0]); int W = Integer.parseInt(line1[1]); for (int j = 0; j < SN; j++) { graph.get(i).add(new Station(i, j, W)); } String[] dist = br.readLine().split(" "); for (int j = 0; j < dist.length; j++) { int d = Integer.parseInt(dist[j]); Station s1 = graph.get(i).get(j); Station s2 = graph.get(i).get(j + 1); s1.neighbors.put(s2, d); s2.neighbors.put(s1, d); } } int tunnelNum = Integer.parseInt(br.readLine()); for (int i = 0; i < tunnelNum; i++) { String[] tunnel = br.readLine().split(" "); int l1 = Integer.parseInt(tunnel[0]) - 1; int s1 = Integer.parseInt(tunnel[1]) - 1; int l2 = Integer.parseInt(tunnel[2]) - 1; int s2 = Integer.parseInt(tunnel[3]) - 1; int d = Integer.parseInt(tunnel[4]); Station sta1 = graph.get(l1).get(s1); Station sta2 = graph.get(l2).get(s2); sta1.neighbors.put(sta2, d + sta2.waitTime); // add wait time to distance sta2.neighbors.put(sta1, d + sta1.waitTime); Station sta11 = sta1.cloneForTunnel(); Station sta22 = sta2.cloneForTunnel(); graph.get(sta1.lineNo).add(sta11); graph.get(sta2.lineNo).add(sta22); for (Station st : sta11.neighbors.keySet()) { sta2.neighbors.put( st, d + sta11.neighbors.get( st)); // don't wait, sta11 means go xsfrom sta2 to sta1 than go to other // tunnel } for (Station st : sta22.neighbors.keySet()) { sta1.neighbors.put(st, d + sta22.neighbors.get(st)); } } int queryNum = Integer.parseInt(br.readLine()); bw.write("Case: #" + t + ":"); bw.newLine(); for (int i = 0; i < queryNum; i++) { String[] query = br.readLine().split(" "); int l1 = Integer.parseInt(query[0]) - 1; int s1 = Integer.parseInt(query[1]) - 1; int l2 = Integer.parseInt(query[2]) - 1; int s2 = Integer.parseInt(query[3]) - 1; Station sta1 = graph.get(l1).get(s1); Station sta2 = graph.get(l2).get(s2); PriorityQueue<Station> pq = new PriorityQueue<>(); sta1.dist = sta1.waitTime; for (List<Station> line : graph) { for (Station st : line) { pq.offer(st); } } Set<Station> visited = new HashSet<>(); visited.add(sta1); boolean done = false; while (!done && !pq.isEmpty()) { Station st = pq.poll(); for (Station neb : st.neighbors.keySet()) { if (!visited.contains(neb)) { neb.dist = st.dist + st.neighbors.get(neb); if (neb == sta2) { // reference to same object done = true; break; } visited.add(neb); pq.remove(neb); // because need to let pq update this item's priority level pq.offer(neb); } } } int ret = sta2.dist == Integer.MAX_VALUE ? -1 : sta2.dist; bw.write("" + ret); bw.newLine(); } } bw.close(); br.close(); }
// 当用户对单元格内容进行修改 时,此方法执行. 为某个属性赋值 public void modify(Object element, String property, Object value) { TableItem tableItem = (TableItem) element; if (tableItem == null) { // tableViewer.update(null, null); return; } Station station = (Station) tableItem.getData(); if (station == null) { // tableViewer.update(null, null); return; } if (property.equals("name")) { String name = (String) value; station.setStation_name(name); } else if (property.equals("down")) { String down = (String) value; if (down.length() > 0) { station.setStation_downnumber(Integer.parseInt(down)); } } else if (property.equals("up")) { String up = (String) value; if (up.length() > 0) { station.setStation_upnumber(Integer.parseInt(up)); } } else if (property.equals("map")) { Integer comboIndex = (Integer) value; if (comboIndex.intValue() != -1) { String mapName = StationData.MAPS[comboIndex.intValue()]; station.setStation_graph(mapName); } } // System.out.println("Modiy:" + value +"::"+columnIndex); /*List list = Arrays.asList(stationData.columnHeads); int columnIndex = list.indexOf(property); switch (columnIndex) { case 0: String id = (String) value; if (id.length() > 0) { station.setStation_id(Integer.parseInt(id)); } break; case 1: String name = (String) value; if (name.length() > 0) { station.setStation_name(name); } break; case 2: String down = (String) value; if (down.length() > 0) { station.setStation_downnumber(Integer.parseInt(down)); } break; case 3: String up = (String) value; if (up.length() > 0) { station.setStation_upnumber(Integer.parseInt(up)); } break; case 4: Integer comboIndex = (Integer) value; if(comboIndex.intValue() != -1){ String mapName = StationData.MAPS[comboIndex.intValue()]; station.setStation_graph(mapName); } break; } */ tableViewer.update(station, null); }