You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Felix Knecht <fe...@apache.org> on 2008/11/02 22:16:27 UTC

Re: svn commit: r709903 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/schema/BooleanNormalizer.java test/java/org/apache/directory/shared/ldap/schema/BooleanNormalizerTest.java

Without knowing the exact context ...

Why is the method definition of return type Object and not String? Wouldn't it be better to be as specific as possible?


> Author: kayyagari
> Date: Sun Nov  2 10:47:32 2008
> New Revision: 709903
> 
> URL: http://svn.apache.org/viewvc?rev=709903&view=rev
> Log:
> o a normalizer for boolean values
> 
> Added:
>     directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/BooleanNormalizer.java
>     directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/BooleanNormalizerTest.java
> 
> Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/BooleanNormalizer.java
> URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/BooleanNormalizer.java?rev=709903&view=auto
> ==============================================================================
> --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/BooleanNormalizer.java (added)
> +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/BooleanNormalizer.java Sun Nov  2 10:47:32 2008
> @@ -0,0 +1,61 @@

<snip>
> +
> +    public Object normalize( Object value ) throws NamingException
> +    {
</snip>

public String normalize( Object value ) throws NamingException


Regards
Felix


Re: svn commit: r709903 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/schema/BooleanNormalizer.java test/java/org/apache/directory/shared/ldap/schema/BooleanNormalizerTest.java

Posted by Kiran Ayyagari <ay...@gmail.com>.
hmm, this sounds good to me, we can avoid casting at least when we use an impl
of Normalizer directly.

And on a second thought I think returning Value<T> from Normalizer may not add
any value but makes the code more cluttered with checks to see if its a Sting
Value or a Binary Value

wdot?

-- 
Kiran Ayyagari

Felix Knecht wrote:
> Kiran Ayyagari schrieb:
>> hi Felix,
>>
>>   The return type can also vary so we have to either return Object (
>> the current
>>   case) or may be we can return Value<T> instead just like the way
>> Emmanuel
>>   proposed to accept Value<T> as a parameter
> 
> Hmmm. I realize, that the discussion is getting deeper than what I
> actually meant (but that's ok ;-) ).
> 
> Trying to make it clearer what I meant in the beginning:
> For some Normalizer implementation it's absolutely clear, what kind of
> type is returned for others not. Being as specific as possible why can't
> we return the specific type when it's clearly defined within the method?
> For all the others I agree with the Value<T> as we can be more specific.
> 
> I sorted out some of them below (and test are running fine, including
> -Dintegration):
> 
> Index:
> ldap/src/main/java/org/apache/directory/shared/ldap/schema/NumericNormalizer.java
> ===================================================================
> ---
> ldap/src/main/java/org/apache/directory/shared/ldap/schema/NumericNormalizer.java  
> (revision 710036)
> +++
> ldap/src/main/java/org/apache/directory/shared/ldap/schema/NumericNormalizer.java  
> (working copy)
> @@ -36,7 +36,7 @@
>  {
>     static final long serialVersionUID = 1L;
> 
> -   public Object normalize( Object value ) throws NamingException
> +   public String normalize( Object value ) throws NamingException
>     {
>         try
>         {
> Index:
> ldap/src/main/java/org/apache/directory/shared/ldap/schema/DeepTrimNormalizer.java
> ===================================================================
> ---
> ldap/src/main/java/org/apache/directory/shared/ldap/schema/DeepTrimNormalizer.java 
> (revision 710036)
> +++
> ldap/src/main/java/org/apache/directory/shared/ldap/schema/DeepTrimNormalizer.java 
> (working copy)
> @@ -39,7 +39,7 @@
>  {
>     private static final long serialVersionUID = 1L;
> 
> -   public Object normalize( Object value ) throws NamingException
> +   public String normalize( Object value ) throws NamingException
>     {
>         try
>         {
> Index:
> ldap/src/main/java/org/apache/directory/shared/ldap/schema/BooleanNormalizer.java
> ===================================================================
> ---
> ldap/src/main/java/org/apache/directory/shared/ldap/schema/BooleanNormalizer.java  
> (revision 710036)
> +++
> ldap/src/main/java/org/apache/directory/shared/ldap/schema/BooleanNormalizer.java  
> (working copy)
> @@ -37,7 +37,7 @@
>      private static final long serialVersionUID = 1L;
> 
> 
> -    public Object normalize( Object value ) throws NamingException
> +    public String normalize( Object value ) throws NamingException
>      {
>          if ( value == null )
>          {
> 
> 
> Felix
> 


Re: svn commit: r709903 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/schema/BooleanNormalizer.java test/java/org/apache/directory/shared/ldap/schema/BooleanNormalizerTest.java

Posted by Felix Knecht <fe...@apache.org>.
Kiran Ayyagari schrieb:
> hi Felix,
>
>   The return type can also vary so we have to either return Object (
> the current
>   case) or may be we can return Value<T> instead just like the way
> Emmanuel
>   proposed to accept Value<T> as a parameter

Hmmm. I realize, that the discussion is getting deeper than what I
actually meant (but that's ok ;-) ).

Trying to make it clearer what I meant in the beginning:
For some Normalizer implementation it's absolutely clear, what kind of
type is returned for others not. Being as specific as possible why can't
we return the specific type when it's clearly defined within the method?
For all the others I agree with the Value<T> as we can be more specific.

I sorted out some of them below (and test are running fine, including
-Dintegration):

Index:
ldap/src/main/java/org/apache/directory/shared/ldap/schema/NumericNormalizer.java
===================================================================
---
ldap/src/main/java/org/apache/directory/shared/ldap/schema/NumericNormalizer.java  
(revision 710036)
+++
ldap/src/main/java/org/apache/directory/shared/ldap/schema/NumericNormalizer.java  
(working copy)
@@ -36,7 +36,7 @@
 {
    static final long serialVersionUID = 1L;

-   public Object normalize( Object value ) throws NamingException
+   public String normalize( Object value ) throws NamingException
    {
        try
        {
Index:
ldap/src/main/java/org/apache/directory/shared/ldap/schema/DeepTrimNormalizer.java
===================================================================
---
ldap/src/main/java/org/apache/directory/shared/ldap/schema/DeepTrimNormalizer.java 
(revision 710036)
+++
ldap/src/main/java/org/apache/directory/shared/ldap/schema/DeepTrimNormalizer.java 
(working copy)
@@ -39,7 +39,7 @@
 {
    private static final long serialVersionUID = 1L;

-   public Object normalize( Object value ) throws NamingException
+   public String normalize( Object value ) throws NamingException
    {
        try
        {
Index:
ldap/src/main/java/org/apache/directory/shared/ldap/schema/BooleanNormalizer.java
===================================================================
---
ldap/src/main/java/org/apache/directory/shared/ldap/schema/BooleanNormalizer.java  
(revision 710036)
+++
ldap/src/main/java/org/apache/directory/shared/ldap/schema/BooleanNormalizer.java  
(working copy)
@@ -37,7 +37,7 @@
     private static final long serialVersionUID = 1L;


-    public Object normalize( Object value ) throws NamingException
+    public String normalize( Object value ) throws NamingException
     {
         if ( value == null )
         {


Felix

Re: svn commit: r709903 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/schema/BooleanNormalizer.java test/java/org/apache/directory/shared/ldap/schema/BooleanNormalizerTest.java

Posted by Emmanuel Lecharny <el...@gmail.com>.
Kiran Ayyagari wrote:
> hi Felix,
>
>   The return type can also vary so we have to either return Object ( 
> the current
>   case) or may be we can return Value<T> instead just like the way 
> Emmanuel
>   proposed to accept Value<T> as a parameter
>
Hi Felix, Kiran

sorry I didn't read the first message correctly.

I think Felix's right : we should not use Object, but instead, as 
suggested by Kiran, use Value<T> instead.

Let's create a JIRA for that.

Thanks !

-- 
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org



Re: svn commit: r709903 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/schema/BooleanNormalizer.java test/java/org/apache/directory/shared/ldap/schema/BooleanNormalizerTest.java

Posted by Kiran Ayyagari <ay...@gmail.com>.
hi Felix,

   The return type can also vary so we have to either return Object ( the current
   case) or may be we can return Value<T> instead just like the way Emmanuel
   proposed to accept Value<T> as a parameter

-- 
Kiran Ayyagari

Felix Knecht wrote:
> Emmanuel Lecharny schrieb:
>> Felix Knecht wrote:
>>> Without knowing the exact context ...
>>>
>>> Why is the method definition of return type Object and not String?
>>> Wouldn't it be better to be as specific as possible?
>>>   
>> Because we can deal with either String or byte[], so we use Object
>> instead. This can be re-evaluated, as now we are using Value<T> instead.
>>
> 
> But what you return is 'String strValue'. I'm talking about the returned type not the parameter.
> 



Re: svn commit: r709903 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/schema/BooleanNormalizer.java test/java/org/apache/directory/shared/ldap/schema/BooleanNormalizerTest.java

Posted by Felix Knecht <fe...@apache.org>.
Emmanuel Lecharny schrieb:
> Felix Knecht wrote:
>> Without knowing the exact context ...
>>
>> Why is the method definition of return type Object and not String?
>> Wouldn't it be better to be as specific as possible?
>>   
> Because we can deal with either String or byte[], so we use Object
> instead. This can be re-evaluated, as now we are using Value<T> instead.
> 

But what you return is 'String strValue'. I'm talking about the returned type not the parameter.

Re: svn commit: r709903 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/schema/BooleanNormalizer.java test/java/org/apache/directory/shared/ldap/schema/BooleanNormalizerTest.java

Posted by Emmanuel Lecharny <el...@gmail.com>.
Felix Knecht wrote:
> Without knowing the exact context ...
>
> Why is the method definition of return type Object and not String? Wouldn't it be better to be as specific as possible?
>   
Because we can deal with either String or byte[], so we use Object 
instead. This can be re-evaluated, as now we are using Value<T> instead.

-- 
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org