List of usage examples for java.util List set
E set(int index, E element);
From source file:com.amalto.workbench.utils.FKFilterParser.java
private static List<Line> buildLine(String criteria, String[] keyNames) { List<Line> lines = new ArrayList<Line>(); if (criteria != null) { String[] criterias = criteria.split(endSeparator); for (String cria : criterias) { String[] values = cria.split("\\$\\$");//$NON-NLS-1$ List<String> list = new ArrayList<String>(); list.addAll(Arrays.asList(values)); int num = 4 - list.size(); for (int i = 0; i < num; i++) { list.add("");//$NON-NLS-1$ }// w w w. ja va 2s . co m // filter value if (list.get(2) != null && list.get(2).length() > 0) { String value = list.get(2); value = value.replaceAll(quot, "\"");//$NON-NLS-1$ list.set(2, value); } List<KeyValue> keyValues = buildKeyValue(keyNames, list.toArray(new String[list.size()])); Line line = new Line(keyValues); lines.add(line); } } return lines; }
From source file:gobblin.instrumented.Instrumented.java
/** * Generates a new {@link gobblin.metrics.MetricContext} with the parent and tags taken from the reference context. * Allows replacing {@link gobblin.metrics.Tag} with new input tags. * This method will not copy any {@link gobblin.metrics.Metric} contained in the reference {@link gobblin.metrics.MetricContext}. * * @param context Reference {@link gobblin.metrics.MetricContext}. * @param newTags New {@link gobblin.metrics.Tag} to apply to context. Repeated keys will override old tags. * @param name Name of the new {@link gobblin.metrics.MetricContext}. * If absent or empty, will modify old name by adding a random integer at the end. * @return Generated {@link gobblin.metrics.MetricContext}. *///from w ww . j a va 2s. co m public static MetricContext newContextFromReferenceContext(MetricContext context, List<Tag<?>> newTags, Optional<String> name) { String newName = name.orNull(); if (Strings.isNullOrEmpty(newName)) { UUID uuid = UUID.randomUUID(); String randomIdPrefix = "uuid:"; String oldName = context.getName(); List<String> splitName = Strings.isNullOrEmpty(oldName) ? Lists.<String>newArrayList() : Lists.newArrayList(Splitter.on(".").splitToList(oldName)); if (splitName.size() > 0 && StringUtils.startsWith(Iterables.getLast(splitName), randomIdPrefix)) { splitName.set(splitName.size() - 1, String.format("%s%s", randomIdPrefix, uuid.toString())); } else { splitName.add(String.format("%s%s", randomIdPrefix, uuid.toString())); } newName = Joiner.on(".").join(splitName); } MetricContext.Builder builder = context.getParent().isPresent() ? context.getParent().get().childBuilder(newName) : MetricContext.builder(newName); return builder.addTags(context.getTags()).addTags(newTags).build(); }
From source file:ch.devmine.javaparser.utils.ParserUtils.java
public static List<String> prepareComments(String comment) { List<String> javadoc = new ArrayList<>(Arrays.asList(comment.split("\n"))); if (javadoc.get(0).trim().isEmpty()) { javadoc.remove(0);//from www. j av a2s. c o m } if (!javadoc.isEmpty() && javadoc.get(javadoc.size() - 1).trim().isEmpty()) { javadoc.remove(javadoc.size() - 1); } for (int i = 0; i < javadoc.size() - 1; i++) { String line = javadoc.get(i); line = StringUtils.stripStart(line, "\t *"); javadoc.set(i, line); if (!line.isEmpty()) { break; } else { javadoc.remove(line); i--; } } for (int j = javadoc.size() - 1; j >= 0; j--) { String line = javadoc.get(j); line = StringUtils.stripStart(line, "\t *"); javadoc.set(j, line); if (!line.isEmpty()) { break; } else { javadoc.remove(line); } } for (int k = 0; k < javadoc.size() - 1; k++) { String line = javadoc.get(k); line = StringUtils.stripStart(line, "\t *"); javadoc.set(k, line); } return javadoc; }
From source file:com.sk89q.craftbook.mech.drops.legacy.LegacyCustomDropManager.java
private static DropDefinition readDrop(String s, String prelude, boolean append) throws IOException { String[] split = RegexUtil.X_PATTERN.split(RegexUtil.PERCENT_PATTERN.split(s)[0]); if (split.length > 2) { List<String> temp = new ArrayList<String>(); for (int i = 0; i < split.length; i++) { if (temp.isEmpty()) temp.add(split[i]);// w ww . j a va2s . co m else if (i < split.length - 1) temp.set(0, temp.get(0) + "x" + split[i]); else temp.add(split[i]); } split = temp.toArray(new String[temp.size()]); } if (split.length > 2) throw new CustomDropParseException(prelude + ": too many drop item fields"); ItemStack stack = ItemUtil.makeItemValid(ItemSyntax.getItem(split[0])); String[] split3 = RegexUtil.MINUS_PATTERN.split(split[1].trim()); if (split3.length > 2) throw new CustomDropParseException(prelude + ": invalid number drops range"); int countMin = Integer.parseInt(split3[0]); int countMax = split3.length == 1 ? countMin : Integer.parseInt(split3[1]); double chance = 100; try { chance = Double.parseDouble(RegexUtil.PERCENT_PATTERN.split(s)[1]); } catch (Exception ignored) { } return new DropDefinition(stack, countMin, countMax, chance, append); }
From source file:Main.java
public static <T> List<T> sortCollection(List<T> collection, String sortCol, boolean isAsc) { for (int i = 0; i < collection.size(); i++) { for (int j = i + 1; j < collection.size(); j++) { BeanWrapper bwi = new BeanWrapperImpl(collection.get(i)); BeanWrapper bwj = new BeanWrapperImpl(collection.get(j)); int leftI = (Integer) bwi.getPropertyValue(sortCol); int leftJ = (Integer) bwj.getPropertyValue(sortCol); if (isAsc) { if (leftI > leftJ) { T obj = collection.get(j); collection.set(j, collection.get(i)); collection.set(i, obj); }//from ww w . j ava2s .c o m } else { if (leftI < leftJ) { T obj = collection.get(j); collection.set(j, collection.get(i)); collection.set(i, obj); } } } } return collection; }
From source file:com.dungnv.vfw5.base.utils.StringUtils.java
public static void trimString(List escapeObjectList, boolean isLower) { Object obj = null;/*from w w w . java 2s . c o m*/ for (int i = 0; i < escapeObjectList.size(); i++) { obj = escapeObjectList.get(i); trimString(obj, isLower); escapeObjectList.set(i, obj); } }
From source file:com.evrythng.thng.resource.model.store.Property.java
public static List<Property<?>> normalize(final List<Property<?>> denormalized) { List<Property<?>> normalized = new ArrayList<>(); Map<String, Integer> indexes = new HashMap<>(); int index = 0; for (Property<?> property : denormalized) { String key = property.getKey() + "-" + (property.getTimestamp() != null ? property.getTimestamp() : ""); if (indexes.get(key) == null) { indexes.put(key, index);/*from w w w . j ava 2s . c o m*/ normalized.add(index, property); index++; } else { normalized.set(indexes.get(key), property); } } return normalized; }
From source file:com.jroossien.boxx.util.Str.java
/** * Integrate ChatColor in multiple strings based on color codes. * This replaces codes like &a&l with al * * @param strings The strings to apply color to. * @return formatted strings//from www . j ava 2 s. co m */ public static List<String> color(List<String> strings) { for (int i = 0; i < strings.size(); i++) { strings.set(i, color(strings.get(i))); } return strings; }
From source file:com.jroossien.boxx.util.Str.java
/** * Remove all color and put regular colors as the formatting codes like &1. * * @param strings The strings to remove color from. * @return formatted strings/*from ww w . ja v a 2s . c o m*/ */ public static List<String> replaceColor(List<String> strings) { for (int i = 0; i < strings.size(); i++) { strings.set(i, replaceColor(strings.get(i))); } return strings; }
From source file:com.jroossien.boxx.util.Str.java
/** * Strips all coloring from the specified strings. * For example a string like: '&a&ltest' becomes 'test' and 'a<est' becomes 'test'. * * @param strings The strings to remove color from. * @return Strings without any colors and without any color codes. *//*w w w . j av a2 s. c o m*/ public static List<String> stripColor(List<String> strings) { for (int i = 0; i < strings.size(); i++) { strings.set(i, stripColor(strings.get(i))); } return strings; }