Example usage for java.lang Short Short

List of usage examples for java.lang Short Short

Introduction

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

Prototype

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

Source Link

Document

Constructs a newly allocated Short object that represents the short value indicated by the String parameter.

Usage

From source file:alice.tuprolog.lib.OOLibrary.java

/**
 * //from   w w w  .  ja  v a  2  s  .  co  m
 * parsing 'as' operator, which makes it possible to define the specific
 * class of an argument
 * 
 */
private boolean parse_as(Object[] values, Class<?>[] types, int i, PTerm castWhat, PTerm castTo) {
    try {
        if (!(castWhat instanceof Number)) {
            String castTo_name = alice.util.Tools.removeApices(((Struct) castTo).getName());
            String castWhat_name = alice.util.Tools.removeApices(castWhat.getTerm().toString());
            // System.out.println(castWhat_name+" "+castTo_name);
            if (castTo_name.equals("java.lang.String") && castWhat_name.equals("true")) {
                values[i] = "true";
                types[i] = String.class;
                return true;
            } else if (castTo_name.equals("java.lang.String") && castWhat_name.equals("false")) {
                values[i] = "false";
                types[i] = String.class;
                return true;
            } else if (castTo_name.endsWith("[]")) {
                switch (castTo_name) {
                case "boolean[]":
                    castTo_name = "[Z";
                    break;
                case "byte[]":
                    castTo_name = "[B";
                    break;
                case "short[]":
                    castTo_name = "[S";
                    break;
                case "char[]":
                    castTo_name = "[C";
                    break;
                case "int[]":
                    castTo_name = "[I";
                    break;
                case "long[]":
                    castTo_name = "[L";
                    break;
                case "float[]":
                    castTo_name = "[F";
                    break;
                case "double[]":
                    castTo_name = "[D";
                    break;
                default:
                    castTo_name = "[L" + castTo_name.substring(0, castTo_name.length() - 2) + ';';
                    break;
                }
            }
            if (!castWhat_name.equals("null")) {
                Object obj_to_cast = currentObjects.get(castWhat_name);
                if (obj_to_cast == null) {
                    if (castTo_name.equals("boolean")) {
                        switch (castWhat_name) {
                        case "true":
                            values[i] = new Boolean(true);
                            break;
                        case "false":
                            values[i] = new Boolean(false);
                            break;
                        default:
                            return false;
                        }
                        types[i] = Boolean.TYPE;
                    } else {
                        // conversion to array
                        return false;
                    }
                } else {
                    values[i] = obj_to_cast;
                    try {
                        types[i] = Class.forName(castTo_name, true, dynamicLoader);
                    } catch (ClassNotFoundException ex) {
                        getEngine().logger.warn("Java class not found: " + castTo_name);
                        return false;
                    }
                }
            } else {
                values[i] = null;
                switch (castTo_name) {
                case "byte":
                    types[i] = Byte.TYPE;
                    break;
                case "short":
                    types[i] = Short.TYPE;
                    break;
                case "char":
                    types[i] = Character.TYPE;
                    break;
                case "int":
                    types[i] = Integer.TYPE;
                    break;
                case "long":
                    types[i] = java.lang.Long.TYPE;
                    break;
                case "float":
                    types[i] = java.lang.Float.TYPE;
                    break;
                case "double":
                    types[i] = java.lang.Double.TYPE;
                    break;
                case "boolean":
                    types[i] = Boolean.TYPE;
                    break;
                default:
                    try {
                        types[i] = Class.forName(castTo_name, true, dynamicLoader);
                    } catch (ClassNotFoundException ex) {
                        getEngine().logger.warn("Java class not found: " + castTo_name);
                        return false;
                    }
                    break;
                }
            }
        } else {
            Number num = (Number) castWhat;
            String castTo_name = ((Struct) castTo).getName();
            switch (castTo_name) {
            case "byte":
                values[i] = new Byte((byte) num.intValue());
                types[i] = Byte.TYPE;
                break;
            case "short":
                values[i] = new Short((short) num.intValue());
                types[i] = Short.TYPE;
                break;
            case "int":
                values[i] = new Integer(num.intValue());
                types[i] = Integer.TYPE;
                break;
            case "long":
                values[i] = new java.lang.Long(num.longValue());
                types[i] = java.lang.Long.TYPE;
                break;
            case "float":
                values[i] = new java.lang.Float(num.floatValue());
                types[i] = java.lang.Float.TYPE;
                break;
            case "double":
                values[i] = new java.lang.Double(num.doubleValue());
                types[i] = java.lang.Double.TYPE;
                break;
            default:
                return false;
            }
        }
    } catch (Exception ex) {
        getEngine().logger.warn("Casting " + castWhat + " to " + castTo + " failed");
        return false;
    }
    return true;
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstPgSql.CFAstPgSqlSchema.java

public static Short getNullableInt16(ResultSet reader, int colidx) {
    try {//ww w  . j  a va2s  . co  m
        short val = reader.getShort(colidx);
        if (reader.wasNull()) {
            return (null);
        } else {
            return (new Short(val));
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(CFAstPgSqlSchema.class, "getNullableInt64", e);
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseSchema.java

public static Short getNullableInt16(ResultSet reader, int colidx) {
    try {/* w w  w. ja  va 2s .c o  m*/
        short val = reader.getShort(colidx);
        if (reader.wasNull()) {
            return (null);
        } else {
            return (new Short(val));
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(CFAstSybaseSchema.class, "getNullableInt64", e);
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstMySql.CFAstMySqlSchema.java

public static Short getNullableInt16(ResultSet reader, int colidx) {
    try {/*  ww w  . j ava2  s .c  o  m*/
        short val = reader.getShort(colidx);
        if (reader.wasNull()) {
            return (null);
        } else {
            return (new Short(val));
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(CFAstMySqlSchema.class, "getNullableInt64", e);
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstDb2LUW.CFAstDb2LUWSchema.java

public static Short getNullableInt16(ResultSet reader, int colidx) {
    try {// w w w . ja v a2 s .c o m
        short val = reader.getShort(colidx);
        if (reader.wasNull()) {
            return (null);
        } else {
            return (new Short(val));
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(CFAstDb2LUWSchema.class, "getNullableInt64", e);
    }
}

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

public void testToList_Short() {
    List expected = new ArrayList();
    expected.add(new Integer(1));
    expected.add(new Integer(2));
    List shorts = new ArrayList();
    shorts.add(new Short((short) 1));
    shorts.add(new Short((short) 2));
    JSONArray jsonArray = JSONArray.fromObject(shorts);
    List actual = JSONArray.toList(jsonArray);
    Assertions.assertEquals(expected, actual);
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstOracle.CFAstOracleSchema.java

public static Short getNullableInt16(ResultSet reader, int colidx) {
    try {/*w  w  w.  java2 s .  c o m*/
        short val = reader.getShort(colidx);
        if (reader.wasNull()) {
            return (null);
        } else {
            return (new Short(val));
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(CFAstOracleSchema.class, "getNullableInt64", e);
    }
}

From source file:net.sourceforge.msscodefactory.cfensyntax.v2_2.CFEnSyntaxMySql.CFEnSyntaxMySqlSchema.java

public static Short getNullableInt16(ResultSet reader, int colidx) {
    try {/*from w w w.j a  va 2  s  .  com*/
        short val = reader.getShort(colidx);
        if (reader.wasNull()) {
            return (null);
        } else {
            return (new Short(val));
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(CFEnSyntaxMySqlSchema.class, "getNullableInt64",
                e);
    }
}

From source file:org.apache.manifoldcf.crawler.connectors.meridio.meridiowrapper.MeridioWrapper.java

public long getUserIdFromName(String userName) throws RemoteException, MeridioDataSetException {
    if (oLog != null && oLog.isDebugEnabled())
        oLog.debug("Meridio: Entering getUserIdFromName method\n" + "User name is <" + userName + ">");

    //=============================================================
    // Create the search criteria to determine the user id
    ///*from w w  w  .ja  v a 2s. c  om*/
    // Create a dataset and a property terms row (search for
    // user properties
    //=============================================================
    DMDataSet dsSearchCriteria = new DMDataSet();
    PROPERTY_TERMS drUserSearch = new PROPERTY_TERMS();

    //=============================================================
    // Populate the property row with the search criteria
    //
    // Find the user that matches based on their name
    //=============================================================
    drUserSearch.setId(1);
    drUserSearch.setTermType(new Short("0").shortValue()); // STRING
    drUserSearch.setPropertyName("PROP_loginName");
    drUserSearch.setStr_relation(new Short("0").shortValue()); // IS
    drUserSearch.setStr_value(userName);
    drUserSearch.setParentId(1);
    dsSearchCriteria.addPROPERTY_TERMS(drUserSearch);

    //=============================================================
    // Only return the user account if it is enabled
    //=============================================================
    PROPERTY_TERMS drUserEnabled = new PROPERTY_TERMS();
    drUserEnabled.setId(2);
    drUserEnabled.setTermType(new Short("1").shortValue()); // NUMBER
    drUserEnabled.setPropertyName("PROP_enabled");
    drUserEnabled.setNum_relation(new Short("0").shortValue()); // EQUAL
    drUserEnabled.setNum_value(1);
    drUserEnabled.setParentId(1);
    dsSearchCriteria.addPROPERTY_TERMS(drUserEnabled);

    //=============================================================
    // 'AND' the two terms together
    //=============================================================
    PROPERTY_OPS drPropertyOps = new PROPERTY_OPS();
    drPropertyOps.setId(1);
    drPropertyOps.setOperator(new Short("0").shortValue()); //AND
    dsSearchCriteria.addPROPERTY_OPS(drPropertyOps);

    //=============================================================
    // Create the result definitions criteria: just the user ID is
    // required
    //=============================================================
    RESULTDEFS drResultDefs = new RESULTDEFS();
    drResultDefs.setPropertyName("PROP_id");
    drResultDefs.setIsVersionProperty(false);
    dsSearchCriteria.addRESULTDEFS(drResultDefs);

    DMSearchResults dsSearchResults = null;
    dsSearchResults = this.searchUsers(dsSearchCriteria, 1, 1, false);

    long rval;

    if (dsSearchResults.totalHitsCount != 1 || null == dsSearchResults.dsDM)
        rval = 0L;
    else
        rval = dsSearchResults.dsDM.getSEARCHRESULTS_USERS()[0].getUserId();

    if (oLog != null)
        oLog.debug("Meridio: Exiting searchUsers method.");

    return rval;
}