package com.mindprod.example;
/**
* example use of enum define the possible dog breeds
* <p/>
* This automatically creates three Breed objects to represent the three breeds. All Breed variables will be either null
* or point to one of these three objects.
* <p/>
* composed with IntelliJ IDEA
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0
*/
@SuppressWarnings( { "UnusedAssignment", "UnusedDeclaration", "WeakerAccess" } )
public enum Breed
{
/**
* Dachshund, smooth and shaggy
*/
DACHSHUND,
/**
* Dalmatian
*/
DALMATIAN,
/**
* Labrador, black and golden
*/
LABRADOR;
/**
* is this a lap dog?
*
* @param breed breed of dog
* @return true if it is a lap dog
*/
public static boolean lap( Breed breed )
{
switch ( breed )
{
case DALMATIAN:
case LABRADOR:
default:
return false;
case DACHSHUND:
return true;
}
}
/**
* constructor, implicitly public
*/
Breed()
{
}
/**
* Breed Test harness
*
* @param args not used
*/
@SuppressWarnings( { "UnusedParameters" } )
public static void main( String[] args )
{
Breed cedar = Breed.LABRADOR;
System.out.println( cedar );
System.out.println( cedar.ordinal() );
System.out.println( Breed.DACHSHUND );
if ( cedar.compareTo( Breed.DALMATIAN ) > 0 )
{
System.out.println( "LABRADOR comes after DALMATIAN" );
}
else
{
System.out.println( "DALMATIAN comes after LABRADOR" );
}
cedar = null;
Breed myDogsBreed = Breed.valueOf( "Dachshund".toUpperCase() );
System.out.println( myDogsBreed );
int i = 1;
Breed theBreed = Breed.values()[ i ];
System.out.println( theBreed );
System.out.println( "All possible breeds" );
for ( Breed breed : Breed.values() )
{
System.out.println( breed );
}
}
}