Esempio n. 1
0
  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();
  }
 @Override
 public void waitForPairing(PairingListener listener) {
   Preconditions.checkNotNull(listener);
   logger.info("Waiting for test notification to pair device");
   pairingListener = listener;
   waitingForPairing.set(true);
 }
Esempio n. 3
0
 /**
  * URL encodes a string
  *
  * @param plain
  * @return percent encoded string
  */
 public static String urlEncodeWrapper(String string) {
   Preconditions.checkNotNull(string, "Cannot encode null string");
   try {
     return URLEncoder.encode(string, UTF_8);
   } catch (UnsupportedEncodingException uee) {
     throw new IllegalStateException(ERROR_MSG, uee);
   }
 }
Esempio n. 4
0
  /**
   * Append given parameters to the query string of the url
   *
   * @param url the url to append parameters to
   * @param params any map
   * @return new url with parameters on query string
   */
  public static String appendParametersToQueryString(String url, Map<String, String> params) {
    Preconditions.checkNotNull(url, "Cannot append to null URL");
    String queryString = URLUtils.formURLEncodeMap(params);
    if (queryString.length() == 0) return url;

    // Check if there are parameters in the url already and use '&' instead of '?'
    url += url.indexOf(QUERY_STRING_SEPARATOR) != -1 ? PARAM_SEPARATOR : QUERY_STRING_SEPARATOR;
    url += queryString;
    return url;
  }
Esempio n. 5
0
 /**
  * Percent encodes a string
  *
  * @param plain
  * @return percent encoded string
  */
 public static String percentEncode(String string) {
   Preconditions.checkNotNull(string, "Cannot encode null string");
   try {
     String encoded = URLEncoder.encode(string, UTF_8);
     for (EncodingRule rule : ENCODING_RULES) {
       encoded = rule.apply(encoded);
     }
     return encoded;
   } catch (UnsupportedEncodingException uee) {
     throw new IllegalStateException(ERROR_MSG, uee);
   }
 }
Esempio n. 6
0
 /**
  * Turns a map into a form-url-encoded string (key=value&key2&key3=value)
  *
  * @param map any map
  * @return form-url-encoded string
  */
 public static String formURLEncodeMap(Map<String, String> map) {
   Preconditions.checkNotNull(map, "Cannot url-encode a null object");
   return (map.size() <= 0) ? EMPTY_STRING : doFormUrlEncode(map);
 }
Esempio n. 7
0
  public List<RoadLink> loadRoadNet(String mif, String mid) throws IOException {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(mif));
    Preconditions.checkArgument(!Strings.isNullOrEmpty(mid));

    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);
    }

    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;
  }