diff options
author | Brian Vosburgh | 2016-07-12 22:11:12 +0000 |
---|---|---|
committer | Brian Vosburgh | 2017-05-18 22:37:46 +0000 |
commit | c06255a0b27d949afea7c27a528e2fb913908eca (patch) | |
tree | 87ee2e9199cac892d43b17f8e119a9a0667e8807 /common | |
parent | 246f11c9c3a8e9a2a55dd00f0069ed004f6da700 (diff) | |
download | webtools.dali-c06255a0b27d949afea7c27a528e2fb913908eca.tar.gz webtools.dali-c06255a0b27d949afea7c27a528e2fb913908eca.tar.xz webtools.dali-c06255a0b27d949afea7c27a528e2fb913908eca.zip |
delete Transformation PVMs
Diffstat (limited to 'common')
38 files changed, 872 insertions, 759 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTModifiedDeclaration.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTModifiedDeclaration.java index 2c8e415c3b..2d009cfc8a 100644 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTModifiedDeclaration.java +++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTModifiedDeclaration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2013 Oracle. All rights reserved. + * Copyright (c) 2006, 2016 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -130,7 +130,7 @@ public class JDTModifiedDeclaration * Return the declaration's annotations. */ protected Iterable<Annotation> getAnnotations() { - return IterableTools.downCast(this.getAnnotations_()); + return IterableTools.downcast(this.getAnnotations_()); } protected Iterable<IExtendedModifier> getAnnotations_() { diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/ClassChooserComboPane.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/ClassChooserComboPane.java index e8e14f2b08..84a9778de5 100644 --- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/ClassChooserComboPane.java +++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/ClassChooserComboPane.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2012 Oracle. All rights reserved. + * Copyright (c) 2008, 2016 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -110,14 +110,14 @@ public abstract class ClassChooserComboPane<T extends Model> extends ClassChoose protected Combo addClassCombo(Composite container) { return this.addEditableCombo( container, - this.buildClassListHolder(), - this.buildTextHolder(), + this.buildClassListModel(), + this.buildTextModel(), this.buildClassConverter(), getHelpId() ); } - protected abstract ListValueModel<String> buildClassListHolder(); + protected abstract ListValueModel<String> buildClassListModel(); protected Transformer<String, String> buildClassConverter() { return TransformerTools.objectToStringTransformer(); diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/ClassChooserPane.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/ClassChooserPane.java index 479bf8a524..bc75b0894a 100644 --- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/ClassChooserPane.java +++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/ClassChooserPane.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2013 Oracle. All rights reserved. + * Copyright (c) 2008, 2016 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -331,7 +331,7 @@ public abstract class ClassChooserPane<T extends Model> extends ChooserPane<T> @Override protected Control addMainControl(Composite container) { - Text text = addText(container, buildTextHolder(), getHelpId()); + Text text = addText(container, buildTextModel(), getHelpId()); ControlContentAssistHelper.createTextContentAssistant( text, @@ -346,7 +346,7 @@ public abstract class ClassChooserPane<T extends Model> extends ChooserPane<T> * * @return The holder of the class name */ - protected abstract ModifiablePropertyValueModel<String> buildTextHolder(); + protected abstract ModifiablePropertyValueModel<String> buildTextModel(); /** * Prompts the user the Open Type dialog. diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/IntegerCombo.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/IntegerCombo.java index 78f357f197..9bda41c06a 100644 --- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/IntegerCombo.java +++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/IntegerCombo.java @@ -13,8 +13,9 @@ import org.eclipse.jface.fieldassist.FieldDecorationRegistry; import org.eclipse.jpt.common.ui.JptCommonUiMessages; import org.eclipse.jpt.common.ui.internal.swt.widgets.ComboTools; import org.eclipse.jpt.common.utility.internal.model.value.PropertyListValueModelAdapter; -import org.eclipse.jpt.common.utility.internal.model.value.TransformationModifiablePropertyValueModel; -import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel; +import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools; +import org.eclipse.jpt.common.utility.internal.transformer.AbstractTransformer; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; import org.eclipse.jpt.common.utility.internal.transformer.TransformerTools; import org.eclipse.jpt.common.utility.model.Model; import org.eclipse.jpt.common.utility.model.value.ListValueModel; @@ -34,21 +35,15 @@ import org.eclipse.swt.widgets.Composite; public abstract class IntegerCombo<T extends Model> extends Pane<T> { - /** * The main (only) widget of this pane. */ private Combo comboBox; - - private PropertyValueModel<String> defaultValueHolder; + private PropertyValueModel<String> defaultValueModel; - // ********** constructors ********** - protected IntegerCombo( - Pane<? extends T> parentPane, - Composite parent - ) { + protected IntegerCombo(Pane<? extends T> parentPane, Composite parent) { super(parentPane, parent); } @@ -56,7 +51,7 @@ public abstract class IntegerCombo<T extends Model> Pane<? extends T> parentPane, Composite parent, PropertyValueModel<Boolean> enabledModel - ) { + ) { super(parentPane, parent, enabledModel); } @@ -77,7 +72,6 @@ public abstract class IntegerCombo<T extends Model> super(parentPane, subjectHolder, enabledModel, parent); } - // ********** initialization ********** @Override protected boolean addsComposite() { @@ -91,7 +85,7 @@ public abstract class IntegerCombo<T extends Model> @Override protected void initializeLayout(Composite container) { - this.defaultValueHolder = this.buildDefaultStringHolder(); + this.defaultValueModel = this.buildDefaultStringModel(); this.comboBox = this.addIntegerCombo(container); int margin = FieldDecorationRegistry.getDefault().getMaximumDecorationWidth(); @@ -108,11 +102,11 @@ public abstract class IntegerCombo<T extends Model> protected Combo addIntegerCombo(Composite container) { return this.addEditableCombo( container, - buildDefaultListHolder(), - buildSelectedItemStringHolder(), + buildDefaultListModel(), + buildSelectedItemStringModel(), TransformerTools.<String>objectToStringTransformer(), getHelpId() - ); + ); } @@ -124,79 +118,79 @@ public abstract class IntegerCombo<T extends Model> }; } - protected ListValueModel<String> buildDefaultListHolder() { - return new PropertyListValueModelAdapter<String>(this.defaultValueHolder); + protected ListValueModel<String> buildDefaultListModel() { + return new PropertyListValueModelAdapter<>(this.defaultValueModel); } - private PropertyValueModel<String> buildDefaultStringHolder() { - return new TransformationPropertyValueModel<Integer, String>(buildDefaultHolder()) { - @Override - protected String transform(Integer value) { - if (value == null) { - return JptCommonUiMessages.NONE_SELECTED; - } - return super.transform(value); - } - @Override - protected String transform_(Integer value) { - return getDefaultValueString(value); - } - }; + private PropertyValueModel<String> buildDefaultStringModel() { + return PropertyValueModelTools.transform_(this.buildDefaultModel(), new DefaultStringTransformer()); + } + + class DefaultStringTransformer + extends TransformerAdapter<Integer, String> + { + @Override + public String transform(Integer integer) { + return (integer == null) ? JptCommonUiMessages.NONE_SELECTED : IntegerCombo.this.getDefaultValueString(integer); + } } - private String getDefaultValueString(Integer defaultValue) { - return NLS.bind( - JptCommonUiMessages.DEFAULT_WITH_ONE_PARAM, - defaultValue - ); + /* CU private */ String getDefaultValueString(Integer defaultValue) { + return NLS.bind(JptCommonUiMessages.DEFAULT_WITH_ONE_PARAM, defaultValue); } /* CU private */ String getDefaultValueString() { - return this.defaultValueHolder.getValue(); + return this.defaultValueModel.getValue(); } - protected ModifiablePropertyValueModel<String> buildSelectedItemStringHolder() { - return new TransformationModifiablePropertyValueModel<Integer, String>(buildSelectedItemHolder()) { - @Override - protected String transform(Integer v) { - return (v == null) ? getDefaultValueString() : v.toString(); - } - - @Override - protected Integer transformSetValue_(String v) { - try { - return Integer.valueOf(v); - } catch (NumberFormatException ex) { - // if the default is selected from the combo, set length to null - return null; - } + protected ModifiablePropertyValueModel<String> buildSelectedItemStringModel() { + return PropertyValueModelTools.transform_(this.buildSelectedItemModel(), new SelectedItemStringModelGetTransformer(), new SelectedItemStringModelSetTransformer()); + } + + public class SelectedItemStringModelGetTransformer + extends TransformerAdapter<Integer, String> + { + @Override + public String transform(Integer integer) { + return (integer == null) ? IntegerCombo.this.getDefaultValueString() : integer.toString(); + } + } + + public class SelectedItemStringModelSetTransformer + extends AbstractTransformer<String, Integer> + { + @Override + protected Integer transform_(String string) { + try { + return Integer.valueOf(string); + } catch (NumberFormatException ex) { + // if the default is selected from the combo, set length to null + return null; } - }; + } } // ********** abstract methods ********** protected abstract String getHelpId(); - protected abstract PropertyValueModel<Integer> buildDefaultHolder(); + protected abstract PropertyValueModel<Integer> buildDefaultModel(); - protected abstract ModifiablePropertyValueModel<Integer> buildSelectedItemHolder(); + protected abstract ModifiablePropertyValueModel<Integer> buildSelectedItemModel(); // ********** combo-box verify listener callback ********** protected void verifyComboBox(VerifyEvent e) { if (e.character == '\b') { - //ignore backspace - return; + return; // ignore backspace } - if (e.text.equals("") //DefaultValueHandler sets the text to "" //$NON-NLS-1$ - || e.text.equals(this.defaultValueHolder.getValue())) { + if (e.text.equals("") // DefaultValueHandler sets the text to "" //$NON-NLS-1$ + || e.text.equals(this.defaultValueModel.getValue())) { return; } try { Integer.parseInt(e.text); - } - catch (NumberFormatException exception) { + } catch (NumberFormatException ex) { e.doit = false; } } diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Pane.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Pane.java index ce0a8067dd..33fdf4af61 100644 --- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Pane.java +++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Pane.java @@ -30,7 +30,6 @@ import org.eclipse.jpt.common.ui.internal.swt.listeners.SWTListenerTools; import org.eclipse.jpt.common.utility.internal.model.value.CollectionValueModelTools; import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools; import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel; import org.eclipse.jpt.common.utility.internal.transformer.TransformerTools; import org.eclipse.jpt.common.utility.model.Model; import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent; @@ -301,7 +300,7 @@ public abstract class Pane<T extends Model> { * <em>enabled</em> state always matching that of its parent pane. */ private static PropertyValueModel<Boolean> buildDefaultEnabledModel() { - return new StaticPropertyValueModel<Boolean>(Boolean.TRUE); + return PropertyValueModelTools.staticPropertyValueModel(Boolean.TRUE); } /** diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ArrayTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ArrayTools.java index 6989099862..dee8dce1cb 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ArrayTools.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ArrayTools.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2015 Oracle. All rights reserved. + * Copyright (c) 2005, 2016 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -24,6 +24,7 @@ import org.eclipse.jpt.common.utility.internal.collection.CollectionTools; import org.eclipse.jpt.common.utility.internal.collection.ListTools; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; import org.eclipse.jpt.common.utility.internal.iterator.IteratorTools; +import org.eclipse.jpt.common.utility.internal.predicate.PredicateTools; import org.eclipse.jpt.common.utility.predicate.Predicate; import org.eclipse.jpt.common.utility.transformer.Transformer; @@ -3142,17 +3143,33 @@ public final class ArrayTools { // ********** filter ********** /** + * Return a new array with the elements of the specified array + * that are instances of the specified class. + */ + public static <E> E[] filter(Object[] array, Class<E> clazz) { + int length = array.length; + E[] result = newInstance(clazz, length); + return filter(array, PredicateTools.instanceOf(clazz), result, length); + } + + /** * Return a new array with the filtered * elements of the specified array. */ public static <E> E[] filter(E[] array, Predicate<E> filter) { int length = array.length; E[] result = newInstance(array, length); + return filter(array, filter, result, length); + } + + private static <E1, E2> E2[] filter(E1[] array, Predicate<E1> filter, E2[] result, int length) { int resultLength = 0; for (int i = 0; i < length; i++) { - E e = array[i]; + E1 e = array[i]; if (filter.evaluate(e)) { - result[resultLength++] = e; + @SuppressWarnings("unchecked") + E2 e2 = (E2) e; + result[resultLength++] = e2; } } return (resultLength < length) ? subArray(result, 0, resultLength) : result; diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/CollectionTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/CollectionTools.java index 43842a2cf1..cf4f859362 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/CollectionTools.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/CollectionTools.java @@ -22,6 +22,7 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; import org.eclipse.jpt.common.utility.collection.Bag; +import org.eclipse.jpt.common.utility.internal.predicate.PredicateTools; import org.eclipse.jpt.common.utility.predicate.Predicate; import org.eclipse.jpt.common.utility.transformer.Transformer; @@ -149,6 +150,15 @@ public final class CollectionTools { // ********** filter ********** /** + * Return a new collection with the elements of the specified collection + * that are instances of the specified class. + */ + @SuppressWarnings("unchecked") + public static <E> HashBag<E> filter(Collection<?> collection, Class<E> clazz) { + return (HashBag<E>) filter(collection, PredicateTools.instanceOf(clazz)); + } + + /** * Return a new collection with the filtered * elements of the specified collection. */ diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/ListTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/ListTools.java index 708ab9dbb4..b352fbb35f 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/ListTools.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/ListTools.java @@ -26,6 +26,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import org.eclipse.jpt.common.utility.internal.Range; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; import org.eclipse.jpt.common.utility.internal.iterator.IteratorTools; +import org.eclipse.jpt.common.utility.internal.predicate.PredicateTools; import org.eclipse.jpt.common.utility.iterable.ListIterable; import org.eclipse.jpt.common.utility.predicate.Predicate; import org.eclipse.jpt.common.utility.transformer.Transformer; @@ -171,12 +172,21 @@ public final class ListTools { // ********** filter ********** /** + * Return a new list with the elements of the specified collection + * that are instances of the specified class. + */ + @SuppressWarnings("unchecked") + public static <E> ArrayList<E> filter(Collection<?> collection, Class<E> clazz) { + return (ArrayList<E>) filter(collection, PredicateTools.instanceOf(clazz)); + } + + /** * Return a new list with the filtered - * elements of the specified list. + * elements of the specified collection. */ - public static <E> ArrayList<E> filter(Collection<? extends E> list, Predicate<? super E> predicate) { - ArrayList<E> result = new ArrayList<>(list.size()); - for (E each : list) { + public static <E> ArrayList<E> filter(Collection<? extends E> collection, Predicate<? super E> predicate) { + ArrayList<E> result = new ArrayList<>(collection.size()); + for (E each : collection) { if (predicate.evaluate(each)) { result.add(each); } diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/MapTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/MapTools.java index 2c56c345fd..9231591c38 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/MapTools.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/MapTools.java @@ -20,6 +20,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import org.eclipse.jpt.common.utility.factory.Factory; import org.eclipse.jpt.common.utility.internal.ClassTools; import org.eclipse.jpt.common.utility.internal.ObjectTools; +import org.eclipse.jpt.common.utility.internal.predicate.PredicateTools; import org.eclipse.jpt.common.utility.predicate.Predicate; import org.eclipse.jpt.common.utility.transformer.Transformer; @@ -508,6 +509,15 @@ public final class MapTools { // ********** filter ********** /** + * Return a new map with the values of the specified map + * that are instances of the specified class. + */ + @SuppressWarnings("unchecked") + public static <K, V> HashMap<K, V> filter(Map<? extends K, ?> map, Class<V> clazz) { + return (HashMap<K, V>) filter(map, PredicateTools.instanceOf(clazz)); + } + + /** * Return a new map with the filtered * values of the specified map. */ diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/IterableTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/IterableTools.java index 795335b859..a586c287a5 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/IterableTools.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/IterableTools.java @@ -526,7 +526,7 @@ public final class IterableTools { * Return an iterable that converts the specified iterable's element type.
* @see SubIterableWrapper
*/
- public static <E1, E2 extends E1> Iterable<E2> downCast(Iterable<E1> iterable) {
+ public static <E1, E2 extends E1> Iterable<E2> downcast(Iterable<E1> iterable) {
return new SubIterableWrapper<>(iterable);
}
@@ -534,7 +534,7 @@ public final class IterableTools { * Return an iterable that converts the specified iterable's element type.
* @see SubListIterableWrapper
*/
- public static <E1, E2 extends E1> ListIterable<E2> downCast(ListIterable<E1> iterable) {
+ public static <E1, E2 extends E1> ListIterable<E2> downcast(ListIterable<E1> iterable) {
return new SubListIterableWrapper<>(iterable);
}
@@ -542,7 +542,7 @@ public final class IterableTools { * Return an iterable that converts the specified iterable's element type.
* @see SuperIterableWrapper
*/
- public static <E> Iterable<E> upCast(Iterable<? extends E> iterable) {
+ public static <E> Iterable<E> upcast(Iterable<? extends E> iterable) {
return new SuperIterableWrapper<>(iterable);
}
@@ -550,7 +550,7 @@ public final class IterableTools { * Return an iterable that converts the specified iterable's element type.
* @see SuperListIterableWrapper
*/
- public static <E> ListIterable<E> upCast(ListIterable<? extends E> iterable) {
+ public static <E> ListIterable<E> upcast(ListIterable<? extends E> iterable) {
return new SuperListIterableWrapper<>(iterable);
}
@@ -842,6 +842,17 @@ public final class IterableTools { }
/**
+ * Return an iterable that will filter the specified iterable to return only the
+ * elements that are instances of the specified class.
+ * @see PredicateTools#instanceOf(Class)
+ * @see #filter(Iterable, Predicate)
+ * @see #downcast(Iterable)
+ */
+ public static <E> Iterable<E> filter(Iterable<?> iterable, Class<E> clazz) {
+ return cast(filter(iterable, PredicateTools.instanceOf(clazz)));
+ }
+
+ /**
* Return an iterable that will use the specified predicate to filter the
* elements in the specified iterable.
* @see FilteringIterable
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/IteratorTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/IteratorTools.java index e00c34d916..e9a020cb9a 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/IteratorTools.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/IteratorTools.java @@ -676,7 +676,7 @@ public final class IteratorTools { * Return an iterator that converts the specified iterator's element type.
* @see SubIteratorWrapper
*/
- public static <E1, E2 extends E1> Iterator<E2> downCast(Iterator<E1> iterator) {
+ public static <E1, E2 extends E1> Iterator<E2> downcast(Iterator<E1> iterator) {
if (isEmpty(iterator)) {
return emptyIterator();
}
@@ -687,7 +687,7 @@ public final class IteratorTools { * Return an iterator that converts the specified iterator's element type.
* @see SubListIteratorWrapper
*/
- public static <E1, E2 extends E1> ListIterator<E2> downCast(ListIterator<E1> iterator) {
+ public static <E1, E2 extends E1> ListIterator<E2> downcast(ListIterator<E1> iterator) {
if (isEmpty(iterator)) {
return emptyListIterator();
}
@@ -698,7 +698,7 @@ public final class IteratorTools { * Return an iterator that converts the specified iterator's element type.
* @see SuperIteratorWrapper
*/
- public static <E> Iterator<E> upCast(Iterator<? extends E> iterator) {
+ public static <E> Iterator<E> upcast(Iterator<? extends E> iterator) {
if (isEmpty(iterator)) {
return emptyIterator();
}
@@ -709,7 +709,7 @@ public final class IteratorTools { * Return an iterator that converts the specified iterator's element type.
* @see SuperListIteratorWrapper
*/
- public static <E> ListIterator<E> upCast(ListIterator<? extends E> iterator) {
+ public static <E> ListIterator<E> upcast(ListIterator<? extends E> iterator) {
if (isEmpty(iterator)) {
return emptyListIterator();
}
@@ -1016,6 +1016,17 @@ public final class IteratorTools { }
/**
+ * Return an iterator that will filter the specified iterator to return only the
+ * elements that are instances of the specified class.
+ * @see PredicateTools#instanceOf(Class)
+ * @see #filter(Iterator, Predicate)
+ * @see #downcast(Iterator)
+ */
+ public static <E> Iterator<E> filter(Iterator<?> iterator, Class<E> clazz) {
+ return cast(filter(iterator, PredicateTools.instanceOf(clazz)));
+ }
+
+ /**
* Return an iterator that will use the specified predicate to filter the
* elements in the specified iterator.
* @see FilteringIterator
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectAdapter.java index 0fcf3c756b..4a819838c6 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectAdapter.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectAdapter.java @@ -10,7 +10,6 @@ package org.eclipse.jpt.common.utility.internal.model.value; import java.util.EventListener; - import org.eclipse.jpt.common.utility.exception.ExceptionHandler; import org.eclipse.jpt.common.utility.internal.exception.DefaultExceptionHandler; import org.eclipse.jpt.common.utility.internal.model.AbstractModel; @@ -67,7 +66,7 @@ public abstract class AspectAdapter<S, A> * Construct an aspect adapter for the specified subject. */ protected AspectAdapter(S subject) { - this(new StaticPropertyValueModel<S>(subject)); + this(PropertyValueModelTools.staticPropertyValueModel(subject)); } /** @@ -174,11 +173,11 @@ public abstract class AspectAdapter<S, A> * Called by {@link LocalChangeSupport} */ protected void engageModels() { - this.engageSubjectHolder(); + this.engageSubjectModel(); this.engageSubject(); } - protected void engageSubjectHolder() { + protected void engageSubjectModel() { this.subjectModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.subjectListener); // sync our subject *after* we start listening to the subject holder, // since its value might change when a listener is added @@ -202,7 +201,7 @@ public abstract class AspectAdapter<S, A> */ protected void disengageModels() { this.disengageSubject(); - this.disengageSubjectHolder(); + this.disengageSubjectModel(); } protected void disengageSubject() { @@ -217,7 +216,7 @@ public abstract class AspectAdapter<S, A> */ protected abstract void disengageSubject_(); - protected void disengageSubjectHolder() { + protected void disengageSubjectModel() { this.subjectModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.subjectListener); // clear out the subject when we are not listening to its holder this.subject = null; diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionAspectAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionAspectAdapter.java index e51fb65268..b2cc71f53f 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionAspectAdapter.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionAspectAdapter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 Oracle. All rights reserved. + * Copyright (c) 2007, 2016 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -65,7 +65,7 @@ public abstract class CollectionAspectAdapter<S extends Model, E> * and collection aspects. */ protected CollectionAspectAdapter(String[] aspectNames, S subject) { - this(new StaticPropertyValueModel<S>(subject), aspectNames); + this(PropertyValueModelTools.staticPropertyValueModel(subject), aspectNames); } /** diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListAspectAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListAspectAdapter.java index 5571772a22..ee0eb4dfeb 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListAspectAdapter.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListAspectAdapter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 Oracle. All rights reserved. + * Copyright (c) 2007, 2016 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -69,7 +69,7 @@ public abstract class ListAspectAdapter<S extends Model, E> * and list aspects. */ protected ListAspectAdapter(String[] aspectNames, S subject) { - this(new StaticPropertyValueModel<S>(subject), aspectNames); + this(PropertyValueModelTools.staticPropertyValueModel(subject), aspectNames); } /** diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCurator.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCurator.java index ca377922c1..e2cbfb9321 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCurator.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCurator.java @@ -50,7 +50,7 @@ public abstract class ListCurator<S extends Model, E> * Construct a curator for the specified subject.
*/
protected ListCurator(S subject) {
- this(new StaticPropertyValueModel<S>(subject));
+ this(PropertyValueModelTools.staticPropertyValueModel(subject));
}
/**
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyAspectAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyAspectAdapter.java index 8048cd4712..f7a77a3758 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyAspectAdapter.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyAspectAdapter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 Oracle. All rights reserved. + * Copyright (c) 2007, 2016 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -58,7 +58,7 @@ public abstract class PropertyAspectAdapter<S extends Model, V> * and property aspects. */ protected PropertyAspectAdapter(String[] aspectNames, S subject) { - this(new StaticPropertyValueModel<S>(subject), aspectNames); + this(PropertyValueModelTools.staticPropertyValueModel(subject), aspectNames); } /** @@ -86,8 +86,7 @@ public abstract class PropertyAspectAdapter<S extends Model, V> * Construct a property aspect adapter for an "unchanging" property aspect in * the specified subject. This is useful for a property aspect that does not * change for a particular subject; but the subject will change, resulting in - * a new property. (A {@link TransformationPropertyValueModel} could also be - * used in this situation.) + * a new property. */ protected PropertyAspectAdapter(PropertyValueModel<? extends S> subjectModel) { this(subjectModel, EMPTY_ASPECT_NAMES); diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyValueModelTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyValueModelTools.java index b20ea89f87..058294e03c 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyValueModelTools.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyValueModelTools.java @@ -29,6 +29,8 @@ public final class PropertyValueModelTools { * Construct a property value model adapter for the specified * property value model that returns whether the property's value * is <code>null</code>. + * + * @see #valueIsNotNull(PropertyValueModel) */ public static PropertyValueModel<Boolean> valueIsNull(PropertyValueModel<?> propertyModel) { return valueIsInSet_(propertyModel, PredicateTools.isNull()); @@ -38,6 +40,8 @@ public final class PropertyValueModelTools { * Construct a property value model adapter for the specified * property value model that returns whether the property's value * is <em>not</em> <code>null</code>. + * + * @see #valueIsNull(PropertyValueModel) */ public static PropertyValueModel<Boolean> valueIsNotNull(PropertyValueModel<?> propertyModel) { return valueIsInSet_(propertyModel, PredicateTools.isNotNull()); @@ -47,6 +51,13 @@ public final class PropertyValueModelTools { * Construct a property value model adapter for the specified * property value model that returns whether the property's value * equals the specified value. + * <p> + * <strong>NB:</strong> If specified model's value is <code>null</code>, + * the returned model's value will be <em>true</em> if the specified value is + * also <code>null</code>. + * + * @see #valueNotEquals(PropertyValueModel, Object) + * @see #valueEquals_(PropertyValueModel, Object) */ public static PropertyValueModel<Boolean> valueEquals(PropertyValueModel<?> propertyModel, Object value) { return valueIsInSet_(propertyModel, PredicateTools.isEqual(value)); @@ -55,7 +66,30 @@ public final class PropertyValueModelTools { /** * Construct a property value model adapter for the specified * property value model that returns whether the property's value + * equals the specified value. + * <p> + * <strong>NB:</strong> If specified model's value is <code>null</code>, + * the returned model's value will also be a <code>null</code> + * {@link Boolean}. + * + * @see #valueNotEquals_(PropertyValueModel, Object) + * @see #valueEquals(PropertyValueModel, Object) + */ + public static PropertyValueModel<Boolean> valueEquals_(PropertyValueModel<?> propertyModel, Object value) { + return valueIsInSet(propertyModel, PredicateTools.isEqual(value)); + } + + /** + * Construct a property value model adapter for the specified + * property value model that returns whether the property's value * does <em>not</em> equal the specified value. + * <p> + * <strong>NB:</strong> If specified model's value is <code>null</code>, + * the returned model's value will be <em>false</em> if the specified value is + * also <code>null</code>. + * + * @see #valueNotEquals_(PropertyValueModel, Object) + * @see #valueEquals(PropertyValueModel, Object) */ public static PropertyValueModel<Boolean> valueNotEquals(PropertyValueModel<?> propertyModel, Object value) { return valueIsInSet_(propertyModel, PredicateTools.isNotEqual(value)); @@ -64,7 +98,30 @@ public final class PropertyValueModelTools { /** * Construct a property value model adapter for the specified * property value model that returns whether the property's value + * does <em>not</em> equal the specified value. + * <p> + * <strong>NB:</strong> If specified model's value is <code>null</code>, + * the returned model's value will also be a <code>null</code> + * {@link Boolean}. + * + * @see #valueNotEquals(PropertyValueModel, Object) + * @see #valueEquals_(PropertyValueModel, Object) + */ + public static PropertyValueModel<Boolean> valueNotEquals_(PropertyValueModel<?> propertyModel, Object value) { + return valueIsInSet_(propertyModel, PredicateTools.isNotEqual(value)); + } + + /** + * Construct a property value model adapter for the specified + * property value model that returns whether the property's value * is <em>identical</em> to the specified value. + * <p> + * <strong>NB:</strong> If specified model's value is <code>null</code>, + * the returned model's value will be <em>true</em> if the specified value is + * also <code>null</code>. + * + * @see #valueIsIdentical_(PropertyValueModel, Object) + * @see #valueIsNotIdentical(PropertyValueModel, Object) */ public static PropertyValueModel<Boolean> valueIsIdentical(PropertyValueModel<?> propertyModel, Object value) { return valueIsInSet_(propertyModel, PredicateTools.isIdentical(value)); @@ -73,7 +130,30 @@ public final class PropertyValueModelTools { /** * Construct a property value model adapter for the specified * property value model that returns whether the property's value + * is <em>identical</em> to the specified value. + * <p> + * <strong>NB:</strong> If specified model's value is <code>null</code>, + * the returned model's value will also be a <code>null</code> + * {@link Boolean}. + * + * @see #valueIsIdentical(PropertyValueModel, Object) + * @see #valueIsNotIdentical_(PropertyValueModel, Object) + */ + public static PropertyValueModel<Boolean> valueIsIdentical_(PropertyValueModel<?> propertyModel, Object value) { + return valueIsInSet(propertyModel, PredicateTools.isIdentical(value)); + } + + /** + * Construct a property value model adapter for the specified + * property value model that returns whether the property's value * is <em>not identical</em> to the specified value. + * <p> + * <strong>NB:</strong> If specified model's value is <code>null</code>, + * the returned model's value will be <em>false</em> if the specified value is + * also <code>null</code>. + * + * @see #valueIsNotIdentical_(PropertyValueModel, Object) + * @see #valueIsIdentical(PropertyValueModel, Object) */ public static PropertyValueModel<Boolean> valueIsNotIdentical(PropertyValueModel<?> propertyModel, Object value) { return valueIsInSet_(propertyModel, PredicateTools.isNotIdentical(value)); @@ -82,13 +162,31 @@ public final class PropertyValueModelTools { /** * Construct a property value model adapter for the specified * property value model that returns whether the property's value + * is <em>not identical</em> to the specified value. + * <p> + * <strong>NB:</strong> If specified model's value is <code>null</code>, + * the returned model's value will also be a <code>null</code> + * {@link Boolean}. + * + * @see #valueIsNotIdentical(PropertyValueModel, Object) + * @see #valueIsIdentical_(PropertyValueModel, Object) + */ + public static PropertyValueModel<Boolean> valueIsNotIdentical_(PropertyValueModel<?> propertyModel, Object value) { + return valueIsInSet(propertyModel, PredicateTools.isNotIdentical(value)); + } + + /** + * Construct a property value model adapter for the specified + * property value model that returns whether the property's value * is in the set defined by the specified predicate. * <p> * <strong>NB:</strong> If specified model's value is <code>null</code>, * the returned model's value will also be a <code>null</code> - * {@link Boolean}; and the value will never be passed to the specified + * {@link Boolean}; and the value will <em>never</em> be passed to the specified * predicate. + * * @see #valueIsInSet_(PropertyValueModel, Predicate) + * @see #valueIsInSet(PropertyValueModel, Predicate, boolean) * @see #valueIsInSet(PropertyValueModel, Predicate, Boolean) */ public static <V> PropertyValueModel<Boolean> valueIsInSet(PropertyValueModel<? extends V> propertyModel, Predicate<? super V> predicate) { @@ -102,9 +200,28 @@ public final class PropertyValueModelTools { * <p> * <strong>NB:</strong> If specified model's value is <code>null</code>, * the returned model's value will be the specified null result; - * and the value will never be passed to the specified predicate. + * and the value will <em>never</em> be passed to the specified predicate. + * + * @see #valueIsInSet(PropertyValueModel, Predicate) + * @see #valueIsInSet_(PropertyValueModel, Predicate) + * @see #valueIsInSet(PropertyValueModel, Predicate, Boolean) + */ + public static <V> PropertyValueModel<Boolean> valueIsInSet(PropertyValueModel<? extends V> propertyModel, Predicate<? super V> predicate, boolean nullResult) { + return valueIsInSet(propertyModel, predicate, Boolean.valueOf(nullResult)); + } + + /** + * Construct a property value model adapter for the specified + * property value model that returns whether the property's value + * is in the set defined by the specified predicate. + * <p> + * <strong>NB:</strong> If specified model's value is <code>null</code>, + * the returned model's value will be the specified null result; + * and the value will <em>never</em> be passed to the specified predicate. + * * @see #valueIsInSet(PropertyValueModel, Predicate) * @see #valueIsInSet_(PropertyValueModel, Predicate) + * @see #valueIsInSet(PropertyValueModel, Predicate, boolean) */ public static <V> PropertyValueModel<Boolean> valueIsInSet(PropertyValueModel<? extends V> propertyModel, Predicate<? super V> predicate, Boolean nullResult) { return transform_(propertyModel, TransformerTools.adapt(predicate, nullResult)); @@ -117,7 +234,9 @@ public final class PropertyValueModelTools { * <p> * <strong>NB:</strong> The specified predicate must be able to * handle a <code>null</code> variable. + * * @see #valueIsInSet(PropertyValueModel, Predicate) + * @see #valueIsInSet(PropertyValueModel, Predicate, boolean) * @see #valueIsInSet(PropertyValueModel, Predicate, Boolean) */ public static <V> PropertyValueModel<Boolean> valueIsInSet_(PropertyValueModel<? extends V> propertyModel, Predicate<? super V> predicate) { @@ -128,11 +247,50 @@ public final class PropertyValueModelTools { // ********** filtering wrappers ********** /** + * Construct a property value model that filters the specified + * property value model to return the wrapped value only if it is an instance + * of the specified class. If the wrapped value is <em>not</em> an instance + * of the specified class, it will return <code>null</code>. + * <p> + * <strong>NB:</strong> If the wrapped value is <code>null</code>, + * the model returns a <code>null</code> value. + * + * @see #filter(PropertyValueModel, Class, Object) + * @see PredicateTools#instanceOf(Class) + */ + public static <V> PropertyValueModel<V> filter(PropertyValueModel<?> propertyModel, Class<V> clazz) { + return filter(propertyModel, clazz, null); + } + + /** + * Construct a property value model that filters the specified + * property value model to return the wrapped value only if it is an instance + * of the specified class. If the wrapped value is <em>not</em> an instance + * of the specified class, it will return the specified default value. + * <p> + * <strong>NB:</strong> If the wrapped value is <code>null</code>, + * the model returns the specified default value. + * + * @see #filter(PropertyValueModel, Class) + * @see PredicateTools#instanceOf(Class) + */ + public static <V> PropertyValueModel<V> filter(PropertyValueModel<?> propertyModel, Class<V> clazz, V defaultValue) { + return transform(propertyModel, TransformerTools.cast(TransformerTools.filteringTransformer(PredicateTools.instanceOf(clazz), defaultValue))); + } + + /** * Construct a property value model that wraps the specified * property value model and filters its value with the specified * filter. If the wrapped value passes the filter, * the model simply returns it; otherwise it returns <code>null</code>. + * <p> + * <strong>NB:</strong> The specified filter will <em>never</em> be passed + * a <code>null</code> variable. + * Instead, if the wrapped value is <code>null</code>, the model returns a + * <code>null</code> value. + * * @see #filter(PropertyValueModel, Predicate, Object) + * @see #filter_(PropertyValueModel, Predicate) * @see PluggablePropertyValueModel */ public static <V> PropertyValueModel<V> filter(PropertyValueModel<? extends V> propertyModel, Predicate<? super V> filter) { @@ -143,14 +301,56 @@ public final class PropertyValueModelTools { * Construct a property value model that wraps the specified * property value model and filters its value with the specified * filter. If the wrapped value passes the filter, + * the model simply returns it; otherwise it returns <code>null</code>. + * <p> + * <strong>NB:</strong> The specified filter must be able to handle + * a <code>null</code> variable. + * + * @see #filter(PropertyValueModel, Predicate) + * @see #filter_(PropertyValueModel, Predicate, Object) + * @see PluggablePropertyValueModel + */ + public static <V> PropertyValueModel<V> filter_(PropertyValueModel<? extends V> propertyModel, Predicate<? super V> filter) { + return filter_(propertyModel, filter, null); + } + + /** + * Construct a property value model that wraps the specified + * property value model and filters its value with the specified + * filter. If the wrapped value passes the filter, * the model simply returns it; otherwise it returns the specified * default value. + * <p> + * <strong>NB:</strong> The specified filter will <em>never</em> be passed + * a <code>null</code> variable. + * Instead, if the wrapped value is <code>null</code>, the model returns the specified + * default value. + * + * @see #filter(PropertyValueModel, Predicate) + * @see #filter_(PropertyValueModel, Predicate, Object) * @see PluggablePropertyValueModel */ public static <V> PropertyValueModel<V> filter(PropertyValueModel<? extends V> propertyModel, Predicate<? super V> filter, V defaultValue) { - return transform(propertyModel, TransformerTools.filteringTransformer(filter, defaultValue)); + return filter_(propertyModel, PredicateTools.nullCheck(filter), defaultValue); } + /** + * Construct a property value model that wraps the specified + * property value model and filters its value with the specified + * filter. If the wrapped value passes the filter, + * the model simply returns it; otherwise it returns the specified + * default value. + * <p> + * <strong>NB:</strong> The specified filter must be able to handle + * a <code>null</code> variable. + * + * @see #filter(PropertyValueModel, Predicate, Object) + * @see #filter_(PropertyValueModel, Predicate) + * @see PluggablePropertyValueModel + */ + public static <V> PropertyValueModel<V> filter_(PropertyValueModel<? extends V> propertyModel, Predicate<? super V> filter, V defaultValue) { + return transform(propertyModel, TransformerTools.filteringTransformer(filter, defaultValue)); + } /** * Construct a modifiable property value model that wraps the specified @@ -159,6 +359,7 @@ public final class PropertyValueModelTools { * the model simply returns it; otherwise it returns <code>null</code>. * If a new value passes the "set" filter, the model passes it to the wrapped * model; otherwise it sets the wrapped model's value to <code>null</code>. + * * @see #filterModifiable(ModifiablePropertyValueModel, Predicate, Object, Predicate, Object) * @see PluggablePropertyValueModel */ @@ -175,6 +376,7 @@ public final class PropertyValueModelTools { * If a new value passes the "set" filter, the model passes it to the wrapped * model; otherwise it sets the wrapped model's value to the specified * default "set" value. + * * @see PluggablePropertyValueModel */ public static <V> ModifiablePropertyValueModel<V> filterModifiable(ModifiablePropertyValueModel<V> propertyModel, Predicate<? super V> getFilter, V defaultGetValue, Predicate<? super V> setFilter, V defaultSetValue) { @@ -188,6 +390,7 @@ public final class PropertyValueModelTools { * Construct a property value model that wraps the specified * property value model and returns the specified null value * if the specified model's value is <code>null</code>. + * * @see PluggablePropertyValueModel */ public static <V> PropertyValueModel<V> nullCheck(PropertyValueModel<? extends V> propertyModel, V nullValue) { @@ -202,8 +405,9 @@ public final class PropertyValueModelTools { * property value model and transforms its value with the specified * transformer. * <p> - * <strong>NB:</strong> The specified transformer will never be passed a <code>null</code> input. + * <strong>NB:</strong> The specified transformer will <em>never</em> be passed a <code>null</code> input. * Instead, a <code>null</code> input will be transformed into a <code>null</code> output. + * * @see PluggablePropertyValueModel */ public static <V1, V2> PropertyValueModel<V2> transform(PropertyValueModel<? extends V1> propertyModel, Transformer<? super V1, ? extends V2> transformer) { @@ -216,6 +420,7 @@ public final class PropertyValueModelTools { * transformer. * <p> * <strong>NB:</strong> The specified transformer must be able to handle a <code>null</code> input. + * * @see PluggablePropertyValueModel */ public static <V1, V2> PropertyValueModel<V2> transform_(PropertyValueModel<? extends V1> propertyModel, Transformer<? super V1, ? extends V2> transformer) { @@ -227,8 +432,9 @@ public final class PropertyValueModelTools { * property value model and transforms its value with the specified * transformer. The specified closure is invoked when the model's value is set. * <p> - * <strong>NB:</strong> The specified transformer will never be passed a <code>null</code> input. + * <strong>NB:</strong> The specified transformer will <em>never</em> be passed a <code>null</code> input. * Instead, a <code>null</code> input will be transformed into a <code>null</code> output. + * * @see PluggablePropertyValueModel */ public static <V1, V2> ModifiablePropertyValueModel<V2> transform(PropertyValueModel<? extends V1> propertyModel, Transformer<? super V1, ? extends V2> transformer, Closure<? super V2> setValueClosure) { @@ -241,6 +447,7 @@ public final class PropertyValueModelTools { * transformer. The specified closure is invoked when the model's value is set. * <p> * <strong>NB:</strong> The specified transformer must be able to handle a <code>null</code> input. + * * @see PluggablePropertyValueModel */ public static <V1, V2> ModifiablePropertyValueModel<V2> transform_(PropertyValueModel<? extends V1> propertyModel, Transformer<? super V1, ? extends V2> transformer, Closure<? super V2> setValueClosure) { @@ -251,8 +458,9 @@ public final class PropertyValueModelTools { * Construct a pluggable property value model adapter factory for the specified * property value model and transformer. * <p> - * <strong>NB:</strong> The specified transformer will never be passed a <code>null</code> input. + * <strong>NB:</strong> The specified transformer will <em>never</em> be passed a <code>null</code> input. * Instead, a <code>null</code> input will be transformed into a <code>null</code> output. + * * @see PluggablePropertyValueModel */ public static <V1, V2> PluggablePropertyValueModel.Adapter.Factory<V2> pluggablePropertyValueModelAdapterFactory(PropertyValueModel<? extends V1> propertyModel, Transformer<? super V1, ? extends V2> transformer) { @@ -264,6 +472,7 @@ public final class PropertyValueModelTools { * property value model and transformer. * <p> * <strong>NB:</strong> The specified transformer must be able to handle a <code>null</code> input. + * * @see PluggablePropertyValueModel */ public static <V1, V2> PluggablePropertyValueModel.Adapter.Factory<V2> pluggablePropertyValueModelAdapterFactory_(PropertyValueModel<? extends V1> propertyModel, Transformer<? super V1, ? extends V2> transformer) { @@ -275,8 +484,9 @@ public final class PropertyValueModelTools { * property value model and transforms its value with the specified * transformer. * <p> - * <strong>NB:</strong> The specified transformers will never be passed a <code>null</code> input. + * <strong>NB:</strong> The specified transformers will <em>never</em> be passed a <code>null</code> input. * Instead, a <code>null</code> input will be transformed into a <code>null</code> output. + * * @see PluggablePropertyValueModel */ public static <V1, V2> ModifiablePropertyValueModel<V2> transform(ModifiablePropertyValueModel<V1> propertyModel, Transformer<? super V1, ? extends V2> getTransformer, Transformer<? super V2, ? extends V1> setTransformer) { @@ -289,6 +499,7 @@ public final class PropertyValueModelTools { * transformer. * <p> * <strong>NB:</strong> The specified transformers must be able to handle a <code>null</code> input. + * * @see PluggablePropertyValueModel */ public static <V1, V2> ModifiablePropertyValueModel<V2> transform_(ModifiablePropertyValueModel<V1> propertyModel, Transformer<? super V1, ? extends V2> getTransformer, Transformer<? super V2, ? extends V1> setTransformer) { @@ -299,8 +510,9 @@ public final class PropertyValueModelTools { * Construct a pluggable property value model adapter factory for the specified * property value model and transformer. * <p> - * <strong>NB:</strong> The specified transformers will never be passed a <code>null</code> input. + * <strong>NB:</strong> The specified transformers will <em>never</em> be passed a <code>null</code> input. * Instead, a <code>null</code> input will be transformed into a <code>null</code> output. + * * @see PluggablePropertyValueModel */ public static <V1, V2> PluggableModifiablePropertyValueModel.Adapter.Factory<V2> pluggableModifiablePropertyValueModelAdapterFactory(ModifiablePropertyValueModel<V1> propertyModel, Transformer<? super V1, ? extends V2> getTransformer, Transformer<? super V2, ? extends V1> setTransformer) { @@ -312,6 +524,7 @@ public final class PropertyValueModelTools { * property value model and transformer. * <p> * <strong>NB:</strong> The specified transformers must be able to handle a <code>null</code> input. + * * @see PluggablePropertyValueModel */ public static <V1, V2> PluggableModifiablePropertyValueModel.Adapter.Factory<V2> pluggableModifiablePropertyValueModelAdapterFactory_(ModifiablePropertyValueModel<V1> propertyModel, Transformer<? super V1, ? extends V2> getTransformer, Transformer<? super V2, ? extends V1> setTransformer) { @@ -356,6 +569,7 @@ public final class PropertyValueModelTools { /** * Construct a property value model adapter for the specified adapter factory. + * * @see PluggablePropertyValueModel */ public static <V> PropertyValueModel<V> propertyValueModel(PluggablePropertyValueModel.Adapter.Factory<V> adapterFactory) { @@ -364,6 +578,7 @@ public final class PropertyValueModelTools { /** * Construct a modifiable property value model adapter for the specified adapter factory. + * * @see PluggableModifiablePropertyValueModel */ public static <V> ModifiablePropertyValueModel<V> modifiablePropertyValueModel(PluggableModifiablePropertyValueModel.Adapter.Factory<V> adapterFactory) { @@ -380,6 +595,18 @@ public final class PropertyValueModelTools { } + // ********** factories ********** + + /** + * Construct property value model that can be used for + * returning a static value, but still allows listeners to be added. + * Listeners will <em>never</em> be notified of any changes, because there should be none. + */ + public static <V> PropertyValueModel<V> staticPropertyValueModel(V value) { + return new StaticPropertyValueModel<>(value); + } + + // ********** value transformers ********** /** @@ -387,6 +614,7 @@ public final class PropertyValueModelTools { * but first checks whether the property value model passed to it is <code>null</code>. * If the property value model is <code>null</code>, the transformer returns * <code>null</code>. + * * @see PropertyValueModel#VALUE_TRANSFORMER */ public static <V, PVM extends PropertyValueModel<? extends V>> Transformer<PVM, V> nullCheckValueTransformer() { @@ -398,6 +626,7 @@ public final class PropertyValueModelTools { * but first checks whether the property value model passed to it is <code>null</code>. * If the property value model is <code>null</code>, the transformer returns * the specified null value. + * * @see PropertyValueModel#VALUE_TRANSFORMER */ public static <V, PVM extends PropertyValueModel<? extends V>> Transformer<PVM, V> nullCheckValueTransformer(V nullValue) { @@ -408,6 +637,7 @@ public final class PropertyValueModelTools { * Return a transformer that converts a property value model to its value. * If the property value model is <code>null</code>, the transformer throws * a {@link NullPointerException}. + * * @see PropertyValueModel#VALUE_TRANSFORMER */ @SuppressWarnings("unchecked") diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/StaticPropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/StaticPropertyValueModel.java index 8803d82672..53d1d5f89a 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/StaticPropertyValueModel.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/StaticPropertyValueModel.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 Oracle. All rights reserved. + * Copyright (c) 2007, 2016 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -36,16 +36,10 @@ public class StaticPropertyValueModel<T> this.value = value; } - - // ********** PropertyValueModel implementation ********** - public T getValue() { return this.value; } - - // ********** Object overrides ********** - @Override public void toString(StringBuilder sb) { sb.append(this.value); diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationModifiablePropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationModifiablePropertyValueModel.java deleted file mode 100644 index c71654348c..0000000000 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationModifiablePropertyValueModel.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2016 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.utility.internal.model.value; - -import org.eclipse.jpt.common.utility.internal.transformer.AbstractTransformer; -import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel; -import org.eclipse.jpt.common.utility.transformer.Transformer; - -/** - * A <code>TransformationWritablePropertyValueModel</code> wraps another - * {@link ModifiablePropertyValueModel} and uses two {@link Transformer}s - * to:<ul> - * <li>transform the wrapped value before it is returned by {@link #getValue()} - * <li>"reverse-transform" the new value that comes in via - * {@link #setValue(Object)} - * </ul> - * <strong>NB:</strong> If the mapping between the wrapped values and the - * transformed values is not strictly one-to-one, the behavior of the - * transformation model may seem unpredictable; since the wrapped model's - * change events can cause the transformation model's value to change. - * For example: If the value is a string to be <em>transformed</em> to uppercase - * and <em>reverse-transformed</em> to lowercase; then mixed case values passed to - * the transformation model will be<ul> - * <li>unchanged if the transformation model has <em>no</em> listeners - * <li>changed to uppercase if the transformation model has any listeners - * ({@link #wrappedValueChanged(org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent)}) - * </ul> - * As an alternative to building two {@link Transformer}s, - * a subclass of <code>TransformationWritablePropertyValueModel</code> can - * override {@link #transform_(Object)} and {@link #transformSetValue_(Object)}; - * or, if something other than <code>null</code> should be returned when the - * wrapped value is <code>null</code> or the new value is <code>null</code>, - * override {@link #transform(Object)} and {@link #transformSetValue(Object)}. - * - * @param <V1> the type of the <em>wrapped</em> model's value - * @param <V2> the type of the model's <em>transformed</em> value - * @see Transformer - */ -public class TransformationModifiablePropertyValueModel<V1, V2> - extends TransformationPropertyValueModel<V1, V2> - implements ModifiablePropertyValueModel<V2> -{ - protected final Transformer<V2, V1> setValueTransformer; - - - // ********** constructors/initialization ********** - - /** - * Construct a writable property value model with the specified nested - * writable property value model and the default transformers. - * Use this constructor if you want to override the - * {@link #transform_(Object)} and {@link #transformSetValue_(Object)} - * (or {@link #transform(Object)} and {@link #transformSetValue(Object)}) - * methods instead of building {@link Transformer}s. - */ - public TransformationModifiablePropertyValueModel(ModifiablePropertyValueModel<V1> valueModel) { - super(valueModel); - this.setValueTransformer = this.buildReverseTransformer(); - } - - /** - * Construct a writable property value model with the specified nested - * writable property value model and transformers. - */ - public TransformationModifiablePropertyValueModel(ModifiablePropertyValueModel<V1> valueModel, Transformer<V1, V2> transformer, Transformer<V2, V1> setValueTransformer) { - super(valueModel, transformer); - if (setValueTransformer == null) { - throw new NullPointerException(); - } - this.setValueTransformer = setValueTransformer; - } - - protected Transformer<V2, V1> buildReverseTransformer() { - return new DefaultReverseTransformer(); - } - - - // ********** WritablePropertyValueModel implementation ********** - - /** - * Cache and "reverse-transform" the new value before passing it to the the - * nested value model. - * A side-effect of caching the new value is that the wrapper will - * <em>not</em> fire an event when the wrapped model fires an event when - * called from here. - * @see #wrappedValueChanged(org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent) - */ - public void setValue(V2 value) { - this.value = value; - this.getValueModel().setValue(this.transformSetValue(value)); - } - - - // ********** transformation ********** - - /** - * "Reverse-transform" the specified value and return the result. - * This is called by {@link #setValue(Object)}. - */ - protected V1 transformSetValue(V2 v) { - return this.setValueTransformer.transform(v); - } - - /** - * "Reverse-transform" the specified, non-<code>null</code>, - * value and return the result. - */ - protected V1 transformSetValue_(@SuppressWarnings("unused") V2 v) { - throw new RuntimeException("This method was not overridden."); //$NON-NLS-1$ - } - - - // ********** queries ********** - - /** - * Our constructors accept only a {@link ModifiablePropertyValueModel}{@code<V>}, - * so this cast should be safe. - */ - @SuppressWarnings("unchecked") - protected ModifiablePropertyValueModel<V1> getValueModel() { - return (ModifiablePropertyValueModel<V1>) this.valueModel; - } - - - // ********** default reverse transformer ********** - - /** - * The default reverse transformer will return <code>null</code> - * if the new value is <code>null</code>. - * If the new value is not <code>null</code>, it is reverse-transformed - * by a subclass implementation of {@link #transformSetValue_(Object)}. - */ - protected class DefaultReverseTransformer - extends AbstractTransformer<V2, V1> - { - @Override - public V1 transform_(V2 v) { - return TransformationModifiablePropertyValueModel.this.transformSetValue_(v); - } - } -} diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationPropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationPropertyValueModel.java deleted file mode 100644 index a21b0d5d02..0000000000 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationPropertyValueModel.java +++ /dev/null @@ -1,166 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2012 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.utility.internal.model.value; - -import org.eclipse.jpt.common.utility.internal.transformer.AbstractTransformer; -import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.common.utility.transformer.Transformer; - -/** - * A <code>TransformationPropertyValueModel</code> wraps another - * {@link PropertyValueModel} and uses a {@link Transformer} - * to transform the wrapped value before it is returned by {@link #getValue()}. - * <p> - * The transformed value is calculated and cached during initialization and every - * time the wrapped value changes. This can be useful when the old value - * passed in to {@link #wrappedValueChanged(org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent)} - * can no longer be "transformed" because its state is no longer valid. - * This caching can also improve time performance in some situations. - * <p> - * As an alternative to building a {@link Transformer}, - * a subclass of <code>TransformationPropertyValueModel</code> can - * either override {@link #transform_(Object)} or, - * if something other than <code>null</code> should be returned when the - * wrapped value is <code>null</code>, override {@link #transform(Object)}. - * - * @param <V1> the type of the <em>wrapped</em> model's value - * @param <V2> the type of the model's <em>transformed</em> value - * @see Transformer - */ -public class TransformationPropertyValueModel<V1, V2> - extends PropertyValueModelWrapper<V1> - implements PropertyValueModel<V2> -{ - /** - * Cache the transformed value so that during property change event - * notification we do not have to transform the old value. It is possible - * the old value is no longer be valid in the model; as a result, - * transforming it would not be valid. - */ - protected volatile V2 value; - - protected final Transformer<V1, V2> transformer; - - - // ********** constructors/initialization ********** - - /** - * Construct a property value model with the specified nested - * property value model and the default transformer. - * Use this constructor if you want to override - * {@link #transform_(Object)} or {@link #transform(Object)} - * method instead of building a {@link Transformer}. - */ - public TransformationPropertyValueModel(PropertyValueModel<? extends V1> valueModel) { - super(valueModel); - this.transformer = this.buildTransformer(); - } - - /** - * Construct a property value model with the specified nested - * property value model and transformer. Depending on the nested model, - * the transformer may be required to handle a <code>null</code> value. - */ - public TransformationPropertyValueModel(PropertyValueModel<? extends V1> valueModel, Transformer<V1, V2> transformer) { - super(valueModel); - if (transformer == null) { - throw new NullPointerException(); - } - this.transformer = transformer; - } - - protected Transformer<V1, V2> buildTransformer() { - return new DefaultTransformer(); - } - - - // ********** PropertyValueModel implementation ********** - - /** - * No need to transform the nested value, simply return the cached value, - * which is already transformed. - */ - public V2 getValue() { - return this.value; - } - - - // ********** PropertyValueModelWrapper implementation ********** - - /** - * Propagate the event with transformed values. - */ - @Override - protected void wrappedValueChanged(V1 oldValue, V1 newValue) { - V2 old = this.value; - this.firePropertyChanged(VALUE, old, this.value = this.transform(newValue)); - } - - - // ********** transformation ********** - - /** - * Transform the specified value and return the result. - */ - protected V2 transform(V1 v) { - return this.transformer.transform(v); - } - - /** - * Transform the specified, non-<code>null</code>, value and return the result. - */ - protected V2 transform_(@SuppressWarnings("unused") V1 v) { - throw new RuntimeException("This method was not overridden."); //$NON-NLS-1$ - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.value); - } - - - // ********** listeners ********** - - /** - * We have listeners, transform the nested value and cache the result. - */ - @Override - protected void engageModel() { - super.engageModel(); - this.value = this.transform(this.valueModel.getValue()); - } - - /** - * We have no more listeners, clear the cached value. - */ - @Override - protected void disengageModel() { - this.value = null; - super.disengageModel(); - } - - - // ********** default transformer ********** - - /** - * The default transformer will return <code>null</code> if the wrapped - * value is <code>null</code>. If the wrapped value is not - * <code>null</code>, it is transformed by a subclass - * implementation of {@link TransformationPropertyValueModel#transform_(Object)}. - */ - protected class DefaultTransformer - extends AbstractTransformer<V1, V2> - { - @Override - public V2 transform_(V1 v) { - return TransformationPropertyValueModel.this.transform_(v); - } - } -} diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencePropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencePropertyValueModel.java index e6b64f1e23..e9c92a1aa8 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencePropertyValueModel.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencePropertyValueModel.java @@ -15,7 +15,7 @@ import java.util.prefs.PreferenceChangeListener; import java.util.prefs.Preferences; import org.eclipse.jpt.common.utility.internal.ObjectTools; import org.eclipse.jpt.common.utility.internal.model.value.AspectAdapter; -import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel; +import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools; import org.eclipse.jpt.common.utility.internal.transformer.TransformerTools; import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel; @@ -167,7 +167,7 @@ public class PreferencePropertyValueModel<P> * the specified default value for the preference. */ public PreferencePropertyValueModel(Preferences preferences, String key, P defaultValue, Transformer<String, P> stringTransformer) { - this(new StaticPropertyValueModel<>(preferences), key, defaultValue, stringTransformer); + this(PropertyValueModelTools.staticPropertyValueModel(preferences), key, defaultValue, stringTransformer); } /** diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencesCollectionValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencesCollectionValueModel.java index 4ff7b61362..9c38afee4f 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencesCollectionValueModel.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencesCollectionValueModel.java @@ -21,7 +21,7 @@ import org.eclipse.jpt.common.utility.internal.collection.CollectionTools; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; import org.eclipse.jpt.common.utility.internal.iterable.TransformationIterable; import org.eclipse.jpt.common.utility.internal.model.value.AspectAdapter; -import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel; +import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools; import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; import org.eclipse.jpt.common.utility.model.listener.CollectionChangeListener; import org.eclipse.jpt.common.utility.model.value.CollectionValueModel; @@ -52,7 +52,7 @@ public class PreferencesCollectionValueModel<P> * Construct an adapter for the specified preferences node. */ public PreferencesCollectionValueModel(Preferences preferences, Adapter<P> adapter) { - this(new StaticPropertyValueModel<>(preferences), adapter); + this(PropertyValueModelTools.staticPropertyValueModel(preferences), adapter); } /** diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/swing/TreeModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/swing/TreeModelAdapter.java index 786763f3d1..c8d4c2443a 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/swing/TreeModelAdapter.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/swing/TreeModelAdapter.java @@ -12,15 +12,13 @@ package org.eclipse.jpt.common.utility.internal.model.value.swing; import java.util.ArrayList; import java.util.IdentityHashMap; import java.util.List; - import javax.swing.event.TreeModelListener; import javax.swing.tree.TreePath; - import org.eclipse.jpt.common.utility.internal.ObjectTools; import org.eclipse.jpt.common.utility.internal.model.listener.awt.AWTListChangeListenerWrapper; import org.eclipse.jpt.common.utility.internal.model.listener.awt.AWTPropertyChangeListenerWrapper; import org.eclipse.jpt.common.utility.internal.model.listener.awt.AWTStateChangeListenerWrapper; -import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel; +import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools; import org.eclipse.jpt.common.utility.model.event.ListAddEvent; import org.eclipse.jpt.common.utility.model.event.ListChangeEvent; import org.eclipse.jpt.common.utility.model.event.ListClearEvent; @@ -58,7 +56,7 @@ public class TreeModelAdapter<T> * the entire tree. Due to limitations in JTree, the root should * never be set to null while we have listeners. */ - private final PropertyValueModel<TreeNodeValueModel<T>> rootHolder; + private final PropertyValueModel<TreeNodeValueModel<T>> rootModel; private final PropertyChangeListener rootListener; /** @@ -117,12 +115,12 @@ public class TreeModelAdapter<T> /** * Construct a tree model for the specified root. */ - public TreeModelAdapter(PropertyValueModel<TreeNodeValueModel<T>> rootHolder) { + public TreeModelAdapter(PropertyValueModel<TreeNodeValueModel<T>> rootModel) { super(); - if (rootHolder == null) { + if (rootModel == null) { throw new NullPointerException(); } - this.rootHolder = rootHolder; + this.rootModel = rootModel; this.rootListener = this.buildRootListener(); this.nodeStateListener = this.buildNodeStateListener(); this.nodeValueListener = this.buildNodeValueListener(); @@ -135,7 +133,7 @@ public class TreeModelAdapter<T> * Construct a tree model for the specified root. */ public TreeModelAdapter(TreeNodeValueModel<T> root) { - this(new StaticPropertyValueModel<>(root)); + this(PropertyValueModelTools.staticPropertyValueModel(root)); } @@ -284,8 +282,8 @@ public class TreeModelAdapter<T> * in the underlying tree model. */ private void engageModel() { - this.rootHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.rootListener); - this.root = this.rootHolder.getValue(); + this.rootModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.rootListener); + this.root = this.rootModel.getValue(); if (this.root == null) { throw new NullPointerException(); // the root cannot be null while we have listeners } @@ -308,7 +306,7 @@ public class TreeModelAdapter<T> this.removeRoot(); this.disengageNode(this.root); this.root = null; - this.rootHolder.removePropertyChangeListener(PropertyValueModel.VALUE, this.rootListener); + this.rootModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.rootListener); } /** @@ -325,7 +323,7 @@ public class TreeModelAdapter<T> * non-root nodes. */ void rootChanged() { - TreeNodeValueModel<T> newRoot = this.rootHolder.getValue(); + TreeNodeValueModel<T> newRoot = this.rootModel.getValue(); if (newRoot == null) { throw new NullPointerException(); // the root cannot be null while we have listeners } diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/Equals.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/Equals.java index 813d69d12d..1e20dc48e5 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/Equals.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/Equals.java @@ -18,12 +18,14 @@ import org.eclipse.jpt.common.utility.internal.ObjectTools; * will evaluate to <code>true</code> if the variable is also * <code>null</code>. * + * @param <V> the type of objects to be evaluated + * * @see IsIdentical * @see IsNotNull * @see IsNull */ -public class Equals - extends CriterionPredicate<Object, Object> +public class Equals<V> + extends CriterionPredicate<V, Object> { /** * Construct a predicate that will evaluate to <code>true</code> if the @@ -42,7 +44,7 @@ public class Equals super(criterion); } - public boolean evaluate(Object variable) { + public boolean evaluate(V variable) { return ObjectTools.equals(variable, this.criterion); } } diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/InstanceOf.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/InstanceOf.java index 1343415828..db6ce6a88e 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/InstanceOf.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/InstanceOf.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 Oracle. All rights reserved. + * Copyright (c) 2013, 2016 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -16,9 +16,9 @@ package org.eclipse.jpt.common.utility.internal.predicate; * @param <V> the type of objects to be evaluated by the predicate */ public class InstanceOf<V> - extends CriterionPredicate<V, Class<? extends V>> + extends CriterionPredicate<V, Class<?>> { - public InstanceOf(Class<? extends V> clazz) { + public InstanceOf(Class<?> clazz) { super(clazz); if (clazz == null) { throw new NullPointerException(); diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/IsIdentical.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/IsIdentical.java index d6576b96a7..7e496d888a 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/IsIdentical.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/IsIdentical.java @@ -16,12 +16,14 @@ package org.eclipse.jpt.common.utility.internal.predicate; * will evaluate to <code>true</code> if the variable is also * <code>null</code>. * + * @param <V> the type of objects to be evaluated + * * @see Equals * @see IsNotNull * @see IsNull */ -public class IsIdentical - extends CriterionPredicate<Object, Object> +public class IsIdentical<V> + extends CriterionPredicate<V, Object> { /** * Construct a predicate that will evaluate to <code>true</code> if the @@ -32,7 +34,7 @@ public class IsIdentical super(criterion); } - public boolean evaluate(Object variable) { + public boolean evaluate(V variable) { return variable == this.criterion; } } diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/IsNotNull.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/IsNotNull.java index 49baead63a..408bd3c5d2 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/IsNotNull.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/IsNotNull.java @@ -25,8 +25,9 @@ public final class IsNotNull { public static final Predicate<Object> INSTANCE = new IsNotNull(); - public static Predicate<Object> instance() { - return INSTANCE; + @SuppressWarnings("unchecked") + public static <V> Predicate<V> instance() { + return (Predicate<V>) INSTANCE; } // ensure single instance diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/IsNull.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/IsNull.java index cbeddabf94..49a5e410d5 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/IsNull.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/IsNull.java @@ -25,8 +25,9 @@ public final class IsNull { public static final Predicate<Object> INSTANCE = new IsNull(); - public static Predicate<Object> instance() { - return INSTANCE; + @SuppressWarnings("unchecked") + public static <V> Predicate<V> instance() { + return (Predicate<V>) INSTANCE; } // ensure single instance diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/PredicateTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/PredicateTools.java index 743dae2ec3..a9aa3f5e2a 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/PredicateTools.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/PredicateTools.java @@ -30,6 +30,7 @@ public final class PredicateTools { /** * Return a predicate that will always evaluate to <code>true</code>. + * * @param <V> the type of objects to be evaluated by the predicate */ public static <V> Predicate<V> true_() { @@ -38,6 +39,7 @@ public final class PredicateTools { /** * Return a predicate that will always evaluate to <code>false</code>. + * * @param <V> the type of objects to be evaluated by the predicate */ public static <V> Predicate<V> false_() { @@ -48,7 +50,7 @@ public final class PredicateTools { * Return a predicate that will evaluate whether an object is * <em>not</em> <code>null</code>. */ - public static Predicate<Object> isNotNull() { + public static <V> Predicate<V> isNotNull() { return IsNotNull.instance(); } @@ -56,13 +58,14 @@ public final class PredicateTools { * Return a predicate that will evaluate whether an object is * <code>null</code>. */ - public static Predicate<Object> isNull() { + public static <V> Predicate<V> isNull() { return IsNull.instance(); } /** * Return a predicate that will throw an exception when it is * evaluated. + * * @param <V> the type of objects to be evaluated by the predicate */ public static <V> Predicate<V> disabledPredicate() { @@ -78,9 +81,11 @@ public final class PredicateTools { * criterion. If the criterion is <code>null</code>, the predicate * will evaluate to <code>true</code> if the variable is also * <code>null</code>. + * + * @param <V> the type of objects to be evaluated by the predicate */ - public static Predicate<Object> isEqual(Object criterion) { - return (criterion == null) ? isNull() : new Equals(criterion); + public static <V> Predicate<V> isEqual(Object criterion) { + return (criterion == null) ? isNull() : new Equals<>(criterion); } /** @@ -90,7 +95,7 @@ public final class PredicateTools { * will evaluate to <code>true</code> if the variable is not * <code>null</code>. */ - public static Predicate<Object> isNotEqual(Object criterion) { + public static <V> Predicate<V> isNotEqual(Object criterion) { return (criterion == null) ? isNotNull() : not(isEqual(criterion)); } @@ -101,8 +106,8 @@ public final class PredicateTools { * will evaluate to <code>true</code> if the variable is also * <code>null</code>. */ - public static Predicate<Object> isIdentical(Object criterion) { - return (criterion == null) ? isNull() : new IsIdentical(criterion); + public static <V> Predicate<V> isIdentical(Object criterion) { + return (criterion == null) ? isNull() : new IsIdentical<>(criterion); } /** @@ -112,7 +117,7 @@ public final class PredicateTools { * will evaluate to <code>true</code> if the variable is not * <code>null</code>. */ - public static Predicate<Object> isNotIdentical(Object criterion) { + public static <V> Predicate<V> isNotIdentical(Object criterion) { return (criterion == null) ? isNotNull() : not(isIdentical(criterion)); } @@ -129,7 +134,9 @@ public final class PredicateTools { * If the list is not empty, this predicate will * exhibit "short-circuit" behavior; i.e. if any one of the predicates evaluates * to <code>false</code>, no following predicates will be evaluated. + * * @param <V> the type of objects to be evaluated by the predicate + * * @see AND */ public static <V> Predicate<V> and(Iterable<Predicate<? super V>> predicates) { @@ -138,7 +145,9 @@ public final class PredicateTools { /** * Return a predicate that will AND the results of the specified predicates. + * * @param <V> the type of objects to be evaluated by the predicate + * * @see #and(Iterable) * @see AND */ @@ -149,7 +158,9 @@ public final class PredicateTools { /** * Return a predicate that will AND the results of the specified predicates. + * * @param <V> the type of objects to be evaluated by the predicate + * * @see #and(Iterable) * @see AND */ @@ -179,7 +190,9 @@ public final class PredicateTools { * If the list is not empty, this predicate will * exhibit "short-circuit" behavior; i.e. if any one of the predicates evaluates * to <code>true</code>, no following predicates will be evaluated. + * * @param <V> the type of objects to be evaluated by the predicate + * * @see OR */ public static <V> Predicate<V> or(Iterable<Predicate<? super V>> predicates) { @@ -188,7 +201,9 @@ public final class PredicateTools { /** * Return a predicate that will OR the results of the specified predicates. + * * @param <V> the type of objects to be evaluated by the predicate + * * @see #or(Iterable) * @see OR */ @@ -199,7 +214,9 @@ public final class PredicateTools { /** * Return a predicate that will OR the results of the specified predicates. + * * @param <V> the type of objects to be evaluated by the predicate + * * @see #or(Iterable) * @see OR */ @@ -225,7 +242,9 @@ public final class PredicateTools { * its wrapped predicates evaluates to <code>true</code>, but <em>not</em> both. * <p> * <strong>NB:</strong> Both predicates will <em>always</em> be evaluated. + * * @param <V> the type of objects to be evaluated by the predicate + * * @see XOR */ public static <V> Predicate<V> xor(Predicate<? super V> predicate1, Predicate<? super V> predicate2) { @@ -237,7 +256,9 @@ public final class PredicateTools { /** * Return a predicate that will NAND the results of the specified predicates. + * * @param <V> the type of objects to be evaluated by the predicate + * * @see #and(Iterable) * @see #not(Predicate) */ @@ -247,7 +268,9 @@ public final class PredicateTools { /** * Return a predicate that will NAND the results of the specified predicates. + * * @param <V> the type of objects to be evaluated by the predicate + * * @see #and(Iterator) * @see #not(Predicate) */ @@ -258,7 +281,9 @@ public final class PredicateTools { /** * Return a predicate that will NAND the results of the specified predicates. + * * @param <V> the type of objects to be evaluated by the predicate + * * @see #and(Predicate[]) * @see #not(Predicate) */ @@ -272,7 +297,9 @@ public final class PredicateTools { /** * Return a predicate that will NOR the results of the specified predicates. + * * @param <V> the type of objects to be evaluated by the predicate + * * @see #or(Iterable) * @see #not(Predicate) */ @@ -282,7 +309,9 @@ public final class PredicateTools { /** * Return a predicate that will NOR the results of the specified predicates. + * * @param <V> the type of objects to be evaluated by the predicate + * * @see #or(Iterator) * @see #not(Predicate) */ @@ -293,7 +322,9 @@ public final class PredicateTools { /** * Return a predicate that will NOR the results of the specified predicates. + * * @param <V> the type of objects to be evaluated by the predicate + * * @see #or(Predicate[]) * @see #not(Predicate) */ @@ -307,7 +338,9 @@ public final class PredicateTools { /** * Return a predicate that will XNOR the results of the specified predicates. + * * @param <V> the type of objects to be evaluated by the predicate + * * @see #xor(Predicate, Predicate) * @see #not(Predicate) */ @@ -321,6 +354,7 @@ public final class PredicateTools { /** * Return a predicate that will return the NOT of the value returned * by the specified predicate. + * * @param <V> the type of objects to be evaluated by the predicate */ public static <V> Predicate<V> not(Predicate<? super V> predicate) { @@ -338,7 +372,9 @@ public final class PredicateTools { * <p> * <strong>NB:</strong> The variable's value will be checked for <code>null</code> * <em>before</em> it is passed to the specified predicate. + * * @param <V> the type of the object passed to the predicate + * * @see NullCheckPredicateWrapper * @see #nullCheck(Predicate, boolean) */ @@ -354,7 +390,9 @@ public final class PredicateTools { * <p> * <strong>NB:</strong> The variable's value will be checked for <code>null</code> * <em>before</em> it is passed to the specified predicate. + * * @param <V> the type of the object passed to the predicate + * * @see NullCheckPredicateWrapper * @see #nullCheck(Predicate) */ @@ -365,6 +403,7 @@ public final class PredicateTools { /** * Return a predicate that wraps the specified predicate, allowing the * wrapped predicate to be changed as necessary. + * * @param <V> the type of objects to be evaluated by the predicate */ public static <V> Predicate<V> wrap(Predicate<? super V> predicate) { @@ -375,6 +414,7 @@ public final class PredicateTools { * Return a predicate that wraps the specified predicate and uses the * specified transformer to transform the variable before passing the * output of the transformer to the specified predicate. + * * @param <I> the type of objects to be evaluated by the predicate and * passed to the specified transformer * @param <O> the type of objects output by the specified transformer and to be @@ -390,9 +430,10 @@ public final class PredicateTools { /** * Return a predicate that will evaluate to <code>true</code> for any object that * is non-<code>null</code> and an instance of the specified class. + * * @param <V> the type of objects to be evaluated by the predicate */ - public static <V> Predicate<V> instanceOf(Class<? extends V> clazz) { + public static <V> Predicate<V> instanceOf(Class<?> clazz) { return new InstanceOf<>(clazz); } @@ -404,6 +445,7 @@ public final class PredicateTools { * value to a predicate evaluation result (i.e. <code>true</code> or * <code>false</code>). If the transformer's output is <code>null</code>, * the predicate will evaluate to <code>false</code>. + * * @param <V> the type of objects to be evaluated by the predicate */ public static <V> Predicate<V> adapt(Transformer<V, Boolean> transformer) { @@ -415,6 +457,7 @@ public final class PredicateTools { * value to a predicate evaluation result (i.e. <code>true</code> or * <code>false</code>). If the transformer's output is <code>null</code>, * the predicate will evaluate to the specified null value. + * * @param <V> the type of objects to be evaluated by the predicate */ public static <V> Predicate<V> adapt(Transformer<V, Boolean> transformer, boolean nullValue) { @@ -427,6 +470,7 @@ public final class PredicateTools { * <code>false</code>). * <strong>NB:</strong> If the transformer's output is <code>null</code>, * the predicate will throw a {@link NullPointerException}. + * * @param <V> the type of objects to be evaluated by the predicate */ public static <V> Predicate<V> adapt_(Transformer<V, Boolean> transformer) { @@ -479,6 +523,7 @@ public final class PredicateTools { /** * Return a predicate that will evaluate to <code>true</code> for any object * that is contained in the specified set. + * * @param <V> the type of objects to be evaluated by the predicate */ public static <V> Predicate<V> isIn(Set<? super V> set) { @@ -488,6 +533,7 @@ public final class PredicateTools { /** * Return a predicate that will evaluate to <code>true</code> for any object * that is <em>not</em> contained in the specified set. + * * @param <V> the type of objects to be evaluated by the predicate */ public static <V> Predicate<V> isNotIn(Set<? super V> set) { @@ -501,6 +547,7 @@ public final class PredicateTools { * Return a predicate that will evaluate to <code>true</code> for any object that * has not been previously evaluated by the predicate (as determined by * object-identity: <code>==</code>). + * * @param <V> the type of objects to be evaluated by the predicate */ public static <V> UniquePredicate<V> uniqueIdentityPredicate() { @@ -511,6 +558,7 @@ public final class PredicateTools { * Return a predicate that will evaluate to <code>true</code> for any object that * has not been previously evaluated by the predicate (as determined by * {@link Object#equals(Object) equality}). + * * @param <V> the type of objects to be evaluated by the predicate */ public static <V> UniquePredicate<V> uniquePredicate() { @@ -521,6 +569,7 @@ public final class PredicateTools { * Return a predicate that will evaluate to <code>true</code> for any object that * has not been previously evaluated by the predicate (as determined by * {@link Object#equals(Object) equality}). + * * @param <V> the type of objects to be evaluated by the predicate */ public static <V> UniquePredicate<V> uniquePredicate(Set<V> set) { @@ -537,6 +586,7 @@ public final class PredicateTools { * <strong>NB:</strong> The actual field is determined at execution time, * not construction time. As a result, the transformer can be used to emulate * "duck typing". + * * @param <V> the type of objects to be evaluated by the predicate */ public static <V> FieldPredicate<V> get(String fieldName) { @@ -550,6 +600,7 @@ public final class PredicateTools { * <strong>NB:</strong> The actual method is determined at execution time, * not construction time. As a result, the transformer can be used to emulate * "duck typing". + * * @param <V> the type of objects to be evaluated by the predicate */ public static <V> MethodPredicate<V> execute(String methodName) { @@ -563,6 +614,7 @@ public final class PredicateTools { * <strong>NB:</strong> The actual method is determined at execution time, * not construction time. As a result, the transformer can be used to emulate * "duck typing". + * * @param <V> the type of objects to be evaluated by the predicate */ public static <V> MethodPredicate<V> execute(String methodName, Class<?> parameterType, Object argument) { @@ -576,6 +628,7 @@ public final class PredicateTools { * <strong>NB:</strong> The actual method is determined at execution time, * not construction time. As a result, the transformer can be used to emulate * "duck typing". + * * @param <V> the type of objects to be evaluated by the predicate */ public static <V> MethodPredicate<V> execute(String methodName, Class<?>[] parameterTypes, Object[] arguments) { diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/PredicateTransformer.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/PredicateTransformer.java index 112f5803a1..8843f8c730 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/PredicateTransformer.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/PredicateTransformer.java @@ -9,6 +9,7 @@ ******************************************************************************/ package org.eclipse.jpt.common.utility.internal.transformer; +import org.eclipse.jpt.common.utility.internal.ObjectTools; import org.eclipse.jpt.common.utility.predicate.Predicate; import org.eclipse.jpt.common.utility.transformer.Transformer; @@ -43,6 +44,6 @@ public class PredicateTransformer<I> @Override public String toString() { - return super.toString(); + return ObjectTools.toString(this, this.predicate); } } diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/TransformerTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/TransformerTools.java index 205e5b74e1..7b2d5500f1 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/TransformerTools.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/TransformerTools.java @@ -40,6 +40,7 @@ public final class TransformerTools { /** * Adapt the specified {@link Closure} to the {@link Transformer} interface. * The returned transformer will always return <code>null</code>. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer */ @@ -51,6 +52,7 @@ public final class TransformerTools { * Adapt the specified {@link Command} to the {@link Transformer} interface. * The returned transformer will always return <code>null</code> and its * input will be ignored. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer */ @@ -62,6 +64,7 @@ public final class TransformerTools { * Adapt the specified {@link Factory} to the {@link Transformer} interface. * The returned transformer will return the factory's output and its * input will be ignored. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer */ @@ -75,6 +78,7 @@ public final class TransformerTools { * Once it has {@link Runnable#run run}, * the returned future will return the transformer's output, * as determined by the specified input. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer * (and future) @@ -88,6 +92,7 @@ public final class TransformerTools { * to the {@link Callable} interface. * The returned callable will return the transformer's output, * as determined by the specified input. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer * (and callable) @@ -107,7 +112,9 @@ public final class TransformerTools { * <p> * <strong>NB:</strong> The transformer will return the string * <code>"null"</code> if it is passed a <code>null</code> input. + * * @param <I> input: the type of the object passed to the transformer + * * @see ObjectToStringTransformer * @see String#valueOf(Object) * @see #objectToStringTransformer() @@ -124,7 +131,9 @@ public final class TransformerTools { * <p> * <strong>NB:</strong> The transformer will return <code>null</code> * if it is passed a <code>null</code> input. + * * @param <I> input: the type of the object passed to the transformer + * * @see ObjectToStringTransformer * @see Object#toString() * @see #objectToStringTransformer(String) @@ -140,7 +149,9 @@ public final class TransformerTools { * returned by its {@link Object#toString()} method. * The transformer will return the specified string * if it is passed a <code>null</code> input. + * * @param <I> input: the type of the object passed to the transformer + * * @see ObjectToStringTransformer * @see Object#toString() * @see #objectToStringTransformer() @@ -157,7 +168,9 @@ public final class TransformerTools { * <p> * <strong>NB:</strong> The transformer will throw a * {@link NullPointerException} if it is passed a <code>null</code> input. + * * @param <I> input: the type of the object passed to the transformer + * * @see ObjectToStringTransformer * @see Object#toString() * @see #objectToStringTransformer() @@ -252,8 +265,10 @@ public final class TransformerTools { * <strong>NB:</strong> If passed a <code>null</code> <em>input</em>, the * transformer will simply return a <code>null</code> <em>output</em> * without forwarding the <em>input</em> to the predicate. + * * @param <I> input: the type of the object passed to the transformer (and * forwarded to the wrapped predicate) + * * @see PredicateTransformer * @see #adapt(Predicate, Boolean) * @see #adapt(Predicate) @@ -269,8 +284,10 @@ public final class TransformerTools { * <strong>NB:</strong> If passed a <code>null</code> <em>input</em>, the * transformer will simply return the specified value * without forwarding the <em>input</em> to the predicate. + * * @param <I> input: the type of the object passed to the transformer (and * forwarded to the wrapped predicate) + * * @see PredicateTransformer * @see #adapt_(Predicate) * @see #adapt(Predicate) @@ -285,8 +302,10 @@ public final class TransformerTools { * <p> * <strong>NB:</strong> If passed a <code>null</code> <em>input</em>, the * transformer will pass a <code>null</code> to the predicate. + * * @param <I> input: the type of the object passed to the transformer (and * forwarded to the wrapped predicate) + * * @see PredicateTransformer * @see #adapt_(Predicate) * @see #adapt(Predicate, Boolean) @@ -304,6 +323,7 @@ public final class TransformerTools { * <p> * <strong>NB:</strong> The transformer will return <code>null</code> * if it is passed a <code>null</code> input. + * * @see StringToBooleanTransformer * @see Boolean#valueOf(String) * @see #stringToBooleanTransformer(Boolean) @@ -317,6 +337,7 @@ public final class TransformerTools { * Return a transformer that transforms a {@link String} to the appropriate * {@link Boolean}. The transformer will return the specified value * if it is passed a <code>null</code> input. + * * @see StringToBooleanTransformer * @see Boolean#valueOf(String) * @see #stringToBooleanTransformer() @@ -332,6 +353,7 @@ public final class TransformerTools { * <p> * <strong>NB:</strong> The transformer will return {@link Boolean#FALSE} * if it is passed a <code>null</code> input. + * * @see StringToBooleanTransformer * @see Boolean#valueOf(String) * @see #stringToBooleanTransformer(Boolean) @@ -347,6 +369,7 @@ public final class TransformerTools { * <p> * <strong>NB:</strong> The transformer will return <code>null</code> * if it is passed a <code>null</code> input. + * * @see StringToIntegerTransformer * @see Integer#valueOf(String) * @see #stringToIntegerTransformer(Integer) @@ -360,6 +383,7 @@ public final class TransformerTools { * Return a transformer that transforms a {@link String} to the appropriate * {@link Integer}. The transformer will return the specified value * if it is passed a <code>null</code> input. + * * @see StringToIntegerTransformer * @see Integer#valueOf(String) * @see #stringToIntegerTransformer() @@ -375,6 +399,7 @@ public final class TransformerTools { * <p> * <strong>NB:</strong> The transformer will throw a * {@link NumberFormatException} if it is passed a <code>null</code> input. + * * @see StringToIntegerTransformer * @see Integer#valueOf(String) * @see #stringToIntegerTransformer() @@ -390,6 +415,7 @@ public final class TransformerTools { /** * Return a transformer that transforms a collection into its first element. * If the collection is empty, the transformer returns <code>null</code>. + * * @param <E> the type of elements held by the collection */ public static <E> Transformer<Collection<? extends E>, E> collectionFirstElementTransformer() { @@ -400,6 +426,7 @@ public final class TransformerTools { * Return a transformer that transforms a collection into its first element. * If the collection is empty, the transformer throws a * {@link java.util.NoSuchElementException}. + * * @param <E> the type of elements held by the collection */ public static <E> Transformer<Collection<? extends E>, E> collectionFirstElementTransformer_() { @@ -409,6 +436,7 @@ public final class TransformerTools { /** * Return a transformer that transforms a collection into its last element. * If the collection is empty, the transformer returns <code>null</code>. + * * @param <E> the type of elements held by the collection */ public static <E> Transformer<Collection<? extends E>, E> collectionLastElementTransformer() { @@ -419,6 +447,7 @@ public final class TransformerTools { * Return a transformer that transforms a collection into its last element. * If the collection is empty, the transformer throws a * {@link java.util.NoSuchElementException}. + * * @param <E> the type of elements held by the collection */ public static <E> Transformer<Collection<? extends E>, E> collectionLastElementTransformer_() { @@ -429,6 +458,7 @@ public final class TransformerTools { * Return a transformer that transforms a collection into its <em>single</em> element. * If the collection is empty or contains more than one element, * the transformer returns <code>null</code>. + * * @param <E> the type of elements held by the collection */ public static <E> Transformer<Collection<? extends E>, E> collectionSingleElementTransformer() { @@ -495,6 +525,7 @@ public final class TransformerTools { /** * Return a transformer that transforms a list into its last element. * If the list is empty, the transformer returns <code>null</code>. + * * @param <E> the type of elements held by the list */ public static <E> Transformer<List<? extends E>, E> listLastElementTransformer() { @@ -504,6 +535,7 @@ public final class TransformerTools { /** * Return a transformer that transforms a list into its last element. * If the list is empty, the transformer throws an {@link IndexOutOfBoundsException}. + * * @param <E> the type of elements held by the list */ public static <E> Transformer<List<? extends E>, E> listLastElementTransformer_() { @@ -518,6 +550,7 @@ public final class TransformerTools { * <em>character references</em> * by replacing the <em>character references</em> with the characters * themselves: <code>"&#x2f;" => '/'</code> + * * @see #xmlStringEncoder(char[]) * @see XMLStringDecoder */ @@ -529,6 +562,7 @@ public final class TransformerTools { * Return a transformer that will replace any of the XML "predefined * entities" with an XML <em>character reference</em>: * <code>'&' => "&#x26;"</code> + * * @see #xmlStringDecoder() * @see #xmlStringEncoder(char[]) * @see XMLStringEncoder @@ -542,6 +576,7 @@ public final class TransformerTools { * Return a transformer that will replace any of the specified set of * characters with an XML <em>character reference</em>: * <code>'/' => "&#x2f;"</code> + * * @see #xmlStringDecoder() * @see #xmlStringEncoder() * @see XMLStringEncoder @@ -557,8 +592,10 @@ public final class TransformerTools { * Return a transformer that allows the client to specify a different transformer * for each thread. If there is no transformer for the current thread, the * transformer will return <code>null</code>. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see ThreadLocalTransformer */ public static <I, O> ThreadLocalTransformer<I, O> threadLocalTransformer() { @@ -569,8 +606,10 @@ public final class TransformerTools { * Return a transformer that allows the client to specify a different transformer * for each thread. If there is no transformer for the current thread, the * specified default transformer is used. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see ThreadLocalTransformer */ public static <I, O> ThreadLocalTransformer<I, O> threadLocalTransformer(Transformer<? super I, ? extends O> defaultTransformer) { @@ -583,8 +622,10 @@ public final class TransformerTools { /** * Return a transformer that caches the results generated by the specified transformer; * the assumption being that the transformation is an expensive action. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see CachingTransformer */ public static <I, O> Transformer<I, O> cachingTransformer(Transformer<? super I, ? extends O> transformer) { @@ -595,8 +636,10 @@ public final class TransformerTools { * Return a transformer that caches, in a thread-safe fashion, * the results generated by the specified transformer; * the assumption being that the transformation is an expensive action. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see CachingInterruptibleTransformer */ public static <I, O> InterruptibleTransformer<I, O> cachingInterruptibleTransformer(Transformer<? super I, ? extends O> transformer) { @@ -610,8 +653,10 @@ public final class TransformerTools { * Wrap the specified transformer converting it * into one that converts the same input object into an <em>iterator</em> * of objects of the same type as the input object. + * * @param <I> input: the type of the object passed to the transformer; also the * type of object returned by the output iterator + * * @see IterableTransformerWrapper */ public static <I> Transformer<I, Iterator<? extends I>> toIterator(Transformer<? super I, ? extends Iterable<? extends I>> transformer) { @@ -623,8 +668,10 @@ public final class TransformerTools { * If the input is <code>null</code>, the transformer will return * the configured output value; * otherwise, it will simply return the input. + * * @param <I> input: the type of the object passed to and * returned by the transformer + * * @see NullCheckTransformer * @see #nullCheck(Transformer) * @see #nullCheck(Transformer, Object) @@ -638,8 +685,10 @@ public final class TransformerTools { * for <code>null</code> input before forwarding the input to the specified * transformer. If the input is <code>null</code>, the transformer will * return <code>null</code>. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see NullCheckTransformerWrapper * @see #nullCheck(Transformer, Object) * @see #nullCheck(Object) @@ -653,8 +702,10 @@ public final class TransformerTools { * for <code>null</code> input before forwarding the input to the specified * transformer. If the input is <code>null</code>, the transformer will * return the specified output value. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see NullCheckTransformerWrapper * @see #nullCheck(Transformer) * @see #nullCheck(Object) @@ -667,8 +718,10 @@ public final class TransformerTools { * Return a transformer that can have its wrapped transformer changed, * allowing a client to change a previously-supplied transformer's * behavior mid-stream. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see TransformerWrapper */ public static <I, O> TransformerWrapper<I, O> wrap(Transformer<? super I, ? extends O> transformer) { @@ -680,12 +733,14 @@ public final class TransformerTools { /** * Return a transformer that simply casts the specified transformer's return type. + * * @param <I> input: the type of the object passed to the transformer * @param <X> intermediate: the type of object returned by the wrapped * transformer * @param <O> output: the type of object returned by the transformer - this * is the same object returned by the wrapped transformer, simply * cast to <code>O</code> + * * @see CastingTransformerWrapper * @see #upcast(Transformer) * @see #downcast(Transformer) @@ -696,12 +751,14 @@ public final class TransformerTools { /** * Return a transformer that simply downcasts the specified transformer's return type. + * * @param <I> input: the type of the object passed to the transformer * @param <X> intermediate: the type of object returned by the wrapped * transformer * @param <O> output: the type of object returned by the transformer - this * is the same object returned by the wrapped transformer, simply * cast to <code>O</code> + * * @see DowncastingTransformerWrapper * @see #cast(Transformer) * @see #upcast(Transformer) @@ -712,12 +769,14 @@ public final class TransformerTools { /** * Return a transformer that simply upcasts the specified transformer's return type. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of object returned by the transformer - this * is the same object returned by the wrapped transformer, simply * cast to <code>O</code> * @param <X> intermediate: the type of object returned by the wrapped * transformer + * * @see UpcastingTransformerWrapper * @see #cast(Transformer) * @see #downcast(Transformer) @@ -735,8 +794,10 @@ public final class TransformerTools { * thrown, the exception's stack trace will be printed to {@link System#err * the "standard" error output stream} and <code>null</code> will be * returned. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see SafeTransformerWrapper * @see DefaultExceptionHandler */ @@ -750,8 +811,10 @@ public final class TransformerTools { * thrown, the exception's stack trace will be printed to {@link System#err * the "standard" error output stream} * and specified output will be returned. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see SafeTransformerWrapper * @see DefaultExceptionHandler */ @@ -764,8 +827,10 @@ public final class TransformerTools { * any exceptions thrown during the transformation. If an exception is * thrown, the exception will be passed to the specified exception handler * and <code>null</code> will be returned. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see SafeTransformerWrapper */ public static <I, O> Transformer<I, O> safe(Transformer<? super I, ? extends O> transformer, ExceptionHandler exceptionHandler) { @@ -777,8 +842,10 @@ public final class TransformerTools { * any exceptions thrown during the transformation. If an exception is * thrown, the exception will be passed to the specified exception handler * and specified output will be returned. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see SafeTransformerWrapper */ public static <I, O> Transformer<I, O> safe(Transformer<? super I, ? extends O> transformer, ExceptionHandler exceptionHandler, O exceptionOutput) { @@ -791,8 +858,10 @@ public final class TransformerTools { /** * Return a transformer that will perform no transformation at all; * it will simply return the input untransformed. + * * @param <I> input: the type of the object passed to the transformer * (and returned by the transformer) + * * @see PassThruTransformer * @see #passThruTransformer(Object) */ @@ -805,8 +874,10 @@ public final class TransformerTools { * it will simply return the input if it is not <code>null</code>. * The transformer will convert a <code>null</code> input into the specified * output. + * * @param <I> input: the type of the object passed to the transformer * (and returned by the transformer) + * * @see PassThruTransformer * @see #passThruTransformer() */ @@ -848,8 +919,10 @@ public final class TransformerTools { /** * Return a transformer that clones its input. + * * @param <I> input: the type of the object passed to the transformer * (and returned by the transformer) + * * @see CloneTransformer */ public static <I extends Cloneable> Transformer<I, I> cloneTransformer() { @@ -860,8 +933,10 @@ public final class TransformerTools { * Return a transformer that transforms a {@link Class} into an instance * by calling {@link Class#newInstance()}. Checked exceptions are converted * to {@link RuntimeException}s. + * * @param <O> output: the type of the object returned by the transformer (and * the class, or superclass of the class, passed to the transformer) + * * @see InstantiationTransformer */ public static <O> Transformer<Class<? extends O>, O> instantiationTransformer() { @@ -875,8 +950,10 @@ public final class TransformerTools { * <strong>NB:</strong> The actual field is determined at execution time, * not construction time. As a result, the transformer can be used to emulate * "duck typing". + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see FieldTransformer */ public static <I, O> Transformer<I, O> get(String fieldName) { @@ -891,8 +968,10 @@ public final class TransformerTools { * <strong>NB:</strong> The actual method is determined at execution time, * not construction time. As a result, the transformer can be used to emulate * "duck typing". + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see MethodTransformer */ public static <I, O> Transformer<I, O> execute(String methodName) { @@ -907,8 +986,10 @@ public final class TransformerTools { * <strong>NB:</strong> The actual method is determined at execution time, * not construction time. As a result, the transformer can be used to emulate * "duck typing". + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see MethodTransformer */ public static <I, O> Transformer<I, O> execute(String methodName, Class<?> parameterType, Object argument) { @@ -923,8 +1004,10 @@ public final class TransformerTools { * <strong>NB:</strong> The actual method is determined at execution time, * not construction time. As a result, the transformer can be used to emulate * "duck typing". + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see MethodTransformer */ public static <I, O> Transformer<I, O> execute(String methodName, Class<?>[] parameterTypes, Object[] arguments) { @@ -949,8 +1032,10 @@ public final class TransformerTools { * <p> * <strong>NB:</strong> The transformer's generic types are for convenience only * and cannot be enforced on the transformers in the chain. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see TransformerChain */ public static <I, O> Transformer<I, O> chain(Iterable<Transformer<?, ?>> transformers) { @@ -965,8 +1050,10 @@ public final class TransformerTools { * determine whether to forward the input to the specified transformer. * If the predicate evaluates to <code>false</code>, the transformer returns * <code>null</code>. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see ClosureTransformer */ public static <I, O> Transformer<I, O> conditionalTransformer(Predicate<? super I> predicate, Transformer<? super I, ? extends O> transformer) { @@ -976,8 +1063,10 @@ public final class TransformerTools { /** * Return a transformer that passes its input to the specified predicate to * determine which of the two specified transformers to execute. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see ClosureTransformer */ public static <I, O> Transformer<I, O> conditionalTransformer(Predicate<? super I> predicate, Transformer<? super I, ? extends O> trueTransformer, Transformer<? super I, ? extends O> falseTransformer) { @@ -1003,8 +1092,10 @@ public final class TransformerTools { * even if other, following, predicates would evaluate to <code>true</code>. * If none of the predicates evaluates to <code>true</code>, the transformer * returns <code>null</code>. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see SwitchTransformer */ public static <I, O> Transformer<I, O> switchTransformer(Iterable<Association<Predicate<? super I>, Transformer<? super I, ? extends O>>> transformers) { @@ -1019,8 +1110,10 @@ public final class TransformerTools { * even if other, following, predicates would evaluate to <code>true</code>. * If none of the predicates evaluates to <code>true</code>, the default transformer * is executed. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see SwitchTransformer */ public static <I, O> Transformer<I, O> switchTransformer(Iterable<Association<Predicate<? super I>, Transformer<? super I, ? extends O>>> transformers, Transformer<? super I, ? extends O> defaultTransformer) { @@ -1035,8 +1128,10 @@ public final class TransformerTools { * if {@link Transformer#transform(Object)} is called. This is useful in * situations where a transformer is optional and the default transformer * should not be used. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see DisabledTransformer */ public static <I, O> Transformer<I, O> disabledTransformer() { @@ -1049,8 +1144,10 @@ public final class TransformerTools { /** * Return a transformer that will transform an input into its value * in the specified map. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see MapTransformer */ public static <I, O> Transformer<I, O> mapTransformer(Map<? super I, ? extends O> map) { @@ -1062,8 +1159,10 @@ public final class TransformerTools { /** * Return a transformer that will transform every input into <code>null</code>. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see NullOutputTransformer */ public static <I, O> Transformer<I, O> nullOutputTransformer() { @@ -1073,8 +1172,10 @@ public final class TransformerTools { /** * Return a transformer that will transform any object into the specified * output. + * * @param <I> input: the type of the object passed to the transformer * @param <O> output: the type of the object returned by the transformer + * * @see StaticOutputTransformer * @see #nullOutputTransformer() */ diff --git a/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/swt/bindings/ComboBoxModelBindingUITest.java b/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/swt/bindings/ComboBoxModelBindingUITest.java index fb1990bd2d..ca11d5a0fa 100644 --- a/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/swt/bindings/ComboBoxModelBindingUITest.java +++ b/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/swt/bindings/ComboBoxModelBindingUITest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2013 Oracle. All rights reserved. + * Copyright (c) 2008, 2016 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -19,10 +19,9 @@ import org.eclipse.jpt.common.utility.internal.ArrayTools; import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.common.utility.internal.model.AbstractModel; import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools; import org.eclipse.jpt.common.utility.internal.model.value.SimpleListValueModel; import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.common.utility.internal.transformer.AbstractTransformer; import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel; import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; @@ -71,13 +70,13 @@ public class ComboBoxModelBindingUITest super(null); this.nameListModel = this.buildNameListModel(); this.testModel = new TestModel(DEFAULT_NAME); - this.testModelModel = new SimplePropertyValueModel<TestModel>(this.testModel); + this.testModelModel = new SimplePropertyValueModel<>(this.testModel); this.nameModel = new NameModel(this.testModelModel); this.allCapsNameModel = this.buildAllCapsNameModel(this.testModelModel); - this.nameListSelectionModel = new SimplePropertyValueModel<String>(); - this.nameListIndexTextModel = new SimplePropertyValueModel<String>(); - this.nameListNameModel = new SimplePropertyValueModel<String>(); + this.nameListSelectionModel = new SimplePropertyValueModel<>(); + this.nameListIndexTextModel = new SimplePropertyValueModel<>(); + this.nameListNameModel = new SimplePropertyValueModel<>(); } private static final Transformer<String, Integer> STRING_INTEGER_TRANSFORMER = new StringIntegerTransformer(); static class StringIntegerTransformer @@ -94,7 +93,7 @@ public class ComboBoxModelBindingUITest } private SimpleListValueModel<String> buildNameListModel() { - SimpleListValueModel<String> x = new SimpleListValueModel<String>(); + SimpleListValueModel<String> x = new SimpleListValueModel<>(); x.add("Daphne"); x.add("Fred"); x.add("Scooby-Doo"); @@ -120,16 +119,16 @@ public class ComboBoxModelBindingUITest } private PropertyValueModel<String> buildAllCapsNameModel(PropertyValueModel<TestModel> vm) { - return new TransformationPropertyValueModel<String, String>(new NameModel(vm), UPPER_CASE_TRANSFORMER); + return PropertyValueModelTools.transform(new NameModel(vm), UPPER_CASE_TRANSFORMER); } public static final Transformer<String, String> UPPER_CASE_TRANSFORMER = new UpperCaseTransformer(); /* CU private */ static class UpperCaseTransformer - extends AbstractTransformer<String, String> + extends TransformerAdapter<String, String> { @Override - protected String transform_(String string) { + public String transform(String string) { return string.toUpperCase(); } } diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java index e87cc82924..18860d8783 100644 --- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2012 Oracle. All rights reserved. + * Copyright (c) 2008, 2016 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -9,11 +9,10 @@ ******************************************************************************/ package org.eclipse.jpt.common.utility.tests.internal.model.value; -import junit.framework.TestCase; import org.eclipse.jpt.common.utility.internal.model.AbstractModel; +import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools; import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.common.utility.internal.transformer.AbstractTransformer; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent; import org.eclipse.jpt.common.utility.model.listener.ChangeAdapter; import org.eclipse.jpt.common.utility.model.listener.ChangeListener; @@ -22,13 +21,16 @@ import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel; import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; import org.eclipse.jpt.common.utility.tests.internal.TestTools; import org.eclipse.jpt.common.utility.transformer.Transformer; +import junit.framework.TestCase; @SuppressWarnings("nls") -public class CachingTransformationPropertyValueModelTests extends TestCase { - private ModifiablePropertyValueModel<Person> objectHolder; +public class CachingTransformationPropertyValueModelTests + extends TestCase +{ + private ModifiablePropertyValueModel<Person> personModel; PropertyChangeEvent event; - private PropertyValueModel<Person> transformationObjectHolder; + private PropertyValueModel<Person> testModel; PropertyChangeEvent transformationEvent; public CachingTransformationPropertyValueModelTests(String name) { @@ -38,8 +40,8 @@ public class CachingTransformationPropertyValueModelTests extends TestCase { @Override protected void setUp() throws Exception { super.setUp(); - this.objectHolder = new SimplePropertyValueModel<Person>(new Person("Karen", "Peggy", null)); - this.transformationObjectHolder = new TransformationPropertyValueModel<Person, Person>(this.objectHolder, PARENT_TRANSFORMER); + this.personModel = new SimplePropertyValueModel<>(new Person("Karen", "Peggy", null)); + this.testModel = PropertyValueModelTools.transform(this.personModel, PARENT_TRANSFORMER); } @Override @@ -50,93 +52,93 @@ public class CachingTransformationPropertyValueModelTests extends TestCase { public void testValue() { ChangeListener listener = this.buildTransformationChangeListener(); - this.transformationObjectHolder.addChangeListener(listener); + this.testModel.addChangeListener(listener); - Person person = this.objectHolder.getValue(); + Person person = this.personModel.getValue(); assertEquals("Karen", person.getName()); - Person parent = this.transformationObjectHolder.getValue(); + Person parent = this.testModel.getValue(); assertEquals(person.getParent().getName(), parent.getName()); - assertNotSame(person.getParent(), this.transformationObjectHolder.getValue()); - assertEquals(parent, this.transformationObjectHolder.getValue()); + assertNotSame(person.getParent(), this.testModel.getValue()); + assertEquals(parent, this.testModel.getValue()); Person person1 = new Person("Matt", "Mitch", null); - this.objectHolder.setValue(person1); - Person parent2 = this.transformationObjectHolder.getValue(); + this.personModel.setValue(person1); + Person parent2 = this.testModel.getValue(); assertEquals(person1.getParent().getName(), parent2.getName()); - assertNotSame(person1.getParent(), this.transformationObjectHolder.getValue()); - assertEquals(parent2, this.transformationObjectHolder.getValue()); + assertNotSame(person1.getParent(), this.testModel.getValue()); + assertEquals(parent2, this.testModel.getValue()); - this.objectHolder.setValue(null); - assertNull(this.objectHolder.getValue()); - assertNull(this.transformationObjectHolder.getValue()); + this.personModel.setValue(null); + assertNull(this.personModel.getValue()); + assertNull(this.testModel.getValue()); Person person3 = new Person("Karen", "Peggy", null); - this.objectHolder.setValue(person3); + this.personModel.setValue(person3); assertEquals("Karen", person3.getName()); - Person parent3 = this.transformationObjectHolder.getValue(); + Person parent3 = this.testModel.getValue(); assertEquals(person3.getParent().getName(), parent3.getName()); - assertNotSame(person3.getParent(), this.transformationObjectHolder.getValue()); - assertEquals(parent3, this.transformationObjectHolder.getValue()); + assertNotSame(person3.getParent(), this.testModel.getValue()); + assertEquals(parent3, this.testModel.getValue()); } public void testLazyListening() { - assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); + assertTrue(((AbstractModel) this.personModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); ChangeListener listener = this.buildTransformationChangeListener(); - this.transformationObjectHolder.addChangeListener(listener); - assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.transformationObjectHolder.removeChangeListener(listener); - assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - - this.transformationObjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, listener); - assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.transformationObjectHolder.removePropertyChangeListener(PropertyValueModel.VALUE, listener); - assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); + this.testModel.addChangeListener(listener); + assertTrue(((AbstractModel) this.personModel).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); + this.testModel.removeChangeListener(listener); + assertTrue(((AbstractModel) this.personModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); + + this.testModel.addPropertyChangeListener(PropertyValueModel.VALUE, listener); + assertTrue(((AbstractModel) this.personModel).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); + this.testModel.removePropertyChangeListener(PropertyValueModel.VALUE, listener); + assertTrue(((AbstractModel) this.personModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); } public void testPropertyChange1() { - this.objectHolder.addChangeListener(this.buildChangeListener()); - this.transformationObjectHolder.addChangeListener(this.buildTransformationChangeListener()); + this.personModel.addChangeListener(this.buildChangeListener()); + this.testModel.addChangeListener(this.buildTransformationChangeListener()); this.verifyPropertyChanges(); } public void testPropertyChange2() { - this.objectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener()); - this.transformationObjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildTransformationListener()); + this.personModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener()); + this.testModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildTransformationListener()); this.verifyPropertyChanges(); } private void verifyPropertyChanges() { this.event = null; this.transformationEvent = null; - Person karen = this.objectHolder.getValue(); - Person peggyParent = this.transformationObjectHolder.getValue(); + Person karen = this.personModel.getValue(); + Person peggyParent = this.testModel.getValue(); Person peggy = new Person("Peggy", "Marian", null); - this.objectHolder.setValue(peggy); - Person marianParent = this.transformationObjectHolder.getValue(); - this.verifyEvent(this.event, this.objectHolder, karen, peggy); - this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, peggyParent, marianParent); + this.personModel.setValue(peggy); + Person marianParent = this.testModel.getValue(); + this.verifyEvent(this.event, this.personModel, karen, peggy); + this.verifyEvent(this.transformationEvent, this.testModel, peggyParent, marianParent); this.event = null; this.transformationEvent = null; Person matt = new Person("Matt", "Mitch", null); - this.objectHolder.setValue(matt); - Person mitchParent = this.transformationObjectHolder.getValue(); - this.verifyEvent(this.event, this.objectHolder, peggy, matt); - this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, marianParent, mitchParent); + this.personModel.setValue(matt); + Person mitchParent = this.testModel.getValue(); + this.verifyEvent(this.event, this.personModel, peggy, matt); + this.verifyEvent(this.transformationEvent, this.testModel, marianParent, mitchParent); this.event = null; this.transformationEvent = null; - this.objectHolder.setValue(null); - this.verifyEvent(this.event, this.objectHolder, matt, null); - this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, mitchParent, null); + this.personModel.setValue(null); + this.verifyEvent(this.event, this.personModel, matt, null); + this.verifyEvent(this.transformationEvent, this.testModel, mitchParent, null); this.event = null; this.transformationEvent = null; - this.objectHolder.setValue(matt); - mitchParent = this.transformationObjectHolder.getValue(); - this.verifyEvent(this.event, this.objectHolder, null, matt); - this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, null, mitchParent); + this.personModel.setValue(matt); + mitchParent = this.testModel.getValue(); + this.verifyEvent(this.event, this.personModel, null, matt); + this.verifyEvent(this.transformationEvent, this.testModel, null, mitchParent); } private PropertyChangeListener buildListener() { @@ -183,10 +185,10 @@ public class CachingTransformationPropertyValueModelTests extends TestCase { private static final Transformer<Person, Person> PARENT_TRANSFORMER = new ParentTransformer(); static class ParentTransformer - extends AbstractTransformer<Person, Person> + extends TransformerAdapter<Person, Person> { @Override - public Person transform_(Person person) { + public Person transform(Person person) { return person.getParent(); } } diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/StaticValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/StaticValueModelTests.java index 535a700f52..1390771067 100644 --- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/StaticValueModelTests.java +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/StaticValueModelTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. + * Copyright (c) 2007, 2016 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -9,15 +9,17 @@ ******************************************************************************/ package org.eclipse.jpt.common.utility.tests.internal.model.value; -import junit.framework.TestCase; -import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel; +import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools; import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; import org.eclipse.jpt.common.utility.tests.internal.TestTools; +import junit.framework.TestCase; @SuppressWarnings("nls") -public class StaticValueModelTests extends TestCase { - private PropertyValueModel<String> objectHolder; - private static final PropertyValueModel<String> OBJECT_HOLDER = new StaticPropertyValueModel<String>("foo"); +public class StaticValueModelTests + extends TestCase +{ + private PropertyValueModel<String> testModel; + private static final PropertyValueModel<String> OBJECT_HOLDER = PropertyValueModelTools.staticPropertyValueModel("foo"); public StaticValueModelTests(String name) { @@ -27,7 +29,7 @@ public class StaticValueModelTests extends TestCase { @Override protected void setUp() throws Exception { super.setUp(); - this.objectHolder = OBJECT_HOLDER; + this.testModel = OBJECT_HOLDER; } @Override @@ -37,11 +39,11 @@ public class StaticValueModelTests extends TestCase { } public void testValue() { - assertEquals("foo", this.objectHolder.getValue()); + assertEquals("foo", this.testModel.getValue()); } public void testToString() { - assertTrue(this.objectHolder.toString().indexOf("foo") >= 0); + assertTrue(this.testModel.toString().indexOf("foo") >= 0); } } diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TransformationModifiablePropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TransformationModifiablePropertyValueModelTests.java index de112694d2..c23cf44a2d 100644 --- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TransformationModifiablePropertyValueModelTests.java +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TransformationModifiablePropertyValueModelTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2012 Oracle. All rights reserved. + * Copyright (c) 2008, 2016 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -9,10 +9,9 @@ ******************************************************************************/ package org.eclipse.jpt.common.utility.tests.internal.model.value; -import junit.framework.TestCase; import org.eclipse.jpt.common.utility.internal.model.AbstractModel; +import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools; import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.common.utility.internal.model.value.TransformationModifiablePropertyValueModel; import org.eclipse.jpt.common.utility.internal.transformer.AbstractTransformer; import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent; import org.eclipse.jpt.common.utility.model.listener.ChangeAdapter; @@ -21,15 +20,16 @@ import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel; import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; import org.eclipse.jpt.common.utility.tests.internal.TestTools; import org.eclipse.jpt.common.utility.transformer.Transformer; +import junit.framework.TestCase; @SuppressWarnings("nls") public class TransformationModifiablePropertyValueModelTests extends TestCase { - private ModifiablePropertyValueModel<Person> objectHolder; - PropertyChangeEvent event; + private ModifiablePropertyValueModel<Person> personModel; + PropertyChangeEvent personEvent; - private ModifiablePropertyValueModel<Person> transformationObjectHolder; + private ModifiablePropertyValueModel<Person> testModel; PropertyChangeEvent transformationEvent; public TransformationModifiablePropertyValueModelTests(String name) { @@ -39,8 +39,8 @@ public class TransformationModifiablePropertyValueModelTests @Override protected void setUp() throws Exception { super.setUp(); - this.objectHolder = new SimplePropertyValueModel<Person>(new Person("Karen", "Peggy", null)); - this.transformationObjectHolder = new TransformationModifiablePropertyValueModel<Person, Person>(this.objectHolder, PARENT_TRANSFORMER, CHILD_TRANSFORMER); + this.personModel = new SimplePropertyValueModel<>(new Person("Karen", "Peggy", null)); + this.testModel = PropertyValueModelTools.transform_(this.personModel, PARENT_TRANSFORMER, CHILD_TRANSFORMER); } @Override @@ -51,131 +51,106 @@ public class TransformationModifiablePropertyValueModelTests public void testValue() { ChangeListener listener = this.buildTransformationListener(); - this.transformationObjectHolder.addChangeListener(listener); + this.testModel.addChangeListener(listener); - Person person = this.objectHolder.getValue(); + Person person = this.personModel.getValue(); assertEquals("Karen", person.getName()); - Person parent = this.transformationObjectHolder.getValue(); + Person parent = this.testModel.getValue(); assertEquals(person.getParent().getName(), parent.getName()); - assertNotSame(person.getParent(), this.transformationObjectHolder.getValue()); - assertEquals(parent, this.transformationObjectHolder.getValue()); + assertNotSame(person.getParent(), this.testModel.getValue()); + assertEquals(parent, this.testModel.getValue()); Person person1 = new Person("Matt", "Mitch", null); - this.objectHolder.setValue(person1); - Person parent2 = this.transformationObjectHolder.getValue(); + this.personModel.setValue(person1); + Person parent2 = this.testModel.getValue(); assertEquals(person1.getParent().getName(), parent2.getName()); - assertNotSame(person1.getParent(), this.transformationObjectHolder.getValue()); - assertEquals(parent2, this.transformationObjectHolder.getValue()); + assertNotSame(person1.getParent(), this.testModel.getValue()); + assertEquals(parent2, this.testModel.getValue()); - this.objectHolder.setValue(null); - assertNull(this.objectHolder.getValue()); - assertNull(this.transformationObjectHolder.getValue()); + this.personModel.setValue(null); + assertNull(this.personModel.getValue()); + assertNull(this.testModel.getValue()); Person person3 = new Person("Karen", "Peggy", null); - this.objectHolder.setValue(person3); + this.personModel.setValue(person3); assertEquals("Karen", person3.getName()); - Person parent3 = this.transformationObjectHolder.getValue(); + Person parent3 = this.testModel.getValue(); assertEquals(person3.getParent().getName(), parent3.getName()); - assertNotSame(person3.getParent(), this.transformationObjectHolder.getValue()); - assertEquals(parent3, this.transformationObjectHolder.getValue()); + assertNotSame(person3.getParent(), this.testModel.getValue()); + assertEquals(parent3, this.testModel.getValue()); } public void testSetValue() { ChangeListener listener = this.buildTransformationListener(); - this.transformationObjectHolder.addChangeListener(listener); + this.testModel.addChangeListener(listener); Person person = new Person("Chris", "Noel", null); - this.transformationObjectHolder.setValue(person.getParent()); - assertEquals(person, this.objectHolder.getValue()); - assertEquals(person.getParent().getName(), this.transformationObjectHolder.getValue().getName()); - assertNotSame(person.getParent(), this.transformationObjectHolder.getValue()); + this.testModel.setValue(person.getParent()); + assertEquals(person, this.personModel.getValue()); + assertEquals(person.getParent().getName(), this.testModel.getValue().getName()); + assertNotSame(person.getParent(), this.testModel.getValue()); Person person2 = new Person("Jon", "Elizabeth", null); - this.transformationObjectHolder.setValue(person2.getParent()); - assertEquals(person2, this.objectHolder.getValue()); - assertEquals(person2.getParent().getName(), this.transformationObjectHolder.getValue().getName()); - assertNotSame(person2.getParent(), this.transformationObjectHolder.getValue()); - - this.transformationObjectHolder.setValue(null); - assertNull(this.objectHolder.getValue()); - assertNull(this.transformationObjectHolder.getValue()); - - this.transformationObjectHolder.setValue(person.getParent()); - assertEquals(person, this.objectHolder.getValue()); - assertEquals(person.getParent().getName(), this.transformationObjectHolder.getValue().getName()); - assertNotSame(person.getParent(), this.transformationObjectHolder.getValue()); + this.testModel.setValue(person2.getParent()); + assertEquals(person2, this.personModel.getValue()); + assertEquals(person2.getParent().getName(), this.testModel.getValue().getName()); + assertNotSame(person2.getParent(), this.testModel.getValue()); + + this.testModel.setValue(null); + assertNull(this.personModel.getValue()); + assertNull(this.testModel.getValue()); + + this.testModel.setValue(person.getParent()); + assertEquals(person, this.personModel.getValue()); + assertEquals(person.getParent().getName(), this.testModel.getValue().getName()); + assertNotSame(person.getParent(), this.testModel.getValue()); } public void testLazyListening() { - assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); + assertTrue(((AbstractModel) this.personModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); ChangeListener listener = this.buildTransformationListener(); - this.transformationObjectHolder.addChangeListener(listener); - assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.transformationObjectHolder.removeChangeListener(listener); - assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - - this.transformationObjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, listener); - assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.transformationObjectHolder.removePropertyChangeListener(PropertyValueModel.VALUE, listener); - assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); + this.testModel.addChangeListener(listener); + assertTrue(((AbstractModel) this.personModel).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); + this.testModel.removeChangeListener(listener); + assertTrue(((AbstractModel) this.personModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); + + this.testModel.addPropertyChangeListener(PropertyValueModel.VALUE, listener); + assertTrue(((AbstractModel) this.personModel).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); + this.testModel.removePropertyChangeListener(PropertyValueModel.VALUE, listener); + assertTrue(((AbstractModel) this.personModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); } public void testPropertyChange1() { - this.objectHolder.addChangeListener(this.buildListener()); - this.transformationObjectHolder.addChangeListener(this.buildTransformationListener()); + this.personModel.addChangeListener(this.buildListener()); + this.testModel.addChangeListener(this.buildTransformationListener()); this.verifyPropertyChanges(); } public void testPropertyChange2() { - this.objectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener()); - this.transformationObjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildTransformationListener()); + this.personModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener()); + this.testModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildTransformationListener()); this.verifyPropertyChanges(); } private void verifyPropertyChanges() { - this.event = null; + this.personEvent = null; this.transformationEvent = null; - Person oldPerson = this.objectHolder.getValue(); - Person oldParent = this.transformationObjectHolder.getValue(); + Person oldPerson = this.personModel.getValue(); + Person oldParent = this.testModel.getValue(); Person newPerson = new Person("Karen" , "Peggy", null); - this.objectHolder.setValue(newPerson); - Person newParent = this.transformationObjectHolder.getValue(); - this.verifyEvent(this.event, this.objectHolder, oldPerson, newPerson); - this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, oldParent, newParent); - -// -// this.event = null; -// this.transformationEvent = null; -// this.objectHolder.setValue("Foo"); -// this.verifyEvent(this.event, this.objectHolder, "baz", "Foo"); -// this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, "BAZ", "FOO"); -// -// this.event = null; -// this.transformationEvent = null; -// this.objectHolder.setValue("FOO"); -// this.verifyEvent(this.event, this.objectHolder, "Foo", "FOO"); -// assertNull(this.transformationEvent); -// -// this.event = null; -// this.transformationEvent = null; -// this.objectHolder.setValue(null); -// this.verifyEvent(this.event, this.objectHolder, "FOO", null); -// this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, "FOO", null); -// -// this.event = null; -// this.transformationEvent = null; -// this.objectHolder.setValue("bar"); -// this.verifyEvent(this.event, this.objectHolder, null, "bar"); -// this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, null, "BAR"); + this.personModel.setValue(newPerson); + Person newParent = this.testModel.getValue(); + this.verifyEvent(this.personEvent, this.personModel, oldPerson, newPerson); + this.verifyEvent(this.transformationEvent, this.testModel, oldParent, newParent); } private ChangeListener buildListener() { return new ChangeAdapter() { @Override public void propertyChanged(PropertyChangeEvent e) { - TransformationModifiablePropertyValueModelTests.this.event = e; + TransformationModifiablePropertyValueModelTests.this.personEvent = e; } }; } @@ -190,6 +165,7 @@ public class TransformationModifiablePropertyValueModelTests } private void verifyEvent(PropertyChangeEvent e, Object source, Object oldValue, Object newValue) { + assertNotNull(e); assertEquals(source, e.getSource()); assertEquals(PropertyValueModel.VALUE, e.getPropertyName()); assertEquals(oldValue, e.getOldValue()); diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TransformationPropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TransformationPropertyValueModelTests.java index f7a837d0a3..4d7248c792 100644 --- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TransformationPropertyValueModelTests.java +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TransformationPropertyValueModelTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2013 Oracle. All rights reserved. + * Copyright (c) 2007, 2016 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -9,10 +9,9 @@ ******************************************************************************/ package org.eclipse.jpt.common.utility.tests.internal.model.value; -import junit.framework.TestCase; import org.eclipse.jpt.common.utility.internal.model.AbstractModel; +import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools; import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.common.utility.internal.model.value.TransformationModifiablePropertyValueModel; import org.eclipse.jpt.common.utility.internal.transformer.AbstractTransformer; import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent; import org.eclipse.jpt.common.utility.model.listener.ChangeAdapter; @@ -21,16 +20,17 @@ import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel; import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; import org.eclipse.jpt.common.utility.tests.internal.TestTools; import org.eclipse.jpt.common.utility.transformer.Transformer; +import junit.framework.TestCase; @SuppressWarnings("nls") public class TransformationPropertyValueModelTests extends TestCase { - private ModifiablePropertyValueModel<String> objectHolder; - PropertyChangeEvent event; + private ModifiablePropertyValueModel<String> stringModel; + PropertyChangeEvent stringEvent; - private ModifiablePropertyValueModel<String> transformationObjectHolder; - PropertyChangeEvent transformationEvent; + private ModifiablePropertyValueModel<String> testModel; + PropertyChangeEvent testEvent; public TransformationPropertyValueModelTests(String name) { super(name); @@ -39,8 +39,8 @@ public class TransformationPropertyValueModelTests @Override protected void setUp() throws Exception { super.setUp(); - this.objectHolder = new SimplePropertyValueModel<String>("foo"); - this.transformationObjectHolder = new TransformationModifiablePropertyValueModel<String, String>(this.objectHolder, UPPER_CASE_TRANSFORMER, LOWER_CASE_TRANSFORMER); + this.stringModel = new SimplePropertyValueModel<>("foo"); + this.testModel = PropertyValueModelTools.transform_(this.stringModel, UPPER_CASE_TRANSFORMER, LOWER_CASE_TRANSFORMER); } private static final Transformer<String, String> UPPER_CASE_TRANSFORMER = new UpperCaseTransformer(); @@ -70,125 +70,125 @@ public class TransformationPropertyValueModelTests } public void testValue() { - assertEquals("foo", this.objectHolder.getValue()); - assertNull(this.transformationObjectHolder.getValue()); + assertEquals("foo", this.stringModel.getValue()); + assertNull(this.testModel.getValue()); ChangeListener listener = this.buildTransformationListener(); - this.transformationObjectHolder.addChangeListener(listener); - assertEquals("FOO", this.transformationObjectHolder.getValue()); + this.testModel.addChangeListener(listener); + assertEquals("FOO", this.testModel.getValue()); - this.objectHolder.setValue("bar"); - assertEquals("bar", this.objectHolder.getValue()); - assertEquals("BAR", this.transformationObjectHolder.getValue()); + this.stringModel.setValue("bar"); + assertEquals("bar", this.stringModel.getValue()); + assertEquals("BAR", this.testModel.getValue()); - this.objectHolder.setValue("baz"); - assertEquals("baz", this.objectHolder.getValue()); - assertEquals("BAZ", this.transformationObjectHolder.getValue()); + this.stringModel.setValue("baz"); + assertEquals("baz", this.stringModel.getValue()); + assertEquals("BAZ", this.testModel.getValue()); - this.objectHolder.setValue(null); - assertNull(this.objectHolder.getValue()); - assertNull(this.transformationObjectHolder.getValue()); + this.stringModel.setValue(null); + assertNull(this.stringModel.getValue()); + assertNull(this.testModel.getValue()); - this.objectHolder.setValue("foo"); - assertEquals("foo", this.objectHolder.getValue()); - assertEquals("FOO", this.transformationObjectHolder.getValue()); + this.stringModel.setValue("foo"); + assertEquals("foo", this.stringModel.getValue()); + assertEquals("FOO", this.testModel.getValue()); } public void testSetValue() { - this.transformationObjectHolder.setValue("BAR"); - assertEquals("bar", this.objectHolder.getValue()); - assertEquals("BAR", this.transformationObjectHolder.getValue()); + this.testModel.setValue("BAR"); + assertEquals("bar", this.stringModel.getValue()); + assertNull(this.testModel.getValue()); // no listeners // NB: odd behavior(!) - this.transformationObjectHolder.setValue("Foo"); - assertEquals("foo", this.objectHolder.getValue()); - assertEquals("Foo", this.transformationObjectHolder.getValue()); + this.testModel.setValue("Foo"); + assertEquals("foo", this.stringModel.getValue()); + assertNull(this.testModel.getValue()); // still no listeners ChangeListener listener = this.buildTransformationListener(); - this.transformationObjectHolder.addChangeListener(listener); - assertEquals("FOO", this.transformationObjectHolder.getValue()); - this.transformationObjectHolder.removeChangeListener(listener); + this.testModel.addChangeListener(listener); + assertEquals("FOO", this.testModel.getValue()); + this.testModel.removeChangeListener(listener); - this.transformationObjectHolder.setValue(null); - assertNull(this.objectHolder.getValue()); - assertNull(this.transformationObjectHolder.getValue()); + this.testModel.setValue(null); + assertNull(this.stringModel.getValue()); + assertNull(this.testModel.getValue()); // NB: odd behavior(!) - this.transformationObjectHolder.setValue("baz"); - assertEquals("baz", this.objectHolder.getValue()); - assertEquals("baz", this.transformationObjectHolder.getValue()); - this.transformationObjectHolder.addChangeListener(listener); - assertEquals("BAZ", this.transformationObjectHolder.getValue()); - this.transformationObjectHolder.removeChangeListener(listener); + this.testModel.setValue("baz"); + assertEquals("baz", this.stringModel.getValue()); + assertNull(this.testModel.getValue()); // no listeners + this.testModel.addChangeListener(listener); + assertEquals("BAZ", this.testModel.getValue()); + this.testModel.removeChangeListener(listener); } public void testLazyListening() { - assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); + assertTrue(((AbstractModel) this.stringModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); ChangeListener listener = this.buildTransformationListener(); - this.transformationObjectHolder.addChangeListener(listener); - assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.transformationObjectHolder.removeChangeListener(listener); - assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - - this.transformationObjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, listener); - assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.transformationObjectHolder.removePropertyChangeListener(PropertyValueModel.VALUE, listener); - assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); + this.testModel.addChangeListener(listener); + assertTrue(((AbstractModel) this.stringModel).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); + this.testModel.removeChangeListener(listener); + assertTrue(((AbstractModel) this.stringModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); + + this.testModel.addPropertyChangeListener(PropertyValueModel.VALUE, listener); + assertTrue(((AbstractModel) this.stringModel).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); + this.testModel.removePropertyChangeListener(PropertyValueModel.VALUE, listener); + assertTrue(((AbstractModel) this.stringModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); } public void testPropertyChange1() { - this.objectHolder.addChangeListener(this.buildListener()); - this.transformationObjectHolder.addChangeListener(this.buildTransformationListener()); + this.stringModel.addChangeListener(this.buildListener()); + this.testModel.addChangeListener(this.buildTransformationListener()); this.verifyPropertyChanges(); } public void testPropertyChange2() { - this.objectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener()); - this.transformationObjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildTransformationListener()); + this.stringModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener()); + this.testModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildTransformationListener()); this.verifyPropertyChanges(); } private void verifyPropertyChanges() { - this.event = null; - this.transformationEvent = null; - this.objectHolder.setValue("bar"); - this.verifyEvent(this.event, this.objectHolder, "foo", "bar"); - this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, "FOO", "BAR"); - - this.event = null; - this.transformationEvent = null; - this.objectHolder.setValue("baz"); - this.verifyEvent(this.event, this.objectHolder, "bar", "baz"); - this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, "BAR", "BAZ"); - - this.event = null; - this.transformationEvent = null; - this.objectHolder.setValue("Foo"); - this.verifyEvent(this.event, this.objectHolder, "baz", "Foo"); - this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, "BAZ", "FOO"); - - this.event = null; - this.transformationEvent = null; - this.objectHolder.setValue("FOO"); - this.verifyEvent(this.event, this.objectHolder, "Foo", "FOO"); - assertNull(this.transformationEvent); - - this.event = null; - this.transformationEvent = null; - this.objectHolder.setValue(null); - this.verifyEvent(this.event, this.objectHolder, "FOO", null); - this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, "FOO", null); - - this.event = null; - this.transformationEvent = null; - this.objectHolder.setValue("bar"); - this.verifyEvent(this.event, this.objectHolder, null, "bar"); - this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, null, "BAR"); + this.stringEvent = null; + this.testEvent = null; + this.stringModel.setValue("bar"); + this.verifyEvent(this.stringEvent, this.stringModel, "foo", "bar"); + this.verifyEvent(this.testEvent, this.testModel, "FOO", "BAR"); + + this.stringEvent = null; + this.testEvent = null; + this.stringModel.setValue("baz"); + this.verifyEvent(this.stringEvent, this.stringModel, "bar", "baz"); + this.verifyEvent(this.testEvent, this.testModel, "BAR", "BAZ"); + + this.stringEvent = null; + this.testEvent = null; + this.stringModel.setValue("Foo"); + this.verifyEvent(this.stringEvent, this.stringModel, "baz", "Foo"); + this.verifyEvent(this.testEvent, this.testModel, "BAZ", "FOO"); + + this.stringEvent = null; + this.testEvent = null; + this.stringModel.setValue("FOO"); + this.verifyEvent(this.stringEvent, this.stringModel, "Foo", "FOO"); + assertNull(this.testEvent); + + this.stringEvent = null; + this.testEvent = null; + this.stringModel.setValue(null); + this.verifyEvent(this.stringEvent, this.stringModel, "FOO", null); + this.verifyEvent(this.testEvent, this.testModel, "FOO", null); + + this.stringEvent = null; + this.testEvent = null; + this.stringModel.setValue("bar"); + this.verifyEvent(this.stringEvent, this.stringModel, null, "bar"); + this.verifyEvent(this.testEvent, this.testModel, null, "BAR"); } private ChangeListener buildListener() { return new ChangeAdapter() { @Override public void propertyChanged(PropertyChangeEvent e) { - TransformationPropertyValueModelTests.this.event = e; + TransformationPropertyValueModelTests.this.stringEvent = e; } }; } @@ -197,7 +197,7 @@ public class TransformationPropertyValueModelTests return new ChangeAdapter() { @Override public void propertyChanged(PropertyChangeEvent e) { - TransformationPropertyValueModelTests.this.transformationEvent = e; + TransformationPropertyValueModelTests.this.testEvent = e; } }; } diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/prefs/PreferencePropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/prefs/PreferencePropertyValueModelTests.java index b527dabc90..0aef2cbd3a 100644 --- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/prefs/PreferencePropertyValueModelTests.java +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/prefs/PreferencePropertyValueModelTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2013 Oracle. All rights reserved. + * Copyright (c) 2007, 2016 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -47,7 +47,7 @@ public class PreferencePropertyValueModelTests extends PreferencesTestCase { super.setUp(); this.testNode.put(KEY_NAME, STRING_VALUE); - this.nodeHolder = new SimplePropertyValueModel<Preferences>(this.testNode); + this.nodeHolder = new SimplePropertyValueModel<>(this.testNode); this.preferenceAdapter = PreferencePropertyValueModel.forString(this.nodeHolder, KEY_NAME, null); this.listener = this.buildValueChangeListener(); this.preferenceAdapter.addPropertyChangeListener(PropertyValueModel.VALUE, this.listener); @@ -387,7 +387,7 @@ public class PreferencePropertyValueModelTests extends PreferencesTestCase { extends PreferencePropertyValueModel<P> { public static PreferencePropertyValueModel<String> forString(PropertyValueModel<? extends Preferences> preferencesModel, String key, String defaultValue) { - return new AlwaysUpdatePreferencePropertyValueModel<String>( + return new AlwaysUpdatePreferencePropertyValueModel<>( preferencesModel, key, defaultValue, diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/swing/TreeModelAdapterTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/swing/TreeModelAdapterTests.java index 97d635aef9..2724f9c2e3 100644 --- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/swing/TreeModelAdapterTests.java +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/swing/TreeModelAdapterTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2013 Oracle. All rights reserved. + * Copyright (c) 2007, 2016 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -20,7 +20,6 @@ import javax.swing.JTree; import javax.swing.event.TreeModelEvent; import javax.swing.event.TreeModelListener; import javax.swing.tree.TreeModel; -import junit.framework.TestCase; import org.eclipse.jpt.common.utility.internal.ObjectTools; import org.eclipse.jpt.common.utility.internal.collection.HashBag; import org.eclipse.jpt.common.utility.internal.iterator.IteratorTools; @@ -30,10 +29,10 @@ import org.eclipse.jpt.common.utility.internal.model.value.CollectionAspectAdapt import org.eclipse.jpt.common.utility.internal.model.value.ItemPropertyListValueModelAdapter; import org.eclipse.jpt.common.utility.internal.model.value.NullListValueModel; import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools; import org.eclipse.jpt.common.utility.internal.model.value.SimpleListValueModel; import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel; import org.eclipse.jpt.common.utility.internal.model.value.SortedListValueModelWrapper; -import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel; import org.eclipse.jpt.common.utility.internal.model.value.TransformationListValueModel; import org.eclipse.jpt.common.utility.internal.model.value.swing.TreeModelAdapter; import org.eclipse.jpt.common.utility.io.IndentingPrintWriter; @@ -47,6 +46,7 @@ import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel; import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; import org.eclipse.jpt.common.utility.model.value.TreeNodeValueModel; import org.eclipse.jpt.common.utility.tests.internal.model.Displayable; +import junit.framework.TestCase; @SuppressWarnings("nls") public class TreeModelAdapterTests extends TestCase { @@ -189,8 +189,8 @@ public class TreeModelAdapterTests extends TestCase { } public void testTreeStructureChanged() { - ModifiablePropertyValueModel<TreeNodeValueModel<Object>> nodeHolder = new SimplePropertyValueModel<TreeNodeValueModel<Object>>(this.buildSortedRootNode()); - TreeModel treeModel = this.buildTreeModel(nodeHolder); + ModifiablePropertyValueModel<TreeNodeValueModel<Object>> nodeModel = new SimplePropertyValueModel<>(this.buildSortedRootNode()); + TreeModel treeModel = this.buildTreeModel(nodeModel); this.eventFired = false; treeModel.addTreeModelListener(new TestTreeModelListener() { @Override @@ -206,7 +206,7 @@ public class TreeModelAdapterTests extends TestCase { TreeModelAdapterTests.this.eventFired = true; } }); - nodeHolder.setValue(this.buildUnsortedRootNode()); + nodeModel.setValue(this.buildUnsortedRootNode()); assertTrue(this.eventFired); } @@ -303,7 +303,7 @@ public class TreeModelAdapterTests extends TestCase { super(); this.parent = parent; this.name = name; - this.children = new HashBag<TestModel>(); + this.children = new HashBag<>(); } public TestModel getParent() { @@ -358,8 +358,9 @@ public class TreeModelAdapterTests extends TestCase { public String dumpString() { StringWriter sw = new StringWriter(); - IndentingPrintWriter ipw = new IndentingPrintWriter(sw); - this.dumpOn(ipw); + try (IndentingPrintWriter ipw = new IndentingPrintWriter(sw)) { + this.dumpOn(ipw); + } return sw.toString(); } public void dumpOn(IndentingPrintWriter writer) { @@ -371,9 +372,10 @@ public class TreeModelAdapterTests extends TestCase { writer.undent(); } public void dumpOn(OutputStream stream) { - IndentingPrintWriter writer = new IndentingPrintWriter(new OutputStreamWriter(stream)); - this.dumpOn(writer); - writer.flush(); + try (IndentingPrintWriter writer = new IndentingPrintWriter(new OutputStreamWriter(stream))) { + this.dumpOn(writer); + writer.flush(); + } } public void dump() { this.dumpOn(System.out); @@ -516,8 +518,9 @@ public class TreeModelAdapterTests extends TestCase { public String dumpString() { StringWriter sw = new StringWriter(); - IndentingPrintWriter ipw = new IndentingPrintWriter(sw); - this.dumpOn(ipw); + try (IndentingPrintWriter ipw = new IndentingPrintWriter(sw)) { + this.dumpOn(ipw); + } return sw.toString(); } @@ -532,9 +535,10 @@ public class TreeModelAdapterTests extends TestCase { } public void dumpOn(OutputStream stream) { - IndentingPrintWriter writer = new IndentingPrintWriter(new OutputStreamWriter(stream)); - this.dumpOn(writer); - writer.flush(); + try (IndentingPrintWriter writer = new IndentingPrintWriter(new OutputStreamWriter(stream))) { + this.dumpOn(writer); + writer.flush(); + } } public void dump() { @@ -607,11 +611,11 @@ public class TreeModelAdapterTests extends TestCase { /** the list should be sorted */ @Override protected ListValueModel<TreeNodeValueModel<Object>> buildChildrenModel(TestModel testModel) { - return new SortedListValueModelWrapper<TreeNodeValueModel<Object>>(this.buildDisplayStringAdapter(testModel)); + return new SortedListValueModelWrapper<>(this.buildDisplayStringAdapter(testModel)); } /** the display string (name) of each node can change */ protected ListValueModel<TreeNodeValueModel<Object>> buildDisplayStringAdapter(TestModel testModel) { - return new ItemPropertyListValueModelAdapter<TreeNodeValueModel<Object>>(this.buildNodeAdapter(testModel), DISPLAY_STRING_PROPERTY); + return new ItemPropertyListValueModelAdapter<>(this.buildNodeAdapter(testModel), DISPLAY_STRING_PROPERTY); } /** children are also sorted nodes */ @Override @@ -676,7 +680,7 @@ public class TreeModelAdapterTests extends TestCase { protected ListValueModel<TreeNodeValueModel<Object>> buildSpecialChildrenModel() { TreeNodeValueModel<Object>[] children = new NameTestNode[1]; children[0] = new NameTestNode(this); - return new SimpleListValueModel<TreeNodeValueModel<Object>>(Arrays.asList(children)); + return new SimpleListValueModel<>(Arrays.asList(children)); } /** children are also special nodes */ @Override @@ -700,7 +704,7 @@ public class TreeModelAdapterTests extends TestCase { this.nameListener = this.buildNameListener(); this.specialNode = specialNode; this.nameAdapter = this.buildNameAdapter(); - this.childrenModel = new NullListValueModel<TreeNodeValueModel<Object>>(); + this.childrenModel = new NullListValueModel<>(); } protected PropertyChangeListener buildNameListener() { return new PropertyChangeListener() { @@ -762,11 +766,12 @@ public class TreeModelAdapterTests extends TestCase { } private TreeModel buildTreeModel(TestNode root) { - return this.buildTreeModel(new StaticPropertyValueModel<TreeNodeValueModel<Object>>(root)); + return this.buildTreeModel(PropertyValueModelTools.staticPropertyValueModel(root)); } - private TreeModel buildTreeModel(PropertyValueModel<TreeNodeValueModel<Object>> rootHolder) { - return new TreeModelAdapter<Object>(rootHolder) { + private TreeModel buildTreeModel(PropertyValueModel<TreeNodeValueModel<Object>> rootModel) { + return new TreeModelAdapter<Object>(rootModel) { + private static final long serialVersionUID = 1L; @Override protected ListChangeListener buildChildrenListener() { return this.buildChildrenListener_(); |