/** * Converts all the object in the iterable extracting the named property. * Actually it handles also Maps, Arrays and Iterator by collecting their values. * Note that this method accepts an Object in order to be used in conjunction with the {@link Lambda#forEach(Iterable)}. * @param iterable The iterable containing the objects to be converted * @param propertyName The name of the item's property on which the item must have no duplicated value * @return A list containing the property's value extracted from the object in the given iterable */ public static <F, T> List<T> extractProperty(Object iterable, String propertyName) { return convert(iterable, new PropertyExtractor<F, T>(propertyName)); }
@Override public int complete(String buffer, int cursor, List<CharSequence> candidates) { Preconditions.checkNotNull(candidates); String text = contextualBuffer(buffer, cursor); List<String> commands = Lambda.filter(StringStartsWith.startsWith(text), this.commands); if(commands.size()>0) { candidates.addAll(commands); if(candidates.size()==1) { candidates.set(0, candidates.get(0) + " "); } return candidates.isEmpty() ? -1 : 0; } else if(text.contains(" ")) { int insertion = text.lastIndexOf(" ") + 1; String tailBuffer = text.substring(insertion); List<String> files = Lambda.convert(Lambda.convert(SpashFileSystem.get().ls(this.session.getWorkingDir()).collect(), new PropertyExtractor<Object, Path>("fileName")), new DefaultStringConverter()); files = Lambda.filter(StringStartsWith.startsWith(tailBuffer), files); candidates.addAll(files); if(candidates.size()==1) { candidates.set(0, candidates.get(0) + " "); } return candidates.isEmpty() ? -1 : insertion; } return -1; }