1 8 package org.jivesoftware.util.log; 9 10 import java.io.ObjectStreamException ; 11 import java.io.Serializable ; 12 13 18 public final class Priority implements Serializable { 19 20 23 public final static Priority DEBUG = new Priority("DEBUG", 5); 24 25 28 public final static Priority INFO = new Priority("INFO", 10); 29 30 34 public final static Priority WARN = new Priority("WARN", 15); 35 36 39 public final static Priority ERROR = new Priority("ERROR", 20); 40 41 45 public final static Priority FATAL_ERROR = new Priority("FATAL_ERROR", 25); 46 47 private final String m_name; 48 private final int m_priority; 49 50 56 public static Priority getPriorityForName(final String priority) { 57 if (Priority.DEBUG.getName().equals(priority)) 58 return Priority.DEBUG; 59 else if (Priority.INFO.getName().equals(priority)) 60 return Priority.INFO; 61 else if (Priority.WARN.getName().equals(priority)) 62 return Priority.WARN; 63 else if (Priority.ERROR.getName().equals(priority)) 64 return Priority.ERROR; 65 else if (Priority.FATAL_ERROR.getName().equals(priority)) 66 return Priority.FATAL_ERROR; 67 else 68 return Priority.DEBUG; 69 } 70 71 77 private Priority(final String name, final int priority) { 78 m_name = name; 79 m_priority = priority; 80 } 81 82 87 public String toString() { 88 return "Priority[" + getName() + "/" + getValue() + "]"; 89 } 90 91 96 public int getValue() { 97 return m_priority; 98 } 99 100 105 public String getName() { 106 return m_name; 107 } 108 109 114 public boolean isGreater(final Priority other) { 115 return m_priority > other.getValue(); 116 } 117 118 123 public boolean isLower(final Priority other) { 124 return m_priority < other.getValue(); 125 } 126 127 132 public boolean isLowerOrEqual(final Priority other) { 133 return m_priority <= other.getValue(); 134 } 135 136 142 private Object readResolve() 143 throws ObjectStreamException { 144 return getPriorityForName(m_name); 145 } 146 } 147 | Popular Tags |