0

I want to use a java library that acts as a substitute for ArrayLists...This library ("Vanilla Java Collections")requires an interface to be declared in the following manner--

interface MutableBoolean {
    public void setFlag(boolean b);
    public boolean getFlag();
}

This is how this list is declared--

// create a huge array of MutableBoolean
HugeArrayList<MutableBoolean> hugeList = new HugeArrayBuilder<MutableBoolean>() {}.create();
List<MutableBoolean> list = hugeList;

This is how data is retrieved--

for (MutableTypes mb : list) {
boolean b1 = mb.getBoolean();

There can be multiple data types within the same interface to insert/retrieve string, integer, double etc values...

Now, in an application I am working on there is a custom variable definition--

public abstract class Variable implements MutableVariable  {

    abstract public byte[] toBinary();
    abstract public byte[] toBinary(String charset);
    abstract public String toString();
    abstract public String toString(String charset);
    abstract public List toList();
    abstract public boolean isEmpty();
    abstract public Object getWrappedObject();
    ----plus some more functions----

Also there is a class "NodeVariable" which extends "Variable" and another class "ListVariable" which implements Variable-- Each ListVariable has a List plus some utility functions pertaining to lists and string manipulation.

I want to implement the array substitute("Vanilla Java Collections") - which requires an interface- in place of the 'ListVariable'. But the class "Variable" is an abstract class. So I am confused here- how do I implement the interface so that I can use the ArrayList Substitute("Vanilla Java Collections") in place of "ListVariable"?

And is this possible with minimal changes to the existing code that utilises "ListVariable" i.e. by making all/most changes to the "ListVariable" class?

1 Answer 1

0

If I understand your question correctly, you want ot use a class named ArayListVariable that you can use anywhere where you could use a ListVariable. If this is the case, you can either extend the Variable abstract class

public class ArrayListVariable extends Variable
{
  // overrides of required functions
}

or implement the MutableVariable interface

public class ArrayListVariable implements MutableVariable
{
  // implementations of required functions
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.