1 11 12 package org.jivesoftware.messenger; 13 14 import org.jivesoftware.util.CacheSizes; 15 import org.jivesoftware.util.StringUtils; 16 import org.jivesoftware.util.Cacheable; 17 18 41 public class Permissions implements Cacheable { 42 43 46 public static final long NONE = 0x000000000000000L; 47 48 51 public static final long VIEW_ONLINE_STATUS = 0x100000000000000L; 52 53 56 public static final long USER_ADMIN = 0x200000000000000L; 57 58 61 public static final long GROUP_ADMIN = 0x400000000000000L; 62 63 66 public static final long SYSTEM_ADMIN = 0x800000000000000L; 67 68 72 private long permissions; 73 74 79 public Permissions(long permissions) { 80 this.permissions = permissions; 81 } 82 83 90 public Permissions(Permissions permissions1, Permissions permissions2) { 91 permissions = permissions1.permissions | permissions2.permissions; 92 } 93 94 100 public boolean hasPermission(long permissionTypes) { 101 return (permissions & permissionTypes) != 0; 102 } 103 104 115 public void set(long permissionTypes, boolean value) { 116 if (value) { 117 permissions = permissions | permissionTypes; 118 } 119 else { 120 permissionTypes = ~permissionTypes; 121 permissions = permissions & permissionTypes; 122 } 123 } 124 125 130 public long value() { 131 return permissions; 132 } 133 134 public String toString() { 135 return StringUtils.zeroPadString(Long.toBinaryString(permissions), 63); 136 } 137 138 140 public int getCachedSize() { 141 int size = 0; 144 size += CacheSizes.sizeOfObject(); size += CacheSizes.sizeOfLong(); return size; 147 } 148 } | Popular Tags |