List of usage examples for java.util ArrayList remove
public boolean remove(Object o)
From source file:eu.cassandra.utils.Utils.java
public static void removePoints(ArrayList<PointOfInterest> points, int minute) { int i = 0;/*from www .j a v a2s .co m*/ for (i = 0; i < points.size(); i++) if (points.get(i).getMinute() == minute) break; points.remove(i); }
From source file:com.wavemaker.commons.util.IOUtils.java
/** * Read the bottom of a File into a String. This probably isn't the proper way to do this in java but my goals here * were limited to NOT flooding memory with the entire file, but just to grab the last N lines and never have more * than the last N lines in memory//ww w .j av a 2 s .c o m */ public static String tail(File f, int lines) throws IOException { java.util.ArrayList<String> lineList = new java.util.ArrayList<String>(lines); BufferedReader br = null; try { br = new BufferedReader(new FileReader(f)); while (br.ready()) { String s = br.readLine(); if (s == null) { break; } else { lineList.add(s); } if (lineList.size() > lines) { lineList.remove(0); } } StringBuilder fileSB = new StringBuilder(); for (int i = 0; i < lineList.size(); i++) { fileSB.append(lineList.get(i) + "\n"); } return fileSB.toString(); } finally { closeSilently(br); } }
From source file:com.wavemaker.common.util.IOUtils.java
/** * Read the bottom of a File into a String. This probably isn't the proper way to do this in java but my goals here * were limited to NOT flooding memory with the entire file, but just to grab the last N lines and never have more * than the last N lines in memory//from ww w . j a va 2s .c om */ public static String tail(File f, int lines) throws IOException { java.util.ArrayList<String> lineList = new java.util.ArrayList<String>(lines); BufferedReader br = null; try { br = new BufferedReader(new FileReader(f)); while (br.ready()) { String s = br.readLine(); if (s == null) { break; } else { lineList.add(s); } if (lineList.size() > lines) { lineList.remove(0); } } StringBuilder fileSB = new StringBuilder(); for (int i = 0; i < lineList.size(); i++) { fileSB.append(lineList.get(i) + "\n"); } return fileSB.toString(); } finally { try { br.close(); } catch (Exception ignore) { } } }
From source file:net.javacoding.xsearch.config.ServerConfiguration.java
public static DatasetConfiguration[] getDatasetConfigurations(String[] indexNames) throws ConfigurationException { if (indexNames == null || indexNames.length <= 0) { ArrayList<DatasetConfiguration> al = getDatasetConfigurations(); for (int i = 0; i < al.size();) { DatasetConfiguration dc = (DatasetConfiguration) al.get(i); if (dc.getDisplayOrder() >= 0) { i++;/*from ww w.j a v a 2s . co m*/ } else { al.remove(i); } } return (DatasetConfiguration[]) al.toArray(new DatasetConfiguration[al.size()]); } ServerConfiguration sc = ServerConfiguration.getServerConfiguration(); sc.syncDatasets(); ArrayList<DatasetConfiguration> dcs = new ArrayList<DatasetConfiguration>(); for (int i = 0; i < indexNames.length; i++) { DatasetConfiguration dc = ServerConfiguration.getDatasetConfiguration(indexNames[i]); if (dc != null) dcs.add(dc); } DatasetConfiguration[] cs = (DatasetConfiguration[]) dcs.toArray(new DatasetConfiguration[dcs.size()]); Arrays.sort(cs, new Comparator<DatasetConfiguration>() { // sort the array public int compare(DatasetConfiguration o1, DatasetConfiguration o2) { return o1.getDisplayOrder() - o2.getDisplayOrder(); } }); return cs; }
From source file:cfappserver.Bot.java
public static void getLunch(HttpClient client, ClssPkg cp) { try {//from www.java2 s . c o m HttpResponse response = client.execute(new HttpGet("https://home-access.cfisd.net/HomeAccess/Content/Student/Classes.aspx")); BufferedReader rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; String count = ""; ArrayList<Period> periods = new ArrayList<Period>(); periods.add(new Period("1")); periods.add(new Period("2")); periods.add(new Period("3")); periods.add(new Period("41")); periods.add(new Period("42")); periods.add(new Period("45")); periods.add(new Period("52")); periods.add(new Period("53")); periods.add(new Period("6")); periods.add(new Period("7")); while ((line = rd.readLine()) != null) { if(line.contains("</tr><tr class=\"sg-asp-table-data-row\">")){ String[] arr = rd.readLine().split("<|>"); String classnum = remSpace(arr[2]); arr = rd.readLine().split("<|>"); String classname = remSpace(arr[2]); CourseWrapper c = new CourseWrapper(classnum, classname); arr = rd.readLine().split("<|>"); String periodnum = remSpace(arr[4]); String email = ""; String teacher = ""; String roomnum = ""; if(arr.length>=34){ email = remSpace(arr[9].substring(arr[9].indexOf(":")+1,arr[9].length()-1)); teacher = remSpace(arr[10]); roomnum = remSpace(arr[16]); } else { teacher = remSpace(arr[8]); roomnum = remSpace(arr[12]); } if(cp.get(classnum+" "+classname)==null && !classname.toLowerCase().equals("lunch")){ cp.classes.add(new Course(classname,teacher,email,roomnum,classnum,Integer.parseInt(periodnum),"","","","","","","","","","")); } for(Period p : periods){ if(p.periodnum.equals(periodnum)){ if(p.semester1==null){ p.semester1 = c; } else if(p.semester2==null){ p.semester2 = c; } } } } } ArrayList<String> sem1arr = new ArrayList<String>(); ArrayList<String> sem2arr = new ArrayList<String>(); ArrayList<String> cn1arr = new ArrayList<String>(); ArrayList<String> cn2arr = new ArrayList<String>(); for(Period p : periods){ if(sem1arr.size()>=2) { if(!p.semester1.name.equals(sem1arr.get(sem1arr.size()-1)) && sem1arr.get(sem1arr.size()-2).equals(sem1arr.get(sem1arr.size()-1))){ sem1arr.remove(sem1arr.size()-1); cn1arr.remove(cn1arr.size()-1); } sem1arr.add(p.semester1.name); cn1arr.add(p.semester1.coursenum); } else { sem1arr.add(p.semester1.name); cn1arr.add(p.semester1.coursenum); } if(sem2arr.size()>=2) { if(!p.semester2.name.equals(sem2arr.get(sem2arr.size()-1)) && sem2arr.get(sem2arr.size()-2).equals(sem2arr.get(sem2arr.size()-1))){ sem2arr.remove(sem2arr.size()-1); cn2arr.remove(cn2arr.size()-1); } sem2arr.add(p.semester2.name); cn2arr.add(p.semester2.coursenum); } else { sem2arr.add(p.semester2.name); cn2arr.add(p.semester2.coursenum); } } for(int i=0;i<sem1arr.size();i++){ cp.sem1cnum.add(cn1arr.get(i)); cp.schedulesem1.add(sem1arr.get(i)); } for(int i=0;i<sem2arr.size();i++){ cp.sem2cnum.add(cn2arr.get(i)); cp.schedulesem2.add(sem2arr.get(i)); } } catch (IOException ex) { Logger.getLogger(Bot.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:net.sf.ehcache.config.BeanHandler.java
/** * Creates a child object.//w w w . j a v a2s . c o m */ private static Object createInstance(Object parent, Class childClass) throws Exception { final Constructor[] constructors = childClass.getConstructors(); ArrayList candidates = new ArrayList(); for (int i = 0; i < constructors.length; i++) { final Constructor constructor = constructors[i]; final Class[] params = constructor.getParameterTypes(); if (params.length == 0) { candidates.add(constructor); } else if (params.length == 1 && params[0].isInstance(parent)) { candidates.add(constructor); } } switch (candidates.size()) { case 0: throw new Exception("No constructor for class " + childClass.getName()); case 1: break; default: throw new Exception("Multiple constructors for class " + childClass.getName()); } final Constructor constructor = (Constructor) candidates.remove(0); if (constructor.getParameterTypes().length == 0) { return constructor.newInstance(new Object[] {}); } else { return constructor.newInstance(new Object[] { parent }); } }
From source file:com.google.cloud.dataflow.sdk.io.TextIOTest.java
License:asdf
private static Function<List<String>, List<String>> removeHeaderAndFooter(final String header, final String footer) { return new Function<List<String>, List<String>>() { @Nullable/*from w w w. j a v a 2 s. c om*/ @Override public List<String> apply(List<String> lines) { ArrayList<String> newLines = Lists.newArrayList(lines); if (header != null) { newLines.remove(0); } if (footer != null) { int last = newLines.size() - 1; newLines.remove(last); } return newLines; } }; }
From source file:configuration.Cluster.java
/** * Test if the output is here path is a Unix path * Added by JG 2017//from w ww. j a va 2s . c o m * @param * @return true or false */ public static boolean downloadResults(workflow_properties properties) { if (isP2RsaHere()) { Enumeration<Object> e = properties.keys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); if (key.contains("ClusterLocalOutput_")) { String fLoc = ""; if (isDocker(properties)) { fLoc = restoreLocalDocker(properties.get(key))[0]; } else { fLoc = properties.get(key); } String fDir = fLoc; if (Util.testIfFile(fLoc)) fDir = Util.getParentOfFile(fLoc); String clusterDir = properties.get("ClusterDirPath"); String fClus = clusterDir + "/outputs/"; ArrayList<String> tab = runSshCommand(properties, "ls " + fClus); if (tab.size() >= 2 && !tab.get(0).contains("ls")) { tab.remove(tab.size() - 1); for (int i = 0; i < tab.size(); i++) { tab.set(i, fClus + tab.get(i)); } String[] tabTmp = tab.toArray(new String[tab.size()]); boolean b2 = runDownloadDir(properties, fDir, tabTmp); if (!b2) { return false; } } else { return false; } } } return true; } return false; }
From source file:edu.oregonstate.eecs.mcplan.domains.blackjack.HitAction.java
@Override public void undoAction(final BlackjackState s) { assert (done_); s.deck().undeal(c_);//from ww w . j av a2s .co m final ArrayList<Card> h = s.hand(player); h.remove(h.size() - 1); s.setPassed(player, false); // In case player busted done_ = false; }
From source file:com.groupon.jenkins.dynamic.build.DynamicProjectBranchTabsProperty.java
public void removeBranch(String branch) { ArrayList<String> branches = parseBranches(); branches.remove(branch); save(branches); }