SizeValue.java

Go to the documentation of this file.
00001 /*
00002  * Size.java
00003  *
00004  * Created on 15 octobre 2003, 14:06
00005  */
00006 
00007 package org.net2map.pov.dimension.size;
00008 
00013 public class SizeValue 
00014        extends org.net2map.pov.dimension.Value 
00015        implements Comparable
00016 {
00017     private static org.apache.log4j.Logger logger = 
00018     org.apache.log4j.Logger.getLogger(SizeValue.class.getName());
00019     public static final long LOWER_LIMIT = 0;
00020     public static final long HIGHER_LIMIT = 100000;
00021 
00022     private long value;
00023     
00025     public SizeValue()
00026     {       
00027         logger.setLevel((org.apache.log4j.Level)org.apache.log4j.Priority.DEBUG);
00028         logger.warn("Creating...");
00029         value = LOWER_LIMIT;
00030         logger.warn("...Created");
00031     }
00032        
00033     public SizeValue(long initializer)
00034     {
00035         value = initializer;
00036     }
00037         
00038     public SizeValue(float initializer)
00039     {
00040         value = (long)initializer;
00041     }
00042     
00043     public SizeValue(SizeValue initializer)
00044     {
00045         value = initializer.getValue();
00046     }
00047         
00048     public long getValue()
00049     {
00050         return (value);
00051     }
00052     public void setValue(SizeValue newValue)
00053     {
00054         value = newValue.getValue ();
00055     }
00056     
00057     public void setValue(float newValue) throws IllegalArgumentException
00058     {
00059         setValue((long)newValue);
00060     }
00061         
00062     public void setValue(long newValue) throws IllegalArgumentException
00063     {
00064         if ( newValue >= LOWER_LIMIT &&
00065              newValue <= HIGHER_LIMIT )
00066         {
00067             value = newValue;
00068         }
00069         else //off limits
00070         {
00071             throw (new IllegalArgumentException("You attempted to set minSize to " 
00072                                                  + newValue + "\n"
00073                                                  + "Please use a value not lower than "
00074                                                  + LOWER_LIMIT
00075                                                  + " and not higher than " 
00076                                                  + HIGHER_LIMIT)  
00077                                                  );
00078         }
00079     }
00080         
00119     public int compareTo (Object o) throws ClassCastException
00120     {
00121         throw (new ClassCastException("Size Objects may only be compared to other Size objects, or to long"));
00122     }
00123     
00124     public int compareTo (SizeValue otherObject)
00125     {
00126         return (otherObject.getValue () == value ? 0 : otherObject.getValue() < value ? 1 : -1);
00127     }
00128     
00129     public int compareTo (long otherValue)
00130     {
00131         return (otherValue == value ? 0 : otherValue < value ? 1 : -1);
00132     }
00133     
00134     public long toLong ()
00135     {
00136         return(value);
00137     }
00138     public String toString()
00139     {
00140         return (String.valueOf(value));
00141     }
00142 }
Accueil | Téléchargement | Manuel | Doc. technique | Sources CVS | Faq | Nous contacter
©2003 - All Rights Reserved