List of usage examples for java.util ArrayList get
public E get(int index)
From source file:Main.java
/** * replaces a list of files with another list of files, indicated by names * @param originalList/*from w ww. j a v a2s. co m*/ * @param newList * @return */ public static void replaceFiles(ArrayList<String> originalList, ArrayList<String> newList) throws UnsupportedOperationException, OperationCanceledException { if (originalList.size() != newList.size()) throw new UnsupportedOperationException(); else { String name = null; for (int i = 0, size = originalList.size(); i < size; i++) { name = originalList.get(i); File f = new File(name); File newF = new File(newList.get(i)); if (f.exists() && newF.exists()) { if (f.delete()) { File temp = new File(name); newF.renameTo(temp); } else { throw new OperationCanceledException("Delete failed"); } } else { throw new UnsupportedOperationException("Wrong lists of file names"); } } } }
From source file:Main.java
public static Element[] getElementsByName(Element parent, String name) { ArrayList resList = new ArrayList(); NodeList nl = getNodeList(parent); for (int i = 0; i < nl.getLength(); i++) { Node nd = nl.item(i);//from w w w .jav a 2s . c om if (nd.getNodeName().equals(name)) { resList.add(nd); } } Element[] res = new Element[resList.size()]; for (int i = 0; i < resList.size(); i++) { res[i] = (Element) resList.get(i); } logger.debug(parent.getNodeName() + "'s children of " + name + "'s num:" + res.length); return res; }
From source file:GUI.WebBrowserPanel.java
public static boolean parseContent(ArrayList<String> content, c_Card card) { boolean foundCard = false; String line;//from ww w .j a va 2 s .com for (int i = 0; i < content.size(); i++) { line = content.get(i); if (line.contains("multiverseid=") && card.MID == 0) { foundCard = true; card.MID = Integer.parseInt(str.middleOf("multiverseid=", line, "\" id=")); i += 300; /* help out the parser a little */ } else if (line.contains("Card Name:")) { i += 2; card.Name = str.leftOf(content.get(i), "</div>").trim(); } else if (line.contains("Mana Cost:")) { i += 2; line = content.get(i); String glyphs = ""; do { line = str.rightOf(line, "/Handlers/Image.ashx?size=medium&name="); glyphs += str.leftOf(line, "&type=symbol") + ","; } while (line.contains("/Handlers/Image.ashx?size=medium&name=")); card.CastingCost = new c_CastingCost(glyphs.substring(0, glyphs.length() - 1)); i += 5; /* skip over converted mana cost */ glyphs = null; } else if (line.contains("Types:")) { i += 2; line = content.get(i); if (line.contains("")) { card.Type = str.leftOf(line, "").trim(); card.SubType = str.middleOf(" ", line, "</div>"); } else { card.Type = str.leftOf(line, "</div>").trim(); card.SubType = ""; } } else if (line.contains("P/T:")) { i += 2; line = content.get(i); card.PT = str.leftOf(line, "</div>").replaceAll(" ", ""); } else if (line.contains("Expansion:")) { i += 4; line = content.get(i); card.Expansion = str.middleOf(">", line, "</a>"); break; /* nothing left of interest */ } } line = null; return foundCard; }
From source file:au.org.ala.layers.grid.GridCacheBuilder.java
private static void writeGroupGRI(File file, ArrayList<Grid> group) { Grid g = group.get(0); RandomAccessFile[] raf = new RandomAccessFile[group.size()]; RandomAccessFile output = null; try {// ww w . j a va 2s. co m output = new RandomAccessFile(file, "rw"); for (int i = 0; i < group.size(); i++) { raf[i] = new RandomAccessFile(group.get(i).filename + ".gri", "r"); } int length = g.ncols * g.nrows; int size = 4; byte[] b = new byte[size * group.size() * g.ncols]; float noDataValue = Float.MAX_VALUE * -1; byte[] bi = new byte[g.ncols * 8]; float[][] rows = new float[group.size()][g.ncols]; for (int i = 0; i < g.nrows; i++) { //read for (int j = 0; j < raf.length; j++) { nextRowOfFloats(rows[j], group.get(j).datatype, group.get(j).byteorderLSB, g.ncols, raf[j], bi, (float) g.nodatavalue); } //write ByteBuffer bb = ByteBuffer.wrap(b); bb.order(ByteOrder.LITTLE_ENDIAN); for (int k = 0; k < g.ncols; k++) { for (int j = 0; j < raf.length; j++) { //float f = getNextValue(raf[j], group.get(j)); float f = rows[j][k]; if (Float.isNaN(f)) { bb.putFloat(noDataValue); } else { bb.putFloat(f); } } } output.write(b); } } catch (IOException e) { logger.error(e.getMessage(), e); } finally { if (output != null) { try { output.close(); } catch (Exception e) { logger.error(e.getMessage(), e); } } for (int i = 0; i < raf.length; i++) { if (raf[i] != null) { try { raf[i].close(); } catch (Exception e) { logger.error(e.getMessage(), e); } } } } }
From source file:com.uniteddev.Unity.Downloader.java
public static void recursiveFileListing(ArrayList<String> extracted_links, String folder) throws IOException { for (int i = 0; i < extracted_links.size(); i++) { String target = extracted_links.get(i).toString(); String new_folder = folder + target; while (target.endsWith("/")) { folders.add(new_folder); String foldername[] = new_folder.split("/"); folder((Minecraft.getWorkingDirectory() + File.separator + new_folder), foldername[foldername.length - 1]); recursiveFileListing(getDirectoryListing(new_folder), new_folder); break; }/* w ww . j a v a 2 s.co m*/ if (!new_folder.endsWith("/")) { files.add(new_folder); rename_files.add(new_folder); } } }
From source file:edu.uci.ics.jung.algorithms.transformation.FoldingTransformerFixed.java
/** * @param target/*from w ww . j av a2 s . c o m*/ * @param e * @param incident */ private static <S, T> void populateTarget(UndirectedGraph<S, FoldedEdge<S, T>> target, T e, ArrayList<S> incident) { for (int i = 0; i < incident.size(); i++) { S v1 = incident.get(i); for (int j = i + 1; j < incident.size(); j++) { S v2 = incident.get(j); FoldedEdge<S, T> e_coll = target.findEdge(v1, v2); if (e_coll == null) { e_coll = new FoldedEdge<S, T>(v1, v2); target.addEdge(e_coll, v1, v2); } e_coll.getFolded().add(e); } } }
From source file:fr.bmartel.android.tictactoe.request.ResponseParser.java
public static List<DeviceItem> parseDeviceList(Intent intent, String excludedDeviceId) { ArrayList<String> actionsStr = intent.getStringArrayListExtra(""); List<DeviceItem> deviceList = new ArrayList<>(); if (actionsStr.size() > 0) { try {// w w w. java 2s. co m JSONObject mainObject = new JSONObject(actionsStr.get(0)); if (mainObject.has(RequestConstants.DEVICE_ITEMS)) { JSONArray devices = mainObject.getJSONArray(RequestConstants.DEVICE_ITEMS); for (int i = 0; i < devices.length(); i++) { JSONObject item = (JSONObject) devices.get(i); JSONObject docItem = item.getJSONObject("doc"); if (docItem.has("_id") && docItem.has(RequestConstants.DEVICE_NAME) && docItem.has(RequestConstants.DEVICE_STATE)) { if (!docItem.getString("_id").equals(excludedDeviceId)) { deviceList.add(new DeviceItem(docItem.getString("_id"), docItem.getString(RequestConstants.DEVICE_NAME), GameStates.getState(docItem.getInt(RequestConstants.DEVICE_STATE)))); } /* deviceList.add(new DeviceItem(docItem.getString("_id"), docItem.getString(RequestConstants.DEVICE_NAME), GameStates.getState(docItem.getInt(RequestConstants.DEVICE_STATE)))); */ } } } } catch (JSONException e) { e.printStackTrace(); } } return deviceList; }
From source file:com.ilearnrw.reader.utils.HttpHelper.java
public static boolean refreshTokens(Context context) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); String refreshToken = preferences.getString(context.getString(R.string.sp_refreshToken), ""); if (refreshToken.isEmpty()) return false; HttpResponse refreshResponse = HttpHelper .get("https://ssl.ilearnrw.eu/ilearnrw/user/newtokens?refresh=" + refreshToken); ArrayList<String> refreshData = HttpHelper.handleResponse(refreshResponse); if (refreshData == null) return false; if (refreshData.size() > 1) { try {//from w w w . j av a 2 s . c om TokenResult lr = new Gson().fromJson(refreshData.get(1), TokenResult.class); SharedPreferences.Editor editor = preferences.edit(); editor.putString(context.getString(R.string.sp_authToken), lr.authToken); editor.putString(context.getString(R.string.sp_refreshToken), lr.refreshToken); editor.apply(); return true; } catch (Exception e) { e.printStackTrace(); return false; } } else { Log.e("Error", refreshData.get(0)); } return false; }
From source file:Main.java
/** * Get the node set from parent node by the specified name * * @param parent/*from ww w .j a v a 2s. co m*/ * @param name * @return */ public static Element[] getElementsByName(Element parent, String name) { ArrayList resList = new ArrayList(); NodeList nl = getNodeList(parent); for (int i = 0; i < nl.getLength(); i++) { Node nd = nl.item(i); if (nd.getNodeName().equals(name)) { resList.add(nd); } } Element[] res = new Element[resList.size()]; for (int i = 0; i < resList.size(); i++) { res[0] = (Element) resList.get(i); } return res; }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CRUDUsuarios.java
protected static void eliminarUsuario(HttpServletRequest request, HttpServletResponse response) throws IOException { ArrayList r = CtrlAdmin.eliminarUsuario(Integer.parseInt(request.getParameter("1"))); // id_usuario response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); if (r.get(0) == "error") { JSONObject obj = new JSONObject(); if (r.get(1) == "usuario") { obj.put("isError", true); obj.put("errorDescrip", "El usuario no existe"); } else {/*from w ww. ja va 2 s . co m*/ Util.errordeRespuesta(r, out); } out.print(obj); } else if (r.get(0) == "isExitoso") { JSONObject obj = new JSONObject(); obj.put("Exitoso", true); out.print(obj); } else Util.errordeRespuesta(r, out); }