[jboss-cvs] JBossCache/tests-50/functional/org/jboss/cache/pojo/test ...
Ben Wang
bwang at jboss.com
Wed Nov 8 03:48:51 EST 2006
User: bwang
Date: 06/11/08 03:48:51
Added: tests-50/functional/org/jboss/cache/pojo/test
EnumPlanet.java
Log:
1. JBCACHE-619 to support Enum.
Revision Changes Path
1.1 date: 2006/11/08 08:48:51; author: bwang; state: Exp;JBossCache/tests-50/functional/org/jboss/cache/pojo/test/EnumPlanet.java
Index: EnumPlanet.java
===================================================================
/*
* JBoss, Home of Professional Open Source.
* Copyright 2006, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.cache.pojo.test;
/**
* Test class for PojoCache Enum.
*
* @version $Revision: 1.1 $
* <p>Below is the annotation that signifies this class is "prepared" under JBossAop. This is used in
* conjunction with a special jboss-aop.xml (supplied by JBossCache). In addition, this is JDK1.4 style,
* so a annoc Ant build target is needed to pre-compile it.</p>
* <p>To use this approach, just apply this line to your pojo and run annoc (and possibly aopc).</p>
*/
// We are using JDK1.5 annotation.
@org.jboss.cache.pojo.annotation.PojoCacheable
public enum EnumPlanet
{
MERCURY(3.303e+23, 2.4397e6),
VENUS(4.869e+24, 6.0518e6),
EARTH(5.976e+24, 6.37814e6),
MARS(6.421e+23, 3.3972e6),
JUPITER(1.9e+27, 7.1492e7),
SATURN(5.688e+26, 6.0268e7),
URANUS(8.686e+25, 2.5559e7),
NEPTUNE(1.024e+26, 2.4746e7);
private double mass; // in kilograms
private double radius; // in meters
// Need this for PojoCache. Can be private as well!
EnumPlanet() {;}
EnumPlanet(double mass, double radius)
{
this.mass = mass;
this.radius = radius;
}
public double mass()
{
return mass;
}
public double radius()
{
return radius;
}
public void setMass(double mass)
{
this.mass = mass;
}
public void setRadius(double radius)
{
this.radius = radius;
}
// universal gravitational constant (m3 kg-1 s-2)
public static final double G = 6.67300E-11;
public double surfaceGravity()
{
return G * mass / (radius * radius);
}
public double surfaceWeight(double otherMass)
{
return otherMass * surfaceGravity();
}
public static void main(String[] args)
{
double earthWeight = Double.parseDouble(args[0]);
double mass = earthWeight / EARTH.surfaceGravity();
for (EnumPlanet p : EnumPlanet.values())
System.out.printf("Weight on %s is %f%n",
p, p.surfaceWeight(mass));
}
}
More information about the jboss-cvs-commits
mailing list