List of usage examples for java.util ArrayList get
public E get(int index)
From source file:com.pclinuxos.rpm.util.FileUtils.java
/** * The method extracts a srpm into the default directory used by the program (/home/<user>/RCEB/srpms/tmp) * //www .j a v a2 s.c o m * @param srpm the srpm to extract * @return 0 if the extraction was successfully, -1 if a IOException occurred, -2 if a InterruptException * occurred. Values > 0 for return codes of the rpm2cpio command. */ public static int extractSrpm(String srpm) { int returnCode = 0; try { Process extractProcess = Runtime.getRuntime() .exec("rpm2cpio " + FileConstants.SRCSRPMS.getAbsolutePath() + "/" + srpm); // 64kb buffer byte[] buffer = new byte[0xFFFF]; InputStream inread = extractProcess.getInputStream(); FileOutputStream out = new FileOutputStream(new File(FileConstants.F4SRPMEX + "archive.cpio")); while (inread.read(buffer) != -1) { out.write(buffer); } returnCode = extractProcess.waitFor(); if (returnCode == 0) { CpioArchiveInputStream cpioIn = new CpioArchiveInputStream( new FileInputStream(FileConstants.F4SRPMEX + "archive.cpio")); CpioArchiveEntry cpEntry; while ((cpEntry = cpioIn.getNextCPIOEntry()) != null) { FileOutputStream fOut = new FileOutputStream(FileConstants.F4SRPMEX + cpEntry.getName()); // Do not make this buffer bigger it breaks the cpio decompression byte[] buffer2 = new byte[1]; ArrayList<Byte> buf = new ArrayList<Byte>(); while (cpioIn.read(buffer2) != -1) { buf.add(buffer2[0]); } byte[] file = new byte[buf.size()]; for (int i = 0; i < buf.size(); i++) { file[i] = buf.get(i); } fOut.write(file); fOut.flush(); fOut.close(); } cpioIn.close(); } } catch (IOException e) { returnCode = -1; } catch (InterruptedException e) { returnCode = -2; } new File(FileConstants.F4SRPMEX + "archive.cpio").delete(); return returnCode; }
From source file:com.qasp.diego.arsp.Atualiza.java
private static void LeituraeAtualizacao(InputStream in, ArrayList<Estacao> estacoes) throws Exception { InputStreamReader isr = new InputStreamReader(in, Charset.forName("UTF-8")); BufferedReader br = new BufferedReader(isr); int size = estacoes.size(); for (int e = 0; e < size; e++) { String line = br.readLine(); // Detectar estacoes defeituosas while (!line.equals(estacoes.get(e).getId())) { estacoes.get(e).setIndisponivel(true); e++;/* w w w . jav a 2 s . com*/ } // Leitura e adicao dos poluentes line = br.readLine(); String[] poluentes = line.split("[ ]"); int NOxcol = -1; int NOcol = -1; int ERT = -1; int colcnt = 0; Log.d("Estacao", estacoes.get(e).getNome()); for (String p : poluentes) { Log.d("Poluentes (String p):", p); if (p.equals("NO")) NOcol = colcnt + 2; else if (p.equals("NOx")) NOxcol = colcnt + 2; else if (p.equals("ERT")) ERT = colcnt + 2; colcnt++; } // Leitura das medicoes das ultimas tres horas int maxlin = 3; boolean horamaisrecente = true; for (int i = 0; i < maxlin; i++) { line = br.readLine(); String[] cols = line.split("[ ]"); colcnt = 0; String datatemp = " "; String horastemp = " "; // DATA HORA MED1 MED2 ... for (String c : cols) { if (colcnt != NOxcol && colcnt != NOcol && colcnt != ERT) { if (colcnt == DATA) datatemp = c; else if (colcnt == HORAS) horastemp = c; else { if (c.equals("--")) { horamaisrecente = false; break; } else { estacoes.get(e).AtualizaPoluente(Integer.parseInt(c), PoluentesIndices.PoluenteproIndice(poluentes[colcnt - 2])); } } } if (horamaisrecente && colcnt > 1) estacoes.get(e).AtualizaTempo(datatemp, horastemp); colcnt++; } } } }
From source file:au.org.ala.layers.grid.GridCacheBuilder.java
private static ArrayList<ArrayList<Grid>> identifyGroups(ArrayList<Grid> grids) { ArrayList<ArrayList<Grid>> groups = new ArrayList<ArrayList<Grid>>(); for (int i = 0; i < grids.size(); i++) { boolean newGroup = true; for (int j = 0; j < groups.size(); j++) { if (compareGrids(groups.get(j).get(0), grids.get(i))) { groups.get(j).add(grids.get(i)); newGroup = false;//from w w w .java2 s . c o m break; } } if (newGroup) { ArrayList<Grid> gs = new ArrayList<Grid>(); gs.add(grids.get(i)); groups.add(gs); } } return groups; }
From source file:com.ricemap.spateDB.core.SpatialSite.java
public static CellInfo[] cellsOf(FileSystem fs, Path path) throws IOException { GlobalIndex<Partition> gindex = getGlobalIndex(fs, path); if (gindex == null) return null; // Find all partitions of the given file. If two partitions overlap, // we consider the union of them. This case corresponds to an R-tree // index where a partition is stored as multiple R-tree. Since we compact // each R-tree when it is stored, different compactions might lead to // different partitions all overlapping the same area. In this case, we // union them to ensure the whole area is covered without having overlaps // between returned partitions. ArrayList<CellInfo> cellSet = new ArrayList<CellInfo>(); for (Partition p : gindex) { Prism r = p;//ww w. ja v a 2 s. co m boolean overlapping = false; for (int i = 0; i < cellSet.size(); i++) { if (r.isIntersected(cellSet.get(i))) { overlapping = true; cellSet.get(i).expand(r); r = cellSet.get(i); } } if (overlapping == false) { cellSet.add(new CellInfo(cellSet.size() + 1, p)); } } return cellSet.toArray(new CellInfo[cellSet.size()]); }
From source file:com.telefonica.iot.cygnus.utils.CommonUtils.java
/** * Encodes a string from an ArrayList.//from ww w . j av a 2 s. co m * @param in * @return The encoded string */ public static String toString(ArrayList in) { String out = ""; for (int i = 0; i < in.size(); i++) { if (i == 0) { out = in.get(i).toString(); } else { out += "," + in.get(i).toString(); } // if else } // for return out; }
From source file:android.databinding.tool.util.XmlEditor.java
private static boolean replace(ArrayList<String> lines, Position start, Position end, String text) { fixPosition(lines, start);//from w w w . j a v a 2 s . c o m fixPosition(lines, end); if (start.line != end.line) { String startLine = lines.get(start.line); String newStartLine = startLine.substring(0, start.charIndex) + text; lines.set(start.line, newStartLine); for (int i = start.line + 1; i < end.line; i++) { String line = lines.get(i); lines.set(i, replaceWithSpaces(line, 0, line.length() - 1)); } String endLine = lines.get(end.line); String newEndLine = replaceWithSpaces(endLine, 0, end.charIndex - 1); lines.set(end.line, newEndLine); return true; } else if (end.charIndex - start.charIndex >= text.length()) { String line = lines.get(start.line); int endTextIndex = start.charIndex + text.length(); String replacedText = replaceRange(line, start.charIndex, endTextIndex, text); String spacedText = replaceWithSpaces(replacedText, endTextIndex, end.charIndex - 1); lines.set(start.line, spacedText); return true; } else { String line = lines.get(start.line); String newLine = replaceWithSpaces(line, start.charIndex, end.charIndex - 1); lines.set(start.line, newLine); return false; } }
From source file:Main.java
public static void sendExtendedNotification(Context context, String smTitle, String smMsg, ArrayList<String> lgMsg) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(android.R.drawable.alert_light_frame).setContentTitle(smTitle).setContentText(smMsg); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); // Sets a title for the Inbox in expanded layout inboxStyle.setBigContentTitle(smTitle); // Moves events into the expanded layout for (int i = 0; i < lgMsg.size(); i++) { inboxStyle.addLine(lgMsg.get(i)); }//from ww w. jav a 2 s .c o m // Moves the expanded layout object into the notification object. mBuilder.setStyle(inboxStyle); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); //Update the ID entered if it exists, create a new one if it doesn't mNotificationManager.notify(notifyId, mBuilder.build()); notifyId++; }
From source file:mt.Tracking.java
public static Pair<Double, Double> fromTo(final ArrayList<PointFunctionMatch> points) { double min = points.get(0).getP1().getW()[0]; double max = min; for (final PointFunctionMatch p : points) { final double value = p.getP1().getW()[0]; min = Math.min(min, value); max = Math.max(max, value); }/*from w w w .j av a2 s. c o m*/ return new ValuePair<Double, Double>(min, max); }
From source file:mt.Tracking.java
public static Pair<Double, Double> fromToY(final ArrayList<PointFunctionMatch> points) { double min = points.get(1).getP1().getW()[1]; double max = min; for (final PointFunctionMatch p : points) { final double value = p.getP1().getW()[1]; min = Math.min(min, value); max = Math.max(max, value); }//from w ww.j av a2 s . c om return new ValuePair<Double, Double>(min, max); }
From source file:com.eucalyptus.bootstrap.BootstrapClassLoader.java
private static ClassFile findMappedClass(BindingElement root) { ArrayList childs = root.topChildren(); if (childs != null) { // recursively search for modifiable mapped class for (int i = childs.size() - 1; i >= 0; i--) { Object child = childs.get(i); if (child instanceof MappingElement) { // end scan if a real mapping is found MappingElementBase map = (MappingElementBase) child; ClassFile cf = map.getHandledClass().getClassFile(); if (!cf.isInterface() && cf.isModifiable()) { return cf; }// ww w . j a v a 2 s .c o m } else if (child instanceof IncludeElement) { // recurse on included binding BindingElement bind = ((IncludeElement) child).getBinding(); if (bind != null) { ClassFile cf = findMappedClass(bind); if (cf != null) { return cf; } } } } } return null; }