Beispiel #1
0
 public static void main(String args[]) {
   Scanner sc = new Scanner(System.in);
   System.out.print("Enter the hours:  ");
   int h = sc.nextInt();
   System.out.print("Enter the Minutes: ");
   int m = sc.nextInt();
   Time t = new Time();
   t.initialize(h, m);
   t.display();
   int a = t.timeMinutes();
   double b = t.timeHours();
   System.out.println("Time in Minutes: " + a);
   System.out.print("Time in Hours: " + b);
 }
Beispiel #2
0
  @Test
  public void testTimeConverter() {
    String sql = "select current_time as col1 from (values(0))";

    Time sqlTime = sql2o.createQuery(sql).executeScalar(Time.class);
    assertThat(sqlTime, is(notNullValue()));
    assertTrue(sqlTime.getTime() > 0);

    Date date = sql2o.createQuery(sql).executeScalar(Date.class);
    assertThat(date, is(notNullValue()));

    LocalTime jodaTime = sql2o.createQuery(sql).executeScalar(LocalTime.class);
    assertTrue(jodaTime.getMillisOfDay() > 0);
    assertThat(jodaTime.getHourOfDay(), is(equalTo(new LocalTime().getHourOfDay())));
  }
Beispiel #3
0
  // enter a world map square
  //  - if there is a portal to a special location then use it
  //  - else create the appropraite outdoor area map
  //
  public static void exitWorldMap(Map m, int tx, int ty) {
    Thing h = Game.hero();

    // record movement time
    Time.logTime(Movement.moveCost(m, h, tx, ty));

    Thing p = m.getFlaggedObject(tx, ty, "IsPortal");
    if (p != null) {
      Portal.travel(p, h);
    } else {
      // put hero into a local area map
      Map nm = WorldMap.createArea(m, tx, ty);

      // phantom Portal
      p = Portal.create();
      Thing t = nm.getEntrance();
      Portal.setDestination(p, nm, t.x, t.y);

      // could build a portal here so we can return to exact location map
      // Don't think we really want this though
      //   addThing(p,tx,ty);

      Portal.travel(p, h);
    }
  }
Beispiel #4
0
 static byte[] encode(char[] cc, Charset cs, boolean testDirect, Time t) throws Exception {
   ByteBuffer bbf;
   CharBuffer cbf;
   CharsetEncoder enc = cs.newEncoder();
   String csn = cs.name();
   if (testDirect) {
     bbf = ByteBuffer.allocateDirect(cc.length * 4);
     cbf = ByteBuffer.allocateDirect(cc.length * 2).asCharBuffer();
     cbf.put(cc).flip();
   } else {
     bbf = ByteBuffer.allocate(cc.length * 4);
     cbf = CharBuffer.wrap(cc);
   }
   CoderResult cr = null;
   long t1 = System.nanoTime() / 1000;
   for (int i = 0; i < iteration; i++) {
     cbf.rewind();
     bbf.clear();
     enc.reset();
     cr = enc.encode(cbf, bbf, true);
   }
   long t2 = System.nanoTime() / 1000;
   t.t = (t2 - t1) / iteration;
   if (cr != CoderResult.UNDERFLOW) {
     System.out.println("ENC-----------------");
     int pos = cbf.position();
     System.out.printf("  cr=%s, cbf.pos=%d, cc[pos]=%x%n", cr.toString(), pos, cc[pos] & 0xffff);
     throw new RuntimeException("Encoding err: " + csn);
   }
   byte[] bb = new byte[bbf.position()];
   bbf.flip();
   bbf.get(bb);
   return bb;
 }
Beispiel #5
0
 private static Time shift(Time v) {
   if (v == null) {
     return null;
   }
   long time = v.getTime();
   int offset = TimeZone.getDefault().getOffset(time);
   return new Time((time + offset) % DateTimeUtil.MILLIS_PER_DAY);
 }
Beispiel #6
0
 static char[] decode(byte[] bb, Charset cs, boolean testDirect, Time t) throws Exception {
   String csn = cs.name();
   CharsetDecoder dec = cs.newDecoder();
   ByteBuffer bbf;
   CharBuffer cbf;
   if (testDirect) {
     bbf = ByteBuffer.allocateDirect(bb.length);
     cbf = ByteBuffer.allocateDirect(bb.length * 2).asCharBuffer();
     bbf.put(bb);
   } else {
     bbf = ByteBuffer.wrap(bb);
     cbf = CharBuffer.allocate(bb.length);
   }
   CoderResult cr = null;
   long t1 = System.nanoTime() / 1000;
   for (int i = 0; i < iteration; i++) {
     bbf.rewind();
     cbf.clear();
     dec.reset();
     cr = dec.decode(bbf, cbf, true);
   }
   long t2 = System.nanoTime() / 1000;
   t.t = (t2 - t1) / iteration;
   if (cr != CoderResult.UNDERFLOW) {
     System.out.println("DEC-----------------");
     int pos = bbf.position();
     System.out.printf(
         "  cr=%s, bbf.pos=%d, bb[pos]=%x,%x,%x,%x%n",
         cr.toString(),
         pos,
         bb[pos++] & 0xff,
         bb[pos++] & 0xff,
         bb[pos++] & 0xff,
         bb[pos++] & 0xff);
     throw new RuntimeException("Decoding err: " + csn);
   }
   char[] cc = new char[cbf.position()];
   cbf.flip();
   cbf.get(cc);
   return cc;
 }
Beispiel #7
0
  public static void main(String[] args) {

    ArrayList list = new ArrayList();
    long time = Time.addTimeList(list);
    long search = Time.searchTimeList(list);
    long removal = Time.removeTimeList(list);
    long sum = Time.total(time, search, removal);
    System.out.println("add to ArrayList " + time);
    System.out.println("Search in ArrayList " + search);
    System.out.println("Removal from ArrayList " + removal);
    System.out.println("Total time spent for ArrayList " + sum);

    LinkedList linked = new LinkedList();
    long time2 = Time.addTimeLinked(linked);
    long search2 = Time.searchTimeLinked(linked);
    long removal2 = Time.removeTimeLinked(linked);
    long sum2 = Time.total2(time2, search2, removal2);
    System.out.println("add to LinkedList " + time2);
    System.out.println("Search in LinkedList " + search2);
    System.out.println("Removal from LinkedList " + removal2);
    System.out.println("Total time spend for LinkedList " + sum2);

    HashSet hash = new HashSet();
    long time3 = Time.addTimeHash(hash);
    long search3 = Time.searchTimeHash(hash);
    long removal3 = Time.removeTimeHash(hash);
    long sum3 = Time.total3(time3, search3, removal3);
    System.out.println("add to HashSet " + time3);
    System.out.println("Search in HashSet " + search3);
    System.out.println("Removal from HasSet " + removal3);
    System.out.println("Total time spend for HashSet " + sum3);

    TreeSet tree = new TreeSet();
    long time4 = Time.TimeTree(tree);
    long search4 = Time.searchTimeTree(tree);
    long removal4 = Time.removeTimeTree(tree);
    long sum4 = Time.total4(time4, search4, removal4);
    System.out.println("add to TreeSet " + time4);
    System.out.println("Search in TreeSet " + search4);
    System.out.println("Removal from TreeSet " + removal4);
    System.out.println("Total time spend for TreeSet " + sum4);

    if (sum < sum2) {
      if (sum < sum3) {
        if (sum < sum4) {
          System.out.println("ArrayList is the fastest");
        } else {
          if (sum2 < sum3) {
            if (sum2 < sum4) {
              System.out.println("LinkedList is the fastest");
            } else {
              if (sum3 < sum4) {
                System.out.println("HashSet is the fastest");
              } else {
                System.out.println("TreeSet is the fastest");
              }
            }
          }
        }
      }
    }
  }
Beispiel #8
0
 public void timeEvent(Time arg0) {
   // System.out.println("time " + arg0.getTime());
   time = arg0.getTime();
 }
  /**
   * Insert all service in services table
   *
   * @param noms
   * @throws SQLException
   */
  public static void insertStations(List<String[]> pdvs) throws SQLException {

    int idPdv;
    String nom = "";
    String adresse = "";
    String ville = "";
    String cp = "";
    String type_route;
    String[] ouvert = new String[3];
    String[] fermer = new String[3];
    Time hor_Ouv = null;
    hor_Ouv.valueOf("00:00:00");
    Time hor_Ferm = null;
    hor_Ferm.valueOf("00:00:00");
    double latitudePdv;
    double longitudePdv;

    String path = "src\\DAL\\StationsNOM.csv";
    List<String> nomStations = LectureFichier.readTXT(path);

    Random rand = new Random();
    int nbrand = 2;

    String requete =
        "INSERT INTO stations "
            + "(id_Station,Nom,Adresse,Ville,CP,Type_route,Horaire_ouverture,Horaire_fermeture,latitude,longitude) "
            + "VALUES(?,?,?,?,?,?,?,?,?,?)";
    // int[] count= new int[0];

    Connection connection = ConnexionManager.GetInstance().GetConnection();
    for (String[] pdv : pdvs) {

      if (!pdv[0].equals("id")) {
        idPdv = Integer.parseInt(pdv[0]);
        // integration des noms g�n�r� al�atoirement
        nbrand = rand.nextInt(nomStations.size() - 2) + 1;
        nom = nomStations.get(nbrand);
        adresse = pdv[1];
        ville = pdv[2];
        cp = pdv[3];
        type_route = pdv[4];
        ouvert = pdv[5].split(":");
        fermer = pdv[6].split(":");
        // fermer = pdv[6].replace(':', '-');
        hor_Ouv =
            new Time(
                Integer.parseInt(ouvert[0]),
                Integer.parseInt(ouvert[1]),
                Integer.parseInt(ouvert[2]));
        hor_Ferm =
            new Time(
                Integer.parseInt(fermer[0]),
                Integer.parseInt(fermer[1]),
                Integer.parseInt(fermer[2]));
        latitudePdv = Double.parseDouble(pdv[7]);
        longitudePdv = Double.parseDouble(pdv[8]);

        try {
          PreparedStatement requeteSql = connection.prepareStatement(requete);
          requeteSql.setInt(1, idPdv);
          requeteSql.setString(2, nom);
          requeteSql.setString(3, adresse);
          requeteSql.setString(4, ville);
          requeteSql.setString(5, cp);
          requeteSql.setString(6, type_route);
          requeteSql.setTime(7, hor_Ouv);
          requeteSql.setTime(8, hor_Ferm);
          requeteSql.setDouble(9, latitudePdv);
          requeteSql.setDouble(10, longitudePdv);
          requeteSql.addBatch();
          int[] count = requeteSql.executeBatch();
          // requeteSql.executeBatch();
          // System.out.println(count.length);
        } catch (SQLException sqle) {
          // TODO Auto-generated catch block

          ConnexionManager.GetInstance().GetConnection().rollback();

          sqle.printStackTrace();
        }
      }
    }
  }
Beispiel #10
0
  public void testGetTime() throws Exception {

    con.createStatement()
        .executeUpdate(
            "INSERT INTO testtimezone(tstz,ts,t,tz) VALUES('2005-01-01 15:00:00 +0300', '2005-01-01 15:00:00', '15:00:00', '15:00:00 +0300')");

    PreparedStatement ps = con.prepareStatement("SELECT tstz,ts,t,tz from testtimezone");
    for (int i = 0; i < PREPARE_THRESHOLD; i++) {
      ResultSet rs = ps.executeQuery();

      assertTrue(rs.next());
      checkDatabaseContents(
          "SELECT tstz::text,ts::text,t::text,tz::text,d::text from testtimezone",
          new String[] {
            "2005-01-01 12:00:00+00", "2005-01-01 15:00:00", "15:00:00", "15:00:00+03"
          });

      Time t;

      // timestamptz: 2005-01-01 15:00:00+03
      t = rs.getTime(1);
      assertEquals(
          43200000L, t.getTime()); // 2005-01-01 13:00:00 +0100 -> 1970-01-01 13:00:00 +0100
      t = rs.getTime(1, cUTC);
      assertEquals(
          43200000L, t.getTime()); // 2005-01-01 12:00:00 +0000 -> 1970-01-01 12:00:00 +0000
      t = rs.getTime(1, cGMT03);
      assertEquals(
          43200000L, t.getTime()); // 2005-01-01 15:00:00 +0300 -> 1970-01-01 15:00:00 +0300
      t = rs.getTime(1, cGMT05);
      assertEquals(
          43200000L, t.getTime()); // 2005-01-01 07:00:00 -0500 -> 1970-01-01 07:00:00 -0500
      t = rs.getTime(1, cGMT13);
      assertEquals(
          -43200000L, t.getTime()); // 2005-01-02 01:00:00 +1300 -> 1970-01-01 01:00:00 +1300

      // timestamp: 2005-01-01 15:00:00
      t = rs.getTime(2);
      assertEquals(50400000L, t.getTime()); // 1970-01-01 15:00:00 +0100
      t = rs.getTime(2, cUTC);
      assertEquals(54000000L, t.getTime()); // 1970-01-01 15:00:00 +0000
      t = rs.getTime(2, cGMT03);
      assertEquals(43200000L, t.getTime()); // 1970-01-01 15:00:00 +0300
      t = rs.getTime(2, cGMT05);
      assertEquals(72000000L, t.getTime()); // 1970-01-01 15:00:00 -0500
      t = rs.getTime(2, cGMT13);
      assertEquals(7200000L, t.getTime()); // 1970-01-01 15:00:00 +1300

      // time: 15:00:00
      t = rs.getTime(3);
      assertEquals(50400000L, t.getTime()); // 1970-01-01 15:00:00 +0100
      t = rs.getTime(3, cUTC);
      assertEquals(54000000L, t.getTime()); // 1970-01-01 15:00:00 +0000
      t = rs.getTime(3, cGMT03);
      assertEquals(43200000L, t.getTime()); // 1970-01-01 15:00:00 +0300
      t = rs.getTime(3, cGMT05);
      assertEquals(72000000L, t.getTime()); // 1970-01-01 15:00:00 -0500
      t = rs.getTime(3, cGMT13);
      assertEquals(7200000L, t.getTime()); // 1970-01-01 15:00:00 +1300

      // timetz: 15:00:00+03
      t = rs.getTime(4);
      assertEquals(43200000L, t.getTime()); // 1970-01-01 13:00:00 +0100
      t = rs.getTime(4, cUTC);
      assertEquals(43200000L, t.getTime()); // 1970-01-01 12:00:00 +0000
      t = rs.getTime(4, cGMT03);
      assertEquals(43200000L, t.getTime()); // 1970-01-01 15:00:00 +0300
      t = rs.getTime(4, cGMT05);
      assertEquals(43200000L, t.getTime()); // 1970-01-01 07:00:00 -0500
      t = rs.getTime(4, cGMT13);
      assertEquals(-43200000L, t.getTime()); // 1970-01-01 01:00:00 +1300
      rs.close();
    }
  }