You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Michael Wooten <mw...@gmail.com> on 2009/08/09 22:37:53 UTC
[LANG] Suggestions For New Features
These are several additions that I feel might be useful to the Commons Lang
Project. Please feel free to provide feedback, and if there is enough
interest in any of them I will create JIRA entries, code them, and provide
patches.
Expand Validate to include more specific, human readable validation for
commonly validated paramter values (so isTrue() isn't needed as often).
Include new Validate methods:
- isFile(File file)
- throws an IllegalArgumentException stating "The file " + file + " is
not a regular file" when the provided file is not a regular file
(File.isFile()).
- isFile(File file, String message)
- throws an IllegalArgumentException stating (message + file) when the
provided file is not a regular file (File.isFile()).
- isDirectory(File directory)
- throws an IllegalArgumentException stating "The file " + file + " is
not a directory" when the provided file is not a directory
(File.isDirectory()).
- isDirectory(File directory, String message)
- throws an IllegalArgumentException stating (message + file) when the
provided file is not a directory (File.isDirectory()).
- isReadable(File file)
- throws an IllegalArgumentException stating "The file " + file + "
cannot be read" when the provided file is unreadable (File.canRead()).
- isReadable(File file, String message)
- throws an IllegalArgumentException stating (message + file) when the
provided file is unreadable (File.canRead()).
- isWritable(File file)
- throws an IllegalArgumentException stating "The file " + file + "
cannot be written to" when the provided file is unwritable
(File.canWrite()).
- isWritable(File file, String message)
- throws an IllegalArgumentException stating (message + file) when the
provided file is unwritable (File.canWrite()).
- fileExists(File file)
- throws an IllegalArgumentException stating "The file " + file + "
does not exist" when the provided file does not exist (File.exists()).
- fileExists(File file, String message)
- throws an IllegalArgumentException stating (message + file) when the
provided file does not exist (File.exists()).
- matchesPattern(String string, String pattern)
- throws an IllegalArgumentException stating ("The string " + string +
" does not match the pattern " + pattern) when the provided
string does not
match the regular expression pattern.
- matchesPattern(String string, String pattern, String message)
- throws an IllegalArgumentException stating (message + string) when
the provided string does not match the regular expression pattern.
- matchesPattern(String string, Pattern pattern)
- throws an IllegalArgumentException stating ("The string " + string +
" does not match the pattern " + pattern) when the provided
string does not
match the regular expression pattern.
- matchesPattern(String string, Pattern pattern, String message)
- throws an IllegalArgumentException stating (message + string) when
the provided string does not match the regular expression pattern.
- inRange(Comparable<T> start, Comparable<T> end, Comparable<T> value)
- throws an IllegalArgumentException stating ("The value " + value + "
is not in the specified range of " + start + " to " + end) when
the provided
value does not fall between the two comparable values.
- inRange(Comparable<T> start, Comparable<T> end, Comparable<T> value,
String message)
- throws an IllegalArgumentException stating (message + value) when
the provided value does not fall between the two comparable values.
- sizeInRange(int minSize, int maxSize, T[] array, String message)
- throws an IllegalArgumentException stating (message + value) when
the length of the provided array does not fall between the minimum and
maximum size values (inclusive).
- sizeInRange(int minSize, int maxSize, Collection<?> collection, String
message)
- throws an IllegalArgumentException stating (message + value) when
the length of the provided collection does not fall between the
minimum and
maximum size values (inclusive).
- sizeInRange(int minSize, int maxSize, Map<?, ?> map, String message)
- throws an IllegalArgumentException stating (message + value) when
the length of the provided map does not fall between the minimum
and maximum
size values (inclusive).
- sizeInRange(int minSize, int maxSize, String string, String message)
- throws an IllegalArgumentException stating (message + value) when
the length of the provided string does not fall between the minimum and
maximum size values (inclusive).
I would also like to propose some support be added to Lang for basic event
handling. This would be based on the way that PropertyChangeSupport can be
used to add and remove listeners and post events.
Add interface EventSupport<L extends EventListener>
- addListener(L listener)
- The signature for the method that can add a listener of some subtype of
EventListener
- removeListener(L listener)
- The signature for the method that can remove a listener of some subtype
of EventListener
Add class AbstractEventSupport implements EventSupport<L>, Iterable<L>
- AbstractEventSupport(Object eventSource)
- Constructs a new AbstractEventSupport object and associates it with the
object that will be used as the source of all events (much like
PropertyChangeSupport).
- addListener(L)
- An implementation that adds a listener to an internal collection.
- removeListener(L)
- An implementation that removes a listener from an internal collection.
- iterator()
- Returns an iterator over the attached listeners.
- getSource()
- Returns a reference to the source object of all events.
The best way to describe this would be to demonstrate an example of how it
can be used.
public class ButtonPressedEventSupport extends
AbstractEventSupport<ButtonPressedListener> {
public ButtonPressedEventSupport(Object source) { super(source); }
public void fireButtonPressed(Button button) {
ButtonPressedEvent bpe = new ButtonPressedEvent(getSource(),
button);
for (ButtonPressedListener listener : this)
{
listener.buttonPressed(bpe);
}
}
}
public class MyWindow implements EventSupport<ButtonPressedListener> {
private final ButtonPressedEventSupport buttonPressedEventSupport;
public MyWindow { buttonPressedEventSupport = new
ButtonPressedEventSupport(this); }
public void addListener(ButtonPressedListener listener) {
buttonPressedEventSupport.addListener(listener); }
public void removeListener(ButtonPressedListener listener) {
buttonPressedEventSupport.removeListener(listener); }
...
private void onDetectButtonPressed(Button button) {
buttonPressedEventSupport.fireButtonPressed(button);
}
}
I haven't compiled the above code. It's just an example of how these classes
could be used so that you're not constantly rewriting the code and
interfaces for adding and removing listeners, and it provides a fairly easy
method of creating methods to fire events.
So, anyone have thoughts or opinions on these proposed features?
-Michael Wooten
Re: [LANG] Suggestions For New Features
Posted by Henri Yandell <fl...@gmail.com>.
Thanks for posting.
On the IO Active comment - it is something we need to figure out how
to do better. I've a set of components I rotate between for example:
IO, Lang, CLI, Codec, Collections amongst others.
I know there are others who do the same kind of thing.
But then we do have components that are less less likely to see a
release/update.
Anyway - feel free to open a JIRA up for IO. I suspect that once Lang
3.0 is out, I'll be interested in an IO 2.0 unless someone gets there
before me.
Hen
On Wed, Jan 6, 2010 at 8:49 AM, Michael Wooten <mw...@gmail.com> wrote:
> Hey All,
>
> I know this is from a long time ago, but I finally created JIRA entries (
> LANG-579 <http://issues.apache.org/jira/browse/LANG-579> and
> LANG-580<http://issues.apache.org/jira/browse/LANG-580>)
> for these features. I changed the inRange() methods to be inclusiveBetween()
> and exclusiveBetween() to handle the issue of inclusiveness. I removed the
> suggestions for the Validate methods related to IO. I will consider
> submitting a proposal for an IoValidate class to the IO project, but IO
> doesn't seem to be active at all.
>
> Feel free to post comments on my suggestions.
>
> Thanks.
>
> -Michael
>
> On Thu, Aug 20, 2009 at 7:27 AM, James Carman <ja...@carmanconsulting.com>wrote:
>
>> On Thu, Aug 20, 2009 at 8:23 AM, Michael Wooten<mw...@gmail.com>
>> wrote:
>> > I was assuming I would use the fact that compareTo() returns 0 for the
>> case
>> > of equality. My original assumption was the test would be as simple as
>> > ((value.compareTo(start) >= 0) && (value.compareTo(end) <= 0)). However,
>> as
>> > the documentation for Comparable states, compareTo()'s 0 return may not
>> be
>> > equivalent to equals(), so feel free to debate how this would be
>> > implemented. It may just be the case that the behavior be documented in
>> the
>> > API.
>> >
>> > Additional thoughts?
>>
>> I meant how are you going to allow for less than vs. less than or
>> equal to on the boundaries of your range with this API?
>>
>> And, compareTo() == 0 only means that objects are equivalent with
>> respect to the comparison being performed. It doesn't necessarily
>> mean they're the same object, as you pointed out (two distinct Person
>> objects with the same last name would show a comparison value of 0 if
>> comparing by last name only).
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [LANG] Suggestions For New Features
Posted by Michael Wooten <mw...@gmail.com>.
Hey All,
I know this is from a long time ago, but I finally created JIRA entries (
LANG-579 <http://issues.apache.org/jira/browse/LANG-579> and
LANG-580<http://issues.apache.org/jira/browse/LANG-580>)
for these features. I changed the inRange() methods to be inclusiveBetween()
and exclusiveBetween() to handle the issue of inclusiveness. I removed the
suggestions for the Validate methods related to IO. I will consider
submitting a proposal for an IoValidate class to the IO project, but IO
doesn't seem to be active at all.
Feel free to post comments on my suggestions.
Thanks.
-Michael
On Thu, Aug 20, 2009 at 7:27 AM, James Carman <ja...@carmanconsulting.com>wrote:
> On Thu, Aug 20, 2009 at 8:23 AM, Michael Wooten<mw...@gmail.com>
> wrote:
> > I was assuming I would use the fact that compareTo() returns 0 for the
> case
> > of equality. My original assumption was the test would be as simple as
> > ((value.compareTo(start) >= 0) && (value.compareTo(end) <= 0)). However,
> as
> > the documentation for Comparable states, compareTo()'s 0 return may not
> be
> > equivalent to equals(), so feel free to debate how this would be
> > implemented. It may just be the case that the behavior be documented in
> the
> > API.
> >
> > Additional thoughts?
>
> I meant how are you going to allow for less than vs. less than or
> equal to on the boundaries of your range with this API?
>
> And, compareTo() == 0 only means that objects are equivalent with
> respect to the comparison being performed. It doesn't necessarily
> mean they're the same object, as you pointed out (two distinct Person
> objects with the same last name would show a comparison value of 0 if
> comparing by last name only).
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
Re: [LANG] Suggestions For New Features
Posted by James Carman <ja...@carmanconsulting.com>.
On Thu, Aug 20, 2009 at 8:23 AM, Michael Wooten<mw...@gmail.com> wrote:
> I was assuming I would use the fact that compareTo() returns 0 for the case
> of equality. My original assumption was the test would be as simple as
> ((value.compareTo(start) >= 0) && (value.compareTo(end) <= 0)). However, as
> the documentation for Comparable states, compareTo()'s 0 return may not be
> equivalent to equals(), so feel free to debate how this would be
> implemented. It may just be the case that the behavior be documented in the
> API.
>
> Additional thoughts?
I meant how are you going to allow for less than vs. less than or
equal to on the boundaries of your range with this API?
And, compareTo() == 0 only means that objects are equivalent with
respect to the comparison being performed. It doesn't necessarily
mean they're the same object, as you pointed out (two distinct Person
objects with the same last name would show a comparison value of 0 if
comparing by last name only).
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [LANG] Suggestions For New Features
Posted by Michael Wooten <mw...@gmail.com>.
On Tue, Aug 11, 2009 at 8:31 AM, James Carman <ja...@carmanconsulting.com>wrote:
> On Tue, Aug 11, 2009 at 2:09 AM, Henri Yandell<fl...@gmail.com> wrote:
> >> - sizeInRange(int minSize, int maxSize, String string, String message)
> >> - throws an IllegalArgumentException stating (message + value) when
> >> the length of the provided string does not fall between the minimum
> and
> >> maximum size values (inclusive).
> >
> > I like 'between' more than 'inRange'.
> >
> > I think a simpler API would be (ignoring the String message overloads):
> >
> > between(Comparable<T> start, Comparable<T> end, Comparable<T> value)
> > between(int minSize, int maxSize, int value)
>
> >> How would you account for the "inclusiveness" of both sides?
>
I was assuming I would use the fact that compareTo() returns 0 for the case
of equality. My original assumption was the test would be as simple as
((value.compareTo(start) >= 0) && (value.compareTo(end) <= 0)). However, as
the documentation for Comparable states, compareTo()'s 0 return may not be
equivalent to equals(), so feel free to debate how this would be
implemented. It may just be the case that the behavior be documented in the
API.
Additional thoughts?
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
Re: [LANG] Suggestions For New Features
Posted by James Carman <ja...@carmanconsulting.com>.
On Tue, Aug 11, 2009 at 2:09 AM, Henri Yandell<fl...@gmail.com> wrote:
>> - sizeInRange(int minSize, int maxSize, String string, String message)
>> - throws an IllegalArgumentException stating (message + value) when
>> the length of the provided string does not fall between the minimum and
>> maximum size values (inclusive).
>
> I like 'between' more than 'inRange'.
>
> I think a simpler API would be (ignoring the String message overloads):
>
> between(Comparable<T> start, Comparable<T> end, Comparable<T> value)
> between(int minSize, int maxSize, int value)
How would you account for the "inclusiveness" of both sides?
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [LANG] Suggestions For New Features
Posted by Henri Yandell <fl...@gmail.com>.
On Mon, Aug 10, 2009 at 11:09 PM, Henri Yandell<fl...@gmail.com> wrote:
> On Sun, Aug 9, 2009 at 1:37 PM, Michael Wooten<mw...@gmail.com> wrote:
>>
>> I would also like to propose some support be added to Lang for basic event
>> handling. This would be based on the way that PropertyChangeSupport can be
>> used to add and remove listeners and post events.
>>
>> Add interface EventSupport<L extends EventListener>
>>
>> - addListener(L listener)
>> - The signature for the method that can add a listener of some subtype of
>> EventListener
>> - removeListener(L listener)
>> - The signature for the method that can remove a listener of some subtype
>> of EventListener
>>
>>
>> Add class AbstractEventSupport implements EventSupport<L>, Iterable<L>
>>
>> - AbstractEventSupport(Object eventSource)
>> - Constructs a new AbstractEventSupport object and associates it with the
>> object that will be used as the source of all events (much like
>> PropertyChangeSupport).
>> - addListener(L)
>> - An implementation that adds a listener to an internal collection.
>> - removeListener(L)
>> - An implementation that removes a listener from an internal collection.
>> - iterator()
>> - Returns an iterator over the attached listeners.
>> - getSource()
>> - Returns a reference to the source object of all events.
>>
>>
>> The best way to describe this would be to demonstrate an example of how it
>> can be used.
>>
>> public class ButtonPressedEventSupport extends
>> AbstractEventSupport<ButtonPressedListener> {
>>
>> public ButtonPressedEventSupport(Object source) { super(source); }
>>
>> public void fireButtonPressed(Button button) {
>> ButtonPressedEvent bpe = new ButtonPressedEvent(getSource(),
>> button);
>> for (ButtonPressedListener listener : this)
>> {
>> listener.buttonPressed(bpe);
>> }
>> }
>> }
>>
>> public class MyWindow implements EventSupport<ButtonPressedListener> {
>> private final ButtonPressedEventSupport buttonPressedEventSupport;
>>
>> public MyWindow { buttonPressedEventSupport = new
>> ButtonPressedEventSupport(this); }
>>
>> public void addListener(ButtonPressedListener listener) {
>> buttonPressedEventSupport.addListener(listener); }
>>
>> public void removeListener(ButtonPressedListener listener) {
>> buttonPressedEventSupport.removeListener(listener); }
>>
>> ...
>>
>> private void onDetectButtonPressed(Button button) {
>> buttonPressedEventSupport.fireButtonPressed(button);
>> }
>> }
>>
>> I haven't compiled the above code. It's just an example of how these classes
>> could be used so that you're not constantly rewriting the code and
>> interfaces for adding and removing listeners, and it provides a fairly easy
>> method of creating methods to fire events.
>
> Worth a JIRA to solicit more feedback :) Seems good, in the 'this
> doesn't exist?' way :)
This'll be why I like the idea I guess :)
http://code.google.com/p/osjava/source/browse/trunk/genjava/gj-core/src/java/com/generationjava/lang/Notifier.java
Hen
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [LANG] Suggestions For New Features
Posted by Henri Yandell <fl...@gmail.com>.
On Sun, Aug 9, 2009 at 1:37 PM, Michael Wooten<mw...@gmail.com> wrote:
> These are several additions that I feel might be useful to the Commons Lang
> Project. Please feel free to provide feedback, and if there is enough
> interest in any of them I will create JIRA entries, code them, and provide
> patches.
>
> Expand Validate to include more specific, human readable validation for
> commonly validated paramter values (so isTrue() isn't needed as often).
> Include new Validate methods:
>
> - isFile(File file)
All the File ones are better placed in Commons IO.
> - matchesPattern(String string, String pattern)
> - throws an IllegalArgumentException stating ("The string " + string +
> " does not match the pattern " + pattern) when the provided
> string does not
> match the regular expression pattern.
> - matchesPattern(String string, String pattern, String message)
> - throws an IllegalArgumentException stating (message + string) when
> the provided string does not match the regular expression pattern.
> - matchesPattern(String string, Pattern pattern)
> - throws an IllegalArgumentException stating ("The string " + string +
> " does not match the pattern " + pattern) when the provided
> string does not
> match the regular expression pattern.
> - matchesPattern(String string, Pattern pattern, String message)
> - throws an IllegalArgumentException stating (message + string) when
> the provided string does not match the regular expression pattern.
+1
> - inRange(Comparable<T> start, Comparable<T> end, Comparable<T> value)
> - throws an IllegalArgumentException stating ("The value " + value + "
> is not in the specified range of " + start + " to " + end) when
> the provided
> value does not fall between the two comparable values.
> - inRange(Comparable<T> start, Comparable<T> end, Comparable<T> value,
> String message)
> - throws an IllegalArgumentException stating (message + value) when
> the provided value does not fall between the two comparable values.
> - sizeInRange(int minSize, int maxSize, T[] array, String message)
> - throws an IllegalArgumentException stating (message + value) when
> the length of the provided array does not fall between the minimum and
> maximum size values (inclusive).
> - sizeInRange(int minSize, int maxSize, Collection<?> collection, String
> message)
> - throws an IllegalArgumentException stating (message + value) when
> the length of the provided collection does not fall between the
> minimum and
> maximum size values (inclusive).
> - sizeInRange(int minSize, int maxSize, Map<?, ?> map, String message)
> - throws an IllegalArgumentException stating (message + value) when
> the length of the provided map does not fall between the minimum
> and maximum
> size values (inclusive).
> - sizeInRange(int minSize, int maxSize, String string, String message)
> - throws an IllegalArgumentException stating (message + value) when
> the length of the provided string does not fall between the minimum and
> maximum size values (inclusive).
I like 'between' more than 'inRange'.
I think a simpler API would be (ignoring the String message overloads):
between(Comparable<T> start, Comparable<T> end, Comparable<T> value)
between(int minSize, int maxSize, int value)
ie) leave the determination of the int to the developer.
> I would also like to propose some support be added to Lang for basic event
> handling. This would be based on the way that PropertyChangeSupport can be
> used to add and remove listeners and post events.
>
> Add interface EventSupport<L extends EventListener>
>
> - addListener(L listener)
> - The signature for the method that can add a listener of some subtype of
> EventListener
> - removeListener(L listener)
> - The signature for the method that can remove a listener of some subtype
> of EventListener
>
>
> Add class AbstractEventSupport implements EventSupport<L>, Iterable<L>
>
> - AbstractEventSupport(Object eventSource)
> - Constructs a new AbstractEventSupport object and associates it with the
> object that will be used as the source of all events (much like
> PropertyChangeSupport).
> - addListener(L)
> - An implementation that adds a listener to an internal collection.
> - removeListener(L)
> - An implementation that removes a listener from an internal collection.
> - iterator()
> - Returns an iterator over the attached listeners.
> - getSource()
> - Returns a reference to the source object of all events.
>
>
> The best way to describe this would be to demonstrate an example of how it
> can be used.
>
> public class ButtonPressedEventSupport extends
> AbstractEventSupport<ButtonPressedListener> {
>
> public ButtonPressedEventSupport(Object source) { super(source); }
>
> public void fireButtonPressed(Button button) {
> ButtonPressedEvent bpe = new ButtonPressedEvent(getSource(),
> button);
> for (ButtonPressedListener listener : this)
> {
> listener.buttonPressed(bpe);
> }
> }
> }
>
> public class MyWindow implements EventSupport<ButtonPressedListener> {
> private final ButtonPressedEventSupport buttonPressedEventSupport;
>
> public MyWindow { buttonPressedEventSupport = new
> ButtonPressedEventSupport(this); }
>
> public void addListener(ButtonPressedListener listener) {
> buttonPressedEventSupport.addListener(listener); }
>
> public void removeListener(ButtonPressedListener listener) {
> buttonPressedEventSupport.removeListener(listener); }
>
> ...
>
> private void onDetectButtonPressed(Button button) {
> buttonPressedEventSupport.fireButtonPressed(button);
> }
> }
>
> I haven't compiled the above code. It's just an example of how these classes
> could be used so that you're not constantly rewriting the code and
> interfaces for adding and removing listeners, and it provides a fairly easy
> method of creating methods to fire events.
Worth a JIRA to solicit more feedback :) Seems good, in the 'this
doesn't exist?' way :)
Hen
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org