Example usage for java.util.concurrent CopyOnWriteArrayList remove

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

Introduction

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

Prototype

public boolean remove(Object o) 

Source Link

Document

Removes the first occurrence of the specified element from this list, if it is present.

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   w  ww  .  j a v a  2  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:codetoanalyze.java.checkers.ContainerWrapper.java

void accessSafeListOk(CopyOnWriteArrayList list, int index) {
    list.remove(index);
}

From source file:org.jboss.windup.bootstrap.Bootstrap.java

private boolean executePhase(CommandPhase phase, CopyOnWriteArrayList<Command> commands) {
    for (Command command : commands) {
        if (phase.equals(command.getPhase())) {
            commands.remove(command);
            if (command instanceof FurnaceDependent)
                ((FurnaceDependent) command).setFurnace(furnace);

            CommandResult result = command.execute();
            if (CommandResult.EXIT.equals(result))
                return false;
        }/*  w  w w.  j a v a2s .c om*/
    }
    return true;
}

From source file:eu.tango.energymodeller.datasourceclient.WattsUpMeterDataSourceAdaptor.java

@Override
public synchronized double getCpuUtilisation(Host host, int lastNSeconds) {
    double count = 0.0;
    double sumOfUtil = 0.0;
    GregorianCalendar cal = new GregorianCalendar();
    long now = TimeUnit.MILLISECONDS.toSeconds(cal.getTimeInMillis());
    long nowMinustime = now - lastNSeconds;
    CopyOnWriteArrayList<CPUUtilisation> list = new CopyOnWriteArrayList<>();
    list.addAll(cpuMeasure);/* w w w. ja va 2  s  .c  om*/
    for (Iterator<CPUUtilisation> it = list.iterator(); it.hasNext();) {
        CPUUtilisation util = it.next();
        if (util.isOlderThan(nowMinustime)) {
            list.remove(util);
            cpuMeasure.remove(util);
        } else {
            sumOfUtil = sumOfUtil + util.getCpuBusy();
            count = count + 1;
        }
    }
    if (count == 0) {
        return 0.0;
    }
    return sumOfUtil / count;
}

From source file:com.web.messaging.MessagingClassConstruct.java

/**
 * This method parses the messagingclass.xml which is obtained after undeploying the War file and metadata which is constructed in removed from the messaingclassMap 
 * @param messagedigester//  w  w  w.  j  a  v  a 2  s  .  c om
 * @param configFile
 * @param messagingClassMap
 * @throws FileNotFoundException
 * @throws IOException
 * @throws SAXException
 */
public void removeMessagingClass(Digester messagedigester, File configFile, Hashtable messagingClassMap)
        throws FileNotFoundException, IOException, SAXException {
    try {
        MessagingClasses messagingClasses = (MessagingClasses) messagedigester
                .parse(new InputSource(new FileInputStream(configFile)));
        for (MessagingClass messagingclass : messagingClasses.messagingClasses) {
            if (messagingclass.getMessagetype().equals("RandomQueue")) {
                ConcurrentHashMap randomqueuemap = (ConcurrentHashMap) messagingClassMap.get("RandomQueue");
                //System.out.println("MessageElemName="+messagingclass.getMessageelemname().trim()+"Random Queue Map"+randomqueuemap);
                if (randomqueuemap != null) {
                    CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) randomqueuemap
                            .get(messagingclass.getMessageelemname().trim());
                    if (queueclassList != null) {
                        for (int count = 0; count < queueclassList.size(); count++) {
                            MessagingClass messagingClassTmp = (MessagingClass) queueclassList.get(count);
                            //System.out.println(messagingClassTmp);
                            //System.out.println(messagingClassTmp.getMessageelemname()+" "+messagingclass.getMessageelemname() );
                            //System.out.println(messagingClassTmp.getMessagetype()+" "+messagingclass.getMessagetype() );
                            //System.out.println(messagingClassTmp.getMessagingclass()+" "+messagingclass.getMessagingclass() );
                            if (messagingClassTmp.getMessageelemname().trim()
                                    .equals(messagingclass.getMessageelemname().trim())
                                    && messagingClassTmp.getMessagetype().trim()
                                            .equals(messagingclass.getMessagetype().trim())
                                    && messagingClassTmp.getMessagingclass().trim()
                                            .equals(messagingclass.getMessagingclass().trim())) {
                                queueclassList.remove(messagingClassTmp);
                            }
                            //System.out.println(count);
                            //System.out.println("MessageElemName="+messagingClassTmp);
                        }
                    }
                }
            } else if (messagingclass.getMessagetype().equals("RoundRobinQueue")) {
                ConcurrentHashMap roundrobinqueuemap = (ConcurrentHashMap) messagingClassMap
                        .get("RoundRobinQueue");
                //System.out.println("RoundRobinQueueMap"+roundrobinqueuemap);
                if (roundrobinqueuemap != null) {
                    CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) roundrobinqueuemap
                            .get(messagingclass.getMessageelemname().trim());
                    if (queueclassList != null) {
                        for (int count = 0; count < queueclassList.size(); count++) {
                            MessagingClass messagingClassTmp = (MessagingClass) queueclassList.get(count);
                            if (messagingClassTmp.getMessageelemname()
                                    .equals(messagingclass.getMessageelemname())
                                    && messagingClassTmp.getMessagetype()
                                            .equals(messagingclass.getMessagetype())
                                    && messagingClassTmp.getMessagingclass()
                                            .equals(messagingclass.getMessagingclass())) {
                                queueclassList.remove(messagingClassTmp);
                            }

                        }
                    }
                }
                //System.out.println("End RoundRobinQueueMap"+roundrobinqueuemap);
            } else if (messagingclass.getMessagetype().equals("Topic")) {
                ConcurrentHashMap topicmap = (ConcurrentHashMap) messagingClassMap.get("Topic");
                //System.out.println("TopicMap"+topicmap);
                if (topicmap != null) {
                    CopyOnWriteArrayList topicclassList = (CopyOnWriteArrayList) topicmap
                            .get(messagingclass.getMessageelemname().trim());
                    if (topicclassList != null) {
                        for (int count = 0; count < topicclassList.size(); count++) {
                            MessagingClass messagingClassTmp = (MessagingClass) topicclassList.get(count);
                            if (messagingClassTmp.getMessageelemname()
                                    .equals(messagingclass.getMessageelemname())
                                    && messagingClassTmp.getMessagetype()
                                            .equals(messagingclass.getMessagetype())
                                    && messagingClassTmp.getMessagingclass()
                                            .equals(messagingclass.getMessagingclass())) {
                                topicclassList.remove(messagingClassTmp);
                            }
                        }
                    }
                }
                //System.out.println("End TopicMap"+topicmap);
            }
        }
    } catch (Exception ex) {
        //ex.printStackTrace();
    }
    //System.out.println(messagingClassMap);
}

From source file:com.app.messaging.MessagingClassConstruct.java

/**
 * This method parses the messagingclass.xml which is obtained after undeploying the War file and metadata which is constructed in removed from the messaingclassMap 
 * @param messagedigester/*from   w w w  . j a  v  a  2s . co m*/
 * @param configFile
 * @param messagingClassMap
 * @throws FileNotFoundException
 * @throws IOException
 * @throws SAXException
 */
public void removeMessagingClass(Digester messagedigester, File configFile, Hashtable messagingClassMap)
        throws FileNotFoundException, IOException, SAXException {
    try {
        MessagingClasses messagingClasses = (MessagingClasses) messagedigester
                .parse(new InputSource(new FileInputStream(configFile)));
        for (MessagingClass messagingclass : messagingClasses.messagingClasses) {
            if (messagingclass.getMessagetype().equals("RandomQueue")) {
                ConcurrentHashMap randomqueuemap = (ConcurrentHashMap) messagingClassMap.get("RandomQueue");
                //System.out.println("MessageElemName="+messagingclass.getMessageelemname().trim()+"Random Queue Map"+randomqueuemap);
                if (randomqueuemap != null) {
                    CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) randomqueuemap
                            .get(messagingclass.getMessageelemname().trim());
                    if (queueclassList != null) {
                        for (int count = 0; count < queueclassList.size(); count++) {
                            MessagingClass messagingClassTmp = (MessagingClass) queueclassList.get(count);
                            //System.out.println(messagingClassTmp);
                            //System.out.println(messagingClassTmp.getMessageelemname()+" "+messagingclass.getMessageelemname() );
                            //System.out.println(messagingClassTmp.getMessagetype()+" "+messagingclass.getMessagetype() );
                            //System.out.println(messagingClassTmp.getMessagingclass()+" "+messagingclass.getMessagingclass() );
                            if (messagingClassTmp.getMessageelemname().trim()
                                    .equals(messagingclass.getMessageelemname().trim())
                                    && messagingClassTmp.getMessagetype().trim()
                                            .equals(messagingclass.getMessagetype().trim())
                                    && messagingClassTmp.getMessagingclass().trim()
                                            .equals(messagingclass.getMessagingclass().trim())) {
                                queueclassList.remove(messagingClassTmp);
                            }
                            //System.out.println(count);
                            //System.out.println("MessageElemName="+messagingClassTmp);
                        }
                    }
                }
            } else if (messagingclass.getMessagetype().equals("RoundRobinQueue")) {
                ConcurrentHashMap roundrobinqueuemap = (ConcurrentHashMap) messagingClassMap
                        .get("RoundRobinQueue");
                //System.out.println("RoundRobinQueueMap"+roundrobinqueuemap);
                if (roundrobinqueuemap != null) {
                    CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) roundrobinqueuemap
                            .get(messagingclass.getMessageelemname().trim());
                    if (queueclassList != null) {
                        for (int count = 0; count < queueclassList.size(); count++) {
                            MessagingClass messagingClassTmp = (MessagingClass) queueclassList.get(count);
                            if (messagingClassTmp.getMessageelemname()
                                    .equals(messagingclass.getMessageelemname())
                                    && messagingClassTmp.getMessagetype()
                                            .equals(messagingclass.getMessagetype())
                                    && messagingClassTmp.getMessagingclass()
                                            .equals(messagingclass.getMessagingclass())) {
                                queueclassList.remove(messagingClassTmp);
                            }

                        }
                    }
                }
                //System.out.println("End RoundRobinQueueMap"+roundrobinqueuemap);
            } else if (messagingclass.getMessagetype().equals("Topic")) {
                ConcurrentHashMap topicmap = (ConcurrentHashMap) messagingClassMap.get("Topic");
                //System.out.println("TopicMap"+topicmap);
                if (topicmap != null) {
                    CopyOnWriteArrayList topicclassList = (CopyOnWriteArrayList) topicmap
                            .get(messagingclass.getMessageelemname().trim());
                    if (topicclassList != null) {
                        for (int count = 0; count < topicclassList.size(); count++) {
                            MessagingClass messagingClassTmp = (MessagingClass) topicclassList.get(count);
                            if (messagingClassTmp.getMessageelemname()
                                    .equals(messagingclass.getMessageelemname())
                                    && messagingClassTmp.getMessagetype()
                                            .equals(messagingclass.getMessagetype())
                                    && messagingClassTmp.getMessagingclass()
                                            .equals(messagingclass.getMessagingclass())) {
                                topicclassList.remove(messagingClassTmp);
                            }
                        }
                    }
                }
                //System.out.println("End TopicMap"+topicmap);
            }
        }
    } catch (Exception ex) {
        log.error("Error occurred in constructing messaging classes", ex);
        //ex.printStackTrace();
    }
    //System.out.println(messagingClassMap);
}