Example usage for java.util ArrayList contains

List of usage examples for java.util ArrayList contains

Introduction

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

Prototype

public boolean contains(Object o) 

Source Link

Document

Returns true if this list contains the specified element.

Usage

From source file:net.drgnome.virtualpack.util.Util.java

public static <T> T[] merge(T[]... objects) {
        ArrayList<T> list = new ArrayList<T>();
        for (T[] array : objects) {
            if (array == null) {
                continue;
            }//from   w w  w.  j ava 2s . c o m
            for (T obj : array) {
                if (obj == null) {
                    continue;
                }
                if (!list.contains(obj)) {
                    list.add(obj);
                }
            }
        }
        return list.toArray((T[]) Array.newInstance(objects[0].getClass().getComponentType(), list.size()));
    }

From source file:com.oeg.oops.VocabUtils.java

/**
 * The reason why the model is not returned is because I want to be able to close it later.
 * @param model// w  w  w. j a va2s . c o  m
 * @param ontoPath
 * @param ontoURL
 */
private static void readOnlineModel(OntModel model, Vocabulary v) {
    ArrayList<String> s = v.getSupportedSerializations();
    if (s.isEmpty()) {
        System.err.println("Error: no serializations available!!");
        Report.getInstance().addErrorForVocab(v.getUri(), TextConstants.Error.NO_SERIALIZATIONS_FOR_VOCAB);
    } else {
        if (s.contains("application/rdf+xml")) {
            model.read(v.getUri(), null, "RDF/XML");
        } else if (s.contains("text/turtle")) {
            model.read(v.getUri(), null, "TURTLE");
        } else if (s.contains("text/n3")) {
            model.read(v.getUri(), null, "N3");
        } else {
            //try the application/rdf+xml anyways. It is the most typical,
            //and sometimes it may not have been recognized because they
            //don't add a content header
            try {
                model.read(v.getUri(), null, "RDF/XML");
                v.getSupportedSerializations().add("application/rdf+xml");
            } catch (Exception e) {
                System.err.println("Error: no serializations available!!");
                Report.getInstance().addErrorForVocab(v.getUri(),
                        TextConstants.Error.NO_SERIALIZATIONS_FOR_VOCAB);
            }
        }
        //            System.out.println("Vocab "+v.getUri()+" loaded successfully!");
    }
}

From source file:eionet.cr.web.action.admin.harvestscripts.HarvestScriptParser.java

/**
 *
 * @param str// www .  ja v  a2 s .  c o  m
 * @param token
 * @return
 */
public static boolean containsToken(String str, String token) {

    if (str == null || str.trim().length() == 0 || token == null || token.trim().length() == 0) {
        return false;
    }

    StringTokenizer st = new StringTokenizer(str, " \t\n\r\f", true);
    ArrayList<String> upperCaseTokens = new ArrayList<String>();
    while (st.hasMoreTokens()) {
        String nextToken = st.nextToken();
        upperCaseTokens.add(nextToken.toUpperCase());
    }

    return upperCaseTokens.contains(token.toUpperCase());
}

From source file:com.hp.test.framework.Reporting.removerunlinks.java

public static void removelinksforpreRuns(String FilePath, String FileName, int lastrun)
        throws FileNotFoundException, IOException {

    log.info("Removing hyper link for the last run");
    ArrayList<String> Links_To_Remove = new ArrayList<String>();

    for (int i = 1; i < lastrun; i++) {
        Links_To_Remove.add("href=\"Run_" + i + "\\CurrentRun.html\"");
    }//from   w w  w  . j ava 2  s  .c  o  m

    File source = new File(FilePath + FileName);
    File temp_file = new File(FilePath + "temp.html");
    BufferedReader in = new BufferedReader(new FileReader(source));
    BufferedWriter out = new BufferedWriter(new FileWriter(temp_file));
    String str = "";
    while ((str = in.readLine()) != null) {

        String temp_ar[] = str.split(" ");

        for (int i = 0; i < temp_ar.length; i++) {
            String temp = temp_ar[i].trim();
            if (!temp.equals("")) {

                if (Links_To_Remove.contains(temp)) {
                    out.write(" ");
                    out.newLine();

                } else {
                    out.write(temp);
                    out.newLine();

                }

            }
        }
    }

    out.close();
    in.close();
    out = null;
    in = null;

    source.delete();
    temp_file.renameTo(source);

}

From source file:JarMaker.java

/**
 * Combine several jar files and some given files into one jar file.
 * @param outJar The output jar file's filename.
 * @param inJarsList The jar files to be combined
 * @param filter A filter that exclude some entries of input jars. User
 *        should implement the EntryFilter interface.
 * @param inFileList The files to be added into the jar file.
 * @param prefixs The prefixs of files to be added into the jar file.
 *        inFileList and prefixs should be paired.
 * @throws FileNotFoundException// w w w .  j  a va  2  s. c  o  m
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public static void combineJars(String outJar, String[] inJarsList, EntryFilter filter, String[] inFileList,
        String[] prefixs) throws FileNotFoundException, IOException {

    JarOutputStream jout = new JarOutputStream(new FileOutputStream(outJar));
    ArrayList entryList = new ArrayList();
    for (int i = 0; i < inJarsList.length; i++) {
        BufferedInputStream bufferedinputstream = new BufferedInputStream(new FileInputStream(inJarsList[i]));
        ZipInputStream zipinputstream = new ZipInputStream(bufferedinputstream);
        byte abyte0[] = new byte[1024 * 4];
        for (ZipEntry zipentry = zipinputstream.getNextEntry(); zipentry != null; zipentry = zipinputstream
                .getNextEntry()) {
            if (filter.accept(zipentry)) {
                if (!entryList.contains(zipentry.getName())) {
                    jout.putNextEntry(zipentry);
                    if (!zipentry.isDirectory()) {
                        int j;
                        try {
                            while ((j = zipinputstream.read(abyte0, 0, abyte0.length)) != -1)
                                jout.write(abyte0, 0, j);
                        } catch (IOException ie) {
                            throw ie;
                        }
                    }
                    entryList.add(zipentry.getName());
                }
            }
        }
        zipinputstream.close();
        bufferedinputstream.close();
    }
    for (int i = 0; i < inFileList.length; i++) {
        add(jout, new File(inFileList[i]), prefixs[i]);
    }
    jout.close();
}

From source file:eu.scape_project.pt.mapred.input.ControlFileInputFormat.java

/**
 * Creates mapping of locations to arraylists of control lines.
 *
 * @param controlFile input control file
 * @param conf Hadoop configuration/*from  ww  w. j  a  v  a2s  .c  o  m*/
 * @param repo Toolspec repository
 * @param parser parser for the control lines
 * @return mapping
 */
public static Map<String, ArrayList<String>> createLocationMap(Path controlFile, Configuration conf,
        Repository repo, CmdLineParser parser) throws IOException {
    FileSystem fs = controlFile.getFileSystem(conf);
    FSDataInputStream in = fs.open(controlFile);
    LineReader lr = new LineReader(in, conf);
    Text controlLine = new Text();
    Map<String, ArrayList<String>> locationMap = new HashMap<String, ArrayList<String>>();
    ArrayList<String> allHosts = new ArrayList<String>();
    int l = 0;
    while ((lr.readLine(controlLine)) > 0) {
        l += 1;
        // read line by line
        Path[] inFiles = getInputFiles(fs, parser, repo, controlLine.toString());

        // count for each host how many blocks it holds of the current control line's input files
        String[] hostsOfFile = getSortedHosts(fs, inFiles);

        for (String host : hostsOfFile) {
            if (!allHosts.contains(host))
                allHosts.add(host);
        }
        ArrayList<String> theseHosts = (ArrayList<String>) allHosts.clone();
        for (String host : hostsOfFile) {
            theseHosts.remove(host);
        }

        String[] hosts = new String[theseHosts.size() + hostsOfFile.length];
        int h = 0;
        for (String host : hostsOfFile) {
            hosts[h] = hostsOfFile[h];
            h++;
        }
        for (String host : theseHosts) {
            hosts[h] = theseHosts.get(h - hostsOfFile.length);
            h++;
        }

        addToLocationMap(locationMap, hosts, controlLine.toString(), l);
    }
    return locationMap;
}

From source file:javadepchecker.Main.java

/**
 * Check for orphaned class files not owned by any package in dependencies
 *
 * @param pkg Gentoo package name//from   w w w  .  j  a v a 2 s . co  m
 * @param deps collection of dependencies for the package
 * @return boolean if the dependency is found or not
 * @throws IOException
 */
private static boolean depsFound(Collection<String> pkgs, Collection<String> deps) throws IOException {
    boolean found = true;
    Collection<String> jars = new ArrayList<>();
    String[] bootClassPathJars = System.getProperty("sun.boot.class.path").split(":");
    // Do we need "java-config -r" here?
    for (String jar : bootClassPathJars) {
        File jarFile = new File(jar);
        if (jarFile.exists()) {
            jars.add(jar);
        }
    }
    pkgs.forEach((String pkg) -> {
        jars.addAll(getPackageJars(pkg));
    });

    if (jars.isEmpty()) {
        return false;
    }
    ArrayList<String> jarClasses = new ArrayList<>();
    jars.forEach((String jarName) -> {
        try {
            JarFile jar = new JarFile(jarName);
            Collections.list(jar.entries()).forEach((JarEntry entry) -> {
                jarClasses.add(entry.getName());
            });
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    });
    for (String dep : deps) {
        if (!jarClasses.contains(dep)) {
            if (found) {
                System.out.println("Class files not found via DEPEND in package.env");
            }
            System.out.println("\t" + dep);
            found = false;
        }
    }
    return found;
}

From source file:gr.interamerican.bo2.utils.JavaBeanUtils.java

/**
 * Finds the properties of a bean.//from  www  .java 2 s  . co m
 * 
 * <li>If the bean is a concrete class the properties of the bean, for which
 * there exists a setter method, a getter method or both. Properties of
 * super-types are returned as well.</li>
 * 
 * <li>If the bean is an abstract class, an empty array is returned</li>
 * 
 * <li>If the bean is an interface, the properties of the bean are returned.
 * The method also queries all super-interfaces and fetches their properties
 * as well.</li>
 * 
 * @param type
 *            the bean
 * @return Returns the property descriptors of a java bean.
 * 
 * TODO: Support properties of abstract classes.
 */
public static PropertyDescriptor[] getBeansProperties(Class<?> type) {

    ArrayList<PropertyDescriptor> propertyDescriptor = new ArrayList<PropertyDescriptor>();

    for (PropertyDescriptor p : PropertyUtils.getPropertyDescriptors(type)) {
        if (!propertyDescriptor.contains(p) && !p.getName().equals("class")) { //$NON-NLS-1$
            propertyDescriptor.add(p);
        }
    }

    if (type.isInterface()) {
        Class<?>[] classArray = type.getInterfaces();
        PropertyDescriptor[] pdArray;
        for (Class<?> next : classArray) {
            pdArray = getBeansProperties(next);
            for (PropertyDescriptor pd : pdArray) {
                if (!propertyDescriptor.contains(pd)) {
                    propertyDescriptor.add(pd);
                }
            }
        }
    }
    return propertyDescriptor.toArray(new PropertyDescriptor[0]);
}

From source file:com.palantir.gerrit.gerritci.servlets.JobsServlet.java

public static ArrayList<String> updateProjectJobFiles(File projectFile, File projectConfigDirectory,
        ArrayList<String> receivedJobNames) throws IOException {

    Scanner scanner = new Scanner(projectFile);

    ArrayList<String> updatedJobs = new ArrayList<String>();
    ArrayList<String> newJobs = new ArrayList<String>();
    ArrayList<String> deletedJobs = new ArrayList<String>();

    while (scanner.hasNextLine()) {
        String line = scanner.nextLine();
        if (receivedJobNames.contains(line)) {
            updatedJobs.add(line);/*from w  w w .j  a v a2 s. co m*/
            receivedJobNames.remove(line);
        } else {
            deletedJobs.add(line);
        }
    }
    logger.info("There are " + receivedJobNames.size() + " new jobs");
    logger.info("There are " + deletedJobs.size() + " deleted jobs");
    logger.info("There are " + updatedJobs.size() + " updated jobs");
    for (String s : receivedJobNames) {
        newJobs.add(s);
    }

    scanner.close();
    FileWriter writer = new FileWriter(projectFile, false);
    for (String s : updatedJobs) {
        writer.write(s);
        writer.write("\n");
    }
    for (String s : newJobs) {
        writer.write(s);
        writer.write("\n");
    }
    writer.close();
    return deletedJobs;
}

From source file:dk.statsbiblioteket.doms.licensemodule.validation.LicenseValidator.java

public static ArrayList<String> filterGroups(ArrayList<License> licenses, ArrayList<String> presentationTypes) {
    HashSet<String> groups = new HashSet<String>();
    for (License current : licenses) {
        for (LicenseContent currentContent : current.getLicenseContents()) {
            for (Presentation currentPresentation : currentContent.getPresentations()) {
                if (presentationTypes.contains(currentPresentation.getKey())) {
                    groups.add(currentContent.getName());

                }/*from  w  w  w .jav a  2s  .  co  m*/
            }
        }
    }
    return new ArrayList<String>(groups);
}