List of usage examples for java.util ArrayList contains
public boolean contains(Object o)
From source file:com.nwn.NwnUpdater.java
/** * Scan local folders which should contain the files needed for the selected server * If any files are missing, add them to the list of files to download * @return/*from w ww . j a v a 2 s . com*/ */ private ArrayList<ServerFile> determineFilesToDownload() { currentGui.setTaskProgressBarValue(0); int currentProgress = 0; int progressIncrement; if (affectedFolders.size() > 0) { progressIncrement = 100 / affectedFolders.size(); } else { progressIncrement = 100; } currentGui.appendOutputText("\nChecking local files"); ArrayList<ServerFile> filesToDownload = new ArrayList<ServerFile>(); for (String folder : affectedFolders) { Path folderPath = Paths.get(nwnRootPath.toString() + File.separator + folder); ArrayList<String> localFiles; try { localFiles = NwnFileHandler.getFileNamesInDirectory(folderPath); } catch (NoSuchFileException nsfe) { currentGui.appendOutputText( "\nERROR: Folder " + folderPath.getFileName().toString() + " does not exist!"); error[0] = true; return new ArrayList<ServerFile>(); } catch (IOException ex) { currentGui.appendOutputText("\nERROR: Cannot parse local directory!"); error[0] = true; return new ArrayList<ServerFile>(); } for (ServerFile serverFile : serverFileList) { currentGui.appendOutputText("."); if (serverFile.getFileList() == null && serverFile.getFolder().equals(folder) && !localFiles.contains(serverFile.getName())) { filesToDownload.add(serverFile); } else if (serverFile.getFileList() != null) { for (String file : serverFile.getFileList()) { if (!localFiles.contains(file) && NwnFileHandler.getFileExtension(file).equalsIgnoreCase(folder) && !filesToDownload.contains(serverFile)) { filesToDownload.add(serverFile); break; } } } } currentProgress = currentProgress + progressIncrement; currentGui.setTaskProgressBarValue(currentProgress); } currentGui.appendOutputText("done"); return filesToDownload; }
From source file:org.jahia.modules.rolesmanager.RolesAndPermissionsHandler.java
private void fillPermIds(JCRNodeWrapper role, List<String> tabs, Map<String, List<String>> permIdsMap, boolean recursive) throws RepositoryException { if (!role.isNodeType(Constants.JAHIANT_ROLE)) { return;/* w ww . j a v a 2 s . com*/ } if (recursive) { fillPermIds(role.getParent(), tabs, permIdsMap, true); } final ArrayList<String> setPermIds = new ArrayList<String>(); permIdsMap.put("current", setPermIds); if (role.hasProperty("j:permissionNames")) { Value[] values = role.getProperty("j:permissionNames").getValues(); for (Value value : values) { String valueString = value.getString(); if (!setPermIds.contains(valueString)) { setPermIds.add(valueString); } } } NodeIterator ni = role.getNodes(); while (ni.hasNext()) { JCRNodeWrapper next = (JCRNodeWrapper) ni.next(); if (next.isNodeType("jnt:externalPermissions")) { try { String path = next.getProperty("j:path").getString(); permIdsMap.put(path, new ArrayList<String>()); Value[] values = next.getProperty("j:permissionNames").getValues(); for (Value value : values) { List<String> ids = permIdsMap.get(path); String valueString = value.getString(); if (!ids.contains(valueString)) { ids.add(valueString); } if (!tabs.contains(path)) { tabs.add(path); } } } catch (RepositoryException e) { logger.error("Cannot initialize role " + next.getPath(), e); } catch (IllegalStateException e) { logger.error("Cannot initialize role " + next.getPath(), e); } } } }
From source file:org.loklak.harvester.TwitterScraper.java
private static String prepareSearchUrl(final String query, final ArrayList<String> filterList) { // check// w w w. j a va 2 s. co m // https://twitter.com/search-advanced for a better syntax // build queries like https://twitter.com/search?f=tweets&vertical=default&q=kaffee&src=typd // https://support.twitter.com/articles/71577-how-to-use-advanced-twitter-search# String httpsUrl = ""; String type = "tweets"; try { // query q StringBuilder t = new StringBuilder(query.length()); for (String s : query.replace('+', ' ').split(" ")) { t.append(' '); if (s.startsWith("since:") || s.startsWith("until:")) { int u = s.indexOf('_'); t.append(u < 0 ? s : s.substring(0, u)); } else { t.append(s); } } String q = t.length() == 0 ? "*" : URLEncoder.encode(t.substring(1), "UTF-8"); // type of content to fetch if (filterList.contains("video") && filterList.size() == 1) { type = "videos"; } // building url httpsUrl = "https://twitter.com/search?f=" + type + "&vertical=default&q=" + q + "&src=typd"; } catch (UnsupportedEncodingException e) { } return httpsUrl; }
From source file:isl.FIMS.utils.Utils.java
public ArrayList<DBFile> findDependats(DBFile dbf, String fileId, String type, String database, String dbUser, String dbPass, String previous_Id, String previous_Type, ArrayList allPrevious) { ArrayList<DBFile> aList = new <DBFile>ArrayList(); String[] res = dbf.queryString("//admin/refs/ref[@sps_id!=0 and (@sps_type!='" + type + "' or @sps_id!='" + fileId + "') and (@sps_type!='" + previous_Type + "' or @sps_id!='" + previous_Id + "')]"); for (int i = 0; i < res.length; i++) { Element e = getElement(res[i]); String sps_type = e.getAttribute("sps_type"); String sps_id = e.getAttribute("sps_id"); String id = sps_type + sps_id; if (!allPrevious.contains(id)) { DBCollection col = new DBCollection(database, this.systemDbCollection + sps_type, dbUser, dbPass); String collectionPath = UtilsQueries.getPathforFile(col, id + ".xml", id.split(sps_type)[1]); col = new DBCollection(database, collectionPath, dbUser, dbPass); DBFile dependantFile = col.getFile(id + ".xml"); allPrevious.add(id);/*w w w. j a v a2s .com*/ aList.add(dependantFile); //findDependats(dependantFile); aList.addAll(findDependats(dependantFile, sps_id, sps_type, database, dbUser, dbPass, fileId, type, allPrevious)); } } return aList; }
From source file:edu.illinois.enforcemop.examples.apache.collections.TestBlockingBuffer.java
/** * Tests interrupted remove.// w ww.jav a 2s . c o m */ @Test // @Schedules({ // @Schedule(name = "InterruptedRemove", sequence = "[beforeRemove: afterRemove]@readThread->beforeInterrupt@main," + // "finishAddException@readThread->afterInterrupt@main") }) public void testInterruptedRemove() throws InterruptedException { Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer()); Object obj = new Object(); // spawn a read thread to wait on the empty buffer ArrayList exceptionList = new ArrayList(); Thread thread = new ReadThread(blockingBuffer, obj, exceptionList, "remove", "InterruptedRemove", "readThread"); thread.start(); try { Thread.sleep(100); //INS-SLEEP } catch (Exception e1) { e1.printStackTrace(); } // Interrupting the thread should cause it to throw BufferUnderflowException /* @Event("beforeInterrupt")*/ thread.interrupt(); // Chill, so thread can throw and add message to exceptionList Thread.sleep(100); /* @Event("afterInterrupt")*/ assertTrue("InterruptedRemove", exceptionList.contains("BufferUnderFlow")); //assertFalse("InterruptedRemove",thread.isAlive()); //if( thread.isAlive() ) { //fail( "Read thread has hung." ); //} }
From source file:com.paniclauncher.workers.InstanceInstaller.java
private void downloadMods(ArrayList<Mod> mods) { fireSubProgressUnknown();/*from w ww.jav a2s . co m*/ ExecutorService executor = Executors.newFixedThreadPool(8); ArrayList<PanicLauncherDownloadable> downloads = getDownloadableMods(); totalDownloads = downloads.size(); for (PanicLauncherDownloadable download : downloads) { executor.execute(download); } executor.shutdown(); while (!executor.isTerminated()) { } for (Mod mod : mods) { if (!downloads.contains(mod) && !isCancelled()) { fireTask(App.settings.getLocalizedString("common.downloading") + " " + mod.getFile()); mod.download(this); } } }
From source file:de.rrze.idmone.utils.jidgen.IdGenerator.java
/** * This method tries to generate the given number of ids. * The method returns an empty list if it does * not manage to create any suitable id within the <em>MAX_ATTEMPTS</em> * or null if an error occurs.//from ww w. j a va 2 s .c om * * @param num * target number of ids to generate * @return a suitable id list, an empty list if such could not be * generated or null on error */ public List<String> generateIDs(int num) { if (this.updateOptions) { this.update(); } ArrayList<String> ids = new ArrayList<String>(); logger.info(Messages.getString("IdGenerator.START_GENERATION") + num); Template template = new Template(this.options.getData()); int i = 0; while (template.hasAlternatives() && (ids.size() < num)) { if (i++ == Globals.MAX_ATTEMPTS) { logger.fatal( Messages.getString("IdGenerator.MAX_ATTEMPTS_REACHED") + " (" + Globals.MAX_ATTEMPTS + ")"); System.exit(152); } String idCandidate = null; idCandidate = template.buildString(); logger.trace(Messages.getString("IdGenerator.TRACE_ID_CANDIDATE") + " " + idCandidate); // apply the filter chain to the generated id // add to list if we got a valid, unique id if ((this.filterChain.apply(idCandidate) != null) && (!ids.contains(idCandidate))) { ids.add(idCandidate); } else { // log some info about the failed attempt logger.trace(Messages.getString("IdGenerator.TRACE_ATTEMPT_GENERATE") + " " + idCandidate); } } logger.debug(Messages.getString("IdGenerator.NUMBER_OF_ITERATIONS") + i); if (ids.size() < num) { logger.warn(Messages.getString("IdGenerator.FAILED_TO_REACH_TARGET_NUM") + ids.size()); } if (ids.size() == 0) { logger.fatal(Messages.getString("IdGenerator.NO_ALTERNATIVES_LEFT")); } return ids; }
From source file:com.nextgis.maplibui.mapui.NGWVectorLayerUI.java
@Override public boolean delete() { File form = new File(mPath, ConstantsUI.FILE_FORM); if (form.exists()) { try {//from www .j a v a 2 s.c o m ArrayList<String> lookupTableIds = LayerUtil.fillLookupTableIds(form); MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance(); if (null == map) throw new IllegalArgumentException( "The map should extends MapContentProviderHelper or inherited"); for (int i = 0; i < map.getLayerCount(); i++) { if (map.getLayer(i) instanceof NGWVectorLayer) { form = new File(map.getLayer(i).getPath(), ConstantsUI.FILE_FORM); if (form.exists()) { ArrayList<String> otherIds = LayerUtil.fillLookupTableIds(form); lookupTableIds.removeAll(otherIds); } } } if (lookupTableIds.size() > 0) for (int i = 0; i < map.getLayerCount(); i++) { if (map.getLayer(i) instanceof NGWLookupTable) { NGWLookupTable table = (NGWLookupTable) map.getLayer(i); String id = table.getRemoteId() + ""; if (table.getAccountName().equals(mAccountName) && lookupTableIds.contains(id)) { map.removeLayer(table); table.delete(); i--; } } } } catch (IOException | JSONException e) { e.printStackTrace(); } } return super.delete(); }
From source file:io.siddhi.extension.io.file.FileSinkTestCase.java
@Test public void fileSinkTest5() throws InterruptedException { log.info("test SiddhiIoFile Sink 5"); String streams = "" + "@App:name('TestSiddhiApp')" + "define stream FooStream (symbol string, price float, volume long); " + "@sink(type='file', @map(type='json'), append='true', " + "file.uri='" + dirUri + "/empty.txt') " + "define stream BarStream (symbol string, price float, volume long); "; String query = "" + "from FooStream " + "select * " + "insert into BarStream; "; SiddhiManager siddhiManager = new SiddhiManager(); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); InputHandler stockStream = siddhiAppRuntime.getInputHandler("FooStream"); siddhiAppRuntime.start();/*from ww w . ja v a 2 s . c o m*/ stockStream.send(new Object[] { "WSO2", 55.6f, 100L }); stockStream.send(new Object[] { "IBM", 57.678f, 100L }); stockStream.send(new Object[] { "GOOGLE", 50f, 100L }); stockStream.send(new Object[] { "REDHAT", 50f, 100L }); Thread.sleep(100); ArrayList<String> msgs = new ArrayList<>(); msgs.add("{\"event\":{\"symbol\":\"WSO2\",\"price\":55.6,\"volume\":100}}"); msgs.add("{\"event\":{\"symbol\":\"IBM\",\"price\":57.678,\"volume\":100}}"); msgs.add("{\"event\":{\"symbol\":\"GOOGLE\",\"price\":50.0,\"volume\":100}}"); msgs.add("{\"event\":{\"symbol\":\"REDHAT\",\"price\":50.0,\"volume\":100}}"); File file = new File(dirUri + "/empty.txt"); try { BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); String line = null; while ((line = bufferedReader.readLine()) != null) { if (msgs.contains(line)) { count.incrementAndGet(); } else { AssertJUnit.fail("Message " + line + " is not supposed to be written."); } } } catch (FileNotFoundException e) { AssertJUnit.fail(e.getMessage()); } catch (IOException e) { AssertJUnit.fail("Error occurred during reading the file '" + file.getAbsolutePath()); } AssertJUnit.assertEquals(4, count.intValue()); Thread.sleep(1000); siddhiAppRuntime.shutdown(); }
From source file:io.siddhi.extension.io.file.FileSinkTestCase.java
@Test public void fileSinkTest4() throws InterruptedException { log.info("test SiddhiIoFile Sink 4"); String streams = "" + "@App:name('TestSiddhiApp')" + "define stream FooStream (symbol string, price float, volume long); " + "@sink(type='file', @map(type='json'), append='true', " + "file.uri='" + dirUri + "/newFile.json') " + "define stream BarStream (symbol string, price float, volume long); "; String query = "" + "from FooStream " + "select * " + "insert into BarStream; "; SiddhiManager siddhiManager = new SiddhiManager(); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); InputHandler stockStream = siddhiAppRuntime.getInputHandler("FooStream"); siddhiAppRuntime.start();//from w w w . j a v a 2 s . c om stockStream.send(new Object[] { "WSO2", 55.6f, 100L }); stockStream.send(new Object[] { "IBM", 57.678f, 100L }); stockStream.send(new Object[] { "GOOGLE", 50f, 100L }); stockStream.send(new Object[] { "REDHAT", 50f, 100L }); Thread.sleep(100); ArrayList<String> msgs = new ArrayList<>(); msgs.add("{\"event\":{\"symbol\":\"WSO2\",\"price\":55.6,\"volume\":100}}"); msgs.add("{\"event\":{\"symbol\":\"IBM\",\"price\":57.678,\"volume\":100}}"); msgs.add("{\"event\":{\"symbol\":\"GOOGLE\",\"price\":50.0,\"volume\":100}}"); msgs.add("{\"event\":{\"symbol\":\"REDHAT\",\"price\":50.0,\"volume\":100}}"); File file = new File(dirUri + "/newFile.json"); try { BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); String line = null; while ((line = bufferedReader.readLine()) != null) { if (msgs.contains(line)) { count.incrementAndGet(); } else { AssertJUnit.fail("Message " + line + " is not supposed to be written."); } } } catch (FileNotFoundException e) { AssertJUnit.fail(e.getMessage()); } catch (IOException e) { AssertJUnit.fail("Error occurred during reading the file '" + file.getAbsolutePath()); } AssertJUnit.assertEquals(4, count.intValue()); Thread.sleep(1000); siddhiAppRuntime.shutdown(); }