List of usage examples for java.util List clear
void clear();
From source file:com.exxonmobile.ace.hybris.storefront.util.MetaSanitizerUtil.java
/** * Takes a List of KeywordModels and returns a comma separated list of keywords as String. * /*from w w w .j av a2s. co m*/ * @param keywords * List of KeywordModel objects * @return String of comma separated keywords */ public static String sanitizeKeywords(final List<KeywordModel> keywords) { // Remove duplicates final List<String> keywordList = new ArrayList<String>(); for (final KeywordModel kw : keywords) { keywordList.add(kw.getKeyword()); } final Set<String> keywordSet = new HashSet<String>(keywordList); keywordList.clear(); keywordList.addAll(keywordSet); // Format keywords final StringBuilder stringBuilder = new StringBuilder(); String formattedKeywords = null; for (final String kw : keywordList) { stringBuilder.append(kw); stringBuilder.append(','); } if (stringBuilder.length() > 0) { formattedKeywords = stringBuilder.substring(0, stringBuilder.length() - 1); } return formattedKeywords; }
From source file:it.attocchi.utils.ListUtils.java
public static <T> void clear(List<T> aList) { if (aList != null) { aList.clear(); } }
From source file:org.imsglobal.lti.LTIUtil.java
public static Map<String, List<String>> setSingleParameter(Map<String, List<String>> parameters, String name, String value) {/*from w w w.j av a 2 s. c om*/ if (parameters.containsKey(name)) { //we want a list with only the provided value List<String> itemList = parameters.get(name); itemList.clear(); itemList.add(value); parameters.put(name, itemList); } else { List<String> itemList = new ArrayList<String>(); itemList.add(value); parameters.put(name, itemList); } return parameters; }
From source file:com.hubrick.raml.codegen.springweb.RestControllerClassGenerator.java
private static JExpression flushBuffer(List<String> stringBuffer) { final String str = stringBuffer.stream().collect(Collectors.joining("")); stringBuffer.clear(); return JExpr.lit(str); }
From source file:illab.nabal.util.ParameterHelper.java
/** * Sort parameters using lexicographical byte value ordering. * /* w w w . j a va 2s . c o m*/ * @param params - list of parameters to sort * @return List<NameValuePair> */ public static List<NameValuePair> sortParams(List<NameValuePair> params) { NameValuePair[] sortedParams = params.toArray(new NameValuePair[params.size()]); Arrays.sort(sortedParams, paramComparator); params.clear(); for (NameValuePair param : sortedParams) { params.add(param); } sortedParams = null; return params; }
From source file:Main.java
private static <T> void addCombination(List<List<T>> perms, List<Collection<T>> domains, int i) { if (i < domains.size()) { for (int permIndex = 0; permIndex < perms.size();) { List<T> perm = perms.get(permIndex); perms.remove(permIndex);/*from w ww. j a v a2 s. c o m*/ if (domains.get(i).isEmpty()) { perms.clear(); return; } for (T domValue : domains.get(i)) { List<T> newPerm = new ArrayList<T>(perm); newPerm.add(domValue); perms.add(permIndex++, newPerm); } } addCombination(perms, domains, i + 1); } }
From source file:com.xpn.xwiki.internal.merge.MergeUtils.java
/** * Merge a {@link List}./* www .j a va 2 s . c o m*/ * * @param <T> the type of the lists elements * @param commonAncestor previous version of the collection * @param next new version of the collection * @param current current version of the collection to modify * @param mergeResult the merge report */ public static <T> void mergeList(List<T> commonAncestor, List<T> next, List<T> current, MergeResult mergeResult) { org.xwiki.diff.MergeResult<T> result; try { result = diffManager.merge(commonAncestor, next, current, null); current.clear(); current.addAll(result.getMerged()); } catch (MergeException e) { mergeResult.getLog().error("Failed to execute merge lists", e); } }
From source file:com.denimgroup.threadfix.util.SimilarityCalculator.java
@Nullable public static String findMostSimilarFilePath(@NotNull String filePath, @NotNull Iterable<String> candidates) { int current = 0; List<String> currentTiedPaths = list(); for (String candidate : candidates) { int score = calculateSimilarity(filePath, candidate); LOG.debug("Candidate " + candidate + " scored " + score); if (score > current) { currentTiedPaths.clear(); currentTiedPaths.add(candidate); current = score;/*w w w. j a va 2 s .c o m*/ } else if (score == current && current != 0) { currentTiedPaths.add(candidate); } } if (currentTiedPaths.size() == 0) { LOG.debug("No path found."); return null; } else if (currentTiedPaths.size() > 1) { LOG.debug("Multiple paths found: " + currentTiedPaths); LOG.debug("Returning " + currentTiedPaths.get(0)); return currentTiedPaths.get(0); } else { LOG.debug("Got single answer with score " + current); return currentTiedPaths.get(0); } }
From source file:com.google.code.guice.repository.spi.TypeUtil.java
/** * Finds and returns class of N parametrization parameter. * * @param aClass generic class//from w ww .j a va 2s . com * @param parameterIndex parameter index * * @return parameter class or {@code null} if parameter can't be found * * @throws IllegalArgumentException if specified {@code aClass} is null or {@code parameterIndex} < 0 */ public static Class getTypeParameterClass(Class aClass, int parameterIndex) { Assert.notNull(aClass); Assert.isTrue(parameterIndex >= 0); List<Type> types = new ArrayList<Type>(); // check interfaces getGenericInterfacesActualTypes(types, aClass); Class result = findAppropriateType(types, parameterIndex); if (result == null) { types.clear(); // check superclasses getGenericSuperclassActualTypes(types, aClass); } return findAppropriateType(types, parameterIndex); }
From source file:com.amalto.core.storage.hibernate.TypeMapping.java
protected static <T> void resetList(List<T> oldValues, List<T> newValues) { if (newValues == null) { if (oldValues != null) { oldValues.clear(); }// w w w. j a va2 s.com return; } Iterator<T> iterator = newValues.iterator(); for (int i = 0; iterator.hasNext(); i++) { T nextNew = iterator.next(); if (nextNew != null) { if (i < oldValues.size() && !nextNew.equals(oldValues.get(i))) { oldValues.set(i, nextNew); } else if (i >= oldValues.size()) { oldValues.add(i, nextNew); } } } while (oldValues.size() > newValues.size()) { oldValues.remove(oldValues.size() - 1); } }