Example usage for java.lang Byte Byte

List of usage examples for java.lang Byte Byte

Introduction

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

Prototype

@Deprecated(since = "9")
public Byte(String s) throws NumberFormatException 

Source Link

Document

Constructs a newly allocated Byte object that represents the byte value indicated by the String parameter.

Usage

From source file:com.willwinder.universalgcodesender.GrblControllerTest.java

/**
 * Test of numCancelSendCalls method, of class GrblController.
 *///from   w w w .  j a  v a2 s  . co  m
@Test
public void testCancelSend() throws Exception {
    System.out.println("cancelSend");
    GrblController instance = new GrblController(mgc);
    instance.openCommPort(getSettings().getConnectionDriver(), "blah", 1234);

    // 0. Test GRBL not returning to idle during cancel.
    instance.rawResponseHandler("Grbl 0.8c");
    instance.cancelSend();
    for (int i = 0; i < 50; i++) {
        instance.rawResponseHandler("<Running,MPos:1.0,2.0,3.0>");
    }
    assertEquals(1, mgc.numPauseSendCalls);
    assertEquals(1, mgc.numCancelSendCalls);
    assertEquals(0, mgc.numSoftResetCalls);
    instance.resumeStreaming();

    setState(instance, COMM_IDLE);

    // Test 1.1 Cancel when nothing is running (Grbl 0.7).
    instance.rawResponseHandler("Grbl 0.7");
    instance.cancelSend();
    assertEquals(2, mgc.numCancelSendCalls);
    assertEquals(0, mgc.numSoftResetCalls);

    // Test 1.2 Cancel when nothing is running (Grbl 0.8c).
    //          Check for soft reset.
    instance.rawResponseHandler("Grbl 0.8c");
    instance.cancelSend();
    instance.rawResponseHandler("<Hold,MPos:1.0,2.0,3.0>");
    instance.rawResponseHandler("<Hold,MPos:1.0,2.0,3.0>");
    assertEquals(3, mgc.numCancelSendCalls);
    assertEquals(2, mgc.numPauseSendCalls);
    assertEquals(1, mgc.numSoftResetCalls);
    instance.resumeStreaming();

    // Test 2.1 
    // Add 30 commands, start send, cancel before any sending. (Grbl 0.7)
    instance.rawResponseHandler("Grbl 0.7");
    for (int i = 0; i < 30; i++) {
        instance.queueCommand(instance.createCommand("G0X" + i));
    }
    try {
        instance.beginStreaming();
    } catch (Exception ex) {
        fail("Unexpected exception from GrblController: " + ex.getMessage());
    }
    instance.cancelSend();
    assertEquals(4, mgc.numCancelSendCalls);
    assertEquals(2, mgc.numPauseSendCalls);
    assertEquals(1, mgc.numSoftResetCalls);
    assertEquals(30, instance.rowsInSend());
    assertEquals(30, instance.rowsRemaining());

    // Test 2.2
    // Add 30 commands, start send, cancel before any sending. (Grbl 0.8c)
    //setUp();
    //instance = new GrblController(mgc);
    instance.rawResponseHandler("Grbl 0.8c");
    for (int i = 0; i < 30; i++) {
        instance.queueCommand(instance.createCommand("G0X" + i));
    }
    try {
        instance.beginStreaming();
    } catch (Exception ex) {
        fail("Unexpected exception from GrblController: " + ex.getMessage());
    }
    instance.cancelSend();
    instance.rawResponseHandler("<Hold,MPos:1.0,2.0,3.0>");
    instance.rawResponseHandler("<Hold,MPos:1.0,2.0,3.0>");
    assertEquals(0, instance.rowsInSend());
    assertEquals(0, instance.rowsRemaining());
    assertEquals(5, mgc.numCancelSendCalls);
    assertEquals(3, mgc.numPauseSendCalls);
    assertEquals(2, mgc.numSoftResetCalls);
    instance.resumeStreaming();

    // Test 3.1
    // Add 30 commands, start send, cancel after sending 15. (Grbl 0.7)
    instance.rawResponseHandler("Grbl 0.7");
    for (int i = 0; i < 30; i++) {
        instance.queueCommand(instance.createCommand("G0X0"));
    }
    try {
        instance.beginStreaming();
        for (int i = 0; i < 15; i++) {
            GcodeCommand command = new GcodeCommand("G0X0");
            command.setSent(true);
            command.setResponse("ok");
            instance.commandSent(command);
        }
    } catch (Exception ex) {
        fail("Unexpected exception from command sent: " + ex.getMessage());
    }
    instance.cancelSend();
    assertEquals(6, mgc.numCancelSendCalls);
    assertEquals(3, mgc.numPauseSendCalls);
    assertEquals(2, mgc.numSoftResetCalls);
    assertEquals(30, instance.rowsInSend());
    assertEquals(30, instance.rowsRemaining());
    // wrap up
    wrapUp(instance, 15);

    // Test 3.2
    // Add 30 commands, start send, cancel after sending 15. (Grbl 0.8c)
    instance.rawResponseHandler("Grbl 0.8c");
    for (int i = 0; i < 30; i++) {
        instance.queueCommand(instance.createCommand("G0X" + i));
    }
    try {
        instance.beginStreaming();
        for (int i = 0; i < 15; i++) {
            GcodeCommand command = new GcodeCommand("G0 X1");
            command.setSent(true);
            command.setResponse("ok");
            instance.commandSent(command);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("Unexpected exception from command sent: " + ex.getMessage());
    }

    instance.cancelSend();
    instance.rawResponseHandler("<Hold,MPos:1.0,2.0,3.0>");
    instance.rawResponseHandler("<Hold,MPos:1.0,2.0,3.0>");
    assertEquals(15, instance.rowsSent());
    assertEquals(0, instance.rowsInSend());
    assertEquals(0, instance.rowsRemaining());
    assertEquals(7, mgc.numCancelSendCalls);
    assertEquals(4, mgc.numPauseSendCalls);
    assertEquals(3, mgc.numSoftResetCalls);
    assertEquals(new Byte(GrblUtils.GRBL_RESET_COMMAND), mgc.sentBytes.get(mgc.sentBytes.size() - 1));
    instance.resumeStreaming();
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgClient.CFAccXMsgClientSchema.java

public static Byte getNullableByte(ResultSet reader, int colidx) {
    try {//from   w w w  . j  a va2 s  . c o  m
        byte val = reader.getByte(colidx);
        if (reader.wasNull()) {
            return (null);
        } else {
            return (new Byte(val));
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(CFAccXMsgClientSchema.class, "getNullableByte",
                e);
    }
}

From source file:org.soybeanMilk.core.config.parser.ConfigurationParser.java

/**
 * ?Arg/* w w w. jav a  2 s.c om*/
 * @param strArg
 * @param strType
 * @return
 * @date 2012-5-8
 */
protected Arg stringToArg(String strArg, String strType) {
    Arg re = null;

    Type argType = null;
    if (strType != null && strType.length() > 0)
        argType = nameToType(strType);

    if (strArg == null || strArg.length() == 0)
        re = new ValueArg(strArg, argType);
    else {
        int len = strArg.length();
        char first = strArg.charAt(0);
        char end = strArg.charAt(len - 1);

        //
        if (Character.isDigit(first)) {
            Type wrappedType = (argType == null ? null : SbmUtils.wrapType(argType));

            if (Byte.class.equals(wrappedType)) {
                re = new ValueArg(new Byte(strArg), argType);
            } else if (Short.class.equals(wrappedType)) {
                re = new ValueArg(new Short(strArg), argType);
            } else if (Integer.class.equals(wrappedType)) {
                re = new ValueArg(new Integer(strArg), argType);
            } else if (Long.class.equals(wrappedType)) {
                re = new ValueArg(new Long(strArg), argType);
            } else if (Float.class.equals(wrappedType)) {
                re = new ValueArg(new Float(strArg), argType);
            } else if (Double.class.equals(wrappedType)) {
                re = new ValueArg(new Double(strArg), argType);
            } else if ('L' == end) {
                re = new ValueArg(new Long(strArg.substring(0, len - 1)), Long.class);
            } else if ('l' == end) {
                re = new ValueArg(new Long(strArg.substring(0, len - 1)), long.class);
            } else if ('F' == end) {
                re = new ValueArg(new Float(strArg.substring(0, len - 1)), Float.class);
            } else if ('f' == end) {
                re = new ValueArg(new Float(strArg.substring(0, len - 1)), float.class);
            } else if ('D' == end) {
                re = new ValueArg(new Double(strArg.substring(0, len - 1)), Double.class);
            } else if ('d' == end) {
                re = new ValueArg(new Double(strArg.substring(0, len - 1)), double.class);
            } else {
                boolean point = strArg.indexOf('.') >= 0;

                if (point)
                    re = new ValueArg(new Double(strArg), argType);
                else
                    re = new ValueArg(new Integer(strArg), argType);
            }
        } else if (first == '"') {
            String ue = SbmUtils.unEscape(strArg);
            len = ue.length();

            if (len < 2 || ue.charAt(len - 1) != '"')
                throw new ParseException("illegal String definition: " + strArg);

            if (len == 2)
                re = new ValueArg("", argType);
            else
                re = new ValueArg(ue.subSequence(1, len - 1), argType);
        } else if (first == '\'') {
            String ue = SbmUtils.unEscape(strArg);
            len = ue.length();

            if (len != 3 || end != '\'')
                throw new ParseException("illegal char definition: " + strArg);

            re = new ValueArg(ue.charAt(1), argType);
        } else if ("true".equals(strArg)) {
            re = new ValueArg(Boolean.TRUE, argType);
        } else if ("false".equals(strArg)) {
            re = new ValueArg(Boolean.FALSE, argType);
        } else if ("null".equals(strArg)) {
            re = new ValueArg(null, argType);
        } else
            re = new KeyArg(strArg, argType);
    }

    return re;
}

From source file:ar.com.fdvs.dj.core.layout.Dj2JrCrosstabBuilder.java

/**
 * Register the Rowgroup buckets and places the header cells for the rows
 *//*from  w  ww. j ava  2 s .com*/
private void registerRows() {
    for (int i = 0; i < rows.length; i++) {
        DJCrosstabRow crosstabRow = rows[i];

        JRDesignCrosstabRowGroup ctRowGroup = new JRDesignCrosstabRowGroup();

        ctRowGroup.setWidth(crosstabRow.getHeaderWidth());

        ctRowGroup.setName(crosstabRow.getProperty().getProperty());

        JRDesignCrosstabBucket rowBucket = new JRDesignCrosstabBucket();
        ctRowGroup.setBucket(rowBucket);

        JRDesignExpression bucketExp = ExpressionUtils.createExpression(
                "$F{" + crosstabRow.getProperty().getProperty() + "}",
                crosstabRow.getProperty().getValueClassName());
        rowBucket.setExpression(bucketExp);

        JRDesignCellContents rowHeaderContents = new JRDesignCellContents();
        JRDesignTextField rowTitle = new JRDesignTextField();

        JRDesignExpression rowTitExp = new JRDesignExpression();
        rowTitExp.setValueClassName(crosstabRow.getProperty().getValueClassName());
        rowTitExp.setText("$V{" + crosstabRow.getProperty().getProperty() + "}");

        rowTitle.setExpression(rowTitExp);
        rowTitle.setWidth(crosstabRow.getHeaderWidth());

        //The width can be the sum of the with of all the rows starting from the current one, up to the inner most one.
        int auxHeight = getRowHeaderMaxHeight(crosstabRow);
        //         int auxHeight = crosstabRow.getHeight(); //FIXME getRowHeaderMaxHeight() must be FIXED because it breaks when 1rs row shows total and 2nd doesn't
        rowTitle.setHeight(auxHeight);

        Style headerstyle = crosstabRow.getHeaderStyle() == null ? this.djcross.getRowHeaderStyle()
                : crosstabRow.getHeaderStyle();

        if (headerstyle != null) {
            layoutManager.applyStyleToElement(headerstyle, rowTitle);
            rowHeaderContents.setBackcolor(headerstyle.getBackgroundColor());
        }

        rowHeaderContents.addElement(rowTitle);
        rowHeaderContents.setMode(new Byte(Transparency.OPAQUE.getValue()));
        applyCellBorder(rowHeaderContents);

        ctRowGroup.setHeader(rowHeaderContents);

        if (crosstabRow.isShowTotals())
            createRowTotalHeader(ctRowGroup, crosstabRow);

        try {
            jrcross.addRowGroup(ctRowGroup);
        } catch (JRException e) {
            log.error(e.getMessage(), e);
        }

    }
}

From source file:org.apache.flex.forks.velocity.runtime.configuration.Configuration.java

/**
 * Get a byte associated with the given configuration key.
 *
 * @param key The configuration key./*  w  w  w.  ja  v  a2s.  c  o  m*/
 * @param defaultValue The default value.
 * @return The associated byte.
 * @exception ClassCastException is thrown if the key maps to an
 * object that is not a Byte.
 * @exception NumberFormatException is thrown if the value mapped
 * by the key has not a valid number format.
 */
public byte getByte(String key, byte defaultValue) {
    return getByte(key, new Byte(defaultValue)).byteValue();
}

From source file:org.lockss.test.LockssTestCase.java

public static void assertNotEquals(String message, byte expected, byte actual) {
    assertNotEquals(message, new Byte(expected), new Byte(actual));
}

From source file:edu.ku.brc.specify.dbsupport.TaskSemaphoreMgr.java

/**
 * Gets the semaphore and set the lock to true.
 * @param session/*  w w w . j  a v a2 s  . c o  m*/
 * @param name the unique name
 * @param context 
 * @param scope the scope of the lock
 * @param doLock
 * @param doOverride
 * @return
 * @throws Exception
 */
private static SpTaskSemaphore setLock(final DataProviderSessionIFace session, final String name,
        final String context, final SCOPE scope, final boolean doLock, final boolean doOverride,
        final boolean checkUsage) throws Exception {
    Timestamp now = new Timestamp(System.currentTimeMillis());

    SpecifyUser user = AppContextMgr.getInstance().getClassObject(SpecifyUser.class);
    Discipline discipline = scope == SCOPE.Discipline
            ? AppContextMgr.getInstance().getClassObject(Discipline.class)
            : null;
    Collection collection = scope == SCOPE.Collection
            ? AppContextMgr.getInstance().getClassObject(Collection.class)
            : null;

    // Get our own copies of the Global Objects.
    user = user != null
            ? session.getData(SpecifyUser.class, "id", user.getId(),
                    DataProviderSessionIFace.CompareType.Equals)
            : null;
    discipline = discipline != null
            ? session.getData(Discipline.class, "id", discipline.getId(),
                    DataProviderSessionIFace.CompareType.Equals)
            : null;
    collection = collection != null
            ? session.getData(Collection.class, "id", collection.getId(),
                    DataProviderSessionIFace.CompareType.Equals)
            : null;

    SpTaskSemaphore semaphore = getSemaphore(session, name, scope, discipline, collection);
    if (semaphore != null) {
        boolean locked = semaphore.getIsLocked()
                || (checkUsage && semaphore.getUsageCount() != null && semaphore.getUsageCount() > 0);
        if (doLock) {
            if (locked && !doOverride) {
                previouslyLocked = true;
                if (semaphore.getOwner() != null && semaphore.getOwner().getAgents() != null
                        && semaphore.getOwner().getAgents().size() > 0) {
                    prevLockedBy = semaphore.getOwner().getAgents().iterator().next().getIdentityTitle();
                } else {
                    prevLockedBy = null;
                }
                return semaphore;
            }
        } else if (!semaphore.getIsLocked()) {
            //throw new RuntimeException("Trying to unlock when already unlocked!");
            log.error("Trying to unlock when already unlocked!");
        }

        previouslyLocked = locked;

    } else if (doLock) {
        semaphore = new SpTaskSemaphore();
        semaphore.initialize();
        semaphore.setTaskName(name);
        semaphore.setTimestampCreated(now);
        //user.addReference(semaphore, "taskSemaphores");
        semaphore.setOwner(user);
        previouslyLocked = false;

    } else {
        // Changing to just an error message for Bug 6478
        // I think it was a timing issue. I wasn't able to
        // reproduce it.
        log.error("Try to unlock when there is no lock.");
        return null;
        // error
        //throw new RuntimeException("No lock!");
    }

    //if (semaphore != null)
    {
        semaphore.setIsLocked(doLock);
        semaphore.setContext(context);
        String machineName = "";
        try {
            machineName = InetAddress.getLocalHost().toString();
        } catch (UnknownHostException ex) {
            //no internet connection. ignore.
        }

        machineName = StringUtils.isNotEmpty(machineName)
                ? machineName.substring(0, Math.min(64, machineName.length()))
                : null;
        semaphore.setMachineName(doLock ? machineName : null);
        semaphore.setScope(new Byte((byte) scope.ordinal()));
        semaphore.setLockedTime(now);
        semaphore.setUsageCount(null);
        semaphore.setTimestampModified(now);
        semaphore.setDiscipline(discipline);
        semaphore.setCollection(collection);
        semaphore.setOwner(user);

        session.beginTransaction();
        session.saveOrUpdate(semaphore);
        session.commit();
    }

    return semaphore;
}

From source file:org.apache.flex.forks.velocity.runtime.configuration.Configuration.java

/**
 * Get a byte associated with the given configuration key.
 *
 * @param key The configuration key./*  w ww. j a  v a  2 s  . co  m*/
 * @param defaultValue The default value.
 * @return The associated byte if key is found and has valid
 * format, default value otherwise.
 * @exception ClassCastException is thrown if the key maps to an
 * object that is not a Byte.
 * @exception NumberFormatException is thrown if the value mapped
 * by the key has not a valid number format.
 */
public Byte getByte(String key, Byte defaultValue) {
    Object value = get(key);

    if (value instanceof Byte) {
        return (Byte) value;
    } else if (value instanceof String) {
        Byte b = new Byte((String) value);
        put(key, b);
        return b;
    } else if (value == null) {
        if (defaults != null) {
            return defaults.getByte(key, defaultValue);
        } else {
            return defaultValue;
        }
    } else {
        throw new ClassCastException('\'' + key + "' doesn't map to a Byte object");
    }
}

From source file:net.sf.json.TestJSONArray.java

public void testToArray_Byte() {
    Integer[] expected = new Integer[] { new Integer(1), new Integer(2) };
    Byte[] bytes = new Byte[] { new Byte((byte) 1), new Byte((byte) 2) };
    JSONArray jsonArray = JSONArray.fromObject(bytes);
    Object actual = JSONArray.toArray(jsonArray);
    Assertions.assertEquals(expected, actual);
}

From source file:net.sf.taverna.t2.activities.apiconsumer.ApiConsumerActivity.java

/**
 * Returns an array of objects representing the arguments of the method to be invoked.
 *
 * @return//from  w  w  w. jav  a 2  s  .c om
 * @throws Exception
 */
private Object[] argumentObjects(Map<String, T2Reference> data, AsynchronousActivityCallback callback)
        throws Exception {

    ReferenceService referenceService = callback.getContext().getReferenceService();

    // Argument objects
    String className = json.get("className").textValue();
    String methodName = json.get("methodName").textValue();
    JsonNode parameterNames = json.get("parameterNames");
    JsonNode parameterTypes = json.get("parameterTypes");
    JsonNode parameterDimensions = json.get("parameterDimensions");
    Object[] inputObjects = new Object[parameterTypes.size()];
    for (int i = 0; i < inputObjects.length; i++) {
        // Get the argument object from the reference service
        String parameterName = parameterNames.get(i).textValue();
        String parameterType = parameterTypes.get(i).textValue();
        int parameterDimension = parameterDimensions.get(i).intValue();
        Object argument = null;

        if (canRegisterAsString(parameterType)) {
            // Parameter was registered as a String with the Reference Service -
            // try to get it as String or list (of lists of ...) Strings and parse it internally
            try {
                argument = referenceService.renderIdentifier(data.get(parameterName), String.class,
                        callback.getContext());
            } catch (ReferenceServiceException rse) {
                throw new Exception("API Consumer " + className + "." + methodName + " error: "
                        + "Could not fetch the input argument " + parameterName + " of type " + parameterType
                        + " from the Reference Service.");
            }

            if (argument == null) {
                throw new Exception(
                        "API Consumer " + className + "." + methodName + " error: " + "Required input argument "
                                + parameterName + " of type " + parameterType + " not found.");
            }

            if (parameterType == "char") {
                // char
                if (parameterDimension == 0) {
                    inputObjects[i] = new Character(((String) argument).charAt(0));
                }
                //char[]
                else if (parameterDimension == 1) {
                    inputObjects[i] = ((String) argument).toCharArray();
                } else // char[][] is returned as a list of Strings, char[][][] is returned as a list of lists of Strings etc.
                {
                    // Convert the list (of lists of ...) Strings to char[][]...[]
                    inputObjects[i] = createInputObject(argument, "char[]", parameterDimension - 1);
                }
            } else {
                inputObjects[i] = createInputObject(argument, parameterType, parameterDimension);
            }
        } else if (parameterType == "byte") {
            // Parameter was registered as byte, byte[], byte[][], etc.
            try {
                argument = referenceService.renderIdentifier(data.get(parameterName), byte[].class,
                        callback.getContext());

            } catch (ReferenceServiceException rse) {
                throw new Exception("API Consumer " + className + "." + methodName + " error: "
                        + "Could not fetch the input argument " + parameterName + " of type " + parameterType
                        + " from the Reference Service.");
            }

            if (argument == null) {
                throw new Exception(
                        "API Consumer " + className + "." + methodName + " error: " + "Required input argument "
                                + parameterName + " of type " + parameterType + " not found.");
            }

            if (parameterDimension == 0) {
                inputObjects[i] = new Byte(((byte[]) argument)[0]);
            } else if (parameterDimension == 1) {
                inputObjects[i] = (byte[]) argument;
            } else // byte[][] is returned as a list of byte[]s, byte[][][] is returned as a list of lists of byte[]s, etc.
            {
                // Convert the list (of lists of ...) byte[] to byte[][]...[]
                inputObjects[i] = createInputObject(argument, "byte[]", parameterDimension - 1);
            }
        } else {
            // Parameter was regestered with Reference Service as object inside an VMObjectReference wrapper
            try {
                // Get the reference set for the VMObjectReference
                ReferenceSet vmObjectReferenceSet = (ReferenceSet) referenceService
                        .resolveIdentifier(data.get(parameterName), null, callback.getContext());
                // The set should contain only one external reference, i.e. VMObjectReference
                Set<ExternalReferenceSPI> externalReferences = vmObjectReferenceSet.getExternalReferences();
                for (ExternalReferenceSPI externalReference : externalReferences) {
                    if (externalReference instanceof VMObjectReference) {
                        argument = (VMObjectReference) externalReference;
                        break;
                    }
                }
            } catch (ReferenceServiceException rse) {
                throw new Exception("API Consumer " + className + "." + methodName + " error: "
                        + "Could not fetch the input argument " + parameterName + " of type " + parameterType
                        + " from the Reference Service.");
            }

            if (argument == null) {
                throw new Exception(
                        "API Consumer " + className + "." + methodName + " error: " + "Required input argument "
                                + parameterName + " of type " + parameterType + " not found.");
            }
            // Get the actual object from the wrapper
            inputObjects[i] = ((VMObjectReference) argument).getObject();
        }
    }
    return inputObjects;
}