java - Calling a method with it's previous values on a single line -
so have quite simple method, has 1 job, has give me min , max values of chaning variable.
public int[] axislimits(int axisinfo, int axismin, int axismax){ if(axisinfo >= axismax){ axismax = axisinfo; }else if(axisinfo < axismin){ axismin = axisinfo; } int axislimits[] = {axismin, axismax}; /* axislimits[0] = axismin; axislimits[1] = axismax; */ return axislimits; }
previously had int axislimits[] = new int[2], that's why have 2 lines commented.
so it's works fine, have predefine 2 variable every axis, , save min , max values before next call:
int limitz[] = new limits().axislimits((int)accelz, minaccelz, maxaccelz); minaccelz = limitz[0]; maxaccelz = limitz[1];
and can use minaccelz , max accelz or limitz[0] , limitz[1].
is there way go around , make single line call? (so can work limitz[0] , limitz[1] needed?
how class like:
public class minmax { private int min; private int max; public minmax(int min, int max) { this.min = min; this.max = max; } public minmax axisinfo(int axisinfo) { if ( axisinfo > max ) max = axisinfo; else if ( axisinfo < min ) min = axisinfo; return this; } public int getmin() { return min; } public int getmax() { return max; } }
and then:
minmax m = new minmax(100,1000) .axisinfo(1500) .axisinfo(90) .axisinfo(70); int min = m.getmin(); int max = m.getmax();
Comments
Post a Comment