Changeset 9473 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2016-01-15T22:25:06+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Utils.java
r9419 r9473 1307 1307 return null; 1308 1308 } else { 1309 final List<String> lines = Arrays.asList(s.split("\\n")); 1310 if (lines.size() > maxLines) { 1311 return join("\n", lines.subList(0, maxLines - 1)) + "\n..."; 1309 return join("\n", limit(Arrays.asList(s.split("\\n")), maxLines, "...")); 1310 } 1311 } 1312 1313 /** 1314 * If the collection {@code elements} is larger than {@code maxElements} elements, 1315 * the collection is shortened and the {@code overflowIndicator} is appended. 1316 * @param elements collection to shorten 1317 * @param maxElements maximum number of elements to keep (including including the {@code overflowIndicator}) 1318 * @param overflowIndicator the element used to indicate that the collection has been shortened 1319 * @return the shortened collection 1320 */ 1321 public static <T> Collection<T> limit(Collection<T> elements, int maxElements, T overflowIndicator) { 1322 if (elements == null) { 1323 return null; 1324 } else { 1325 if (elements.size() > maxElements) { 1326 final Collection<T> r = new ArrayList<>(maxElements); 1327 final Iterator<T> it = elements.iterator(); 1328 while (r.size() < maxElements - 1) { 1329 r.add(it.next()); 1330 } 1331 r.add(overflowIndicator); 1332 return r; 1312 1333 } else { 1313 return s;1334 return elements; 1314 1335 } 1315 1336 }
Note:
See TracChangeset
for help on using the changeset viewer.