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:org.apache.uima.ruta.ontologies.MarkTableAction2.java

private void fillFeatures(TOP structure, Map<String, Integer> map, AnnotationFS annotationFS,
        RuleElement element, List<String> row, RutaStream stream) {
    List<?> featuresList = structure.getType().getFeatures();
    for (int i = 0; i < featuresList.size(); i++) {
        Feature targetFeature = (Feature) featuresList.get(i);
        String name = targetFeature.getName();
        String shortFName = name.substring(name.indexOf(":") + 1, name.length());
        Integer entryIndex = map.get(shortFName);
        Type range = targetFeature.getRange();
        if (entryIndex != null && row.size() >= entryIndex) {
            String value = row.get(entryIndex - 1);
            if (range.getName().equals(CAS.TYPE_NAME_STRING)) {
                structure.setStringValue(targetFeature, value);
            } else if (range.getName().equals(CAS.TYPE_NAME_INTEGER)) {
                Integer integer = Integer.parseInt(value);
                structure.setIntValue(targetFeature, integer);
            } else if (range.getName().equals(CAS.TYPE_NAME_DOUBLE)) {
                Double d = Double.parseDouble(value);
                structure.setDoubleValue(targetFeature, d);
            } else if (range.getName().equals(CAS.TYPE_NAME_FLOAT)) {
                Float d = Float.parseFloat(value);
                structure.setFloatValue(targetFeature, d);
            } else if (range.getName().equals(CAS.TYPE_NAME_BYTE)) {
                Byte d = Byte.parseByte(value);
                structure.setByteValue(targetFeature, d);
            } else if (range.getName().equals(CAS.TYPE_NAME_SHORT)) {
                Short d = Short.parseShort(value);
                structure.setShortValue(targetFeature, d);
            } else if (range.getName().equals(CAS.TYPE_NAME_LONG)) {
                Long d = Long.parseLong(value);
                structure.setLongValue(targetFeature, d);
            } else if (range.getName().equals(CAS.TYPE_NAME_BOOLEAN)) {
                Boolean b = Boolean.parseBoolean(value);
                structure.setBooleanValue(targetFeature, b);
            } else {
            }/* w  w w  . ja v a  2 s .co  m*/
        }

    }
}

From source file:com.aoindustries.website.clientarea.accounting.EditCreditCardCompletedAction.java

@Override
public ActionForward executePermissionGranted(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response, SiteSettings siteSettings, Locale locale,
        Skin skin, AOServConnector aoConn) throws Exception {
    EditCreditCardForm editCreditCardForm = (EditCreditCardForm) form;

    String persistenceId = editCreditCardForm.getPersistenceId();
    if (GenericValidator.isBlankOrNull(persistenceId)) {
        // Redirect back to credit-card-manager if no persistenceId selected
        return mapping.findForward("credit-card-manager");
    }/*from w  w  w  .jav a2s  .c o m*/
    int pkey;
    try {
        pkey = Integer.parseInt(persistenceId);
    } catch (NumberFormatException err) {
        getServlet().log(null, err);
        // Redirect back to credit-card-manager if persistenceId can't be parsed to int
        return mapping.findForward("credit-card-manager");
    }
    // Find the credit card
    CreditCard creditCard = aoConn.getCreditCards().get(pkey);
    if (creditCard == null) {
        // Redirect back to credit-card-manager if card no longer exists or is inaccessible
        return mapping.findForward("credit-card-manager");
    }

    // Validation
    ActionMessages errors = editCreditCardForm.validate(mapping, request);
    if (errors != null && !errors.isEmpty()) {
        saveErrors(request, errors);
        // Init request values before showing input
        initRequestAttributes(request, getServlet().getServletContext());
        request.setAttribute("creditCard", creditCard);
        return mapping.findForward("input");
    }

    // Tells the view layer what was updated
    boolean updatedCardDetails = false;
    boolean updatedCardNumber = false;
    boolean updatedExpirationDate = false;
    boolean reactivatedCard = false;

    if (!nullOrBlankEquals(editCreditCardForm.getFirstName(), creditCard.getFirstName())
            || !nullOrBlankEquals(editCreditCardForm.getLastName(), creditCard.getLastName())
            || !nullOrBlankEquals(editCreditCardForm.getCompanyName(), creditCard.getCompanyName())
            || !nullOrBlankEquals(editCreditCardForm.getStreetAddress1(), creditCard.getStreetAddress1())
            || !nullOrBlankEquals(editCreditCardForm.getStreetAddress2(), creditCard.getStreetAddress2())
            || !nullOrBlankEquals(editCreditCardForm.getCity(), creditCard.getCity())
            || !nullOrBlankEquals(editCreditCardForm.getState(), creditCard.getState())
            || !nullOrBlankEquals(editCreditCardForm.getPostalCode(), creditCard.getPostalCode())
            || !nullOrBlankEquals(editCreditCardForm.getCountryCode(), creditCard.getCountryCode().getCode())
            || !nullOrBlankEquals(editCreditCardForm.getDescription(), creditCard.getDescription())) {
        // Update all fields except card number and expiration
        // Root connector used to get processor
        AOServConnector rootConn = siteSettings.getRootAOServConnector();
        CreditCard rootCreditCard = rootConn.getCreditCards().get(creditCard.getPkey());
        if (rootCreditCard == null)
            throw new SQLException("Unable to find CreditCard: " + creditCard.getPkey());
        CreditCardProcessor rootProcessor = CreditCardProcessorFactory
                .getCreditCardProcessor(rootCreditCard.getCreditCardProcessor());
        com.aoindustries.creditcards.CreditCard storedCreditCard = CreditCardFactory
                .getCreditCard(rootCreditCard);
        // Update fields
        storedCreditCard.setFirstName(editCreditCardForm.getFirstName());
        storedCreditCard.setLastName(editCreditCardForm.getLastName());
        storedCreditCard.setCompanyName(editCreditCardForm.getCompanyName());
        storedCreditCard.setStreetAddress1(editCreditCardForm.getStreetAddress1());
        storedCreditCard.setStreetAddress2(editCreditCardForm.getStreetAddress2());
        storedCreditCard.setCity(editCreditCardForm.getCity());
        storedCreditCard.setState(editCreditCardForm.getState());
        storedCreditCard.setPostalCode(editCreditCardForm.getPostalCode());
        storedCreditCard.setCountryCode(editCreditCardForm.getCountryCode());
        storedCreditCard.setComments(editCreditCardForm.getDescription());
        // Update persistence
        rootProcessor.updateCreditCard(
                new AOServConnectorPrincipal(rootConn,
                        aoConn.getThisBusinessAdministrator().getUsername().getUsername().toString()),
                storedCreditCard);
        updatedCardDetails = true;
    }

    String newCardNumber = editCreditCardForm.getCardNumber();
    String newExpirationMonth = editCreditCardForm.getExpirationMonth();
    String newExpirationYear = editCreditCardForm.getExpirationYear();
    String newCardCode = editCreditCardForm.getCardCode();
    if (!GenericValidator.isBlankOrNull(newCardNumber)) {
        // Update card number and expiration
        // Root connector used to get processor
        AOServConnector rootConn = siteSettings.getRootAOServConnector();
        CreditCard rootCreditCard = rootConn.getCreditCards().get(creditCard.getPkey());
        if (rootCreditCard == null)
            throw new SQLException("Unable to find CreditCard: " + creditCard.getPkey());
        CreditCardProcessor rootProcessor = CreditCardProcessorFactory
                .getCreditCardProcessor(rootCreditCard.getCreditCardProcessor());
        rootProcessor.updateCreditCardNumberAndExpiration(
                new AOServConnectorPrincipal(rootConn,
                        aoConn.getThisBusinessAdministrator().getUsername().getUsername().toString()),
                CreditCardFactory.getCreditCard(rootCreditCard), newCardNumber,
                Byte.parseByte(newExpirationMonth), Short.parseShort(newExpirationYear), newCardCode);
        updatedCardNumber = true;
        updatedExpirationDate = true;
    } else {
        if (!GenericValidator.isBlankOrNull(newExpirationMonth)
                && !GenericValidator.isBlankOrNull(newExpirationYear)) {
            // Update expiration only
            // Root connector used to get processor
            AOServConnector rootConn = siteSettings.getRootAOServConnector();
            CreditCard rootCreditCard = rootConn.getCreditCards().get(creditCard.getPkey());
            if (rootCreditCard == null)
                throw new SQLException("Unable to find CreditCard: " + creditCard.getPkey());
            CreditCardProcessor rootProcessor = CreditCardProcessorFactory
                    .getCreditCardProcessor(rootCreditCard.getCreditCardProcessor());
            rootProcessor
                    .updateCreditCardExpiration(
                            new AOServConnectorPrincipal(rootConn,
                                    aoConn.getThisBusinessAdministrator().getUsername().getUsername()
                                            .toString()),
                            CreditCardFactory.getCreditCard(rootCreditCard), Byte.parseByte(newExpirationMonth),
                            Short.parseShort(newExpirationYear));
            updatedExpirationDate = true;
        }
    }

    if (!creditCard.getIsActive()) {
        // Reactivate if not active
        creditCard.reactivate();
        reactivatedCard = true;
    }

    // Set the cardNumber request attribute
    String cardNumber;
    if (!GenericValidator.isBlankOrNull(editCreditCardForm.getCardNumber()))
        cardNumber = com.aoindustries.creditcards.CreditCard
                .maskCreditCardNumber(editCreditCardForm.getCardNumber());
    else
        cardNumber = creditCard.getCardInfo();
    request.setAttribute("cardNumber", cardNumber);

    // Store which steps were done
    request.setAttribute("updatedCardDetails", updatedCardDetails ? "true" : "false");
    request.setAttribute("updatedCardNumber", updatedCardNumber ? "true" : "false");
    request.setAttribute("updatedExpirationDate", updatedExpirationDate ? "true" : "false");
    request.setAttribute("reactivatedCard", reactivatedCard ? "true" : "false");

    return mapping.findForward("success");
}

From source file:com.sms.server.service.parser.MetadataParser.java

public MediaElement parse(MediaElement mediaElement) {

    try {//from   w w  w .  j av  a 2  s .c  o  m
        // Use transcoder to parse file metadata
        File parser = transcodeService.getTranscoder();

        String[] command = new String[] { parser.getAbsolutePath(), "-i", mediaElement.getPath() };
        ProcessBuilder processBuilder = new ProcessBuilder(command).redirectErrorStream(true);
        Process process = processBuilder.start();

        String[] metadata = readInputStream(process.getInputStream());

        // Get Media Type
        Byte mediaType = mediaElement.getType();

        // Begin Parsing
        for (String line : metadata) {
            Matcher matcher;

            if (mediaType == MediaElementType.AUDIO || mediaType == MediaElementType.VIDEO) {
                //
                // Duration
                //
                matcher = DURATION.matcher(line);

                if (matcher.find()) {
                    int hours = Integer.parseInt(matcher.group(1));
                    int minutes = Integer.parseInt(matcher.group(2));
                    int seconds = Integer.parseInt(matcher.group(3));
                    mediaElement.setDuration(hours * 3600 + minutes * 60 + seconds);
                }

                //
                // Bitrate
                //
                matcher = BITRATE.matcher(line);

                if (matcher.find()) {
                    mediaElement.setBitrate(Integer.parseInt(matcher.group(1)));
                }

                //
                // Audio Stream
                //
                matcher = AUDIO_STREAM.matcher(line);

                if (matcher.find()) {
                    // Language

                    // Always set audio language for video elements
                    if (matcher.group(1) == null && mediaType == MediaElementType.VIDEO) {
                        mediaElement.setAudioLanguage(
                                addToCommaSeparatedList(mediaElement.getAudioLanguage(), "und"));
                    }

                    // Set audio language if present
                    if (matcher.group(1) != null) {
                        mediaElement.setAudioLanguage(addToCommaSeparatedList(mediaElement.getAudioLanguage(),
                                String.valueOf(matcher.group(2))));
                    }

                    // Codec
                    mediaElement.setAudioCodec(addToCommaSeparatedList(mediaElement.getAudioCodec(),
                            String.valueOf(matcher.group(3))));

                    //Sample Rate
                    mediaElement.setAudioSampleRate(addToCommaSeparatedList(mediaElement.getAudioSampleRate(),
                            String.valueOf(matcher.group(4))));

                    //Configuration
                    mediaElement.setAudioConfiguration(addToCommaSeparatedList(
                            mediaElement.getAudioConfiguration(), String.valueOf(matcher.group(5))));
                }
            }

            if (mediaType == MediaElementType.AUDIO) {
                //
                // Title
                //
                matcher = TITLE.matcher(line);

                if (matcher.find()) {
                    mediaElement.setTitle(String.valueOf(matcher.group(1)));
                }

                //
                // Artist
                //
                matcher = ARTIST.matcher(line);

                if (matcher.find()) {
                    mediaElement.setArtist(String.valueOf(matcher.group(2)));
                }

                //
                // Album Artist
                //
                matcher = ALBUMARTIST.matcher(line);

                if (matcher.find()) {
                    mediaElement.setAlbumArtist(String.valueOf(matcher.group(2)));
                }

                //
                // Album
                //
                matcher = ALBUM.matcher(line);

                if (matcher.find()) {
                    mediaElement.setAlbum(String.valueOf(matcher.group(1)));
                }

                //
                // Comment
                //
                matcher = COMMENT.matcher(line);

                if (matcher.find()) {
                    mediaElement.setDescription(String.valueOf(matcher.group(1)));
                }

                //
                // Date
                //
                matcher = YEAR.matcher(line);

                if (matcher.find()) {
                    mediaElement.setYear(Short.parseShort(matcher.group(2)));
                }

                //
                // Disc Number
                //
                matcher = DISCNUMBER.matcher(line);

                if (matcher.find()) {
                    mediaElement.setDiscNumber(Byte.parseByte(matcher.group(2)));
                }

                //
                // Disc Subtitle
                //

                matcher = DISCSUBTITLE.matcher(line);

                if (matcher.find()) {
                    mediaElement.setDiscSubtitle(String.valueOf(matcher.group(1)));
                }

                //
                // Track Number
                //
                matcher = TRACK.matcher(line);

                if (matcher.find()) {
                    mediaElement.setTrackNumber(Short.parseShort(matcher.group(1)));
                }

                //
                // Genre
                //
                matcher = GENRE.matcher(line);

                if (matcher.find()) {
                    mediaElement.setGenre(String.valueOf(matcher.group(1)));
                }
            }

            if (mediaType == MediaElementType.VIDEO) {
                //
                // Video Stream
                //
                matcher = VIDEO_STREAM.matcher(line);

                // Only pull metadata for the first video stream (embedded images are also detected as video...)
                if (matcher.find() && mediaElement.getVideoCodec() == null) {
                    // Codec
                    mediaElement.setVideoCodec(String.valueOf(matcher.group(1)));

                    // Dimensions
                    short width = Short.parseShort(matcher.group(2));
                    short height = Short.parseShort(matcher.group(3));

                    if (width > 0 && height > 0) {
                        mediaElement.setVideoWidth(width);
                        mediaElement.setVideoHeight(height);
                    }
                }

                //
                // Subtitle Stream
                //
                matcher = SUBTITLE_STREAM.matcher(line);

                if (matcher.find()) {
                    // Language
                    if (matcher.group(1) == null) {
                        mediaElement.setSubtitleLanguage(
                                addToCommaSeparatedList(mediaElement.getSubtitleLanguage(), "und"));
                    } else {
                        mediaElement.setSubtitleLanguage(addToCommaSeparatedList(
                                mediaElement.getSubtitleLanguage(), String.valueOf(matcher.group(2))));
                    }

                    // Format
                    mediaElement.setSubtitleFormat(addToCommaSeparatedList(mediaElement.getSubtitleFormat(),
                            String.valueOf(matcher.group(3))));

                    //Forced
                    if (matcher.group(4) == null) {
                        mediaElement.setSubtitleForced(
                                addToCommaSeparatedList(mediaElement.getSubtitleForced(), "false"));
                    } else {
                        mediaElement.setSubtitleForced(
                                addToCommaSeparatedList(mediaElement.getSubtitleForced(), "true"));
                    }
                }
            }
        }
    } catch (IOException x) {
        LogService.getInstance().addLogEntry(LogService.Level.ERROR, CLASS_NAME,
                "Unable to parse metadata for file " + mediaElement.getPath(), x);
    }

    return mediaElement;
}

From source file:com.adf.bean.AbsBean.java

/**
 * IMPORT//from  www .  j  a va2  s  .c o m
 * */
public void setValueByColumn(String col, String val) throws IllegalArgumentException {
    try {
        Field f = getClass().getDeclaredField(col);
        Class<?> cls = f.getType();
        f.setAccessible(true);
        if (cls.isArray()) {
            JSONArray arr;
            try {
                arr = new JSONArray(val);
                setArrayColumn(col, arr);
            } catch (JSONException e) {
            }
            return;
        }
        if ((int.class == cls) || (Integer.class == cls)) {
            int ival = Integer.parseInt(val);
            f.set(this, ival);
        } else if ((long.class == cls) || (Long.class == cls)) {
            long lval = Long.parseLong(val);
            f.set(this, lval);
        } else if ((float.class == cls) || (Float.class == cls)) {
            float fval = Float.parseFloat(val);
            f.set(this, fval);
        } else if ((short.class == cls) || (Short.class == cls)) {
            short sval = Short.parseShort(val);
            f.set(this, sval);
        } else if ((double.class == cls) || (Double.class == cls)) {
            double dval = Double.parseDouble(val);
            f.set(this, dval);
        } else if ((byte.class == cls) || (Byte.class == cls)) {
            byte bval = Byte.parseByte(val);
            f.set(this, bval);
        } else if ((boolean.class == cls) || (Boolean.class == cls)) {
            boolean bval = Boolean.parseBoolean(val);
            f.set(this, bval);
        } else if (char.class == cls) {
            char cval = val.charAt(0);
            f.set(this, cval);
        } else {
            Constructor<?> cons = cls.getDeclaredConstructor(String.class);
            cons.setAccessible(true);
            Object obj = cons.newInstance(val);
            f.set(this, obj);
        }
    } catch (NoSuchFieldException e) {
        LogUtil.err("setValueByColumn NoSuchFieldException, col " + col + " not exist!!!");
    } catch (IllegalAccessException e) {
        LogUtil.err("setValueByColumn IllegalAccessException, col " + col + " :" + e.getMessage());
        //throw e;
    } catch (IllegalArgumentException e) {
        LogUtil.err("setValueByColumn IllegalArgumentException, col " + col + " :" + e.getMessage());
        //throw e;
    } catch (NoSuchMethodException e) {
        LogUtil.err("setValueByColumn NoSuchMethodException, col " + col + " :" + e.getMessage());
        //throw e;
    } catch (InstantiationException e) {
        LogUtil.err("setValueByColumn InstantiationException, col " + col + " :" + e.getMessage());
        //throw e;
    } catch (InvocationTargetException e) {
        LogUtil.err("setValueByColumn InvocationTargetException, col " + col + " :" + e.getMessage());
        //throw e;
    }
}

From source file:com.gae.JsonBeans.java

public Entity setentity(String mod, Key ekey, String kind, String key, String[] id, String[] val) {
    try {/*  w w w . j  a  v  a 2  s  .  c om*/
        String prop[][] = getprop(id);
        Entity entity = new Entity(ekey);
        for (int i = 0; i < id.length; i++) {
            if (prop[i][0].equals("st")) {
                if (val[i].indexOf(",") == -1) { // Not List property
                    entity.setProperty(prop[i][1], val[i]);
                } else { // List property
                    entity.setProperty(prop[i][1], Arrays.asList(val[i].split(",")));
                }
            } else if (prop[i][0].equals("te")) { //long text
                Text val1 = new Text(val[i].trim());
                entity.setProperty(prop[i][1], val1);
            } else if (prop[i][0].equals("by")) { //byte
                byte val1;
                if (val[i].indexOf(",") == -1) { //Not List property
                    //Byte val1 = Byte.parseByte(val[i].trim());
                    if (val[i].trim().equals("na") || val[i].trim().equals("")) {
                        val1 = 0;
                    } else {
                        val1 = Byte.parseByte(val[i].trim());
                    }
                    entity.setProperty(prop[i][1], val1);
                } else { //List property
                    ArrayList<Byte> dlist = new ArrayList<Byte>();
                    String[] val2 = val[i].split(",");
                    for (int j = 0; j < val2.length; j++) {
                        dlist.add(Byte.parseByte(val2[j].trim()));
                    }
                    entity.setProperty(prop[i][1], dlist);
                }
            } else if (prop[i][0].equals("sh")) { //short
                short val1;
                if (val[i].indexOf(",") == -1) { //Not List property
                    //Short val1 = Short.parseShort(val[i].trim());
                    if (val[i].trim().equals("na") || val[i].trim().equals("")) {
                        val1 = 0;
                    } else {
                        val1 = Short.parseShort(val[i].trim());
                    }
                    entity.setProperty(prop[i][1], val1);
                } else { //List property
                    ArrayList<Short> dlist = new ArrayList<Short>();
                    String[] val2 = val[i].split(",");
                    for (int j = 0; j < val2.length; j++) {
                        dlist.add(Short.parseShort(val2[j].trim()));
                    }
                    entity.setProperty(prop[i][1], dlist);
                }
            } else if (prop[i][0].equals("in")) { //integer
                int val1;
                if (val[i].indexOf(",") == -1) { //Not List property
                    if (val[i].trim().equals("na") || val[i].trim().equals("")) {
                        val1 = 0;
                    } else {
                        val1 = Integer.parseInt(val[i].trim());
                    }
                    entity.setProperty(prop[i][1], val1);
                } else { //List property
                    ArrayList<Integer> dlist = new ArrayList<Integer>();
                    String[] val2 = val[i].split(",");
                    for (int j = 0; j < val2.length; j++) {
                        dlist.add(Integer.parseInt(val2[j].trim()));
                    }
                    entity.setProperty(prop[i][1], dlist);
                }
            } else if (prop[i][0].equals("lo")) { //long
                long val1;
                if (val[i].indexOf(",") == -1) { //Not List property
                    //long val1 = Long.parseLong(val[i].trim());
                    if (val[i].trim().equals("na") || val[i].trim().equals("")) {
                        val1 = 0;
                    } else {
                        val1 = Long.parseLong(val[i].trim());
                    }
                    entity.setProperty(prop[i][1], val1);
                } else { //List property
                    ArrayList<Long> dlist = new ArrayList<Long>();
                    String[] val2 = val[i].split(",");
                    for (int j = 0; j < val2.length; j++) {
                        dlist.add(Long.parseLong(val2[j].trim()));
                    }
                    entity.setProperty(prop[i][1], dlist);
                }
            } else if (prop[i][0].equals("fl")) { //float
                float val1;
                if (val[i].indexOf(",") == -1) { //Not List property
                    //float val1 = Float.parseFloat(val[i].trim());
                    if (val[i].trim().equals("na") || val[i].trim().equals("")) {
                        val1 = 0;
                    } else {
                        val1 = Float.parseFloat(val[i].trim());
                    }
                    entity.setProperty(prop[i][1], val1);
                } else { //List property
                    ArrayList<Float> dlist = new ArrayList<Float>();
                    String[] val2 = val[i].split(",");
                    for (int j = 0; j < val2.length; j++) {
                        dlist.add(Float.parseFloat(val2[j].trim()));
                    }
                    entity.setProperty(prop[i][1], dlist);
                }
            } else if (prop[i][0].equals("do")) { //double
                double val1;
                if (val[i].indexOf(",") == -1) { //Not List property
                    //double val1 = Double.parseDouble(val[i].trim());
                    if (val[i].trim().equals("na") || val[i].trim().equals("")) {
                        val1 = 0;
                    } else {
                        val1 = Double.parseDouble(val[i].trim());
                    }
                    entity.setProperty(prop[i][1], val1);
                } else { //List property
                    ArrayList<Double> dlist = new ArrayList<Double>();
                    String[] val2 = val[i].split(",");
                    for (int j = 0; j < val2.length; j++) {
                        dlist.add(Double.parseDouble(val2[j].trim()));
                    }
                    entity.setProperty(prop[i][1], dlist);
                }
            } else if (prop[i][0].equals("bo")) { //boolean
                if (val[i].indexOf(",") == -1) { //Not List property
                    boolean val1 = Boolean.valueOf(val[i].trim()).booleanValue();
                    entity.setProperty(prop[i][1], val1);
                } else { //List Property
                    ArrayList<Boolean> dlist = new ArrayList<Boolean>();
                    String[] val2 = val[i].split(",");
                    for (int j = 0; j < val2.length; j++) {
                        dlist.add(Boolean.parseBoolean(val2[j].trim()));
                    }
                    entity.setProperty(prop[i][1], dlist);
                }
            }

        }
        return entity;
    } catch (Exception e2) {
        if (mod.equals("add")) {
            //return("?? := " + e2);
            //Entity entity_err = new Entity("?? := " + e2);
            Entity entity_err = new Entity("");
            return entity_err;
        } else {
            //return("?? := " + e2);
            //Entity entity_err = new Entity("?? := " + e2);
            Entity entity_err = new Entity("");
            return entity_err;
        }
    }
}

From source file:io.horizondb.model.core.fields.DecimalField.java

/**
 * {@inheritDoc}/*w  w  w.  j  a  v  a 2  s  .  c o  m*/
 */
@Override
public Field setValueFromString(TimeZone timeZone, String s) {

    int exponentIndex = s.indexOf('E');

    if (!s.contains(".") && exponentIndex >= 0) {

        this.mantissa = Long.parseLong(s.substring(0, exponentIndex));
        this.exponent = Byte.parseByte(s.substring(exponentIndex + 1));
    }

    return setDouble(Double.parseDouble(s));
}

From source file:org.apache.nifi.grok.GrokRecordReader.java

protected Object convert(final DataType fieldType, final String string) {
    if (fieldType == null) {
        return string;
    }//  w ww .  j  a  v  a2 s. com

    if (string == null) {
        return null;
    }

    // If string is empty then return an empty string if field type is STRING. If field type is
    // anything else, we can't really convert it so return null
    if (string.isEmpty() && fieldType.getFieldType() != RecordFieldType.STRING) {
        return null;
    }

    switch (fieldType.getFieldType()) {
    case BOOLEAN:
        return Boolean.parseBoolean(string);
    case BYTE:
        return Byte.parseByte(string);
    case SHORT:
        return Short.parseShort(string);
    case INT:
        return Integer.parseInt(string);
    case LONG:
        return Long.parseLong(string);
    case FLOAT:
        return Float.parseFloat(string);
    case DOUBLE:
        return Double.parseDouble(string);
    case DATE:
        try {
            Date date = TIME_FORMAT_DATE.parse(string);
            return new java.sql.Date(date.getTime());
        } catch (ParseException e) {
            return null;
        }
    case TIME:
        try {
            Date date = TIME_FORMAT_TIME.parse(string);
            return new java.sql.Time(date.getTime());
        } catch (ParseException e) {
            return null;
        }
    case TIMESTAMP:
        try {
            Date date = TIME_FORMAT_TIMESTAMP.parse(string);
            return new java.sql.Timestamp(date.getTime());
        } catch (ParseException e) {
            return null;
        }
    case STRING:
    default:
        return string;
    }
}

From source file:de.themoep.simpleteampvp.TeamInfo.java

public boolean setBlock(String blockStr) {
    if (blockStr.indexOf(':') > -1 && blockStr.length() > blockStr.indexOf(':') + 1) {
        String matStr = blockStr.toUpperCase().substring(0, blockStr.indexOf(':'));
        try {/*w w w . j  a va2 s.  c om*/
            blockMaterial = Material.valueOf(matStr);
        } catch (IllegalArgumentException e) {
            Bukkit.getLogger().log(Level.WARNING,
                    "[SimpleTeamPvP] " + matStr + " is not a valid block material name!");
            return false;
        }
        String dataStr = blockStr.substring(blockStr.indexOf(':') + 1);
        try {
            blockData = Byte.parseByte(dataStr);
        } catch (NumberFormatException e) {
            Bukkit.getLogger().log(Level.WARNING,
                    "[SimpleTeamPvP] " + dataStr + " is not valid block data byte!");
            return false;
        }
    } else {
        try {
            blockMaterial = Material.valueOf(blockStr.toUpperCase());
        } catch (IllegalArgumentException e) {
            Bukkit.getLogger().log(Level.WARNING,
                    "[SimpleTeamPvP] " + blockStr + " is not a valid block material name!");
            return false;
        }
    }
    return true;
}

From source file:org.romaframework.core.schema.SchemaField.java

protected Object convertValue(Object iFieldValue) {
    if (type == null || isArray())
        return iFieldValue;

    SchemaClass typeClass = getType().getSchemaClass();
    if (typeClass.equals(Roma.schema().getSchemaClass(iFieldValue)))
        return iFieldValue;

    String textValue = null;// w w  w .  j a va  2  s . c om
    if (iFieldValue instanceof String) {
        textValue = (String) iFieldValue;
    } else if (iFieldValue != null) {
        textValue = iFieldValue.toString();
    }

    Object value = null;

    if (textValue != null) {
        // TRY A SOFT CONVERSION
        if (typeClass.isOfType(Integer.class) || typeClass.isOfType(Integer.TYPE)) {
            try {
                value = textValue.equals("") ? null : Integer.parseInt(textValue);
            } catch (Exception e) {
                value = textValue.equals("") ? null : Double.valueOf(textValue).intValue();
            }
        } else if (typeClass.isOfType(Long.class) || typeClass.isOfType(Long.TYPE)) {
            value = textValue.equals("") ? null : Long.parseLong(textValue);
        } else if (typeClass.isOfType(Short.class) || typeClass.isOfType(Short.TYPE)) {
            value = textValue.equals("") ? null : Short.parseShort(textValue);
        } else if (typeClass.isOfType(Byte.class) || typeClass.isOfType(Byte.TYPE)) {
            value = textValue.equals("") ? null : Byte.parseByte(textValue);
        } else if (typeClass.isOfType(Character.class) || typeClass.isOfType(Character.TYPE)) {
            if (textValue.length() > 0) {
                value = new Character(textValue.charAt(0));
            }
        } else if (typeClass.isOfType(Float.class) || typeClass.isOfType(Float.TYPE)) {
            value = textValue.equals("") ? null : Float.parseFloat(textValue);
        } else if (typeClass.isOfType(Double.class) || typeClass.isOfType(Double.TYPE)) {
            value = textValue.equals("") ? null : Double.parseDouble(textValue);
        } else if (typeClass.isOfType(BigDecimal.class)) {
            value = textValue.equals("") ? null : new BigDecimal(textValue);
        } else if (iFieldValue != null && !typeClass.isArray() && iFieldValue.getClass().isArray()) {
            // DESTINATION VALUE IS NOT AN ARRAY: ASSIGN THE FIRST ONE ELEMENT
            value = ((Object[]) iFieldValue)[0];
        } else {
            value = iFieldValue;
        }
    }

    if (value != null) {
        // TODO is this the right place to do this...?
        Class<?> valueClass = value.getClass();
        // SUCH A MONSTER!!! MOVE THIS LOGIC IN SchemaClass.isAssignableFrom...
        if (value instanceof VirtualObject
                && !(typeClass.getLanguageType() instanceof Class<?>
                        && ((Class<?>) typeClass.getLanguageType()).isAssignableFrom(VirtualObject.class))
                && ((VirtualObject) value).getSuperClassObject() != null) {
            if (ComposedEntity.class
                    .isAssignableFrom(((VirtualObject) value).getSuperClassObject().getClass())) {
                value = ((VirtualObject) value).getSuperClassObject();
                valueClass = value.getClass();
            }
        }

        if (value instanceof ComposedEntity<?> && !typeClass.isAssignableFrom(valueClass)) {
            value = ((ComposedEntity<?>) value).getEntity();
        }
    }

    if (value == null && typeClass.isPrimitive()) {
        log.warn("Cannot set the field value to null for primitive types! Field: " + getEntity() + "." + name
                + " of class " + getType().getName() + ". Setting value to 0.");
        // SET THE VALUE TO 0
        value = SchemaHelper.assignDefaultValueToLiteral(typeClass);
    }
    return value;
}

From source file:cn.ac.ncic.mastiff.io.coding.DeltaBinaryArrayZigZarByteReader.java

@Override
public byte[] ensureDecompressed() throws IOException {
    FlexibleEncoding.ORC.DynamicByteArray dynamicBuffer = new FlexibleEncoding.ORC.DynamicByteArray();
    dynamicBuffer.add(inBuf.getData(), 12, inBuf.getLength() - 12);
    FlexibleEncoding.Parquet.DeltaByteArrayReader reader = new FlexibleEncoding.Parquet.DeltaByteArrayReader();
    ByteBuffer byteBuf = ByteBuffer.allocate(dynamicBuffer.size());
    dynamicBuffer.setByteBuffer(byteBuf, 0, dynamicBuffer.size());
    byteBuf.flip();/*w  w w  . j a va2s . c  om*/
    reader.initFromPage(numPairs, byteBuf.array(), 0);
    DataOutputBuffer decoding = new DataOutputBuffer();
    decoding.writeInt(decompressedSize);
    decoding.writeInt(numPairs);
    decoding.writeInt(startPos);
    for (int i = 0; i < numPairs; i++) {
        byte tmp = Byte.parseByte(reader.readBytes().toStringUsingUTF8());
        decoding.writeByte(tmp);
    }
    byteBuf.clear();
    inBuf.close();
    return decoding.getData();
}