FileDocCategorySizeDatePackage
BitFieldDemo.javaAPI DocExample1893Sun Dec 14 22:47:30 GMT 2003oreilly.hcj.constants

BitFieldDemo

public class BitFieldDemo extends Object
Demonstration of aspects of bit fields.
author
Robert Simmons jr. (kraythe)
version
$Revision: 1.4 $

Fields Summary
private Car
myCar
Holds the demo car.
Constructors Summary
public BitFieldDemo()
Creates a new BitFieldDemo object.


	      	 
	  
	
Methods Summary
public voidclearStandardTires()
Remove the standard tires option.

		myCar.setOptions(myCar.getOptions() ^ Car.STANDARD_TIRES);
		System.out.println(myCar.getOptions());
	
public static final voidmain(java.lang.String[] args)
Main Demo Method.

param
args Command line arguments.

		BitFieldDemo demo = new BitFieldDemo();
		demo.setBitFields();
		demo.clearStandardTires();
		demo.printCarOptions();
	
public voidprintCarOptions()
Write the car's options to the console.

		System.out.println("-- Options --");
		if ((myCar.getOptions() & Car.POWER_WINDOWS) > 0) {
			System.out.println("Power Windows");
		}
		if ((myCar.getOptions() & Car.POWER_LOCKS) > 0) {
			System.out.println("Power Locks");
		}
	
public voidsetBitFields()
Set the default options.

		this.myCar = new Car();
		myCar.setOptions(Car.CRUISE_CONTROL | Car.STANDARD_TIRES | Car.POWER_LOCKS);
		System.out.println(myCar.getOptions());