source: trunk/src/org/expeditee/items/Permission.java@ 286

Last change on this file since 286 was 115, checked in by ra33, 16 years ago

added functionality for dockable @v's

File size: 1.4 KB
Line 
1package org.expeditee.items;
2
3public enum Permission{
4 none, followLinks, copy, createFrames, full;
5
6 /**
7 * Converts the given Expeditee justification code into a int corresponding
8 * to the constants defined in Item.
9 *
10 * @param permissionCode
11 * The Expeditee justification code to convert
12 * @return The resulting int corresponding to one of the constants defined
13 * in Item
14 */
15 public static Permission getPermission(String permissionCode) {
16 return getPermission(permissionCode, Permission.full);
17 }
18
19 public static Permission getPermission(String permissionCode, Permission defaultPermission) {
20 if (permissionCode == null)
21 return defaultPermission;
22
23 permissionCode = permissionCode.trim().toLowerCase();
24 if (permissionCode.length() == 0)
25 return defaultPermission;
26
27 // if it is a single char just match the first character
28 try{
29 return values()[Integer.parseInt(permissionCode)];
30 // Otherwise match the whole string
31 }catch(Exception ex){
32 try{
33 return valueOf(permissionCode);
34 }catch (Exception e) {
35 }
36 }
37
38 // default permission
39 return defaultPermission;
40 }
41
42
43 public int getCode() {
44 return ordinal();
45 }
46
47 public String toString() {
48 return this.name();
49 }
50
51 public static Permission min(Permission p1, Permission p2) {
52 return p1.ordinal() < p2.ordinal() ? p1 : p2;
53 }
54
55 public static Permission max(Permission p1, Permission p2) {
56 return p1.ordinal() > p2.ordinal() ? p1 : p2;
57 }
58}
Note: See TracBrowser for help on using the repository browser.