use of org.hisp.dhis.commons.collection.UniqueArrayList in project dhis2-core by dhis2.
the class AnalyticsTableTest method testEquals.
@Test
public void testEquals() {
Period periodA = new YearlyPeriodType().createPeriod(new DateTime(2014, 1, 1, 0, 0).toDate());
Period periodB = new YearlyPeriodType().createPeriod(new DateTime(2015, 1, 1, 0, 0).toDate());
AnalyticsTable tableA = new AnalyticsTable("analytics", null, periodA);
AnalyticsTable tableB = new AnalyticsTable("analytics", null, periodA);
AnalyticsTable tableC = new AnalyticsTable("analytics", null, periodB);
List<AnalyticsTable> uniqueList = new UniqueArrayList<>();
uniqueList.add(tableA);
uniqueList.add(tableB);
uniqueList.add(tableC);
assertEquals(2, uniqueList.size());
}
use of org.hisp.dhis.commons.collection.UniqueArrayList in project dhis2-core by dhis2.
the class DatePeriodResourceTable method getPopulateTempTableContent.
@Override
public Optional<List<Object[]>> getPopulateTempTableContent() {
List<PeriodType> periodTypes = PeriodType.getAvailablePeriodTypes();
List<Object[]> batchArgs = new ArrayList<>();
//TODO
Date startDate = new Cal(1975, 1, 1, true).time();
Date endDate = new Cal(2025, 1, 1, true).time();
List<Period> days = new UniqueArrayList<>(new DailyPeriodType().generatePeriods(startDate, endDate));
Calendar calendar = PeriodType.getCalendar();
for (Period day : days) {
List<Object> values = new ArrayList<>();
values.add(day.getStartDate());
for (PeriodType periodType : periodTypes) {
values.add(periodType.createPeriod(day.getStartDate(), calendar).getIsoDate());
}
batchArgs.add(values.toArray());
}
return Optional.of(batchArgs);
}
use of org.hisp.dhis.commons.collection.UniqueArrayList in project dhis2-core by dhis2.
the class JdbcEventAnalyticsTableManager method getTables.
@Override
@Transactional
public List<AnalyticsTable> getTables(Date earliest) {
log.info(String.format("Get tables using earliest: %s, spatial support: %b", earliest, databaseInfo.isSpatialSupport()));
List<AnalyticsTable> tables = new UniqueArrayList<>();
Calendar calendar = PeriodType.getCalendar();
String baseName = getTableName();
List<Program> programs = idObjectManager.getAllNoAcl(Program.class);
for (Program program : programs) {
List<Integer> dataYears = getDataYears(program, earliest);
Collections.sort(dataYears);
for (Integer year : dataYears) {
Period period = PartitionUtils.getPeriod(calendar, year);
AnalyticsTable table = new AnalyticsTable(baseName, null, period, program);
List<AnalyticsTableColumn> dimensionColumns = getDimensionColumns(table);
table.setDimensionColumns(dimensionColumns);
tables.add(table);
}
}
return tables;
}
use of org.hisp.dhis.commons.collection.UniqueArrayList in project dhis2-core by dhis2.
the class UniqueArrayListTest method testAdd.
@Test
public void testAdd() {
List<Period> list = new UniqueArrayList<>();
PeriodType periodType = new MonthlyPeriodType();
Period peA = periodType.createPeriod(new DateTime(2000, 1, 1, 0, 0).toDate());
// Duplicate
Period peB = periodType.createPeriod(new DateTime(2000, 1, 1, 0, 0).toDate());
Period peC = periodType.createPeriod(new DateTime(2000, 2, 1, 0, 0).toDate());
list.add(peA);
list.add(peB);
list.add(peC);
assertEquals(2, list.size());
assertTrue(list.contains(peA));
assertTrue(list.contains(peB));
assertTrue(list.contains(peC));
}
use of org.hisp.dhis.commons.collection.UniqueArrayList in project dhis2-core by dhis2.
the class UniqueArrayListTest method testAddAll.
@Test
public void testAddAll() {
List<Period> list = new ArrayList<>();
PeriodType periodType = new MonthlyPeriodType();
Period peA = periodType.createPeriod(new DateTime(2000, 1, 1, 0, 0).toDate());
// Duplicate
Period peB = periodType.createPeriod(new DateTime(2000, 1, 1, 0, 0).toDate());
Period peC = periodType.createPeriod(new DateTime(2000, 2, 1, 0, 0).toDate());
list.add(peA);
list.add(peB);
list.add(peC);
assertEquals(3, list.size());
List<Period> uniqueList = new UniqueArrayList<>();
uniqueList.addAll(list);
assertEquals(2, uniqueList.size());
assertTrue(uniqueList.contains(peA));
assertTrue(uniqueList.contains(peB));
assertTrue(uniqueList.contains(peC));
}
Aggregations