Java Program to Implement RoleUnresolvedList API

This Java program Implements RoleUnresolved API.A RoleUnresolvedList represents a list of RoleUnresolved objects, representing roles not retrieved from a relation due to a problem encountered when trying to access (read or write) the roles.

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

  1. import java.util.Collection;
  2. import java.util.LinkedList;
  3. import java.util.List;
  4. import javax.management.MalformedObjectNameException;
  5. import javax.management.ObjectName;
  6. import javax.management.relation.RoleUnresolved;
  7. import javax.management.relation.RoleUnresolvedList;
  8.  
  9. public class RoleUnresolvedListImpl
  10. {
  11.     private RoleUnresolvedList roleUnresolvedList;
  12.  
  13.     /** Constructs an empty RoleUnresolvedList. **/
  14.     public RoleUnresolvedListImpl()
  15.     {
  16.         roleUnresolvedList = new RoleUnresolvedList();
  17.     }
  18.  
  19.     /**
  20.      * Constructs an empty RoleUnresolvedList with the initial capacity
  21.      * specified.
  22.     **/
  23.     public RoleUnresolvedListImpl(int initialCapacity)
  24.     {
  25.         roleUnresolvedList = new RoleUnresolvedList(initialCapacity);
  26.     }
  27.  
  28.     /**
  29.      * Constructs a RoleUnresolvedList containing the elements of the List
  30.      * specified, in the order in which they are returned by the List's
  31.      * iterator.
  32.     **/
  33.     public RoleUnresolvedListImpl(List<RoleUnresolved> list)
  34.     {
  35.         roleUnresolvedList = new RoleUnresolvedList(list);
  36.     }
  37.  
  38.     /** Inserts the specified element at the specified position in this list. **/
  39.     public void add(int index, Object element)
  40.     {
  41.         roleUnresolvedList.add(index, element);
  42.     }
  43.  
  44.     /**
  45.      * Inserts the unresolved role specified as an element at the position
  46.      * specified.
  47.     **/
  48.     public void add(int index, RoleUnresolved role)
  49.     {
  50.         roleUnresolvedList.add(index, role);
  51.     }
  52.  
  53.     /** Appends the specified element to the end of this list. **/
  54.     public boolean add(Object o)
  55.     {
  56.         return roleUnresolvedList.add(o);
  57.     }
  58.  
  59.     /** Adds the RoleUnresolved specified as the last element of the list. **/
  60.     public void add(RoleUnresolved role)
  61.     {
  62.         roleUnresolvedList.add(role);
  63.     }
  64.  
  65.     /**
  66.      * Appends all of the elements in the specified collection to the end of
  67.      * this list, in the order that they are returned by the specified
  68.      * collection's Iterator.
  69.     **/
  70.     public boolean addAll(Collection<?> c)
  71.     {
  72.         return roleUnresolvedList.addAll(c);
  73.     }
  74.  
  75.     /**
  76.      * Inserts all of the elements in the specified collection into this list,
  77.      * starting at the specified position.
  78.     **/
  79.     public boolean addAll(int index, Collection<?> c)
  80.     {
  81.         return roleUnresolvedList.addAll(index, c);
  82.     }
  83.  
  84.     /**
  85.      * Inserts all of the elements in the RoleUnresolvedList specified into this
  86.      * list, starting at the specified position, in the order in which they are
  87.      * returned by the Iterator of the RoleUnresolvedList specified.
  88.     **/
  89.     public boolean addAll(int index, RoleUnresolvedList roleList)
  90.     {
  91.         return this.roleUnresolvedList.addAll(index, roleList);
  92.     }
  93.  
  94.     /**
  95.      * Appends all the elements in the RoleUnresolvedList specified to the end
  96.      * of the list, in the order in which they are returned by the Iterator of
  97.      * the RoleUnresolvedList specified.
  98.     **/
  99.     public boolean addAll(RoleUnresolvedList roleList)
  100.     {
  101.         return roleList.addAll(roleList);
  102.     }
  103.  
  104.     /** Return a view of this list as a List<RoleUnresolved>. **/
  105.     public List<RoleUnresolved> asList()
  106.     {
  107.         return roleUnresolvedList.asList();
  108.     }
  109.  
  110.     /**
  111.      * Replaces the element at the specified position in this list with the
  112.      * specified element.
  113.     **/
  114.     public Object set(int index, Object element)
  115.     {
  116.         return roleUnresolvedList.set(index, element);
  117.     }
  118.  
  119.     /**
  120.      * Sets the element at the position specified to be the unresolved role
  121.      * specified.
  122.     **/
  123.     public void set(int index, RoleUnresolved role)
  124.     {
  125.         roleUnresolvedList.set(index, role);
  126.     }
  127.  
  128.     public static void main(String... arg) throws MalformedObjectNameException
  129.     {
  130.         RoleUnresolvedListImpl roleUnresolvedList = new RoleUnresolvedListImpl();
  131.         List<ObjectName> rolelist1 = new LinkedList<ObjectName>();
  132.         rolelist1.add(new ObjectName("domain1", "key1", "value1"));
  133.         rolelist1.add(new ObjectName("domain2", "key2", "value2"));
  134.         roleUnresolvedList.add(0, new RoleUnresolved("rolename1", rolelist1, 1));
  135.  
  136.         List<ObjectName> roleList2 = new LinkedList<ObjectName>();
  137.         roleList2.add(new ObjectName("domain3", "key3", "value3"));
  138.         roleList2.add(new ObjectName("domain4", "key4", "value4"));
  139.         roleUnresolvedList.add(1, new RoleUnresolved("rolename2", roleList2, 2));
  140.  
  141.         List<RoleUnresolved> list = roleUnresolvedList.asList();
  142.         int index = 0;
  143.         while (index < list.size())
  144.         {
  145.             System.out.println(list.get(index++) + "\t");
  146.         }
  147.         System.out.println();
  148.     }
  149. }

$ javac RoleUnresolvedListImpl.java
$ java RoleUnresolvedListImpl
role name: rolename1; value: domain1:key1=value1, domain2:key2=value2; problem type: 1	
role name: rolename2; value: domain3:key3=value3, domain4:key4=value4; problem type: 2

Sanfoundry Global Education & Learning Series – 1000 Java Programs.

advertisement
advertisement
If you wish to look at all Java Programming examples, go to Java Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.