示例#1
0
 public static ArrayList<MedicineObject> getAllMedicineFromDateObjects(
     Context context, ArrayList<DateObject> dateObjects) {
   ArrayList<MedicineObject> medicineObjects = new ArrayList<>();
   ArrayList<Integer> medicineIds = new ArrayList<>();
   for (DateObject dateObject : dateObjects) {
     MedicineObject medicineObject =
         MedicineHelper.getMedicine(context, dateObject.getMedicineId());
     if (!medicineIds.contains(medicineObject.getId())) {
       medicineObjects.add(medicineObject);
       medicineIds.add(medicineObject.getId());
     }
   }
   return medicineObjects;
 }
  @MemberOrder(sequence = "30")
  public DateObject createDateObject(
      final @ParameterLayout(named = "Name") String name,
      final @ParameterLayout(named = "Year") int year,
      final @ParameterLayout(named = "Month") int month,
      final @ParameterLayout(named = "Day") int day,
      final @ParameterLayout(named = "Hour") int hour,
      final @ParameterLayout(named = "Minutes") int minutes) {
    final DateObject obj = container.newTransientInstance(DateObject.class);
    obj.setName(name);

    final org.joda.time.DateTime dt = new org.joda.time.DateTime(year, month, day, hour, minutes);
    final org.joda.time.LocalDateTime ldt =
        new org.joda.time.LocalDateTime(year, month, day, hour, minutes);
    final org.joda.time.LocalDate ld = new org.joda.time.LocalDate(year, month, day);
    final java.util.Date jud = dt.toDate();
    final Date sqldt = new Date(jud.getTime());
    final Timestamp ts = new Timestamp(jud.getTime());

    obj.setSomeJavaUtilDateMandatory(jud);
    obj.setSomeJavaUtilDateOptional(jud);
    obj.setSomeJavaUtilDateHidden(jud);
    obj.setSomeJavaUtilDateDisabled(jud);
    obj.setSomeJavaUtilDateWithValidation(jud);
    obj.setSomeJavaUtilDateMandatoryWithChoices(jud);
    obj.setSomeJavaUtilDateOptionalWithChoices(jud);

    obj.setSomeJavaSqlDateMandatory(sqldt);
    obj.setSomeJavaSqlDateOptional(sqldt);
    obj.setSomeJavaSqlDateHidden(sqldt);
    obj.setSomeJavaSqlDateDisabled(sqldt);
    obj.setSomeJavaSqlDateWithValidation(sqldt);
    obj.setSomeJavaSqlDateMandatoryWithChoices(sqldt);
    obj.setSomeJavaSqlDateOptionalWithChoices(sqldt);

    obj.setSomeJavaSqlTimestampMandatory(ts);
    obj.setSomeJavaSqlTimestampOptional(ts);
    obj.setSomeJavaSqlTimestampHidden(ts);
    obj.setSomeJavaSqlTimestampDisabled(ts);
    obj.setSomeJavaSqlTimestampWithValidation(ts);
    obj.setSomeJavaSqlTimestampMandatoryWithChoices(ts);
    obj.setSomeJavaSqlTimestampOptionalWithChoices(ts);

    obj.setSomeJodaDateTimeMandatory(dt);
    obj.setSomeJodaDateTimeOptional(dt);
    obj.setSomeJodaDateTimeHidden(dt);
    obj.setSomeJodaDateTimeDisabled(dt);
    obj.setSomeJodaDateTimeWithValidation(dt);
    obj.setSomeJodaDateTimeMandatoryWithChoices(dt);
    obj.setSomeJodaDateTimeOptionalWithChoices(dt);

    //        obj.setSomeJodaLocalDateTimeMandatory(ldt);
    //        obj.setSomeJodaLocalDateTimeOptional(ldt);
    //        obj.setSomeJodaLocalDateTimeHidden(ldt);
    //        obj.setSomeJodaLocalDateTimeDisabled(ldt);
    //        obj.setSomeJodaLocalDateTimeWithValidation(ldt);
    //        obj.setSomeJodaLocalDateTimeMandatoryWithChoices(ldt);
    //        obj.setSomeJodaLocalDateTimeOptionalWithChoices(ldt);

    obj.setSomeJodaLocalDateMandatory(ld);
    obj.setSomeJodaLocalDateOptional(ld);
    obj.setSomeJodaLocalDateHidden(ld);
    obj.setSomeJodaLocalDateDisabled(ld);
    obj.setSomeJodaLocalDateWithValidation(ld);
    obj.setSomeJodaLocalDateMandatoryWithChoices(ld);
    obj.setSomeJodaLocalDateOptionalWithChoices(ld);

    //        obj.setSomeApplibDateMandatory(new Date(ld.toDate()));
    //        obj.setSomeApplibDateTimeMandatory(new DateTime(ldt.toDateTime()));

    container.persistIfNotAlready(obj);
    return obj;
  }