{
        JDOFatalInternalException ex = new JDOFatalInternalException(msg);
        logger.throwing("jqlc.ErrorMsg", "fatal", ex);
        throw ex;
    }

/*
 * ErrorMsg.java
 *
 * Created on April 3, 2000
 */
package com.sun.jdo.spi.persistence.support.sqlstore.query.jqlc;

import java.util.ResourceBundle;
import com.sun.jdo.api.persistence.support.JDOQueryException;
import com.sun.jdo.api.persistence.support.JDOFatalInternalException;
import com.sun.jdo.api.persistence.support.JDOUnsupportedOptionException;
import com.sun.jdo.spi.persistence.utility.logging.Logger;
import org.glassfish.persistence.common.I18NHelper;

/**
 * @author  Michael Bouschen
 * @version 0.1
 */
public class ErrorMsg {

    protected String context = null;

    /**
     * I18N support
     */
    protected final static ResourceBundle messages = I18NHelper.loadBundle(ErrorMsg.class);

    /**
     * The logger
     */
    private static Logger logger = LogHelperQueryCompilerJDO.getLogger();

    public String getContext() {
        return context;
    }

    public void setContext(String name) {
        context = name;
    }

    /**
     * Indicates an error situation.
     * @param line line number
     * @param col column number
     * @param msg error message
     */
    public void error(int line, int col, String msg) throws JDOQueryException {
        JDOQueryException ex;
        if (line > 1) {
            // include line and column info
            Object[] args = { context, line, col, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msglinecolumn", // NOI18N
            args));
        } else if (col > 0) {
            // include column info
            Object[] args = { context, col, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msgcolumn", // NOI18N
            args));
        } else {
            Object[] args = { context, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msg", // NOI18N
            args));
        }
        logger.throwing("jqlc.ErrorMsg", "error", ex);
        throw ex;
    }

    /**
     * Indicates that a feature is not supported by the current release.
     * @param line line number
     * @param col column number
     * @param msg message
     */
    public void unsupported(int line, int col, String msg) throws JDOUnsupportedOptionException {
        JDOUnsupportedOptionException ex;
        if (line > 1) {
            // include line and column info
            Object[] args = { context, line, col, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msglinecolumn", // NOI18N
            args));
        } else if (col > 0) {
            // include column info
            Object[] args = { context, col, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msgcolumn", // NOI18N
            args));
        } else {
            Object[] args = { context, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msg", // NOI18N
            args));
        }
        logger.throwing("jqlc.ErrorMsg", "unsupported", ex);
        throw ex;
    }

    /**
     * Indicates a fatal situation (implementation error).
     * @param msg error message
     */
    public void fatal(String msg) throws JDOFatalInternalException

    /**
     * Indicates a fatal situation (implementation error).
     * @param msg error message
     */
    public void fatal(String msg, Exception nested) throws JDOFatalInternalException {
        JDOFatalInternalException ex = new JDOFatalInternalException(msg, nested);
        logger.throwing("jqlc.ErrorMsg", "fatal", ex);
        throw ex;
    }
}


/*
 * ErrorMsg.java
 *
 * Created on April 3, 2000
 */
package com.sun.jdo.spi.persistence.support.sqlstore.query.jqlc;

import java.util.ResourceBundle;
import com.sun.jdo.api.persistence.support.JDOQueryException;
import com.sun.jdo.api.persistence.support.JDOFatalInternalException;
import com.sun.jdo.api.persistence.support.JDOUnsupportedOptionException;
import com.sun.jdo.spi.persistence.utility.logging.Logger;
import org.glassfish.persistence.common.I18NHelper;

/**
 * @author  Michael Bouschen
 * @version 0.1
 */
public class ErrorMsg {

    protected String context = null;

    /**
     * I18N support
     */
    protected final static ResourceBundle messages = I18NHelper.loadBundle(ErrorMsg.class);

    /**
     * The logger
     */
    private static Logger logger = LogHelperQueryCompilerJDO.getLogger();

    public String getContext() {
        return context;
    }

    public void setContext(String name) {
        context = name;
    }

    /**
     * Indicates an error situation.
     * @param line line number
     * @param col column number
     * @param msg error message
     */
    public void error(int line, int col, String msg) throws JDOQueryException {
        JDOQueryException ex;
        if (line > 1) {
            // include line and column info
            Object[] args = { context, line, col, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msglinecolumn", // NOI18N
            args));
        } else if (col > 0) {
            // include column info
            Object[] args = { context, col, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msgcolumn", // NOI18N
            args));
        } else {
            Object[] args = { context, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msg", // NOI18N
            args));
        }
        logger.throwing("jqlc.ErrorMsg", "error", ex);
        throw ex;
    }

    /**
     * Indicates that a feature is not supported by the current release.
     * @param line line number
     * @param col column number
     * @param msg message
     */
    public void unsupported(int line, int col, String msg) throws JDOUnsupportedOptionException {

        if (line > 1) {
            // include line and column info
            Object[] args = { context, line, col, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msglinecolumn", // NOI18N
            args));
        } else if (col > 0) {
            // include column info
            Object[] args = { context, col, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msgcolumn", // NOI18N
            args));
        } else {
            Object[] args = { context, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msg", // NOI18N
            args));
        }
        logger.throwing("jqlc.ErrorMsg", "unsupported", ex);
        throw ex;
    }

    /**
     * Indicates a fatal situation (implementation error).
     * @param msg error message
     */
    public void fatal(String msg) throws JDOFatalInternalException {
        JDOFatalInternalException ex = new JDOFatalInternalException(msg);
        logger.throwing("jqlc.ErrorMsg", "fatal", ex);
        throw ex;
    }

    /**
     * Indicates a fatal situation (implementation error).
     * @param msg error message
     */
    public void fatal(String msg, Exception nested) throws JDOFatalInternalException {
        JDOFatalInternalException ex = new JDOFatalInternalException(msg, nested);
        logger.throwing("jqlc.ErrorMsg", "fatal", ex);
        throw ex;
    }
}


if (line > 1) {
            // include line and column info
            Object[] args = { context, line, col, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msglinecolumn", // NOI18N
            args));
        } else if (col > 0) {
            // include column info
            Object[] args = { context, col, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msgcolumn", // NOI18N
            args));
        } else {
            Object[] args = { context, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msg", // NOI18N
            args));
        }
        logger.throwing("jqlc.ErrorMsg", "unsupported", ex);

/*
 * ErrorMsg.java
 *
 * Created on April 3, 2000
 */
package com.sun.jdo.spi.persistence.support.sqlstore.query.jqlc;

import java.util.ResourceBundle;
import com.sun.jdo.api.persistence.support.JDOQueryException;
import com.sun.jdo.api.persistence.support.JDOFatalInternalException;
import com.sun.jdo.api.persistence.support.JDOUnsupportedOptionException;
import com.sun.jdo.spi.persistence.utility.logging.Logger;
import org.glassfish.persistence.common.I18NHelper;

/**
 * @author  Michael Bouschen
 * @version 0.1
 */
public class ErrorMsg {

    protected String context = null;

    /**
     * I18N support
     */
    protected final static ResourceBundle messages = I18NHelper.loadBundle(ErrorMsg.class);

    /**
     * The logger
     */
    private static Logger logger = LogHelperQueryCompilerJDO.getLogger();

    public String getContext() {
        return context;
    }

    public void setContext(String name) {
        context = name;
    }

    /**
     * Indicates an error situation.
     * @param line line number
     * @param col column number
     * @param msg error message
     */
    public void error(int line, int col, String msg) throws JDOQueryException {
        JDOQueryException ex;
        if (line > 1) {
            // include line and column info
            Object[] args = { context, line, col, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msglinecolumn", // NOI18N
            args));
        } else if (col > 0) {
            // include column info
            Object[] args = { context, col, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msgcolumn", // NOI18N
            args));
        } else {
            Object[] args = { context, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msg", // NOI18N
            args));
        }
        logger.throwing("jqlc.ErrorMsg", "error", ex);
        throw ex;
    }

    /**
     * Indicates that a feature is not supported by the current release.
     * @param line line number
     * @param col column number
     * @param msg message
     */
    public void unsupported(int line, int col, String msg) throws JDOUnsupportedOptionException {
        JDOUnsupportedOptionException ex;

        throw ex;
    }

    /**
     * Indicates a fatal situation (implementation error).
     * @param msg error message
     */
    public void fatal(String msg) throws JDOFatalInternalException {
        JDOFatalInternalException ex = new JDOFatalInternalException(msg);
        logger.throwing("jqlc.ErrorMsg", "fatal", ex);
        throw ex;
    }

    /**
     * Indicates a fatal situation (implementation error).
     * @param msg error message
     */
    public void fatal(String msg, Exception nested) throws JDOFatalInternalException {
        JDOFatalInternalException ex = new JDOFatalInternalException(msg, nested);
        logger.throwing("jqlc.ErrorMsg", "fatal", ex);
        throw ex;
    }
}


/*
 * ErrorMsg.java
 *
 * Created on April 3, 2000
 */
package com.sun.jdo.spi.persistence.support.sqlstore.query.jqlc;

import java.util.ResourceBundle;
import com.sun.jdo.api.persistence.support.JDOQueryException;
import com.sun.jdo.api.persistence.support.JDOFatalInternalException;
import com.sun.jdo.api.persistence.support.JDOUnsupportedOptionException;
import com.sun.jdo.spi.persistence.utility.logging.Logger;
import org.glassfish.persistence.common.I18NHelper;

/**
 * @author  Michael Bouschen
 * @version 0.1
 */
public class ErrorMsg {

    protected String context = null;

    /**
     * I18N support
     */
    protected final static ResourceBundle messages = I18NHelper.loadBundle(ErrorMsg.class);

    /**
     * The logger
     */
    private static Logger logger = LogHelperQueryCompilerJDO.getLogger();

    public String getContext() {
        return context;
    }

    public void setContext(String name) {
        context = name;
    }

    /**
     * Indicates an error situation.
     * @param line line number
     * @param col column number
     * @param msg error message
     */
    public void error(int line, int col, String msg) throws JDOQueryException {
        JDOQueryException ex;
        if (line > 1) {
            // include line and column info
            Object[] args = { context, line, col, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msglinecolumn", // NOI18N
            args));
        } else if (col > 0) {
            // include column info
            Object[] args = { context, col, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msgcolumn", // NOI18N
            args));
        } else {
            Object[] args = { context, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msg", // NOI18N
            args));
        }
        logger.throwing("jqlc.ErrorMsg", "error", ex);
        throw ex;
    }

    /**
     * Indicates that a feature is not supported by the current release.
     * @param line line number
     * @param col column number
     * @param msg message
     */
    public void unsupported(int line, int col, String msg) throws JDOUnsupportedOptionException {
        JDOUnsupportedOptionException ex;
        if (line > 1) {
            // include line and column info
            Object[] args = { context, line, col, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msglinecolumn", // NOI18N
            args));
        } else if (col > 0) {
            // include column info
            Object[] args = { context, col, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msgcolumn", // NOI18N
            args));
        } else {
            Object[] args = { context, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msg", // NOI18N
            args));
        }
        logger.throwing("jqlc.ErrorMsg", "unsupported", ex);

    /**
     * Indicates a fatal situation (implementation error).
     * @param msg error message
     */
    public void fatal(String msg) throws JDOFatalInternalException {
        JDOFatalInternalException ex = new JDOFatalInternalException(msg);
        logger.throwing("jqlc.ErrorMsg", "fatal", ex);
        throw ex;
    }

    /**
     * Indicates a fatal situation (implementation error).
     * @param msg error message
     */
    public void fatal(String msg, Exception nested) throws JDOFatalInternalException {
        JDOFatalInternalException ex = new JDOFatalInternalException(msg, nested);
        logger.throwing("jqlc.ErrorMsg", "fatal", ex);
        throw ex;
    }
}


/*
 * ErrorMsg.java
 *
 * Created on April 3, 2000
 */
package com.sun.jdo.spi.persistence.support.sqlstore.query.jqlc;

import java.util.ResourceBundle;
import com.sun.jdo.api.persistence.support.JDOQueryException;
import com.sun.jdo.api.persistence.support.JDOFatalInternalException;
import com.sun.jdo.api.persistence.support.JDOUnsupportedOptionException;
import com.sun.jdo.spi.persistence.utility.logging.Logger;
import org.glassfish.persistence.common.I18NHelper;

/**
 * @author  Michael Bouschen
 * @version 0.1
 */
public class ErrorMsg {

    protected String context = null;

    /**
     * I18N support
     */
    protected final static ResourceBundle messages = I18NHelper.loadBundle(ErrorMsg.class);

    /**
     * The logger
     */
    private static Logger logger = LogHelperQueryCompilerJDO.getLogger();

    public String getContext() {
        return

    }

    public void setContext(String name) {
        context = name;
    }

    /**
     * Indicates an error situation.
     * @param line line number
     * @param col column number
     * @param msg error message
     */
    public void error(int line, int col, String msg) throws JDOQueryException {
        JDOQueryException ex;
        if (line > 1) {
            // include line and column info
            Object[] args = { context, line, col, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msglinecolumn", // NOI18N
            args));
        } else if (col > 0) {
            // include column info
            Object[] args = { context, col, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msgcolumn", // NOI18N
            args));
        } else {
            Object[] args = { context, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msg", // NOI18N
            args));
        }
        logger.throwing("jqlc.ErrorMsg", "error", ex);
        throw ex;
    }

    /**
     * Indicates that a feature is not supported by the current release.
     * @param line line number
     * @param col column number
     * @param msg message
     */
    public void unsupported(int line, int col, String msg) throws JDOUnsupportedOptionException {
        JDOUnsupportedOptionException ex;
        if (line > 1) {
            // include line and column info
            Object[] args = { context, line, col, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msglinecolumn", // NOI18N
            args));
        } else if (col > 0) {
            // include column info
            Object[] args = { context, col, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msgcolumn", // NOI18N
            args));
        } else {
            Object[] args = { context, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msg", // NOI18N
            args));
        }
        logger.throwing("jqlc.ErrorMsg", "unsupported", ex);
        throw ex;
    }

    /**
     * Indicates a fatal situation (implementation error).
     * @param msg error message
     */
    public void fatal(String msg) throws JDOFatalInternalException {
        JDOFatalInternalException ex = new JDOFatalInternalException(msg);
        logger.throwing("jqlc.ErrorMsg", "fatal", ex);
        throw ex;
    }

    /**
     * Indicates a fatal situation (implementation error).
     * @param msg error message
     */
    public void fatal(String msg, Exception nested) throws JDOFatalInternalException {
        JDOFatalInternalException ex = new JDOFatalInternalException(msg, nested);
        logger.throwing("jqlc.ErrorMsg", "fatal", ex);
        throw ex;
    }
}


public void fatal(String msg, Exception nested) throws JDOFatalInternalException {
        JDOFatalInternalException ex = new JDOFatalInternalException(msg, nested);
        logger.throwing("jqlc.ErrorMsg", "fatal", ex);
        throw ex;
    }

/*
 * ErrorMsg.java
 *
 * Created on April 3, 2000
 */
package com.sun.jdo.spi.persistence.support.sqlstore.query.jqlc;

import java.util.ResourceBundle;
import com.sun.jdo.api.persistence.support.JDOQueryException;
import com.sun.jdo.api.persistence.support.JDOFatalInternalException;
import com.sun.jdo.api.persistence.support.JDOUnsupportedOptionException;
import com.sun.jdo.spi.persistence.utility.logging.Logger;
import org.glassfish.persistence.common.I18NHelper;

/**
 * @author  Michael Bouschen
 * @version 0.1
 */
public class ErrorMsg {

    protected String context = null;

    /**
     * I18N support
     */
    protected final static ResourceBundle messages = I18NHelper.loadBundle(ErrorMsg.class);

    /**
     * The logger
     */
    private static Logger logger = LogHelperQueryCompilerJDO.getLogger();

    public String getContext() {
        return context;
    }

    public void setContext(String name) {
        context = name;
    }

    /**
     * Indicates an error situation.
     * @param line line number
     * @param col column number
     * @param msg error message
     */
    public void error(int line, int col, String msg) throws JDOQueryException {
        JDOQueryException ex;
        if (line > 1) {
            // include line and column info
            Object[] args = { context, line, col, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msglinecolumn", // NOI18N
            args));
        } else if (col > 0) {
            // include column info
            Object[] args = { context, col, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msgcolumn", // NOI18N
            args));
        } else {
            Object[] args = { context, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msg", // NOI18N
            args));
        }
        logger.throwing("jqlc.ErrorMsg", "error", ex);
        throw ex;
    }

    /**
     * Indicates that a feature is not supported by the current release.
     * @param line line number
     * @param col column number
     * @param msg message
     */
    public void unsupported(int line, int col, String msg) throws JDOUnsupportedOptionException {
        JDOUnsupportedOptionException ex;
        if (line > 1) {
            // include line and column info
            Object[] args = { context, line, col, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msglinecolumn", // NOI18N
            args));
        } else if (col > 0) {
            // include column info
            Object[] args = { context, col, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msgcolumn", // NOI18N
            args));
        } else {
            Object[] args = { context, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msg", // NOI18N
            args));
        }
        logger.throwing("jqlc.ErrorMsg", "unsupported", ex);
        throw ex;
    }

    /**
     * Indicates a fatal situation (implementation error).
     * @param msg error message
     */
    public void fatal(String msg) throws JDOFatalInternalException {
        JDOFatalInternalException ex = new JDOFatalInternalException(msg);
        logger.throwing("jqlc.ErrorMsg", "fatal", ex);
        throw ex;
    }

    /**
     * Indicates a fatal situation (implementation error).
     * @param msg error message
     */


if (col > 0) {
            // include column info
            Object[] args = { context, col, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msgcolumn", // NOI18N
            args));
        } else {
            Object[] args = { context, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msg", // NOI18N
            args));
        }

/*
 * ErrorMsg.java
 *
 * Created on April 3, 2000
 */
package com.sun.jdo.spi.persistence.support.sqlstore.query.jqlc;

import java.util.ResourceBundle;
import com.sun.jdo.api.persistence.support.JDOQueryException;
import com.sun.jdo.api.persistence.support.JDOFatalInternalException;
import com.sun.jdo.api.persistence.support.JDOUnsupportedOptionException;
import com.sun.jdo.spi.persistence.utility.logging.Logger;
import org.glassfish.persistence.common.I18NHelper;

/**
 * @author  Michael Bouschen
 * @version 0.1
 */
public class ErrorMsg {

    protected String context = null;

    /**
     * I18N support
     */
    protected final static ResourceBundle messages = I18NHelper.loadBundle(ErrorMsg.class);

    /**
     * The logger
     */
    private static Logger logger = LogHelperQueryCompilerJDO.getLogger();

    public String getContext() {
        return context;
    }

    public void setContext(String name) {
        context = name;
    }

    /**
     * Indicates an error situation.
     * @param line line number
     * @param col column number
     * @param msg error message
     */
    public void error(int line, int col, String msg) throws JDOQueryException {
        JDOQueryException ex;
        if (line > 1) {
            // include line and column info
            Object[] args = { context, line, col, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msglinecolumn", // NOI18N
            args));
        } else if (col > 0) {
            // include column info
            Object[] args = { context, col, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msgcolumn", // NOI18N
            args));
        } else {
            Object[] args = { context, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msg", // NOI18N
            args));
        }
        logger.throwing("jqlc.ErrorMsg", "error", ex);
        throw ex;
    }

    /**
     * Indicates that a feature is not supported by the current release.
     * @param line line number
     * @param col column number
     * @param msg message
     */
    public void unsupported(int line, int col, String msg) throws JDOUnsupportedOptionException {
        JDOUnsupportedOptionException ex;
        if (line > 1) {
            // include line and column info
            Object[] args = { context, line, col, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msglinecolumn", // NOI18N
            args));
        } else

        logger.throwing("jqlc.ErrorMsg", "unsupported", ex);
        throw ex;
    }

    /**
     * Indicates a fatal situation (implementation error).
     * @param msg error message
     */
    public void fatal(String msg) throws JDOFatalInternalException {
        JDOFatalInternalException ex = new JDOFatalInternalException(msg);
        logger.throwing("jqlc.ErrorMsg", "fatal", ex);
        throw ex;
    }

    /**
     * Indicates a fatal situation (implementation error).
     * @param msg error message
     */
    public void fatal(String msg, Exception nested) throws JDOFatalInternalException {
        JDOFatalInternalException ex = new JDOFatalInternalException(msg, nested);
        logger.throwing("jqlc.ErrorMsg", "fatal", ex);
        throw ex;
    }
}


/*
 * ErrorMsg.java
 *
 * Created on April 3, 2000
 */
package com.sun.jdo.spi.persistence.support.sqlstore.query.jqlc;

import java.util.ResourceBundle;
import com.sun.jdo.api.persistence.support.JDOQueryException;
import com.sun.jdo.api.persistence.support.JDOFatalInternalException;
import com.sun.jdo.api.persistence.support.JDOUnsupportedOptionException;
import com.sun.jdo.spi.persistence.utility.logging.Logger;
import org.glassfish.persistence.common.I18NHelper;

/**
 * @author  Michael Bouschen
 * @version 0.1
 */
public class ErrorMsg {

    protected String context = null;

    /**
     * I18N support
     */
    protected final static ResourceBundle messages = I18NHelper.loadBundle(ErrorMsg.class);

    /**
     * The logger
     */
    private static Logger logger = LogHelperQueryCompilerJDO.getLogger();

    public String getContext() {
        return context;
    }

    public void setContext(String name) {
        context = name;
    }

    /**
     * Indicates an error situation.
     * @param line line number
     * @param col column number
     * @param msg error message
     */
    public void error(int line, int col, String msg) throws JDOQueryException {
        JDOQueryException ex;
        if (line > 1) {
            // include line and column info
            Object[] args = { context, line, col, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msglinecolumn", // NOI18N
            args));
        } else if (col > 0) {
            // include column info
            Object[] args = { context, col, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msgcolumn", // NOI18N
            args));
        } else {
            Object[] args = { context, msg };
            ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msg", // NOI18N
            args));
        }
        logger.throwing("jqlc.ErrorMsg", "error", ex);
        throw ex;
    }

    /**
     * Indicates that a feature is not supported by the current release.
     * @param line line number
     * @param col column number
     * @param msg message
     */
    public void unsupported(int line, int col, String msg) throws JDOUnsupportedOptionException {
        JDOUnsupportedOptionException ex;
        if (line > 1) {
            // include line and column info
            Object[] args = { context, line, col, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msglinecolumn", // NOI18N
            args));
        } else if (col > 0) {
            // include column info
            Object[] args = { context, col, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msgcolumn", // NOI18N
            args));
        } else {
            Object[] args = { context, msg };
            ex = new JDOUnsupportedOptionException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msg", // NOI18N
            args));
        }
        logger.throwing("jqlc.ErrorMsg", "unsupported", ex);
        throw ex;
    }

    /**
     * Indicates a fatal situation (implementation error).
     * @param msg error message
     */
    public void fatal(String msg) throws JDOFatalInternalException {
        JDOFatalInternalException ex = new J

DOFatalInternalException(msg);
        logger.throwing("jqlc.ErrorMsg", "fatal", ex);
        throw ex;
    }

    /**
     * Indicates a fatal situation (implementation error).
     * @param msg error message
     */
    public void fatal(String msg, Exception nested) throws JDOFatalInternalException {
        JDOFatalInternalException ex = new JDOFatalInternalException(msg, nested);
        logger.throwing("jqlc.ErrorMsg", "fatal", ex);
        throw ex;
    }
}


@Override
    public boolean isAllowed(final JBBPFieldTypeParameterContainer fieldType, final String fieldName, final int extraData, final boolean isArray)

package com.igormaznitsa.jbbp.utils;

import static com.igormaznitsa.jbbp.utils.JBBPUtils.ARRAY_STRING_EMPTY;
import com.igormaznitsa.jbbp.JBBPCustomFieldTypeProcessor;
import com.igormaznitsa.jbbp.compiler.JBBPNamedFieldInfo;
import com.igormaznitsa.jbbp.compiler.tokenizer.JBBPFieldTypeParameterContainer;
import com.igormaznitsa.jbbp.io.JBBPBitInputStream;
import com.igormaznitsa.jbbp.io.JBBPBitOrder;
import com.igormaznitsa.jbbp.model.JBBPAbstractField;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * The Aggregator allows to join several custom field type processors.
 *
 * @since 1.2.0
 */
public class JBBPCustomFieldTypeProcessorAggregator implements JBBPCustomFieldTypeProcessor {

    private final Map<String, JBBPCustomFieldTypeProcessor> customTypeMap;

    private final String[] types;

    /**
     * Constructor.
     *
     * @param processors processors which should be joined.
     */
    public JBBPCustomFieldTypeProcessorAggregator(final JBBPCustomFieldTypeProcessor... processors) {
        this.customTypeMap = new HashMap<>();
        for (final JBBPCustomFieldTypeProcessor p : processors) {
            for (final String s : p.getCustomFieldTypes()) {
                JBBPUtils.assertNotNull(s, "Type must not be null");
                if (this.customTypeMap.containsKey(s)) {
                    throw new IllegalArgumentException("Detected duplicated field type [" + s + ']');
                }
                this.customTypeMap.put(s, p);
            }
        }
        this.types = this.customTypeMap.keySet().toArray(ARRAY_STRING_EMPTY);
    }

    @Override
    public String[] getCustomFieldTypes() {
        return this.types;
    }

{
        return this.customTypeMap.get(fieldType.getTypeName()).isAllowed(fieldType, fieldName, extraData, isArray);
    }

    @Override
    public JBBPAbstractField readCustomFieldType(JBBPBitInputStream in, JBBPBitOrder bitOrder, int parserFlags, JBBPFieldTypeParameterContainer fieldType, JBBPNamedFieldInfo fieldName, int extraData, boolean readWholeStream, int arrayLength) throws IOException {
        return this.customTypeMap.get(fieldType.getTypeName()).readCustomFieldType(in, bitOrder, parserFlags, fieldType, fieldName, extraData, readWholeStream, arrayLength);
    }
}


{
        return this.customTypeMap.get(fieldType.getTypeName()).isAllowed(fieldType, fieldName, extraData, isArray);
    }

package com.igormaznitsa.jbbp.utils;

import static com.igormaznitsa.jbbp.utils.JBBPUtils.ARRAY_STRING_EMPTY;
import com.igormaznitsa.jbbp.JBBPCustomFieldTypeProcessor;
import com.igormaznitsa.jbbp.compiler.JBBPNamedFieldInfo;
import com.igormaznitsa.jbbp.compiler.tokenizer.JBBPFieldTypeParameterContainer;
import com.igormaznitsa.jbbp.io.JBBPBitInputStream;
import com.igormaznitsa.jbbp.io.JBBPBitOrder;
import com.igormaznitsa.jbbp.model.JBBPAbstractField;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * The Aggregator allows to join several custom field type processors.
 *
 * @since 1.2.0
 */
public class JBBPCustomFieldTypeProcessorAggregator implements JBBPCustomFieldTypeProcessor {

    private final Map<String, JBBPCustomFieldTypeProcessor> customTypeMap;

    private final String[] types;

    /**
     * Constructor.
     *
     * @param processors processors which should be joined.
     */
    public JBBPCustomFieldTypeProcessorAggregator(final JBBPCustomFieldTypeProcessor... processors) {
        this.customTypeMap = new HashMap<>();
        for (final JBBPCustomFieldTypeProcessor p : processors) {
            for (final String s : p.getCustomFieldTypes()) {
                JBBPUtils.assertNotNull(s, "Type must not be null");
                if (this.customTypeMap.containsKey(s)) {
                    throw new IllegalArgumentException("Detected duplicated field type [" + s + ']');
                }
                this.customTypeMap.put(s, p);
            }
        }
        this.types = this.customTypeMap.keySet().toArray(ARRAY_STRING_EMPTY);
    }

    @Override
    public String[] getCustomFieldTypes() {
        return this.types;
    }

    @Override
    public boolean isAllowed(final JBBPFieldTypeParameterContainer fieldType, final String fieldName, final int extraData, final boolean isArray)

    @Override
    public JBBPAbstractField readCustomFieldType(JBBPBitInputStream in, JBBPBitOrder bitOrder, int parserFlags, JBBPFieldTypeParameterContainer fieldType, JBBPNamedFieldInfo fieldName, int extraData, boolean readWholeStream, int arrayLength) throws IOException {
        return this.customTypeMap.get(fieldType.getTypeName()).readCustomFieldType(in, bitOrder, parserFlags, fieldType, fieldName, extraData, readWholeStream, arrayLength);
    }
}


package com.igormaznitsa.jbbp.utils;

import static com.igormaznitsa.jbbp.utils.JBBPUtils.ARRAY_STRING_EMPTY;
import com.igormaznitsa.jbbp.JBBPCustomFieldTypeProcessor;
import com.igormaznitsa.jbbp.compiler.JBBPNamedFieldInfo;
import com.igormaznitsa.jbbp.compiler.tokenizer.JBBPFieldTypeParameterContainer;
import com.igormaznitsa.jbbp.io.JBBPBitInputStream;
import com.igormaznitsa.jbbp.io.JBBPBitOrder;
import com.igormaznitsa.jbbp.model.JBBPAbstractField;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * The Aggregator allows to join several custom field type processors.
 *
 * @since 1.2.0
 */
public class JBBPCustomFieldTypeProcessorAggregator implements JBBPCustomFieldTypeProcessor {

    private final Map<String, JBBPCustomFieldTypeProcessor> customTypeMap;

    private final String[] types;

    /**
     * Constructor.
     *
     * @param processors processors which should be joined.
     */
    public JBBPCustomFieldTypeProcessorAggregator(final JBBPCustomFieldTypeProcessor... processors) {
        this.customTypeMap = new HashMap<>();
        for (final JBBPCustomFieldTypeProcessor p : processors) {
            for (final String s : p.getCustomFieldTypes()) {
                JBBPUtils.assertNotNull(s, "Type must not be null");
                if (this.customTypeMap.containsKey(s)) {
                    throw new IllegalArgumentException("Detected duplicated field type [" + s + ']');
                }
                this.customTypeMap.put(s, p);
            }
        }
        this.types = this.customTypeMap.keySet().toArray(ARRAY_STRING_EMPTY);
    }

    @Override
    public String[] getCustomFieldTypes() {
        return th

    }

    @Override
    public boolean isAllowed(final JBBPFieldTypeParameterContainer fieldType, final String fieldName, final int extraData, final boolean isArray) {
        return this.customTypeMap.get(fieldType.getTypeName()).isAllowed(fieldType, fieldName, extraData, isArray);
    }

    @Override
    public JBBPAbstractField readCustomFieldType(JBBPBitInputStream in, JBBPBitOrder bitOrder, int parserFlags, JBBPFieldTypeParameterContainer fieldType, JBBPNamedFieldInfo fieldName, int extraData, boolean readWholeStream, int arrayLength) throws IOException {
        return this.customTypeMap.get(fieldType.getTypeName()).readCustomFieldType(in, bitOrder, parserFlags, fieldType, fieldName, extraData, readWholeStream, arrayLength);
    }
}


if (this.customTypeMap.containsKey(s)) {
                    throw new IllegalArgumentException("Detected duplicated field type [" + s + ']');
                }

package com.igormaznitsa.jbbp.utils;

import static com.igormaznitsa.jbbp.utils.JBBPUtils.ARRAY_STRING_EMPTY;
import com.igormaznitsa.jbbp.JBBPCustomFieldTypeProcessor;
import com.igormaznitsa.jbbp.compiler.JBBPNamedFieldInfo;
import com.igormaznitsa.jbbp.compiler.tokenizer.JBBPFieldTypeParameterContainer;
import com.igormaznitsa.jbbp.io.JBBPBitInputStream;
import com.igormaznitsa.jbbp.io.JBBPBitOrder;
import com.igormaznitsa.jbbp.model.JBBPAbstractField;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * The Aggregator allows to join several custom field type processors.
 *
 * @since 1.2.0
 */
public class JBBPCustomFieldTypeProcessorAggregator implements JBBPCustomFieldTypeProcessor {

    private final Map<String, JBBPCustomFieldTypeProcessor> customTypeMap;

    private final String[] types;

    /**
     * Constructor.
     *
     * @param processors processors which should be joined.
     */
    public JBBPCustomFieldTypeProcessorAggregator(final JBBPCustomFieldTypeProcessor... processors) {
        this.customTypeMap = new HashMap<>();
        for (final JBBPCustomFieldTypeProcessor p : processors) {
            for (final String s : p.getCustomFieldTypes()) {
                JBBPUtils.assertNotNull(s, "Type must not be null");

                this.customTypeMap.put(s, p);
            }
        }
        this.types = this.customTypeMap.keySet().toArray(ARRAY_STRING_EMPTY);
    }

    @Override
    public String[] getCustomFieldTypes() {
        return this.types;
    }

    @Override
    public boolean isAllowed(final JBBPFieldTypeParameterContainer fieldType, final String fieldName, final int extraData, final boolean isArray) {
        return this.customTypeMap.get(fieldType.getTypeName()).isAllowed(fieldType, fieldName, extraData, isArray);
    }

    @Override
    public JBBPAbstractField readCustomFieldType(JBBPBitInputStream in, JBBPBitOrder bitOrder, int parserFlags, JBBPFieldTypeParameterContainer fieldType, JBBPNamedFieldInfo fieldName, int extraData, boolean readWholeStream, int arrayLength) throws IOException {
        return this.customTypeMap.get(fieldType.getTypeName()).readCustomFieldType(in, bitOrder, parserFlags, fieldType, fieldName, extraData, readWholeStream, arrayLength);
    }
}


package com.igormaznitsa.jbbp.utils;

import static com.igormaznitsa.jbbp.utils.JBBPUtils.ARRAY_STRING_EMPTY;
import com.igormaznitsa.jbbp.JBBPCustomFieldTypeProcessor;
import com.igormaznitsa.jbbp.compiler.JBBPNamedFieldInfo;
import com.igormaznitsa.jbbp.compiler.tokenizer.JBBPFieldTypeParameterContainer;
import com.igormaznitsa.jbbp.io.JBBPBitInputStream;
import com.igormaznitsa.jbbp.io.JBBPBitOrder;
import com.igormaznitsa.jbbp.model.JBBPAbstractField;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * The Aggregator allows to join several custom field type processors.
 *
 * @since 1.2.0
 */
public class JBBPCustomFieldTypeProcessorAggregator implements JBBPCustomFieldTypeProcessor {

    private final Map<String, JBBPCustomFieldTypeProcessor> customTypeMap;

    private final String[] types;

    /**
     * Constructor.
     *
     * @param processors processors which should be joined.
     */
    public JBBPCustomFieldTypeProcessorAggregator(final JBBPCustomFieldTypeProcessor... processors) {
        this.customTypeMap = new HashMap<>();
        for (final JBBPCustomFieldTypeProcessor p : processors) {
            for (final String s : p.getCustomFieldTypes()) {
                JBBPUtils.assertNotNull(s, "Type must not be null");
                if (this.customTypeMap.containsKey(s)) {
                    throw new IllegalArgumentException("Detected duplicated field type [" + s + ']');
                }
                this.customT

ypeMap.put(s, p);
            }
        }
        this.types = this.customTypeMap.keySet().toArray(ARRAY_STRING_EMPTY);
    }

    @Override
    public String[] getCustomFieldTypes() {
        return this.types;
    }

    @Override
    public boolean isAllowed(final JBBPFieldTypeParameterContainer fieldType, final String fieldName, final int extraData, final boolean isArray) {
        return this.customTypeMap.get(fieldType.getTypeName()).isAllowed(fieldType, fieldName, extraData, isArray);
    }

    @Override
    public JBBPAbstractField readCustomFieldType(JBBPBitInputStream in, JBBPBitOrder bitOrder, int parserFlags, JBBPFieldTypeParameterContainer fieldType, JBBPNamedFieldInfo fieldName, int extraData, boolean readWholeStream, int arrayLength) throws IOException {
        return this.customTypeMap.get(fieldType.getTypeName()).readCustomFieldType(in, bitOrder, parserFlags, fieldType, fieldName, extraData, readWholeStream, arrayLength);
    }
}


package androidx.work.integration.testapp;

import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.util.Log;
import android.widget.Toast;
import androidx.work.Data;
import androidx.work.OneTimeWorkRequest;
import androidx.work.Worker;

/**
 *  A {@link Worker} that shows a given Toast.
 */
public class ToastWorker extends Worker {

    static final String ARG_MESSAGE = "message";

    /**
     * Create a {@link OneTimeWorkRequest.Builder} with the given message.
     *
     * @param message The toast message to display
     * @return A {@link OneTimeWorkRequest.Builder}
     */
    public static OneTimeWorkRequest.Builder create(String message) {
        Data input = new Data.Builder().putString(ARG_MESSAGE, message).build();
        return new OneTimeWorkRequest.Builder(ToastWorker.class).setInputData(input);
    }

    @Override
    @NonNull
    public Result doWork() {
        Data input = getInputData();
        final String message = input.getString(ARG_MESSAGE, "completed!");
        new Handler(Looper.getMainLooper()).post(new Runnable() {

{
                Log.d("ToastWorker", message);
                Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
            }
        });
        return Result.SUCCESS;
    }
}


{
        Data input = getInputData();
        final String message = input.getString(ARG_MESSAGE, "completed!");
        new Handler(Looper.getMainLooper()).post(new Runnable() {

            @Override
            public void run() {
                Log.d("ToastWorker", message);
                Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
            }
        });
        return Result.SUCCESS;
    }

package androidx.work.integration.testapp;

import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.util.Log;
import android.widget.Toast;
import androidx.work.Data;
import androidx.work.OneTimeWorkRequest;
import androidx.work.Worker;

/**
 *  A {@link Worker} that shows a given Toast.
 */
public class ToastWorker extends Worker {

    static final String ARG_MESSAGE = "message";

    /**
     * Create a {@link OneTimeWorkRequest.Builder} with the given message.
     *
     * @param message The toast message to display
     * @return A {@link OneTimeWorkRequest.Builder}
     */
    public static OneTimeWorkRequest.Builder create(String message) {
        Data input = new Data.Builder().putString(ARG_MESSAGE, message).build();
        return new OneTimeWorkRequest.Builder(ToastWorker.class).setInputData(input);
    }

    @Override
    @NonNull
    public Result doWork()


package androidx.work.integration.testapp;

import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.util.Log;
import android.widget.Toast;
import androidx.work.Data;
import androidx.work.OneTimeWorkRequest;
import androidx.work.Worker;

/**
 *  A {@link Worker} that shows a given Toast.
 */
public class ToastWorker extends Worker {

    static final String ARG_MESSAGE = "message";

    /**
     * Create a {@link OneTimeWorkRequest.Builder} with the given message.
     *
     * @param message The toast message to display
     * @return A {@link OneTimeWorkRequest.Builder}
     */
    public static OneTimeWorkRequest.Builder create(String message) {
        Data input = new Data.Builder().putString(ARG_MESSAGE, message).build();
        return new OneTimeWorkRequest.Builder(ToastWorker.class).setInputData(input);
    }

    @Override
    @NonNull
    public Result doWork() {

        final String message = input.getString(ARG_MESSAGE, "completed!");
        new Handler(Looper.getMainLooper()).post(new Runnable() {

            @Override
            public void run() {
                Log.d("ToastWorker", message);
                Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
            }
        });
        return Result.SUCCESS;
    }
}


final String message = input.getString(ARG_MESSAGE, "completed!");
        new Handler(Looper.getMainLooper()).post(new Runnable() {

            @Override
            public void run() {
                Log.d("ToastWorker", message);
                Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
            }
        });

package androidx.work.integration.testapp;

import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.util.Log;
import android.widget.Toast;
import androidx.work.Data;
import androidx.work.OneTimeWorkRequest;
import androidx.work.Worker;

/**
 *  A {@link Worker} that shows a given Toast.
 */
public class ToastWorker extends Worker {

    static final String ARG_MESSAGE = "message";

    /**
     * Create a {@link OneTimeWorkRequest.Builder} with the given message.
     *
     * @param message The toast message to display
     * @return A {@link OneTimeWorkRequest.Builder}
     */
    public static OneTimeWorkRequest.Builder create(String message) {
        Data input = new Data.Builder().putString(ARG_MESSAGE, message).build();
        return new OneTimeWorkRequest.Builder(ToastWorker.class).setInputData(input);
    }

    @Override
    @NonNull
    public Result doWork() {
        Data input = getInputData();


package androidx.work.integration.testapp;

import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.util.Log;
import android.widget.Toast;
import androidx.work.Data;
import androidx.work.OneTimeWorkRequest;
import androidx.work.Worker;

/**
 *  A {@link Worker} that shows a given Toast.
 */
public class ToastWorker extends Worker {

    static final String ARG_MESSAGE = "message";

    /**
     * Create a {@link OneTimeWorkRequest.Builder} with the given message.
     *
     * @param message The toast message to display
     * @return A {@link OneTimeWorkRequest.Builder}
     */
    public static OneTimeWorkRequest.Builder create(String message) {
        Data input = new Data.Builder().putString(ARG_MESSAGE, message).build();
        return new OneTimeWorkRequest.Builder(ToastWorker.class).setInputData(input);
    }

    @Override
    @NonNull
    public Result doWork() {
        Data input = getInputData();
        final String message = input.getString(ARG_MESSAGE, "completed!");
        new Handler(Looper.getMainLooper()).post(new Runnable() {

            @Override
            public void run() {
                Log.d("ToastWorker", message);
                Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
            }
        });


package androidx.work.integration.testapp;

import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.util.Log;
import android.widget.Toast;
import androidx.work.Data;
import androidx.work.OneTimeWorkRequest;
import androidx.work.Worker;

/**
 *  A {@link Worker} that shows a given Toast.
 */
public class ToastWorker extends Worker {

    static final String ARG_MESSAGE = "message";

    /**
     * Create a {@link OneTimeWorkRequest.Builder} with the given message.
     *
     * @param message The toast message to display
     * @return A {@link OneTimeWorkRequest.Builder}
     */
    public static OneTimeWorkRequest.Builder create(String message) {
        Data input = new Data.Builder().putString(ARG_MESSAGE, message).build();
        return new OneTimeWorkRequest.Builder(ToastWorker.class).setInputData(input);
    }

    @Override
    @NonNull
    public Result doWork() {
        Data input = getInputData();
        final String message = input.getString(AR

        new Handler(Looper.getMainLooper()).post(new Runnable() {

            @Override
            public void run() {
                Log.d("ToastWorker", message);
                Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
            }
        });
        return Result.SUCCESS;
    }
}


public static OneTimeWorkRequest.Builder create(String message) {
        Data input = new Data.Builder().putString(ARG_MESSAGE, message).build();
        return new OneTimeWorkRequest.Builder(ToastWorker.class).setInputData(input);
    }

package androidx.work.integration.testapp;

import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.util.Log;
import android.widget.Toast;
import androidx.work.Data;
import androidx.work.OneTimeWorkRequest;
import androidx.work.Worker;

/**
 *  A {@link Worker} that shows a given Toast.
 */
public class ToastWorker extends Worker {

    static final String ARG_MESSAGE = "message";

    /**
     * Create a {@link OneTimeWorkRequest.Builder} with the given message.
     *
     * @param message The toast message to display
     * @return A {@link OneTimeWorkRequest.Builder}
     */

    @Override
    @NonNull
    public Result doWork() {
        Data input = getInputData();
        final String message = input.getString(ARG_MESSAGE, "completed!");
        new Handler(Looper.getMainLooper()).post(new Runnable() {

            @Override
            public void run() {
                Log.d("ToastWorker", message);
                Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
            }
        });
        return Result.SUCCESS;
    }
}


package androidx.work.integration.testapp;

import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.util.Log;
import android.widget.Toast;
import androidx.work.Data;
import androidx.work.OneTimeWorkRequest;
import androidx.work.Worker;

/**
 *  A {@link Worker} that shows a given Toast.
 */
public class ToastWorker extends Worker {

    static final String ARG_MESSAGE = "message";

    /**
     * Create a {@link OneTimeWorkRequest.Builder} with the given message.
     *
     * @param message The toast message to display
     * @return A {@link OneTimeWorkRequest.Builder}
     */
    public static OneTimeWorkRequest.Builder create(String message) {
        Data input = new Data.Builder().putString(ARG_MESSAGE, message).build();
        return new OneTimeWorkRequest.Builder(ToastWorker.class).setInputData(input);
    }

    @Override
    @NonNull
    public Result doWork() {
        Data input = getInputData();
        final String message = input.getString(ARG_MESSAGE, "completed!");
        new Handler(Looper.getMainLooper()).post(new Runnable() {

            @Override
            public void run() {
                Log.d("ToastWorker", message);
                Toast.makeText(getApplic

ationContext(), message, Toast.LENGTH_SHORT).show();
            }
        });
        return Result.SUCCESS;
    }
}


public static void main(String[] args) throws Exception

package amodeus.socket;

import java.io.File;
import java.util.Objects;
import amodeus.amodeus.analysis.Analysis;
import amodeus.amodeus.options.ScenarioOptions;
import amodeus.amodeus.options.ScenarioOptionsBase;
import amodeus.amodeus.prep.LegCount;
import amodeus.amodeus.util.io.MultiFileTools;
import amodeus.amodeus.util.matsim.xml.ConfigDispatcherChanger;
import amodeus.amodeus.util.matsim.xml.ConfigVehiclesChanger;
import amodeus.amodeus.util.net.StringServerSocket;
import amodeus.amodeus.util.net.StringSocket;
import amodeus.amodeus.video.VideoGenerator;
import org.matsim.amodeus.config.AmodeusModeConfig;
import amodeus.socket.core.ScoreParameters;
import amodeus.socket.core.SocketDispatcherHost;
import amodeus.socket.core.SocketScoreElement;
import ch.ethz.idsc.tensor.RealScalar;
import ch.ethz.idsc.tensor.Scalar;
import ch.ethz.idsc.tensor.Tensor;
import ch.ethz.idsc.tensor.Tensors;
import ch.ethz.idsc.tensor.red.Total;
import ch.ethz.idsc.tensor.sca.Round;

// TODO refactor and shorten @clruch
/**
 * host that runs in container.
 * a client can connect to a running host via TCP/IP
 *
 * Usage:
 * java -cp target/amod-VERSION.jar amod.socket.SocketHost [city]
 */
public enum SocketHost {
    ;

    public static final int PORT = 9382;

    private static final String ENV_SCENARIO = "SCENARIO";

    private static final String ENV_FLEET_SIZE = "FLEET_SIZE";

    private static final String ENV_REQUESTS_SIZE = "REQUESTS_SIZE";

    private static final String ENV_VIDEO_EXPORT = "VIDEO_EXPORT";

{
        File workingDirectory = MultiFileTools.getDefaultWorkingDirectory();
        run(workingDirectory);
    }

    public static void run(File workingDirectory) throws Exception {
        System.out.println("Using scenario directory: " + workingDirectory);
        StringSocket stringSocket = null;
        /**
         * open String server and wait for initial command
         */
        try (StringServerSocket serverSocket = new StringServerSocket(PORT)) {
            stringSocket = serverSocket.getSocketWait();
            // only allow one connection
            serverSocket.close();
            String readLine = stringSocket.readLine();
            Tensor config = Tensors.fromString(readLine);
            System.out.println("SocketHost config: " + config);
            Thread.sleep(1000);
            String scenarioTag = config.Get(0).toString();
            {
                String env = System.getenv(ENV_SCENARIO);
                if (Objects.nonNull(env))
                    env = scenarioTag;
            }
            /**
             * download the chosen scenario
             */
            SocketScenarioResource.extract(scenarioTag, workingDirectory);
            /**
             * setup environment variables
             */
            StaticHelper.setup();
            /**
             * run first part of scenario preparer
             */
            SocketPreparer preparer = new SocketPreparer(workingDirectory);
            /**
             * get number of requests in population
             */
            long numReq = LegCount.of(preparer.getPopulation(), AmodeusModeConfig.DEFAULT_MODE);
            Scalar nominalFleetSize = Round.of(RealScalar.of(numReq).multiply(ScoreParameters.GLOBAL.gamma));
            Tensor initialInfo = Tensors.of(RealScalar.of(numReq), preparer.getBoundingBox(), nominalFleetSize);
            /**
             * send initial data: {numberRequests,boundingBox}
             */
            stringSocket.writeln(initialInfo);
            /**
             * get additional information
             */
            String readLine2 = stringSocket.readLine();
            Tensor config2 = Tensors.fromString(readLine2);
            int numReqDes = config2.Get(0).number().intValue();
            int fleetSize = config2.Get(1).number().intValue();
            {
                String env = System.getenv(ENV_REQUESTS_SIZE);
                if (Objects.nonNull(env))
                    try {
                        numReqDes = Integer.parseInt(env);
                    } catch (Exception exception) {
                        exception.printStackTrace();
                    }
            }
            {
                String env = System.getenv(ENV_FLEET_SIZE);
                if (Objects.nonNull(env))
                    try {
                        fleetSize = Integer.parseInt(env);
                    } catch (Exception exception) {
                        exception.printStackTrace();
                    }
            }
            /**
             * run second part of preparer
             */
            preparer.run2(numReqDes);
            /**
             * run with socket dispatcher
             */
            ScenarioOptions scenarioOptions = new ScenarioOptions(workingDirectory, ScenarioOptionsBase.getDefault());
            String simConfigPath = scenarioOptions.getSimulationConfigName();
            ConfigDispatcherChanger.change(simConfigPath, SocketDispatcherHost.class.getSimpleName());
            ConfigVehiclesChanger.change(simConfigPath, fleetSize);
            SocketServer socketServer = new SocketServer();
            socketServer.simulate(stringSocket, numReqDes, workingDirectory);
            /**
             * send empty tensor "{}" to stop
             */
            stringSocket.writeln(Tensors.empty());
            /**
             * analyze and send final score
             */
            Analysis analysis = //
            Analysis.//
            setup(//
            socketServer.getScenarioOptions(), socketServer.getOutputDirectory(), socketServer.getNetwork(), preparer.getDatabase());
            SocketScoreElement socketScoreElement = new SocketScoreElement(fleetSize, numReqDes, preparer.getDatabase());
            analysis.addAnalysisElement(socketScoreElement);
            SocketExport socketExport = new SocketExport(socketScoreElement);
            analysis.addAnalysisExport(socketExport);
            SocketHtmlReport socketHtmlReport = new SocketHtmlReport(socketScoreElement);
            analysis.addHtmlElement(socketHtmlReport);
            analysis.run();
            {
                /**
                 * create a video if environment variable is set
                 */
                String env = System.getenv(ENV_VIDEO_EXPORT);
                if (Objects.nonNull(env) && env.equalsIgnoreCase("true"))
                    new VideoGenerator(workingDirectory).start();
            }
            /**
             * send final score,
             * {total waiting time, total distance with customer, total empty distance}
             */
            stringSocket.writeln(Total.of(socketScoreElement.getScoreDiffHistory()));
        } catch (Exception exception) {
            shutdown(stringSocket);
            throw exception;
        }
    }

    private static void shutdown(StringSocket stringSocket) throws Exception {
        if (Objects.nonNull(stringSocket)) {
            /**
             * send empty tensor "{}" to stop
             */
            stringSocket.writeln(Tensors.empty());
            /**
             * send fictitious costs
             */
            stringSocket.writeln(StaticHelper.FAILURE_SCORE);
        }
    }
}


{
        if (Objects.nonNull(stringSocket)) {
            /**
             * send empty tensor "{}" to stop
             */
            stringSocket.writeln(Tensors.empty());
            /**
             * send fictitious costs
             */
            stringSocket.writeln(StaticHelper.FAILURE_SCORE);
        }
    }

package amodeus.socket;

import java.io.File;
import java.util.Objects;
import amodeus.amodeus.analysis.Analysis;
import amodeus.amodeus.options.ScenarioOptions;
import amodeus.amodeus.options.ScenarioOptionsBase;
import amodeus.amodeus.prep.LegCount;
import amodeus.amodeus.util.io.MultiFileTools;
import amodeus.amodeus.util.matsim.xml.ConfigDispatcherChanger;
import amodeus.amodeus.util.matsim.xml.ConfigVehiclesChanger;
import amodeus.amodeus.util.net.StringServerSocket;
import amodeus.amodeus.util.net.StringSocket;
import amodeus.amodeus.video.VideoGenerator;
import org.matsim.amodeus.config.AmodeusModeConfig;
import amodeus.socket.core.ScoreParameters;
import amodeus.socket.core.SocketDispatcherHost;
import amodeus.socket.core.SocketScoreElement;
import ch.ethz.idsc.tensor.RealScalar;
import ch.ethz.idsc.tensor.Scalar;
import ch.ethz.idsc.tensor.Tensor;
import ch.ethz.idsc.tensor.Tensors;
import ch.ethz.idsc.tensor.red.Total;
import ch.ethz.idsc.tensor.sca.Round;

// TODO refactor and shorten @clruch
/**
 * host that runs in container.
 * a client can connect to a running host via TCP/IP
 *
 * Usage:
 * java -cp target/amod-VERSION.jar amod.socket.SocketHost [city]
 */
public enum SocketHost {
    ;

    public static final int PORT = 9382;

    private static final String ENV_SCENARIO = "SCENARIO";

    private static final String ENV_FLEET_SIZE = "FLEET_SIZE";

    private static final String ENV_REQUESTS_SIZE = "REQUESTS_SIZE";

    private static final String ENV_VIDEO_EXPORT = "VIDEO_EXPORT";

    public static void main(String[] args) throws Exception {
        File workingDirectory = MultiFileTools.getDefaultWorkingDirectory();
        run(workingDirectory);
    }

    public static void run(File workingDirectory) throws Exception {
        System.out.println("Using scenario directory: " + workingDirectory);
        StringSocket stringSocket = null;
        /**
         * open String server and wait for initial command
         */
        try (StringServerSocket serverSocket = new StringServerSocket(PORT)) {
            stringSocket = serverSocket.getSocketWait();
            // only allow one connection
            serverSocket.close();
            String readLine = stringSocket.readLine();
            Tensor config = Tensors.fromString(readLine);
            System.out.println("SocketHost config: " + config);
            Thread.sleep(1000);
            String scenarioTag = config.Get(0).toString();
            {
                String env = System.getenv(ENV_SCENARIO);
                if (Objects.nonNull(env))
                    env = scenarioTag;
            }
            /**
             * download the chosen scenario
             */
            SocketScenarioResource.extract(scenarioTag, workingDirectory);
            /**
             * setup environment variables
             */
            StaticHelper.setup();
            /**
             * run first part of scenario preparer
             */
            SocketPreparer preparer = new SocketPreparer(workingDirectory);
            /**
             * get number of requests in population
             */
            long numReq = LegCount.of(preparer.getPopulation(), AmodeusModeConfig.DEFAULT_MODE);
            Scalar nominalFleetSize = Round.of(RealScalar.of(numReq).multiply(ScoreParameters.GLOBAL.gamma));
            Tensor initialInfo = Tensors.of(RealScalar.of(numReq), preparer.getBoundingBox(), nominalFleetSize);
            /**
             * send initial data: {numberRequests,boundingBox}
             */
            stringSocket.writeln(initialInfo);
            /**
             * get additional information
             */
            String readLine2 = stringSocket.readLine();
            Tensor config2 = Tensors.fromString(readLine2);
            int numReqDes = config2.Get(0).number().intValue();
            int fleetSize = config2.Get(1).number().intValue();
            {
                String env = System.getenv(ENV_REQUESTS_SIZE);
                if (Objects.nonNull(env))
                    try {
                        numReqDes = Integer.parseInt(env);
                    } catch (Exception exception) {
                        exception.printStackTrace();
                    }
            }
            {
                String env = System.getenv(ENV_FLEET_SIZE);
                if (Objects.nonNull(env))
                    try {
                        fleetSize = Integer.parseInt(env);
                    } catch (Exception exception) {
                        exception.printStackTrace();
                    }
            }
            /**
             * run second part of preparer
             */
            preparer.run2(numReqDes);
            /**
             * run with socket dispatcher
             */
            ScenarioOptions scenarioOptions = new ScenarioOptions(workingDirectory, ScenarioOptionsBase.getDefault());
            String simConfigPath = scenarioOptions.getSimulationConfigName();
            ConfigDispatcherChanger.change(simConfigPath, SocketDispatcherHost.class.getSimpleName());
            ConfigVehiclesChanger.change(simConfigPath, fleetSize);
            SocketServer socketServer = new SocketServer();
            socketServer.simulate(stringSocket, numReqDes, workingDirectory);
            /**
             * send empty tensor "{}" to stop
             */
            stringSocket.writeln(Tensors.empty());
            /**
             * analyze and send final score
             */
            Analysis analysis = //
            Analysis.//
            setup(//
            socketServer.getScenarioOptions(), socketServer.getOutputDirectory(), socketServer.getNetwork(), preparer.getDatabase());
            SocketScoreElement socketScoreElement = new SocketScoreElement(fleetSize, numReqDes, preparer.getDatabase());
            analysis.addAnalysisElement(socketScoreElement);
            SocketExport socketExport = new SocketExport(socketScoreElement);
            analysis.addAnalysisExport(socketExport);
            SocketHtmlReport socketHtmlReport = new SocketHtmlReport(socketScoreElement);
            analysis.addHtmlElement(socketHtmlReport);
            analysis.run();
            {
                /**
                 * create a video if environment variable is set
                 */
                String env = System.getenv(ENV_VIDEO_EXPORT);
                if (Objects.nonNull(env) && env.equalsIgnoreCase("true"))
                    new VideoGenerator(workingDirectory).start();
            }
            /**
             * send final score,
             * {total waiting time, total distance with customer, total empty distance}
             */
            stringSocket.writeln(Total.of(socketScoreElement.getScoreDiffHistory()));
        } catch (Exception exception) {
            shutdown(stringSocket);
            throw exception;
        }
    }

    private static void shutdown(StringSocket stringSocket) throws Exception


package amodeus.socket;

import java.io.File;
import java.util.Objects;
import amodeus.amodeus.analysis.Analysis;
import amodeus.amodeus.options.ScenarioOptions;
import amodeus.amodeus.options.ScenarioOptionsBase;
import amodeus.amodeus.prep.LegCount;
import amodeus.amodeus.util.io.MultiFileTools;
import amodeus.amodeus.util.matsim.xml.ConfigDispatcherChanger;
import amodeus.amodeus.util.matsim.xml.ConfigVehiclesChanger;
import amodeus.amodeus.util.net.StringServerSocket;
import amodeus.amodeus.util.net.StringSocket;
import amodeus.amodeus.video.VideoGenerator;
import org.matsim.amodeus.config.AmodeusModeConfig;
import amodeus.socket.core.ScoreParameters;
import amodeus.socket.core.SocketDispatcherHost;
import amodeus.socket.core.SocketScoreElement;
import ch.ethz.idsc.tensor.RealScalar;
import ch.ethz.idsc.tensor.Scalar;
import ch.ethz.idsc.tensor.Tensor;
import ch.ethz.idsc.tensor.Tensors;
import ch.ethz.idsc.tensor.red.Total;
import ch.ethz.idsc.tensor.sca.Round;

// TODO refactor and shorten @clruch
/**
 * host that runs in container.
 * a client can connect to a running host via TCP/IP
 *
 * Usage:
 * java -cp target/amod-VERSION.jar amod.socket.SocketHost [city]
 */
public enum SocketHost {
    ;

    public static final int PORT = 9382;

    private static final String ENV_SCENARIO = "SCENARIO";

    private static final String ENV_FLEET_SIZE = "FLEET_SIZE";

    private static final String ENV_REQUESTS_SIZE = "REQUESTS_SIZE";

    private static final String ENV_VIDEO_EXPORT = "VIDEO_EXPORT";

    public static void main(String[] args) throws Exception {
        File workingDirectory = MultiFileTools.getDefaultWorkingDirectory();
        run(workingDirectory);
    }

    public static void run(File workingDirectory) throws Exception {
        System.out.println("Using scenario directory: " + workingDirectory);
        StringSocket stringSocket = null;
        /**
         * open String server and wait for initial command
         */
        try (StringServerSocket serverSocket = new StringServerSocket(PORT)) {
            stringSocket = serverSocket.getSocketWait();
            // only allow one connection
            serverSocket.close();
            String readLine = stringSocket.readLine();
            Tensor config = Tensors.fromString(readLine);
            System.out.println("SocketHost config: " + config);
            Thread.sleep(1000);
            String scenarioTag = config.Get(0).toString();
            {
                String env = System.getenv(ENV_SCENARIO);
                if (Objects.nonNull(env))
                    env = scenarioTag;
            }
            /**
             * download the chosen scenario
             */
            SocketScenarioResource.extract(scenarioTag, workingDirectory);
            /**
             * setup environment variables
             */
            StaticHelper.setup();
            /**
             * run first part of scenario preparer
             */
            SocketPreparer preparer = new SocketPreparer(workingDirectory);
            /**
             * get number of requests in population
             */
            long numReq = LegCount.of(preparer.getPopulation(), AmodeusModeConfig.DEFAULT_MODE);
            Scalar nominalFleetSize = Round.of(RealScalar.of(numReq).multiply(ScoreParameters.GLOBAL.gamma));
            Tensor initialInfo = Tensors.of(RealScalar.of(numReq), preparer.getBoundingBox(), nominalFleetSize);
            /**
             * send initial data: {numberRequests,boundingBox}
             */
            stringSocket.writeln(initialInfo);
            /**
             * get additional information
             */
            String readLine2 = stringSocket.readLine();
            Tensor config2 = Tensors.fromString(readLine2);
            int numReqDes = config2.Get(0).number().intValue();
            int fleetSize = config2.Get(1).number().intValue();
            {
                String env = System.getenv(ENV_REQUESTS_SIZE);
                if (Objects.nonNull(env))
                    try {
                        numReqDes = Integer.parseInt(env);
                    } catch (Exception exception) {
                        exception.printStackTrace();
                    }
            }
            {
                String env = System.getenv(ENV_FLEET_SIZE);
                if (Objects.nonNull(env))
                    try {
                        fleetSize = Integer.parseInt(env);
                    } catch (Exception exception) {
                        exception.printStackTrace();
                    }
            }
            /**
             * run second part of preparer
             */
            preparer.run2(numReqDes);
            /**
             * run with socket dispatcher
             */
            ScenarioOptions scenarioOptions = new ScenarioOptions(workingDirectory, ScenarioOptionsBase.getDefault());
            String simConfigPath = scenarioOptions.getSimulationConfigName();
            ConfigDispatcherChanger.change(simConfigPath, SocketDispatcherHost.class.getSimpleName());
            ConfigVehiclesChanger.change(simConfigPath, fleetSize);
            SocketServer socketServer = new SocketServer();
            socketServer.simulate(stringSocket, numReqDes, workingDirectory);
            /**
             * send empty tensor "{}" to stop
             */
            stringSocket.writeln(Tensors.empty());
            /**
             * analyze and send final score
             */
            Analysis analysis = //
            Analysis.//
            setup(//
            socketServer.getScenarioOptions(), socketServer.getOutputDirectory(), socketServer.getNetwork(), preparer.getDatabase());
            SocketScoreElement socketScoreElement = new SocketScoreElement(fleetSize, numReqDes, preparer.getDatabase());
            analysis.addAnalysisElement(socketScoreElement);
            SocketExport socketExport = new SocketExport(socketScoreElement);
            analysis.addAnalysisExport(socketExport);
            SocketHtmlReport socketHtmlReport = new SocketHtmlReport(socketScoreElement);
            analysis.addHtmlElement(socketHtmlReport);
            analysis.run();
            {
                /**
                 * create a video if environment variable is set
                 */
                String env = System.getenv(ENV_VIDEO_EXPORT);
                if (Objects.nonNull(env) && env.equalsIgnoreCase("true"))
                    new VideoGenerator(workingDirectory).start();
            }
            /**
             * send final score,
             * {total waiting time, total distance with customer, total empty distance}
             */
            stringSocket.writeln(Total.of(socketScoreElement.getScoreDiffHistory()));
        } catch (Exception exception) {
            shutdown(stringSocket);
            throw exception;
        }
    }

    private static void shutdown(StringSocket stringSocket) throws Exception {

        if (Objects.nonNull(stringSocket)) {
            /**
             * send empty tensor "{}" to stop
             */
            stringSocket.writeln(Tensors.empty());
            /**
             * send fictitious costs
             */
            stringSocket.writeln(StaticHelper.FAILURE_SCORE);
        }
    }
}


if (Objects.nonNull(stringSocket)) {
            /**
             * send empty tensor "{}" to stop
             */
            stringSocket.writeln(Tensors.empty());
            /**
             * send fictitious costs
             */
            stringSocket.writeln(StaticHelper.FAILURE_SCORE);
        }


package amodeus.socket;

import java.io.File;
import java.util.Objects;
import amodeus.amodeus.analysis.Analysis;
import amodeus.amodeus.options.ScenarioOptions;
import amodeus.amodeus.options.ScenarioOptionsBase;
import amodeus.amodeus.prep.LegCount;
import amodeus.amodeus.util.io.MultiFileTools;
import amodeus.amodeus.util.matsim.xml.ConfigDispatcherChanger;
import amodeus.amodeus.util.matsim.xml.ConfigVehiclesChanger;
import amodeus.amodeus.util.net.StringServerSocket;
import amodeus.amodeus.util.net.StringSocket;
import amodeus.amodeus.video.VideoGenerator;
import org.matsim.amodeus.config.AmodeusModeConfig;
import amodeus.socket.core.ScoreParameters;
import amodeus.socket.core.SocketDispatcherHost;
import amodeus.socket.core.SocketScoreElement;
import ch.ethz.idsc.tensor.RealScalar;
import ch.ethz.idsc.tensor.Scalar;
import ch.ethz.idsc.tensor.Tensor;
import ch.ethz.idsc.tensor.Tensors;
import ch.ethz.idsc.tensor.red.Total;
import ch.ethz.idsc.tensor.sca.Round;

// TODO refactor and shorten @clruch
/**
 * host that runs in container.
 * a client can connect to a running host via TCP/IP
 *
 * Usage:
 * java -cp target/amod-VERSION.jar amod.socket.SocketHost [city]
 */
public enum SocketHost {
    ;

    public static final int PORT = 9382;

    private static final String ENV_SCENARIO = "SCENARIO";

    private static final String ENV_FLEET_SIZE = "FLEET_SIZE";

    private static final String ENV_REQUESTS_SIZE = "REQUESTS_SIZE";

    private static final String ENV_VIDEO_EXPORT = "VIDEO_EXPORT";

    public static void main(String[] args) throws Exception {
        File workingDirectory = MultiFileTools.getDefaultWorkingDirectory();
        run(workingDirectory);
    }

    public static void run(File workingDirectory) throws Exception {
        System.out.println("Using scenario directory: " + workingDirectory);
        StringSocket stringSocket = null;
        /**
         * open String server and wait for initial command
         */
        try (StringServerSocket serverSocket = new StringServerSocket(PORT)) {
            stringSocket = serverSocket.getSocketWait();
            // only allow one connection
            serverSocket.close();
            String readLine = stringSocket.readLine();
            Tensor config = Tensors.fromString(readLine);
            System.out.println("SocketHost config: " + config);
            Thread.sleep(1000);
            String scenarioTag = config.Get(0).toString();
            {
                String env = System.getenv(ENV_SCENARIO);
                if (Objects.nonNull(env))
                    env = scenarioTag;
            }
            /**
             * download the chosen scenario
             */
            SocketScenarioResource.extract(scenarioTag, workingDirectory);
            /**
             * setup environment variables
             */
            StaticHelper.setup();
            /**
             * run first part of scenario preparer
             */
            SocketPreparer preparer = new SocketPreparer(workingDirectory);
            /**
             * get number of requests in population
             */
            long numReq = LegCount.of(preparer.getPopulation(), AmodeusModeConfig.DEFAULT_MODE);
            Scalar nominalFleetSize = Round.of(RealScalar.of(numReq).multiply(ScoreParameters.GLOBAL.gamma));
            Tensor initialInfo = Tensors.of(RealScalar.of(numReq), preparer.getBoundingBox(), nominalFleetSize);
            /**
             * send initial data: {numberRequests,boundingBox}
             */
            stringSocket.writeln(initialInfo);
            /**
             * get additional information
             */
            String readLine2 = stringSocket.readLine();
            Tensor config2 = Tensors.fromString(readLine2);
            int numReqDes = config2.Get(0).number().intValue();
            int fleetSize = config2.Get(1).number().intValue();
            {
                String env = System.getenv(ENV_REQUESTS_SIZE);
                if (Objects.nonNull(env))
                    try {
                        numReqDes = Integer.parseInt(env);
                    } catch (Exception exception) {
                        exception.printStackTrace();
                    }
            }
            {
                String env = System.getenv(ENV_FLEET_SIZE);
                if (Objects.nonNull(env))
                    try {
                        fleetSize = Integer.parseInt(env);
                    } catch (Exception exception) {
                        exception.printStackTrace();
                    }
            }
            /**
             * run second part of preparer
             */
            preparer.run2(numReqDes);
            /**
             * run with socket dispatcher
             */
            ScenarioOptions scenarioOptions = new ScenarioOptions(workingDirectory, ScenarioOptionsBase.getDefault());
            String simConfigPath = scenarioOptions.getSimulationConfigName();
            ConfigDispatcherChanger.change(simConfigPath, SocketDispatcherHost.class.getSimpleName());
            ConfigVehiclesChanger.change(simConfigPath, fleetSize);
            SocketServer socketServer = new SocketServer();
            socketServer.simulate(stringSocket, numReqDes, workingDirectory);
            /**
             * send empty tensor "{}" to stop
             */
            stringSocket.writeln(Tensors.empty());
            /**
             * analyze and send final score
             */
            Analysis analysis = //
            Analysis.//
            setup(//
            socketServer.getScenarioOptions(), socketServer.getOutputDirectory(), socketServer.getNetwork(), preparer.getDatabase());
            SocketScoreElement socketScoreElement = new SocketScoreElement(fleetSize, numReqDes, preparer.getDatabase());
            analysis.addAnalysisElement(socketScoreElement);
            SocketExport socketExport = new SocketExport(socketScoreElement);
            analysis.addAnalysisExport(socketExport);
            SocketHtmlReport socketHtmlReport = new SocketHtmlReport(socketScoreElement);
            analysis.addHtmlElement(socketHtmlReport);
            analysis.run();
            {
                /**
                 * create a video if environment variable is set
                 */
                String env = System.getenv(ENV_VIDEO_EXPORT);
                if (Objects.nonNull(env) && env.equalsIgnoreCase("true"))
                    new VideoGenerator(workingDirectory).start();
            }
            /**
             * send final score,
             * {total waiting time, total distance with customer, total empty distance}
             */
            stringSocket.writeln(Total.of(socketScoreElement.getScoreDiffHistory()));
        } catch (Exception exception) {
            shutdown(stringSocket);
            throw exception;
        }
    }

    private static void shutdown(StringSocket stringSocket) throws Exception {
        if (Objects.nonNull(stringSocket)) {
            /**
             * send empty tensor "{}" to stop
             */
            stringSocket.writeln(Tensors.empty());
            /**
             * send fictitious costs
             */
            stringSocket.writeln(StaticHelper.FAILURE_SCORE);
        }


package amodeus.socket;

import java.io.File;
import java.util.Objects;
import amodeus.amodeus.analysis.Analysis;
import amodeus.amodeus.options.ScenarioOptions;
import amodeus.amodeus.options.ScenarioOptionsBase;
import amodeus.amodeus.prep.LegCount;
import amodeus.amodeus.util.io.MultiFileTools;
import amodeus.amodeus.util.matsim.xml.ConfigDispatcherChanger;
import amodeus.amodeus.util.matsim.xml.ConfigVehiclesChanger;
import amodeus.amodeus.util.net.StringServerSocket;
import amodeus.amodeus.util.net.StringSocket;
import amodeus.amodeus.video.VideoGenerator;
import org.matsim.amodeus.config.AmodeusModeConfig;
import amodeus.socket.core.ScoreParameters;
import amodeus.socket.core.SocketDispatcherHost;
import amodeus.socket.core.SocketScoreElement;
import ch.ethz.idsc.tensor.RealScalar;
import ch.ethz.idsc.tensor.Scalar;
import ch.ethz.idsc.tensor.Tensor;
import ch.ethz.idsc.tensor.Tensors;
import ch.ethz.idsc.tensor.red.Total;
import ch.ethz.idsc.tensor.sca.Round;

// TODO refactor and shorten @clruch
/**
 * host that runs in container.
 * a client can connect to a running host via TCP/IP
 *
 * Usage:
 * java -cp target/amod-VERSION.jar amod.socket.SocketHost [city]
 */
public enum SocketHost {
    ;

    public static final int PORT = 9382;

    private static final String ENV_SCENARIO = "SCENARIO";

    private static final String ENV_FLEET_SIZE = "FLEET_SIZE";

    private static final String ENV_REQUESTS_SIZE = "REQUESTS_SIZE";

    private static final String ENV_VIDEO_EXPORT = "VIDEO_EXPORT";

    public static void main(String[] args) throws Exception {
        File workingDirectory = MultiFileTools.getDefaultWorkingDirectory()

        run(workingDirectory);
    }

    public static void run(File workingDirectory) throws Exception {
        System.out.println("Using scenario directory: " + workingDirectory);
        StringSocket stringSocket = null;
        /**
         * open String server and wait for initial command
         */
        try (StringServerSocket serverSocket = new StringServerSocket(PORT)) {
            stringSocket = serverSocket.getSocketWait();
            // only allow one connection
            serverSocket.close();
            String readLine = stringSocket.readLine();
            Tensor config = Tensors.fromString(readLine);
            System.out.println("SocketHost config: " + config);
            Thread.sleep(1000);
            String scenarioTag = config.Get(0).toString();
            {
                String env = System.getenv(ENV_SCENARIO);
                if (Objects.nonNull(env))
                    env = scenarioTag;
            }
            /**
             * download the chosen scenario
             */
            SocketScenarioResource.extract(scenarioTag, workingDirectory);
            /**
             * setup environment variables
             */
            StaticHelper.setup();
            /**
             * run first part of scenario preparer
             */
            SocketPreparer preparer = new SocketPreparer(workingDirectory);
            /**
             * get number of requests in population
             */
            long numReq = LegCount.of(preparer.getPopulation(), AmodeusModeConfig.DEFAULT_MODE);
            Scalar nominalFleetSize = Round.of(RealScalar.of(numReq).multiply(ScoreParameters.GLOBAL.gamma));
            Tensor initialInfo = Tensors.of(RealScalar.of(numReq), preparer.getBoundingBox(), nominalFleetSize);
            /**
             * send initial data: {numberRequests,boundingBox}
             */
            stringSocket.writeln(initialInfo);
            /**
             * get additional information
             */
            String readLine2 = stringSocket.readLine();
            Tensor config2 = Tensors.fromString(readLine2);
            int numReqDes = config2.Get(0).number().intValue();
            int fleetSize = config2.Get(1).number().intValue();
            {
                String env = System.getenv(ENV_REQUESTS_SIZE);
                if (Objects.nonNull(env))
                    try {
                        numReqDes = Integer.parseInt(env);
                    } catch (Exception exception) {
                        exception.printStackTrace();
                    }
            }
            {
                String env = System.getenv(ENV_FLEET_SIZE);
                if (Objects.nonNull(env))
                    try {
                        fleetSize = Integer.parseInt(env);
                    } catch (Exception exception) {
                        exception.printStackTrace();
                    }
            }
            /**
             * run second part of preparer
             */
            preparer.run2(numReqDes);
            /**
             * run with socket dispatcher
             */
            ScenarioOptions scenarioOptions = new ScenarioOptions(workingDirectory, ScenarioOptionsBase.getDefault());
            String simConfigPath = scenarioOptions.getSimulationConfigName();
            ConfigDispatcherChanger.change(simConfigPath, SocketDispatcherHost.class.getSimpleName());
            ConfigVehiclesChanger.change(simConfigPath, fleetSize);
            SocketServer socketServer = new SocketServer();
            socketServer.simulate(stringSocket, numReqDes, workingDirectory);
            /**
             * send empty tensor "{}" to stop
             */
            stringSocket.writeln(Tensors.empty());
            /**
             * analyze and send final score
             */
            Analysis analysis = //
            Analysis.//
            setup(//
            socketServer.getScenarioOptions(), socketServer.getOutputDirectory(), socketServer.getNetwork(), preparer.getDatabase());
            SocketScoreElement socketScoreElement = new SocketScoreElement(fleetSize, numReqDes, preparer.getDatabase());
            analysis.addAnalysisElement(socketScoreElement);
            SocketExport socketExport = new SocketExport(socketScoreElement);
            analysis.addAnalysisExport(socketExport);
            SocketHtmlReport socketHtmlReport = new SocketHtmlReport(socketScoreElement);
            analysis.addHtmlElement(socketHtmlReport);
            analysis.run();
            {
                /**
                 * create a video if environment variable is set
                 */
                String env = System.getenv(ENV_VIDEO_EXPORT);
                if (Objects.nonNull(env) && env.equalsIgnoreCase("true"))
                    new VideoGenerator(workingDirectory).start();
            }
            /**
             * send final score,
             * {total waiting time, total distance with customer, total empty distance}
             */
            stringSocket.writeln(Total.of(socketScoreElement.getScoreDiffHistory()));
        } catch (Exception exception) {
            shutdown(stringSocket);
            throw exception;
        }
    }

    private static void shutdown(StringSocket stringSocket) throws Exception {
        if (Objects.nonNull(stringSocket)) {
            /**
             * send empty tensor "{}" to stop
             */
            stringSocket.writeln(Tensors.empty());
            /**
             * send fictitious costs
             */
            stringSocket.writeln(StaticHelper.FAILURE_SCORE);
        }
    }
}


try {
                        fleetSize = Integer.parseInt(env);
                    } catch (Exception exception) {
                        exception.printStackTrace();
                    }

package amodeus.socket;

import java.io.File;
import java.util.Objects;
import amodeus.amodeus.analysis.Analysis;
import amodeus.amodeus.options.ScenarioOptions;
import amodeus.amodeus.options.ScenarioOptionsBase;
import amodeus.amodeus.prep.LegCount;
import amodeus.amodeus.util.io.MultiFileTools;
import amodeus.amodeus.util.matsim.xml.ConfigDispatcherChanger;
import amodeus.amodeus.util.matsim.xml.ConfigVehiclesChanger;
import amodeus.amodeus.util.net.StringServerSocket;
import amodeus.amodeus.util.net.StringSocket;
import amodeus.amodeus.video.VideoGenerator;
import org.matsim.amodeus.config.AmodeusModeConfig;
import amodeus.socket.core.ScoreParameters;
import amodeus.socket.core.SocketDispatcherHost;
import amodeus.socket.core.SocketScoreElement;
import ch.ethz.idsc.tensor.RealScalar;
import ch.ethz.idsc.tensor.Scalar;
import ch.ethz.idsc.tensor.Tensor;
import ch.ethz.idsc.tensor.Tensors;
import ch.ethz.idsc.tensor.red.Total;
import ch.ethz.idsc.tensor.sca.Round;

// TODO refactor and shorten @clruch
/**
 * host that runs in container.
 * a client can connect to a running host via TCP/IP
 *
 * Usage:
 * java -cp target/amod-VERSION.jar amod.socket.SocketHost [city]
 */
public enum SocketHost {
    ;

    public static final int PORT = 9382;

    private static final String ENV_SCENARIO = "SCENARIO";

    private static final String ENV_FLEET_SIZE = "FLEET_SIZE";

    private static final String ENV_REQUESTS_SIZE = "REQUESTS_SIZE";

    private static final String ENV_VIDEO_EXPORT = "VIDEO_EXPORT";

    public static void main(String[] args) throws Exception {
        File workingDirectory = MultiFileTools.getDefaultWorkingDirectory();
        run(workingDirectory);
    }

    public static void run(File workingDirectory) throws Exception {
        System.out.println("Using scenario directory: " + workingDirectory);
        StringSocket stringSocket = null;
        /**
         * open String server and wait for initial command
         */
        try (StringServerSocket serverSocket = new StringServerSocket(PORT)) {
            stringSocket = serverSocket.getSocketWait();
            // only allow one connection
            serverSocket.close();
            String readLine = stringSocket.readLine();
            Tensor config = Tensors.fromString(readLine);
            System.out.println("SocketHost config: " + config);
            Thread.sleep(1000);
            String scenarioTag = config.Get(0).toString();
            {
                String env = System.getenv(ENV_SCENARIO);
                if (Objects.nonNull(env))
                    env = scenarioTag;
            }
            /**
             * download the chosen scenario
             */
            SocketScenarioResource.extract(scenarioTag, workingDirectory);
            /**
             * setup environment variables
             */
            StaticHelper.setup();
            /**
             * run first part of scenario preparer
             */
            SocketPreparer preparer = new SocketPreparer(workingDirectory);
            /**
             * get number of requests in population
             */
            long numReq = LegCount.of(preparer.getPopulation(), AmodeusModeConfig.DEFAULT_MODE);
            Scalar nominalFleetSize = Round.of(RealScalar.of(numReq).multiply(ScoreParameters.GLOBAL.gamma));
            Tensor initialInfo = Tensors.of(RealScalar.of(numReq), preparer.getBoundingBox(), nominalFleetSize);
            /**
             * send initial data: {numberRequests,boundingBox}
             */
            stringSocket.writeln(initialInfo);
            /**
             * get additional information
             */
            String readLine2 = stringSocket.readLine();
            Tensor config2 = Tensors.fromString(readLine2);
            int numReqDes = config2.Get(0).number().intValue();
            int fleetSize = config2.Get(1).number().intValue();
            {
                String env = System.getenv(ENV_REQUESTS_SIZE);
                if (Objects.nonNull(env))
                    try {
                        numReqDes = Integer.parseInt(env);
                    } catch (Exception exception) {
                        exception.printStackTrace();
                    }
            }
            {
                String env = System.getenv(ENV_FLEET_SIZE);
                if (Objects.nonNull(env))

            }
            /**
             * run second part of preparer
             */
            preparer.run2(numReqDes);
            /**
             * run with socket dispatcher
             */
            ScenarioOptions scenarioOptions = new ScenarioOptions(workingDirectory, ScenarioOptionsBase.getDefault());
            String simConfigPath = scenarioOptions.getSimulationConfigName();
            ConfigDispatcherChanger.change(simConfigPath, SocketDispatcherHost.class.getSimpleName());
            ConfigVehiclesChanger.change(simConfigPath, fleetSize);
            SocketServer socketServer = new SocketServer();
            socketServer.simulate(stringSocket, numReqDes, workingDirectory);
            /**
             * send empty tensor "{}" to stop
             */
            stringSocket.writeln(Tensors.empty());
            /**
             * analyze and send final score
             */
            Analysis analysis = //
            Analysis.//
            setup(//
            socketServer.getScenarioOptions(), socketServer.getOutputDirectory(), socketServer.getNetwork(), preparer.getDatabase());
            SocketScoreElement socketScoreElement = new SocketScoreElement(fleetSize, numReqDes, preparer.getDatabase());
            analysis.addAnalysisElement(socketScoreElement);
            SocketExport socketExport = new SocketExport(socketScoreElement);
            analysis.addAnalysisExport(socketExport);
            SocketHtmlReport socketHtmlReport = new SocketHtmlReport(socketScoreElement);
            analysis.addHtmlElement(socketHtmlReport);
            analysis.run();
            {
                /**
                 * create a video if environment variable is set
                 */
                String env = System.getenv(ENV_VIDEO_EXPORT);
                if (Objects.nonNull(env) && env.equalsIgnoreCase("true"))
                    new VideoGenerator(workingDirectory).start();
            }
            /**
             * send final score,
             * {total waiting time, total distance with customer, total empty distance}
             */
            stringSocket.writeln(Total.of(socketScoreElement.getScoreDiffHistory()));
        } catch (Exception exception) {
            shutdown(stringSocket);
            throw exception;
        }
    }

    private static void shutdown(StringSocket stringSocket) throws Exception {
        if (Objects.nonNull(stringSocket)) {
            /**
             * send empty tensor "{}" to stop
             */
            stringSocket.writeln(Tensors.empty());
            /**
             * send fictitious costs
             */
            stringSocket.writeln(StaticHelper.FAILURE_SCORE);
        }
    }
}