Пример #1
0
  private synchronized void refreshWormholes(
      Map<String, List<Wormhole>> r, QuadrantProvider quads) {
    r.clear();
    final String QUERY = "v/0/alle/json/"; // $NON-NLS-1$
    final String result = this.performRequest(QUERY);
    if (result == "") { // $NON-NLS-1$
      return;
    }
    final Gson gson = new GsonBuilder().setDateFormat(API_DATE_FORMAT).create();
    final WLSWormhole[] holes = gson.fromJson(result, WLSWormhole[].class);

    for (final WLSWormhole hole : holes) {
      final Quadrant sourceQuadrant = quads.getQuadrant(hole.von_quadrant);
      final Quadrant targetQuadrant = quads.getQuadrant(hole.nach_quadrant);

      hole.source = sourceQuadrant.getSector(hole.von_x, hole.von_y);
      hole.target = targetQuadrant.getSector(hole.nach_x, hole.nach_y);
      hole.loadRequired = LoadRequired.parse(hole.geladen);
      final Matcher m = UNLOAD_PATTERN.matcher(hole.entladung);
      if (m.matches()) {
        hole.minUnload = RegexUtils.subint(hole.entladung, m, 1);
        hole.maxUnload = RegexUtils.subint(hole.entladung, m, 2);
      }

      List<Wormhole> list = r.get(hole.von_quadrant);
      if (list == null) {
        list = new ArrayList<>();
        r.put(hole.von_quadrant, list);
      }
      list.add(hole);
    }
  }
Пример #2
0
 @Override
 public List<Wormhole> getWormholes(Quadrant quadrant, QuadrantProvider quads) {
   if (this.quadHoleCache.isEmpty()) {
     this.refreshWormholes(this.quadHoleCache, quads);
   }
   final List<Wormhole> wormholes = this.quadHoleCache.get(quadrant.getName());
   if (wormholes == null) {
     return Collections.emptyList();
   }
   return wormholes;
 }