Пример #1
0
  public void transfer(Account source, Account target, double amount) {
    if (!timeService.isServiceAvailable(LocalTime.now())) {
      return;
    }

    double sourceBalance = source.getBalance();
    double deductAmount = amount + policy.getFee(amount);
    double newSourceBalance = sourceBalance - deductAmount;
    if (amount <= this.getMinimumAmount() || amount <= 0) {
      throw new IllegalAmountException();
    } else if (sourceBalance >= deductAmount) {
      source.setBalance(newSourceBalance);
      target.setBalance(amount);
    } else {
      throw new InsufficientFundException();
    }
  }
Пример #2
0
  @Test
  public void registerNewUser() {
    // test data
    String newUser = "******";
    String newUserEmail = "@test.ua";
    String newUserPassword;
    String newUserZip = "40211";
    boolean privacyPolicyOfNewUserName = true;

    // prepare test data
    String now = LocalTime.now().toString("HHmmssSSS");
    newUserEmail = newUser + now + newUserEmail;
    newUserPassword = newUser + now;

    openNascarMainPage();
    register(newUserEmail, newUserPassword, newUserZip, privacyPolicyOfNewUserName);
    logOutFromNascarMainPage();
  }
 @Override
 public View onCreateView(
     LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
   Log.i(TAG, "On create view...");
   // Inflate the layout for this fragment
   LocalTime time = LocalTime.now();
   if (getArguments() != null) {
     time = new DateTime(getArguments().getLong(ARG_TIME)).toLocalTime();
   }
   View view = inflater.inflate(R.layout.fragment_time_picker, container, false);
   mTimePicker = (TimePicker) view.findViewById(R.id.time_picker);
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
     mTimePicker.setHour(time.getHourOfDay());
     mTimePicker.setMinute(time.getMinuteOfHour());
   } else {
     mTimePicker.setCurrentHour(time.getHourOfDay());
     mTimePicker.setCurrentMinute(time.getMinuteOfHour());
   }
   return view;
 }
@Entity
public class Item extends play.db.ebean.Model implements ChatEntry {
  @Id @GeneratedValue public Long internalId;

  @OneToOne public User user;

  public LocalTime timestamp = LocalTime.now();

  @Required
  @MaxLength(140)
  public String message;

  public Item() {}

  public Item(User user, LocalTime timestamp, String message) {
    this.user = user;
    this.timestamp = timestamp;
    this.message = message;
  }

  public LocalTime timestamp() {
    return timestamp;
  }
}
Пример #5
0
 private void timeCalculate() {
   LocalTime localTime = LocalTime.now();
   this.dayMinute = localTime.getHourOfDay() * 60 + localTime.getMinuteOfHour();
 }
  public static Result index() {
    DateTime today = DateTime.now();
    DateTime yesterday = today.minus(Days.ONE);

    Chat chat11 =
        new Chat(
            yesterday,
            1,
            asList(
                new Item("me", LocalTime.now(), "Hello!"),
                new Item("other", LocalTime.now(), "Hi!"),
                new Item("me", LocalTime.now(), "Fine?"),
                new Item("other", LocalTime.now(), "Yes")));
    // later on
    Chat chat12 =
        new Chat(
            yesterday,
            2,
            asList(
                new Item("me", LocalTime.now(), "It's hot today!"),
                new Item("other", LocalTime.now(), "Indeed...")));

    Chat chat21 =
        new Chat(
            today,
            1,
            asList(
                new Item("me", LocalTime.now(), "Hello!"),
                new Item("me", LocalTime.now(), "Youhou?"),
                new Item("no-one", LocalTime.now(), "...")));
    Chat chat22 =
        new Chat(
            today,
            2,
            asList(
                new Item("me", LocalTime.now(), "Ding ding!"),
                new Item("me", LocalTime.now(), "Poueeeeeeeeeet?"),
                new Item("no-one", LocalTime.now(), "...")));

    Chat chat23 =
        new Chat(
            today,
            3,
            asList(
                new Item("me", LocalTime.now(), "No one?"),
                new Item("no-one", LocalTime.now(), "Yes?")));

    return ok(index.render("It Works!", asList(chat23, chat11, chat21, chat12, chat22)));
  }
public class Application extends Controller {

  public static Result index() {
    String email = session().get("email");
    if (email != null) {
      return redirect(routes.Chats.allChats());
    } else {
      return unauthorized(views.html.login.render());
    }
  }

  public static Result login() {
    return ok(views.html.login.render());
  }

  public static Result logout() {
    session().clear();
    return ok(views.html.login.render());
  }

  public static Result enter() {
    Map<String, String[]> params;
    params = request().body().asFormUrlEncoded();

    String email = params.get("email")[0];
    User user = User.find.byId(email);
    if (user == null) {
      return redirect(routes.Application.login());
    } else {
      session("email", email);
      return redirect(routes.Chats.allChats());
    }
  }

  public static LocalDate today = LocalDate.now();
  public static LocalDate yesterday = today.minus(Days.ONE);

  public static Chat chat11 =
      new Chat(
          yesterday,
          1,
          asList(
              new Item(SampleUsers.get.me, LocalTime.now(), "Hello!"),
              new Item(SampleUsers.get.robin, LocalTime.now(), "Hi!"),
              new Item(SampleUsers.get.me, LocalTime.now(), "Fine?"),
              new Item(SampleUsers.get.robin, LocalTime.now(), "Yes")),
          new ArrayList<Image>());
  // later on
  public static Chat chat12 =
      new Chat(
          yesterday,
          2,
          asList(
              new Item(SampleUsers.get.me, LocalTime.now(), "It's hot today!"),
              new Item(SampleUsers.get.robin, LocalTime.now(), "Indeed...")),
          new ArrayList<Image>());

  public static Chat chat21 =
      new Chat(
          today,
          1,
          asList(
              new Item(SampleUsers.get.me, LocalTime.now(), "Hello!"),
              new Item(SampleUsers.get.me, LocalTime.now(), "Youhou?"),
              new Item(SampleUsers.get.noOne, LocalTime.now(), "...")),
          new ArrayList<Image>());
  public static Chat chat22 =
      new Chat(
          today,
          2,
          asList(
              new Item(SampleUsers.get.me, LocalTime.now(), "Ding ding!"),
              new Item(SampleUsers.get.me, LocalTime.now(), "Poueeeeeeeeeet?"),
              new Item(SampleUsers.get.noOne, LocalTime.now(), "...")),
          new ArrayList<Image>());

  public static Chat chat23 =
      new Chat(
          today,
          3,
          asList(
              new Item(SampleUsers.get.me, LocalTime.now(), "No one?"),
              new Item(SampleUsers.get.noOne, LocalTime.now(), "Yes?")),
          new ArrayList<Image>());

  public static Result sample() {

    return ok(sample.render("Chat Archives", asList(chat23, chat11, chat21, chat12, chat22)));
  }
}
Пример #8
0
 @Override
 public LocalTime now() {
   return LocalTime.now();
 }