SquirrelJME/SquirrelJME

View on GitHub
modules/cldc-compact/src/main/java/cc/squirreljme/jvm/suite/SuiteDependencyType.java

Summary

Maintainability
A
0 mins
Test Coverage
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// SquirrelJME
//     Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the Mozilla Public License Version 2.0.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package cc.squirreljme.jvm.suite;

import cc.squirreljme.runtime.cldc.debug.Debugging;

/**
 * This represents the type of the dependency that is to be included.
 *
 * @since 2017/02/22
 */
public enum SuiteDependencyType
{
    /** Liblet. */
    LIBLET,
    
    /** Standard. */
    STANDARD,
    
    /** Service. */
    SERVICE,
    
    /** Proprietary. */
    PROPRIETARY,
    
    /** End. */
    ;
    
    /**
     * {@inheritDoc}
     * @since 2017/02/22
     */
    @Override
    public String toString()
    {
        // Convert string
        switch (this)
        {
            case LIBLET:        return "liblet";
            case STANDARD:        return "standard";
            case SERVICE:        return "service";
            case PROPRIETARY:    return "proprietary";
            
            default:
                throw Debugging.oops();
        }
    }
    
    /**
     * Returns the dependency type based on the input string.
     *
     * @param __s The input string to parse.
     * @return The dependency type for the given string.
     * @throws InvalidSuiteException If the dependency type is not
     * valid.
     * @throws NullPointerException On null arguments.
     * @since 2017/02/22
     */
    public static SuiteDependencyType of(String __s)
        throws InvalidSuiteException, NullPointerException
    {
        // Check
        if (__s == null)
            throw new NullPointerException("NARG");
        
        // Depends
        switch (__s.trim())
        {
            case "liblet":        return SuiteDependencyType.LIBLET;
            case "standard":    return SuiteDependencyType.STANDARD;
            case "service":        return SuiteDependencyType.SERVICE;
            case "proprietary":    return SuiteDependencyType.PROPRIETARY;
            
                /* {@squirreljme.error DG0a The specified string is not a valid
                dependency type. (The input string)} */
            default:
                throw new InvalidSuiteException(
                    String.format("AR0a %s", __s));
        }
    }
}