Example usage for java.util ArrayList removeAll

List of usage examples for java.util ArrayList removeAll

Introduction

In this page you can find the example usage for java.util ArrayList removeAll.

Prototype

public boolean removeAll(Collection<?> c) 

Source Link

Document

Removes from this list all of its elements that are contained in the specified collection.

Usage

From source file:org.nuclos.common.collection.CollectionUtils.java

/**
 * @param a  a list//  w  w  w.  j a v a2s .co m
 * @param b  a list
 * @return a - b, if both are not null, null if a is null, a if b is null
 */
public static <T> List<T> subtract(List<T> a, List<T> b) {
    if (a == null)
        return null;
    if (b == null)
        return a;
    ArrayList<T> r = new ArrayList<T>(a);
    r.removeAll(b);
    return r;
}

From source file:com.bitants.wally.fragments.SavedImagesFragment.java

private void checkIfAddedOrRemovedItem(ArrayList<Uri> oldList, ArrayList<Uri> newList) {
    ArrayList<Uri> oldCompList = new ArrayList<Uri>(oldList);
    ArrayList<Uri> newCompList = new ArrayList<Uri>(newList);

    oldCompList.removeAll(newList);
    if (oldCompList.size() > 0) { //Items removed
        recyclerSavedImagesAdapter.notifyItemRangeRemoved(oldList.indexOf(oldCompList.get(0)),
                oldCompList.size());/*from www .  ja  v  a  2s  . c  o m*/
    }

    newCompList.removeAll(oldList);
    if (newCompList.size() > 0) { //Items added
        recyclerSavedImagesAdapter.notifyItemRangeInserted(newList.indexOf(newCompList.get(0)),
                newCompList.size());
    }
}

From source file:org.svij.taskwarriorapp.TaskAddActivity.java

public void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.Theme_Sherlock_Light_DarkActionBar);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_task_add);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    final TextView tvDueDate = (TextView) findViewById(R.id.tvDueDate);
    tvDueDate.setOnClickListener(new View.OnClickListener() {

        @Override/*from   www  .  j av a2  s . com*/
        public void onClick(View v) {
            DatePickerFragment date = new DatePickerFragment();
            date.setCallBack(onDate);
            date.setTimestamp(timestamp);
            date.show(getSupportFragmentManager().beginTransaction(), "date_dialog");
        }
    });

    final TextView tvDueTime = (TextView) findViewById(R.id.tvDueTime);
    tvDueTime.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            TimePickerFragment date = new TimePickerFragment();
            date.setCallBack(onTime);
            date.setTimestamp(timestamp);
            date.show(getSupportFragmentManager().beginTransaction(), "time_dialog");
        }
    });

    tvDueDate.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            if (TextUtils.isEmpty(tvDueTime.getText().toString())) {
                timestamp = 0;
            } else {
                cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR));
                cal.set(Calendar.MONTH, Calendar.getInstance().get(Calendar.MONTH));
                cal.set(Calendar.DAY_OF_MONTH, Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
                timestamp = cal.getTimeInMillis();
            }
            tvDueDate.setText("");
            return true;
        }
    });

    tvDueTime.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            if (TextUtils.isEmpty(tvDueDate.getText().toString())) {
                timestamp = 0;
            } else {
                cal.set(Calendar.HOUR_OF_DAY, 0);
                cal.set(Calendar.MINUTE, 0);
                cal.set(Calendar.SECOND, 0);
                timestamp = cal.getTimeInMillis();
            }
            tvDueTime.setText("");
            return true;
        }
    });

    TaskDataSource dataSource = new TaskDataSource(this);
    ArrayList<String> projectsAR = dataSource.getProjects();
    projectsAR.removeAll(Collections.singleton(null));
    String[] projects = projectsAR.toArray(new String[projectsAR.size()]);
    final AutoCompleteTextView actvProject = (AutoCompleteTextView) findViewById(R.id.actvProject);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            projects);
    actvProject.setAdapter(adapter);

    actvProject.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View arg0, MotionEvent arg1) {
            actvProject.showDropDown();
            return false;
        }
    });

    Intent intent = getIntent();
    Bundle extras = intent.getExtras();

    if (extras != null) {
        taskID = extras.getString("taskID");

        if (taskID != null) {
            datasource = new TaskDataSource(this);
            Task task = datasource.getTask(UUID.fromString(taskID));

            TextView etTaskAdd = (TextView) findViewById(R.id.etTaskAdd);
            Spinner spPriority = (Spinner) findViewById(R.id.spPriority);
            TextView etTags = (TextView) findViewById(R.id.etTags);

            etTaskAdd.setText(task.getDescription());
            if (task.getDue() != null && task.getDue().getTime() != 0) {

                tvDueDate.setText(DateFormat.getDateInstance(DateFormat.SHORT).format(task.getDue()));
                if (!DateFormat.getTimeInstance().format(task.getDue()).equals("00:00:00")) {
                    tvDueTime.setText(DateFormat.getTimeInstance(DateFormat.SHORT).format(task.getDue()));
                }

                cal.setTime(task.getDue());
                timestamp = cal.getTimeInMillis();

            }
            actvProject.setText(task.getProject());
            Log.i("PriorityID", ":" + task.getPriorityID());
            spPriority.setSelection(task.getPriorityID());
            etTags.setText(task.getTags());
        } else {
            String action = intent.getAction();
            if ((action.equalsIgnoreCase(Intent.ACTION_SEND)
                    || action.equalsIgnoreCase("com.google.android.gm.action.AUTO_SEND"))
                    && intent.hasExtra(Intent.EXTRA_TEXT)) {
                String s = intent.getStringExtra(Intent.EXTRA_TEXT);
                TextView etTaskAdd = (TextView) findViewById(R.id.etTaskAdd);
                etTaskAdd.setText(s);
                addingTaskFromOtherApp = true;
            }
        }
    }

}

From source file:org.svij.taskwarriorapp.activities.TaskAddActivity.java

public void onCreate(Bundle savedInstanceState) {
    setTheme(android.R.style.Theme_Holo_Light_DarkActionBar);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_task_add);

    final TextView tvDueDate = (TextView) findViewById(R.id.tvDueDate);
    tvDueDate.setOnClickListener(new View.OnClickListener() {

        @Override//  w  w  w.  j  av a 2s. co m
        public void onClick(View v) {
            FragmentManager fm = getSupportFragmentManager();
            CalendarDatePickerDialog calendarDatePickerDialog = CalendarDatePickerDialog.newInstance(
                    TaskAddActivity.this, Calendar.getInstance().get(Calendar.YEAR),
                    Calendar.getInstance().get(Calendar.MONTH),
                    Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
            calendarDatePickerDialog.show(fm, "fragment_date_picker");
        }
    });

    final TextView tvDueTime = (TextView) findViewById(R.id.tvDueTime);
    tvDueTime.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            FragmentManager fm = getSupportFragmentManager();
            RadialTimePickerDialog timePickerDialog = RadialTimePickerDialog.newInstance(TaskAddActivity.this,
                    Calendar.getInstance().get(Calendar.HOUR_OF_DAY),
                    Calendar.getInstance().get(Calendar.MINUTE),
                    android.text.format.DateFormat.is24HourFormat(TaskAddActivity.this));
            timePickerDialog.show(fm, "fragment_time_picker_name");
        }
    });

    tvDueDate.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            if (TextUtils.isEmpty(tvDueTime.getText().toString())) {
                timestamp = 0;
            } else {
                cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR));
                cal.set(Calendar.MONTH, Calendar.getInstance().get(Calendar.MONTH));
                cal.set(Calendar.DAY_OF_MONTH, Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
                timestamp = cal.getTimeInMillis();
            }
            tvDueDate.setText("");
            return true;
        }
    });

    tvDueTime.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            if (TextUtils.isEmpty(tvDueDate.getText().toString())) {
                timestamp = 0;
            } else {
                cal.set(Calendar.HOUR_OF_DAY, 0);
                cal.set(Calendar.MINUTE, 0);
                cal.set(Calendar.SECOND, 0);
                timestamp = cal.getTimeInMillis();
            }
            tvDueTime.setText("");
            return true;
        }
    });

    TaskDatabase dataSource = new TaskDatabase(this);
    ArrayList<String> projects = dataSource.getProjects();
    projects.removeAll(Collections.singleton(null));
    final AutoCompleteTextView actvProject = (AutoCompleteTextView) findViewById(R.id.actvProject);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            projects.toArray(new String[projects.size()]));
    actvProject.setAdapter(adapter);
    actvProject.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View arg0, MotionEvent arg1) {
            actvProject.showDropDown();
            return false;
        }
    });

    Intent intent = getIntent();
    Bundle extras = intent.getExtras();

    if (extras != null) {
        taskID = extras.getString("taskID");

        if (taskID != null) {
            data = new TaskDatabase(this);
            Task task = data.getTask(UUID.fromString(taskID));

            TextView etTaskAdd = (TextView) findViewById(R.id.etTaskAdd);
            Spinner spPriority = (Spinner) findViewById(R.id.spPriority);

            etTaskAdd.setText(task.getDescription());
            if (task.getDue() != null && task.getDue().getTime() != 0) {

                tvDueDate.setText(DateFormat.getDateInstance(DateFormat.SHORT).format(task.getDue()));
                if (!DateFormat.getTimeInstance().format(task.getDue()).equals("00:00:00")) {
                    tvDueTime.setText(DateFormat.getTimeInstance(DateFormat.SHORT).format(task.getDue()));
                }

                cal.setTime(task.getDue());
                timestamp = cal.getTimeInMillis();

            }
            actvProject.setText(task.getProject());

            Log.i("PriorityID", ":" + task.getPriorityID());
            spPriority.setSelection(task.getPriorityID());

            if (task.getTags() != null) {
                TextView etTags = (TextView) findViewById(R.id.etTags);
                String tagString = "";

                for (String s : task.getTags()) {
                    tagString += s + " ";
                }
                etTags.setText(tagString.trim());
            }
        } else {
            String action = intent.getAction();
            if ((action.equalsIgnoreCase(Intent.ACTION_SEND)
                    || action.equalsIgnoreCase("com.google.android.gm.action.AUTO_SEND"))
                    && intent.hasExtra(Intent.EXTRA_TEXT)) {
                String s = intent.getStringExtra(Intent.EXTRA_TEXT);
                TextView etTaskAdd = (TextView) findViewById(R.id.etTaskAdd);
                etTaskAdd.setText(s);
                addingTaskFromOtherApp = true;
            }
        }
    }

}

From source file:com.pindroid.syncadapter.BookmarkSyncAdapter.java

private void InsertBookmarks(Account account, SyncResult syncResult) throws AuthenticationException,
        IOException, TooManyRequestsException, ParseException, PinboardException {

    long lastUpdate = getServerSyncMarker(account);
    final String username = account.name;
    mAccount = account;/*from  w w w  .j a  v a 2s.  c  o  m*/

    final Update update = PinboardApi.lastUpdate(account, mContext);

    if (update.getLastUpdate() > lastUpdate) {

        Log.d(TAG, "In Bookmark Load");
        final ArrayList<String> accounts = new ArrayList<String>();
        accounts.add(account.name);

        final ArrayList<Bookmark> addBookmarkList = getBookmarkList();
        BookmarkManager.TruncateBookmarks(accounts, mContext, false);
        if (!addBookmarkList.isEmpty()) {
            List<Bookmark> unsyncedBookmarks = BookmarkManager.GetLocalBookmarks(username, mContext);
            addBookmarkList.removeAll(unsyncedBookmarks);

            BookmarkManager.BulkInsert(addBookmarkList, username, mContext);
        }

        final ArrayList<Tag> tagList = PinboardApi.getTags(account, mContext);
        TagManager.TruncateTags(username, mContext);
        if (!tagList.isEmpty()) {
            TagManager.BulkInsert(tagList, username, mContext);
        }

        SyncNotes();

        setServerSyncMarker(account, update.getLastUpdate());

        syncResult.stats.numEntries += addBookmarkList.size();
    } else {
        Log.d(TAG, "No update needed.  Last update time before last sync.");
    }
}

From source file:com.moscona.dataSpace.ExportHelper.java

public void csvExport(DataFrame df, String fileName, boolean includeMetaData)
        throws FileNotFoundException, DataSpaceException {
    // FIXME exports sorted and label columns twice - once populated and once not - the populated ones are the wrong ones
    PrintStream out = new PrintStream(new File(fileName));
    try {//from   w w  w . j  a v  a2  s. c  om
        ArrayList<String> labels = new ArrayList<String>();
        ArrayList<String> sorted = new ArrayList<String>();

        for (String col : df.getColumnNames()) {
            if (df.isLabel(col)) {
                labels.add(col);
            }
            if (df.get(col).isSorted()) {
                sorted.add(col);
            }
        }

        if (includeMetaData) {
            csvOut(out, "name", df.getName());
            csvOut(out, "description", df.getDescription());
            csvOut(out, "row ID", df.getRowId());
            csvOut(out, "sort column", df.getSortColumn());

            Collections.sort(labels);
            Collections.sort(sorted);

            out.println(excelQuote("label columns") + "," + StringUtils.join(labels, ","));
            out.println(excelQuote("sorted columns") + "," + StringUtils.join(sorted, ","));
            out.println();
        }

        ArrayList<String> columns = new ArrayList<String>();
        ArrayList<String> remaining = new ArrayList<String>(df.getColumnNames());
        if (df.getRowId() != null) {
            // make first column the row ID
            String rowId = df.getRowId();
            columns.add(rowId);
            remaining.remove(rowId);
        }
        // add all the sorted columns
        columns.addAll(sorted);
        remaining.removeAll(sorted);
        remaining.removeAll(labels); // those will come in last
        Collections.sort(remaining);
        columns.addAll(remaining);
        columns.addAll(labels);

        out.println(StringUtils.join(columns, ","));
        IVectorIterator<Map<String, IScalar>> iterator = df.iterator();
        while (iterator.hasNext()) {
            Map<String, IScalar> row = iterator.next();
            ArrayList<String> values = new ArrayList<String>();
            for (String col : columns) {
                values.add(toCsvString(row.get(col)));
            }
            out.println(StringUtils.join(values, ","));
        }
    } finally {
        out.close();
    }
}

From source file:ivory.ltr.GreedyLearn.java

public void train(String featFile, String modelOutputFile, int numModels, String metricClassName,
        boolean pruneCorrelated, double correlationThreshold, boolean logFeatures, boolean productFeatures,
        boolean quotientFeatures, int numThreads) throws IOException, InterruptedException, ExecutionException,
        ConfigurationException, InstantiationException, IllegalAccessException, ClassNotFoundException {
    // read training instances
    Instances trainInstances = new Instances(featFile);

    // get feature map (mapping from feature names to feature number)
    Map<String, Integer> featureMap = trainInstances.getFeatureMap();

    // construct initial model
    Model initialModel = new Model();

    // initialize feature pools
    Map<Model, ArrayList<Feature>> featurePool = new HashMap<Model, ArrayList<Feature>>();
    featurePool.put(initialModel, new ArrayList<Feature>());

    // add simple features to feature pools
    for (String featureName : featureMap.keySet()) {
        featurePool.get(initialModel).add(new SimpleFeature(featureMap.get(featureName), featureName));
    }//from w  w w.  j a va  2  s. c om

    // eliminate document-independent features
    List<Feature> constantFeatures = new ArrayList<Feature>();
    for (int i = 0; i < featurePool.size(); i++) {
        Feature f = featurePool.get(initialModel).get(i);
        if (trainInstances.featureIsConstant(f)) {
            System.err.println("Feature " + f.getName() + " is constant -- removing from feature pool!");
            constantFeatures.add(f);
        }
    }
    featurePool.get(initialModel).removeAll(constantFeatures);

    // initialize score tables
    Map<Model, ScoreTable> scoreTable = new HashMap<Model, ScoreTable>();
    scoreTable.put(initialModel, new ScoreTable(trainInstances));

    // initialize model queue
    List<Model> models = new ArrayList<Model>();
    models.add(initialModel);

    // set up threading
    ExecutorService threadPool = Executors.newFixedThreadPool(numThreads);

    Map<Model, ArrayList<ArrayList<Feature>>> featureBatches = new HashMap<Model, ArrayList<ArrayList<Feature>>>();
    featureBatches.put(initialModel, new ArrayList<ArrayList<Feature>>());

    for (int i = 0; i < numThreads; i++) {
        featureBatches.get(initialModel).add(new ArrayList<Feature>());
    }

    for (int i = 0; i < featurePool.get(initialModel).size(); i++) {
        featureBatches.get(initialModel).get(i % numThreads).add(featurePool.get(initialModel).get(i));
    }

    // greedily add features
    double curMetric = 0.0;
    double prevMetric = Double.NEGATIVE_INFINITY;
    int iter = 1;

    while (curMetric - prevMetric > TOLERANCE) {

        Map<ModelFeaturePair, AlphaMeasurePair> modelFeaturePairMeasures = new HashMap<ModelFeaturePair, AlphaMeasurePair>();

        // update models
        for (Model model : models) {
            List<Future<Map<Feature, AlphaMeasurePair>>> futures = new ArrayList<Future<Map<Feature, AlphaMeasurePair>>>();
            for (int i = 0; i < numThreads; i++) {
                // construct measure
                Measure metric = (Measure) Class.forName(metricClassName).newInstance();

                // line searcher
                LineSearch search = new LineSearch(model, featureBatches.get(model).get(i),
                        scoreTable.get(model), metric);

                Future<Map<Feature, AlphaMeasurePair>> future = threadPool.submit(search);
                futures.add(future);
            }

            for (int i = 0; i < numThreads; i++) {
                Map<Feature, AlphaMeasurePair> featAlphaMeasureMap = futures.get(i).get();
                for (Feature f : featAlphaMeasureMap.keySet()) {
                    AlphaMeasurePair featAlphaMeasure = featAlphaMeasureMap.get(f);
                    modelFeaturePairMeasures.put(new ModelFeaturePair(model, f), featAlphaMeasure);
                }
            }
        }

        // sort model-feature pairs
        List<ModelFeaturePair> modelFeaturePairs = new ArrayList<ModelFeaturePair>(
                modelFeaturePairMeasures.keySet());
        Collections.sort(modelFeaturePairs, new ModelFeatureComparator(modelFeaturePairMeasures));

        // preserve current list of models
        List<Model> oldModels = new ArrayList<Model>(models);

        // add best model feature pairs to pool
        models = new ArrayList<Model>();

        //Lidan: here consider top-K features, rather than just the best one

        for (int i = 0; i < numModels; i++) {
            Model model = modelFeaturePairs.get(i).model;
            Feature feature = modelFeaturePairs.get(i).feature;
            String bestFeatureName = feature.getName();
            AlphaMeasurePair bestAlphaMeasure = modelFeaturePairMeasures.get(modelFeaturePairs.get(i));

            System.err.println("Model = " + model);
            System.err.println("Best feature: " + bestFeatureName);
            System.err.println("Best alpha: " + bestAlphaMeasure.alpha);
            System.err.println("Best measure: " + bestAlphaMeasure.measure);

            Model newModel = new Model(model);
            models.add(newModel);

            ArrayList<ArrayList<Feature>> newFeatureBatch = new ArrayList<ArrayList<Feature>>();
            for (ArrayList<Feature> fb : featureBatches.get(model)) {
                newFeatureBatch.add(new ArrayList<Feature>(fb));
            }
            featureBatches.put(newModel, newFeatureBatch);
            featurePool.put(newModel, new ArrayList<Feature>(featurePool.get(model)));

            // add auxiliary features (for atomic features only)
            if (featureMap.containsKey(bestFeatureName)) {
                int bestFeatureIndex = featureMap.get(bestFeatureName);

                // add log features, if requested
                if (logFeatures) {
                    Feature logFeature = new LogFeature(bestFeatureIndex, "log(" + bestFeatureName + ")");
                    featureBatches.get(newModel).get(bestFeatureIndex % numThreads).add(logFeature);
                    featurePool.get(newModel).add(logFeature);
                }

                // add product features, if requested
                if (productFeatures) {
                    for (String featureNameB : featureMap.keySet()) {
                        int indexB = featureMap.get(featureNameB);
                        Feature prodFeature = new ProductFeature(bestFeatureIndex, indexB,
                                bestFeatureName + "*" + featureNameB);
                        featureBatches.get(newModel).get(indexB % numThreads).add(prodFeature);
                        featurePool.get(newModel).add(prodFeature);
                    }
                }

                // add quotient features, if requested
                if (quotientFeatures) {
                    for (String featureNameB : featureMap.keySet()) {
                        int indexB = featureMap.get(featureNameB);
                        Feature divFeature = new QuotientFeature(bestFeatureIndex, indexB,
                                bestFeatureName + "/" + featureNameB);
                        featureBatches.get(newModel).get(indexB % numThreads).add(divFeature);
                        featurePool.get(newModel).add(divFeature);
                    }
                }
            }

            // prune highly correlated features
            if (pruneCorrelated) {
                if (!newModel.containsFeature(feature)) {
                    List<Feature> correlatedFeatures = new ArrayList<Feature>();

                    for (Feature f : featurePool.get(newModel)) {
                        if (f == feature) {
                            continue;
                        }
                        double correl = trainInstances.getCorrelation(f, feature);
                        if (correl > correlationThreshold) {
                            System.err.println("Pruning highly correlated feature: " + f.getName());
                            correlatedFeatures.add(f);
                        }
                    }

                    for (ArrayList<Feature> batch : featureBatches.get(newModel)) {
                        batch.removeAll(correlatedFeatures);
                    }

                    featurePool.get(newModel).removeAll(correlatedFeatures);
                }
            }

            // update score table
            if (iter == 0) {
                scoreTable.put(newModel, scoreTable.get(model).translate(feature, 1.0, 1.0));
                newModel.addFeature(feature, 1.0);
            } else {
                scoreTable.put(newModel, scoreTable.get(model).translate(feature, bestAlphaMeasure.alpha,
                        1.0 / (1.0 + bestAlphaMeasure.alpha)));
                newModel.addFeature(feature, bestAlphaMeasure.alpha);
            }
        }

        for (Model model : oldModels) {
            featurePool.remove(model);
            featureBatches.remove(model);
            scoreTable.remove(model);
        }

        // update metrics
        prevMetric = curMetric;
        curMetric = modelFeaturePairMeasures.get(modelFeaturePairs.get(0)).measure;

        iter++;
    }

    // serialize model
    System.out.println("Final Model: " + models.get(0));
    models.get(0).write(modelOutputFile);

    threadPool.shutdown();
}

From source file:org.apache.hadoop.hbase.regionserver.compactions.StripeCompactionPolicy.java

public List<StoreFile> preSelectFilesForCoprocessor(StripeInformationProvider si,
        List<StoreFile> filesCompacting) {
    // We sincerely hope nobody is messing with us with their coprocessors.
    // If they do, they are very likely to shoot themselves in the foot.
    // We'll just exclude all the filesCompacting from the list.
    ArrayList<StoreFile> candidateFiles = new ArrayList<StoreFile>(si.getStorefiles());
    candidateFiles.removeAll(filesCompacting);
    return candidateFiles;
}

From source file:org.eclipse.emf.teneo.annotations.mapper.AbstractProcessingContext.java

/**
 * Remove all id-features not inherited from a direct mapped superclass, and
 * add the features from the mapped superclass
 *//*from w ww.  j  a  va  2 s  .c o  m*/
private void removeIdFeatures(PAnnotatedEClass aClass, List<EStructuralFeature> inheritedFeatures) {
    // first get all the mapped superclasses
    final ArrayList<EClass> mappedSuperEClasses = new ArrayList<EClass>();
    for (EClass superEClass : aClass.getModelEClass().getESuperTypes()) {
        final PAnnotatedEClass superPAClass = aClass.getPaModel().getPAnnotated(superEClass);
        if (superPAClass != null && superPAClass.getMappedSuperclass() != null) {
            mappedSuperEClasses.add(superPAClass.getModelEClass());
        }
    }

    // now get all the efeatures of the mappedsuperclasses to prevent any id
    // features from them being removed, only do that when the aclass does
    // not
    // have a real super type, in that case the id can be inherited from the
    // mappedsuperclass
    final ArrayList<EStructuralFeature> mappedSuperFeatures = new ArrayList<EStructuralFeature>();
    if (aClass.getPaSuperEntity() == null || aClass.getPaSuperEntity().getMappedSuperclass() != null) {
        for (EClass mappedSuperEClass : mappedSuperEClasses) {
            mappedSuperFeatures.removeAll(mappedSuperEClass.getEAllStructuralFeatures());
            mappedSuperFeatures.addAll(mappedSuperEClass.getEAllStructuralFeatures());
        }
    }

    // now remove all id features not coming from a direct mapped superclass
    final ArrayList<EStructuralFeature> toRemove = new ArrayList<EStructuralFeature>();
    for (EStructuralFeature esf : inheritedFeatures) {
        final PAnnotatedEStructuralFeature pef = aClass.getPaModel().getPAnnotated(esf);

        if (pef instanceof PAnnotatedEAttribute && ((PAnnotatedEAttribute) pef).getId() != null
                && !mappedSuperFeatures.contains(esf)) {
            toRemove.add(esf);
        }
    }
    inheritedFeatures.removeAll(toRemove);
}

From source file:org.opendaylight.genius.itm.listeners.VtepConfigSchemaListener.java

/**
 * Handle deleted dpns from schema.//from  ww w. j a v  a  2 s . c om
 *
 * @param original
 *            the original
 * @param originalDpnIds
 *            the original dpn ids
 * @param updatedDpnIds
 *            the updated dpn ids
 */
private void handleDeletedDpnsFromSchema(VtepConfigSchema original, List<DpnIds> originalDpnIds,
        List<DpnIds> updatedDpnIds) {
    ArrayList<DpnIds> deletedDpns = new ArrayList<>(originalDpnIds);
    deletedDpns.removeAll(updatedDpnIds);
    LOG.debug("DPNs to be removed DPNs {} from VTEP config schema [{}].", deletedDpns,
            original.getSchemaName());
    if (!deletedDpns.isEmpty()) {
        LOG.debug("Deleting of DPNs from VTEP Schema: {}. To be deleted Dpns: {}", original, deletedDpns);
        deleteVteps(original, ItmUtils.getDpnIdList(deletedDpns));
    }
}