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

Last change on this file since 427 was 427, checked in by ra33, 15 years ago
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 permission code into a int corresponding to
8 * the constants defined in Item.
9 *
10 * @param permissionCode
11 * The Expeditee permission code to convert
12 * @return The resulting int corresponding to one of the constants defined
13 * in Item
14 */
15 public static Permission convertString(String permissionCode) {
16 return getPermission(permissionCode, Permission.full);
17 }
18
19 public static Permission getPermission(String permissionCode,
20 Permission defaultPermission) {
21 if (permissionCode == null)
22 return defaultPermission;
23
24 permissionCode = permissionCode.trim().toLowerCase();
25 if (permissionCode.length() == 0)
26 return defaultPermission;
27
28 // if it is a single char just match the first character
29 try {
30 return values()[Integer.parseInt(permissionCode)];
31 // Otherwise match the whole string
32 } catch (Exception ex) {
33 try {
34 return valueOf(permissionCode);
35 } catch (Exception e) {
36 }
37 }
38
39 // default permission
40 return defaultPermission;
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.