List of usage examples for java.util ArrayList clone
public Object clone()
From source file:Main.java
public static void main(String args[]) { // create an empty array list ArrayList<StringBuilder> arrlist1 = new ArrayList<StringBuilder>(); // use add for new value arrlist1.add(new StringBuilder("from java2s.com")); // using clone to affect the objects pointed to by the references. ArrayList arrlist2 = (ArrayList) arrlist1.clone(); // appending the string StringBuilder strbuilder = arrlist1.get(0); strbuilder.append("tutorials"); System.out.println(arrlist1); System.out.println(arrlist2); }
From source file:uk.ac.diamond.scisoft.ncd.core.utils.NcdDataUtils.java
/** * Method for generating all combination of elements supplied in the input array * // w ww .j a va 2 s .c o m * @param input * Array containing arrays of elements. * Resulting combinations will pick single element from every input array. * @return * Array containing all combinations of the input elements with only one element * picked from every input array at a time. */ public static ArrayList<int[]> generateCombinations(final ArrayList<int[]> input) { ArrayList<int[]> result = new ArrayList<int[]>(); @SuppressWarnings("unchecked") ArrayList<int[]> tmpInput = (ArrayList<int[]>) input.clone(); int[] first = tmpInput.remove(0); for (int i = 0; i < first.length; i++) { if (!tmpInput.isEmpty()) { ArrayList<int[]> recursive = generateCombinations(tmpInput); for (int j = 0; j < recursive.size(); j++) { ArrayList<Integer> tmp = new ArrayList<Integer>(); tmp.add(first[i]); tmp.addAll(Arrays.asList(ArrayUtils.toObject(recursive.get(j)))); result.add(ArrayUtils.toPrimitive(tmp.toArray(new Integer[] {}))); } } else { ArrayList<Integer> tmp = new ArrayList<Integer>(); tmp.add(first[i]); result.add(ArrayUtils.toPrimitive(tmp.toArray(new Integer[] {}))); } } return result; }
From source file:org.xulux.core.XuluxContext.java
/** * Fires the rules on the specified field * * @param widget The field to fire the rules for * @param request the requeset object to pass to the rule * @param type the type of request to fire in the rule *//* w w w . j a v a 2 s . c o m*/ public static void fireFieldRequest(Widget widget, PartRequest request, int type) { ArrayList tmpRules = widget.getRules(); if (tmpRules == null || tmpRules.size() == 0) { return; } ArrayList currentRules = (ArrayList) tmpRules.clone(); Iterator it = currentRules.iterator(); fireRequests(it, request, type); currentRules.clear(); currentRules = null; }
From source file:org.xulux.core.XuluxContext.java
/** * Fires an fieldrequest of the type specfied * * @param request the requeset object to pass to the rule * @param type the type of request to fire in the rule *///ww w .jav a 2 s .com public static void fireFieldRequests(PartRequest request, int type) { ArrayList requestWidgets = request.getPart().getWidgets(); if (requestWidgets == null) { return; } ArrayList currentWidgets = (ArrayList) requestWidgets.clone(); Iterator wit = currentWidgets.iterator(); boolean stopAllRules = false; while (wit.hasNext() && !stopAllRules) { Widget widget = (Widget) wit.next(); if (request.getWidget() != null && widget.equals(request.getWidget())) { // don't process the caller again.. continue; } stopAllRules = request.getPart().needToStopAllRules(getInstance()); if (stopAllRules) { return; } ArrayList tmpRules = widget.getRules(); if (tmpRules == null || tmpRules.size() == 0) { continue; } ArrayList currentRules = (ArrayList) tmpRules.clone(); Iterator it = currentRules.iterator(); stopAllRules = fireRequests(it, request, type); } }
From source file:net.ytbolg.mcxa.Launcher.GameInfoGet.java
public static String libstotruedir(ArrayList l) throws JSONException, IOException { // System.out.println("5"); // System.out.println("start libs to true dir"); GameInfo.NotFoundedLibs = new ArrayList(); GameInfo.unzipAbledLibs = new ArrayList(); String tmp = GameInfo.GameDir + tpf + "libraries"; ArrayList temp = (ArrayList) l.clone(); String a = ""; // System.out.println(getSys()); for (int i = 0; i < temp.size(); i++) { String Native = ""; if (((JSONObject) temp.get(i)).has("natives")) { Native = MakeNatives(((JSONObject) temp.get(i)).getJSONObject("natives")); // GameInfo.unzipAbledLibs.add(i) }//from ww w. ja va 2 s . c o m if (((JSONObject) temp.get(i)).has("rules")) { JSONArray ja = ((JSONObject) temp.get(i)).getJSONArray("rules"); if (ja.length() == 1) { if (ja.getJSONObject(0).getString("action").equals("disallow")) { if (ja.getJSONObject(0).toString().contains(getSys())) { // System.out.println(ja.getJSONObject(0).toString()); continue; } } if (ja.getJSONObject(0).getString("action").equals("allow")) { if (!ja.getJSONObject(0).toString().contains(getSys())) { // System.out.println(ja.getJSONObject(0).toString()); continue; } } } if (ja.length() == 2) { if (ja.getJSONObject(1).getString("action").equals("disallow")) { if (ja.getJSONObject(1).toString().contains(getSys())) { // System.out.println(ja.getJSONObject(1).toString()); continue; } } } } // System.out.println("6"); String x = ((JSONObject) temp.get(i)).getString("name"); String e = x; String c = ""; String s[] = x.split(":"); for (int xci = 0; xci < s.length - 2; xci++) { c = c + s[xci].replace(".", tpf) + tpf; } c = c + s[s.length - 2] + tpf + s[s.length - 1]; /* String z = x.substring(0, x.lastIndexOf(":")); x = x.substring(x.lastIndexOf(":")); z = z.replace(".", tpf); x = x.replace(":", tpf);*/ // c = z + x; c = c.replace(":", tpf); String cc[] = e.split(":"); String cd = ""; // System.out.println(e); // System.out.println(cc.length); if (cc.length >= 2) { cd = cc[cc.length - 2] + "-" + cc[cc.length - 1] + Native + ".jar"; // System.out.println(cd+"Check"); } // System.out.println(new File(dir + tpf + "libraries" + tpf + c + tpf + cd).exists()); // System.out.println(new File(dir + tpf + "libraries" + tpf + c + tpf + cd).exists() ? "Notfound:" + dir + tpf + "libraries" + tpf + c + tpf + cd : ""); cd = cd.replace("$", ""); cd = cd.replace("{", ""); cd = cd.replace("}", ""); cd = cd.replaceAll("arch", System.getProperty("sun.arch.data.model")); if (new File(GameInfo.GameDir + tpf + "libraries" + tpf + c + tpf + cd).exists() == false) { if (cd.contains("nightly")) { continue; } // System.out.println( // "" + tpf + c + tpf + cd); GameInfo.NotFoundedLibs.add(tpf + c + tpf + cd); // System.out.print();; // System.out.println(GameInfo.NotFoundedLibs.isEmpty()); } if (Native.equals("") == false) { GameInfo.unzipAbledLibs.add(GameInfo.GameDir + tpf + "libraries" + tpf + c + tpf + cd); continue; } // Runtime.getRuntime().exec("chmod 777 " + dir + tpf + "libraries" + tpf + c + tpf + cd); String h = "\""; String j = ";"; if (!System.getProperty("os.name").contains("Windows")) { h = "'"; j = ":"; } // System.out.println(tpf); // a=a.replace(tpf+tpf, tpf); // System.out.println( h + GameInfo.GameDir + tpf + "libraries" + tpf + c + tpf + cd + h + j); a = a + h + GameInfo.GameDir + tpf + "libraries" + tpf + c + tpf + cd + h + j; } return a; }
From source file:org.xulux.core.XuluxContext.java
/** * Fires a request of a certain type.// w ww . ja va 2s . c o m * * @param request the requeset object to pass to the rule * @param type the type of request to fire in the rule */ public static void fireRequest(PartRequest request, int type) { ApplicationPart part = request.getPart(); ArrayList tmpRules = part.getRules(); if (tmpRules == null || tmpRules.size() == 0) { return; } if (log.isDebugEnabled()) { log.debug("Rules : " + tmpRules); } ArrayList currentRules = (ArrayList) tmpRules.clone(); Iterator it = currentRules.iterator(); fireRequests(it, request, type); }
From source file:com.deque.axe.AXE.java
/** * Recursively find frames and inject a script into them. * @param driver An initialized WebDriver * @param script Script to inject// w w w. ja v a2 s. co m * @param parents A list of all toplevel frames */ private static void injectIntoFrames(final WebDriver driver, final String script, final ArrayList<WebElement> parents) { final JavascriptExecutor js = (JavascriptExecutor) driver; final List<WebElement> frames = driver.findElements(By.tagName("iframe")); for (WebElement frame : frames) { driver.switchTo().defaultContent(); if (parents != null) { for (WebElement parent : parents) { driver.switchTo().frame(parent); } } driver.switchTo().frame(frame); js.executeScript(script); ArrayList<WebElement> localParents = (ArrayList<WebElement>) parents.clone(); localParents.add(frame); injectIntoFrames(driver, script, localParents); } }
From source file:org.apache.axis2.engine.AxisEngine.java
/** * Sends the SOAP Fault to another SOAP node. * * @param msgContext/*from w w w . ja v a 2s.c om*/ * @throws AxisFault */ public static void sendFault(MessageContext msgContext) throws AxisFault { if (LoggingControl.debugLoggingAllowed && log.isTraceEnabled()) { log.trace(msgContext.getLogIDString() + " sendFault:" + msgContext.getMessageID()); } OperationContext opContext = msgContext.getOperationContext(); //FIXME: If this gets paused in the operation-specific phases, the resume is not going to function correctly as the phases will not have all been set // find and execute the Fault Out Flow Handlers if (opContext != null) { AxisOperation axisOperation = opContext.getAxisOperation(); ArrayList faultExecutionChain = axisOperation.getPhasesOutFaultFlow(); //adding both operation specific and global out fault flows. ArrayList outFaultPhases = new ArrayList(); outFaultPhases.addAll((ArrayList) faultExecutionChain.clone()); msgContext.setExecutionChain((ArrayList) outFaultPhases.clone()); msgContext.setFLOW(MessageContext.OUT_FAULT_FLOW); try { InvocationResponse pi = invoke(msgContext, NOT_RESUMING_EXECUTION); if (pi.equals(InvocationResponse.SUSPEND)) { log.warn(msgContext.getLogIDString() + " The resumption of this flow may function incorrectly, as the OutFaultFlow will not be used"); return; } else if (pi.equals(InvocationResponse.ABORT)) { flowComplete(msgContext); return; } else if (!pi.equals(InvocationResponse.CONTINUE)) { String errorMsg = "Unrecognized InvocationResponse encountered in AxisEngine.sendFault()"; log.error(msgContext.getLogIDString() + " " + errorMsg); throw new AxisFault(errorMsg); } } catch (AxisFault e) { msgContext.setFailureReason(e); flowComplete(msgContext); throw e; } } ArrayList<Handler> executionChain = new ArrayList<Handler>( msgContext.getConfigurationContext().getAxisConfiguration().getOutFaultFlowPhases()); msgContext.setExecutionChain(executionChain); msgContext.setFLOW(MessageContext.OUT_FAULT_FLOW); InvocationResponse pi = invoke(msgContext, NOT_RESUMING_EXECUTION); if (pi.equals(InvocationResponse.CONTINUE)) { // Actually send the SOAP Fault TransportOutDescription transportOut = msgContext.getTransportOut(); if (transportOut == null) { throw new AxisFault("Transport out has not been set"); } TransportSender sender = transportOut.getSender(); sender.invoke(msgContext); flowComplete(msgContext); } else if (pi.equals(InvocationResponse.SUSPEND)) { } else if (pi.equals(InvocationResponse.ABORT)) { flowComplete(msgContext); } else { String errorMsg = "Unrecognized InvocationResponse encountered in AxisEngine.sendFault()"; log.error(msgContext.getLogIDString() + " " + errorMsg); throw new AxisFault(errorMsg); } }
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:org.carcv.web.servlet.CarTableServlet.java
/** * @see CarTableServlet//from w w w .j a v a2 s . c om * @param request the HttpServletRequest * @param response the HttpServletResponse * @throws ServletException * @throws IOException */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final ArrayList<FileEntry> requestEntries = (ArrayList<FileEntry>) bean.getAll(); @SuppressWarnings("unchecked") ArrayList<FileEntry> abstractEntries = (ArrayList<FileEntry>) requestEntries.clone(); // Timezone String timeZoneStr = request.getParameter("timezone"); TimeZone tz = TimeZone.getTimeZone(timeZoneStr); DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy"); dateFormat.setTimeZone(tz); DateFormat timeFormat = new SimpleDateFormat("HH:mm"); timeFormat.setTimeZone(tz); Collections.sort(abstractEntries, new Comparator<FileEntry>() { @Override public int compare(FileEntry o1, FileEntry o2) { return new CompareToBuilder().append(o2.getCarData().getTimestamp(), o1.getCarData().getTimestamp()) .toComparison(); } }); String date, time, entryId, licensePlate, location, previewPath; ArrayList<WebReportTableMember> wrtmList = new ArrayList<>(); for (FileEntry e : abstractEntries) { // initialize date = dateFormat.format(e.getCarData().getTimestamp()); time = timeFormat.format(e.getCarData().getTimestamp()); entryId = e.getId().toString(); licensePlate = e.getCarData().getNumberPlate().getOrigin() + ": " + e.getCarData().getNumberPlate().getText(); location = e.getCarData().getAddress().printBR(); FileCarImage fci = e.getCarImages().get(0); previewPath = fci.getFilepath().toString(); WebReportTableMember wrtm = new WebReportTableMember(previewPath, entryId, time, date, location, licensePlate, timeZoneStr); wrtmList.add(wrtm); } request.setAttribute("wrtmList", wrtmList); boolean isAdmin = request.isUserInRole(adminRole); request.setAttribute("isAdmin", isAdmin); RequestDispatcher rd = getServletContext().getRequestDispatcher("/app/cartable.jsp"); rd.forward(request, response); }