java - How to use variables for each object -


i have array of elements. making object on basis of each elements name , call getter functions. object of class making third party library, "sigar".

the problem don't want modify third party library, because of not able keep variables values separate each object. need come way keep separate variable separate each object.

i hope description explains want. following code

private long lastdiskcheck = 0; private long lastdiskread = 0; private long lastdiskwrite = 0; private string getdiskusage() {     try {         list<filesystem> result = new arraylist<filesystem>();         org.hyperic.sigar.filesystem[] fss = null;         fss = sig.getfilesystemlist();         list<integer> diskusage = new arraylist<integer>();         string iostat = "";         (int = 0; i<fss.length; i++) {             filesystem fs = fss[i];             filesystemusage usage = sig.getfilesystemusage(fs.getdirname());             if (lastdiskcheck!=0) {                 long diff = (nanotime() - lastdiskcheck)/1000000;                 long diffread = usage.getdiskreadbytes() - lastdiskread;                 long diffwrite = usage.getdiskwritebytes() - lastdiskwrite;                 iostat = string.format("(%d/%d kb/s)", diffread/diff, diffwrite / diff);             }             lastdiskread = usage.getdiskreadbytes();             lastdiskwrite = usage.getdiskwritebytes();             lastdiskcheck = nanotime();             diskusage.add((int)(usage.getusepercent()*100));         }         return string.format("%d%% %s", (collections.max(diskusage)), iostat);     } catch (sigarexception e) {         e.printstacktrace();     }     return "n/a"; } 

the 3 variables

private long lastdiskcheck = 0; private long lastdiskread = 0; private long lastdiskwrite = 0; 

updates each object inside loop don't want. how can keep different each object?

public class myclass {     private long lastdiskcheck;     private long lastdiskread;     private long lastdiskwrite;      private yourobject object;      public void setlastdiskcheck(lastdiskcheck){ // setter of lastdiskcheck         this.lastdiskcheck = lastdiskcheck;     }      public long getlastdiskcheck(){ //getter of lastdiskcheck         return lastdiskcheck;     } } 

with methodology, can keep each object in myclass , keep different value each.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -