@Override public void removeKey(final String key) { final String[] parts = (String[]) Iterables.toArray( Splitter.on('.').split((CharSequence) this.createRelativeKey(key)), (Class) String.class); final Map<String, Tag> parent = this.findLastParent(parts); parent.remove(parts[parts.length - 1]); }
private Map<String, Tag> findLastParent(final String[] parts) { Map<String, Tag> map = NBTStorage.this.root; for (int i = 0; i < parts.length - 1; ++i) { if (!map.containsKey(parts[i]) || !(map.get(parts[i]) instanceof CompoundTag)) { return null; } map = map.get(parts[i]).getValue(); } return map; }
public void loadGridNet(String mapGrid) throws IOException { Preconditions.checkArgument(!Strings.isNullOrEmpty(mapGrid)); logger.debug("loading {}...", mapGrid); CSVReader reader = new CSVReader(new FileReader(mapGrid), ',', '"', 1); String[] row; while ((row = reader.readNext()) != null) { String gridId = row[1].trim(); String dmRoads = row[2].trim(); String gjRoads = row[3].trim(); Set<String> x = Sets.newHashSet(Splitter.on('|').trimResults().omitEmptyStrings().split(dmRoads)); Set<String> y = Sets.newHashSet(Splitter.on('|').trimResults().omitEmptyStrings().split(gjRoads)); if (x.size() > 0 || y.size() > 0) { MapGrid grid = new MapGrid(); grid.dmRoads = x; grid.gjRoads = y; gridNet.put(gridId, grid); // logger.debug("{},{},{}", gridId, x, y); } } reader.close(); }
private Tag findLastTag(final String key, final boolean relative) { final String[] parts = (String[]) Iterables.toArray( Splitter.on('.') .omitEmptyStrings() .split((CharSequence) (relative ? this.createRelativeKey(key) : key)), (Class) String.class); if (parts.length == 0) { return new CompoundTag(NBTStorage.this.name, NBTStorage.this.root); } final Map<String, Tag> map = this.findLastParent(parts); if (!map.containsKey(parts[parts.length - 1])) { return null; } return map.get(parts[parts.length - 1]); }
public List<RoadLink> getRoadLinks(Point2D pos, boolean isGrid) { int row = (int) ((pos.getX() - fcdSettings.getMap().getxOffset()) / fcdSettings.getMap().getGridLength()); int col = (int) ((pos.getY() - fcdSettings.getMap().getyOffset()) / fcdSettings.getMap().getGridLength()); Set<String> links = new HashSet(); for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { String grid = row + "+" + col; Optional<MapGrid> mapGrid = Optional.fromNullable(gridNet.get(grid)); if (mapGrid.isPresent()) { links.addAll(mapGrid.get().union()); } } } // logger.debug("---->{}", links); List<RoadLink> roads = new ArrayList(); for (String linkId : links) { // logger.debug("=>{}", linkId); Optional<RoadLink> roadLink = Optional.fromNullable(roadNet.get(Integer.valueOf(linkId))); if (roadLink.isPresent()) { RoadLink link = roadLink.get(); if (link.xmin < pos.getX() + 50 && link.ymin < pos.getY() + 50 && link.xmax > pos.getX() - 50 && link.ymax > pos.getY() - 50) { roads.add(link); } } } return roads; }
@Override public Map<String, Object> getValuesDeep() { final Tag tag = this.findLastTag(this.path, false); if (!(tag instanceof CompoundTag)) { return Collections.emptyMap(); } final Queue<Node> node = new ArrayDeque<Node>( (Collection<? extends Node>) ImmutableList.of((Object) new Node(tag))); final Map<String, Object> values = (Map<String, Object>) Maps.newHashMap(); while (!node.isEmpty()) { final Node root = node.poll(); for (final Map.Entry<String, Tag> entry : root.values.entrySet()) { final String key = this.createRelativeKey(root.parent, entry.getKey()); if (entry.getValue() instanceof CompoundTag) { node.add(new Node(key, entry.getValue())); } else { values.put(key, entry.getValue().getValue()); } } } return values; }
private void putTag(final String key, final Tag tag) { final String[] parts = (String[]) Iterables.toArray( Splitter.on('.').split((CharSequence) this.createRelativeKey(key)), (Class) String.class); Map<String, Tag> parent = NBTStorage.this.root; for (int i = 0; i < parts.length - 1; ++i) { if (!parent.containsKey(parts[i]) || !(parent.get(parts[i]) instanceof CompoundTag)) { parent.put(parts[i], new CompoundTag(parts[i])); } parent = parent.get(parts[i]).getValue(); } parent.put(tag.getName(), tag); }
public List<RoadLink> loadToDatabase(String mif, String mid) throws IOException { logger.debug("loading {}...", mid); CSVReader reader = new CSVReader(new FileReader(mid), ',', '"', 0); String[] row; List<RoadLink> links = new ArrayList(); while ((row = reader.readNext()) != null) { RoadLink link = new RoadLink(); link.no = Integer.valueOf(row[0]); link.fromNode = Integer.valueOf(row[1]); link.toNode = Integer.valueOf(row[2]); link.name = row[3]; link.length = Double.valueOf(row[4]); link.ft = row[5]; link.tf = row[6]; link.combine = row[7]; link.overhead = row[8]; link.xmin = Double.valueOf(row[9]); link.ymin = Double.valueOf(row[10]); link.xmax = Double.valueOf(row[11]); link.ymax = Double.valueOf(row[12]); links.add(link); roadNet.put(link.no, link); } for (final RoadLink link : links) { jdbcTemplate.update( sql1, link.no, link.fromNode, link.toNode, link.name, link.length, link.ft, link.tf, link.combine, link.overhead, link.xmin, link.ymin, link.xmax, link.ymax); } Charset charset = Charset.forName("UTF-8"); BufferedReader mifReader = Files.newBufferedReader(Paths.get(mif), charset); String line; int index = -1; int pos = -1; int segs = -1; Point2D prePoint = null; while ((line = mifReader.readLine()) != null) { List<String> cols = Lists.newArrayList( Splitter.on(CharMatcher.BREAKING_WHITESPACE) .trimResults() .omitEmptyStrings() .split(line)); // logger.debug("{}", line); if (cols.get(0).compareTo("PLINE") == 0) { index++; segs = Integer.valueOf(cols.get(1)); pos = 0; prePoint = null; } else if (cols.get(0).compareTo("LINE") == 0) { index++; RoadLink link = links.get(index); // link.segments.add(new Point2D.Double(Double.valueOf(cols.get(1)), // Double.valueOf(cols.get(2)))); // link.segments.add(new Point2D.Double(Double.valueOf(cols.get(3)), // Double.valueOf(cols.get(4)))); Segment seg = new Segment(); seg.start = new Point2D.Double(Double.valueOf(cols.get(1)), Double.valueOf(cols.get(2))); seg.end = new Point2D.Double(Double.valueOf(cols.get(3)), Double.valueOf(cols.get(4))); seg.length = seg.start.distance(seg.end); link.segments.add(seg); } else if (index >= 0) { if (prePoint == null) { prePoint = new Point2D.Double(Double.valueOf(cols.get(0)), Double.valueOf(cols.get(1))); } else { Segment seg = new Segment(); seg.start = prePoint; prePoint = new Point2D.Double(Double.valueOf(cols.get(0)), Double.valueOf(cols.get(1))); seg.end = prePoint; seg.length = seg.start.distance(seg.end); RoadLink link = links.get(index); link.segments.add(seg); } // RoadLink link = links.get(index); // link.segments.add(new Point2D.Double(Double.valueOf(cols.get(0)), // Double.valueOf(cols.get(1)))); } } return links; }
@Override public void unpairDevice(String deviceId) { pairedDevices.remove(deviceId); }
@Override public void pairDevice(String deviceId, String deviceName) { pairedDevices.put(deviceId, deviceName); }
@Override public String getDeviceName(String deviceId) { return isReceptionFromAnyDevice() ? null : pairedDevices.get(deviceId); }
@Override public boolean isAllowedDeviceId(String deviceId) { return isReceptionFromAnyDevice() || pairedDevices.containsKey(deviceId); }
@Override public Collection<String> getPairedDeviceIds() { return pairedDevices.keySet(); }