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