package com.mindprod.example;
/**
* Enumeration of continents and animals that live there.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2016-09-19 initial version.
* @since 2016-09-19
*/
public enum Continent
{
AUSTRALIA( "koala", 4,
"kangaroo", 2,
"wombat", 4 ),
EUROPE( "badger", 4,
"deer", 4,
"wolf", 4 ),
NORTHAMERICA( "bison", 4,
"black widow spider", 8,
"lynx", 4,
"caribou", 4
);
/**
* names of animals
*/
private final String[] animalNames;
/**
* how many legs this animal has
*/
private final int[] legs;
/**
* constructor
*
* @param alterate animal name, legs
*/
Continent( Object... pairs )
{
assert ( pairs.length & 1 ) == 0 : "Must have pairs of animal/legs";
final int p2 = pairs.length / 2;
this.animalNames = new String[ p2 ];
this.legs = new int[ p2 ];
for ( int i = 0; i < p2; i++ )
{
animalNames[ i ] = ( String ) pairs[ i * 2 ];
}
for ( int i = 0; i < p2; i++ )
{
legs[ i ] = ( Integer ) pairs[ i * 2 + 1 ];
}
}
/**
* get array of animal names
*
* @return array of animal names
*/
public String[] getAnimalNames()
{
return animalNames;
}
/**
* get arry of leg counts
*
* @return array of leg counts
*/
public int[] getLegs()
{
return legs;
}
}