Example usage for java.lang Byte parseByte

List of usage examples for java.lang Byte parseByte

Introduction

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

Prototype

public static byte parseByte(String s) throws NumberFormatException 

Source Link

Document

Parses the string argument as a signed decimal byte .

Usage

From source file:com.lottery.gui.MainLotteryForm.java

private void btnStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStartActionPerformed
    try {//from ww w .  j  ava 2s  .c o  m
        drawDate = LotteryUtils.getDate(ftfDrawDate.getText().trim());
        byte round = Byte.parseByte((String) cbbRound.getSelectedItem());

        DrawResult existedDrawResult = drawResultService.findBy(drawDate, round);
        if (existedDrawResult != null) {
            JOptionPane.showMessageDialog(this,
                    "Already drawed on " + ftfDrawDate.getText().trim() + " for round " + round);
            return;
        }

        dbTicketTables = ticketTableService.getByDate(drawDate);
    } catch (ParseException ex) {
        JOptionPane.showMessageDialog(this, "Invalid date format: dd/MM/yyyy");
        ftfDrawDate.requestFocusInWindow();
        return;
    }
    //        if (dbTicketTables.isEmpty()) {
    //            dbTicketTables = ticketTableService.getByDate(today);
    //        }

    Date today = LotteryUtils.getDateWithoutTime(new Date());

    if (drawDate.before(today)) {
        JOptionPane.showMessageDialog(this, "Draw date must be greater or equal than today!");
        ftfDrawDate.requestFocusInWindow();
        return;
    }

    setPanelEnabled(pnSettings, false);
    btnReplay.setEnabled(true);
    setPanelEnabled(pnInput, true);
    isGameRunning = true;
}

From source file:com.hzc.framework.ssh.controller.WebUtil.java

private static <T> T pbRecurrence(Class<T> c, String prefix) throws RuntimeException {
    try {//from   w  w  w .j a v  a  2 s . c  o  m
        HttpServletRequest request = ActionContext.getReq();
        T newInstance = c.newInstance();
        Field[] declaredFields = c.getDeclaredFields();
        for (Field field : declaredFields) {
            field.setAccessible(true);
            String name = field.getName();
            String key = "".equals(prefix) ? name : prefix + "." + name;
            String value = request.getParameter(key);

            Class<?> type = field.getType();
            if (type.isArray()) {//?string   file
                Class<?> componentType = type.getComponentType();
                if (componentType == String.class) {
                    String[] values = request.getParameterValues(name);
                    //                    if (null == value || "".equals(value)) continue;
                    //                    String[] split = value.split(",");
                    field.set(newInstance, values);
                } else if (componentType == File.class) {
                    ServletContext servletContext = getServletContext();
                    File file = new File(servletContext.getRealPath("upload"));
                    if (!file.exists())
                        file.mkdir();
                    MultipartRequest multi = new MultipartRequest(request, file.getAbsolutePath(),
                            1024 * 1024 * 1024, "UTF-8", new DefaultFileRenamePolicy());
                    Enumeration files = multi.getFileNames();
                    List<File> fileList = new ArrayList<File>();
                    if (files.hasMoreElements()) {
                        File f = multi.getFile((String) files.nextElement());
                        fileList.add(f);
                    }
                    field.set(newInstance, fileList.toArray(new File[] {}));
                }

            }
            // ? 
            validation(field, name, value);
            if (null == value) {
                continue;
            }
            if (type == Long.class) {
                field.set(newInstance, Long.parseLong(value));
            } else if (type == String.class) {
                field.set(newInstance, value);
            } else if (type == Byte.class) {
                field.set(newInstance, Byte.parseByte(value));
            } else if (type == Integer.class) {
                field.set(newInstance, Integer.parseInt(value));
            } else if (type == Character.class) {
                field.set(newInstance, value.charAt(0));
            } else if (type == Boolean.class) {
                field.set(newInstance, Boolean.parseBoolean(value));
            } else if (type == Double.class) {
                field.set(newInstance, Double.parseDouble(value));
            } else if (type == Float.class) {
                field.set(newInstance, Float.parseFloat(value));
            } else if (type == Date.class) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                field.set(newInstance, sdf.parse(value));
            } else { // 
                Object obj = pbRecurrence(field.getType(), name);// 
                field.set(newInstance, obj);
            }
        }
        return newInstance;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:op.controlling.PnlQMSSchedule.java

public void save() throws NumberFormatException {

    qmssched.setDaily(/* ww w.  j  a  v a  2s .c o m*/
            tabWdh.getSelectedIndex() == TAB_DAILY ? Byte.parseByte(spinTaeglich.getValue().toString()) : 0);
    qmssched.setWeekly(
            tabWdh.getSelectedIndex() == TAB_WEEKLY ? Byte.parseByte(spinWoche.getValue().toString()) : 0);
    qmssched.setMonthly(
            tabWdh.getSelectedIndex() == TAB_MONTHLY ? Byte.parseByte(spinMonat.getValue().toString()) : 0);
    qmssched.setYearly(
            tabWdh.getSelectedIndex() == TAB_YEARLY ? Byte.parseByte(spinYearly.getValue().toString()) : 0);
    qmssched.setStartingOn(jdcStartingOn.getDate());

    if (tabWdh.getSelectedIndex() == TAB_DAILY) {
        qmssched.setWeekday(0);
    }

    if (tabWdh.getSelectedIndex() == TAB_MONTHLY) {
        qmssched.setDayinmonth(Integer.parseInt(spinDayInMonth.getValue().toString()));
        qmssched.setWeekday(cmbTag.getSelectedIndex());
    }

    if (tabWdh.getSelectedIndex() == TAB_YEARLY) {
        qmssched.setDayinmonth(Integer.parseInt(spinDayInMonthInYear.getValue().toString()));
        qmssched.setMonthinyear(cmbMonth.getSelectedIndex() + 1);
    }

    qmssched.setMeasure(SYSTools.tidy(txtQMS.getText()));
    qmssched.setText(SYSTools.tidy(txtBemerkung.getText()));

    qmssched.setDuedays(Integer.parseInt(txtDueDays.getText()));

    if (cmbLocation.getSelectedItem() == null) {
        qmssched.setHome(null);
        qmssched.setStation(null);
    } else if (cmbLocation.getSelectedItem() instanceof TreePath) {
        TreePath treePath = (TreePath) cmbLocation.getSelectedItem();
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent();
        if (node.getUserObject() instanceof Station) {
            qmssched.setStation((Station) node.getUserObject());
            qmssched.setHome(null);
        } else if (node.getUserObject() instanceof Homes) {
            qmssched.setHome((Homes) node.getUserObject());
            qmssched.setStation(null);
        } else {
            qmssched.setHome(null);
            qmssched.setStation(null);
        }
    } else {
        qmssched.setHome(null);
        qmssched.setStation(null);
    }

    qmssched.getQmsList().clear();
    QmsTools.generate(qmssched, 2);

}

From source file:org.breizhbeans.thrift.tools.thriftmongobridge.protocol.TBSONUnstackedProtocol.java

private Object getCurrentFieldValue(byte ttype) throws TException {
    ThriftIO thriftIO = peekIOStack();//  ww  w  . ja va 2 s .com

    Object fieldReaded = null;
    if (thriftIO.list) {
        fieldReaded = ((BasicDBList) thriftIO.mongoIO).get(thriftIO.containerIndex);
        thriftIO.containerIndex++;
    } else if (thriftIO.map && thriftIO.mapEntry == null) {
        // a first read for the key
        thriftIO.mapEntry = thriftIO.mapIterator.next();

        // IF YOU READ A KEY YOU MUST CONVERT THE STRING INTO NUMBER
        switch (ttype) {
        case TType.BYTE:
            fieldReaded = Byte.parseByte(thriftIO.mapEntry.getKey());
            break;
        case TType.I32:
        case TType.I16:
            fieldReaded = Integer.parseInt(thriftIO.mapEntry.getKey());
            break;
        case TType.I64:
            fieldReaded = Long.parseLong(thriftIO.mapEntry.getKey());
            break;
        case TType.DOUBLE:
            fieldReaded = Double.parseDouble(thriftIO.mapEntry.getKey());
            break;
        default:
            fieldReaded = thriftIO.mapEntry.getKey();
        }
    } else if (thriftIO.map && thriftIO.mapEntry != null) {
        // a second read for the value
        fieldReaded = thriftIO.mapEntry.getValue();

        // a secured map have a thriftIO.securedMongoIO not null
        if (thriftIO.securedMongoIO != null) {
            byte[] data = TBSONUnstackedProtocol.tbsonSecuredWrapper.decipherValue((String) fieldReaded);
            fieldReaded = "";
            if (data != null) {
                fieldReaded = new String(data);
            }
        }
        thriftIO.mapEntry = null;
    } else {
        // normal field read
        ThriftFieldMetadata fieldMetadata = thriftIO.fieldsStack.peek();
        if (fieldMetadata.securedFieldMetaData.isSecured()) {
            byte[] data = TBSONUnstackedProtocol.tbsonSecuredWrapper.decipherSecuredField(
                    fieldMetadata.tfield.id, (DBObject) thriftIO.mongoIO.get("securedwrap"));
            if (data != null) {
                fieldReaded = new String(data);
            }
        } else {
            fieldReaded = thriftIO.mongoIO.get(fieldMetadata.tfield.name);
        }

    }
    return fieldReaded;
}

From source file:org.apache.axis2.databinding.utils.ConverterUtil.java

/**
 * @param baseArrayClass//from  w  w w  .  ja  v a 2  s  .com
 * @param objectList     -> for primitive type array conversion we assume the content to be
 *                       strings!
 * @return Returns Object.
 */
public static Object convertToArray(Class baseArrayClass, List objectList) {
    int listSize = objectList.size();
    Object returnArray = null;
    if (int.class.equals(baseArrayClass)) {
        int[] array = new int[listSize];
        for (int i = 0; i < listSize; i++) {
            Object o = objectList.get(i);
            if (o != null) {
                array[i] = Integer.parseInt(o.toString());
            } else {
                array[i] = Integer.MIN_VALUE;
            }
        }
        returnArray = array;
    } else if (float.class.equals(baseArrayClass)) {
        float[] array = new float[listSize];
        for (int i = 0; i < listSize; i++) {
            Object o = objectList.get(i);
            if (o != null) {
                array[i] = Float.parseFloat(o.toString());
            } else {
                array[i] = Float.NaN;
            }
        }
        returnArray = array;
    } else if (short.class.equals(baseArrayClass)) {
        short[] array = new short[listSize];
        for (int i = 0; i < listSize; i++) {
            Object o = objectList.get(i);
            if (o != null) {
                array[i] = Short.parseShort(o.toString());
            } else {
                array[i] = Short.MIN_VALUE;
            }
        }
        returnArray = array;
    } else if (byte.class.equals(baseArrayClass)) {
        byte[] array = new byte[listSize];
        for (int i = 0; i < listSize; i++) {
            Object o = objectList.get(i);
            if (o != null) {
                array[i] = Byte.parseByte(o.toString());
            } else {
                array[i] = Byte.MIN_VALUE;
            }
        }
        returnArray = array;
    } else if (long.class.equals(baseArrayClass)) {
        long[] array = new long[listSize];
        for (int i = 0; i < listSize; i++) {
            Object o = objectList.get(i);
            if (o != null) {
                array[i] = Long.parseLong(o.toString());
            } else {
                array[i] = Long.MIN_VALUE;
            }
        }
        returnArray = array;
    } else if (boolean.class.equals(baseArrayClass)) {
        boolean[] array = new boolean[listSize];
        for (int i = 0; i < listSize; i++) {
            Object o = objectList.get(i);
            if (o != null) {
                array[i] = o.toString().equalsIgnoreCase("true");
            }
        }
        returnArray = array;
    } else if (char.class.equals(baseArrayClass)) {
        char[] array = new char[listSize];
        for (int i = 0; i < listSize; i++) {
            Object o = objectList.get(i);
            if (o != null) {
                array[i] = o.toString().toCharArray()[0];
            }
        }
        returnArray = array;
    } else if (double.class.equals(baseArrayClass)) {
        double[] array = new double[listSize];
        for (int i = 0; i < listSize; i++) {
            Object o = objectList.get(i);
            if (o != null) {
                array[i] = Double.parseDouble(o.toString());
            } else {
                array[i] = Double.NaN;
            }
        }
        returnArray = array;
    } else if (Calendar.class.equals(baseArrayClass)) {
        Calendar[] array = new Calendar[listSize];
        for (int i = 0; i < listSize; i++) {
            Object o = objectList.get(i);
            if (o != null) {
                if (o instanceof String) {
                    array[i] = ConverterUtil.convertToDateTime(o.toString());
                } else if (o instanceof Calendar) {
                    array[i] = (Calendar) o;
                }
            }
        }
        returnArray = array;
    } else if (Date.class.equals(baseArrayClass)) {
        Date[] array = new Date[listSize];
        for (int i = 0; i < listSize; i++) {
            Object o = objectList.get(i);
            if (o != null) {
                if (o instanceof String) {
                    array[i] = ConverterUtil.convertToDate(o.toString());
                } else if (o instanceof Date) {
                    array[i] = (Date) o;
                }
            }
        }
        returnArray = array;
    } else {
        returnArray = Array.newInstance(baseArrayClass, listSize);
        ConvertToArbitraryObjectArray(returnArray, baseArrayClass, objectList);
    }
    return returnArray;
}

From source file:org.opendaylight.controller.northbound.integrationtest.NorthboundIT.java

private void testFlowStat(JSONObject flowStat, String actionType, int actIndex) throws JSONException {
    Assert.assertTrue(flowStat.getInt("tableId") == 1);
    Assert.assertTrue(flowStat.getInt("durationSeconds") == 40);
    Assert.assertTrue(flowStat.getInt("durationNanoseconds") == 400);
    Assert.assertTrue(flowStat.getInt("packetCount") == 200);
    Assert.assertTrue(flowStat.getInt("byteCount") == 100);

    // test that flow information is correct
    JSONObject flow = flowStat.getJSONObject("flow");
    Assert.assertTrue(flow.getInt("priority") == (3500 + actIndex));
    Assert.assertTrue(flow.getInt("idleTimeout") == 1000);
    Assert.assertTrue(flow.getInt("hardTimeout") == 2000);
    Assert.assertTrue(flow.getInt("id") == 12345);

    JSONArray matches = (flow.getJSONObject("match").getJSONArray("matchField"));
    Assert.assertEquals(matches.length(), 1);
    JSONObject match = matches.getJSONObject(0);
    Assert.assertTrue(match.getString("type").equals("NW_DST"));
    Assert.assertTrue(match.getString("value").equals("1.1.1.1"));

    JSONArray actionsArray = flow.getJSONArray("actions");
    Assert.assertEquals(actionsArray.length(), 1);
    JSONObject act = actionsArray.getJSONObject(0);
    Assert.assertTrue(act.getString("type").equals(actionType));

    if (act.getString("type").equals("OUTPUT")) {
        JSONObject port = act.getJSONObject("port");
        JSONObject port_node = port.getJSONObject("node");
        Assert.assertTrue(port.getInt("id") == 51966);
        Assert.assertTrue(port.getString("type").equals("STUB"));
        Assert.assertTrue(port_node.getInt("id") == 51966);
        Assert.assertTrue(port_node.getString("type").equals("STUB"));
    }/*w  w  w  . j a  va  2  s .com*/

    if (act.getString("type").equals("SET_DL_SRC")) {
        byte srcMatch[] = { (byte) 5, (byte) 4, (byte) 3, (byte) 2, (byte) 1 };
        String src = act.getString("address");
        byte srcBytes[] = new byte[5];
        srcBytes[0] = Byte.parseByte(src.substring(0, 2));
        srcBytes[1] = Byte.parseByte(src.substring(2, 4));
        srcBytes[2] = Byte.parseByte(src.substring(4, 6));
        srcBytes[3] = Byte.parseByte(src.substring(6, 8));
        srcBytes[4] = Byte.parseByte(src.substring(8, 10));
        Assert.assertTrue(Arrays.equals(srcBytes, srcMatch));
    }

    if (act.getString("type").equals("SET_DL_DST")) {
        byte dstMatch[] = { (byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5 };
        String dst = act.getString("address");
        byte dstBytes[] = new byte[5];
        dstBytes[0] = Byte.parseByte(dst.substring(0, 2));
        dstBytes[1] = Byte.parseByte(dst.substring(2, 4));
        dstBytes[2] = Byte.parseByte(dst.substring(4, 6));
        dstBytes[3] = Byte.parseByte(dst.substring(6, 8));
        dstBytes[4] = Byte.parseByte(dst.substring(8, 10));
        Assert.assertTrue(Arrays.equals(dstBytes, dstMatch));
    }
    if (act.getString("type").equals("SET_DL_TYPE")) {
        Assert.assertTrue(act.getInt("dlType") == 10);
    }
    if (act.getString("type").equals("SET_VLAN_ID")) {
        Assert.assertTrue(act.getInt("vlanId") == 2);
    }
    if (act.getString("type").equals("SET_VLAN_PCP")) {
        Assert.assertTrue(act.getInt("pcp") == 3);
    }
    if (act.getString("type").equals("SET_VLAN_CFI")) {
        Assert.assertTrue(act.getInt("cfi") == 1);
    }

    if (act.getString("type").equals("SET_NW_SRC")) {
        Assert.assertTrue(act.getString("address").equals("2.2.2.2"));
    }
    if (act.getString("type").equals("SET_NW_DST")) {
        Assert.assertTrue(act.getString("address").equals("1.1.1.1"));
    }

    if (act.getString("type").equals("PUSH_VLAN")) {
        int head = act.getInt("VlanHeader");
        // parsing vlan header
        int id = head & 0xfff;
        int cfi = (head >> 12) & 0x1;
        int pcp = (head >> 13) & 0x7;
        int tag = (head >> 16) & 0xffff;
        Assert.assertTrue(id == 1234);
        Assert.assertTrue(cfi == 1);
        Assert.assertTrue(pcp == 1);
        Assert.assertTrue(tag == 0x8100);
    }
    if (act.getString("type").equals("SET_NW_TOS")) {
        Assert.assertTrue(act.getInt("tos") == 16);
    }
    if (act.getString("type").equals("SET_TP_SRC")) {
        Assert.assertTrue(act.getInt("port") == 4201);
    }
    if (act.getString("type").equals("SET_TP_DST")) {
        Assert.assertTrue(act.getInt("port") == 8080);
    }
}

From source file:org.ariose.util.SMPPSender.java

/**
 * Gets a property and converts it into byte.
 *///from www  .j a  va2  s  . c  o  m
private byte getByteProperty(String propName, byte defaultValue) {
    return Byte.parseByte(properties.getProperty(propName, Byte.toString(defaultValue)));
}

From source file:org.deeplearning4j.models.embeddings.loader.WordVectorSerializer.java

/**
 * This method allows you to read ParagraphVectors from externaly originated vectors and syn1.
 * So, technically this method is compatible with any other w2v implementation
 *
 * @param vectors   text file with words and their wieghts, aka Syn0
 * @param hs    text file HS layers, aka Syn1
 * @param h_codes   text file with Huffman tree codes
 * @param h_points  text file with Huffman tree points
 * @return//from   w  w  w .ja  v a2s . com
 */
public static Word2Vec readWord2VecFromText(@NonNull File vectors, @NonNull File hs, @NonNull File h_codes,
        @NonNull File h_points, @NonNull VectorsConfiguration configuration) throws IOException {
    // first we load syn0
    Pair<InMemoryLookupTable, VocabCache> pair = loadTxt(vectors);
    InMemoryLookupTable lookupTable = pair.getFirst();
    lookupTable.setNegative(configuration.getNegative());
    if (configuration.getNegative() > 0)
        lookupTable.initNegative();
    VocabCache<VocabWord> vocab = (VocabCache<VocabWord>) pair.getSecond();

    // now we load syn1
    BufferedReader reader = new BufferedReader(new FileReader(hs));
    String line = null;
    List<INDArray> rows = new ArrayList<>();
    while ((line = reader.readLine()) != null) {
        String[] split = line.split(" ");
        double array[] = new double[split.length];
        for (int i = 0; i < split.length; i++) {
            array[i] = Double.parseDouble(split[i]);
        }
        rows.add(Nd4j.create(array));
    }
    reader.close();

    // it's possible to have full model without syn1
    if (rows.size() > 0) {
        INDArray syn1 = Nd4j.vstack(rows);
        lookupTable.setSyn1(syn1);
    }

    // now we transform mappings into huffman tree points
    reader = new BufferedReader(new FileReader(h_points));
    while ((line = reader.readLine()) != null) {
        String[] split = line.split(" ");
        VocabWord word = vocab.wordFor(decodeB64(split[0]));
        List<Integer> points = new ArrayList<>();
        for (int i = 1; i < split.length; i++) {
            points.add(Integer.parseInt(split[i]));
        }
        word.setPoints(points);
    }
    reader.close();

    // now we transform mappings into huffman tree codes
    reader = new BufferedReader(new FileReader(h_codes));
    while ((line = reader.readLine()) != null) {
        String[] split = line.split(" ");
        VocabWord word = vocab.wordFor(decodeB64(split[0]));
        List<Byte> codes = new ArrayList<>();
        for (int i = 1; i < split.length; i++) {
            codes.add(Byte.parseByte(split[i]));
        }
        word.setCodes(codes);
        word.setCodeLength((short) codes.size());
    }
    reader.close();

    Word2Vec.Builder builder = new Word2Vec.Builder(configuration).vocabCache(vocab).lookupTable(lookupTable)
            .resetModel(false);

    TokenizerFactory factory = getTokenizerFactory(configuration);

    if (factory != null)
        builder.tokenizerFactory(factory);

    Word2Vec w2v = builder.build();

    return w2v;
}

From source file:com.hzc.framework.ssh.controller.WebUtil.java

public static Byte getByte(String... key) throws RuntimeException {
    try {/*from w  ww  .j a  v a  2  s .  c o m*/
        try {
            HttpServletRequest req = WebUtil.getReq();
            String attachId = req.getParameter(key[0]);
            return Byte.parseByte(attachId);
        } catch (Exception e) {
            if (key.length == 2)
                throw new ValidationException(key[1]);
            throw new ValidationException(e);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.axis2.databinding.utils.ConverterUtil.java

/**
 * @param byteVlaue//ww w  . j  a v a2s . com
 * @param value
 * @return 0 if equal , + value if greater than , - value if less than
 */
public static int compare(byte byteVlaue, String value) {
    return byteVlaue - Byte.parseByte(value);
}