All Downloads are FREE. Search and download functionalities are using the official Maven repository.

moa.options.AbstractOptionHandler Maven / Gradle / Ivy

Go to download

Massive On-line Analysis is an environment for massive data mining. MOA provides a framework for data stream mining and includes tools for evaluation and a collection of machine learning algorithms. Related to the WEKA project, also written in Java, while scaling to more demanding problems.

There is a newer version: 2024.07.0
Show newest version
/*
 *    AbstractOptionHandler.java
 *    Copyright (C) 2007 University of Waikato, Hamilton, New Zealand
 *    @author Richard Kirkby ([email protected])
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program. If not, see .
 *    
 */
package moa.options;

import com.github.javacliparser.Options;
import moa.AbstractMOAObject;
import moa.core.ObjectRepository;
import moa.tasks.NullMonitor;
import moa.tasks.TaskMonitor;

/**
 * Abstract Option Handler. All classes that have options in
 * MOA extend this class.
 *
 * @author Richard Kirkby ([email protected])
 * @version $Revision: 7 $
 */
public abstract class AbstractOptionHandler extends AbstractMOAObject implements
        OptionHandler {

    private static final long serialVersionUID = 1L;

    /** Options to handle */
    //protected Options options;

    /** Dictionary with option texts and objects */
    //protected Map classOptionNamesToPreparedObjects;

    @Override
    public String getPurposeString() {
        return "Anonymous object: purpose undocumented.";
    }

    @Override
    public Options getOptions() {
        /*if (this.options == null) {
            this.options = new Options();
            if (this.config== null) {
                this.config = new OptionsHandler(this, "");
                this.config.prepareForUse();
            }
            Option[] myOptions = this.config.discoverOptionsViaReflection();
            for (Option option : myOptions) {
                this.options.addOption(option);
            }
        }
        return this.options;*/
        if ( this.config == null){
            this.config = new OptionsHandler(this, "");
            //this.config.prepareForUse(monitor, repository);
        }
        return this.config.getOptions();
    }

    @Override
    public void prepareForUse() {
        prepareForUse(new NullMonitor(), null);
    }

    protected OptionsHandler config; 
    
    @Override
    public void prepareForUse(TaskMonitor monitor, ObjectRepository repository) {
        //prepareClassOptions(monitor, repository);
        if ( this.config == null){
            this.config = new OptionsHandler(this, "");
            this.config.prepareForUse(monitor, repository);
        }
        prepareForUseImpl(monitor, repository);
    }

    /**
     * This method describes the implementation of how to prepare this object for use.
     * All classes that extends this class have to implement prepareForUseImpl
     * and not prepareForUse since
     * prepareForUse calls prepareForUseImpl.
     *
     * @param monitor the TaskMonitor to use
     * @param repository  the ObjectRepository to use
     */
    protected abstract void prepareForUseImpl(TaskMonitor monitor,
            ObjectRepository repository);

    @Override
    public String getCLICreationString(Class expectedType) {
        return ClassOption.stripPackagePrefix(this.getClass().getName(),
                expectedType)
                + " " + getOptions().getAsCLIString();
    }

    @Override
    public OptionHandler copy() {
        return (OptionHandler) super.copy();
    }

    /**
     * Gets the options of this class via reflection.
     *
     * @return an array of options
     */
 /*   protected Option[] discoverOptionsViaReflection() {
        Class c = this.getClass();
        Field[] fields = c.getFields();
        List




© 2015 - 2025 Weber Informatics LLC | Privacy Policy