Example usage for java.lang EnumConstantNotPresentException EnumConstantNotPresentException

List of usage examples for java.lang EnumConstantNotPresentException EnumConstantNotPresentException

Introduction

In this page you can find the example usage for java.lang EnumConstantNotPresentException EnumConstantNotPresentException.

Prototype

public EnumConstantNotPresentException(Class<? extends Enum> enumType, String constantName) 

Source Link

Document

Constructs an EnumConstantNotPresentException for the specified constant.

Usage

From source file:de.qaware.chronix.solr.query.analysis.functions.math.NElements.java

/**
 * @param type        the calculation type: BOTTOM or TOP
 * @param n           the number of values n bottom or top values
 * @param timesStamps the time stamps of the time series
 * @param values      the belonging values of the time series
 * @return a result containing the top / bottom measurements (timestamp + value) of the time series
 *///from  w  w  w  .  j  a v a2s . c  o m
public static NElementsResult calc(NElementsCalculation type, int n, long[] timesStamps, double[] values) {
    //we have to convert them to a pair array, to not loose the reference to the time stamps
    Pair[] pairs = create(values);
    Arrays.sort(pairs);

    double[] nValues = new double[n];
    long[] nTimes = new long[n];

    switch (type) {
    case TOP:
        int j = 0;
        for (int i = timesStamps.length - 1; timesStamps.length - n <= i; i--) {
            nValues[j] = pairs[i].value;
            nTimes[j] = timesStamps[pairs[i].index];
            j++;
        }
        break;
    case BOTTOM:
        for (int i = 0; i < n; i++) {
            nValues[i] = pairs[i].value;
            nTimes[i] = timesStamps[pairs[i].index];
        }
        break;
    default:
        throw new EnumConstantNotPresentException(NElementsCalculation.class,
                "Type: " + type + " not available");
    }

    return new NElementsResult(nTimes, nValues);
}

From source file:it.scoppelletti.programmerpower.security.spi.EncodedKeyFactory.java

@Override
protected KeySpec getKeySpec(String alg, KeyRep.Type keyType, Properties props, String prefix) {
    String name, value;//  ww w  .j  av a  2 s.c o  m
    byte[] data;
    KeySpec keySpec;

    name = Strings.concat(prefix, EncodedKeyFactory.PROP_DATA);
    value = props.getProperty(name);
    if (Strings.isNullOrEmpty(value)) {
        throw new ArgumentNullException(name);
    }

    data = Base64.decodeBase64(value);

    switch (keyType) {
    case PUBLIC:
        keySpec = new X509EncodedKeySpec(data);
        break;

    case PRIVATE:
        keySpec = new PKCS8EncodedKeySpec(data);
        break;

    default:
        throw new EnumConstantNotPresentException(KeyRep.Type.class, keyType.toString());
    }

    return keySpec;
}

From source file:de.decoit.visa.http.ajax.handlers.ExecuteModificationsHandler.java

@Override
public void handle(HttpExchange he) throws IOException {
    log.info(he.getRequestURI().toString());

    // Get the URI of the request and extract the query string from it
    QueryString queryParameters = new QueryString(he.getRequestURI());

    // Create StringBuilder for the response
    String response = null;/* w w  w  .j av  a2s.  com*/

    // Check if the query parameters are valid for this handler
    if (this.checkQueryParameters(queryParameters)) {
        // Any exception thrown during object creation will cause
        // failure of the AJAX request
        try {
            JSONObject rv = new JSONObject();

            // Get the modification queue which will be processed
            ModificationQueue mq = TEBackend.getModificationQueue(queryParameters.get("queueID").get());

            for (Modification mod : mq.getModifications()) {
                switch (mod.getTargetType()) {
                case COMPONENT:
                    // Get the target object
                    NetworkComponent nc = TEBackend.TOPOLOGY_STORAGE.getComponent(mod.getTargetLocalName());

                    if (mod.getTargetAttribute().equals(ModificationTargetAttribute.COMPONENT_NAME)) {
                        nc.setName(mod.getTargetAttributeValue());
                    } else {
                        throw new IllegalArgumentException(
                                "Unsupported target attribute for target object COMPONENT found");
                    }
                    break;
                case INTERFACE:
                    // Get the target object
                    Interface iface = TEBackend.TOPOLOGY_STORAGE.getInterface(mod.getTargetLocalName());

                    if (mod.getTargetAttribute().equals(ModificationTargetAttribute.INTERFACE_NETWORK)) {
                        List<IPConfig> ipList = iface.getNonLinkLocalIPConfig();
                        if (ipList.size() > 1) {
                            throw new UnsupportedOperationException(
                                    "Changing network value on interfaces with multiple non-link-local addresses is not supported");
                        } else if (ipList.size() == 1) {
                            iface.removeIPConfiguration(ipList.get(0));
                        }

                        if (!mod.getTargetAttributeValue().equals("none")) {
                            IPNetwork network = TEBackend.TOPOLOGY_STORAGE
                                    .getNetwork(mod.getTargetAttributeValue());
                            IPAddress dummyAddr = network.getFreeIPAddress();

                            iface.configureIP(dummyAddr, network);
                        }
                    } else if (mod.getTargetAttribute()
                            .equals(ModificationTargetAttribute.INTERFACE_ORIENTATION)) {
                        PortOrientation ori = PortOrientation.valueOf(mod.getTargetAttributeValue());

                        iface.setOrientation(ori);
                    } else {
                        throw new IllegalArgumentException(
                                "Unsupported target attribute for target object INTERFACE found");
                    }
                    break;
                default:
                    throw new EnumConstantNotPresentException(ModificationTarget.class,
                            mod.getTargetType().toString());
                }
            }

            rv.put("status", AJAXServer.AJAX_SUCCESS);
            rv.put("topology", TEBackend.TOPOLOGY_STORAGE.genTopologyJSON());

            response = rv.toString();
        } catch (Throwable ex) {
            TEBackend.logException(ex, log);

            try {
                // Synchronize the topology with the RDF model to resolve
                // any errors caused by the caught exception
                TEBackend.RDF_MANAGER.syncTopologyToRDF();

                JSONObject rv = new JSONObject();
                rv.put("status", AJAXServer.AJAX_ERROR_EXCEPTION);
                rv.put("type", ex.getClass().getSimpleName());
                rv.put("message", ex.getMessage());
                rv.put("topology", TEBackend.TOPOLOGY_STORAGE.genTopologyJSON());
                response = rv.toString();
            } catch (Throwable e) {
                // Exception during synchronization, the model may have been
                // corrupted so the whole backend was cleared
                JSONObject rv = new JSONObject();
                try {
                    rv.put("status", AJAXServer.AJAX_ERROR_EXCEPTION_UNRESOLVED);
                    rv.put("topology", TEBackend.TOPOLOGY_STORAGE.genTopologyJSON());
                } catch (JSONException exc) {
                    /* Ignore */
                }

                response = rv.toString();
            }
        }

    } else {
        // Missing or malformed query string, set response to error code
        JSONObject rv = new JSONObject();
        try {
            rv.put("status", AJAXServer.AJAX_ERROR_MISSING_ARGS);
        } catch (JSONException exc) {
            /* Ignore */
        }

        response = rv.toString();
    }

    // Send the response
    sendResponse(he, response);
}

From source file:it.scoppelletti.programmerpower.web.control.ActionBase.java

public void display(MessageEvent event) {
    synchronized (myMessages) {
        myMessages.add(new ActionMessage(event));

        switch (event.getMessageType()) {
        case ERROR:
            super.addActionError(event.getMessage());
            break;

        case INFORMATION:
            super.addActionMessage(event.getMessage());
            break;

        case WARNING:
            super.addActionMessage(event.getMessage());
            break;

        default:/*from   ww w  .  j  av  a2  s.  com*/
            throw new EnumConstantNotPresentException(MessageType.class, event.getMessageType().name());
        }
    }
}