2 Replies Latest reply: May 14, 2010 1:52 PM by jschellSomeoneStoleMyAlias RSS

    Failing to code algorithm

    843853
      Hi,

      consider the following situation:

      - I have an array of Class-objects

      I need to check if the Class-objects inside the arrays are primitive-wrappers (Integer.class, Boolean.class, Character.class,...)
      If they are, I want 2 Class[]-arrays (one with the wrapper, one with the primitive).

      Still following?

      Example:
      Class[] classes = new Class[] { String.class, Boolean.class, Double.class };
      I want to pass this to my function and retrieve a List<Class[]> object that contains the following Class[]-arrays
      - String.class, Boolean.class, Double.class
      - String.class, boolean.class, Double.class
      - String.class, Boolean.class, double.class
      - String.class, boolean.class, double.class

      So when there's 2 primitive-wrappers, I receive a list of 4 Class[]-arrays, if there are 20 wrappers, I'd receive a list of 400 Class[]-arrays.

      Is there a standard algorithm for this?
      If not, some help is welcome.

      B.
        • 1. Re: Failing to code algorithm
          800459
          So when there's 2 primitive-wrappers, I receive a list of 4 Class[]-arrays, if there are 20 wrappers, I'd receive a list of 400 Class[]-arrays.
          I can see little correction here. when you 2 primitive-wrappers, you should expect 2^2=4 class[]-arrays
          for 3 primitive-wrappers, you should expect 2^3=8 class[]-arrays
          for 4 primitive-wrappers, you should expect 2^4=16 class[]-arrays
          for 5 primitive-wrappers, you should expect 2^5=32 class[]-arrays
          Similarly for 20 primitive-wrappers, you should expect 2^20 class[]-arrays.

          Also As per my knowledge I couldn't see any direct solution of it from java. One hint is, you need to maintain list/map of all primitives and their wrappers while working on it.
          • 2. Re: Failing to code algorithm
            jschellSomeoneStoleMyAlias
            thierensb wrote:
            Is there a standard algorithm for this?
            No.
            If not, some help is welcome.
            What is the problem? It is solved with some if/else structures and nothing else is really needed.