/** * Creates a converter that projects the value of the argument of an object using as alias * the argument property name as defined by {@link Argument#getInkvokedPropertyName()} * @param argument An argument defined using the {@link Lambda#on(Class)} method * @return A converter that can be used as projector in the {@link Lambda#project(Object, Converter[])} method */ public static <F> Converter<F, Map.Entry<String, Object>> as(Object argument) { return new AliasedArgumentConverter<F, Object>(argument); }
public static <S> Callback<TableColumn<S,String>, TableCell<S,String>> forTableColumn() { return forTableColumn(new DefaultStringConverter()); }
/** * {@inheritDoc} */ @Override public String convert(T from) { Object converted = super.convert(from); return converted == null ? "" : converted.toString(); } }
/** * {@inheritDoc} */ public T next() { return converter.convert(iterator.next()); }
public ConstructorArgumentConverter(Class<T> clazz, Object... arguments) { for (Constructor<?> c : clazz.getConstructors()) { if (isCompatible(c, arguments)) { this.constructor = (Constructor<T>)c; break; } } if (constructor == null) throw new IntrospectionException("Unable to find a constructor of " + clazz.getName() + " compatible with the given arguments"); if (arguments != null) for (Object argument : arguments) { argumentConverters.add(new ArgumentConverter<F, Object>(argument)); } }
/** * 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)); }
/** * Converts all the object in the iterable extracting the property defined by the given argument. * 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 argument An argument defined using the {@link Lambda#on(Class)} method * @return A list containing the argument's value extracted from the object in the given iterable */ public static <F, T> List<T> extract(Object iterable, T argument) { return convert(iterable, new ArgumentConverter<F, T>(argument)); }
/** * Converts all the object in the iterable using the given {@link Converter}. * 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 converter The converter that specifies how each object in the iterable must be converted * @return An Iterator on all the objects in the given iterable converted using the given {@link Converter} */ public static <F, T> Iterator<T> convertIterator(Object iterable, Converter<F, T> converter) { return new ConverterIterator(converter, asIterator(iterable)); }
/** * Projects the objects in the given iterable by converting each of them in a set of key/value pairs. * 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 projected * @param projectors The converters that define how each object should be projected * @return A list of map where each map is the result of the projection of an object in the iterable */ public static <F> List<Map<String, Object>> project(Object iterable, Converter<F, Map.Entry<String, Object>>... projectors) { return convert(iterable, new ProjectConverter<F>(projectors)); }
public List<Integer> columnSizes() { return Lambda.convert(this.values, new StringLengthConverter()); }
public static <S> Callback<TableColumn<S,String>, TableCell<S,String>> forTableColumn() { return forTableColumn(new DefaultStringConverter()); }
/** * Indexes the objects in the given iterable based on the value of their argument. * 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 indexed * @param argument An argument defined using the {@link Lambda#on(Class)} method * @return A map having as keys the argument value extracted from the objects in the given iterable and as values the corresponding objects */ public static <F, T> Map<T, F> index(Object iterable, T argument) { return map(iterable, new ArgumentConverter<F, T>(argument)); }
/** * Creates a converter that projects the value of the argument of an object using as the given alias * @param alias The key on which the argument value is paired * @param argument An argument defined using the {@link Lambda#on(Class)} method * @return A converter that can be used as projector in the {@link Lambda#project(Object, Converter[])} method */ public static <F> Converter<F, Map.Entry<String, Object>> as(String alias, Object argument) { return new AliasedArgumentConverter<F, Object>(alias, argument); }
ObservableList<BankAccount> bankValues = FXCollections.emptyList(); accountColumn.setCellFactory(ComboBoxTableCell.forTableColumn( new DefaultStringConverter(), bankValues));
/** * Converts all the values in the map extracting the property defined by the given argument. * @param map The map containing the values to be converted * @param argument An argument defined using the {@link Lambda#on(Class)} method * @return A Map containing the same keys of the original one and the argument's value extracted from the value * in the corresponding entry of the map */ public static <K, F, T> Map<K, T> convertMap(Map<K, F> map, T argument) { return convertMap(map, new ArgumentConverter<F, T>(argument)); }
ObservableList<String> cbValues = FXCollections.observableArrayList("1", "2", "3"); TableColumn<Map, String> column2 = new TableColumn<>(Desglose2); column2.setCellFactory(ComboBoxTableCell.forTableColumn(new DefaultStringConverter(), cbValues));
/** * Converts all the object in the iterable extracting the property defined by the given argument. * Actually it handles also Maps, Arrays and Iterator by collecting their values. * Unlike the method {@link #extract(Object, Object)} this one doesn't build a new collection, and the * extraction is done only when someone iterates over the returned iterator. * 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 argument An argument defined using the {@link Lambda#on(Class)} method * @return A list containing the argument's value extracted from the object in the given iterable */ public static <F, T> Iterator<T> extractIterator(Object iterable, T argument) { return convertIterator(iterable, new ArgumentConverter<F, T>(argument)); }
tv.setEditable(true); tv.setCellFactory(new Callback<TreeView<String>, TreeCell<String>>() { private final MyContextMenu contextMenu = new MyContextMenu(); private final StringConverter converter = new DefaultStringConverter(); @Override public TreeCell<String> call(TreeView<String> param) { return new CustomTreeCell(contextMenu, converter); } });
/** * For each item in the given iterable collects the value defined by the given argument and * then aggregates them iterable using the given {@link Aggregator}. * 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 of numbers to be summed * @param aggregator The function that defines how the objects in this iterable have to be aggregated * @param argument An argument defined using the {@link Lambda#on(Class)} method * @return The result of the aggregation of all the items in the given iterable * @throws RuntimeException if the iterable is not an Iterable */ public static <T, A> T aggregate(Object iterable, Aggregator<T> aggregator, A argument) { return aggregate(convertIterator(iterable, new ArgumentConverter<T, A>(argument)), aggregator); }
/** * Converts all the object in the iterable in its String representation. * 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 in strings * @return A list containing the String representation of the objects in the given iterable */ public static List<String> extractString(Object iterable) { return convert(iterable, new DefaultStringConverter()); }