Results 1 to 5 of 5
  1. #1
    aragornx is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Default How to map parameters from multiple classes into one set of parameters ?

    I have multiple Java classes that holds lots of time based parameters, e.g.: (simplified):

    Java Code:
    class Engine {
       float rpm;
       boolean enabled;
       int runningTime;
    }
    
    class Temperature {
       float degrees;
    }
    
    class Tank {
       float maxVolume;
       float currentVolume;
    }
    
    class TimeRecord {
       Engine engine1Params;
       Temperature temp1Sensor;
       Temperature temp2Sensor;
       Tank tank1;
       Tank tank2;
       [...]
       Time timeStamp;
    }
    Now the problem is that I want to present all this parameter to user in one parameters set:

    Engine 1 RPM
    Engine 1 On
    Engine 1 Running Time
    Temperature #1
    Temperature #2
    [...]
    Tank #1 Volume

    Is there any simply solution to map all these parameters from my TimeRecord to one list(vector,map) of params that user can choose from and see the value in proper form (floating type, boolean type) ?

    I will be greatfull for any advice...

    PS.
    I just want that user can pick a paremter's name from list or combobox and choose parameter that he wants to see. I don't want to duplicate the data - just some kind of mapping algorithm between list of parameters names and my TimeRecord. eg. some collection class that holds all names and connections: Parameters params; fill combo/list from this class for ( String name : params ) { combo.add(name);}, then when user picks some field from combo: params.getValue( myTimeRecord, name ) return correct parameter value (just my first thought)

    PS.2
    Later, I want to replace all floats,ints,booleans with some kind of templated class eg. Value which will hold all kinds of measurement unit with conversion support - but it's only a plan now. I still trying to make a good design of data structers - and I'm a little bit confused now - that's the reason of my question...

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,165
    Rep Power
    6

    Default Re: How to map parameters from multiple classes into one set of parameters ?

    This may help:

    BeanUtils - Commons

    Specifically: the BeanMap class. You might also like the many object to JSON conversion APIs, such as Google GSON.
    Last edited by gimbal2; 03-06-2014 at 10:56 AM.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    aragornx is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Default Re: How to map parameters from multiple classes into one set of parameters ?

    Thank you - BeanUtils looks promising. One more question for advise. How do you see issues with replacing standard types (floats,ints) with some class that supports different types of values and units (Metric,US) conversion. I intend to make one interface
    Java Code:
    public interface ParameterInterface {
       public void set( UnitType value) throws UnitIncompatibleTypesException;
       public void set( String stringValue );
       public String get();
       public Unit getUnit();
       public String get( Unit u );
    }
    then eg.:
    Java Code:
    public ParameterDouble implements ParameterInterface {
       private double value = 0.0;
       public void set( String val ) {
          this.value = Double.parseDouble(val);
       }
       [...]
    }
    I'm not sure it it's good designed in case of lots of converstions from double->string string->double. Are there any design patterns that supports classes for holding multiple types of values?
    Thanks again for BeanUtils...

  4. #4
    aragornx is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Default Re: How to map parameters from multiple classes into one set of parameters ?

    Now I think the better solutin will be something similar to JScience:
    Java Code:
    class Tank1 {
       Amount<Volume> vol;
       Amount<Volume> maxVol;
       Amount<Temperature> temp;
       Amount<Ph> ph;
    }
    But I'm not sure how to make such a structure...

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,165
    Rep Power
    6

    Default Re: How to map parameters from multiple classes into one set of parameters ?

    When you start to build something you are never sure about how the implementation will end up; that's the development process, you refine it as you go along. I advise you to stop being insecure, dig in and start making and correcting mistakes. Its the best way to learn.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Replies: 3
    Last Post: 01-12-2013, 10:03 PM
  2. query with multiple IN parameters
    By learnjava32 in forum JDBC
    Replies: 3
    Last Post: 10-09-2012, 05:44 PM
  3. Replies: 10
    Last Post: 01-24-2012, 11:02 PM
  4. Replies: 5
    Last Post: 11-21-2010, 03:08 PM
  5. Replies: 4
    Last Post: 10-01-2010, 11:52 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •