1 17 package org.apache.log; 18 19 import java.io.Serializable ; 20 21 26 public final class Priority 27 implements Serializable 28 { 29 32 public static final Priority DEBUG = new Priority( "DEBUG", 5 ); 33 34 37 public static final Priority INFO = new Priority( "INFO", 10 ); 38 39 43 public static final Priority WARN = new Priority( "WARN", 15 ); 44 45 48 public static final Priority ERROR = new Priority( "ERROR", 20 ); 49 50 54 public static final Priority FATAL_ERROR = new Priority( "FATAL_ERROR", 25 ); 55 56 59 public static final Priority NONE = new Priority( "NONE", Integer.MAX_VALUE ); 60 61 private final String m_name; 62 private final int m_priority; 63 64 70 public static Priority getPriorityForName( final String priority ) 71 { 72 if( Priority.DEBUG.getName().equals( priority ) ) 73 { 74 return Priority.DEBUG; 75 } 76 else if( Priority.INFO.getName().equals( priority ) ) 77 { 78 return Priority.INFO; 79 } 80 else if( Priority.WARN.getName().equals( priority ) ) 81 { 82 return Priority.WARN; 83 } 84 else if( Priority.ERROR.getName().equals( priority ) ) 85 { 86 return Priority.ERROR; 87 } 88 else if( Priority.FATAL_ERROR.getName().equals( priority ) ) 89 { 90 return Priority.FATAL_ERROR; 91 } 92 else if( Priority.NONE.getName().equals( priority ) ) 93 { 94 return Priority.NONE; 95 } 96 else 97 { 98 return Priority.DEBUG; 99 } 100 } 101 102 108 private Priority( final String name, final int priority ) 109 { 110 if( null == name ) 111 { 112 throw new NullPointerException ( "name" ); 113 } 114 115 m_name = name; 116 m_priority = priority; 117 } 118 119 124 public String toString() 125 { 126 return "Priority[" + getName() + "/" + getValue() + "]"; 127 } 128 129 134 public int getValue() 135 { 136 return m_priority; 137 } 138 139 144 public String getName() 145 { 146 return m_name; 147 } 148 149 155 public boolean isGreater( final Priority other ) 156 { 157 return m_priority > other.getValue(); 158 } 159 160 166 public boolean isLower( final Priority other ) 167 { 168 return m_priority < other.getValue(); 169 } 170 171 177 public boolean isLowerOrEqual( final Priority other ) 178 { 179 return m_priority <= other.getValue(); 180 } 181 182 187 private Object readResolve() 188 { 189 return getPriorityForName( m_name ); 190 } 191 } 192 | Popular Tags |