Skip to content
Related Articles

Related Articles

Improve Article

Implementing RoleUnresolvedList API in Java

  • Last Updated : 13 Jan, 2021

An API is an acronym for Application Programming Interface, it is software that allows two applications to communicate with each other. RoleUnresolvedList represents the list of RoleUnresolved Object and RoleUnresolved Object represents the roles that are not retrieved from a relationship due to some problem encountered when trying to access read or write the roles. Thus, RoleUnresolvedList API is a program that communicates with the internal file to retrieve the object meaning and represents the roles which is not retrieved from relation due to some problem.

Prerequisites:

(A) Packages: In the RoleUnresolvedList  API program in java, various  Packages are used in order to retrieve the meaning and use of an object which is used in the program. Below Images shows the packages imported in the program:

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.relation.RoleUnresolved;
import javax.management.relation.RoleUnresolvedList;

NOTE: In Order to move further, please go through the following Packages  for better Understanding.

(B) Constructor’s Used



  • RoleUnresolvedList(): It is used to Construct Empty  RoleUnresolvedList.
  • RoleUnresolvedList(int initialCapacity): It is used to Construct an Empty RoleUnresolvedList with Initial Capacity specified.
  • RoleUnresolvedListImpl(List<RoleUnresolved> list): It is used to Construct RoleUnresolvedList containing elements of the list specified. It is Constructed in order to which they are returned by List Iterator.

(C) Methods

  • add(int index, Object element): This Method is used to insert the specific element in a specific position.
  • add(int index, RoleUnresolved role): This method inserts the Unresolved role specified as an element at the specified position.
  • add(Object o): It appends the specified element at the end of the list.
  • add(RoleUnresolved role): It will add the RoleUnresolved specified at the last element of the list.
  • addAll(Collection<?> c): It will append the elements in the specified list at the end.
  • addAll(int index, Collection<?> c): It will insert the elements at the specified location.
  • addAll(int index, RoleUnresolvedList roleList): Inserts all the elements in the RoleUnresolvedList specified into this list, starting at the specified position, in the order in which they are returned by the Iterator of the RoleUnresolvedList specified.

Java




// Java Program to Implement RoleUnresolvedList API
  
// Packages are imported whose methods
// will be used withinProgram
// Importing classes drom java.util package
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
// Importing javax.management package
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.relation.RoleUnresolved;
import javax.management.relation.RoleUnresolvedList;
  
// Class
public class GFG
  
{
    private RoleUnresolvedList roleUnresolvedList;
  
    // Constructor 1
    // It Constructs an empty RoleUnresolvedList
    public GFG()
    {
        roleUnresolvedList = new RoleUnresolvedList();
    }
  
    // Constructor 2
    // Constructs an empty RoleUnresolvedList
    // with the initial capacity specified
    public GFG(int initialCapacity)
  
    {
        roleUnresolvedList
            = new RoleUnresolvedList(initialCapacity);
    }
  
    // Constructor 3
    // It Constructs a RoleUnresolvedList containing
    // the elements of the List specified
    public GFG(List<RoleUnresolved> list)
  
    {
        roleUnresolvedList = new RoleUnresolvedList(list);
    }
  
    // Method 1
    // Inserts the specified element at the specified
    // position in this list
    public void add(int index, Object element)
  
    {
        roleUnresolvedList.add(index, element);
    }
  
    // Method 2
    // Inserts the unresolved role specified as an element
    // at the position specified.
    public void add(int index, RoleUnresolved role)
    {
        roleUnresolvedList.add(index, role);
    }
  
    // Method 3
    // Appends the specified element to the end of this list
    public boolean add(Object o)
    {
        return roleUnresolvedList.add(o);
    }
  
    // Method 4
    // Adds the RoleUnresolved specified as the last element
    // of the list
    public void add(RoleUnresolved role)
    {
        roleUnresolvedList.add(role);
    }
  
    // Method 5
    // Appends all of the elements in the specified
    // collection to the end of list, in the order that they
    // are returned by the specified collection's Iterator.
    public boolean addAll(Collection<?> c)
    {
        return roleUnresolvedList.addAll(c);
    }
  
    // Method 6
    // 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 roleUnresolvedList.addAll(index, c);
    }
  
    // Method 7
    // Inserts all of the elements in the RoleUnresolvedList
    // specified into list, starting at the specified
    // position, in the order in which they are returned by
    // the Iterator of the RoleUnresolvedList specified.
    public boolean addAll(int index,
                          RoleUnresolvedList roleList)
    {
        return this.roleUnresolvedList.addAll(index,
                                              roleList);
    }
  
    // Method 8
    // Appends all the elements in the RoleUnresolvedList
    // specified to the end of the list, in the order in
    // which they are returned by the Iterator o the
    // RoleUnresolvedList specified.
    public boolean addAll(RoleUnresolvedList roleList)
    {
        return roleList.addAll(roleList);
    }
  
    // Method 9
    // Return a view of this list as a List<RoleUnresolved>
    public List<RoleUnresolved> asList()
    {
        return roleUnresolvedList.asList();
    }
  
    // Method 10
    // Replaces the element at the specified position in
    // this list with the specified element
    public Object set(int index, Object element)
    {
        return roleUnresolvedList.set(index, element);
    }
  
    // Method 11
    // Sets the element at the position
    // specified to be the unresolved role specified.
    public void set(int index, RoleUnresolved role)
    {
        roleUnresolvedList.set(index, role);
    }
  
    // Method 12
    // Main driver method
    public static void main(String[] arg)
        throws MalformedObjectNameException
    {
        // Creating object of GFG class
        GFG roleUnresolvedList = new GFG();
  
        // Creating a List object
        // Declaring List of type ObjectName
        List<ObjectName> rolelist1
            = new LinkedList<ObjectName>();
  
        // Adding elements to above object
        // Custom inputs
        rolelist1.add(
            new ObjectName("domain1", "key1", "value1"));
        rolelist1.add(
            new ObjectName("domain2", "key2", "value2"));
        roleUnresolvedList.add(
            0,
            new RoleUnresolved("rolename1", rolelist1, 1));
  
        // Creating another List object
        List<ObjectName> roleList2
            = new LinkedList<ObjectName>();
  
        // Adding elements to above object
        // Custom inputs
        roleList2.add(
            new ObjectName("domain3", "key3", "value3"));
        roleList2.add(
            new ObjectName("domain4", "key4", "value4"));
        roleUnresolvedList.add(
            1,
            new RoleUnresolved("rolename2", roleList2, 2));
  
        // Creating(declaring) object of type RoleUnresolved
        List<RoleUnresolved> list
            = roleUnresolvedList.asList();
  
        // Initialising variable count
        int index = 0;
  
        // Condition check using size() method in List
        while (index < list.size())
  
        {
            // Print the elements
            System.out.println(list.get(index++) + "\t");
        }
  
        // As the condition fails
        // jump to new line
        System.out.println();
    }
}
Output
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

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :