// // NumericSet.java - class NumericSet definition // // Code Developed for the Java Tutor column in Java Report Magazine // Copyright (c) 1996 by Philip Meese, All Rights Reserved // package ThirdParty.BarChart; public class NumericSet { // member data private int _length=0; // actual no of elemts in set private int _maxLength=25; // capacity of set private int _set[]; // internal storage array private boolean _debug=false; // off by default // member functions // // constructor public NumericSet(){ _set=new int[_maxLength]; } // parses a string with integers seperated by spaces in it public void setFromString(String s_){ int idx=0, idxSpace=0; for(_length=0; _length<_maxLength && idx < s_.length(); _length++){ // find end of first token idxSpace=s_.indexOf(" ", idx); if(idxSpace == -1) idxSpace=s_.length(); // end of string _set[_length]=Integer.parseInt(s_.substring(idx, idxSpace)); // eat white space while(s_.length() > ++idxSpace && !Character.isDigit(s_.charAt(idxSpace))) ; idx=idxSpace; } } // returns the value of a member of the set public int value(int idx_){ if(idx_ >= _length) return 0; else return _set[idx_]; } // returns the maximum value in the set public int max(){ int maxValue=0; for(int i=0;i<_length; i++) if(maxValue<_set[i]) maxValue=_set[i]; return(maxValue); } public int length() { return _length; } public void dump(){ System.out.println(getClass().getName() + ": " ); for(int i=0; i<_length; i++) System.out.println(" Elemt #" + i + "=" + _set[i]); } public void debugPrintln(String s_){ if(_debug) System.out.println(s_); } } // end of class NumericSet