How to get values from Java List<E>?

2.4k views Asked by At

I'm trying to write a mini plugin for the BMC Action Request System Server.

filterAPICall
public abstract List<com.bmc.arsys.api.Value> filterAPICall(ARPluginContext context,
                                                        List<com.bmc.arsys.api.Value> pInValues)
                                                 throws com.bmc.arsys.api.ARExceptionDescription copied from interface: ARFilterAPIPluggable

Given a set of input values, process it and return a list of output values. The plugin context and instance data are also provided.

Specified by:
filterAPICall in interface ARFilterAPIPluggable

Parameters:
context - Current context for this plugin call, like username etc.
pInValues - input values 

Returns:
output values 

Throws: 
com.bmc.arsys.api.ARException

The description of com.bmc.arsys.api.Value is here: http://www.javasystemsolutions.com/documentation/thirdparty/arapiv75/com/bmc/arsys/api/Value.html

Now, here is my call:

    public List<Value> filterAPICall(ARPluginContext context, List<Value> pInValues) throws ARException{
        context.logMessage(pluginInfo, ARPluginContext.PLUGIN_LOG_LEVEL_INFO, "filterapiCall()");

        if (pInValues.size() == 0)
            return null;

        ArrayList<Value> outValues = new ArrayList<Value>();

        outValues.add(0, new Value(String.valueOf(InetAddresses.isInetAddress(String.valueOf(pInValues)))));

        return outValues;
    }

For some reason

    outValues.add(0, new Value(String.valueOf(InetAddresses.isInetAddress(String.valueOf(pInValues)))));

is not working.

I've also tried:

    outValues.add(0, new Value(String.valueOf(InetAddresses.isInetAddress(String.valueOf(pInValues.getValue())))));

but the compiler says:

javac IPChecker.java
IPChecker.java:30: cannot find symbol
symbol  : method getValue()
location: interface java.util.List<com.bmc.arsys.api.Value>
        outValues.add(0, new Value(String.valueOf(InetAddresses.isInetAddress(String.valueOf(pInValues.getValue())))));
                                                                                                      ^
1 error

Any ideas?

Thanks Thomas

3

There are 3 answers

0
adarshr On BEST ANSWER

You should be iterating.

if (pInValues.size() == 0)
    return null;

ArrayList<Value> outValues = new ArrayList<Value>();

for(Value value : pInValues) {
    outValues.add(0, new Value(String.valueOf(InetAddresses.isInetAddress(String.valueOf(value)))));
}

return outValues;
1
Hari Menon On

pInValues is a java.util.List. Lists don't have a getValue() method.

0
Attila On

You will need to access an element in the List to be able to call getValue() on it. Try:

outValues.add(0, new Value(String.valueOf(InetAddresses.isInetAddress(
    String.valueOf(pInValues.get(0).getValue())))));

This will translate the first element and add it to the output list. To get all elements, you need to iterate through the elements in pInValues and translate them one-by-one, adding each result to the output list