Example usage for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList

List of usage examples for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList

Introduction

In this page you can find the example usage for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList.

Prototype

public CopyOnWriteArrayList(E[] toCopyIn) 

Source Link

Document

Creates a list holding a copy of the given array.

Usage

From source file:tech.tablesaw.filters.TimeDependentFilteringTest.java

public static void main(String[] args) throws Exception {

    int numberOfRecordsInTable = 100_000_000;
    Stopwatch stopwatch = Stopwatch.createStarted();

    Table t = defineSchema();/*from ww w.  ja  v a2 s. co  m*/
    generateTestData(t, numberOfRecordsInTable, stopwatch);

    t.setName("Observations");

    // non temporal constraints
    String conceptA = t.stringColumn("concept").get(RandomUtils.nextInt(0, t.rowCount()));
    String conceptB = t.stringColumn("concept").get(RandomUtils.nextInt(0, t.rowCount()));

    // independent temporal constraints
    String conceptZ = t.stringColumn("concept").get(RandomUtils.nextInt(0, t.rowCount()));
    String conceptD = t.stringColumn("concept").get(RandomUtils.nextInt(0, t.rowCount()));
    DependencyFilter independentConstraintFilter = DependencyFilter.FIRST;

    // temporal dependency range constraint
    Range<Integer> daysConstraint = Range.closed(0, 0);

    StringColumn concept = t.stringColumn("concept");

    //Non-temporal clause
    Table nt = t.where(concept.isEqualTo(conceptA).and(concept.isNotEqualTo(conceptB)));

    DoubleColumn ntPatients = nt.doubleColumn("patient");

    // Group the original table by patient id
    TableSliceGroup patients = StandardTableSliceGroup.create(t, "patient");

    // Create a list of patient sub-tables to work with TODO(lwhite): Build the copy-on-write to ViewGroups to avoid
    CopyOnWriteArrayList<TableSlice> patientTables = new CopyOnWriteArrayList<>(patients.getSlices());

    // Apply the independent temporal event filtering to the patient subtables and remove any that don't pass
    for (TableSlice patientTable : patients) {
        StringColumn concepts = patientTable.stringColumn("concept");
        double patientId = Double.parseDouble(patientTable.name());
        if (!concepts.contains(conceptZ) || concepts.contains(conceptD)) {
            patientTables.remove(patientTable);
        } else if (!ntPatients.contains(patientId)) { // filtering out the non-temporal now constraints for
            // efficiency
            patientTables.remove(patientTable);
        }
    }

    List<IndependentResult> independentResults = new ArrayList<>();

    // Working with the filtered patient tables, calculate the event dates for the independent events
    for (TableSlice patientTable : patientTables) {
        IndependentResult result = new IndependentResult();
        List<LocalDate> eventDates = new ArrayList<>();

        // iterate an individual table and find the rows where concept matches the target concept
        for (int row : patientTable) {
            StringColumn concepts = patientTable.stringColumn("concept");
            DateColumn dates = patientTable.dateColumn("date");
            if (concepts.get(row).equals(conceptZ)) {
                eventDates.add(dates.get(row));
            }
        }

        if (independentConstraintFilter == DependencyFilter.FIRST) {
            if (eventDates.isEmpty()) {
                // this is an error
                fail("There are no event dates");
            } else { //Get the first event for the current patient and createFromCsv a date range around it
                LocalDate date = eventDates.get(0);
                result.addRange(Range.closed(date.minusDays(daysConstraint.lowerEndpoint()),
                        date.plusDays(daysConstraint.upperEndpoint())));
            } //TODO handle last and any cases
        }
        independentResults.add(result);
    }
}

From source file:Main.java

public static <T> List<T> createConcurrentList(T... items) {
    return new CopyOnWriteArrayList<T>(items);
}

From source file:Main.java

public static <E> CopyOnWriteArrayList<E> getCopyOnWriteArrayList(E[] toCopyIn) {
    return new CopyOnWriteArrayList<E>(toCopyIn);
}

From source file:Main.java

/**
 * Create a {@link CopyOnWriteArrayList} from a given {@link Collection}
 * @param source/*from w w w.j  a  v  a  2s . c  o m*/
 * @return CopyOnWriteArrayList<O>
 */
public static <O> CopyOnWriteArrayList<O> copyOnWriteArrayList(Collection<O> source) {
    return new CopyOnWriteArrayList<>(source);
}

From source file:Main.java

public static <E> CopyOnWriteArrayList<E> newCopyOnWriteArrayList(final Collection<E> collection) {
    return new CopyOnWriteArrayList<E>(collection);
}

From source file:Main.java

public static <E> CopyOnWriteArrayList<E> newCopyOnWriteArrayList(final Collection<? extends E> c) {
    return new CopyOnWriteArrayList<E>(c);
}

From source file:Main.java

public static <E> CopyOnWriteArrayList<E> newCopyOnWriteArrayList(final E[] array) {
    return new CopyOnWriteArrayList<E>(array);
}

From source file:Main.java

public static <E> CopyOnWriteArrayList<E> newCopyOnWriteArrayList(final E[] toCopyIn) {
    return new CopyOnWriteArrayList<E>(toCopyIn);
}

From source file:Main.java

/**
 * Creates a new {@link CopyOnWriteArrayList} that contains all of the 
 * elements in {@code original}. Keep in mind that you only want to use 
 * {@code CopyOnWriteArrayList} for lists that are not going to be 
 * modified very often!//from   w  w w . j  a  va2  s. c om
 * 
 * @param original Collection to be copied into the new list.
 * 
 * @return A new {@code CopyOnWriteArrayList} whose contents are the same 
 * as {@code original}.
 */
public static <E> List<E> concurrentList(Collection<E> original) {
    return new CopyOnWriteArrayList<>(original);
}

From source file:Main.java

/**
 * Creates a new {@link CopyOnWriteArrayList} from the incoming 
 * {@literal "varargs"}. Keep in mind that you only want to use 
 * {@code CopyOnWriteArrayList} for lists that are not going to be modified 
 * very often!/*  w w  w  . j av a  2s. c o m*/
 * 
 * @param elems Elements that will be contained in the resulting list.
 * 
 * @return A new {@code CopyOnWriteArrayList} that contains the incoming 
 * objects.
 */
public static <E> List<E> concurrentList(E... elems) {
    return new CopyOnWriteArrayList<>(elems);
}