Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Attributes

Reply
Thread Tools

Attributes

 
 
switch
Guest
Posts: n/a
 
      08-21-2003
I've seen code where people pass in 'attributes' by using the | operator.
Like MULTI | TRANSPARENT | EDITABLE

I want to use this kind of thing in my own code, and I know you need to set
up each constant to be 1,2,4,8,16, etc, but my question is, given a value,
how do I test if an attribute is set ?




 
Reply With Quote
 
 
 
 
Jacob
Guest
Posts: n/a
 
      08-21-2003
switch wrote:
> I've seen code where people pass in 'attributes' by using the | operator.
> Like MULTI | TRANSPARENT | EDITABLE
>
> I want to use this kind of thing in my own code, and I know you need to set
> up each constant to be 1,2,4,8,16, etc, but my question is, given a value,
> how do I test if an attribute is set ?


Use the binary and operator:

if (attribute & TRANSPARENT)
// TRANSPARENT is set
etc.


 
Reply With Quote
 
 
 
 
switch
Guest
Posts: n/a
 
      08-21-2003

> switch <(E-Mail Removed)> scribbled the following:
>> I've seen code where people pass in 'attributes' by using the |
>> operator.
>> Like MULTI | TRANSPARENT | EDITABLE


>> I want to use this kind of thing in my own code, and I know you need
>> to set up each constant to be 1,2,4,8,16, etc, but my question is,
>> given a value, how do I test if an attribute is set ?


> Like this:


> int attributes = getAttributesFromAMagicalPlace();
> if ((attributes & MULTI) != 0) {
> doMultiStuff();
> }
> if ((attributes & TRANSPARENT) != 0) {
> doTransparentStuff();
> }
> if ((attributes & EDITABLE) != 0) {
> doEditableStuff();
> }


Thank you Sir.




 
Reply With Quote
 
Joona I Palaste
Guest
Posts: n/a
 
      08-21-2003
switch <(E-Mail Removed)> scribbled the following:
> Thank you Sir.


I am pleased you figured out my real gender so quickly. Most people who
don't know me initially assume I'm a woman (which I'm not, despite my
feminine-sounding name).

--
/-- Joona Palaste ((E-Mail Removed)) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"We sorcerers don't like to eat our words, so to say."
- Sparrowhawk
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      08-21-2003
On Thu, 21 Aug 2003 14:15:46 +0200, Jacob <(E-Mail Removed)> wrote or
quoted :

>if (attribute & TRANSPARENT)


In forth that would be :
attribute TRANSPARENT AND IF

in C that would be :
if (attribute & TRANSPARENT)

but in Java it has to be :
if ( (attribute & TRANSPARENT) != 0 )

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      08-23-2003
On Sat, 23 Aug 2003 11:05:13 -0700, "Jon A. Cruz" <(E-Mail Removed)>
wrote or quoted :

>Then it'd have to be
>
>if ( (attribute & TRANSPARENT) == TRANSPARENT )


I did some work JavaDocing and cleaning a large Java project. The
thing I found more difficult to deal with than anything else was
deciding which enumeration masks were ints, which where single bit
mask and which where multiple bit masks and checking they were all
being used consistently.

Pascal with its sets and automatic enum numbering kept track. It
seems odd that Java can't do at least as well. The typical Pascal
implementation puts a fixed size or a cap on set size, which would
unlikely be considered acceptable in Java.

If we are not going to give any language support for bit map enums,
perhaps Sun could at least offer some naming conventions to help
clarify intentions.


--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
data attributes override method attributes? Jayden Python 16 09-29-2012 03:20 AM
attributes ala java annotations or .Net attributes? Kyle Schmitt Ruby 3 07-24-2007 07:48 PM
class attributes & data attributes james_027 Python 2 06-20-2007 03:12 PM
WebControl.Attributes.Add and custom attributes P4trykx ASP .Net 2 01-31-2007 04:33 PM
Parse reserved attributes as normal attributes Max XML 1 09-22-2006 12:04 PM



Advertisments