Example usage for java.util Calendar clear

List of usage examples for java.util Calendar clear

Introduction

In this page you can find the example usage for java.util Calendar clear.

Prototype

public final void clear() 

Source Link

Document

Sets all the calendar field values and the time value (millisecond offset from the Epoch) of this Calendar undefined.

Usage

From source file:org.obiba.onyx.core.etl.participant.impl.ParticipantReaderTest.java

@Test
public void testProcessWithConfiguredAttributes() throws IOException {
    Calendar cal = Calendar.getInstance();

    cal.clear();
    cal.set(2008, 9 - 1, 1, 9, 0);//from  w  w  w  . j  a  va  2s  .  com
    final Date expectedAppointmentTime = cal.getTime();

    cal.clear();
    cal.set(1964, 10 - 1, 1);
    final Date expectedBirthDate = cal.getTime();

    ParticipantReaderForTest reader = createParticipantReaderForTest(1, 2, 3, true,
            TEST_RESOURCES_DIR + "/appointmentList_includesConfiguredAttributes.xls");
    reader.open(context);
    List<Participant> participants = new ArrayList<Participant>();

    try {
        while (reader.getRow() != null) {
            Participant participant = reader.read();
            if (participant != null)
                participants.add(participant);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    Assert.assertEquals(1, participants.size());
    Assert.assertEquals(expectedAppointmentTime, participants.get(0).getAppointment().getDate());
    Assert.assertEquals("cag001", participants.get(0).getSiteNo());
    Assert.assertEquals("100001", participants.get(0).getEnrollmentId());
    Assert.assertEquals("Tremblay", participants.get(0).getLastName());
    Assert.assertEquals("Chantal", participants.get(0).getFirstName());
    Assert.assertEquals("F", (participants.get(0).getGender().equals(Gender.FEMALE) ? "F" : "M"));
    Assert.assertEquals(expectedBirthDate, participants.get(0).getBirthDate());

    // Verify that the participant's configured attributes have been assigned the correct values.
    Assert.assertEquals("299, Avenue des Pins Ouest",
            participants.get(0).getConfiguredAttributeValue("Street").getValue());
    Assert.assertEquals("Montr\u00e9al", participants.get(0).getConfiguredAttributeValue("City").getValue());
    Assert.assertEquals("QC", participants.get(0).getConfiguredAttributeValue("Province").getValue());
    Assert.assertEquals("Canada", participants.get(0).getConfiguredAttributeValue("Country").getValue());
    Assert.assertEquals("H1T 2M4", participants.get(0).getConfiguredAttributeValue("Postal Code").getValue());
    Assert.assertEquals("514-343-9898 ext 9494",
            participants.get(0).getConfiguredAttributeValue("Phone").getValue());
}

From source file:org.apache.olingo.server.core.serializer.json.EdmAssistedJsonSerializerTest.java

@Test
public void entityCollectionWithComplexPropertyMetadataNone() throws Exception {
    Entity entity = new Entity();
    entity.setId(null);// www. ja v  a  2  s. c  om
    entity.addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, 1L));
    ComplexValue complexValue = new ComplexValue();
    complexValue.getValue()
            .add(new Property(null, "Inner1", ValueType.PRIMITIVE, BigDecimal.TEN.scaleByPowerOfTen(-5)));
    Calendar time = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    time.clear();
    time.set(Calendar.HOUR_OF_DAY, 13);
    time.set(Calendar.SECOND, 59);
    time.set(Calendar.MILLISECOND, 999);
    complexValue.getValue().add(new Property("Edm.TimeOfDay", "Inner2", ValueType.PRIMITIVE, time));
    entity.addProperty(new Property("Namespace.ComplexType", "Property2", ValueType.COMPLEX, complexValue));
    EntityCollection entityCollection = new EntityCollection();
    entityCollection.getEntities().add(entity);
    Assert.assertEquals(
            "{" + "\"value\":[{" + "\"Property1\":1," + "\"Property2\":{" + "\"Inner1\":0.00010,"
                    + "\"Inner2\":\"13:00:59.999\"}}]}",
            serialize(serializerNone, metadata, null, entityCollection, null));
}

From source file:org.apache.olingo.server.core.serializer.json.EdmAssistedJsonSerializerTest.java

@Test
public void entityCollectionMetadataNone() throws Exception {
    Entity entity = new Entity();
    entity.setId(null);//  w  w w.  ja  va 2 s .  c o m
    entity.addProperty(new Property(null, "Property0", ValueType.PRIMITIVE, null))
            .addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, 1));
    Calendar date = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    date.clear();
    date.set(2000, 1, 29);
    entity.addProperty(new Property("Edm.Date", "Property2", ValueType.PRIMITIVE, date))
            .addProperty(new Property("Edm.DateTimeOffset", "Property3", ValueType.PRIMITIVE, date))
            .addProperty(new Property(null, "Property4", ValueType.COLLECTION_PRIMITIVE,
                    Arrays.asList(true, false, null)));
    EntityCollection entityCollection = new EntityCollection();
    entityCollection.getEntities().add(entity);
    entityCollection.setCount(2);
    entityCollection.setNext(URI.create("nextLink"));
    Assert.assertEquals(
            "{" + "\"@odata.count\":2," + "\"value\":[{" + "\"Property0\":null," + "\"Property1\":1,"
                    + "\"Property2\":\"2000-02-29\"," + "\"Property3\":\"2000-02-29T00:00:00Z\","
                    + "\"Property4\":[true,false,null]}]," + "\"@odata.nextLink\":\"nextLink\"}",
            serialize(serializerNone, metadata, null, entityCollection, null));
}

From source file:org.apache.olingo.server.core.serializer.json.EdmAssistedJsonSerializerTest.java

@Test
public void entityCollectionWithComplexPropertyMetadataMin() throws Exception {
    Entity entity = new Entity();
    entity.setId(null);/*from  w  ww  . java  2s.c  o m*/
    entity.addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, 1L));
    ComplexValue complexValue = new ComplexValue();
    complexValue.getValue()
            .add(new Property(null, "Inner1", ValueType.PRIMITIVE, BigDecimal.TEN.scaleByPowerOfTen(-5)));
    Calendar time = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    time.clear();
    time.set(Calendar.HOUR_OF_DAY, 13);
    time.set(Calendar.SECOND, 59);
    time.set(Calendar.MILLISECOND, 999);
    complexValue.getValue().add(new Property("Edm.TimeOfDay", "Inner2", ValueType.PRIMITIVE, time));
    entity.addProperty(new Property("Namespace.ComplexType", "Property2", ValueType.COMPLEX, complexValue));
    EntityCollection entityCollection = new EntityCollection();
    entityCollection.getEntities().add(entity);
    Assert.assertEquals(
            "{\"@odata.context\":\"$metadata#EntitySet(Property1,Property2)\"," + "\"value\":[{"
                    + "\"Property1\":1," + "\"Property2\":{" + "\"Inner1\":0.00010,"
                    + "\"Inner2\":\"13:00:59.999\"}}]}",
            serialize(serializerMin, metadata, null, entityCollection, null));
}

From source file:org.apache.olingo.server.core.serializer.json.EdmAssistedJsonSerializerTest.java

@Test
public void entityCollectionMetadataMin() throws Exception {
    Entity entity = new Entity();
    entity.setId(null);//from www . j a  v a2s.c o  m
    entity.addProperty(new Property(null, "Property0", ValueType.PRIMITIVE, null))
            .addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, 1));
    Calendar date = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    date.clear();
    date.set(2000, 1, 29);
    entity.addProperty(new Property("Edm.Date", "Property2", ValueType.PRIMITIVE, date))
            .addProperty(new Property("Edm.DateTimeOffset", "Property3", ValueType.PRIMITIVE, date))
            .addProperty(new Property(null, "Property4", ValueType.COLLECTION_PRIMITIVE,
                    Arrays.asList(true, false, null)));
    EntityCollection entityCollection = new EntityCollection();
    entityCollection.getEntities().add(entity);
    entityCollection.setCount(2);
    entityCollection.setNext(URI.create("nextLink"));
    Assert.assertEquals(
            "{\"@odata.context\":\"$metadata#EntitySet(Property0,Property1,Property2,Property3,Property4)\","
                    + "\"@odata.count\":2," + "\"value\":[{" + "\"Property0\":null," + "\"Property1\":1,"
                    + "\"Property2\":\"2000-02-29\"," + "\"Property3\":\"2000-02-29T00:00:00Z\","
                    + "\"Property4\":[true,false,null]}]," + "\"@odata.nextLink\":\"nextLink\"}",
            serialize(serializerMin, metadata, null, entityCollection, null));
}

From source file:org.apache.olingo.server.core.serializer.json.EdmAssistedJsonSerializerTest.java

@Test
public void entityCollectionWithComplexProperty() throws Exception {
    Entity entity = new Entity();
    entity.setId(null);/*from   ww  w . java  2 s  .c  o  m*/
    entity.addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, 1L));
    ComplexValue complexValue = new ComplexValue();
    complexValue.getValue()
            .add(new Property(null, "Inner1", ValueType.PRIMITIVE, BigDecimal.TEN.scaleByPowerOfTen(-5)));
    Calendar time = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    time.clear();
    time.set(Calendar.HOUR_OF_DAY, 13);
    time.set(Calendar.SECOND, 59);
    time.set(Calendar.MILLISECOND, 999);
    complexValue.getValue().add(new Property("Edm.TimeOfDay", "Inner2", ValueType.PRIMITIVE, time));
    entity.addProperty(new Property("Namespace.ComplexType", "Property2", ValueType.COMPLEX, complexValue));
    EntityCollection entityCollection = new EntityCollection();
    entityCollection.getEntities().add(entity);
    Assert.assertEquals(
            "{\"@odata.context\":\"$metadata#EntitySet(Property1,Property2)\","
                    + "\"value\":[{\"@odata.id\":null," + "\"Property1@odata.type\":\"#Int64\",\"Property1\":1,"
                    + "\"Property2\":{\"@odata.type\":\"#Namespace.ComplexType\","
                    + "\"Inner1@odata.type\":\"#Decimal\",\"Inner1\":0.00010,"
                    + "\"Inner2@odata.type\":\"#TimeOfDay\",\"Inner2\":\"13:00:59.999\"}}]}",
            serialize(serializer, metadata, null, entityCollection, null));
}

From source file:org.apache.olingo.server.core.serializer.json.EdmAssistedJsonSerializerTest.java

@Test
public void entityCollection() throws Exception {
    Entity entity = new Entity();
    entity.setId(null);// w w  w.  j  ava  2 s.c o m
    entity.addProperty(new Property(null, "Property0", ValueType.PRIMITIVE, null))
            .addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, 1));
    Calendar date = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    date.clear();
    date.set(2000, 1, 29);
    entity.addProperty(new Property("Edm.Date", "Property2", ValueType.PRIMITIVE, date))
            .addProperty(new Property("Edm.DateTimeOffset", "Property3", ValueType.PRIMITIVE, date))
            .addProperty(new Property(null, "Property4", ValueType.COLLECTION_PRIMITIVE,
                    Arrays.asList(true, false, null)));
    EntityCollection entityCollection = new EntityCollection();
    entityCollection.getEntities().add(entity);
    entityCollection.setCount(2);
    entityCollection.setNext(URI.create("nextLink"));
    Assert.assertEquals(
            "{\"@odata.context\":\"$metadata#EntitySet(Property0,Property1,Property2,Property3,Property4)\","
                    + "\"@odata.count\":2," + "\"value\":[{\"@odata.id\":null," + "\"Property0\":null,"
                    + "\"Property1@odata.type\":\"#Int32\",\"Property1\":1,"
                    + "\"Property2@odata.type\":\"#Date\",\"Property2\":\"2000-02-29\","
                    + "\"Property3@odata.type\":\"#DateTimeOffset\",\"Property3\":\"2000-02-29T00:00:00Z\","
                    + "\"Property4@odata.type\":\"#Collection(Boolean)\",\"Property4\":[true,false,null]}],"
                    + "\"@odata.nextLink\":\"nextLink\"}",
            serialize(serializer, metadata, null, entityCollection, null));
}

From source file:org.apache.axis2.databinding.utils.ConverterUtil.java

/**
 * Converts a given string into a date. Code from Axis1 DateDeserializer.
 *
 * @param source//from w w  w .j a v  a  2 s .  c  o  m
 * @return Returns Date.
 */
public static Date convertToDate(String source) {

    // the lexical form of the date is '-'? yyyy '-' mm '-' dd zzzzzz?
    if ((source == null) || source.trim().equals("")) {
        return null;
    }
    source = source.trim();
    boolean bc = false;
    if (source.startsWith("-")) {
        source = source.substring(1);
        bc = true;
    }

    int year = 0;
    int month = 0;
    int day = 0;
    int timeZoneOffSet = TimeZone.getDefault().getRawOffset();

    if (source.length() >= 10) {
        //first 10 numbers must give the year
        if ((source.charAt(4) != '-') || (source.charAt(7) != '-')) {
            throw new RuntimeException("invalid date format (" + source + ") with out - s at correct place ");
        }
        year = Integer.parseInt(source.substring(0, 4));
        month = Integer.parseInt(source.substring(5, 7));
        day = Integer.parseInt(source.substring(8, 10));

        if (source.length() > 10) {
            String restpart = source.substring(10);
            if (restpart.startsWith("Z")) {
                // this is a gmt time zone value
                timeZoneOffSet = 0;
            } else if (restpart.startsWith("+") || restpart.startsWith("-")) {
                // this is a specific time format string
                if (restpart.charAt(3) != ':') {
                    throw new RuntimeException(
                            "invalid time zone format (" + source + ") without : at correct place");
                }
                int hours = Integer.parseInt(restpart.substring(1, 3));
                int minits = Integer.parseInt(restpart.substring(4, 6));
                timeZoneOffSet = ((hours * 60) + minits) * 60000;
                if (restpart.startsWith("-")) {
                    timeZoneOffSet = timeZoneOffSet * -1;
                }
            } else {
                throw new RuntimeException("In valid string sufix");
            }
        }
    } else {
        throw new RuntimeException("In valid string to parse");
    }

    Calendar calendar = Calendar.getInstance();
    calendar.clear();
    calendar.setLenient(false);
    calendar.set(Calendar.YEAR, year);
    //xml month stars from the 1 and calendar month is starts with 0
    calendar.set(Calendar.MONTH, month - 1);
    calendar.set(Calendar.DAY_OF_MONTH, day);
    calendar.set(Calendar.ZONE_OFFSET, timeZoneOffSet);

    // set the day light off set only if time zone
    if (source.length() >= 10) {
        calendar.set(Calendar.DST_OFFSET, 0);
    }
    calendar.getTimeInMillis();
    if (bc) {
        calendar.set(Calendar.ERA, GregorianCalendar.BC);
    }

    return calendar.getTime();

}

From source file:com.googlecode.osde.internal.ui.views.people.PersonPage.java

private void setDate(DateTime dateTime, Date date) {
    if (date != null) {
        Calendar cal = Calendar.getInstance();
        cal.clear();
        cal.setTime(date);//w  w  w .  j  ava2  s. c  o  m
        dateTime.setYear(cal.get(Calendar.YEAR));
        dateTime.setMonth(cal.get(Calendar.MONTH));
        dateTime.setDay(cal.get(Calendar.DATE));
    }
}

From source file:org.apache.olingo.fit.proxy.v4.APIBasicDesignTestITCase.java

/**
 * Java client should support the deletion based on locally created entity.
 * See also <a href="https://issues.apache.org/jira/browse/OLINGO-395">Olingo Issue 395</a>.
 *///from   w  w w. j a  v a  2 s  .c om
@Test
public void issueOLINGO395() {
    Order order = getContainer().newEntityInstance(Order.class);
    order.setOrderID(1105);

    final Calendar orderDate = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    orderDate.clear();
    orderDate.set(2011, 3, 4, 16, 3, 57);
    order.setOrderDate(new Timestamp(orderDate.getTimeInMillis()));

    order.setShelfLife(BigDecimal.ZERO);

    final PrimitiveCollection<BigDecimal> osl = getContainer().newPrimitiveCollection(BigDecimal.class);
    osl.add(BigDecimal.TEN.negate());
    osl.add(BigDecimal.TEN);

    order.setOrderShelfLifes(osl);

    getContainer().getOrders().add(order);
    getContainer().getOrders().delete(order);

    getContainer().flush();

    service.getContext().detachAll();
    try {
        getContainer().getOrders().getByKey(1105).load();
        fail();
    } catch (IllegalArgumentException e) {
    }
    service.getContext().detachAll(); // avoid influences

    order = getContainer().newEntityInstance(Order.class);
    order.setOrderID(1105);

    getContainer().getOrders().delete(order);
    getContainer().flush(); // test service doesn't fail for delete requests about unexisting objects

    service.getContext().detachAll();
    try {
        getContainer().getOrders().getByKey(1105).load();
        fail();
    } catch (IllegalArgumentException e) {
    }
    service.getContext().detachAll(); // avoid influences
}