// Path: core/src/main/java/com/github/sdnwiselab/sdnwise/flowtable/AbstractAction.java
// public enum Action {
//     /**
//      * An empty action.
//      */
//     NULL(0),
//     /**
//      * Forward to a destination in unicast.
//      */
//     FORWARD_U(1),
//     /**
//      * Forward to a destination in broadcast.
//      */
//     FORWARD_B(2),
//     /**
//      * Drops the packet.
//      */
//     DROP(3),
//     /**
//      * Creates a new Request packet containing the current packet and sends
//      * it to the controller.
//      */
//     ASK(4),
//     /**
//      * Invokes a function.
//      */
//     FUNCTION(5),
//     /**
//      * Sets a byte in the status register or in the packet.
//      */
//     SET(6),
//     /**
//      * Matches the packet against the FlowTable.
//      */
//     MATCH(7);
// 
//     /**
//      * A byte representing the action.
//      */
//     private final byte value;
// 
//     /**
//      * Contains all the possible action values.
//      */
//     private static final Action[] A_VALUES = Action.values();
// 
//     /**
//      * Returns the corresponting Action given a byte.
//      *
//      * @param value a byte representing the Action
//      * @return the corresponding Action
//      */
//     public static Action fromByte(final byte value) {
//         return A_VALUES[value];
//     }
// 
//     /**
//      * Creates a new Action.
//      *
//      * @param v a byte representing the action.
//      */
//     Action(final int v) {
//         value = (byte) v;
//     }
// }
// 
// Path: core/src/main/java/com/github/sdnwiselab/sdnwise/flowtable/AbstractAction.java
// protected static final int TYPE_INDEX = 0;


import com.github.sdnwiselab.sdnwise.flowtable.AbstractAction.Action;
import static com.github.sdnwiselab.sdnwise.flowtable.AbstractAction.TYPE_INDEX;
/*
 * Copyright (C) 2015 SDN-WISE
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.github.sdnwiselab.sdnwise.flowtable;


/**
 * @author Sebastiano Milardo
 */
public final class ActionBuilder {

    /**
     * Builds a class extending AbstractAction, given a String.
     *
     * @param val the String representing the action
     * @return an object extending AbstractAction
     */
    public static AbstractAction build(final String val) {
        switch (Action.valueOf(val.split(" ")[0])) {
            case FORWARD_U:
                return new ForwardUnicastAction(val);
            case FORWARD_B:
                return new ForwardBroadcastAction();
            case SET:
                return new SetAction(val);
            case MATCH:
                return new MatchAction();
            case ASK:
                return new AskAction();
            case FUNCTION:
                return new FunctionAction(val);
            case DROP:
                return new DropAction();
            default:
                throw new IllegalArgumentException();
        }
    }

    /**
     * Builds a class extending AbstractAction, given a byte array.
     *
     * @param array the byte[] representing the action
     * @return an object extending AbstractAction
     */
    public static AbstractAction build(final byte[] array) {
// Path: core/src/main/java/com/github/sdnwiselab/sdnwise/flowtable/AbstractAction.java
// public enum Action {
//     /**
//      * An empty action.
//      */
//     NULL(0),
//     /**
//      * Forward to a destination in unicast.
//      */
//     FORWARD_U(1),
//     /**
//      * Forward to a destination in broadcast.
//      */
//     FORWARD_B(2),
//     /**
//      * Drops the packet.
//      */
//     DROP(3),
//     /**
//      * Creates a new Request packet containing the current packet and sends
//      * it to the controller.
//      */
//     ASK(4),
//     /**
//      * Invokes a function.
//      */
//     FUNCTION(5),
//     /**
//      * Sets a byte in the status register or in the packet.
//      */
//     SET(6),
//     /**
//      * Matches the packet against the FlowTable.
//      */
//     MATCH(7);
// 
//     /**
//      * A byte representing the action.
//      */
//     private final byte value;
// 
//     /**
//      * Contains all the possible action values.
//      */
//     private static final Action[] A_VALUES = Action.values();
// 
//     /**
//      * Returns the corresponting Action given a byte.
//      *
//      * @param value a byte representing the Action
//      * @return the corresponding Action
//      */
//     public static Action fromByte(final byte value) {
//         return A_VALUES[value];
//     }
// 
//     /**
//      * Creates a new Action.
//      *
//      * @param v a byte representing the action.
//      */
//     Action(final int v) {
//         value = (byte) v;
//     }
// }
// 
// Path: core/src/main/java/com/github/sdnwiselab/sdnwise/flowtable/AbstractAction.java
// protected static final int TYPE_INDEX = 0;


// Path: core/src/main/java/com/github/sdnwiselab/sdnwise/flowtable/ActionBuilder.java
import com.github.sdnwiselab.sdnwise.flowtable.AbstractAction.Action;
import static com.github.sdnwiselab.sdnwise.flowtable.AbstractAction.TYPE_INDEX;

/*
 * Copyright (C) 2015 SDN-WISE
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.github.sdnwiselab.sdnwise.flowtable;


/**
 * @author Sebastiano Milardo
 */
public final class ActionBuilder {

    /**
     * Builds a class extending AbstractAction, given a String.
     *
     * @param val the String representing the action
     * @return an object extending AbstractAction
     */
    public static AbstractAction build(final String val) {
        switch (Action.valueOf(val.split(" ")[0])) {
            case FORWARD_U:
                return new ForwardUnicastAction(val);
            case FORWARD_B:
                return new ForwardBroadcastAction();
            case SET:
                return new SetAction(val);
            case MATCH:
                return new MatchAction();
            case ASK:
                return new AskAction();
            case FUNCTION:
                return new FunctionAction(val);
            case DROP:
                return new DropAction();
            default:
                throw new IllegalArgumentException();
        }
    }

    /**
     * Builds a class extending AbstractAction, given a byte array.
     *
     * @param array the byte[] representing the action
     * @return an object extending AbstractAction
     */
    public static AbstractAction build(final byte[] array) {
        switch (Action.fromByte(array[TYPE_INDEX])) {