Example usage for java.lang Short valueOf

List of usage examples for java.lang Short valueOf

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static Short valueOf(short s) 

Source Link

Document

Returns a Short instance representing the specified short value.

Usage

From source file:gov.nih.nci.cabig.caaers.dataimport.AgentSpecificTermsImporter.java

public Map<String, Object> importFile() throws Exception {

    POIFSFileSystem poifs;//from  w w  w.j a va  2s  .co  m
    HSSFWorkbook wb;
    HSSFSheet sh = null;

    boolean isExcel = file.getName().endsWith(".xls");
    boolean isCSV = file.getName().endsWith(".csv");

    Map<String, Object> results = new HashMap<String, Object>();
    int rowCount = 0;
    int columnsCount = 0;
    Map<String, Agent> agents = new HashMap<String, Agent>();
    Map<String, Agent> missingAgents = new HashMap<String, Agent>();
    Set<String> missingTerms = new HashSet<String>();
    Map<String, String> asaelCache = new HashMap<String, String>();
    int asael;

    // wipe out the table
    agentSpecificTermDao.deleteAll();
    studyDao.deleteAllExpectedTerms();
    // if (true) return null;

    // get needed headers
    if (isExcel) {
        poifs = new POIFSFileSystem(new FileInputStream(file));
        wb = new HSSFWorkbook(poifs);
        sh = wb.getSheetAt(0);
        rowCount = sh.getLastRowNum();
        columnsCount = sh.getRow(0).getLastCellNum();

        for (byte i = 0; i < columnsCount; i++) {
            HSSFCell cell = sh.getRow(0).getCell(i);
            if (headers.containsKey(cell.getStringCellValue())) {
                headers.remove(cell.getStringCellValue());
                headers.put(cell.getStringCellValue(), Short.valueOf(i));
            }
        }
    }

    InputStream ir = null;
    Reader r = null;
    BufferedReader br = null;

    if (isCSV) {
        // readLines
        rowCount = 0;
        ir = new FileInputStream(file);
        r = new InputStreamReader(ir);
        br = new BufferedReader(r);
        String s = br.readLine();
        while (s != null) {
            if (rowCount == 0) {
                String[] _s = s.split("[\\|]{1}");
                for (byte j = 0; j < _s.length; j++) {
                    // System.out.println(_s[j]);
                    if (headers.containsKey(_s[j])) {
                        headers.remove(_s[j]);
                        headers.put(_s[j], Short.valueOf(j));
                    }
                }
            }
            rowCount++;
            s = br.readLine();
        }
        br.close();
        r.close();
        ir.close();

        ir = new FileInputStream(file);
        r = new InputStreamReader(ir);
        br = new BufferedReader(r);
    }

    /*
            System.out.println(rowCount);
            for (Map.Entry e : headers.entrySet()) {
    System.out.println(e.getKey() + "=>" + e.getValue());
            }
    */

    agents.clear();
    missingTerms.clear();
    missingAgents.clear();
    asael = 0;
    int duplicateAgentTerms = 0;

    //
    String nsc = "";
    String ctcae_category = "";
    String ctcae_version = "0.0";
    String ae_term = "";
    String other_toxicity = "";

    // Loading ASAE list
    // if (true) {  return null; }

    int i = 1;
    while (i <= rowCount) {

        nsc = "";

        if (isExcel) {
            HSSFRow row = sh.getRow(i);
            if (row != null) {
                nsc = getCellData("", i, row.getCell((short) headers.get("NSC")));
                ctcae_category = getCellData("", i, row.getCell((short) headers.get("CTCAE_CATEGORY")));
                ctcae_version = getCellData("", i, row.getCell((short) headers.get("CTCAE_VERSION")));
                ae_term = getCellData("", i, row.getCell((short) headers.get("AE_TERM")));
                other_toxicity = getCellData("", i, row.getCell((short) headers.get("OTHER_TOXICITY")));
            }
        } else {
            String s;
            s = br.readLine();
            if (s != null) {
                String[] _s = s.split("[\\|]{1}");
                if (i > 1 && _s.length > 1) {
                    nsc = _s[headers.get("NSC")];
                    ctcae_category = _s[headers.get("CTCAE_CATEGORY")];
                    try {
                        ctcae_version = _s[headers.get("CTCAE_VERSION")].trim();
                    } catch (NumberFormatException e) {
                        //                                System.out.println(s);
                        return null;
                    }
                    ae_term = _s[headers.get("AE_TERM")];
                    if (_s.length - 1 >= headers.get("OTHER_TOXICITY"))
                        other_toxicity = _s[headers.get("OTHER_TOXICITY")];
                    else
                        other_toxicity = "";
                }
            }
        }

        if (nsc.trim().equals("")) {
            i++;
            continue;
        } else {
            // System.out.println(String.format("%s). NSC:%s,   V:%s,   C:%s,   T:%s", i, nsc, ctcae_version, ctcae_category, ae_term));
        }

        Agent a = agents.get(nsc);
        if (a == null) {
            a = agentDao.getByNscNumber(nsc);
            // System.out.println(asael + ". OK. Found agent [" + a.getName() + "] for NSC: [" + nsc + "]");
            agents.put(nsc, a);
        }

        if (a != null) {
            AgentSpecificCtcTerm t = new AgentSpecificCtcTerm();
            t.setAgent(a);
            t.setOtherToxicity(other_toxicity);

            List<CtcTerm> list = terminologyRepository.getCtcTerm(ctcae_category, ctcae_version, ae_term);
            if (list.size() == 0) {
                // System.out.println("<ERROR>: Term not found: " + ae_term + ", Category: " + ctcae_category + ", CTCAE Version: " + ctcae_version);
                missingTerms.add("Term not found: " + ae_term + ", Category: " + ctcae_category
                        + ", CTCAE Version: " + ctcae_version);
            } else {
                t.setCtcTerm(list.get(0));
                if (persistASAE(t))
                    asael++;
                else
                    duplicateAgentTerms++;
            }

            agentSpecificTermDao.evict(t);

        } else {
            if (!missingAgents.containsKey(nsc)) {
                // System.out.println("<ERROR>: The agent was not found by its NSC: " + nsc);
                missingAgents.put(nsc, null);
            }
        }

        i++;
    }

    if (isCSV) {
        br.close();
        r.close();
        ir.close();
    }

    results.put(KEY_MISSING_TERMS, missingTerms);
    results.put(KEY_PROCESSED_AGENTS, agents.size() - missingAgents.size());
    results.put(KEY_PROCESSED_AGENTTERMS, asael);
    results.put(KEY_MISSING_AGENTS, missingAgents);
    results.put(KEY_DUPLICATE_AGENT_TERMS, duplicateAgentTerms);

    return results;
}

From source file:org.mifos.application.meeting.struts.actionforms.MeetingActionForm.java

public WeekDay getWeekDayValue() {
    return StringUtils.isNotBlank(getWeekDay()) ? WeekDay.getWeekDay(Short.valueOf(getWeekDay())) : null;
}

From source file:com.glaf.core.util.Tools.java

public static Object getValue(Class<?> type, String propertyValue) {
    if (type == null || propertyValue == null || propertyValue.trim().length() == 0) {
        return null;
    }/*  w  w w.  j  av  a 2  s . com*/
    Object value = null;
    try {
        if (type == String.class) {
            value = propertyValue;
        } else if ((type == Integer.class) || (type == int.class)) {
            if (propertyValue.indexOf(',') != -1) {
                propertyValue = propertyValue.replaceAll(",", "");
            }
            value = Integer.parseInt(propertyValue);
        } else if ((type == Long.class) || (type == long.class)) {
            if (propertyValue.indexOf(',') != -1) {
                propertyValue = propertyValue.replaceAll(",", "");
            }
            value = Long.parseLong(propertyValue);
        } else if ((type == Float.class) || (type == float.class)) {
            if (propertyValue.indexOf(',') != -1) {
                propertyValue = propertyValue.replaceAll(",", "");
            }
            value = Float.valueOf(propertyValue);
        } else if ((type == Double.class) || (type == double.class)) {
            if (propertyValue.indexOf(',') != -1) {
                propertyValue = propertyValue.replaceAll(",", "");
            }
            value = Double.parseDouble(propertyValue);
        } else if ((type == Boolean.class) || (type == boolean.class)) {
            value = Boolean.valueOf(propertyValue);
        } else if ((type == Character.class) || (type == char.class)) {
            value = Character.valueOf(propertyValue.charAt(0));
        } else if ((type == Short.class) || (type == short.class)) {
            if (propertyValue.indexOf(',') != -1) {
                propertyValue = propertyValue.replaceAll(",", "");
            }
            value = Short.valueOf(propertyValue);
        } else if ((type == Byte.class) || (type == byte.class)) {
            value = Byte.valueOf(propertyValue);
        } else if (type == java.util.Date.class) {
            value = DateUtils.toDate(propertyValue);
        } else if (type == java.sql.Date.class) {
            value = DateUtils.toDate(propertyValue);
        } else if (type == java.sql.Timestamp.class) {
            value = DateUtils.toDate(propertyValue);
        } else if (type.isAssignableFrom(List.class)) {
        } else if (type.isAssignableFrom(Set.class)) {
        } else if (type.isAssignableFrom(Collection.class)) {
        } else if (type.isAssignableFrom(Map.class)) {
        } else {
            value = propertyValue;
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    return value;
}

From source file:org.apache.hadoop.hive.serde2.binarysortable.MyTestPrimitiveClass.java

public int randomFill(Random r, int randField, int field, ExtraTypeInfo extraTypeInfo) {
    myBool = chooseNull(r, randField, field++) ? null : Boolean.valueOf(r.nextInt(1) == 1);
    myByte = chooseNull(r, randField, field++) ? null : Byte.valueOf((byte) r.nextInt());
    myShort = chooseNull(r, randField, field++) ? null : Short.valueOf((short) r.nextInt());
    myInt = chooseNull(r, randField, field++) ? null : Integer.valueOf(r.nextInt());
    myLong = chooseNull(r, randField, field++) ? null : Long.valueOf(r.nextLong());
    myFloat = chooseNull(r, randField, field++) ? null : Float.valueOf(r.nextFloat() * 10 - 5);
    myDouble = chooseNull(r, randField, field++) ? null : Double.valueOf(r.nextDouble() * 10 - 5);
    myString = chooseNull(r, randField, field++) ? null : getRandString(r);
    myHiveChar = chooseNull(r, randField, field++) ? null : getRandHiveChar(r, extraTypeInfo);
    myHiveVarchar = chooseNull(r, randField, field++) ? null : getRandHiveVarchar(r, extraTypeInfo);
    myBinary = getRandBinary(r, r.nextInt(1000));
    myDecimal = chooseNull(r, randField, field++) ? null : getRandHiveDecimal(r, extraTypeInfo);
    myDate = chooseNull(r, randField, field++) ? null : getRandDate(r);
    myTimestamp = chooseNull(r, randField, field++) ? null : RandomTypeUtil.getRandTimestamp(r);
    myIntervalYearMonth = chooseNull(r, randField, field++) ? null : getRandIntervalYearMonth(r);
    myIntervalDayTime = chooseNull(r, randField, field++) ? null : getRandIntervalDayTime(r);
    return field;
}

From source file:org.apache.hadoop.hive.serde2.binarysortable.MyTestClass.java

public int randomFill(Random r, ExtraTypeInfo extraTypeInfo) {
    int randField = r.nextInt(MyTestClass.fieldCount);
    int field = 0;

    myBool = (randField == field++) ? null : (r.nextInt(1) == 1);
    myByte = (randField == field++) ? null : Byte.valueOf((byte) r.nextInt());
    myShort = (randField == field++) ? null : Short.valueOf((short) r.nextInt());
    myInt = (randField == field++) ? null : Integer.valueOf(r.nextInt());
    myLong = (randField == field++) ? null : Long.valueOf(r.nextLong());
    myFloat = (randField == field++) ? null : Float.valueOf(r.nextFloat() * 10 - 5);
    myDouble = (randField == field++) ? null : Double.valueOf(r.nextDouble() * 10 - 5);
    myString = (randField == field++) ? null : MyTestPrimitiveClass.getRandString(r);
    myHiveChar = (randField == field++) ? null : MyTestPrimitiveClass.getRandHiveChar(r, extraTypeInfo);
    myHiveVarchar = (randField == field++) ? null : MyTestPrimitiveClass.getRandHiveVarchar(r, extraTypeInfo);
    myBinary = MyTestPrimitiveClass.getRandBinary(r, r.nextInt(1000));
    myDecimal = (randField == field++) ? null : MyTestPrimitiveClass.getRandHiveDecimal(r, extraTypeInfo);
    myDate = (randField == field++) ? null : MyTestPrimitiveClass.getRandDate(r);
    myTimestamp = (randField == field++) ? null : RandomTypeUtil.getRandTimestamp(r);
    myIntervalYearMonth = (randField == field++) ? null : MyTestPrimitiveClass.getRandIntervalYearMonth(r);
    myIntervalDayTime = (randField == field++) ? null : MyTestPrimitiveClass.getRandIntervalDayTime(r);

    myStruct = (randField == field++) ? null : new MyTestInnerStruct(r.nextInt(5) - 2, r.nextInt(5) - 2);
    myList = (randField == field++) ? null : getRandIntegerArray(r);
    return field;
}

From source file:org.apache.hadoop.hbase.regionserver.wal.SequenceFileLogWriter.java

@Override
public void init(FileSystem fs, Path path, Configuration conf, boolean overwritable) throws IOException {
    super.init(fs, path, conf, overwritable);
    boolean compress = initializeCompressionContext(conf, path);
    // Create a SF.Writer instance.
    try {/*from w  w w.  j  av a2  s. c  o  m*/
        // reflection for a version of SequenceFile.createWriter that doesn't
        // automatically create the parent directory (see HBASE-2312)
        this.writer = (SequenceFile.Writer) SequenceFile.class
                .getMethod("createWriter",
                        new Class[] { FileSystem.class, Configuration.class, Path.class, Class.class,
                                Class.class, Integer.TYPE, Short.TYPE, Long.TYPE, Boolean.TYPE,
                                CompressionType.class, CompressionCodec.class, Metadata.class })
                .invoke(null,
                        new Object[] { fs, conf, path, HLogKey.class, WALEdit.class,
                                Integer.valueOf(FSUtils.getDefaultBufferSize(fs)),
                                Short.valueOf((short) conf.getInt("hbase.regionserver.hlog.replication",
                                        FSUtils.getDefaultReplication(fs, path))),
                                Long.valueOf(conf.getLong("hbase.regionserver.hlog.blocksize",
                                        FSUtils.getDefaultBlockSize(fs, path))),
                                Boolean.valueOf(false) /*createParent*/, SequenceFile.CompressionType.NONE,
                                new DefaultCodec(), createMetadata(conf, compress) });
    } catch (InvocationTargetException ite) {
        // function was properly called, but threw it's own exception
        throw new IOException(ite.getCause());
    } catch (Exception e) {
        // ignore all other exceptions. related to reflection failure
    }

    // if reflection failed, use the old createWriter
    if (this.writer == null) {
        LOG.debug("new createWriter -- HADOOP-6840 -- not available");
        this.writer = SequenceFile.createWriter(fs, conf, path, HLogKey.class, WALEdit.class,
                FSUtils.getDefaultBufferSize(fs),
                (short) conf.getInt("hbase.regionserver.hlog.replication",
                        FSUtils.getDefaultReplication(fs, path)),
                conf.getLong("hbase.regionserver.hlog.blocksize", FSUtils.getDefaultBlockSize(fs, path)),
                SequenceFile.CompressionType.NONE, new DefaultCodec(), null, createMetadata(conf, compress));
    } else {
        if (LOG.isTraceEnabled())
            LOG.trace("Using new createWriter -- HADOOP-6840");
    }

    this.writer_out = getSequenceFilePrivateFSDataOutputStreamAccessible();
    if (LOG.isTraceEnabled())
        LOG.trace("Path=" + path + ", compression=" + compress);
}

From source file:com.fjn.helper.common.io.file.common.FileUpAndDownloadUtil.java

/**
 * ???????/*from  w  w  w. j a  v a 2 s . c om*/
 * @param klass   ???klass?Class
 * @param filepath   ?
 * @param sizeThreshold   ??
 * @param isFileNameBaseTime   ????
 * @return bean
 */
public static <T> Object upload(HttpServletRequest request, Class<T> klass, String filepath, int sizeThreshold,
        boolean isFileNameBaseTime) throws Exception {
    FileItemFactory fileItemFactory = null;
    if (sizeThreshold > 0) {
        File repository = new File(filepath);
        fileItemFactory = new DiskFileItemFactory(sizeThreshold, repository);
    } else {
        fileItemFactory = new DiskFileItemFactory();
    }
    ServletFileUpload upload = new ServletFileUpload(fileItemFactory);
    ServletRequestContext requestContext = new ServletRequestContext(request);
    T bean = null;
    if (klass != null) {
        bean = klass.newInstance();
    }
    // 
    if (ServletFileUpload.isMultipartContent(requestContext)) {
        File parentDir = new File(filepath);

        List<FileItem> fileItemList = upload.parseRequest(requestContext);
        for (int i = 0; i < fileItemList.size(); i++) {
            FileItem item = fileItemList.get(i);
            // ??
            if (item.isFormField()) {
                String paramName = item.getFieldName();
                String paramValue = item.getString("UTF-8");
                log.info("?" + paramName + "=" + paramValue);
                request.setAttribute(paramName, paramValue);
                // ?bean
                if (klass != null) {
                    Field field = null;
                    try {
                        field = klass.getDeclaredField(paramName);

                        if (field != null) {
                            field.setAccessible(true);
                            Class type = field.getType();
                            if (type == Integer.TYPE) {
                                field.setInt(bean, Integer.valueOf(paramValue));
                            } else if (type == Double.TYPE) {
                                field.setDouble(bean, Double.valueOf(paramValue));
                            } else if (type == Float.TYPE) {
                                field.setFloat(bean, Float.valueOf(paramValue));
                            } else if (type == Boolean.TYPE) {
                                field.setBoolean(bean, Boolean.valueOf(paramValue));
                            } else if (type == Character.TYPE) {
                                field.setChar(bean, paramValue.charAt(0));
                            } else if (type == Long.TYPE) {
                                field.setLong(bean, Long.valueOf(paramValue));
                            } else if (type == Short.TYPE) {
                                field.setShort(bean, Short.valueOf(paramValue));
                            } else {
                                field.set(bean, paramValue);
                            }
                        }
                    } catch (NoSuchFieldException e) {
                        log.info("" + klass.getName() + "?" + paramName);
                    }
                }
            }
            // 
            else {
                // <input type='file' name='xxx'> xxx
                String paramName = item.getFieldName();
                log.info("?" + item.getSize());

                if (sizeThreshold > 0) {
                    if (item.getSize() > sizeThreshold)
                        continue;
                }
                String clientFileName = item.getName();
                int index = -1;
                // ?IE?
                if ((index = clientFileName.lastIndexOf("\\")) != -1) {
                    clientFileName = clientFileName.substring(index + 1);
                }
                if (clientFileName == null || "".equals(clientFileName))
                    continue;

                String filename = null;
                log.info("" + paramName + "\t??" + clientFileName);
                if (isFileNameBaseTime) {
                    filename = buildFileName(clientFileName);
                } else
                    filename = clientFileName;

                request.setAttribute(paramName, filename);

                // ?bean
                if (klass != null) {
                    Field field = null;
                    try {
                        field = klass.getDeclaredField(paramName);
                        if (field != null) {
                            field.setAccessible(true);
                            field.set(bean, filename);
                        }
                    } catch (NoSuchFieldException e) {
                        log.info("" + klass.getName() + "?  " + paramName);
                        continue;
                    }
                }

                if (!parentDir.exists()) {
                    parentDir.mkdirs();
                }

                File newfile = new File(parentDir, filename);
                item.write(newfile);
                String serverPath = newfile.getPath();
                log.info("?" + serverPath);
            }
        }
    }
    return bean;
}

From source file:org.ibeans.impl.support.util.Utils.java

/**
 * Gets a short from a value in a null-safe manner.
 * <p/>/*from w  ww . ja  v a  2  s  . co  m*/
 *
 * @param answer       the object value
 * @param defaultValue the default to use if null or of incorrect type
 * @return the value as a short, or the defaultValue
 */
public static short getShort(final Object answer, short defaultValue) {
    if (answer == null) {
        return defaultValue;
    } else if (answer instanceof Number) {
        return ((Number) answer).shortValue();
    } else if (answer instanceof String) {
        try {
            return Short.valueOf((String) answer).shortValue();
        } catch (NumberFormatException e) {
            //handled below
        }
    }
    if (logger.isWarnEnabled()) {
        logger.warn("Value exists but cannot be converted to short: " + answer + ", returning default value: "
                + defaultValue);
    }
    return defaultValue;
}

From source file:org.mifos.application.meeting.struts.actionforms.MeetingActionForm.java

public RecurrenceType getRecurrenceType() {
    return StringUtils.isNotBlank(getFrequency()) ? RecurrenceType.fromInt(Short.valueOf(getFrequency()))
            : null;
}

From source file:org.apache.kylin.jdbc.KylinClient.java

public static Object wrapObject(String value, int sqlType) {
    if (null == value) {
        return null;
    }/* w  w w  . j  a  v  a2s .  c  o  m*/

    switch (sqlType) {
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        return value;
    case Types.NUMERIC:
    case Types.DECIMAL:
        return new BigDecimal(value);
    case Types.BIT:
        return Boolean.parseBoolean(value);
    case Types.TINYINT:
        return Byte.valueOf(value);
    case Types.SMALLINT:
        return Short.valueOf(value);
    case Types.INTEGER:
        return Integer.parseInt(value);
    case Types.BIGINT:
        return Long.parseLong(value);
    case Types.FLOAT:
        return Float.parseFloat(value);
    case Types.REAL:
    case Types.DOUBLE:
        return Double.parseDouble(value);
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        return value.getBytes();
    case Types.DATE:
        return Date.valueOf(value);
    case Types.TIME:
        return Time.valueOf(value);
    case Types.TIMESTAMP:
        return Timestamp.valueOf(value);
    default:
        //do nothing
        break;

    }

    return value;
}