if(indexString.length() != 0){ if(indexString.equals("first")) getInstances().setClassIndex(0); else{ if(indexString.equals("last")) getInstances().setClassIndex(getInstances().numAttributes()-1); else{ int classIndex = Integer.parseInt(indexString); if(classIndex >=0 && classIndex < getInstances().numAttributes()) getInstances().setClassIndex(classIndex); else throw new IOException("Invalid class index"); } } } else getInstances().setClassIndex(getInstances().numAttributes()-1);
  public void setOptions(String[] options) throws Exception {        String outputString = Utils.getOption('o', options);    String inputString = Utils.getOption('i', options);    String indexString = Utils.getOption('c', options);        ArffLoader loader = new ArffLoader();        resetOptions();        if(inputString.length() != 0){        try{            File input = new File(inputString);            loader.setFile(input);            setInstances(loader.getDataSet());        } catch(Exception ex){            throw new IOException("No data set loaded. Data set has to be arff format.");        }    }    else        throw new IOException("No data set to save.");    if (outputString.length() != 0){         //add appropriate file extension        if(!outputString.endsWith(getFileExtension())){            if(outputString.lastIndexOf('.') != -1)                outputString = (outputString.substring(0,outputString.lastIndexOf('.'))) + getFileExtension();            else                outputString = outputString + getFileExtension();        }        try{            File output = new File(outputString);            setFile(output);        } catch(Exception ex){            throw new IOException("Cannot create output file.");        } finally{            setDestination(retrieveFile());        }    }    if(indexString.length() != 0){        if(indexString.equals("first"))            getInstances().setClassIndex(0);        else{            if(indexString.equals("last"))                getInstances().setClassIndex(getInstances().numAttributes()-1);            else{                int classIndex = Integer.parseInt(indexString);                if(classIndex >=0 && classIndex < getInstances().numAttributes())                    getInstances().setClassIndex(classIndex);                else                    throw new IOException("Invalid class index");            }        }    }    else        getInstances().setClassIndex(getInstances().numAttributes()-1);  }