You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Steve Downey <st...@netfolio.com> on 2002/09/28 00:28:32 UTC

CharRange UNSET ?

CharRange uses an unassigned static character, UNSET, as a flag value
for testing if the range is a range or a single value.

This looks a little odd to me. I had the distinct impression that
accessing an unassigned value was an error. However, the comparison
works. I'm just not sure it's working as intended, and won't fail to
work an a different VM?

relevant code:
    /**
     * Used internally to represent null in a char.
     */
    private static char UNSET;

// ...

    /**
     * Is this CharRange over many characters
     *
     * @return boolean true is many characters
     */
    public boolean isRange() {
        return this.close != UNSET;
    }






--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: CharRange UNSET ?

Posted by Henri Yandell <ba...@generationjava.com>.

On Fri, 27 Sep 2002, Steve Downey wrote:

> OK the problem now is (and this is in no way a holdup, it's in the class of
> "Doc it hurts when I do this") UNSET isn't a signalling value. 0 is a
> legitimate character. Now, you would have to construct a range of, e.g.,
> "Z-\u0000", which is silly. But that range wouldn't be a range. Reverse
> ranges are broken, anyway, though.

Yeah. I agree though that this is something to fix when reverse ranges are
introduced.

>
> This is odd, though:
>
>         if("-".equals(str)) {
>             range = new CharRange('_');
>             set.add(range);
>             return;
>         }
>
> Shouldn't that be new CharRange('-')?

Fixed. I blame gremlins. I added a test to notice this.

One thing to decide at some point is what "a-" means. Currently this is an
unsupported syntax.

Hen



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: CharRange UNSET ?

Posted by Steve Downey <st...@netfolio.com>.
OK the problem now is (and this is in no way a holdup, it's in the class of 
"Doc it hurts when I do this") UNSET isn't a signalling value. 0 is a 
legitimate character. Now, you would have to construct a range of, e.g., 
"Z-\u0000", which is silly. But that range wouldn't be a range. Reverse 
ranges are broken, anyway, though.

This is odd, though:

        if("-".equals(str)) {
            range = new CharRange('_');
            set.add(range);
            return;
        } 

Shouldn't that be new CharRange('-')?


On Friday 27 September 2002 11:09 pm, Henri Yandell wrote:
> Yeah, method variables are that way.
>
> I don't think instance/class variables are
>
> public class Bob {
>
>     private String name = null;
>
> ..
>
> is overkill.
>
> For example, I commonly see standard bean code like:
>
> public Person {
>
>     private int age;
>
>     public int getAge() {
>         return this.age;
>     }
>
> ..
>
> }
>
> Looking at the spec, I think it says this is okay. Chapter 2, 2.5.1
> _Initial Values of Variables_:
>
> "Every variable in a program must have a value before it is used:
>
>   *	Each class variable, instance variable, and array component is
> initialized with a default value when it is created:"
>
> it then goes on to detail the default values. Basically what you'd expect,
> 0, false or null.
>
> I'd URL, but it's on my local machine. It's in 'Concepts.doc.html' if that
> helps.
>
> Hen
>
> On Fri, 27 Sep 2002, Steve Downey wrote:
> > public class TestDefAssign {
> >   public static char UNSET;
> >   public static void main(String[] args) {
> >   char c;
> >   char d = 0;
> >   //System.out.println(d == c);
> >   //System.out.println(d != c);
> >   //System.out.println(c);
> >   System.out.println(d != UNSET);
> >   System.out.println(d == UNSET);
> >   //System.out.println(c != UNSET);
> >   //System.out.println(c == UNSET);
> >   }
> > }
> >
> > Uncomment any of the commented out lines and you get something like
> > TestDefAssign.java:12: variable c might not have been initialized
> >
> > The output of the program is
> > false
> > true
> >
> > Which indicates that UNSET actually has the value of 0, but I don't think
> > you're supposed to use it.
> >
> > On Friday 27 September 2002 06:36 pm, Henri Yandell wrote:
> > > Weird. I'd thought all values in Java were set to a defined value.
> > > Thought we got rid of the unassigned stuff with C. But I don't delve
> > > into the JVM and language spec enough so could be wrong very easily.
> > >
> > > Hen
> > >
> > > On 27 Sep 2002, Steve Downey wrote:
> > > > CharRange uses an unassigned static character, UNSET, as a flag value
> > > > for testing if the range is a range or a single value.
> > > >
> > > > This looks a little odd to me. I had the distinct impression that
> > > > accessing an unassigned value was an error. However, the comparison
> > > > works. I'm just not sure it's working as intended, and won't fail to
> > > > work an a different VM?
> > > >
> > > > relevant code:
> > > >     /**
> > > >      * Used internally to represent null in a char.
> > > >      */
> > > >     private static char UNSET;
> > > >
> > > > // ...
> > > >
> > > >     /**
> > > >      * Is this CharRange over many characters
> > > >      *
> > > >      * @return boolean true is many characters
> > > >      */
> > > >     public boolean isRange() {
> > > >         return this.close != UNSET;
> > > >     }
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > --
> > > > To unsubscribe, e-mail:
> > > > <ma...@jakarta.apache.org> For additional
> > > > commands, e-mail: <ma...@jakarta.apache.org>
> >
> > --
> > To unsubscribe, e-mail:  
> > <ma...@jakarta.apache.org> For additional
> > commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: CharRange UNSET ?

Posted by Henri Yandell <ba...@generationjava.com>.
Yeah, method variables are that way.

I don't think instance/class variables are

public class Bob {

    private String name = null;

..

is overkill.

For example, I commonly see standard bean code like:

public Person {

    private int age;

    public int getAge() {
        return this.age;
    }

..

}

Looking at the spec, I think it says this is okay. Chapter 2, 2.5.1
_Initial Values of Variables_:

"Every variable in a program must have a value before it is used:

  *	Each class variable, instance variable, and array component is
initialized with a default value when it is created:"

it then goes on to detail the default values. Basically what you'd expect,
0, false or null.

I'd URL, but it's on my local machine. It's in 'Concepts.doc.html' if that
helps.

Hen

On Fri, 27 Sep 2002, Steve Downey wrote:

> public class TestDefAssign {
>   public static char UNSET;
>   public static void main(String[] args) {
>   char c;
>   char d = 0;
>   //System.out.println(d == c);
>   //System.out.println(d != c);
>   //System.out.println(c);
>   System.out.println(d != UNSET);
>   System.out.println(d == UNSET);
>   //System.out.println(c != UNSET);
>   //System.out.println(c == UNSET);
>   }
> }
>
> Uncomment any of the commented out lines and you get something like
> TestDefAssign.java:12: variable c might not have been initialized
>
> The output of the program is
> false
> true
>
> Which indicates that UNSET actually has the value of 0, but I don't think
> you're supposed to use it.
>
>
> On Friday 27 September 2002 06:36 pm, Henri Yandell wrote:
> > Weird. I'd thought all values in Java were set to a defined value. Thought
> > we got rid of the unassigned stuff with C. But I don't delve into the JVM
> > and language spec enough so could be wrong very easily.
> >
> > Hen
> >
> > On 27 Sep 2002, Steve Downey wrote:
> > > CharRange uses an unassigned static character, UNSET, as a flag value
> > > for testing if the range is a range or a single value.
> > >
> > > This looks a little odd to me. I had the distinct impression that
> > > accessing an unassigned value was an error. However, the comparison
> > > works. I'm just not sure it's working as intended, and won't fail to
> > > work an a different VM?
> > >
> > > relevant code:
> > >     /**
> > >      * Used internally to represent null in a char.
> > >      */
> > >     private static char UNSET;
> > >
> > > // ...
> > >
> > >     /**
> > >      * Is this CharRange over many characters
> > >      *
> > >      * @return boolean true is many characters
> > >      */
> > >     public boolean isRange() {
> > >         return this.close != UNSET;
> > >     }
> > >
> > >
> > >
> > >
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> > > <ma...@jakarta.apache.org> For additional
> > > commands, e-mail: <ma...@jakarta.apache.org>
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: CharRange UNSET ?

Posted by Steve Downey <st...@netfolio.com>.
public class TestDefAssign {
  public static char UNSET;
  public static void main(String[] args) {
  char c;
  char d = 0;
  //System.out.println(d == c);
  //System.out.println(d != c);
  //System.out.println(c);
  System.out.println(d != UNSET);
  System.out.println(d == UNSET);
  //System.out.println(c != UNSET);
  //System.out.println(c == UNSET);
  }
}

Uncomment any of the commented out lines and you get something like
TestDefAssign.java:12: variable c might not have been initialized

The output of the program is
false
true

Which indicates that UNSET actually has the value of 0, but I don't think 
you're supposed to use it.


On Friday 27 September 2002 06:36 pm, Henri Yandell wrote:
> Weird. I'd thought all values in Java were set to a defined value. Thought
> we got rid of the unassigned stuff with C. But I don't delve into the JVM
> and language spec enough so could be wrong very easily.
>
> Hen
>
> On 27 Sep 2002, Steve Downey wrote:
> > CharRange uses an unassigned static character, UNSET, as a flag value
> > for testing if the range is a range or a single value.
> >
> > This looks a little odd to me. I had the distinct impression that
> > accessing an unassigned value was an error. However, the comparison
> > works. I'm just not sure it's working as intended, and won't fail to
> > work an a different VM?
> >
> > relevant code:
> >     /**
> >      * Used internally to represent null in a char.
> >      */
> >     private static char UNSET;
> >
> > // ...
> >
> >     /**
> >      * Is this CharRange over many characters
> >      *
> >      * @return boolean true is many characters
> >      */
> >     public boolean isRange() {
> >         return this.close != UNSET;
> >     }
> >
> >
> >
> >
> >
> >
> > --
> > To unsubscribe, e-mail:  
> > <ma...@jakarta.apache.org> For additional
> > commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: CharRange UNSET ?

Posted by Henri Yandell <ba...@generationjava.com>.
Weird. I'd thought all values in Java were set to a defined value. Thought
we got rid of the unassigned stuff with C. But I don't delve into the JVM
and language spec enough so could be wrong very easily.

Hen

On 27 Sep 2002, Steve Downey wrote:

> CharRange uses an unassigned static character, UNSET, as a flag value
> for testing if the range is a range or a single value.
>
> This looks a little odd to me. I had the distinct impression that
> accessing an unassigned value was an error. However, the comparison
> works. I'm just not sure it's working as intended, and won't fail to
> work an a different VM?
>
> relevant code:
>     /**
>      * Used internally to represent null in a char.
>      */
>     private static char UNSET;
>
> // ...
>
>     /**
>      * Is this CharRange over many characters
>      *
>      * @return boolean true is many characters
>      */
>     public boolean isRange() {
>         return this.close != UNSET;
>     }
>
>
>
>
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>