use of org.joda.time.LocalDate in project joda-time-android by dlew.
the class JodaSampleActivity method sampleIsToday.
private void sampleIsToday() {
List<String> text = new ArrayList<String>();
LocalDate today = LocalDate.now();
text.add("Today: " + DateUtils.isToday(today));
text.add("Tomorrow: " + DateUtils.isToday(today.plusDays(1)));
text.add("Yesterday: " + DateUtils.isToday(today.minusDays(1)));
addSample("DateUtils.isToday()", text);
}
use of org.joda.time.LocalDate in project qi4j-sdk by Qi4j.
the class AbstractEntityStoreTest method whenNewEntityThenCanFindEntityAndCorrectValues.
@Test
public void whenNewEntityThenCanFindEntityAndCorrectValues() throws Exception {
UnitOfWork unitOfWork = module.newUnitOfWork();
try {
TestEntity instance = createEntity(unitOfWork);
unitOfWork.complete();
// Find entity
unitOfWork = module.newUnitOfWork();
instance = unitOfWork.get(instance);
// Check state
assertThat("property 'intValue' has correct value", instance.intValue().get(), equalTo(42));
assertThat("property 'longValue' has correct value", instance.longValue().get(), equalTo(42L));
assertThat("property 'doubleValue' has correct value", instance.doubleValue().get(), equalTo(42D));
assertThat("property 'floatValue' has correct value", instance.floatValue().get(), equalTo(42F));
assertThat("property 'booleanValue' has correct value", instance.booleanValue().get(), equalTo(Boolean.TRUE));
assertThat("property 'bigInteger' has correct value", instance.bigIntegerValue().get(), equalTo(new BigInteger("42")));
assertThat("property 'bigDecimal' has correct value", instance.bigDecimalValue().get(), equalTo(new BigDecimal("42")));
assertThat("property 'dateValue' has correct value", instance.dateValue().get(), equalTo(new DateTime("2020-03-04T13:24:35", UTC).toDate()));
assertThat("property 'dateTimeValue' has correct value", instance.dateTimeValue().get(), equalTo(new DateTime("2020-03-04T13:24:35", UTC)));
assertThat("property 'localDateTimeValue' has correct value", instance.localDateTimeValue().get(), equalTo(new LocalDateTime("2020-03-04T13:23:00", UTC)));
assertThat("property 'localDateValue' has correct value", instance.localDateValue().get(), equalTo(new LocalDate("2020-03-04")));
assertThat("property 'name' has correct value", instance.name().get(), equalTo("Test"));
assertThat("property 'unsetName' has correct value", instance.unsetName().get(), equalTo(null));
assertThat("property 'emptyName' has correct value", instance.emptyName().get(), equalTo(""));
assertThat("property 'valueProperty.stringValue' has correct value", instance.valueProperty().get().valueProperty().get().stringValue().get(), equalTo("Bar"));
assertThat("property 'valueProperty.listProperty' has correct value", instance.valueProperty().get().listProperty().get().get(0), equalTo("Foo"));
assertThat("property 'valueProperty.enumProperty' has correct value", instance.valueProperty().get().enumProperty().get(), equalTo(TestEnum.VALUE3));
assertThat("property 'valueProperty.anotherValue.bling' has correct value", instance.valueProperty().get().valueProperty().get().anotherValue().get().bling().get(), equalTo("BlinkLjus"));
assertThat("property 'valueProperty.tjabbaProperty.bling' has correct value", instance.valueProperty().get().tjabbaProperty().get().bling().get(), equalTo("Brakfis"));
Map<String, String> mapValue = new HashMap<>();
mapValue.put("foo", "bar");
assertThat("property 'valueProperty.mapStringStringProperty' has correct value", instance.valueProperty().get().mapStringStringProperty().get(), equalTo(mapValue));
assertThat("association has correct value", instance.association().get(), equalTo(instance));
assertThat("manyAssociation has correct value", instance.manyAssociation().iterator().next(), equalTo(instance));
assertThat("namedAssociation has correct 'foo' value", instance.namedAssociation().get("foo"), equalTo(instance));
assertThat("namedAssociation has correct 'bar' value", instance.namedAssociation().get("bar"), equalTo(instance));
unitOfWork.discard();
} finally {
unitOfWork.discard();
}
}
use of org.joda.time.LocalDate in project qi4j-sdk by Qi4j.
the class TestData method populate.
static void populate(Module module) throws UnitOfWorkCompletionException {
try (UnitOfWork unitOfWork = module.newUnitOfWork()) {
NameableAssert.clear();
Domain gaming;
{
EntityBuilder<Domain> domainBuilder = unitOfWork.newEntityBuilder(Domain.class, "Gaming");
gaming = domainBuilder.instance();
gaming.name().set("Gaming");
gaming.description().set("Gaming domain");
gaming = domainBuilder.newInstance();
NameableAssert.trace(gaming);
}
Domain programming;
{
EntityBuilder<Domain> domainBuilder = unitOfWork.newEntityBuilder(Domain.class);
programming = domainBuilder.instance();
programming.name().set("Programming");
programming.description().set("Programing domain");
programming = domainBuilder.newInstance();
NameableAssert.trace(programming);
}
Domain cooking;
{
EntityBuilder<Domain> domainBuilder = unitOfWork.newEntityBuilder(Domain.class);
cooking = domainBuilder.instance();
cooking.name().set("Cooking");
cooking.description().set("Cooking domain");
cooking = domainBuilder.newInstance();
NameableAssert.trace(cooking);
}
Domain cars;
{
EntityBuilder<Domain> domainBuilder = unitOfWork.newEntityBuilder(Domain.class);
cars = domainBuilder.instance();
cars.name().set("Cars");
cars.description().set("Cars");
cars = domainBuilder.newInstance();
NameableAssert.trace(cars);
}
City kualaLumpur;
{
EntityBuilder<City> cityBuilder = unitOfWork.newEntityBuilder(City.class);
kualaLumpur = cityBuilder.instance();
kualaLumpur.name().set("Kuala Lumpur");
kualaLumpur.country().set("Malaysia");
kualaLumpur.county().set("Some Jaya");
kualaLumpur = cityBuilder.newInstance();
NameableAssert.trace(kualaLumpur);
}
City penang;
{
EntityBuilder<City> cityBuilder = unitOfWork.newEntityBuilder(City.class);
penang = cityBuilder.instance();
penang.name().set("Penang");
penang.country().set("Malaysia");
penang.county().set("Some Other Jaya");
penang = cityBuilder.newInstance();
NameableAssert.trace(penang);
}
Account annsAccount;
{
EntityBuilder<Account> accountBuilder = unitOfWork.newEntityBuilder(Account.class, "accountOfAnnDoe");
annsAccount = accountBuilder.instance();
annsAccount.number().set("accountOfAnnDoe");
annsAccount = accountBuilder.newInstance();
}
Account jacksAccount;
{
EntityBuilder<Account> accountBuilder = unitOfWork.newEntityBuilder(Account.class, "accountOfJackDoe");
jacksAccount = accountBuilder.instance();
jacksAccount.number().set("accountOfJackDoe");
jacksAccount = accountBuilder.newInstance();
}
ValueBuilder<Address> addressBuilder = module.newValueBuilder(Address.class);
Address address = addressBuilder.prototype();
address.line1().set("Qi Street 4j");
address.line2().set("Off main Java Street");
address.zipcode().set("12345");
Female annDoe;
{
EntityBuilder<FemaleEntity> femaleBuilder = unitOfWork.newEntityBuilder(FemaleEntity.class, "anndoe");
annDoe = femaleBuilder.instance();
annDoe.name().set("Ann Doe");
annDoe.title().set(Person.Title.MRS);
annDoe.placeOfBirth().set(kualaLumpur);
annDoe.yearOfBirth().set(1975);
annDoe.interests().add(0, cooking);
annDoe.password().set("passwordOfAnnDoe");
annDoe.mainAccount().set(annsAccount);
annDoe.accounts().put("anns", annsAccount);
annDoe.accounts().put("jacks", jacksAccount);
annDoe.address().set(addressBuilder.newInstance());
annDoe = femaleBuilder.newInstance();
NameableAssert.trace(annDoe);
}
{
EntityBuilder<MaleEntity> maleBuilder = unitOfWork.newEntityBuilder(MaleEntity.class);
Male joeDoe = maleBuilder.instance();
joeDoe.name().set("Joe Doe");
joeDoe.title().set(Person.Title.MR);
joeDoe.placeOfBirth().set(kualaLumpur);
joeDoe.yearOfBirth().set(1990);
joeDoe.mother().set(annDoe);
joeDoe.interests().add(0, programming);
joeDoe.interests().add(0, gaming);
joeDoe.email().set("joe@thedoes.net");
joeDoe.password().set("passwordOfJoeDoe");
joeDoe = maleBuilder.newInstance();
address = module.newValueBuilderWithPrototype(address).prototype();
address.line1().set("Qi Alley 4j");
joeDoe.address().set(address);
joeDoe.bigInteger().set(new BigInteger("23232323232323232323232323"));
joeDoe.bigDecimal().set(new BigDecimal("23.4276931348623157e+309"));
joeDoe.dateValue().set(new DateTime("2020-03-04T13:24:35", UTC).toDate());
joeDoe.dateTimeValue().set(new DateTime("2020-03-04T13:24:35", UTC));
joeDoe.localDateTimeValue().set(new LocalDateTime("2020-03-04T13:23:00"));
joeDoe.localDateValue().set(new LocalDate("2020-03-04"));
NameableAssert.trace(joeDoe);
}
{
EntityBuilder<MaleEntity> maleBuilder = unitOfWork.newEntityBuilder(MaleEntity.class);
Male jackDoe = maleBuilder.instance();
jackDoe.name().set("Jack Doe");
jackDoe.title().set(Person.Title.DR);
jackDoe.placeOfBirth().set(penang);
jackDoe.yearOfBirth().set(1970);
jackDoe.interests().add(0, cars);
jackDoe.wife().set(annDoe);
jackDoe.password().set("passwordOfJohnDoe");
jackDoe.mainAccount().set(jacksAccount);
jackDoe.accounts().put("anns", annsAccount);
jackDoe.accounts().put("jacks", jacksAccount);
address = module.newValueBuilderWithPrototype(address).prototype();
address.line1().set("Qi Avenue 4j");
jackDoe.address().set(address);
jackDoe.bigInteger().set(new BigInteger("42424242424242424242424242"));
jackDoe.bigDecimal().set(new BigDecimal("42.2376931348623157e+309"));
jackDoe.dateValue().set(new DateTime("2010-03-04T13:24:35", UTC).toDate());
jackDoe.dateTimeValue().set(new DateTime("2010-03-04T13:24:35", UTC));
jackDoe.localDateTimeValue().set(new LocalDateTime("2010-03-04T13:23:00"));
jackDoe.localDateValue().set(new LocalDate("2010-03-04"));
ValueBuilder<URL> urlBuilder = module.newValueBuilder(URL.class);
ValueBuilder<Protocol> protocolBuilder = module.newValueBuilder(Protocol.class);
ValueBuilder<QueryParam> queryParamBuilder = module.newValueBuilder(QueryParam.class);
Protocol protocol = protocolBuilder.prototype();
protocol.value().set("http");
List<QueryParam> queryParams = new ArrayList<>(2);
QueryParam param = queryParamBuilder.prototype();
param.name().set("user");
param.value().set("jackdoe");
queryParams.add(queryParamBuilder.newInstance());
queryParamBuilder = module.newValueBuilder(QueryParam.class);
param = queryParamBuilder.prototype();
param.name().set("password");
param.value().set("somepassword");
queryParams.add(queryParamBuilder.newInstance());
URL url = urlBuilder.prototype();
url.protocol().set(protocolBuilder.newInstance());
url.queryParams().set(queryParams);
jackDoe.personalWebsite().set(urlBuilder.newInstance());
jackDoe = maleBuilder.newInstance();
NameableAssert.trace(jackDoe);
}
{
EntityBuilder<CatEntity> catBuilder = unitOfWork.newEntityBuilder(CatEntity.class);
Cat felix = catBuilder.instance();
felix.name().set("Felix");
catBuilder.newInstance();
}
unitOfWork.complete();
}
}
use of org.joda.time.LocalDate in project qi4j-sdk by Qi4j.
the class AbstractPlainValueSerializationTest method givenLocalDateValueWhenSerializingAndDeserializingExpectEquals.
@Test
public void givenLocalDateValueWhenSerializingAndDeserializingExpectEquals() {
String serialized = valueSerialization.serialize(new LocalDate("2020-03-04"));
assertThat(serialized, equalTo("2020-03-04"));
LocalDate deserialized = valueSerialization.deserialize(LocalDate.class, serialized);
assertThat(deserialized, equalTo(new LocalDate("2020-03-04")));
}
use of org.joda.time.LocalDate in project qi4j-sdk by Qi4j.
the class AbstractQueryTest method script43_LocalDate.
@Test
public void script43_LocalDate() {
QueryBuilder<Person> qb = this.module.newQueryBuilder(Person.class);
Person person = templateFor(Person.class);
Query<Person> query = unitOfWork.newQuery(qb.where(and(gt(person.localDateValue(), new LocalDate("2005-03-04", UTC)), lt(person.localDateValue(), new LocalDate("2015-03-04", UTC)))));
System.out.println("*** script43_LocalDate: " + query);
verifyUnorderedResults(query, "Jack Doe");
}
Aggregations