whats the max num of parameters a constructor can have?

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

whats the max num of parameters a constructor can have?

Postby PatrickLismore » Thu Jan 17, 2008 10:25 am

Every time i try and load up a constructor with more than 15 parameters I keep getting the error message that only 16 are allowed.

Does any one know why this is and is there away around it.

I am currently trying to pass data via channels i am using JCSP , so i have 3 LightSensor processes , three filters all trying to feed into and out of my control process but I keep getting hit with this error that I have to many parameters.

I cant leave a parameter out because if you have an .in() you must have somewhere a corresponding out.() so having one without the other would cause a bug,

So does anyone know if there is a limit to the number of parameters that a constructor can have in Lejos.

thanks P
User avatar
PatrickLismore
Active User
 
Posts: 81
Joined: Tue Oct 16, 2007 7:28 pm
Location: Prague

Postby kirkpthompson » Thu Jan 17, 2008 1:42 pm

If I understand your problem correctly...

Try to create a class w/public variables:
Code: Select all
public class DataStruct {
  public int param1;
  public int param2;
  public String param3;
  ...
  public xxx param20;
}

Create an instance and populate the vars:
Code: Select all
DataStruct myData = new DataStruct();
myData.param1 = 23;
myData.param2 = -999;
...

And use that class as the data type in the constructor of the class you need 16+ params for:
Code: Select all
class myClass {
  private DataStruct localData;
 
  public myClass(DataStruct passedData) {
    localData = passedData;
     ...
  }
}

and pass an instance of that to your class's constructor:
Code: Select all
...
MyClass mc = new MyClass(myData);
...
User avatar
kirkpthompson
leJOS Team Member
 
Posts: 304
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA

Postby PatrickLismore » Thu Jan 17, 2008 3:02 pm

here is my class, you will see that i have instantiated 3 ActiveLightSensor processes, then 3 Binary Filter processes, and finally a process called, logic.

The logic process as you can see is being passed 16 parameters, that logic class constructor is expecting all those parameters but when you compile the error message was saying that only 16 parameter words allowed and that i have 17.


Code: Select all
public class control implements CSProcess {

   
   
   Parallel par = new Parallel();
   
   private ChannelInputInt buttonPress;

        //==sensor ports i have three left, center, right
   private SensorPort sLeft;
   private SensorPort sCenter;
   private SensorPort sRight;

        //===setup channels of communication between
        //===processes , ActiveLightSensor, Binary Filter, logic
        //===================================
   private One2OneChannelInt configLeft;
   private One2OneChannelInt configCenter;
   private One2OneChannelInt configRight;

        //====output values from ActiveLightSensor process
   private One2OneChannelInt outLeft;
        private One2OneChannelInt outCenter;
   private One2OneChannelInt outRight;

        //====light levels===============
   private One2OneChannelInt levelLeft;
   private One2OneChannelInt levelCenter;
   private One2OneChannelInt levelRight;

        //===Black values from the filters===========
   private One2OneChannelInt filterOutBlackLeft;
   private One2OneChannelInt filterOutBlackCenter;
   private One2OneChannelInt filterOutBlackRight;

        //===white values from the filters============
   private One2OneChannelInt filterOutWhiteLeft;
   private One2OneChannelInt filterOutWhiteCenter;
   private One2OneChannelInt filterOutWhiteRight;

        //===Level Out================
   private One2OneChannelInt outLLeft;
   private One2OneChannelInt outLCenter;
   private One2OneChannelInt outLRight;

        //====configure filters=============
   private One2OneChannelInt filterConfigLeft;
   private One2OneChannelInt filterConfigCenter;
   private One2OneChannelInt filterConfigRight;
   
   
   public control (ChannelInputInt buttonPress ){
      
      this.buttonPress = buttonPress;
      
      //-----------------------------------------------
      //SENSORS>>>>>>>>>>>>>>>>>>>>
      //====left====================
      par.addProcess( new ActiveLightSensor ( sLeft, 25, configLeft.in(), levelLeft.out(), outLeft.out()  ) );

      par.addProcess( new BinaryFilter ( filterOutBlackLeft.out(), filterOutWhiteLeft.out(), outLLeft.in(), filterConfigLeft.in()));
      
                 //==center=====================
      par.addProcess( new ActiveLightSensor ( sCenter, 25, configCenter.in(), levelCenter.out(), outCenter.out()  ) );
      
               par.addProcess( new BinaryFilter ( filterOutBlackCenter.out(), filterOutWhiteCenter.out(), outLCenter.in(), filterConfigCenter.in()));
      
                //====right======================
      par.addProcess( new ActiveLightSensor ( sRight, 25, configRight.in(), levelRight.out(), outRight.out()  ) );
      
                 par.addProcess( new BinaryFilter ( filterOutBlackRight.out(), filterOutWhiteRight.out(), outLRight.in(), filterConfigRight.in()));
      //======end====
          //>>>>>>>>>>>>>>>>
              //------------------------------
      
//=========control
      par.addProcess( new logic(buttonPress,
                                 levelLeft,
            levelCenter,
            levelRight,
            filterOutWhiteLeft,
            filterOutWhiteCenter,
            filterOutWhiteRight,
            filterOutBlackLeft,
            filterOutBlackCenter,
            filterOutBlackRight,
            configLeft,
            configCenter,
            configRight,
            filterConfigLeft,
            filterConfigCenter,
            filterConfigRight));
      
   }
   public void run() {
      
      par.run();
      
      
   }
[/code]
User avatar
PatrickLismore
Active User
 
Posts: 81
Joined: Tue Oct 16, 2007 7:28 pm
Location: Prague

Postby PatrickLismore » Thu Jan 17, 2008 3:18 pm

Ill see if i can implement your solution,


kirkpthompson wrote:If I understand your problem correctly...

Try to create a class w/public variables:
Code: Select all
public class DataStruct {
  public int param1;
  public int param2;
  public String param3;
  ...
  public xxx param20;
}

Create an instance and populate the vars:
Code: Select all
DataStruct myData = new DataStruct();
myData.param1 = 23;
myData.param2 = -999;
...

And use that class as the data type in the constructor of the class you need 16+ params for:
Code: Select all
class myClass {
  private DataStruct localData;
 
  public myClass(DataStruct passedData) {
    localData = passedData;
     ...
  }
}

and pass an instance of that to your class's constructor:
Code: Select all
...
MyClass mc = new MyClass(myData);
...
User avatar
PatrickLismore
Active User
 
Posts: 81
Joined: Tue Oct 16, 2007 7:28 pm
Location: Prague


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 1 guest

cron
more stuff