Link to home
Start Free TrialLog in
Avatar of rohitdivas
rohitdivas

asked on

structure/package data types..

hi,

working on java 1.5 for windows platform.

I have a base class CMainBase and have 4 classes derived from it , cboolean,

cintvalue, cstring and cother.

every data type(boolean, intvalue, string, other) has some attribute(s ) associated with it.

read-only,
read-write,
execute-only,
hidden.

these attribute, can be any or combination for each datatype (string,

boolean, other, value). The length of each attribute is 1 byte.

I am planning to make a structure containing alll these types like:

public abstract class CMainBase {

class attrib{
byte read-only;
byte read-write;
byte execute-only;
byte hidden;
}
}

and then use the same. Is this the right way to proceed ?? How to use this

class to package all the attribtutes so that overall length should not exceed 1 byte ?? i mean to say looking at the value i can deduce the attributes present for a datatype.

All suggestion are welcome.  

Regards,
rdh

Avatar of aozarov
aozarov

You can have one int variable (e.g int attributes)
and then have constants like:
public int READ = 1;
public int WRITE = 2;
public int EXECUTE = 4;
...

(each value is bigger then its previous one by multiply of 2).
Then you can assing to a type something like this:

intvalue intVal = ..
intVal.setAttributes( READ | WRITE); // or READ + WRITE;
which means that this value has RW attibutes.
If you want to check if this value has WRITE persmissions then you can do something like this:

if ((intVal & WRITE) > 0) ... // then this value has write persmissions.
There are many examples of the JDK for such technique (e.g. http://www.docjar.org/html/api/java/awt/Font.java.html)
For the Font class it is they way its store its style atributes (PLAIN , BOLD, ITALIC)
or FlowLayout with its alignment attributes: http://www.docjar.org/html/api/java/awt/FlowLayout.java.html
Avatar of rohitdivas

ASKER

The combination of all of them should not exceed 1 byte.  but here it is exceeding.

i need to achieve the functionality provided by enum data type (and enum is not provided in java) .  The method suggested by you will work, but  i am in search of alternatives methods.

rdh
ASKER CERTIFIED SOLUTION
Avatar of aozarov
aozarov

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial