Package de.hpi.eworld.model.db.data

Examples of de.hpi.eworld.model.db.data.TrafficLightModel$NodeObserver


    // restore
    modelManager.clearModel();
    PersistenceManager.getInstance().loadFromFile(EWD_FILE);
    for( ModelElement modelElement : modelManager.getAllModelElements()){
      if (modelElement.getClass().equals(TrafficLightModel.class)) {
        TrafficLightModel restoredTl1 = (TrafficLightModel) modelElement;
        Assert.assertEquals(tl1.getDurations().length, restoredTl1.getDurations().length);
        Assert.assertEquals(tl1.getNoOfIncomingEdges(), restoredTl1.getNoOfIncomingEdges());
        Assert.assertEquals(tl1.getNoOfPhases(), restoredTl1.getNoOfPhases());
        Assert.assertEquals(tl1.getPosition().getLatitude(), restoredTl1.getPosition().getLatitude(), 0.1);
        Assert.assertEquals(tl1.getUsedBy().size(), restoredTl1.getUsedBy().size());
      }
    }
   
    //cleanup
    Assert.assertTrue(FileSysUtils.deleteFile(EWD_FILE));
View Full Code Here


          if (curNode.getChildNodes().item(j).getNodeName().equals("key")) {
            curID = curNode.getChildNodes().item(j).getTextContent();
          }
        }
        NodeModel existingNode = this.nodes.get(curID);
        TrafficLightModel newTL = new TrafficLightModel(existingNode);

//        for (EdgeModel e : existingNode.getUsedBy()) {
//          newTL.addUsedBy(e);
//          if (e.getFromNode().equals(existingNode)) {
//            e.setFromNode(newTL);
View Full Code Here

          } else if (curNode.getChildNodes().item(j).getNodeName().equals("phaseno")) {
            phaseno = Integer.parseInt(curNode.getChildNodes().item(j).getTextContent());
          }
        }
//        TrafficLightModel existingNode = (TrafficLightModel) this.nodes.get(curID);
        TrafficLightModel existingNode = trafficLights.get(curID);
        int offset = 0;

        int[] durations = new int[phaseno];
        // iterate phases
        NodeList tllogicchilds = curNode.getChildNodes();
        for (int j = 0; j < tllogicchilds.getLength(); j++) {
          if (tllogicchilds.item(j).getNodeName().equals("phase")) {
            String dAttr = tllogicchilds.item(j).getAttributes().getNamedItem("duration")
                .getTextContent();
            int dur = Integer.parseInt(dAttr);
            durations[offset] = dur;
            offset++;
          }
        }
        existingNode.setDurations(durations);

        // build logic
        HashMap<EdgeModel, TrafficLightStateList> dl = new HashMap<EdgeModel, TrafficLightStateList>();

        existingNode.setNoOfPhases(phaseno);

        for (int j = 0; j < tllogicchilds.getLength(); j++) {
          if (tllogicchilds.item(j).getNodeName().equals("phase")) {

            String phase = tllogicchilds.item(j).getAttributes().getNamedItem("phase")
                .getTextContent();
            String brake = tllogicchilds.item(j).getAttributes().getNamedItem("brake")
                .getTextContent();
            String yellow = tllogicchilds.item(j).getAttributes().getNamedItem("yellow")
                .getTextContent();

            int k = phase.length();
            int noOutgoing = existingNode.getUsedBy().size()
                - existingNode.getNoOfIncomingEdges();
            int countIncomingEdge = 0;
            for (EdgeModel e : existingNode.getUsedBy()) {
              // incoming edge...
              if (e.getToNode().equals(existingNode)) {
                if (dl.get(e) == null) {
                  dl.put(e, new TrafficLightStateList());
                }

                int c = k - countIncomingEdge * noOutgoing - 1;
                String phaseCode = phase.substring(c, c + 1) + brake.substring(c, c + 1)
                    + yellow.substring(c, c + 1);

                if (phaseCode.equals("010")) { // red
                  dl.get(e).add(new TrafficLightStateListEntry(TrafficLightState.Red));
                } else if (phaseCode.equals("011")) { // yellow
                  dl.get(e).add(new TrafficLightStateListEntry(TrafficLightState.Yellow));
                } else if (phaseCode.equals("110") || phaseCode.equals("100")) { // green
                  dl.get(e).add(new TrafficLightStateListEntry(TrafficLightState.Green));
                }

                countIncomingEdge++;
              }
            }

            // System.out.println("phase-length: " + k +
            // "  outgoing:" + noOutgoing + " incoming:"
            // + existingNode.getNoOfIncomingEdges());
          }
        }
        existingNode.setDefaultLogic(dl);
        current++;
        this.setChanged();
        this.notifyObservers(new ObserverNotification(NotificationType.progress,
            (current/100)*all, "Build traffic light logic"));
        this.clearChanged();
View Full Code Here

      Logger.getLogger(getClass()).debug(
          "TrafficLight could not be dropped, no crossing under the cursor at "
              + scrolledPoint);
      return null;
    }
    return new TrafficLightModel(crossing);
  }
View Full Code Here

   
    for(String id : nodes.keySet()) {
      MyNode n = nodes.get(id);
      NodeModel newNode = new NodeModel(n.lat, n.lon);
      if (n.isTrafficLight){
        TrafficLightModel trafficLight = new TrafficLightModel(newNode);
        eTrafficLights.put(id, trafficLight);
      }
//      if (n.isTrafficLight)
//        newNode = new TrafficLightModel(n.lat, n.lon);
//      else
View Full Code Here

TOP

Related Classes of de.hpi.eworld.model.db.data.TrafficLightModel$NodeObserver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.