List of usage examples for java.util ArrayList get
public E get(int index)
From source file:no.digipost.android.api.ContentOperations.java
private static String getUploadUri(Context context, int content) throws DigipostApiException, DigipostClientException, DigipostAuthenticationException { getCurrentMailbox(context);/*from w ww. j a v a 2 s. c o m*/ if (content == ApplicationConstants.MAILBOX) { return mailbox.getUploadToInboxUri(); } else { content -= ApplicationConstants.numberOfStaticFolders; ArrayList<Folder> folders = mailbox.getFolders().getFolder(); return folders.get(content).getUploadUri(); } }
From source file:com.passwdmanager.formats.JSONManager.java
public static String makeFile(String username, ArrayList<PasswdResource> passwords) { String data = "{ \n\t\"username\": \"" + username + "\", \n"; data += "\t\"sites\": ["; int max = passwords.size(); for (int i = 0; i < max; i++) { PasswdResource pr = passwords.get(i); if (i > 0) data += ", "; data += "\n\t\t{"; data += "\t\t\t\"sitename\": \"" + pr.getSite() + "\", \n"; data += "\t\t\t\"name\": \"" + pr.getName() + "\", \n"; data += "\t\t\t\"password\": \"" + pr.getPassword(); if (pr.getNote() != null) data += "\", \n\t\t\t\"note\": \"" + pr.getNote() + "\"\n"; else//w w w . j av a 2 s .com data += "\"\n"; data += "\t\t}"; } data += "\n\t]\n"; data += "}"; return data; }
From source file:controllers.FileHandler.java
/** * brief: read content of a given file to the proper list * @param strFilePath - path of given file e.g. "D:\\EGYETEM\\Szakdolgozat\\Mernoki_tervezes\\update files\\sr28upd\\ADD_NUTR.txt" * @param strFileType - type of the given file e.g. AddFood * @param TList - list to fill with data e.g. List<FileFoodStruct> ListFFS *///from w ww . ja v a2 s.c om public static <T> void readFile(String strFilePath, List<T> TList, String strFileType) { TList.clear(); try { File file = FileUtils.getFile(strFilePath); LineIterator iter = FileUtils.lineIterator(file); while (iter.hasNext()) { String strLine = iter.next(); switch (strFileType) { case "ADD_FOOD": { ArrayList<String> strList = ParseUpdateFile(strLine); FileStructFood Object = new FileStructFood(strList.get(0), strList.get(2), strList.get(3), Integer.valueOf(strList.get(8))); TList.add((T) Object); //System.out.println(Object.toString()); break; } case "ADD_NUTR": { ArrayList<String> strList = ParseUpdateFile(strLine); FileStructNutrient Object = new FileStructNutrient(strList.get(0), strList.get(1), Double.valueOf(strList.get(2))); TList.add((T) Object); //System.out.println(Object.toString()); break; } case "ADD_WGT": { ArrayList<String> strList = ParseUpdateFile(strLine); FileStructWeight Object = new FileStructWeight(strList.get(0), Double.valueOf(strList.get(2)), strList.get(3), Double.valueOf(strList.get(4))); TList.add((T) Object); //System.out.println(Object.toString()); break; } case "CHG_FOOD": { ArrayList<String> strList = ParseUpdateFile(strLine); FileStructFood Object = new FileStructFood(strList.get(0), strList.get(2), strList.get(3), Integer.valueOf(strList.get(8))); TList.add((T) Object); //System.out.println(Object.toString()); break; } case "CHG_NUTR": { ArrayList<String> strList = ParseUpdateFile(strLine); FileStructNutrient Object = new FileStructNutrient(strList.get(0), strList.get(1), Double.valueOf(strList.get(2))); TList.add((T) Object); //System.out.println(Object.toString()); break; } case "CHG_WGT": { ArrayList<String> strList = ParseUpdateFile(strLine); FileStructWeight Object = new FileStructWeight(strList.get(0), Double.valueOf(strList.get(2)), strList.get(3), Double.valueOf(strList.get(4))); TList.add((T) Object); //System.out.println(Object.toString()); break; } case "DEL_FOOD": { ArrayList<String> strList = ParseUpdateFile(strLine); FileStructFood Object = new FileStructFood(strList.get(0), strList.get(1)); TList.add((T) Object); //System.out.println(Object.toString()); break; } case "DEL_NUTR": { ArrayList<String> strList = ParseUpdateFile(strLine); FileStructNutrient Object = new FileStructNutrient(strList.get(0), strList.get(1)); TList.add((T) Object); //System.out.println(Object.toString()); break; } case "DEL_WGT": { ArrayList<String> strList = ParseUpdateFile(strLine); FileStructWeight Object = new FileStructWeight(strList.get(0), Double.valueOf(strList.get(2)), strList.get(3), Double.valueOf(strList.get(4))); TList.add((T) Object); //System.out.println(Object.toString()); break; } case "ADD_NDEF": { ArrayList<String> strList = ParseUpdateFile(strLine); FileStructNutrient Object = new FileStructNutrient(strList.get(0), strList.get(1), strList.get(2), strList.get(3), Integer.valueOf(strList.get(4))); TList.add((T) Object); System.out.println(strList.get(0) + " " + strList.get(1) + " " + strList.get(2) + " " + strList.get(3) + " " + Integer.valueOf(strList.get(4))); break; } case "CHG_NDEF": { ArrayList<String> strList = ParseUpdateFile(strLine); FileStructNutrient Object = new FileStructNutrient(strList.get(0), strList.get(1), strList.get(2), strList.get(3), Integer.valueOf(strList.get(4))); TList.add((T) Object); System.out.println(strList.get(0) + " " + strList.get(1) + " " + strList.get(2) + " " + strList.get(3) + " " + Integer.valueOf(strList.get(4))); break; } case "LOG_FILE": { ArrayList<String> strList = ParseLogFile(strLine); TraceMessage Object = new TraceMessage(strList.get(0), strList.get(1)); TList.add((T) Object); break; } } } iter.close(); } catch (IOException ex) { Logger.getLogger(FileHandler.class.getName()).log(Level.SEVERE, null, ex); } finally { return; } }
From source file:Helpers.HelpersCSV.java
public static String joinArrayListAsEscapedString(ArrayList<String> arrayList) { ArrayList<String> escapedList = new ArrayList<String>(arrayList.size()); for (int i = 0; i < arrayList.size(); i++) { escapedList.add("\"" + arrayList.get(i) + "\""); }/*from w ww. j ava 2s . c om*/ return StringUtils.join(escapedList, ','); }
From source file:Estadistica.java
/** * Metodo multiple//w w w . j av a 2 s .com * param una lista de valores (xArrayList) * @return */ public static double multiple(ArrayList<Double> xArrayList) { double cal = 0; for (int i = 0; i < xArrayList.size(); i++) { cal += xArrayList.get(i); } return cal; }
From source file:au.org.ala.layers.grid.GridCacheBuilder.java
private static void writeGroupGRD(File file, ArrayList<Grid> group) { Grid g = group.get(0); g.writeHeader(file.getPath(), g.xmin, g.ymin, g.xmin + g.xres * g.nrows, g.ymin + g.yres * g.ncols, g.xres, g.yres, g.nrows, g.ncols, g.minval, g.maxval); }
From source file:Main.java
public static BigInteger getZ(ArrayList<byte[]> c1, ArrayList<byte[]> c2, BigInteger p) { BigInteger z = BigInteger.ZERO; //TODO: make sure c1 and c2 are of the same size int size = c1.size(); if (size > c2.size()) { size = c2.size();/*from w w w .ja v a 2 s. c o m*/ } for (int i = 0; i < size; i++) { BigInteger c1BI = new BigInteger(1, c1.get(i)); BigInteger c2BI = new BigInteger(1, c2.get(i)); BigInteger exp = new BigInteger(1, ByteBuffer.allocate(8).putLong((long) Math.pow(2, i)).array()); z = z.add((c1BI.multiply(c2BI)).modPow(exp, p)); Log.d("CeCk", "z calculation " + i + "/" + size + " round"); } return z.mod(p); }
From source file:com.yahoo.egads.utilities.AutoSensitivity.java
public static Float getLowDensitySensitivity(Float[] data, float sDAutoSensitivy, float amntAutoSensitivity) { Float toReturn = Float.POSITIVE_INFINITY; Arrays.sort(data, Collections.reverseOrder()); while (data.length > 0) { ArrayList<Float> fData = new ArrayList<Float>(); fData.add(data[0]);/* w w w . j a v a 2 s .c om*/ data = ((Float[]) ArrayUtils.remove(data, 0)); Float centroid = (float) fData.get(0); Float maxDelta = (float) sDAutoSensitivy * StatsUtils.getSD(data, StatsUtils.getMean(data)); logger.debug("AutoSensitivity: Adding: " + fData.get(0) + " SD: " + maxDelta); // Add points while it's in the same cluster or not part of the other cluster. String localDebug = null; while (data.length > 0 && (centroid - data[0]) <= ((float) (maxDelta))) { float maxDeltaInit = maxDelta; fData.add(data[0]); data = ((Float[]) ArrayUtils.remove(data, 0)); Float[] tmp = new Float[fData.size()]; tmp = fData.toArray(tmp); centroid = StatsUtils.getMean(tmp); if (data.length > 0) { Float sdOtherCluster = (float) StatsUtils.getSD(data, StatsUtils.getMean(data)); maxDelta = sDAutoSensitivy * sdOtherCluster; logger.debug( "AutoSensitivity: Adding: " + data[0] + " SD: " + maxDeltaInit + " SD': " + maxDelta); } } if (data.length > 0) { logger.debug("AutoSensitivity: Next Point I would have added is " + data[0]); } if (((double) fData.size() / (double) data.length) > amntAutoSensitivity) { // Cannot do anomaly detection. logger.debug("AutoSensitivity: Returning " + toReturn + " data size: " + data.length + " fData.size: " + fData.size()); return toReturn; } toReturn = fData.get(fData.size() - 1); logger.debug("AutoSensitivity: Updating toReturn: " + toReturn + " SD: " + maxDelta); return toReturn; } return toReturn; }
From source file:y.graphs.ChartHelperELF.java
private static TimeSeriesCollection createDataset(ElfValue[][] dayvalues, int[] mediane, boolean[] medianevalide, int med_max, Config config, ArrayList<ConfigSerie> series) { final TimeSeries[] aserie = new TimeSeries[series.size()]; for (int i = 0; i < aserie.length; i++) aserie[i] = new TimeSeries(series.get(i).getName()); for (int d = 0; d < dayvalues.length; d++) { final ElfValue[] day = dayvalues[d]; for (int i = 0; i < day.length; i++) { final ElfValue value = day[i]; final DateTime time = value.getTime(); final RegularTimePeriod date = new Minute(time.toDate()); if (value.isValid()) for (int aix = 0; aix < aserie.length; aix++) series.get(aix).add(aserie[aix], date, value.getValue(), mediane[d], medianevalide[d], mediane[med_max]); }/* w w w. j ava 2s .c o m*/ } final TimeSeriesCollection dataset = new TimeSeriesCollection(); for (int aix = 0; aix < aserie.length; aix++) dataset.addSeries(aserie[aix]); return dataset; }
From source file:br.edu.ufcg.supervisor.engine.Simulation.java
public static void executeModel(JSONObject r, Automaton model, HashMap<String, Float> map1, HashMap<Integer, Float> map2, String currentState, String recommendation, String logString) throws Exception { ArrayList<String> names = LoadedModel.getNomesVariaveisMonitoradas(); ArrayList<String> arrayMensagens = new ArrayList<String>(); for (int i = 0; i < map1.size(); i++) { currentState = currentState + "- " + names.get(i) + ": " + map1.get(names.get(i)) + ".<br>"; }/*from ww w . j a va 2s . c o m*/ logString = logString + currentState + " - "; r.put("cur", currentState); State estado = model.buscaEstadoCorrespondente(map2); if (!(estado.getClassificacao() == State.INT_CL_ACEITACAO)) { Search alg = new Search(model); alg.execute(estado); for (State estadoAceito : model.getArrayEstadosAceitos()) { LinkedList<State> caminho = alg.getPath(estadoAceito); if (caminho != null) { for (int j = 0; j < caminho.size() - 1; j++) recommendation += "." + model.getMensagemDasTransicoesEntreDoisEstadosQuaisquer( caminho.get(j), caminho.get(j + 1));//elthon arrayMensagens.add(recommendation); } } recommendation = getShortestPath(arrayMensagens); recommendation = eliminateReplicatedRecommendations(recommendation); if (recommendation.equals(".")) recommendation = "Some variable has not been measured!"; logString = logString + recommendation + "\n"; } else { recommendation = "Keep going!"; logString = logString + "(" + recommendation + ")\n"; } r.put("rec", recommendation); }