List of usage examples for java.util ArrayList get
public E get(int index)
From source file:au.org.ala.layers.grid.GridCacheBuilder.java
private static void writeGroupHeader(File f, ArrayList<Grid> group) throws IOException { FileWriter fw = null;//ww w. j a va 2s .c om try { fw = new FileWriter(f); for (int i = 0; i < group.size(); i++) { fw.write(group.get(i).filename); fw.write("\n"); } fw.flush(); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { if (fw != null) { try { fw.close(); } catch (Exception e) { logger.error(e.getMessage(), e); } } } }
From source file:ExifUtils.ExifReadWrite.java
private static List<meta> exifToMetaET(ArrayList<String> filenames, File dir) { String filename = null;/*from w ww .j a v a2 s . c o m*/ if (filenames.size() == 1 && filenames.get(0).length() > 5) { filename = dir + "\\" + filenames.get(0); } filenames.add(0, "-OriginalDocumentID"); filenames.add(0, "-DocumentID"); filenames.add(0, "-InstanceID"); filenames.add(0, "-DateTimeOriginal"); filenames.add(0, "-xmp:DateTimeOriginal"); filenames.add(0, "-Model"); filenames.add(0, "exiftool"); ArrayList<String> exifTool = exifTool(filenames.toArray(new String[0]), dir); Iterator<String> iterator = exifTool.iterator(); ArrayList<meta> results = new ArrayList<>(); int i = -1; String model = null; String note = ""; String iID = null; String dID = null; String odID = null; String captureDate = null; Boolean dateFormat = null; while (iterator.hasNext()) { String line = iterator.next(); if (line.startsWith("========")) { if (i > -1) { meta meta = new meta(filename, getZonedTimeFromStr(captureDate), dateFormat, model, iID, dID, odID, note); System.out.println(meta); results.add(meta); } i++; String fileTemp = line.substring(9).replaceAll("./", "").replaceAll("/", "\\"); filename = dir + "\\" + fileTemp; model = null; captureDate = null; dID = null; odID = null; note = ""; dateFormat = false; //End of exiftool output } else if (line.contains("image files read")) { if (!line.contains(" 0 image files read")) { } } else if (line.contains("files could not be read")) { } else { String tagValue = ""; if (line.length() > 34) tagValue = line.substring(34); switch (line.substring(0, 4)) { case "Date": if (captureDate == null) captureDate = tagValue; else { if (Math.abs(captureDate.length() - tagValue.length()) == 6) dateFormat = true; captureDate = tagValue; } break; case "Came": model = tagValue; break; case "Orig": odID = tagValue; break; case "Docu": dID = tagValue; break; case "Inst": iID = tagValue; break; case "Warn": note = line; break; } } } if (filename != null) { meta meta = new meta(filename, getZonedTimeFromStr(captureDate), dateFormat, model, iID, dID, odID, note); System.out.println(meta); results.add(meta); // results.add(new meta(filename, getZonedTimeFromStr(captureDate), dateFormat, model, note, dID, odID)); } return results; }
From source file:com.shenit.commons.utils.CollectionUtils.java
/** * Take the first n elements// w w w . ja v a2 s . co m * @param cols * @param n * @return */ public static <T> Collection<T> take(Collection<T> cols, int n, int direction) { if (cols == null || n < 0) return null; ArrayList<T> result = new ArrayList<T>(); ArrayList<T> colsArr = new ArrayList<T>(cols); int size = cols.size(); for (int i = 0; i < cols.size(); i++) { if ((i < n && direction >= 0) || (i >= (size - n) && direction < 0)) result.add(colsArr.get(i)); } return result; }
From source file:mxnet.ImageClassification.java
/** * Helper class to print the maximum prediction result * @param probabilities The float array of probability * @param modelPathPrefix model Path needs to load the synset.txt *///from w w w . j av a 2 s . co m private static String printMaximumClass(float[] probabilities, String modelPathPrefix) throws IOException { String synsetFilePath = modelPathPrefix.substring(0, 1 + modelPathPrefix.lastIndexOf(File.separator)) + "/synset.txt"; BufferedReader reader = new BufferedReader(new FileReader(synsetFilePath)); ArrayList<String> list = new ArrayList<>(); String line = reader.readLine(); while (line != null) { list.add(line); line = reader.readLine(); } reader.close(); int maxIdx = 0; for (int i = 1; i < probabilities.length; i++) { if (probabilities[i] > probabilities[maxIdx]) { maxIdx = i; } } return "Probability : " + probabilities[maxIdx] + " Class : " + list.get(maxIdx); }
From source file:com.redhat.jenkins.nodesharingbackend.ReservationVerifier.java
@VisibleForTesting public static void verify(ConfigRepo.Snapshot config, Api api) { // Capture multiple plans so we can identify long-lasting problems. The number of samples and delay is to be fine-tuned. ArrayList<Map<ExecutorJenkins, PlannedFixup>> plans = new ArrayList<>(); plans.add(computePlannedFixup(config, api)); if (plans.get(0).isEmpty()) return; // If there is nothing to do, no need to doublecheck try {/* w w w. j a v a 2 s.c o m*/ Thread.sleep(RestEndpoint.TIMEOUT * 2); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; } plans.add(computePlannedFixup(config, api)); Map<ExecutorJenkins, PlannedFixup> plan = PlannedFixup.reduce(plans); // First kill all dangling reservations, then schedule new ones across the orchestrator to make sure backfills // are not blocked by reservations we are about to kill // Completed reservations may stick around for a while - avoid reporting that as a problem ArrayList<ReservationTask.ReservationExecutable> justCompleted = new ArrayList<>(); // NC1 for (Map.Entry<ExecutorJenkins, PlannedFixup> e2pf : plan.entrySet()) { ExecutorJenkins executor = e2pf.getKey(); for (String cancel : e2pf.getValue().toCancel) { ShareableComputer computer; try { computer = ShareableComputer.getByName(cancel); } catch (NoSuchElementException e) { continue; } ReservationTask.ReservationExecutable reservation = computer.getReservation(); if (reservation == null) continue; ReservationTask parent = reservation.getParent(); if (!parent.getOwner().equals(executor)) continue; LOGGER.info("Canceling dangling " + reservation); reservation.complete(); justCompleted.add(reservation); } } // NC2 for (Map.Entry<ExecutorJenkins, PlannedFixup> e2pf : plan.entrySet()) { ExecutorJenkins executor = e2pf.getKey(); for (String host : e2pf.getValue().toSchedule) { try { ShareableComputer computer = ShareableComputer.getByName(host); ReservationTask task = new ReservationTask(executor, host, true); LOGGER.info("Starting backfill " + task); ReservationTask.ReservationExecutable reservation = computer.getReservation(); if (reservation != null && !justCompleted.contains(reservation)) { ExecutorJenkins owner = reservation.getParent().getOwner(); if (owner.equals(executor)) continue; LOGGER.warning("Host " + host + " is already used by " + reservation); } task.schedule(); } catch (NoSuchElementException ex) { continue; // host disappeared } } } }
From source file:es.uniovi.imovil.fcrtrainer.highscores.HighscoreManager.java
private static ArrayList<Highscore> trim(ArrayList<Highscore> highscores, int maxNumberHighscores) { ArrayList<Highscore> trimmedHighscores = new ArrayList<Highscore>(); SparseIntArray highscoresPerExercise = new SparseIntArray(); Collections.sort(highscores); Collections.reverse(highscores); for (int i = 0; i < highscores.size(); i++) { int exercise = highscores.get(i).getExercise(); if (highscoresPerExercise.get(exercise) != 0) { int numHighscores = highscoresPerExercise.get(exercise); if (numHighscores < maxNumberHighscores) { highscoresPerExercise.put(exercise, numHighscores + 1); trimmedHighscores.add(highscores.get(i)); }/*from w ww.j a v a2 s .c o m*/ } else { highscoresPerExercise.put(exercise, 1); trimmedHighscores.add(highscores.get(i)); } } return trimmedHighscores; }
From source file:de.ingrid.portal.global.UtilsFileHelper.java
/** * Sort long values in ArrayList// www .ja v a 2 s .c om * * @param fileArray */ public static void sortFileByDate(ArrayList<Long> fileArray) { boolean unsort = true; long temp; while (unsort) { unsort = false; for (int i = 0; i < fileArray.size() - 1; i++) if (fileArray.get(i) > fileArray.get(i + 1)) { temp = fileArray.get(i); fileArray.set(i, fileArray.get(i + 1)); fileArray.set(i + 1, temp); unsort = true; } } }
From source file:com.epam.dlab.backendapi.dao.BaseDAO.java
private static Object getDotted(Document d, String fieldName) { if (fieldName.isEmpty()) { return null; }/*from w w w. j av a 2 s. com*/ final String[] fieldParts = StringUtils.split(fieldName, '.'); Object val = d.get(fieldParts[0]); for (int i = 1; i < fieldParts.length; ++i) { if (fieldParts[i].equals("$") && val instanceof ArrayList) { ArrayList<?> array = (ArrayList<?>) val; if (array.isEmpty()) { return val; } else { val = array.get(0); } } else if (val instanceof Document) { val = ((Document) val).get(fieldParts[i]); } else { return val; } } return val; }
From source file:android.databinding.tool.util.XmlEditor.java
private static ImmutablePair<Position, Position> findTerminalPositions(XMLParser.ElementContext node, ArrayList<String> lines) { Position endPosition = toEndPosition(node.getStop()); Position startPosition = toPosition(node.getStop()); int index;// w w w .j av a2 s. co m do { index = lines.get(startPosition.line).lastIndexOf("</"); startPosition.line--; } while (index < 0); startPosition.line++; startPosition.charIndex = index; //noinspection unchecked return new ImmutablePair<>(startPosition, endPosition); }
From source file:Main.java
public static int getFrequentElement(int[] bcp) { HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(); ArrayList<Integer> count = new ArrayList<Integer>(); ArrayList<Integer> uniId = new ArrayList<Integer>(); int id = 0;/*from w ww . j ava 2s . co m*/ for (int col = 0; col < bcp.length; col++) { //System.out.print(bcp[col] + "\t"); int no = 0; if (!map.containsKey(bcp[col])) { map.put(bcp[col], id++); count.add(1); uniId.add(bcp[col]); } else { no = map.get(bcp[col]); count.set(no, count.get(no) + 1); } } int maximum = Integer.MIN_VALUE; int maxId = Integer.MIN_VALUE; for (int i = 0; i < count.size(); i++) { //System.out.print(uniId.get(i) + ":" + count.get(i) + ",\t"); if (maximum < count.get(i)) { maximum = count.get(i); maxId = uniId.get(i); } } //System.out.println(); map.clear(); uniId.clear(); count.clear(); return maxId; }