Java Program to Implement AttributeList API

This Java program Implements AttributeList API.Represents a list of values for attributes of an MBean.

Here is the source code of the Java Program to Implement AttributeList 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.List;
import javax.management.Attribute;
import javax.management.AttributeList;
 
public class AttributeListImpl
{
    private AttributeList attributeList;
 
    /** Constructs an empty AttributeList. **/
    public AttributeListImpl()
    {
        attributeList = new AttributeList();
    }
 
    /**
     * Constructs an AttributeList containing the elements of the AttributeList
     * specified, in the order in which they are returned by the AttributeList's
     * iterator.
    **/
    public AttributeListImpl(AttributeList list)
    {
        attributeList = new AttributeList();
    }
 
    /** Constructs an empty AttributeList with the initial capacity specified. **/
    public AttributeListImpl(int initialCapacity)
    {
        attributeList = new AttributeList(initialCapacity);
    }
 
    /**
     * Constructs an AttributeList containing the elements of the List
     * specified, in the order in which they are returned by the List's
     * iterator.
     **/
    public AttributeListImpl(List<Attribute> list)
    {
        attributeList = new AttributeList();
    }
 
    /** Adds the Attribute specified as the last element of the list. **/
    public void add(Attribute object)
    {
        attributeList.add(object);
    }
 
    /** Inserts the attribute specified as an element at the position specified. **/
    public void add(int index, Attribute object)
    {
        attributeList.add(index, object);
    }
 
    /** Inserts the specified element at the specified position in this list. **/
    public void add(int index, Object element)
    {
        attributeList.add(index, element);
    }
 
    /** Appends the specified element to the end of this list. **/
    public boolean add(Object element)
    {
        return attributeList.add(element);
    }
 
    /**
     * Appends all the elements in the AttributeList specified to the end of the
     * list, in the order in which they are returned by the Iterator of the
     * AttributeList specified.
    **/
    public boolean addAll(AttributeList list)
    {
        return attributeList.addAll(list);
    }
 
    /**
     * 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 attributeList.addAll(c);
    }
 
    /**
     * Inserts all of the elements in the AttributeList specified into this
     * list, starting at the specified position, in the order in which they are
     * returned by the Iterator of the AttributeList specified.
     **/
    public boolean addAll(int index, AttributeList list)
    {
        return attributeList.addAll(index, list);
    }
 
    /**
     * 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 attributeList.addAll(index, c);
    }
 
    /** Return a view of this list as a List<Attribute>. **/
    public List<Attribute> asList()
    {
        return attributeList.asList();
    }
 
    /** Sets the element at the position specified to be the attribute specified. **/
    public void set(int index, Attribute element)
    {
        attributeList.set(index, element);
    }
 
    /**
     * Replaces the element at the specified position in this list with the
     * specified element.
    **/
    public Object set(int index, Object element)
    {
        return attributeList.set(index, element);
    }
 
    public static void main(String... arg)
    {
        AttributeListImpl attributeList = new AttributeListImpl();
        attributeList.add(new Attribute("one", 1));
        attributeList.add(new Attribute("two", 2));
        attributeList.add(new Attribute("three", 3));
        attributeList.add(new Attribute("four", 4));
        attributeList.add(new Attribute("five", 5));
        attributeList.add(new Attribute("six", 7));
        System.out.println("the elements of the attributelist are");
        List<Attribute> list = attributeList.asList();
        int index = 0;
        while (index < list.size())
        {
            System.out.print(list.get(index++) + "\t");
        }
        System.out.println();
        attributeList.set(5, new Attribute("six", 6));
        System.out.println("after setting index 5");
        System.out.println("the elements of the attributelist are");
        list = attributeList.asList();
        index = 0;
        while (index < list.size())
        {
            System.out.print(list.get(index++) + "\t");
        }
    }
}
$ javac AttributeListImpl.java
$ java AttributeListImpl
the elements of the attributelist are
one = 1	two = 2	three = 3	four = 4	five = 5	six = 7	
after setting index 5
the elements of the attributelist are
one = 1	two = 2	three = 3	four = 4	five = 5	six = 6

Related posts:

Giới thiệu Aspect Oriented Programming (AOP)
Java Program to Find the Longest Path in a DAG
Java Program to Check Whether a Directed Graph Contains a Eulerian Cycle
Java Program to Check if a Directed Graph is a Tree or Not Using DFS
Spring Security Logout
Java Program to Implement RenderingHints API
Java Program to Implement an Algorithm to Find the Global min Cut in a Graph
Java Program to Implement Max-Flow Min-Cut Theorem
Reading an HTTP Response Body as a String in Java
Java Program to Perform the Shaker Sort
Request a Delivery / Read Receipt in Javamail
Java Program to Perform Inorder Recursive Traversal of a Given Binary Tree
Java Program to Check Whether an Input Binary Tree is the Sub Tree of the Binary Tree
Java Program to Check whether Directed Graph is Connected using BFS
Java Program to Implement Sieve Of Atkin
Introduction to Spring Cloud OpenFeign
Java Program to Implement Interpolation Search Algorithm
Java Program to Implement ConcurrentSkipListMap API
Java Program to Implement Heap’s Algorithm for Permutation of N Numbers
Guide to DelayQueue
Java Program to Implement Leftist Heap
Từ khóa static và final trong java
The Spring @Controller and @RestController Annotations
Tạo ứng dụng Java RESTful Client với thư viện Retrofit
Java InputStream to String
Java Program to Implement Segment Tree
Guide to the ConcurrentSkipListMap
Setting a Request Timeout for a Spring REST API
Tổng quan về ngôn ngữ lập trình java
Spring Boot - CORS Support
Spring Boot Tutorial – Bootstrap a Simple Application
Convert Character Array to String in Java