List of usage examples for java.util List set
E set(int index, E element);
From source file:com.github.steveash.jg2p.seq.PhonemeACrfTrainer.java
private static void updateEpsilons(List<String> phones) { String last = "<EPS>"; int blankCount = 0; for (int i = 0; i < phones.size(); i++) { String p = phones.get(i); if (isBlank(p)) { // phones.set(i, last + "_" + blankCount); phones.set(i, "<EPS>"); blankCount += 1;// w w w .ja v a 2 s . c o m } else { last = p; blankCount = 0; } } }
From source file:chat.viska.xmpp.Jid.java
private static List<String> parseJidParts(final String rawJid) { final List<String> result = Arrays.asList("", "", ""); if (StringUtils.isBlank(rawJid)) { return result; }//w w w . j a v a 2s . c o m final int indexOfSlash = rawJid.indexOf("/"); if (indexOfSlash > 0) { result.set(2, rawJid.substring(indexOfSlash + 1, rawJid.length())); } else if (indexOfSlash < 0) { result.set(2, ""); } else { throw new InvalidJidSyntaxException(); } final String bareJid = indexOfSlash > 0 ? rawJid.substring(0, indexOfSlash) : rawJid; final int indexOfAt = rawJid.indexOf("@"); if (indexOfAt > 0) { result.set(0, bareJid.substring(0, indexOfAt)); result.set(1, bareJid.substring(indexOfAt + 1)); } else if (indexOfAt < 0) { result.set(0, ""); result.set(1, rawJid); } else { throw new InvalidJidSyntaxException(); } return result; }
From source file:io.wcm.devops.conga.generator.util.VariableMapResolver.java
private static List<Object> deescapeList(List<Object> list) { List<Object> listCopy = new ArrayList<>(list); for (int i = 0; i < listCopy.size(); i++) { Object item = listCopy.get(i); Object deescapedValue = deescapeAny(item); if (item != deescapedValue) { listCopy.set(i, deescapedValue); }//from ww w .ja v a 2s . c o m } return listCopy; }
From source file:Main.java
private static <T extends Comparable<T>> void eqSort(List<T> list, int lo0, int hi0) { int lo = lo0; int hi = hi0; if ((hi - lo) <= 3) { eqBrute(list, lo, hi);//from w w w . j ava 2 s . c om return; } /* * Pick a pivot and move it out of the way */ T e, pivot = list.get((lo + hi) / 2); list.set((lo + hi) / 2, list.get(hi)); list.set(hi, pivot); while (lo < hi) { /* * Search forward from a[lo] until an element is found that * is greater than the pivot or lo >= hi */ while (list.get(lo).compareTo(pivot) <= 0 && lo < hi) { lo++; } /* * Search backward from a[hi] until element is found that * is less than the pivot, or hi <= lo */ while (pivot.compareTo(list.get(hi)) <= 0 && lo < hi) { hi--; } /* * Swap elements a[lo] and a[hi] */ if (lo < hi) { e = list.get(lo); list.set(lo, list.get(hi)); list.set(hi, e); } } /* * Put the median in the "center" of the list */ list.set(hi0, list.get(hi)); list.set(hi, pivot); /* * Recursive calls, elements a[lo0] to a[lo-1] are less than or * equal to pivot, elements a[hi+1] to a[hi0] are greater than * pivot. */ eqSort(list, lo0, lo - 1); eqSort(list, hi + 1, hi0); }
From source file:io.wcm.devops.conga.generator.util.VariableMapResolver.java
private static List<Object> replaceList(List<Object> list, Map<String, Object> variables) { boolean replacedAny = false; List<Object> listCopy = new ArrayList<>(list); for (int i = 0; i < listCopy.size(); i++) { Object item = listCopy.get(i); Object replacedValue = replaceAny(item, variables); if (item != replacedValue) { listCopy.set(i, replacedValue); replacedAny = true;//from w w w. j a va2s . c o m } } if (replacedAny) { return listCopy; } else { return list; } }
From source file:net.sf.jabref.sql.SQLUtil.java
/** * @param allFields All existent fields for a given entry type * @param reqFields list containing required fields for an entry type * @param optFields list containing optional fields for an entry type * @param utiFields list containing utility fields for an entry type * @param origList original list with the correct size filled with the default values for each field * @return origList changing the values of the fields that appear on reqFields, optFields, utiFields set to 'req', * 'opt' and 'uti' respectively/* ww w . j av a 2 s . c om*/ */ public static List<String> setFieldRequirement(List<String> allFields, List<String> reqFields, List<String> optFields, List<String> utiFields, List<String> origList) { String currentField; for (int i = 0; i < allFields.size(); i++) { currentField = allFields.get(i); if (reqFields.contains(currentField)) { origList.set(i, "req"); } else if (optFields.contains(currentField)) { origList.set(i, "opt"); } else if (utiFields.contains(currentField)) { origList.set(i, "uti"); } } return origList; }
From source file:Main.java
private static <T> void eqSort(List<T> list, int lo0, int hi0, Comparator<? super T> c) { int lo = lo0; int hi = hi0; if ((hi - lo) <= 3) { eqBrute(list, lo, hi, c);/*from ww w .jav a 2s .com*/ return; } /* * Pick a pivot and move it out of the way */ T e, pivot = list.get((lo + hi) / 2); list.set((lo + hi) / 2, list.get(hi)); list.set(hi, pivot); while (lo < hi) { /* * Search forward from a[lo] until an element is found that * is greater than the pivot or lo >= hi */ while (c.compare(list.get(lo), pivot) <= 0 && lo < hi) { lo++; } /* * Search backward from a[hi] until element is found that * is less than the pivot, or hi <= lo */ while (c.compare(pivot, list.get(hi)) <= 0 && lo < hi) { hi--; } /* * Swap elements a[lo] and a[hi] */ if (lo < hi) { e = list.get(lo); list.set(lo, list.get(hi)); list.set(hi, e); } } /* * Put the median in the "center" of the list */ list.set(hi0, list.get(hi)); list.set(hi, pivot); /* * Recursive calls, elements a[lo0] to a[lo-1] are less than or * equal to pivot, elements a[hi+1] to a[hi0] are greater than * pivot. */ eqSort(list, lo0, lo - 1, c); eqSort(list, hi + 1, hi0, c); }
From source file:Main.java
public static void markItemsAsPro(ListPreference listPref, String[] labels, String[] values, List<String> proItems, String proWord) { List<String> labelsList = new ArrayList<String>(Arrays.asList(labels)); List<String> valuesList = new ArrayList<String>(Arrays.asList(values)); Iterator<String> it = valuesList.iterator(); for (int i = 0; i < valuesList.size(); i++) { String value = valuesList.get(i); String label = labelsList.get(i); if (proItems.contains(value)) { labelsList.set(i, label + " " + proWord); }// w ww . j a v a2s. c om } listPref.setEntries(labelsList.toArray(new String[1])); listPref.setEntryValues(valuesList.toArray(new String[1])); }
From source file:it.incipict.tool.profiles.util.ProfilesToolUtils.java
public static List<Double> divideByScalar(final List<Double> vector, float scalar) { // Make a copy the original vector List<Double> result = new ArrayList<Double>(vector); // Divide vector elements between range of position start-end by a scalar int index = 0; for (Double v : vector) { result.set(index++, (v / scalar)); }// w ww . j av a 2s . c om return result; }
From source file:Main.java
/** * Merges two consecutive sorted lists in place. * * <p>This implementation is based on:</p> * * <p>J. Chen, "<a href="http://dx.doi.org/10.1016/j.ipl.2005.11.018">A * simple algorithm for in-place merging</a>", Information Processing * Letters 98:34-40, 2006.</p>.//from www . jav a2s . co m * * This algorithm is a direct transcription of Fig. 3 on page 37 of this * paper, plus the two modifications indicated in the last paragraph of * Sec. 2 (page 38) to increase the efficiency using recursion and to * allow the algorithm to "work correctly when y<sub>0</sub> - x<sub>0</sub> * < 2k". * * @param A The <code>List</code> to be merged. * @param x0 The index of the start of the first sub-list. * @param y0 The index of the start of the second sub-list. * @param yn The index of the end of the second sub-list. * @param k The block size. * @param depth The recursion depth. */ private static <T extends Comparable<? super T>> void merge(List<T> A, int x0, int y0, int yn, int k, int depth) { int f = (y0 - x0) % k; int x = (f == 0) ? (y0 - 2 * k) : (y0 - k - f); if (x < x0) { x = x0; } T t = A.get(x); A.set(x, A.get(x0)); int z = x0, y = y0, b1 = x + 1, b2 = y0 - k; while ((y - z) > (2 * k)) { if (y > yn || A.get(x).compareTo(A.get(y)) <= 0) { A.set(z, A.get(x)); A.set(x, A.get(b1)); x++; if (((x - x0) % k) == f) { if (z < (x - k)) { b2 = x - k; } x = findNextXBlock(A, x0, z, y, k, f, b1, b2); } } else { A.set(z, A.get(y)); A.set(y, A.get(b1)); y++; if (((y - y0) % k) == 0) { b2 = y - k; } } z++; A.set(b1, A.get(z)); if (z == x) { x = b1; } if (z == b2) { b2 = -1; } b1++; if (((b1 - x0) % k) == f) { if (b2 == -1) { b1 -= k; } else { b1 = b2; } } } A.set(z, t); if (depth > 0) { mergeBandY(A, z, y, yn); } else { Collections.sort(A.subList(z, y)); merge(A, z, y, yn, (int) Math.sqrt(k), 1); } }