Java Program to Implement RoleList API

This Java program Implements RoleList API.A RoleList represents a list of roles (Role objects). It is used as parameter when creating a relation, and when trying to set several roles in a relation (via ‘setRoles()’ method). It is returned as part of a RoleResult, to provide roles successfully retrieved.

Here is the source code of the Java Program to Implement RoleList API.The Java program is successfully compiled and run on a Linux system. The program output is also shown below.

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.relation.Role;
import javax.management.relation.RoleList;
 
public class RoleListImpl
{
    private RoleList roleList;
 
    /** Constructs an empty RoleList. **/  
    public RoleListImpl()
    {
        roleList = new RoleList();
    }
 
    /** Constructs an empty RoleList with the initial capacity specified. **/
    public RoleListImpl(int initialCapacity)
    {
        roleList = new RoleList(initialCapacity);
    }
 
    /**
     * Constructs a RoleList containing the elements of the List specified, in
     * the order in which they are returned by the List's iterator.
    **/
    public RoleListImpl(List<Role> list)
    {
        roleList = new RoleList(list);
    }
 
    /** Inserts the specified element at the specified position in this list. **/
    public void add(int index, Object element)
    {
        roleList.add(index, element);
    }
 
    /** Inserts the role specified as an element at the position specified. **/
    public void add(int index, Role role)
    {
        roleList.add(index, role);
    }
 
    /** Appends the specified element to the end of this list. **/
    public boolean add(Object o)
    {
        return roleList.add(o);
    }
 
    /** Adds the Role specified as the last element of the list. **/
    public void add(Role role)
    {
        roleList.add(role);
    }
 
    /**
     * Appends all of the elements in the specified collection to the end of
     * this list, in the order that they are returned by the specified
     * collection's Iterator.
    **/
    public boolean addAll(Collection<?> c)
    {
        return roleList.addAll(c);
    }
 
    /**
     * Inserts all of the elements in the specified collection into this list,
     * starting at the specified position.
    **/
    public boolean addAll(int index, Collection<?> c)
    {
        return roleList.addAll(index, c);
    }
 
    /**
     * Inserts all of the elements in the RoleList specified into this list,
     * starting at the specified position, in the order in which they are
     * returned by the Iterator of the RoleList specified.
    **/
    public boolean addAll(int index, RoleList roleList)
    {
        return this.roleList.addAll(index, roleList);
    }
 
    /**
     * Appends all the elements in the RoleList specified to the end of the
     * list, in the order in which they are returned by the Iterator of the
     * RoleList specified.
    **/
    public boolean addAll(RoleList roleList)
    {
        return roleList.addAll(roleList);
    }
 
    /** vReturn a view of this list as a List<Role>. **/
    public List<Role> asList()
    {
        return roleList.asList();
    }
 
    /**
     * Replaces the element at the specified position in this list with the
     * specified element.
    **/
    public Object set(int index, Object element)
    {
        return roleList.set(index, element);
    }
 
    /** Sets the element at the position specified to be the role specified. **/
    public void set(int index, Role role)
    {
        roleList.set(index, role);
    }
 
    public static void main(String... arg) throws MalformedObjectNameException
    {
        RoleListImpl roleList = new RoleListImpl();
        List<ObjectName> rolelist1 = new LinkedList<ObjectName>();
        rolelist1.add(new ObjectName("domain1","key1","value1"));
        rolelist1.add(new ObjectName("domain2","key2","value2"));
        roleList.add(0, new Role("rolename1", rolelist1));
 
        List<ObjectName> roleList2 = new LinkedList<ObjectName>();
        roleList2.add(new ObjectName("domain3","key3","value3"));
        roleList2.add(new ObjectName("domain4","key4","value4"));
        roleList.add(1, new Role("rolename2", roleList2));
 
        List<Role> list = roleList.asList();
        int index = 0;
        while (index < list.size())
        {
            System.out.println(list.get(index++) + "\t");
        }
        System.out.println();
    }
}
$ javac RoleListImpl.java
$ java RoleListImpl
role name: rolename1; role value: domain1:key1=value1, domain2:key2=value2	
role name: rolename2; role value: domain3:key3=value3, domain4:key4=value4

Related posts:

Java Program to Implement Bresenham Line Algorithm
Java Program to Compute DFT Coefficients Directly
Java Program to Represent Linear Equations in Matrix Form
Using Custom Banners in Spring Boot
Java Program to Check Cycle in a Graph using Graph traversal
Java Program to Create a Minimal Set of All Edges Whose Addition will Convert it to a Strongly Conne...
Java Program to Implement Kosaraju Algorithm
Introduction to Java 8 Streams
Hướng dẫn Java Design Pattern – Decorator
Hướng dẫn Java Design Pattern – Service Locator
Deploy a Spring Boot App to Azure
Java Program to Implement LinkedHashSet API
Java Program to Implement a Binary Search Tree using Linked Lists
Java Program to Implement Trie
The “final” Keyword in Java
Java Program to Implement Graph Structured Stack
Giới thiệu Json Web Token (JWT)
Java Program to Implement SynchronosQueue API
Java Program to Implement PriorityQueue API
Java Program to Solve a Matching Problem for a Given Specific Case
Các chương trình minh họa sử dụng Cấu trúc điều khiển trong Java
Guide to Spring 5 WebFlux
HttpClient 4 Cookbook
Java Program to Find Strongly Connected Components in Graphs
Java Program to Implement ConcurrentHashMap API
Java Program to Implement Ford–Fulkerson Algorithm
Java Program to Find the Connected Components of an UnDirected Graph
Java Program to Implement Best-First Search
Spring WebClient Requests with Parameters
Spring Data – CrudRepository save() Method
Java Program to Solve any Linear Equation in One Variable
OAuth 2.0 Resource Server With Spring Security 5