mardi 8 décembre 2015

Looking for a design pattern & List to store multiple Types (object & integer)

I guess I'm looking for an Design-Pattern but I have a hard time to evalute which one is the one I need.

I'm gonna explain my setup a little and then it may be clear to some1 that has a little more experience.

  • When my Application starts I want to create a number of Objects of a class that is in a different .java file
  • Their lifecyle should only end when the Application is being closed, so I can access them while the application is running from any class whithin my application

Right now I read in data from my database, & create the Objects using that data, but when leaving that function those Objects lifecyle is up but I want them to stay till my application closes.

I'm working on an web application using Java & JSP & Apache Shiro Framework

I have this class that runs at application start

Startup.java

public class Startup implements javax.servlet.ServletContextListener {

    private static final transient Logger log = LoggerFactory.getLogger(Startup.class);

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        // Code here is executed on application startup

    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        // Code here is executed on application close
        throw new UnsupportedOperationException("Not supported yet.");
    }
}

The second thing I'm looking for is a List that stores Object of multiple types. So far I have a List that stores 3 List of Integers:

public List<List<Integer>> roles = new ArrayList<List<Integer>>(3);
roles.add(new ArrayList<Integer>());
roles.add(new ArrayList<Integer>());
roles.add(new ArrayList<Integer>());

What i really want is a List that stores object of a class in the first List and Integers in the 2 other Lists like this:

public List<List<Object>> roles = new ArrayList<List<Object>>(3);
roles.add(new ArrayList<Role>());    //error here (Role is a class inside my application)
roles.add(new ArrayList<Integer>()); //error here
roles.add(new ArrayList<Integer>()); //error here

Can any1 help me with those two issues??

Aucun commentaire:

Enregistrer un commentaire