1 16 package org.outerj.daisy.repository; 17 18 21 public class LockType { 22 private final String name; 23 private final String code; 24 25 private LockType(String name, String code) { 26 this.name = name; 27 this.code = code; 28 } 29 30 public String toString() { 31 return name; 32 } 33 34 37 public String getCode() { 38 return code; 39 } 40 41 public static LockType getByCode(String code) { 42 if (code.equals("W")) { 43 return WARN; 44 } else if (code.equals("P")) { 45 return PESSIMISTIC; 46 } else { 47 throw new RuntimeException ("Invalid LockType code: " + code); 48 } 49 } 50 51 public static LockType fromString(String lockTypeString) { 52 if (lockTypeString.equals("warn")) 53 return WARN; 54 else if (lockTypeString.equals("pessimistic")) 55 return PESSIMISTIC; 56 else 57 throw new RuntimeException ("Invalid LockType string: " + lockTypeString); 58 } 59 60 public static final LockType WARN = new LockType("warn", "W"); 61 public static final LockType PESSIMISTIC = new LockType("pessimistic", "P"); 62 } 63 | Popular Tags |