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:org.eclipse.dataset.ShortDataset.java

@Override
protected Number fromDoubleToNumber(double x) {
    short r = (short) (long) x; // ADD_CAST // PRIM_TYPE_LONG
    return Short.valueOf(r); // CLASS_TYPE
    // return Integer.valueOf((int) (long) x); // BOOLEAN_USE
    // return null; // OBJECT_USE
}

From source file:ch.entwine.weblounge.common.impl.request.RequestUtils.java

/**
 * Checks if the parameter <code>parameter</code> is present in the request
 * and is a valid <code>short</code>. In that case, the parameter is returned
 * as a <code>short</code>, otherwise <code>0</code> is returned.
 * <p>/*ww  w  .  j  a  v  a  2 s . c om*/
 * If the parameter is required, then an {@link IllegalStateException} is
 * thrown.
 * 
 * @param request
 *          the weblounge request
 * @param parameterName
 *          the parameter name
 * @param required
 *          <code>true</code> if this parameter is mandatory
 * @return the parameter value or <code>0</code> if the parameter is not
 *         available
 * @throws IllegalArgumentException
 *           if the parameter value cannot be cast to a <code>short</code>
 * @throws IllegalStateException
 *           if the parameter was not found in the request
 */
private static short getShortParameter(WebloungeRequest request, String parameterName, boolean required)
        throws IllegalArgumentException, IllegalStateException {
    String p = null;
    if (required)
        p = getRequiredParameter(request, parameterName);
    else
        p = getParameter(request, parameterName);
    if (p == null)
        return 0;
    try {
        return Short.valueOf(p);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("Request parameter '" + parameterName + "' must be a short");
    }
}

From source file:com.mimp.controllers.main.java

@RequestMapping(value = "/inscSesInd", method = RequestMethod.GET)
public ModelAndView inscSesInd_GET(ModelMap map, HttpSession session) {
    long turno = 0;
    String estado = "";
    String nombre = "";
    String apellidoP = "";
    String apellidoM = "";
    String paisNac = "";
    String depNac = "";
    String proNac = "";
    String fechaNac = "";
    String edad = "";
    String doc = "";
    String numDoc = "";
    String profesion = "";
    String cel = "";
    String correo = "";
    String pais = "";
    String dep = "";
    String prov = "";
    String dist = "";
    String dir = "";
    String telf = "";
    try {//  www  . j a va2  s  .co  m
        turno = Long.parseLong(session.getAttribute("turno").toString());
        estado = session.getAttribute("estado").toString();
        nombre = session.getAttribute("nombre").toString();
        apellidoP = session.getAttribute("apellidoP").toString();
        apellidoM = session.getAttribute("apellidoM").toString();
        paisNac = session.getAttribute("paisNac").toString();
        depNac = session.getAttribute("depNac").toString();
        proNac = session.getAttribute("proNac").toString();
        fechaNac = session.getAttribute("fechaNac").toString();
        edad = session.getAttribute("edad").toString();
        doc = session.getAttribute("doc").toString();
        numDoc = session.getAttribute("numDoc").toString();
        profesion = session.getAttribute("profesion").toString();
        cel = session.getAttribute("cel").toString();
        correo = session.getAttribute("correo").toString();
        pais = session.getAttribute("pais").toString();
        dep = session.getAttribute("dep").toString();
        prov = session.getAttribute("prov").toString();
        dist = session.getAttribute("dist").toString();
        dir = session.getAttribute("dir").toString();
        telf = session.getAttribute("telf").toString();
    } catch (Exception ex) {
        return new ModelAndView("redirect:/", map);
    }
    session.removeAttribute("estado");
    session.removeAttribute("turno");
    session.removeAttribute("nombre");
    session.removeAttribute("apellidoP");
    session.removeAttribute("apellidoM");
    session.removeAttribute("paisNac");
    session.removeAttribute("depNac");
    session.removeAttribute("proNac");
    session.removeAttribute("fechaNac");
    session.removeAttribute("edad");
    session.removeAttribute("doc");
    session.removeAttribute("numDoc");
    session.removeAttribute("profesion");
    session.removeAttribute("cel");
    session.removeAttribute("correo");
    session.removeAttribute("pais");
    session.removeAttribute("dep");
    session.removeAttribute("prov");
    session.removeAttribute("dist");
    session.removeAttribute("dir");
    session.removeAttribute("telf");

    Turno temp = ServicioMain.getTurno(turno);
    FormularioSesion fs = new FormularioSesion();
    Asistente asis = new Asistente();
    AsistenciaFT aft = new AsistenciaFT();
    fs.setSesion(temp.getSesion());
    aft.setTurno(temp);
    String asistencia = "F";
    char asist = asistencia.charAt(0);
    aft.setAsistencia(asist);
    String inajust = "1";
    Short i = Short.valueOf(inajust);
    aft.setInasJus(i);

    Date today = new Date();

    fs.setFechaSol(today);
    fs.setPaisRes(pais);
    fs.setDepRes(dep);
    fs.setProvRes(prov);
    fs.setDistritoRes(dist);
    fs.setDireccionRes(dir);
    fs.setTelefono(telf);
    fs.setEstadoCivil(estado);
    String sexo = "";
    if (estado.equals("soltero") || estado.equals("viudo") || estado.equals("divorciado")) {
        sexo = "m";
    }
    if (estado.equals("soltera") || estado.equals("viuda") || estado.equals("divorciada")) {
        sexo = "f";
    }
    char s = sexo.charAt(0);
    asis.setSexo(s);
    asis.setNombre(nombre);
    asis.setApellidoP(apellidoP);
    asis.setApellidoM(apellidoM);
    asis.setPaisNac(paisNac);
    asis.setDepNac(depNac);
    asis.setProvNac(proNac);
    short b = Byte.valueOf(edad);
    asis.setEdad(b);
    if (fechaNac != null && !fechaNac.equals("")) {
        asis.setFechaNac(df.stringToDate(fechaNac));
    }
    char c = doc.charAt(0);
    asis.setTipoDoc(c);
    asis.setNDoc(numDoc);
    asis.setProfesion(profesion);
    asis.setCelular(cel);
    asis.setCorreo(correo);

    ArrayList<Asistente> tempList = new ArrayList();
    tempList = ServicioMain.listaAsistentes(temp.getSesion().getIdsesion());
    if (!tempList.isEmpty()) {
        for (Asistente asistente : tempList) {
            if (asistente.getNDoc().equals(numDoc)) {
                map.put("mensaje", "inscrito");
                return new ModelAndView("/Inscripcion/inscripcion_sesion1b", map);
            }

        }
    }
    if (temp.getVacantes() > temp.getAsistenciaFTs().size()) {
        map.put("ts", ts);
        map.put("turno", temp);
        ServicioMain.InsertFormInd(asis, fs, aft);
        return new ModelAndView("/Inscripcion/inscripcion_sesion4", map);
    } else {
        map.put("ts", ts);
        map.put("turno", temp);
        //ServicioMain.InsertFormInd(asis, fs, aft);
        return new ModelAndView("/Inscripcion/inscripcion_sesion1b", map);
    }
    //return new ModelAndView("contacto", map);
}

From source file:com.complexible.pinto.RDFMapper.java

private Object valueToObject(final Value theValue, final Model theGraph,
        final PropertyDescriptor theDescriptor) {
    if (theValue instanceof Literal) {
        final Literal aLit = (Literal) theValue;
        final IRI aDatatype = aLit.getDatatype() != null ? aLit.getDatatype() : null;

        if (aDatatype == null || XMLSchema.STRING.equals(aDatatype) || RDFS.LITERAL.equals(aDatatype)) {
            String aStr = aLit.getLabel();

            if (theDescriptor != null && Character.TYPE.isAssignableFrom(theDescriptor.getPropertyType())) {
                if (aStr.length() == 1) {
                    return aStr.charAt(0);
                } else {
                    throw new RDFMappingException("Bean type is char, but value is a a string.");
                }/*from w w w . ja  v a  2 s.c o  m*/
            } else {
                return aStr;
            }
        } else if (XMLSchema.BOOLEAN.equals(aDatatype)) {
            return Boolean.valueOf(aLit.getLabel());
        } else if (INTEGER_TYPES.contains(aDatatype)) {
            return Integer.parseInt(aLit.getLabel());
        } else if (LONG_TYPES.contains(aDatatype)) {
            return Long.parseLong(aLit.getLabel());
        } else if (XMLSchema.DOUBLE.equals(aDatatype)) {
            return Double.valueOf(aLit.getLabel());
        } else if (FLOAT_TYPES.contains(aDatatype)) {
            return Float.valueOf(aLit.getLabel());
        } else if (SHORT_TYPES.contains(aDatatype)) {
            return Short.valueOf(aLit.getLabel());
        } else if (BYTE_TYPES.contains(aDatatype)) {
            return Byte.valueOf(aLit.getLabel());
        } else if (XMLSchema.ANYURI.equals(aDatatype)) {
            try {
                return new java.net.URI(aLit.getLabel());
            } catch (URISyntaxException e) {
                LOGGER.warn("URI syntax exception converting literal value which is not a valid URI {} ",
                        aLit.getLabel());
                return null;
            }
        } else if (XMLSchema.DATE.equals(aDatatype) || XMLSchema.DATETIME.equals(aDatatype)) {
            return Dates2.asDate(aLit.getLabel());
        } else if (XMLSchema.TIME.equals(aDatatype)) {
            return new Date(Long.parseLong(aLit.getLabel()));
        } else {
            throw new RuntimeException("Unsupported or unknown literal datatype: " + aLit);
        }
    } else if (theDescriptor != null && Enum.class.isAssignableFrom(theDescriptor.getPropertyType())) {
        IRI aURI = (IRI) theValue;
        Object[] aEnums = theDescriptor.getPropertyType().getEnumConstants();
        for (Object aObj : aEnums) {
            if (((Enum) aObj).name().equals(aURI.getLocalName())) {
                return aObj;
            }
        }

        for (Field aField : theDescriptor.getPropertyType().getFields()) {
            Iri aAnnotation = aField.getAnnotation(Iri.class);
            if (aAnnotation != null && aURI.equals(iri(aAnnotation.value()))) {
                for (Object aObj : aEnums) {
                    if (((Enum) aObj).name().equals(aField.getName())) {
                        return aObj;
                    }
                }

                // if the uri in the Iri annotation equals the value we're converting, but there was no field
                // match, something bad has happened
                throw new RDFMappingException("Expected enum value not found");
            }
        }

        LOGGER.info("{} maps to the enum {}, but does not correspond to any of the values of the enum.", aURI,
                theDescriptor.getPropertyType());

        return null;
    } else {
        Resource aResource = (Resource) theValue;

        final Class aClass = pinpointClass(theGraph, aResource, theDescriptor);

        RDFCodec aCodec = mCodecs.get(aClass);
        if (aCodec != null) {
            return aCodec.readValue(theGraph, aResource);
        } else {
            return readValue(theGraph, aClass, aResource);
        }
    }
}

From source file:org.mifos.accounts.loan.business.LoanBORedoDisbursalIntegrationTest.java

@Ignore
@Test//w  w w  . j  a  v  a2 s  .  c o m
public void testRedoLoanApplyFractionalMiscFeeBeforeRepayments() throws Exception {

    LoanBO loan = redoLoanWithMondayMeetingAndVerify(userContext, 14, new ArrayList<AccountFeesEntity>());
    disburseLoanAndVerify(userContext, loan, 14);

    applyCharge(loan, Short.valueOf(AccountConstants.MISC_FEES), new Double("33.7"));

    LoanTestUtils.assertInstallmentDetails(loan, 1, 50.9, 0.1, 0.0, 0.0, 0.0);
    LoanTestUtils.assertInstallmentDetails(loan, 2, 51.2, 0.1, 0.0, 33.7, 0.0);
    LoanTestUtils.assertInstallmentDetails(loan, 3, 50.9, 0.1, 0.0, 0.0, 0.0);
    LoanTestUtils.assertInstallmentDetails(loan, 4, 50.9, 0.1, 0.0, 0.0, 0.0);
    LoanTestUtils.assertInstallmentDetails(loan, 5, 50.9, 0.1, 0.0, 0.0, 0.0);
    LoanTestUtils.assertInstallmentDetails(loan, 6, 45.2, 0.8, 0.0, 0.0, 0.0);
}

From source file:org.dspace.servicemanager.config.DSpaceConfigurationService.java

/**
 * Convert the value of a given property to a specific object type.
 * <P>/*from  w  w w  .jav  a  2 s  .  co  m*/
 * Note: in most cases we can just use Configuration get*() methods.
 *
 * @param name Key of the property to convert
 * @param <T> object type
 * @return converted value
 */
private <T> T convert(String name, Class<T> type) {

    // If this key doesn't exist, just return null
    if (!configuration.containsKey(name)) {
        // Special case. For booleans, return false if key doesn't exist
        if (Boolean.class.equals(type) || boolean.class.equals(type))
            return (T) Boolean.FALSE;
        else
            return null;
    }

    // Based on the type of class, call the appropriate
    // method of the Configuration object
    if (type.isArray())
        return (T) configuration.getStringArray(name);
    else if (String.class.equals(type) || type.isAssignableFrom(String.class))
        return (T) configuration.getString(name);
    else if (BigDecimal.class.equals(type))
        return (T) configuration.getBigDecimal(name);
    else if (BigInteger.class.equals(type))
        return (T) configuration.getBigInteger(name);
    else if (Boolean.class.equals(type) || boolean.class.equals(type))
        return (T) Boolean.valueOf(configuration.getBoolean(name));
    else if (Byte.class.equals(type) || byte.class.equals(type))
        return (T) Byte.valueOf(configuration.getByte(name));
    else if (Double.class.equals(type) || double.class.equals(type))
        return (T) Double.valueOf(configuration.getDouble(name));
    else if (Float.class.equals(type) || float.class.equals(type))
        return (T) Float.valueOf(configuration.getFloat(name));
    else if (Integer.class.equals(type) || int.class.equals(type))
        return (T) Integer.valueOf(configuration.getInt(name));
    else if (List.class.equals(type))
        return (T) configuration.getList(name);
    else if (Long.class.equals(type) || long.class.equals(type))
        return (T) Long.valueOf(configuration.getLong(name));
    else if (Short.class.equals(type) || short.class.equals(type))
        return (T) Short.valueOf(configuration.getShort(name));
    else {
        // If none of the above works, try to convert the value to the required type
        SimpleTypeConverter converter = new SimpleTypeConverter();
        return (T) converter.convertIfNecessary(configuration.getProperty(name), type);
    }
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.common.source.CswFilterDelegate.java

@Override
public FilterType propertyIsLessThanOrEqualTo(String propertyName, short literal) {
    isComparisonOperationSupported(ComparisonOperatorType.LESS_THAN_EQUAL_TO);
    propertyName = mapPropertyName(propertyName);
    if (isPropertyQueryable(propertyName)) {
        return cswFilterFactory.buildPropertyIsLessThanOrEqualToFilter(propertyName, Short.valueOf(literal));
    } else {/*  www . j av  a 2s .c  o  m*/
        return new FilterType();
    }
}

From source file:com.healthmarketscience.jackcess.Column.java

/**
 * Deserialize a raw byte value for this column into an Object
 * @param data The raw byte value/*from   www  . j a  v  a  2  s .  c  o  m*/
 * @param order Byte order in which the raw value is stored
 * @return The deserialized Object
 * @usage _advanced_method_
 */
public Object read(byte[] data, ByteOrder order) throws IOException {
    ByteBuffer buffer = ByteBuffer.wrap(data);
    buffer.order(order);
    if (_type == DataType.BOOLEAN) {
        throw new IOException("Tried to read a boolean from data instead of null mask.");
    } else if (_type == DataType.BYTE) {
        return Byte.valueOf(buffer.get());
    } else if (_type == DataType.INT) {
        return Short.valueOf(buffer.getShort());
    } else if (_type == DataType.LONG) {
        return Integer.valueOf(buffer.getInt());
    } else if (_type == DataType.DOUBLE) {
        return Double.valueOf(buffer.getDouble());
    } else if (_type == DataType.FLOAT) {
        return Float.valueOf(buffer.getFloat());
    } else if (_type == DataType.SHORT_DATE_TIME) {
        return readDateValue(buffer);
    } else if (_type == DataType.BINARY) {
        return data;
    } else if (_type == DataType.TEXT) {
        return decodeTextValue(data);
    } else if (_type == DataType.MONEY) {
        return readCurrencyValue(buffer);
    } else if (_type == DataType.OLE) {
        if (data.length > 0) {
            return readLongValue(data);
        }
        return null;
    } else if (_type == DataType.MEMO) {
        if (data.length > 0) {
            return readLongStringValue(data);
        }
        return null;
    } else if (_type == DataType.NUMERIC) {
        return readNumericValue(buffer);
    } else if (_type == DataType.GUID) {
        return readGUIDValue(buffer, order);
    } else if ((_type == DataType.UNKNOWN_0D) || (_type == DataType.UNKNOWN_11)) {
        // treat like "binary" data
        return data;
    } else if (_type == DataType.COMPLEX_TYPE) {
        return new ComplexValueForeignKey(this, buffer.getInt());
    } else if (_type.isUnsupported()) {
        return rawDataWrapper(data);
    } else {
        throw new IOException("Unrecognized data type: " + _type);
    }
}

From source file:org.apache.ambari.server.controller.internal.ClusterStackVersionResourceProvider.java

private void addHostVersionInstallCommandsToStage(final String desiredRepoVersion, Cluster cluster,
        AmbariManagementController managementController, AmbariMetaInfo ami, final StackId stackId,
        Map<String, List<RepositoryEntity>> perOsRepos, Stage stage, Host host) throws SystemException {
    // Determine repositories for host
    String osFamily = host.getOsFamily();
    final List<RepositoryEntity> repoInfo = perOsRepos.get(osFamily);
    if (repoInfo == null) {
        throw new SystemException(
                String.format("Repositories for os type %s are " + "not defined. Repo version=%s, stackId=%s",
                        osFamily, desiredRepoVersion, stackId));
    }//  w  ww  . jav a  2 s . c  o m

    // determine packages for all services that are installed on host
    List<ServiceOsSpecific.Package> packages = new ArrayList<ServiceOsSpecific.Package>();
    Set<String> servicesOnHost = new HashSet<String>();
    List<ServiceComponentHost> components = cluster.getServiceComponentHosts(host.getHostName());
    for (ServiceComponentHost component : components) {
        servicesOnHost.add(component.getServiceName());
    }
    List<String> blacklistedPackagePrefixes = configuration.getRollingUpgradeSkipPackagesPrefixes();
    for (String serviceName : servicesOnHost) {
        ServiceInfo info;
        try {
            info = ami.getService(stackId.getStackName(), stackId.getStackVersion(), serviceName);
        } catch (AmbariException e) {
            throw new SystemException("Cannot enumerate services", e);
        }

        List<ServiceOsSpecific.Package> packagesForService = managementController.getPackagesForServiceHost(
                info, new HashMap<String, String>(), // Contents are ignored
                osFamily);
        for (ServiceOsSpecific.Package aPackage : packagesForService) {
            if (!aPackage.getSkipUpgrade()) {
                boolean blacklisted = false;
                for (String prefix : blacklistedPackagePrefixes) {
                    if (aPackage.getName().startsWith(prefix)) {
                        blacklisted = true;
                        break;
                    }
                }
                if (!blacklisted) {
                    packages.add(aPackage);
                }
            }
        }
    }

    final String packageList = gson.toJson(packages);
    final String repoList = gson.toJson(repoInfo);

    Map<String, String> params = new HashMap<String, String>();
    params.put("stack_id", stackId.getStackId());
    params.put("repository_version", desiredRepoVersion);
    params.put("base_urls", repoList);
    params.put("package_list", packageList);

    // add host to this stage
    RequestResourceFilter filter = new RequestResourceFilter(null, null,
            Collections.singletonList(host.getHostName()));

    ActionExecutionContext actionContext = new ActionExecutionContext(cluster.getClusterName(),
            INSTALL_PACKAGES_ACTION, Collections.singletonList(filter), params);
    actionContext.setTimeout(Short.valueOf(configuration.getDefaultAgentTaskTimeout(true)));

    try {
        actionExecutionHelper.get().addExecutionCommandsToStage(actionContext, stage);
    } catch (AmbariException e) {
        throw new SystemException("Can not modify stage", e);
    }
}

From source file:org.mifos.application.servicefacade.CollectionSheetServiceImpl.java

private Boolean isIndividualSavingsAccount(Short customerLevelId, Short recommendedAmountUnitId) {
    if (customerLevelId.compareTo(CustomerLevel.CENTER.getValue()) == 0) {
        return true;
    }//from w  w w  . jav  a  2s .c o  m
    if ((customerLevelId.compareTo(CustomerLevel.GROUP.getValue()) == 0) && (recommendedAmountUnitId != null)
            && (recommendedAmountUnitId.compareTo(Short.valueOf("1")) == 0)) {
        return true;
    }
    return false;
}