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:Main.java

/** See if the java.protocol.handler.pkgs system property has changed
 and if it has, parse it to update the handlerPkgs array.
 *//*  w w w  .j a  va  2s . c  om*/
private synchronized void checkHandlerPkgs() {
    String handlerPkgsProp = System.getProperty("java.protocol.handler.pkgs");
    if (handlerPkgsProp != null && handlerPkgsProp.equals(lastHandlerPkgs) == false) {
        // Update the handlerPkgs[] from the handlerPkgsProp
        StringTokenizer tokeninzer = new StringTokenizer(handlerPkgsProp, "|");
        ArrayList tmp = new ArrayList();
        while (tokeninzer.hasMoreTokens()) {
            String pkg = tokeninzer.nextToken().intern();
            if (tmp.contains(pkg) == false)
                tmp.add(pkg);
        }
        // Include the JBoss default protocol handler pkg
        if (tmp.contains(PACKAGE_PREFIX) == false)
            tmp.add(PACKAGE_PREFIX);
        handlerPkgs = new String[tmp.size()];
        tmp.toArray(handlerPkgs);
        lastHandlerPkgs = handlerPkgsProp;
    }
}

From source file:jeplus.TRNSYSWinTools.java

/**
 * Update the DCK template file with the absolute directory for ASSIGN calls
 *
 * @param line Assign line//from   w  w w .  j a v  a 2s  .  c  o  m
 * @param DCKDir The directory of template DCK
 * @param WorkDir The working directory in which the new DCK file will be saved
 * @param searchstrings The list of search strings to be looked up
 * @param newvals The list of new values to be used to replace the search strings
 * @param Printers The printers in the dck model
 * @return Assign line modified
 */
public static String TRNSYSUpdateAssign(String line, String DCKDir, String WorkDir, String[] searchstrings,
        String[] newvals, ArrayList<String> Printers) {

    // Parse Assign statement
    String[] args = new String[0];
    if (line.contains("\"")) {
        args = line.trim().split("\\s*\"\\s*");
    } else {
        args = line.trim().split("\\s* \\s*");
    }
    // Check if file name in the output file list
    String assigname = new File(args[1].trim()).getName();
    String fullpath = RelativeDirUtil.checkAbsolutePath(args[1].trim(), DCKDir);
    if (!Printers.contains(assigname.toLowerCase())) {
        if (new File(fullpath).exists()) {
            boolean ok = false;
            try (BufferedReader insassign = new BufferedReader(
                    new InputStreamReader(new FileInputStream(fullpath), "ISO-8859-1"));
                    PrintWriter outsassign = new PrintWriter(
                            new OutputStreamWriter(new FileOutputStream(WorkDir + assigname), "ISO-8859-1"))) {
                String line2 = insassign.readLine();
                while (line2 != null) {
                    for (int j = 0; j < searchstrings.length; j++) {
                        if ((!ok) && (line2.contains(searchstrings[j]))) {
                            ok = true;
                        }
                        line2 = line2.replaceAll(searchstrings[j], newvals[j]);
                    }
                    outsassign.println(line2);
                    line2 = insassign.readLine();
                }
                outsassign.flush();
            } catch (Exception ex) {
                logger.error("Error updating file " + fullpath + " to " + WorkDir + assigname, ex);
                ok = false;
            }
            if (ok) {
                line = args[0].trim() + " \"" + assigname + "\" " + args[2].trim();
                TRNSYSTask.setjeplusfile(assigname);
            } else {
                line = args[0].trim() + " \"" + fullpath + "\" " + args[2].trim();
                new File(WorkDir + assigname).delete();
            }
        } else {
            line = args[0].trim() + " \"" + fullpath + "\" " + args[2].trim();
        }
    } else {
        line = args[0].trim() + " \"" + assigname + "\" " + args[2].trim();
    }
    return line;
}

From source file:alpine.event.framework.BaseEventService.java

/**
 * {@inheritDoc}/*w  w  w  .  jav a 2s  .  c o m*/
 * @since 1.0.0
 */
public void subscribe(Class<? extends Event> eventType, Class<? extends Subscriber> subscriberType) {
    if (!subscriptionMap.containsKey(eventType)) {
        subscriptionMap.put(eventType, new ArrayList<>());
    }
    final ArrayList<Class<? extends Subscriber>> subscribers = subscriptionMap.get(eventType);
    if (!subscribers.contains(subscriberType)) {
        subscribers.add(subscriberType);
    }
}

From source file:info.magnolia.cms.gui.fckeditor.FCKEditorSimpleUploadServlet.java

/**
 * Helper function to verify if a file extension is allowed or not allowed.
 *///from   www  .ja v a 2  s .c o m

private boolean extIsAllowed(String fileType, String ext) {

    ext = ext.toLowerCase();

    ArrayList allowList = (ArrayList) allowedExtensions.get(fileType);
    ArrayList denyList = (ArrayList) deniedExtensions.get(fileType);

    if (allowList.size() == 0) {
        if (denyList.contains(ext)) {
            return false;
        }
        return true;

    }

    if (denyList.size() == 0) {
        if (allowList.contains(ext)) {
            return true;
        }
        return false;

    }

    return false;
}

From source file:controller.PostsController.java

@RequestMapping(value = "home", method = RequestMethod.GET)
public ModelAndView handleHome(HttpServletRequest request) {
    HttpSession session = request.getSession();
    if (session == null || !request.isRequestedSessionIdValid()) {
        return new ModelAndView("index");
    }//from   w  w w.ja va 2s  .c  o  m

    session.setAttribute("currentPage", "/home.htm");

    // Get all the posts sent to this user
    UsersEntity user = (UsersEntity) session.getAttribute("user");
    ArrayList<PostsEntity> posts = this.postsService.searchByTarget(user);

    // Add the posts sent by this user
    for (PostsEntity post : this.postsService.searchBySender(user)) {
        if (!posts.contains(post)) {
            posts.add(post);
        }
    }

    // Add the posts sent by friends
    for (UsersEntity friend : user.getFriends()) {
        for (PostsEntity post : this.postsService.searchBySender(friend)) {
            if (!posts.contains(post)) {
                posts.add(post);
            }
        }
    }

    Collections.sort(posts, Collections.reverseOrder());

    ModelAndView mv = new ModelAndView("home");
    mv.addObject("currentUser", user);
    mv.addObject("posts", posts);
    mv.addObject("nbNotifs", this.notifsService.searchByTarget(user).size());

    return mv;
}

From source file:com.uniteddev.Unity.Downloader.java

public static void removeOutdated() throws IOException, InterruptedException {
    Login.progressText.setText("Removing outdated files...");
    System.out.println("Removing outdated files...");
    class removefile implements Runnable {
        private int i;

        removefile(int i) {
            this.i = i;
        }/*from   w w w .  j  ava2 s  . c  om*/

        public void run() {
            if (!((folders.get(this.i).contains("bin/")) || (folders.get(this.i).contains("resources/")))) {
                try {
                    //System.out.println("Currently attempting Pool Index: "+this.i);
                    ArrayList<String> online_list = getDirectoryListing(folders.get(this.i));
                    ArrayList<String> offline_list = new ArrayList<String>();
                    if (new File(Minecraft.getWorkingDirectory(), folders.get(this.i)).isDirectory()) {
                        File[] offline_files = new File(Minecraft.getWorkingDirectory(), folders.get(this.i))
                                .listFiles();
                        for (int j = 0; j < offline_files.length; j++) {
                            if (!offline_files[j].isDirectory()) {
                                offline_list.add(offline_files[j].getName());
                            }
                        }
                    }
                    for (int j = 0; j < online_list.size(); j++) {
                        online_list.set(j, namefix(online_list.get(j)));
                    }
                    for (int j = 0; j < offline_list.size(); j++) {
                        if (!online_list.contains(offline_list.get(j))) {
                            clean(Minecraft.getWorkingDirectory() + File.separator + folders.get(this.i),
                                    offline_list.get(j));
                        }
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    ExecutorService pool = Executors.newFixedThreadPool(cores + 2);
    for (int i = 0; i < folders.size(); i++) {
        pool.submit(new removefile(i));
    }
    pool.shutdown();
    pool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}

From source file:com.fredck.FCKeditor.uploader.SimpleUploaderServlet.java

/**
 * Helper function to verify if a file extension is allowed or not allowed.
 *///w  w w.  jav a2 s .  co m
private boolean extIsAllowed(String fileType, String ext) {
    ext = ext.toLowerCase();
    ArrayList allowList = (ArrayList) allowedExtensions.get(fileType);
    ArrayList denyList = (ArrayList) deniedExtensions.get(fileType);
    if (allowList.size() == 0)
        if (denyList.contains(ext))
            return false;
        else
            return true;
    if (denyList.size() == 0)
        if (allowList.contains(ext))
            return true;
        else
            return false;
    return false;
}

From source file:com.kylinolap.common.persistence.HBaseResourceStoreTest.java

void testAStore(ResourceStore store) throws IOException {
    String dir1 = "/cube";
    String path1 = "/cube/_test.json";
    StringEntity content1 = new StringEntity("anything");
    String dir2 = "/table";
    String path2 = "/table/_test.json";
    StringEntity content2 = new StringEntity("something");

    // cleanup legacy if any
    store.deleteResource(path1);/*from   w  w  w.j  a  v  a2s  . co m*/
    store.deleteResource(path2);

    StringEntity t;

    // put/get
    store.putResource(path1, content1, StringEntity.serializer);
    assertTrue(store.exists(path1));
    t = store.getResource(path1, StringEntity.class, StringEntity.serializer);
    assertEquals(content1, t);

    store.putResource(path2, content2, StringEntity.serializer);
    assertTrue(store.exists(path2));
    t = store.getResource(path2, StringEntity.class, StringEntity.serializer);
    assertEquals(content2, t);

    // overwrite
    t.str = "new string";
    store.putResource(path2, t, StringEntity.serializer);

    // write conflict
    try {
        t.setLastModified(t.lastModified - 1);
        store.putResource(path2, t, StringEntity.serializer);
        fail("write conflict should trigger IllegalStateException");
    } catch (IllegalStateException e) {
        // expected
    }

    // list
    ArrayList<String> list;

    list = store.listResources(dir1);
    assertTrue(list.contains(path1));
    assertTrue(list.contains(path2) == false);

    list = store.listResources(dir2);
    assertTrue(list.contains(path2));
    assertTrue(list.contains(path1) == false);

    list = store.listResources("/");
    assertTrue(list.contains(dir1));
    assertTrue(list.contains(dir2));
    assertTrue(list.contains(path1) == false);
    assertTrue(list.contains(path2) == false);

    list = store.listResources(path1);
    assertNull(list);
    list = store.listResources(path2);
    assertNull(list);

    // delete/exist
    store.deleteResource(path1);
    assertTrue(store.exists(path1) == false);
    list = store.listResources(dir1);
    assertTrue(list == null || list.contains(path1) == false);

    store.deleteResource(path2);
    assertTrue(store.exists(path2) == false);
    list = store.listResources(dir2);
    assertTrue(list == null || list.contains(path2) == false);
}

From source file:mcnutty.music.get.ProcessQueue.java

QueueItem next_item() {
    //Return an enpty item if there is nothing to play
    if (bucket_queue.isEmpty()) {
        return new QueueItem();
    }//www .  java2 s  . c  o m

    //Return the next item in the current bucket
    ArrayList<String> played_ips = bucket_played.stream().map(item -> item.ip)
            .collect(Collectors.toCollection(ArrayList::new));
    for (QueueItem item : bucket_queue) {
        if (!played_ips.contains(item.ip)) {
            return item;
        }
    }

    //If the current bucket it empty, start the next one
    System.out.println("REACHED END OF BUCKET");
    bucket_played.clear();
    return next_item();
}

From source file:de.eonas.opencms.portlet.CmsPortletWidget.java

@NotNull
static private ArrayList<String> fetchRegisteredPortlets(@Nullable String selected) {
    String metainfo = null;/*w ww  . ja va 2s  .  c o m*/
    if (!CmsStringUtil.isEmpty(selected)) {
        PortletWindowConfig selectedConfig = PortletWindowConfig.fromId(selected);
        metainfo = selectedConfig.getMetaInfo();
    }

    if (metainfo == null) {
        metainfo = createPlacementId();
    }

    if (m_context == null) {
        LOG.warn("ServletContext still unset. Maybe the listener is missing?");
        return new ArrayList<String>();
    }
    // Es wird auf die PortletContainer Instanz zugegriffen
    PortletContainer container = (PortletContainer) m_context.getAttribute(AttributeKeys.PORTLET_CONTAINER);

    PortalDriverServicesImpl driverserviceimpl = (PortalDriverServicesImpl) container.getContainerServices();
    Iterator<DriverPortletContext> iter = driverserviceimpl.getPortletContextService().getPortletContexts();

    ArrayList<String> liste = new ArrayList<String>();
    // Das Select Element wird mit Werten der PortletApplikationen gefuellt
    while (iter.hasNext()) {
        DriverPortletContext portletcontext = iter.next();
        PortletApplicationDefinition portletAppDd = portletcontext.getPortletApplicationDefinition();

        String contextPath = portletcontext.getApplicationName();
        if (contextPath.length() > 0) {
            contextPath = "/" + contextPath;
        }

        for (PortletDefinition portlet : portletAppDd.getPortlets()) {
            String portletName = portlet.getPortletName();

            String portletId = PortletWindowConfig.createPortletId(contextPath, portletName, metainfo);

            liste.add(portletId);
        }
    }

    // Pruefung damit ein Portlet, das selektiert ist, aber zur Zeit nicht
    // verfuegbar ist, troztdem in der Liste bleibt
    // und nicht ausgelassen wird.
    if (selected != null && selected.length() > 0 && !liste.contains(selected)) {
        liste.add(selected);
    }

    Collections.sort(liste, String.CASE_INSENSITIVE_ORDER);
    return liste;
}