public static void fromCRAWDAD(
      LinkTrace links,
      InputStream in,
      double timeMul,
      long ticsPerSecond,
      long offset,
      IdGenerator idGen)
      throws IOException {

    StatefulWriter<LinkEvent, Link> linkWriter = links.getWriter();
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String line;

    while ((line = br.readLine()) != null) {
      String[] elems = line.split("[ \t]+");
      Integer id1 = idGen.getInternalId(elems[0]);
      Integer id2 = idGen.getInternalId(elems[1]);
      long begin = (long) (Long.parseLong(elems[2]) * timeMul) + offset;
      long end = (long) (Long.parseLong(elems[3]) * timeMul) + offset;
      linkWriter.queue(begin, new LinkEvent(id1, id2, LinkEvent.UP));
      linkWriter.queue(end, new LinkEvent(id1, id2, LinkEvent.DOWN));
    }
    linkWriter.flush();
    linkWriter.setProperty(Trace.timeUnitKey, Units.toTimeUnit(ticsPerSecond));
    idGen.writeTraceInfo(linkWriter);
    linkWriter.close();
    br.close();
  }
示例#2
0
  // read all defense missile from given defense destructor
  protected void readDefenseDestructorFromGivenDestructor(Element destructor) {
    NamedNodeMap attributes = destructor.getAttributes();
    String id = "";
    String type;

    Attr attr = (Attr) attributes.item(0);

    String name = attr.getNodeName();

    // if it's iron dome
    if (name.equals("id")) {
      id = attr.getNodeValue();

      // update id's in the war
      IdGenerator.updateIronDomeId(id);
      // add to war
      war.addIronDome(id);

      NodeList destructdMissiles = destructor.getElementsByTagName("destructdMissile");
      readDefensDestructoreMissiles(destructdMissiles, id);

      // if it's launcher destructor
    } else {
      if (name.equals("type")) {
        type = attr.getNodeValue();

        // add to war
        id = war.addDefenseLauncherDestructor(type);

        NodeList destructedLanuchers = destructor.getElementsByTagName("destructedLanucher");
        readDefensDestructoreMissiles(destructedLanuchers, id);
      }
    }
  }
示例#3
0
  // read enemy launchers and their missiles form XML
  protected void readEnemyLaunchers() {
    NodeList launchers = root.getElementsByTagName("launcher");

    for (int i = 0; i < launchers.getLength(); i++) {
      Element tempLauncher = (Element) launchers.item(i);

      String idLauncher = tempLauncher.getAttribute("id");
      boolean isHidden = Boolean.parseBoolean(tempLauncher.getAttribute("isHidden"));

      // add to the war
      war.addEnemyLauncher(idLauncher, isHidden);
      IdGenerator.updateEnemyLauncherId(idLauncher);

      NodeList missiles = tempLauncher.getElementsByTagName("missile");

      // read all missiles
      readMissilesForGivenLauncher(missiles, idLauncher);
    }

    // update the id's in the war
    IdGenerator.updateFinalEnemyMissileId();
    IdGenerator.updateFinalEnemyLauncherId();
  }
示例#4
0
  // read all defense destructors and their missiles from XML
  protected void readDefenseDestructors() {
    ;
    NodeList destructors = root.getElementsByTagName("destructor");

    int destructorsSize = destructors.getLength();
    for (int i = 0; i < destructorsSize; i++) {
      Element destructor = (Element) destructors.item(i);

      readDefenseDestructorFromGivenDestructor(destructor);
    }

    // update the id's in the war
    IdGenerator.updateFinalIronDomeId();
  }
示例#5
0
 /**
  * 通过IdGenerator产生的id
  *
  * @return 新的id
  */
 String getOneID() {
   return IdGenerator.createNewId();
 }