Example usage for java.util List removeAll

List of usage examples for java.util List removeAll

Introduction

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

Prototype

boolean removeAll(Collection<?> c);

Source Link

Document

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

Usage

From source file:com.thesmartweb.swebrank.Moz.java

/**
 * Method that captures the various Moz metrics for the provided urls (with help of the sample here https://github.com/seomoz/SEOmozAPISamples
 * and ranks them accordingly/*  w ww.  j ava2  s . co m*/
 * @param links the urls to analyze
 * @param top_count the amount of results to keep when we rerank the results according to their value of a specific Moz metric
 * @param moz_threshold the threshold to the Moz value to use
 * @param moz_threshold_option flag if we are going to use threshold in the Moz value or not
 * @param mozMetrics list that contains which metric to use for Moz //1st place is Page Authority,2nd external mozRank, 3rd, mozTrust, 4th DomainAuthority and 5th MozRank (it is the default)
 * @param config_path path that has the config files with the api keys and secret for Moz
 * @return an array with the links sorted according to their moz values
 */
public String[] perform(String[] links, int top_count, Double moz_threshold, Boolean moz_threshold_option,
        List<Boolean> mozMetrics, String config_path) {
    //=====short codes for the metrics 
    long upa = 34359738368L;//page authority
    long pda = 68719476736L;//domain authority
    long uemrp = 1048576;//mozrank external equity
    long utrp = 131072;//moztrust 
    long fmrp = 32768;//mozrank subdomain
    long umrp = 16384;//mozrank
    System.gc();
    System.out.println("into Moz");
    Double[] mozRanks = new Double[links.length];
    DataManipulation textualmanipulation = new DataManipulation();
    for (int i = 0; i < links.length; i++) {
        if (links[i] != null) {
            if (!textualmanipulation.StructuredFileCheck(links[i])) {
                try {
                    Thread.sleep(10000);
                    URLMetricsService urlMetricsservice;
                    urlMetricsservice = authenticate(config_path);
                    String objectURL = links[i].substring(0, links[i].length());
                    Gson gson = new Gson();
                    if (mozMetrics.get(1)) {//Domain Authority
                        String response = urlMetricsservice.getUrlMetrics(objectURL, pda);
                        UrlResponse res = gson.fromJson(response, UrlResponse.class);
                        System.gc();
                        if (res != null && !(response.equalsIgnoreCase("{}"))) {
                            String mozvalue_string = res.getPda();
                            mozRanks[i] = Double.parseDouble(mozvalue_string);
                        } else {
                            mozRanks[i] = Double.parseDouble("0");
                        }
                    } else if (mozMetrics.get(2)) {//External MozRank
                        String response = urlMetricsservice.getUrlMetrics(objectURL, uemrp);
                        UrlResponse res = gson.fromJson(response, UrlResponse.class);
                        System.gc();
                        if (res != null && !(response.equalsIgnoreCase("{}"))) {
                            String mozvalue_string = res.getUemrp();
                            mozRanks[i] = Double.parseDouble(mozvalue_string);
                        } else {
                            mozRanks[i] = Double.parseDouble("0");
                        }
                    } else if (mozMetrics.get(3)) {//MozRank
                        String response = urlMetricsservice.getUrlMetrics(objectURL, umrp);
                        UrlResponse res = gson.fromJson(response, UrlResponse.class);
                        System.gc();
                        if (res != null && !(response.equalsIgnoreCase("{}"))) {
                            String mozvalue_string = res.getUmrp();
                            mozRanks[i] = Double.parseDouble(mozvalue_string);
                        } else {
                            mozRanks[i] = Double.parseDouble("0");
                        }
                    } else if (mozMetrics.get(4)) {//MozTrust
                        String response = urlMetricsservice.getUrlMetrics(objectURL, utrp);
                        UrlResponse res = gson.fromJson(response, UrlResponse.class);
                        System.gc();
                        if (res != null && !(response.equalsIgnoreCase("{}"))) {
                            String mozvalue_string = res.getUtrp();
                            mozRanks[i] = Double.parseDouble(mozvalue_string);
                        } else {
                            mozRanks[i] = Double.parseDouble("0");
                        }
                    } else if (mozMetrics.get(5)) {//Page Authority
                        String response = urlMetricsservice.getUrlMetrics(objectURL, upa);
                        UrlResponse res = gson.fromJson(response, UrlResponse.class);
                        System.gc();
                        if (res != null && !(response.equalsIgnoreCase("{}"))) {
                            String mozvalue_string = res.getUpa();
                            mozRanks[i] = Double.parseDouble(mozvalue_string);
                        } else {
                            mozRanks[i] = Double.parseDouble("0");
                        }
                    } else if (mozMetrics.get(6)) {//subdomain MozRank
                        String response = urlMetricsservice.getUrlMetrics(objectURL, fmrp);
                        UrlResponse res = gson.fromJson(response, UrlResponse.class);
                        System.gc();
                        if (res != null && !(response.equalsIgnoreCase("{}"))) {
                            String mozvalue_string = res.getFmrp();
                            mozRanks[i] = Double.parseDouble(mozvalue_string);
                        } else {
                            mozRanks[i] = Double.parseDouble("0");
                        }
                    }
                } catch (InterruptedException | JsonSyntaxException | NumberFormatException ex) {
                    System.out.println("exception moz:" + ex.toString());
                    mozRanks[i] = Double.parseDouble("0");
                    String[] links_out = null;
                    return links_out;
                }
            } else {
                mozRanks[i] = Double.parseDouble("0");
            }
        }
    }
    try {//ranking of the urls according to their moz score
         //get the scores to a list
        System.out.println("I am goint to rank the scores of Moz");
        System.gc();
        List<Double> seomozRanks_scores_list = Arrays.asList(mozRanks);
        //create a hashmap in order to map the scores with the indexes
        System.gc();
        IdentityHashMap<Double, Integer> originalIndices = new IdentityHashMap<Double, Integer>();
        //copy the original scores list
        System.gc();
        for (int i = 0; i < seomozRanks_scores_list.size(); i++) {
            originalIndices.put(seomozRanks_scores_list.get(i), i);
            System.gc();
        }
        //sort the scores
        List<Double> sorted_seomozRanks_scores = new ArrayList<Double>();
        System.gc();
        sorted_seomozRanks_scores.addAll(seomozRanks_scores_list);
        System.gc();
        sorted_seomozRanks_scores.removeAll(Collections.singleton(null));
        System.gc();
        if (!sorted_seomozRanks_scores.isEmpty()) {
            Collections.sort(sorted_seomozRanks_scores, Collections.reverseOrder());
        }
        //get the original indexes
        //the max amount of results
        int[] origIndex = new int[150];
        if (!sorted_seomozRanks_scores.isEmpty()) {
            //if we want to take the top scores(for example top 10)
            if (!moz_threshold_option) {
                origIndex = new int[top_count];
                for (int i = 0; i < top_count; i++) {
                    Double score = sorted_seomozRanks_scores.get(i);
                    System.gc();
                    // Lookup original index efficiently
                    origIndex[i] = originalIndices.get(score);
                }
            }
            //if we have a threshold
            else if (moz_threshold_option) {
                int j = 0;
                int counter = 0;
                while (j < sorted_seomozRanks_scores.size()) {
                    if (sorted_seomozRanks_scores.get(j).compareTo(moz_threshold) >= 0) {
                        counter++;
                    }
                    j++;
                }
                origIndex = new int[counter];
                for (int k = 0; k < origIndex.length - 1; k++) {
                    System.gc();
                    Double score = sorted_seomozRanks_scores.get(k);
                    origIndex[k] = originalIndices.get(score);
                }
            }
        }
        String[] links_out = new String[origIndex.length];
        for (int jj = 0; jj < origIndex.length; jj++) {
            System.gc();
            links_out[jj] = links[origIndex[jj]];
        }
        System.gc();
        System.out.println("I have ranked the scores of moz");
        return links_out;
    } catch (Exception ex) {
        System.out.println("exception moz list" + ex.toString());
        //Logger.getLogger(Moz.class.getName()).log(Level.SEVERE, null, ex);
        String[] links_out = null;
        return links_out;
    }
}

From source file:hudson.scm.parameter.listdirs.ListDirectoriesParameterDefinition.java

/**
 * Removes the parent directory (that is, the tags directory) from a list of
 * directories.//from   w w  w.j  a v  a 2  s. co m
 */
protected void removeParentDir(List<String> dirs) {
    List<String> dirsToRemove = new ArrayList<String>();
    for (String dir : dirs) {
        if (getRepositoryURL().endsWith(dir)) {
            dirsToRemove.add(dir);
        }
    }
    dirs.removeAll(dirsToRemove);
}

From source file:com.github.trask.sandbox.ec2.Ec2Service.java

public void syncInboundRules(SecurityGroup securityGroup, List<IpPermission> ipPermissions) {
    List<WrappedIpPermission> revokeWrappedIpPermissions = wrap(securityGroup.getIpPermissions());
    revokeWrappedIpPermissions.removeAll(wrap(ipPermissions));
    List<WrappedIpPermission> authorizeWrappedIpPermissions = wrap(ipPermissions);
    authorizeWrappedIpPermissions.removeAll(wrap(securityGroup.getIpPermissions()));

    // revoke must be done first in case one of multiple UserIdGroupPairs for
    // a single IpPermission is being revoked
    if (!revokeWrappedIpPermissions.isEmpty()) {
        RevokeSecurityGroupIngressRequest request = new RevokeSecurityGroupIngressRequest(
                securityGroup.getGroupName(), new ArrayList<IpPermission>(unwrap(revokeWrappedIpPermissions)));
        ec2.revokeSecurityGroupIngress(request);
    }/* w  ww.java  2 s .c  om*/
    if (!authorizeWrappedIpPermissions.isEmpty()) {
        AuthorizeSecurityGroupIngressRequest request = new AuthorizeSecurityGroupIngressRequest(
                securityGroup.getGroupName(),
                new ArrayList<IpPermission>(unwrap(authorizeWrappedIpPermissions)));
        ec2.authorizeSecurityGroupIngress(request);
    }
}

From source file:com.all.ultrapeer.UltrapeerService.java

private List<UltrapeerNode> getNewUltrapeers(List<UltrapeerNode> clientList) {
    List<UltrapeerNode> newUltrapeers = new ArrayList<UltrapeerNode>(currentUltrapeers);
    newUltrapeers.removeAll(clientList);
    return newUltrapeers.isEmpty() ? null : newUltrapeers;
}

From source file:net.sf.jabref.pdfimport.PdfImporter.java

/**
 *
 * Imports the PDF files given by fileNames
 *
 * @param fileNames states the names of the files to import
 * @return list of successful created BibTeX entries and list of non-PDF files
 *//*from w  w  w  . jav a2s  .co m*/
public ImportPdfFilesResult importPdfFiles(String[] fileNames) {
    // sort fileNames in PDFfiles to import and other files
    // PDFfiles: variable files
    // other files: variable noPdfFiles
    List<String> files = new ArrayList<>(Arrays.asList(fileNames));
    List<String> noPdfFiles = new ArrayList<>();
    PdfFileFilter pdfFilter = PdfFileFilter.INSTANCE;
    for (String file : files) {
        if (!pdfFilter.accept(file)) {
            noPdfFiles.add(file);
        }
    }
    files.removeAll(noPdfFiles);
    // files and noPdfFiles correctly sorted

    // import the files
    List<BibEntry> entries = importPdfFiles(files);

    return new ImportPdfFilesResult(noPdfFiles, entries);
}

From source file:cz.zcu.kiv.eegdatabase.wui.ui.experiments.components.ExperimentPackageManagePanel.java

/**
 * Add window which allows to add new license to the package.
 *///from w w  w  . j a  v  a  2 s  . co m
private void addLicenseAddWindow() {
    addLicenseWindow = new ModalWindow("addLicenseWindow");
    addLicenseWindow.setAutoSize(true);
    addLicenseWindow.setResizable(false);
    addLicenseWindow.setMinimalWidth(600);
    addLicenseWindow.setMinimalHeight(400);
    addLicenseWindow.setWidthUnit("px");
    addLicenseWindow.showUnloadConfirmation(false);

    // prepare list of licenses not associated with the package yet
    IModel<List<License>> licenses = new LoadableDetachableModel<List<License>>() {
        @Override
        protected List<License> load() {
            List<License> list = licenseFacade.getAllRecords();
            list.removeAll(licenseFacade.getLicensesForPackage(epModel.getObject()));
            return list;
        }
    };

    LicensePriceForm addLicenseForm = new LicensePriceForm(addLicenseWindow.getContentId(), licenses) {

        @Override
        protected void onSubmitAction(License license, BigDecimal price, AjaxRequestTarget target,
                Form<?> form) {
            ExperimentPackageLicense expPacLic = new ExperimentPackageLicense();
            expPacLic.setExperimentPackage(epModel.getObject());
            expPacLic.setLicense(license);
            expPacLic.setPrice(price);
            experimentPackageLicenseFacade.create(expPacLic);
            ModalWindow.closeCurrent(target);
            target.add(header);
            experimentsToAddModel.detach(); // list of experiments to add must be reloaded for the actual set of licenses
            // TODO check all experiments contained in the package for the new license
        }

        @Override
        protected void onCancelAction(AjaxRequestTarget target, Form<?> form) {
            ModalWindow.closeCurrent(target);
            target.add(header);
        }

    };

    addLicenseWindow.setContent(addLicenseForm);
    this.add(addLicenseWindow);
}

From source file:edu.indiana.d2i.htrc.portal.HTRCPersistenceAPIClient.java

/** Get all the other allWorksets other than user's allWorksets
 *
 *//*from  w  ww  .j av  a 2  s  .co  m*/

public List<Workset> getPublicWorksets() throws IOException, JAXBException {
    List<Workset> allWorksets = getAllWorksets();
    allWorksets.removeAll(getUserWorksets());
    return allWorksets;
}

From source file:com.thoughtworks.go.server.service.UserService.java

private boolean willDisableAllAdmins(List<String> usersToBeDisabled) {
    List<String> enabledUserNames = toUserNames(userDao.enabledUsers());
    enabledUserNames.removeAll(usersToBeDisabled);
    return !userNameListContainsAdmin(enabledUserNames);
}

From source file:edu.harvard.iq.dataverse.DatasetField.java

/**
 * appears to be only used for sending info to solr; changed to return values
 * instead of display values/*from  ww  w .  j  a v  a 2  s  .  c om*/
 */
public List<String> getValuesWithoutNaValues() {
    List<String> returnList = getValues_nondisplay();
    returnList.removeAll(Arrays.asList(NA_VALUE));
    return returnList;
}

From source file:hudson.scm.listtagsparameter.ListSubversionTagsParameterDefinition.java

/**
 * Removes the parent directory (that is, the tags directory) from a list of
 * directories./*from   ww w  .j  av  a  2  s  .c o  m*/
 */
protected void removeParentDir(List<String> dirs) {
    List<String> dirsToRemove = new ArrayList<String>();
    for (String dir : dirs) {
        if (getTagsDir().endsWith(dir)) {
            dirsToRemove.add(dir);
        }
    }
    dirs.removeAll(dirsToRemove);
}