RE: Series.getValues()

2008-03-28 Thread Jerome Louvel

Hi Tim,

I wish the Series class could implement both ListParameter and MapString,
String but some method conflicts prevent this (due to the remove() method
result param for example). 

As a compromise I've just added to SVN trunk a getValuesMap() method to the
Series class, returning a MapString, String. Internally it uses a
LinkedHashMap.

Having repeating parameters is not uncommon in Web forms or query strings.
For HTTP headers it is very common. I prefer to have a more complete backing
structure (ListParameter) even if it looks unfamiliar at first sight
rather than a simpler one (MapString, String) because it allows me to
expose it in as many views I need (as array, as map, as encoded string,
etc.).

If you can convince me than another structure is better, I'd be happy to
reconsider the approach for Restlet API 2.0 for example! :)

Best regards,
Jerome  

 -Message d'origine-
 De : [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] De la 
 part de Tim Peierls
 Envoyé : jeudi 27 mars 2008 19:51
 À : discuss@restlet.tigris.org
 Objet : Re: Series.getValues()
 
 ListParameter doesn't seem like the right abstraction, even 
 when provided as Series. Parameters seem more akin to a 
 multimap than to a sequence of key-value pairs. And for the 
 (many?) users who don't take advantage of the multiplicity 
 they are closer to regular maps. If sequence of keys is 
 important, one could use a LinkedHashMap.
 
 But maybe this would be too much upheaval to contemplate.
 
 --tim
 
 
 
 On Tue, Mar 25, 2008 at 6:08 AM, Jerome Louvel 
 [EMAIL PROTECTED] wrote:
 
 
 
   Hi Paul,
   
 
You can use ListParameter if you write more generic 
 utility classes:
   
   
   [...]
   
   
The bonuses are:
   
1. The Series class doesn't leak into places that
shouldn't have a
dependency on it since you're using an ordinary List.
   
2. The solution above is completely generic and can 
 be used for lots
of other stuff.
   
If you want, you can add other Util methods that 
 are convenience
methods to lessen typing.
   
   
   You filter approach is nice and very flexible. However, 
 if you call the
   subList() method, I don't see how the Series class 
 leaks, you can do this:
   
   ListParameter fooParams = in.sublist(foo);
   
   You still have the Restlet Parameter class dependency 
 so you might still
   prefer the new getValuesArray(foo) method anyway.
   
   Best regards,
   Jerome
   
   
 
 
 



Re: Series.getValues()

2008-03-27 Thread Tim Peierls
ListParameter doesn't seem like the right abstraction, even when provided
as Series. Parameters seem more akin to a multimap than to a sequence of
key-value pairs. And for the (many?) users who don't take advantage of the
multiplicity they are closer to regular maps. If sequence of keys is
important, one could use a LinkedHashMap.

But maybe this would be too much upheaval to contemplate.

--tim


On Tue, Mar 25, 2008 at 6:08 AM, Jerome Louvel [EMAIL PROTECTED] wrote:


 Hi Paul,

  You can use ListParameter if you write more generic utility classes:
 
 [...]
 
  The bonuses are:
 
  1. The Series class doesn't leak into places that
  shouldn't have a
  dependency on it since you're using an ordinary List.
 
  2. The solution above is completely generic and can be used for lots
  of other stuff.
 
  If you want, you can add other Util methods that are convenience
  methods to lessen typing.

 You filter approach is nice and very flexible. However, if you call the
 subList() method, I don't see how the Series class leaks, you can do this:

 ListParameter fooParams = in.sublist(foo);

 You still have the Restlet Parameter class dependency so you might still
 prefer the new getValuesArray(foo) method anyway.

 Best regards,
 Jerome




RE: Series.getValues()

2008-03-25 Thread Jerome Louvel

Hi Paul,

 You can use ListParameter if you write more generic utility classes:
 
[...]
 
 The bonuses are:
 
 1. The Series class doesn't leak into places that 
 shouldn't have a  
 dependency on it since you're using an ordinary List.
 
 2. The solution above is completely generic and can be used for lots  
 of other stuff.
 
 If you want, you can add other Util methods that are convenience  
 methods to lessen typing.

You filter approach is nice and very flexible. However, if you call the
subList() method, I don't see how the Series class leaks, you can do this:

ListParameter fooParams = in.sublist(foo);

You still have the Restlet Parameter class dependency so you might still
prefer the new getValuesArray(foo) method anyway.

Best regards,
Jerome



Re: Series.getValues()

2008-03-24 Thread Paul J. Lucas

On Mar 23, 2008, at 10:50 AM, Jerome Louvel wrote:

Paul, the Series class address the lack of a structure maintaining a  
list of
named entries. There is no reusable Parameter class (name, value  
pair) in
the JDK. Only the Map.EntryK,V interface comes close to it. Having  
just a
ListParameter (via ArrayList or similar) is good but doesn't  
provide any

facility to lookup the structure by parameter name (like the
getValuesArray(name) method you were looking for). This is what the  
Series
class adds in addition of being a ListParameter. I hope that makes  
sense.



You can use ListParameter if you write more generic utility classes:

public interface CollectionFilterT {
boolean accept( T obj );
}

public final class CollectionUtil {

public static T CollectionT filter( CollectionT in,
CollectionT out,
 
CollectionFilterT filter ) {

for ( T x : in )
if ( filter.accept( x ) )
out.add( x );
return out;
}
}

Then you just implement CollectionFilter:

public ParameterNameFilter implements CollectionFilterParameter {
public ParameterNameFilter( String name ) {
m_name = name;
}
public boolean accept( Parameter p ) {
return p.getName().equals( m_name );
}
private final String m_name;
}

Finally:

ListParameter fooParams = CollectionUtil.filter(
in, new LinkedListParameter, new ParameterNameFilter( foo )
);

The bonuses are:

1. The Series class doesn't leak into places that shouldn't have a  
dependency on it since you're using an ordinary List.


2. The solution above is completely generic and can be used for lots  
of other stuff.


If you want, you can add other Util methods that are convenience  
methods to lessen typing.


- Paul


RE: Series.getValues()

2008-03-23 Thread Jerome Louvel

Hi all,

I've added a new method on Series: getValuesArray(String name):String[].
There is already a getValues(String name):String method so I had to prepend
the 'Array' suffix. Code checked in SVN trunk.

Paul, the Series class address the lack of a structure maintaining a list of
named entries. There is no reusable Parameter class (name, value pair) in
the JDK. Only the Map.EntryK,V interface comes close to it. Having just a
ListParameter (via ArrayList or similar) is good but doesn't provide any
facility to lookup the structure by parameter name (like the
getValuesArray(name) method you were looking for). This is what the Series
class adds in addition of being a ListParameter. I hope that makes sense.

Best regards,
Jerome  

 -Message d'origine-
 De : William Pietri [mailto:[EMAIL PROTECTED] 
 Envoyé : samedi 22 mars 2008 21:04
 À : discuss@restlet.tigris.org
 Objet : Re: Series.getValues()
 
 Stephan Koops wrote:
  Series is also a List. you can handle it as List.
 
 Not exactly. Series is a List of Parameters. If there were a 
 getValues(paramName) call that returned a list of Strings, 
 that would be 
 just as good as an array of Strings from my perspective. But 
 the Series 
 isn't as good, as I need to pass the values into domain code 
 that should 
 have no dependency on Restlet code.
 
 William



Re: Series.getValues()

2008-03-23 Thread William Pietri

Jerome Louvel wrote:

I've added a new method on Series: getValuesArray(String name):String[].
There is already a getValues(String name):String method so I had to prepend
the 'Array' suffix. Code checked in SVN trunk.
  


Fab! Thanks for that. I know that many people don't make use of the 
multiple-values-per-key power of HTTP requests, but for those of us who 
do, this is very helpful. Now that it's in Restlet, I'll get to delete 
some code I'm responsible for, and deleting code is one of my favorite 
things ever.


William


Re: Series.getValues()

2008-03-22 Thread William Pietri

I'd second his request here. I think having this:

   String[] getValues(String name)

makes good sense. Sure, that may end up being a little API sugar that 
you can get another way if you understand the inheritance hierarchy. But 
the existing getValues method suggests that's a reasonable name, and 
anybody coming from the Servlet world will be looking for something like 
that. I sure did. Repeatedly.


William

Jerome Louvel wrote:

Hi Paul,

You can to this with: subList(name).toArray(). Is that sufficient?

Maybe we could also add a toArray(String name) or subArray(String name)
shortcut method?

Best regards,
Jerome  

  

-Message d'origine-
De : Paul J. Lucas [mailto:[EMAIL PROTECTED] 
Envoyé : jeudi 20 mars 2008 16:27

À : discuss@restlet.tigris.org
Objet : Series.getValues()

Sorry if this is a duplicate, but I never say my original 
message echo  
to the list.


Begin forwarded message:
Date: March 19, 2008 4:19:32 PM PDT
To: discuss@restlet.tigris.org
Subject: Series.getValues()

This method, as written in Restlet 1.0.8, specifically this variant:

getValues(String name, String separator, boolean ignoreCase)

has room for improvement.  Aside from the fact that the ignoreCase  
parameter is not used, globbing the values together with a separator  
is not that useful.  I really want:


String[] getValues(String name)

with an implementation like:

public String[] getFormValues( String paramName ) {
final ListString temp = new LinkedListString();
for ( Parameter param : this )
if ( param.getName().equalsIgnoreCase( paramName ) )
temp.add( param.getValue() );
return temp.toArray( new String[ temp.size() ] );
}

- Paul




  




Re: Series.getValues()

2008-03-22 Thread Stephan Koops

Hi,

is it necessary to use the legacy datatype array? I think never the 
Series deals with arrays. What about returning SeriesString?


best regards
  Stephan

Jerome Louvel schrieb:

Hi Paul,

You can to this with: subList(name).toArray(). Is that sufficient?

Maybe we could also add a toArray(String name) or subArray(String name)
shortcut method?

Best regards,
Jerome  

  

-Message d'origine-
De : Paul J. Lucas [mailto:[EMAIL PROTECTED] 
Envoyé : jeudi 20 mars 2008 16:27

À : discuss@restlet.tigris.org
Objet : Series.getValues()

Sorry if this is a duplicate, but I never say my original 
message echo  
to the list.


Begin forwarded message:
Date: March 19, 2008 4:19:32 PM PDT
To: discuss@restlet.tigris.org
Subject: Series.getValues()

This method, as written in Restlet 1.0.8, specifically this variant:

getValues(String name, String separator, boolean ignoreCase)

has room for improvement.  Aside from the fact that the ignoreCase  
parameter is not used, globbing the values together with a separator  
is not that useful.  I really want:


String[] getValues(String name)

with an implementation like:

public String[] getFormValues( String paramName ) {
final ListString temp = new LinkedListString();
for ( Parameter param : this )
if ( param.getName().equalsIgnoreCase( paramName ) )
temp.add( param.getValue() );
return temp.toArray( new String[ temp.size() ] );
}

- Paul




  


Re: Series.getValues()

2008-03-22 Thread Paul J. Lucas

On Mar 22, 2008, at 4:21 AM, Stephan Koops wrote:


is it necessary to use the legacy datatype array?


Since when is an array a legacy datatype?  (If this were C++ instead  
of Java, that question would have more merit.)


I think never the Series deals with arrays. What about returning  
SeriesString?


I prefer simpler APIs.  Your suggestion means I have to understand  
what a Series is, why it's supposedly better than either an array or a  
Collection, and how I have to use it.


In Restlet, I don't even really understand what problem all the  
Wrapper classes solve, never mind Series.  To me, it's a lot of code  
one either has to maintain or learn about for very little (if any)  
benefit.  IMHO, Restlet should be a reference implementation of REST,  
not an exercise in how to tweak the Java collections API.


- Paul


Re: Series.getValues()

2008-03-22 Thread Stephan Koops

Hello Paul,

is it necessary to use the legacy datatype array?
Since when is an array a legacy datatype?  (If this were C++ instead 
of Java, that question would have more merit.)
Since we have java.util.List. Ok, sometime it is useful to ue arrays, 
but IMO in the most cases the list is the better solution. Typically you 
collect the result in a List, because you don't know the result size. 
Than you perhaps convert it to an array. So it is not faster to return 
arrays. The only argument for arrays are for me, that they are faster.
I think never the Series deals with arrays. What about returning 
SeriesString?
I prefer simpler APIs.  Your suggestion means I have to understand 
what a Series is, why it's supposedly better than either an array or a 
Collection, and how I have to use it.

Series is also a List. you can handle it as List.

best regards
  Stephan


Re: Series.getValues()

2008-03-22 Thread Paul J. Lucas

On Mar 22, 2008, at 11:16 AM, Stephan Koops wrote:

Since we have java.util.List. Ok, sometime it is useful to ue  
arrays, but IMO in the most cases the list is the better solution.  
Typically you collect the result in a List, because you don't know  
the result size. Than you perhaps convert it to an array. So it is  
not faster to return arrays. The only argument for arrays are for  
me, that they are faster.



I don't have that strong opinions on List vs. arrays.  My only point  
was saying that Java arrays are not legacy.



Series is also a List. you can handle it as List.


Yes, I know.  I simply don't see that Series solves any particular  
problem and hence why it's necessary.  IMHO, it would have been  
simpler and cleaner just to use List directly which every Java  
programmers knows how to use already.


- Paul


Re: Series.getValues()

2008-03-22 Thread William Pietri

Stephan Koops wrote:

Series is also a List. you can handle it as List.


Not exactly. Series is a List of Parameters. If there were a 
getValues(paramName) call that returned a list of Strings, that would be 
just as good as an array of Strings from my perspective. But the Series 
isn't as good, as I need to pass the values into domain code that should 
have no dependency on Restlet code.


William


RE: Series.getValues()

2008-03-21 Thread Jerome Louvel

Hi Paul,

You can to this with: subList(name).toArray(). Is that sufficient?

Maybe we could also add a toArray(String name) or subArray(String name)
shortcut method?

Best regards,
Jerome  

 -Message d'origine-
 De : Paul J. Lucas [mailto:[EMAIL PROTECTED] 
 Envoyé : jeudi 20 mars 2008 16:27
 À : discuss@restlet.tigris.org
 Objet : Series.getValues()
 
 Sorry if this is a duplicate, but I never say my original 
 message echo  
 to the list.
 
 Begin forwarded message:
 Date: March 19, 2008 4:19:32 PM PDT
 To: discuss@restlet.tigris.org
 Subject: Series.getValues()
 
 This method, as written in Restlet 1.0.8, specifically this variant:
 
   getValues(String name, String separator, boolean ignoreCase)
 
 has room for improvement.  Aside from the fact that the ignoreCase  
 parameter is not used, globbing the values together with a separator  
 is not that useful.  I really want:
 
   String[] getValues(String name)
 
 with an implementation like:
 
 public String[] getFormValues( String paramName ) {
 final ListString temp = new LinkedListString();
 for ( Parameter param : this )
 if ( param.getName().equalsIgnoreCase( paramName ) )
 temp.add( param.getValue() );
 return temp.toArray( new String[ temp.size() ] );
 }
 
 - Paul
 



Series.getValues()

2008-03-20 Thread Paul J. Lucas
Sorry if this is a duplicate, but I never say my original message echo  
to the list.


Begin forwarded message:
Date: March 19, 2008 4:19:32 PM PDT
To: discuss@restlet.tigris.org
Subject: Series.getValues()

This method, as written in Restlet 1.0.8, specifically this variant:

getValues(String name, String separator, boolean ignoreCase)

has room for improvement.  Aside from the fact that the ignoreCase  
parameter is not used, globbing the values together with a separator  
is not that useful.  I really want:


String[] getValues(String name)

with an implementation like:

   public String[] getFormValues( String paramName ) {
   final ListString temp = new LinkedListString();
   for ( Parameter param : this )
   if ( param.getName().equalsIgnoreCase( paramName ) )
   temp.add( param.getValue() );
   return temp.toArray( new String[ temp.size() ] );
   }

- Paul