List of usage examples for java.util List set
E set(int index, E element);
From source file:io.mesosphere.mesos.frameworks.cassandra.executor.ProdObjectFactory.java
private static void modifyCassandraEnvSh(@NotNull final Marker taskIdMarker, @NotNull final String version, @NotNull final CassandraServerConfig cassandraServerConfig) throws IOException { int jmxPort = 0; String localJmx = "yes"; boolean noJmxAuth = false; for (final TaskEnv.Entry entry : cassandraServerConfig.getTaskEnv().getVariablesList()) { if ("JMX_PORT".equals(entry.getName())) { jmxPort = Integer.parseInt(entry.getValue()); } else if ("LOCAL_JMX".equals(entry.getName())) { localJmx = entry.getValue(); } else if ("CASSANDRA_JMX_NO_AUTHENTICATION".equals(entry.getName())) { noJmxAuth = "no".equals(entry.getValue()); }/*from w ww . j a v a 2 s . c om*/ } LOGGER.info(taskIdMarker, "Building cassandra-env.sh"); // Unfortunately it is not possible to pass JMX_PORT as an environment variable to C* startup - // it is explicitly set in cassandra-env.sh final File cassandraEnvSh = new File("apache-cassandra-" + version + "/conf/cassandra-env.sh"); LOGGER.info(taskIdMarker, "Reading cassandra-env.sh"); final List<String> lines = Files.readLines(cassandraEnvSh, Charset.forName("UTF-8")); for (int i = 0; i < lines.size(); i++) { final String line = lines.get(i); if (line.startsWith("JMX_PORT=")) { lines.set(i, "JMX_PORT=" + jmxPort); } else if (line.startsWith("LOCAL_JMX=")) { lines.set(i, "LOCAL_JMX=" + localJmx); } else if (noJmxAuth) { if (line.contains("JVM_OPTS=\"$JVM_OPTS -Dcom.sun.management.jmxremote.authenticate=")) { lines.set(i, "JVM_OPTS=\"$JVM_OPTS -Dcom.sun.management.jmxremote.authenticate=false\""); } } } LOGGER.info(taskIdMarker, "Writing cassandra-env.sh"); try (PrintWriter pw = new PrintWriter(new FileWriter(cassandraEnvSh))) { for (final String line : lines) pw.println(line); } }
From source file:com.ibuildapp.romanblack.CataloguePlugin.model.ShoppingCart.java
/** * Insert passed product to cart/*from w ww. j av a2s . c o m*/ * * @param product product */ public static void insertProduct(final Product product) { List<Product> products = getProducts(); int index = products.indexOf(product); if (index == -1) { products.add(product); } else { products.set(index, new Product.Builder().setId(product.getId()).setQuantity(product.getQuantity()).build()); } SqlAdapter.insertShoppingCartContent(products); }
From source file:it.incipict.tool.profiles.util.ProfilesToolUtils.java
public static List<Double> divideByScalar(final List<Double> vector, float scalar, int start, int end) { int index = start; // 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 for (Double v : vector) { if (index <= 26) { result.set(index++, (v / scalar)); }/* w ww. j av a2 s . c om*/ } return result; }
From source file:Main.java
/** * Swaps 2 items//w w w . j a v a 2 s. c om * * @param data * @param from * @param to */ public static <T> void swapItems(final List<T> data, int from, int to) { if (from == to) return; if (!hasElements(data)) return; if (from < 0 || from >= data.size()) { throw new IllegalArgumentException("'from' must be within 0 to n-1"); } if (to < 0 || to >= data.size()) { throw new IllegalArgumentException("'to' must be within 0 to n-1"); } T temp = data.get(from); data.set(from, data.get(to)); data.set(to, temp); }
From source file:Main.java
/** * Copies all of the elements from one list into another. After the * operation, the index of each copied element in the destination list will * be identical to its index in the source list. The destination list must * be at least as long as the source list. If it is longer, the remaining * elements in the destination list are unaffected. * <p>/* www .j ava 2 s. c o m*/ * This method runs in linear time. * @param <T> . * @param dest The destination list. * @param src The source list. * * @return boolean isCopyValide */ public static <T> Boolean copy(List<? super T> dest, List<? extends T> src) { Boolean isCopyValide = null; int srcSize = src.size(); if (srcSize > dest.size()) { isCopyValide = false; throw new IndexOutOfBoundsException("Source does not fit in dest"); } if (srcSize < COPY_THRESHOLD || (src instanceof RandomAccess && dest instanceof RandomAccess)) { for (int i = 0; i < srcSize; i++) { dest.set(i, src.get(i)); } } else { ListIterator<? super T> di = dest.listIterator(); ListIterator<? extends T> si = src.listIterator(); for (int i = 0; i < srcSize; i++) { di.next(); di.set(si.next()); } } isCopyValide = true; return isCopyValide; }
From source file:com.fegati.utilities.CSVPreprocessor.java
private static void balanceColumnsSizeOfTheRows(List<String[]> rows, int columnSize) { for (int i = 0; i < rows.size(); i++) { String[] row = rows.get(i); int remain = columnSize - row.length; /* Replace the expended row if needed */ if (remain > 0) { rows.set(i, expendRowWithEmptyString(rows.get(i), remain)); }/* w w w . ja v a 2 s. c om*/ } }
From source file:Main.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public synchronized static void sortTwoLists(List<Integer> queryList, List secondList) { if (queryList.size() != secondList.size()) { throw new IllegalArgumentException("The lists have to be of equal size!"); }/*from w ww . j a v a 2s .c o m*/ int n = queryList.size(); for (int i = 0; i < n; i++) { for (int j = n - 1; j > i; j--) { int one = ((Number) queryList.get(j - 1)).intValue(); int two = ((Number) queryList.get(j)).intValue(); if (one > two) { queryList.set(j - 1, two); queryList.set(j, one); Object temp = secondList.get(j - 1); secondList.set(j - 1, secondList.get(j)); secondList.set(j, temp); } } } }
From source file:com.hybris.mobile.app.commerce.utils.RegexUtils.java
public static List<String> getAddToCart(String value) { List<String> productAndQty = applyPattern(ADD_TO_CART_PATTERN, value, 2); if (productAndQty != null) { if (productAndQty.size() == 1 && StringUtils.isBlank(productAndQty.get(0))) { productAndQty = null;//from w w w . j a v a 2s.com } else if (productAndQty.size() == 2 && StringUtils.isNotBlank(productAndQty.get(1))) { // First character is a / productAndQty.set(1, productAndQty.get(1).substring(1)); } } return productAndQty; }
From source file:cool.pandora.modeller.ui.handlers.common.NodeMap.java
/** * getAreaIdMap.//www .ja v a 2 s . c o m * * @param hocr hOCRData * @param pageIdList List * @return Map */ public static Map<String, List<String>> getAreaIdMap(final hOCRData hocr, final List<String> pageIdList) { final Map<String, List<String>> nodemap = new HashMap<>(); List<String> areaIdList; for (String pageId : pageIdList) { areaIdList = getAreaIdListforPage(hocr, pageId); for (int i = 0; i < areaIdList.size(); i++) { final String areaId = StringUtils.substringAfter(areaIdList.get(i), "_"); areaIdList.set(i, areaId); } pageId = StringUtils.substringAfter(pageId, "_"); nodemap.put(pageId, areaIdList); } return nodemap; }
From source file:cool.pandora.modeller.ui.handlers.common.NodeMap.java
/** * getLineIdMap./* w w w . ja v a 2s .c o m*/ * * @param hocr hOCRData * @param areaIdList List * @return Map */ public static Map<String, List<String>> getLineIdMap(final hOCRData hocr, final List<String> areaIdList) { final Map<String, List<String>> nodemap = new HashMap<>(); List<String> lineIdList; for (String areaId : areaIdList) { lineIdList = getLineIdListforArea(hocr, areaId); for (int i = 0; i < lineIdList.size(); i++) { final String lineId = StringUtils.substringAfter(lineIdList.get(i), "_"); lineIdList.set(i, lineId); } areaId = StringUtils.substringAfter(areaId, "_"); nodemap.put(areaId, lineIdList); } return nodemap; }