public static synchronized Role getRole(String roleName) { if (roleName != null) { for (final Role r : Role.values()) { if (roleName.equalsIgnoreCase(r.name())) { return r; } } } return null; }
public Conference( final Date the_deadline_submission, final Date the_deadline_review, final Date the_deadline_decision) { // Initialize each Role with an empty Set of Users. for (Role r : Role.values()) { my_roles.put(r, new HashSet<User>()); } setDeadlineSubmission(the_deadline_submission); my_deadline_review = the_deadline_review; my_deadline_decision = the_deadline_decision; }
/** * Creates a new {@link DiscoveryNode} by reading from the stream provided as argument * * @param in the stream * @throws IOException if there is an error while reading from the stream */ public DiscoveryNode(StreamInput in) throws IOException { this.nodeName = in.readString().intern(); this.nodeId = in.readString().intern(); this.ephemeralId = in.readString().intern(); this.hostName = in.readString().intern(); this.hostAddress = in.readString().intern(); this.address = TransportAddressSerializers.addressFromStream(in); int size = in.readVInt(); this.attributes = new HashMap<>(size); for (int i = 0; i < size; i++) { this.attributes.put(in.readString(), in.readString()); } int rolesSize = in.readVInt(); this.roles = EnumSet.noneOf(Role.class); for (int i = 0; i < rolesSize; i++) { int ordinal = in.readVInt(); if (ordinal < 0 || ordinal >= Role.values().length) { throw new IOException("Unknown Role ordinal [" + ordinal + "]"); } this.roles.add(Role.values()[ordinal]); } this.version = Version.readVersion(in); }
/** * Creates a new {@link DiscoveryNode}. * * <p><b>Note:</b> if the version of the node is unknown {@link * Version#minimumCompatibilityVersion()} should be used for the current version. it corresponds * to the minimum version this elasticsearch version can communicate with. If a higher version is * used the node might not be able to communicate with the remove node. After initial handshakes * node versions will be discovered and updated. * * @param nodeName the nodes name * @param nodeId the nodes unique persistent id * @param ephemeralId the nodes unique ephemeral id * @param hostAddress the nodes host address * @param address the nodes transport address * @param attributes node attributes * @param roles node roles * @param version the version of the node */ public DiscoveryNode( String nodeName, String nodeId, String ephemeralId, String hostName, String hostAddress, TransportAddress address, Map<String, String> attributes, Set<Role> roles, Version version) { if (nodeName != null) { this.nodeName = nodeName.intern(); } else { this.nodeName = ""; } this.nodeId = nodeId.intern(); this.ephemeralId = ephemeralId.intern(); this.hostName = hostName.intern(); this.hostAddress = hostAddress.intern(); this.address = address; if (version == null) { this.version = Version.CURRENT; } else { this.version = version; } this.attributes = Collections.unmodifiableMap(attributes); // verify that no node roles are being provided as attributes Predicate<Map<String, String>> predicate = (attrs) -> { for (Role role : Role.values()) { assert attrs.containsKey(role.getRoleName()) == false; } return true; }; assert predicate.test(attributes); Set<Role> rolesSet = EnumSet.noneOf(Role.class); rolesSet.addAll(roles); this.roles = Collections.unmodifiableSet(rolesSet); }
public List<Role> getAllRole() { return new ArrayList<Role>(Arrays.asList(Role.values())); }