Package chapter02.s05

Examples of chapter02.s05.Vehicle


    final String OWNER = "Kubota";
    Vehicle[] vehicles = new Vehicle[VEHICLE_NUM];
   
    
    for(int i = 0; i < vehicles.length; i++) {
      vehicles[i] = new Vehicle();
      vehicles[i].setOwner(OWNER);
      vehicles[i].setSpeed(Math.random() * i);
      vehicles[i].setDirection(Math.random() * i);
    }
   
    LinkedList startNode = new LinkedList(vehicles[0]);
   
    LinkedList node = startNode;
    for(int i = 1; i < vehicles.length; i++) {
      node.setNext(new LinkedList(vehicles[i]));
      node = node.next;
    }
   
    node = startNode;
    while(node != null) {
      Vehicle output = (Vehicle)node.getValue();
      System.out.println("ID : " + output.getId());
      System.out.println("OWNER : " + output.getOwner());
      System.out.println("SPEED : " + output.getSpeed());
      System.out.println("DIRECTION : " + output.getDirection());
      System.out.println();
     
      node = node.next;
    }
   
View Full Code Here


    final String OWNER = "Kubota";
    Vehicle[] vehicles = new Vehicle[VEHICLE_NUM];
   
    
    for(int i = 0; i < vehicles.length; i++) {
      vehicles[i] = new Vehicle();
      vehicles[i].setOwner(OWNER);
      vehicles[i].setSpeed(Math.random() * i);
      vehicles[i].setDirection(Math.random() * i);
    }
   
    LinkedList startNode = new LinkedList(vehicles[0]);
   
    LinkedList node = startNode;
    for(int i = 1; i < vehicles.length; i++) {
      node.setNext(new LinkedList(vehicles[i]));
      node = node.next;
    }
   
    node = startNode;
    while(node != null) {
      Vehicle output = (Vehicle)node.getValue();
      System.out.println("ID : " + output.getId());
      System.out.println("OWNER : " + output.getOwner());
      System.out.println("SPEED : " + output.getSpeed());
      System.out.println("DIRECTION : " + output.getDirection());
      System.out.println();
     
      node = node.next;
    }
   
View Full Code Here

    final String OWNER = "Kubota";
    Vehicle[] vehicles = new Vehicle[VEHICLE_NUM];
   
    
    for(int i = 0; i < vehicles.length; i++) {
      vehicles[i] = new Vehicle();
      vehicles[i].setOwner(OWNER);
      vehicles[i].setSpeed(Math.random() * i);
      vehicles[i].setDirection(Math.random() * i);
    }
   
    LinkedList startNode = new LinkedList(vehicles[0]);
   
    LinkedList node = startNode;
    for(int i = 1; i < vehicles.length; i++) {
      node.setNext(new LinkedList(vehicles[i]));
      node = node.next;
    }
   
    node = startNode;
    while(node != null) {
      Vehicle output = (Vehicle)node.getValue();
      System.out.println("ID : " + output.getId());
      System.out.println("OWNER : " + output.getOwner());
      System.out.println("SPEED : " + output.getSpeed());
      System.out.println("DIRECTION : " + output.getDirection());
      System.out.println();
     
      node = node.next;
    }
   
View Full Code Here

    final String OWNER = "Kubota";
    Vehicle[] vehicles = new Vehicle[VEHICLE_NUM];
   
    
    for(int i = 0; i < vehicles.length; i++) {
      vehicles[i] = new Vehicle();
      vehicles[i].setOwner(OWNER);
      vehicles[i].setSpeed(Math.random() * i);
      vehicles[i].setDirection(Math.random() * i);
    }
   
    LinkedList startNode = new LinkedList(vehicles[0]);
   
    LinkedList node = startNode;
    for(int i = 1; i < vehicles.length; i++) {
      node.setNext(new LinkedList(vehicles[i]));
      node = node.next;
    }
   
    node = startNode;
    while(node != null) {
      Vehicle output = (Vehicle)node.getValue();
      System.out.println("ID : " + output.getId());
      System.out.println("OWNER : " + output.getOwner());
      System.out.println("SPEED : " + output.getSpeed());
      System.out.println("DIRECTION : " + output.getDirection());
      System.out.println();
     
      node = node.next;
    }
  }
View Full Code Here

    final String OWNER = "Kubota";
    Vehicle[] vehicles = new Vehicle[VEHICLE_NUM];
   
    
    for(int i = 0; i < vehicles.length; i++) {
      vehicles[i] = new Vehicle();
      vehicles[i].setOwner(OWNER);
      vehicles[i].setSpeed(Math.random() * i);
      vehicles[i].setDirection(Math.random() * i);
    }
   
    LinkedList startNode = new LinkedList(vehicles[0]);
   
    LinkedList node = startNode;
    for(int i = 1; i < vehicles.length; i++) {
      node.setNext(new LinkedList(vehicles[i]));
      node = node.next;
    }
   
    node = startNode;
    while(node != null) {
      Vehicle output = (Vehicle)node.getValue();
      System.out.println("ID : " + output.getId());
      System.out.println("OWNER : " + output.getOwner());
      System.out.println("SPEED : " + output.getSpeed());
      System.out.println("DIRECTION : " + output.getDirection());
      System.out.println();
     
      node = node.next;
    }
  }
View Full Code Here

        assertTrue("dynamic property".equals(obj.getProperty("x")));
        assertTrue(obj.getMetaClass().getAttribute(obj, "x") == newX3);
    }

    public void testMetaClassNameHandlingWithClosures() {
        final Tt1cgi obj = new Tt1cgi()// Test class implementing GroovyObject
        final Closure newX = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x";
            }
        };
        final Closure newX1 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x1";
            }
        };
        final Closure newX2 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x2";
            }
        };
        final Closure newX3 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x3";
            }
        };

        assertTrue(((Closure) obj.getProperty("x")).call() == obj.getX().call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == obj.x.call());
        assertTrue(obj.invokeMethod("x", new Object[]{}) == obj.x());

        obj.setProperty("x", newX);
        obj.getMetaClass().setAttribute(obj, "x", newX1);

        assertTrue(((Closure) obj.getProperty("x")).call() == newX.call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX1.call());

        obj.setX(newX2);
        obj.x = newX3;

        assertTrue(((Closure) obj.getProperty("x")).call() == newX2.call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX3.call());
    }
View Full Code Here

        assertTrue(((Closure) obj.getProperty("x")).call() == newX2.call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX3.call());
    }

    public void testMetaClassNameHandlingWithClosures1() {
        final Tt1cgi obj = new Tt1cgi() {
        }// repeat test with subclass
        final Closure newX = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x";
            }
        };
        final Closure newX1 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x1";
            }
        };
        final Closure newX2 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x2";
            }
        };
        final Closure newX3 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x3";
            }
        };

        assertTrue(((Closure) obj.getProperty("x")).call() == obj.getX().call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == obj.x.call());
        assertTrue(obj.invokeMethod("x", new Object[]{}) == obj.x());

        obj.setProperty("x", newX);
        obj.getMetaClass().setAttribute(obj, "x", newX1);

        assertTrue(((Closure) obj.getProperty("x")).call() == newX.call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX1.call());

        obj.setX(newX2);
        obj.x = newX3;

        assertTrue(((Closure) obj.getProperty("x")).call() == newX2.call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX3.call());
    }
View Full Code Here

        assertTrue(obj.getProperty("x") == newX2);
        assertTrue(obj.getMetaClass().getAttribute(obj, "x") == newX3);
    }

    public void testObjectSupportNameHandlingWitnClosureValues() {
        final Tt1cgo obj = new Tt1cgo()// Test subclass of GroovyObjectSupport
        final Closure newX = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x";
            }
        };
        final Closure newX1 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x1";
            }
        };
        final Closure newX2 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x2";
            }
        };
        final Closure newX3 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x3";
            }
        };

        assertTrue(((Closure) obj.getProperty("x")).call() == obj.getX().call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == obj.x.call());
        assertTrue(obj.invokeMethod("x", new Object[]{}) == obj.x());

        obj.setProperty("x", newX);
        obj.getMetaClass().setAttribute(obj, "x", newX1);

        assertTrue(((Closure) obj.getProperty("x")).call() == newX.call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX1.call());

        obj.setX(newX2);
        obj.x = newX3;

        assertTrue(((Closure) obj.getProperty("x")).call() == newX2.call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX3.call());
    }
View Full Code Here

        assertTrue(((Closure) obj.getProperty("x")).call() == newX2.call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX3.call());
    }

    public void testObjectSupportNameHandlingWitnClosureValuesi() {
        final Tt1cgo obj = new Tt1cgo() {
        }// repeat test with subclass
        final Closure newX = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x";
            }
        };
        final Closure newX1 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x1";
            }
        };
        final Closure newX2 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x2";
            }
        };
        final Closure newX3 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x3";
            }
        };

        assertTrue(((Closure) obj.getProperty("x")).call() == obj.getX().call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == obj.x.call());
        assertTrue(obj.invokeMethod("x", new Object[]{}) == obj.x());

        obj.setProperty("x", newX);
        obj.getMetaClass().setAttribute(obj, "x", newX1);

        assertTrue(((Closure) obj.getProperty("x")).call() == newX.call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX1.call());

        obj.setX(newX2);
        obj.x = newX3;

        assertTrue(((Closure) obj.getProperty("x")).call() == newX2.call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX3.call());
    }
View Full Code Here

        assertTrue(((Closure) obj.getProperty("x")).call() == newX2.call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX3.call());
    }

    public void testMetaClassNameHandling() {
        final Tt1gi obj = new Tt1gi()// Test class implementing GroovyObject
        final String newX = "new x";
        final String newX1 = "new x1";
        final String newX2 = "new x2";
        final String newX3 = "new x3";

        assertTrue("dynamic property".equals(obj.getProperty("x")));
        assertTrue(obj.getMetaClass().getAttribute(obj, "x") == obj.x);
        assertTrue("dynamic method".equals(obj.invokeMethod("x", new Object[]{})));

        obj.setProperty("x", newX);
        obj.getMetaClass().setAttribute(obj, "x", newX1);

        assertTrue("dynamic property".equals(obj.getProperty("x")));
        assertTrue(obj.getMetaClass().getAttribute(obj, "x") == newX1);

        obj.setX(newX2);
        obj.x = newX3;

        assertTrue("dynamic property".equals(obj.getProperty("x")));
        assertTrue(obj.getMetaClass().getAttribute(obj, "x") == newX3);
    }
View Full Code Here

TOP

Related Classes of chapter02.s05.Vehicle

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.