예제 #1
0
 // -----------------------------------------------------------------------
 // isSupportedBy(TemporalAccessor temporal) and getFrom(TemporalAccessor temporal)
 // -----------------------------------------------------------------------
 @DataProvider(name = "fieldAndAccessor")
 Object[][] data_fieldAndAccessor() {
   return new Object[][] {
     {YEAR, LocalDate.of(2000, 2, 29), true, 2000},
     {YEAR, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 2000},
     {MONTH_OF_YEAR, LocalDate.of(2000, 2, 29), true, 2},
     {MONTH_OF_YEAR, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 2},
     {DAY_OF_MONTH, LocalDate.of(2000, 2, 29), true, 29},
     {DAY_OF_MONTH, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 29},
     {DAY_OF_YEAR, LocalDate.of(2000, 2, 29), true, 60},
     {DAY_OF_YEAR, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 60},
     {HOUR_OF_DAY, LocalTime.of(5, 4, 3, 200), true, 5},
     {HOUR_OF_DAY, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 5},
     {MINUTE_OF_DAY, LocalTime.of(5, 4, 3, 200), true, 5 * 60 + 4},
     {MINUTE_OF_DAY, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 5 * 60 + 4},
     {MINUTE_OF_HOUR, LocalTime.of(5, 4, 3, 200), true, 4},
     {MINUTE_OF_HOUR, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 4},
     {SECOND_OF_DAY, LocalTime.of(5, 4, 3, 200), true, 5 * 3600 + 4 * 60 + 3},
     {SECOND_OF_DAY, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 5 * 3600 + 4 * 60 + 3},
     {SECOND_OF_MINUTE, LocalTime.of(5, 4, 3, 200), true, 3},
     {SECOND_OF_MINUTE, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 3},
     {NANO_OF_SECOND, LocalTime.of(5, 4, 3, 200), true, 200},
     {NANO_OF_SECOND, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 200},
     {YEAR, LocalTime.of(5, 4, 3, 200), false, -1},
     {MONTH_OF_YEAR, LocalTime.of(5, 4, 3, 200), false, -1},
     {DAY_OF_MONTH, LocalTime.of(5, 4, 3, 200), false, -1},
     {DAY_OF_YEAR, LocalTime.of(5, 4, 3, 200), false, -1},
     {HOUR_OF_DAY, LocalDate.of(2000, 2, 29), false, -1},
     {MINUTE_OF_DAY, LocalDate.of(2000, 2, 29), false, -1},
     {MINUTE_OF_HOUR, LocalDate.of(2000, 2, 29), false, -1},
     {SECOND_OF_DAY, LocalDate.of(2000, 2, 29), false, -1},
     {SECOND_OF_MINUTE, LocalDate.of(2000, 2, 29), false, -1},
     {NANO_OF_SECOND, LocalDate.of(2000, 2, 29), false, -1},
   };
 }
예제 #2
0
  @SuppressWarnings("unchecked")
  @Override
  public void readExternal(ObjectInput arg0) throws IOException, ClassNotFoundException {
    createdDate = (LocalDate) arg0.readObject();
    createdTime = (LocalTime) arg0.readObject();
    user = (User) arg0.readObject();
    serveAtDate = (LocalDate) arg0.readObject();
    serveAtTime = (LocalTime) arg0.readObject();
    active = (boolean) arg0.readObject();
    number = (String) arg0.readObject();
    orderedMeals = (ArrayList<MealAndQuantity>) arg0.readObject();

    sspCreatedDate = new SimpleStringProperty(createdDate.toString());
    sspCreatedTime = new SimpleStringProperty(createdTime.toString());
    sspOrderedMeals = new SimpleStringProperty();
    sspUserName = new SimpleStringProperty(user.getUserName().get());
    sspNumber = new SimpleStringProperty(number.toString());
    sspServeAtDate = new SimpleStringProperty(serveAtDate.toString());
    sspServeAtTime = new SimpleStringProperty(serveAtTime.toString());
    sspPrice = new SimpleStringProperty();

    sspCreatedAtCompact =
        new SimpleStringProperty(createdDate.toString() + " " + createdTime.toString());
    sspServeAtCompact =
        new SimpleStringProperty(serveAtDate.toString() + " " + serveAtTime.toString());
  }
  private void asyncButtonHandler(ActionEvent event) {

    this.asyncButton.setDisable(true);
    this.asyncLabel.setText(
        String.format("started at %s", LocalTime.now().format(JavaFXClass.TIME_FORMATTER)));

    new Thread(
            () -> {
              Future<LocalTime> task = this.asyncExecutor.submit(this::asyncTask);

              try {
                LocalTime finished = task.get(JavaFXClass.ASYNC_SECONDS_ABORT, TimeUnit.SECONDS);

                Platform.runLater(
                    () -> {
                      this.asyncLabel.setText(
                          String.format(
                              "finished at %s", finished.format(JavaFXClass.TIME_FORMATTER)));
                      this.asyncButton.setDisable(false);
                    });

              } catch (TimeoutException ex) {
                Platform.runLater(
                    () -> {
                      this.asyncLabel.setText(
                          String.format("aborted after %ss", JavaFXClass.ASYNC_SECONDS_ABORT));
                      this.asyncButton.setDisable(false);
                    });

              } catch (ExecutionException | InterruptedException ex) {
                ex.printStackTrace();
              }
            })
        .start();
  }
예제 #4
0
 @Override
 public void parse(Message m) {
   String target = m.param();
   if (!m.param().startsWith("#")) target = m.sender();
   if (m.trailing().equals("TIME")) {
     String time =
         String.format(
             "%s %02d:%02d:%02d ",
             LocalDate.now().toString(),
             LocalTime.now().getHour(),
             LocalTime.now().getMinute(),
             LocalTime.now().getSecond());
     m.notice(m.sender(), String.format("TIME %s", time));
   }
   if (m.command().equals("PRIVMSG")) {
     if (m.botCommand().equals("time")) {
       if (m.hasBotParams()) {
         for (int i = 0; i < m.botParamsArray().length; i++) {
           m.pm(m.botParamsArray()[i], "TIME");
           requests.put(m.botParamsArray()[i], target);
         }
       }
     }
   }
   if (m.command().equals("NOTICE")) {
     if (requests.containsKey(m.sender())) {
       if (m.trailing().startsWith("TIME")) {
         String version = m.trailing().substring(5, m.trailing().length() - 1);
         Server.say(requests.get(m.sender()), "[" + m.sender() + "] Current Time: " + version);
         requests.remove(m.sender());
       }
     }
   }
 }
 @Override
 public int hashCode() {
   int result = bound.hashCode();
   result = 31 * result + from.hashCode();
   result = 31 * result + till.hashCode();
   return result;
 }
  @Test
  public void checkRulePassengerTime() {
    List<PassengerGenerationRule> workDayRulesOfGagarina = new ArrayList<>();
    workDayRulesOfGagarina.add(
        PassengerGenerationRule.of(8, LocalTime.of(6, 0), LocalTime.of(6, 0), LocalTime.of(0, 15)));
    //        workDayRulesOfGagarina.add(PassengerGenerationRule.of(
    //                4, LocalTime.of(9, 0), LocalTime.of(13, 0), LocalTime.of(0, 17))
    //        );
    //        workDayRulesOfGagarina.add(PassengerGenerationRule.of(
    //                2, LocalTime.of(13, 0), LocalTime.of(16, 0), LocalTime.of(0, 17))
    //        );
    //        workDayRulesOfGagarina.add(PassengerGenerationRule.of(
    //                8, LocalTime.of(16, 0), LocalTime.of(19, 0), LocalTime.of(0, 15))
    //        );
    //        workDayRulesOfGagarina.add(PassengerGenerationRule.of(
    //                4, LocalTime.of(19, 0), LocalTime.of(23, 0), LocalTime.of(0, 15))
    //        );

    PassengerGenerationRuleList item =
        PassengerGenerationRuleList.of(HOLIDAY, workDayRulesOfGagarina);

    Set<ConstraintViolation<PassengerGenerationRuleList>> constraintViolations =
        validator.validate(item, ImitationSourceSequence.class);
    constraintViolations.forEach(System.out::println);

    assertEquals(1, constraintViolations.size());
    assertEquals(
        "{incorrect rule passenger generation time}",
        constraintViolations.iterator().next().getMessage());
  }
  @RequestMapping(value = "/insertRoute.do", method = RequestMethod.POST)
  public ModelAndView insertRoute(
      @RequestParam(value = ROUTE_NUMBER) String routeNumber,
      @RequestParam(value = STATION_LEAVING_STATION) String leavingStation,
      @RequestParam(value = STATION_ARRIVAL_STATION) String arrivalStation,
      @RequestParam(value = STATION_LEAVING_HOUR) String leavingHH,
      @RequestParam(value = STATION_LEAVING_MINUTE) String leavingMM,
      @RequestParam(value = STATION_ARRIVAL_HOUR) String arrivalHH,
      @RequestParam(value = STATION_ARRIVAL_MINUTE) String arrivalMM) {

    Integer routeNum = routeNumberCheck(routeNumber);
    if (routeNum != null) {
      Route route = new Route();
      route.setRouteNumber(routeNum);
      route.setLeavingStation(leavingStation);
      route.setArrivalStation(arrivalStation);
      route.setLeavingTime(LocalTime.of(Integer.parseInt(leavingHH), Integer.parseInt(leavingMM)));
      route.setArrivalTime(LocalTime.of(Integer.parseInt(arrivalHH), Integer.parseInt(arrivalMM)));
      if (iRouteService.insertRoute(route)) {
        return new ModelAndView(PAGE_MAIN, INFO, route.toString() + " added");
      } else {
        return new ModelAndView(PAGE_INSERT_ROUTE, INFO, route.toString() + " didn't add");
      }
    } else {
      return new ModelAndView(PAGE_INSERT_ROUTE, INFO, "Wrong route number format");
    }
  }
예제 #8
0
  public Order(
      User user,
      LocalDate createdAtDate,
      LocalTime createdAtTime,
      LocalDate serveAtDate,
      LocalTime serveAtTime,
      String orderNumber,
      String desc)
      throws NullPointerException {
    this.createdDate = createdAtDate;
    this.createdTime = createdAtTime;
    this.user = user;
    createdTime = LocalTime.now();
    this.serveAtDate = serveAtDate;
    this.serveAtTime = serveAtTime;
    this.description = desc;
    orderedMeals = new ArrayList<>();
    number = orderNumber;

    sspCreatedDate = new SimpleStringProperty(createdDate.toString());
    sspCreatedTime = new SimpleStringProperty(createdTime.toString());
    sspOrderedMeals = new SimpleStringProperty();
    sspUserName = new SimpleStringProperty(this.user.getUserName().get());
    sspNumber = new SimpleStringProperty(number.toString());
    sspServeAtDate = new SimpleStringProperty(serveAtDate.toString());
    sspServeAtTime = new SimpleStringProperty(serveAtTime.toString());
    sspPrice = new SimpleStringProperty();
    sspDescription = new SimpleStringProperty(description);

    sspCreatedAtCompact =
        new SimpleStringProperty(createdDate.toString() + " " + createdTime.toString());
    sspServeAtCompact =
        new SimpleStringProperty(serveAtDate.toString() + " " + serveAtTime.toString());
  }
예제 #9
0
  @Test
  public void MinionsSpawnAt30SecondsInterval() throws Exception {
    int tickPerSecond = 10;
    Engine engine = new Engine();
    Nexus nexus = new Nexus(engine);
    SummonerRiftNexusBehavior behavior = new SummonerRiftNexusBehavior(engine, nexus);
    nexus.setBehavior(behavior);
    engine.addActor(nexus);

    Actor spectator = Mockito.mock(Actor.class);
    engine.addActor(spectator);
    engine.start();

    engine.enqueue(new TickEvent(LocalTime.parse("00:01:30"), tickPerSecond));
    Mockito.verify(spectator, Mockito.timeout(100).times(1))
        .onEvent(Matchers.isA(MinionWaveSpawnEvent.class));

    engine.enqueue(new TickEvent(LocalTime.parse("00:01:40"), tickPerSecond));
    Mockito.verify(spectator, Mockito.timeout(100).times(1))
        .onEvent(Matchers.isA(MinionWaveSpawnEvent.class));

    engine.enqueue(new TickEvent(LocalTime.parse("00:01:50"), tickPerSecond));
    Mockito.verify(spectator, Mockito.timeout(100).times(1))
        .onEvent(Matchers.isA(MinionWaveSpawnEvent.class));

    engine.enqueue(new TickEvent(LocalTime.parse("00:02:00"), tickPerSecond));
    Mockito.verify(spectator, Mockito.timeout(100).times(2))
        .onEvent(Matchers.isA(MinionWaveSpawnEvent.class));
  }
예제 #10
0
 private void loadScheduleTimesFromDatabase() {
   scheduleTimeList.add(
       new ScheduleTime(DayOfWeek.MONDAY, LocalTime.now(), Duration.ofMinutes(60)));
   scheduleTimeList.add(
       new ScheduleTime(DayOfWeek.TUESDAY, LocalTime.now(), Duration.ofMinutes(60)));
   scheduleTimeList.add(
       new ScheduleTime(DayOfWeek.THURSDAY, LocalTime.now(), Duration.ofMinutes(3)));
 }
예제 #11
0
 @Test(groups = {"implementation"})
 public void factory_time_4ints_singletons() {
   for (int i = 0; i < 24; i++) {
     LocalTime test1 = LocalTime.of(i, 0, 0, 0);
     LocalTime test2 = LocalTime.of(i, 0, 0, 0);
     assertSame(test1, test2);
   }
 }
예제 #12
0
 @Test(groups = {"implementation"})
 public void factory_ofNanoOfDay_singletons() {
   for (int i = 0; i < 24; i++) {
     LocalTime test1 = LocalTime.ofNanoOfDay(i * 1000000000L * 60L * 60L);
     LocalTime test2 = LocalTime.of(i, 0);
     assertSame(test1, test2);
   }
 }
  @Test
  public void checkRulePassengerIntersection() {
    List<PassengerGenerationRule> workDayRulesOfGagarina = new ArrayList<>();
    workDayRulesOfGagarina.add(
        PassengerGenerationRule.of(
            8, LocalTime.of(6, 0), LocalTime.of(9, 50), LocalTime.of(0, 15)));
    workDayRulesOfGagarina.add(
        PassengerGenerationRule.of(
            8, LocalTime.of(5, 0), LocalTime.of(8, 50), LocalTime.of(0, 20)));
    workDayRulesOfGagarina.add(
        PassengerGenerationRule.of(
            8, LocalTime.of(22, 0), LocalTime.of(4, 50), LocalTime.of(0, 20)));

    PassengerGenerationRuleList item =
        PassengerGenerationRuleList.of(HOLIDAY, workDayRulesOfGagarina);

    Set<ConstraintViolation<PassengerGenerationRuleList>> constraintViolations =
        validator.validate(item, ImitationSourceSequence.class);
    constraintViolations.forEach(System.out::println);

    assertEquals(1, constraintViolations.size());
    assertEquals(
        "{rule passenger generation is intersection}",
        constraintViolations.iterator().next().getMessage());
  }
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    TotalLargerByPeriodSameProduct that = (TotalLargerByPeriodSameProduct) o;

    if (!bound.equals(that.bound)) return false;
    if (!from.equals(that.from)) return false;
    return till.equals(that.till);
  }
  @Test
  public void testVoteSuccess() {

    Vote correctVote = new Vote();
    correctVote.setRestaurantId(Long.MIN_VALUE);
    Restaurant restaurant = new Restaurant();
    restaurant.setRestaurantId(Long.MIN_VALUE);

    when(restaurantRepository.findOne(Long.MIN_VALUE)).thenReturn(restaurant);

    when(votingRepository.findByUser("admin")).thenReturn(null);

    try {
      MvcResult successVoteRes =
          mockMvc
              .perform(
                  post("/vote")
                      .contentType(MediaType.APPLICATION_JSON)
                      .content(mapper.writeValueAsString(correctVote)))
              .andExpect(status().isOk())
              .andReturn();

      String outdatedVoteResString = successVoteRes.getResponse().getContentAsString();
      assertTrue(outdatedVoteResString.contains(Status.SUCCESS.getStatusValue()));
    } catch (Exception e) {
      fail();
    }

    LocalTime currentTime = LocalTime.now();
    if (currentTime.isBefore(RestaurantController.DEADLINE)) {
      Restaurant votingRestaurant = new Restaurant();
      votingRestaurant.setRestaurantId(Long.MAX_VALUE);
      Voting identicalVoting = new Voting();
      identicalVoting.setRestaurant(votingRestaurant);
      when(votingRepository.findByUser("admin")).thenReturn(identicalVoting);

      try {
        MvcResult actualVoteRes =
            mockMvc
                .perform(
                    post("/vote")
                        .contentType(MediaType.APPLICATION_JSON)
                        .content(mapper.writeValueAsString(correctVote)))
                .andExpect(status().isOk())
                .andReturn();

        String outdatedVoteResString = actualVoteRes.getResponse().getContentAsString();
        assertTrue(outdatedVoteResString.contains(Status.SUCCESS.getStatusValue()));
      } catch (Exception e) {
        fail();
      }
    }
  }
예제 #16
0
  @Test
  public void updateTask() throws Exception {
    // update existing task
    Task t = new Task();
    Long id = PermanentUserData.tasks.get(0).getId();
    t.setName("updated");
    t.setRole(new Role(PermanentUserData.tasks.get(0).getRole().getId()));
    given()
        .contentType("application/json")
        .filter(sessionFilter)
        .body(om.writeValueAsString(t))
        .put("/web/" + id.toString())
        .then()
        .statusCode(204);

    // delete it
    given()
        .header(PermanentUserData.tokenHeader)
        .delete("/m/" + PermanentUserData.tasks.get(0).getId())
        .then()
        .statusCode(204);

    // test if is recreated with correct values
    t.setNote("note");
    LocalTime moment = LocalTime.now();
    int minutes = moment.getMinute();
    int hours = moment.getHour();
    t.setTime(moment);
    given()
        .contentType("application/json")
        .header(PermanentUserData.tokenHeader)
        .body(om.writeValueAsString(t))
        .put("/m/" + id.toString())
        .then()
        .statusCode(204);
    try (Connection conn = ds.getConnection();
        PreparedStatement ps = conn.prepareStatement("select * from task where name = ?"); ) {
      ps.setString(1, "updated");
      try (ResultSet rs = ps.executeQuery(); ) {
        rs.next();
        assertThat(rs.getString("name"), equalTo("updated"));
        assertThat(rs.getString("note"), equalTo("note"));
        assertThat(rs.getTime("time").getMinutes(), equalTo(minutes));
        assertThat(rs.getTime("time").getHours(), equalTo(hours));
        // rest was set to default
        assertThat(rs.getBoolean("finished"), equalTo(false));
        assertThat(rs.getBoolean("important"), equalTo(false));
        assertThat(rs.getBoolean("finished"), equalTo(false));
        assertThat(rs.getDate("date"), equalTo(null));
        assertThat(rs.getDate("firstDate"), equalTo(null));
      }
    }
  }
  @Test
  public void checkPassengerGenerationRuleMax() {
    PassengerGenerationRule item =
        PassengerGenerationRule.of(1001, LocalTime.now(), LocalTime.now(), LocalTime.now());
    Set<ConstraintViolation<PassengerGenerationRule>> constraintViolations =
        validator.validate(item, ImitationSourceSequence.class);
    constraintViolations.forEach(System.out::println);

    assertEquals(1, constraintViolations.size());
    constraintViolations.forEach(
        constraint ->
            assertEquals("must be less than or equal toXML 1000", constraint.getMessage()));
  }
예제 #18
0
 public static void main(String[] args) {
   List<UserMeal> mealList =
       Arrays.asList(
           new UserMeal(LocalDateTime.of(2015, Month.MAY, 30, 10, 0), "Завтрак", 500),
           new UserMeal(LocalDateTime.of(2015, Month.MAY, 30, 13, 0), "Обед", 1000),
           new UserMeal(LocalDateTime.of(2015, Month.MAY, 30, 20, 0), "Ужин", 500),
           new UserMeal(LocalDateTime.of(2015, Month.MAY, 31, 10, 0), "Завтрак", 1000),
           new UserMeal(LocalDateTime.of(2015, Month.MAY, 31, 13, 0), "Обед", 500),
           new UserMeal(LocalDateTime.of(2015, Month.MAY, 31, 20, 0), "Ужин", 510));
   getFilteredWithExceeded(mealList, LocalTime.of(7, 0), LocalTime.of(12, 0), 2000);
   //        .toLocalDate();
   //        .toLocalTime();
 }
  @Test
  public void testVoteError() {
    try {
      Vote wrongVote = new Vote();
      wrongVote.setRestaurantId(Long.MAX_VALUE);
      when(restaurantRepository.findOne(Long.MAX_VALUE)).thenReturn(null);
      MvcResult wrongIdVoteRes =
          mockMvc
              .perform(
                  post("/vote")
                      .contentType(MediaType.APPLICATION_JSON)
                      .content(mapper.writeValueAsString(wrongVote)))
              .andExpect(status().isOk())
              .andReturn();
      String wrongIdVoteResponseString = wrongIdVoteRes.getResponse().getContentAsString();
      assertTrue(wrongIdVoteResponseString.contains(Status.FAILED.getStatusValue()));
      assertTrue(wrongIdVoteResponseString.contains(RestaurantController.WRONG_RESTAURANT_MSG));

      LocalTime currentTime = LocalTime.now();
      if (currentTime.isAfter(RestaurantController.DEADLINE)) {

        Vote correctVote = new Vote();
        correctVote.setRestaurantId(Long.MIN_VALUE);
        Restaurant restaurant = new Restaurant();
        restaurant.setRestaurantId(Long.MIN_VALUE);

        when(restaurantRepository.findOne(Long.MIN_VALUE)).thenReturn(restaurant);

        Restaurant votingRestaurant = new Restaurant();
        votingRestaurant.setRestaurantId(Long.MAX_VALUE);
        Voting outdatedVoting = new Voting();
        outdatedVoting.setRestaurant(votingRestaurant);

        when(votingRepository.findByUser("admin")).thenReturn(outdatedVoting);

        MvcResult outdatedVoteRes =
            mockMvc
                .perform(
                    post("/vote")
                        .contentType(MediaType.APPLICATION_JSON)
                        .content(mapper.writeValueAsString(correctVote)))
                .andExpect(status().isOk())
                .andReturn();
        String outdatedVoteResString = outdatedVoteRes.getResponse().getContentAsString();
        assertTrue(outdatedVoteResString.contains(Status.FAILED.getStatusValue()));
      }
    } catch (Exception e) {
      fail();
    }
  }
예제 #20
0
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (!(o instanceof TerminalWorkTime)) return false;

    TerminalWorkTime that = (TerminalWorkTime) o;

    if (endWorkTime != null ? !endWorkTime.equals(that.endWorkTime) : that.endWorkTime != null)
      return false;
    if (startWorkTime != null
        ? !startWorkTime.equals(that.startWorkTime)
        : that.startWorkTime != null) return false;

    return true;
  }
예제 #21
0
  public void setAttendanceStatusType(AttendanceStatusType statusType) {
    if (statusType.compareTo(AttendanceStatusType.PRESENT) == 0) {
      if (getWorkTimeForDay().compareTo(LocalTime.of(4, 0)) < 0)
        statusType = AttendanceStatusType.ABSENT;
      else if (getWorkTimeForDay().compareTo(LocalTime.of(6, 0)) < 0)
        statusType = AttendanceStatusType.HALF_DAY;
    }

    if (statusType.compareTo(AttendanceStatusType.ABSENT) == 0) {
      if (getCurrentDate().getDayOfWeek() == DayOfWeek.SATURDAY
          || getCurrentDate().getDayOfWeek() == DayOfWeek.SUNDAY)
        statusType = AttendanceStatusType.WEEKEND_HOLIDAY;
    }
    this.attendanceStatusType = statusType;
  }
  @FXML
  private void saveNewMatch() throws RemoteException {

    if (validateInput()) {

      MatchDTO newMatch = new MatchDTOImpl();
      newMatch.setDuration(_duration);
      Calendar cal = new GregorianCalendar();
      cal.set(
          _localDate.getYear(),
          _localDate.getMonthValue(),
          _localDate.getDayOfMonth(),
          _localTime.getHour(),
          _localTime.getMinute(),
          _localTime.getSecond());
      newMatch.setStart(cal.getTime());

      MatchDTOImpl.SimpleMatchTeamDTO team1 =
          new MatchDTOImpl.SimpleMatchTeamDTO(
              _allTeamsTableView.getSelectionModel().getSelectedItem().getId());
      team1.setId(_allTeamsOpponentTableView.getSelectionModel().getSelectedItem().getId());
      team1.setName(_allTeamsTableView.getSelectionModel().getSelectedItem().getName());
      team1.setVersion(_allTeamsTableView.getSelectionModel().getSelectedItem().getVersion());

      MatchDTOImpl.SimpleMatchTeamDTO team2 =
          new MatchDTOImpl.SimpleMatchTeamDTO(
              _allTeamsOpponentTableView.getSelectionModel().getSelectedItem().getId());
      team2.setId(_allTeamsOpponentTableView.getSelectionModel().getSelectedItem().getId());
      team2.setName(_allTeamsOpponentTableView.getSelectionModel().getSelectedItem().getName());
      team2.setVersion(
          _allTeamsOpponentTableView.getSelectionModel().getSelectedItem().getVersion());

      newMatch.setTeam1(team1);
      newMatch.setTeam2(team2);
      newMatch.setTournamentId(_tournament.getId());
      newMatch.setMatchStatus("Planned");

      _tournament.addMatch(newMatch);

      initSuccessAlert();
      // todo fix correct weiterleitung
      if (_newTournament) {
        SportifyGUI.getSharedMainApp().loadNewTournamentView(_tournament, _externalDisplayTeamDTOs);
      } else {
        SportifyGUI.getSharedMainApp().loadEditTournamentForm(_tournament);
      }
    }
  }
/** @author <a href="mailto:[email protected]">Lennart J&ouml;relid</a>, jGuru Europe AB */
public class LocalDateTimeAdapterTest {

  private String transportForm = "2015-04-25T15:40:00";
  private LocalDateTime objectForm =
      LocalDateTime.of(LocalDate.of(2015, Month.APRIL, 25), LocalTime.of(15, 40, 0));
  private LocalDateTimeAdapter unitUnderTest = new LocalDateTimeAdapter();

  @Test
  public void validateConvertingToTransportForm() throws Exception {

    // Assemble

    // Act
    final String result = unitUnderTest.marshal(objectForm);
    // System.out.println("Got: " + result);

    // Assert
    Assert.assertNull(unitUnderTest.marshal(null));
    Assert.assertEquals(transportForm, result);
  }

  @Test
  public void validateConvertingFromTransportForm() throws Exception {

    // Assemble

    // Act
    final LocalDateTime result = unitUnderTest.unmarshal(transportForm);

    // Assert
    Assert.assertNull(unitUnderTest.unmarshal(null));
    Assert.assertEquals(objectForm, result);
  }
}
예제 #24
0
  public static void main(String[] args) {

    // Current Date
    LocalDateTime today = LocalDateTime.now();
    System.out.println("Current DateTime=" + today);

    // Current Date using LocalDate and LocalTime
    today = LocalDateTime.of(LocalDate.now(), LocalTime.now());
    System.out.println("Current DateTime=" + today);

    // Creating LocalDateTime by providing input arguments
    LocalDateTime specificDate = LocalDateTime.of(2014, Month.JANUARY, 1, 10, 10, 30);
    System.out.println("Specific Date=" + specificDate);

    // Try creating date by providing invalid inputs
    // LocalDateTime feb29_2014 = LocalDateTime.of(2014, Month.FEBRUARY, 28,
    // 25,1,1);
    // Exception in thread "main" java.time.DateTimeException:
    // Invalid value for HourOfDay (valid values 0 - 23): 25

    // Current date in "Asia/Kolkata", you can get it from ZoneId javadoc
    LocalDateTime todayKolkata = LocalDateTime.now(ZoneId.of("Asia/Kolkata"));
    System.out.println("Current Date in IST=" + todayKolkata);

    // java.time.zone.ZoneRulesException: Unknown time-zone ID: IST
    // LocalDateTime todayIST = LocalDateTime.now(ZoneId.of("IST"));

    // Getting date from the base date i.e 01/01/1970
    LocalDateTime dateFromBase = LocalDateTime.ofEpochSecond(10000, 0, ZoneOffset.UTC);
    System.out.println("10000th second time from 01/01/1970= " + dateFromBase);
  }
  public LocalTime toMemberType(Long val) {
    if (val == null) {
      return null;
    }

    return LocalTime.ofNanoOfDay(val);
  }
예제 #26
0
 // simualte the streaming data
 public boolean streamEmulation() throws IOException {
   String line = null;
   while (this.cacheContentOfGraphIds.size() < this.size) {
     AGGraph graph =
         this.graphMaker.createGraph("http://fefocacheeviction.org/graph" + this.graphID);
     for (int i = 0; i < this.numberOfTriples; ++i) {
       if ((line = this.br.readLine()) != null) {
         line = line.replaceAll("<", "");
         line = line.replaceAll(">", "");
         String[] parts = line.split(" ");
         Node s = NodeFactory.createURI(parts[0]);
         Node p = NodeFactory.createURI(parts[1]);
         if (parts[2].contains("http")) {
           Node o = NodeFactory.createURI(parts[2].substring(0, parts[2].length()));
           graph.add(new Triple(s, p, o));
         } else {
           Node o = NodeFactory.createLiteral(parts[2].substring(1, parts[2].length() - 1));
           graph.add(new Triple(s, p, o));
         }
       } else {
         return false;
       }
     }
     this.cacheContentOfGraphIds.add(
         new GraphIdCounterPair(
             "http://fefocacheeviction.org/graph" + (this.graphID++), LocalTime.now()));
     this.modelGraph = this.graphMaker.createUnion(this.modelGraph, graph);
   }
   return true;
 }
  public static void main(String[] args) {
    LocalDateTime lDT = LocalDateTime.of(LocalDate.of(2016, 01, 17), LocalTime.of(23, 11, 25));

    System.out.println("The date and time is : " + lDT.toString());
    System.out.println("The strict date is :" + lDT.toLocalDate().toString());
    System.out.println("The strict time is :" + lDT.toLocalTime().toString());
  }
 @Test
 public void should_fail_if_timeTime_as_string_parameter_is_null() {
   expectException(
       IllegalArgumentException.class,
       "The String representing the LocalTime to compare actual with should not be null");
   assertThat(LocalTime.now()).isAfterOrEqualTo((String) null);
 }
  public Object getObject(ExecutionContext ec, ResultSet resultSet, int[] exprIndex) {
    if (exprIndex == null) {
      return null;
    }

    Object datastoreValue = getDatastoreMapping(0).getObject(resultSet, exprIndex[0]);
    if (datastoreValue == null) {
      return null;
    }

    if (datastoreValue instanceof String) {
      TypeConverter conv =
          ec.getNucleusContext()
              .getTypeManager()
              .getTypeConverterForType(LocalTime.class, String.class);
      if (conv != null) {
        return conv.toMemberType(datastoreValue);
      } else {
        throw new NucleusUserException("This type doesn't support persistence as a String");
      }
    } else if (datastoreValue instanceof Time) {
      Time time = (Time) datastoreValue;
      Calendar cal = Calendar.getInstance();
      cal.setTime(time);
      LocalTime localTime =
          LocalTime.of(
              cal.get(Calendar.HOUR_OF_DAY),
              cal.get(Calendar.MINUTE),
              cal.get(Calendar.SECOND),
              cal.get(Calendar.MILLISECOND) * 1000000);
      return localTime;
    } else {
      return null;
    }
  }
  public static void main(String[] args) {
    LocalDateTime date1 = LocalDateTime.of(LocalDate.of(1999, 5, 15), LocalTime.of(10, 22));
    LocalDateTime date2 = LocalDateTime.of(LocalDate.of(2008, 2, 11), LocalTime.of(5, 33));
    System.out.println("date1: " + date1);
    System.out.println("date2: " + date2);

    System.out.println(ChronoUnit.YEARS.between(date1, date2));
    System.out.println(ChronoUnit.MONTHS.between(date1, date2));
    System.out.println(ChronoUnit.WEEKS.between(date1, date2));
    System.out.println(ChronoUnit.DAYS.between(date1, date2));
    System.out.println(ChronoUnit.HOURS.between(date1, date2));
    System.out.println(ChronoUnit.MINUTES.between(date1, date2));
    System.out.println(ChronoUnit.SECONDS.between(date1, date2));
  }