Example usage for java.lang Integer shortValue

List of usage examples for java.lang Integer shortValue

Introduction

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

Prototype

public short shortValue() 

Source Link

Document

Returns the value of this Integer as a short after a narrowing primitive conversion.

Usage

From source file:org.mifos.customers.persistence.CustomerDaoHibernate.java

@SuppressWarnings("unchecked")
private Money retrieveTotalForQuery(String query, final String searchId, final Short officeId) {
    Map<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put("SEARCH_STRING1", searchId);
    queryParameters.put("SEARCH_STRING2", searchId + ".%");
    queryParameters.put("OFFICE_ID", officeId);
    List queryResult = this.genericDao.executeNamedQuery(query, queryParameters);

    if (queryResult.size() > 1) {
        throw new CurrencyMismatchException(ExceptionConstants.ILLEGALMONEYOPERATION);
    }/*from  w  w  w.j  av  a2s.c  o  m*/
    if (queryResult.size() == 0) {
        // if we found no results, then return zero using the default currency
        return new Money(Money.getDefaultCurrency(), "0.0");
    }
    Integer currencyId = (Integer) ((Object[]) queryResult.get(0))[0];
    MifosCurrency currency = AccountingRules.getCurrencyByCurrencyId(currencyId.shortValue());

    BigDecimal total = (BigDecimal) ((Object[]) queryResult.get(0))[1];

    return new Money(currency, total);
}

From source file:pltag.parser.semantics.DepTreeState.java

/**
 * Grab argument information from the (potentially argument-complete) subtree rooted on the child node
 * that is attaching on the integration point of <code>arc</code>. We search through the dependencies
 * we have already encountered.//from   w w  w. ja  va2 s . c  o m
 * @param arc
 * @param coveredNodes
 * @param offsetNodeIdsOfShadowTree
 * @param tree
 * @param timestamp
 * @return 
 */
private boolean fillArgumentFromChildNode(DependencyArc arc, DualHashBidiMap<Integer, Integer> coveredNodes,
        DualHashBidiMap<Short, Short> offsetNodeIdsOfShadowTree, ElementaryStringTree tree, String[] words,
        String[] origPosTags, int timestamp) {
    boolean filled = false;
    if (arc.getArgument() != null) // TODO Investigate
    {
        int idOfArgOnPrefix = arc.getArgument().getId();
        Short idOfArgOnShadow = offsetNodeIdsOfShadowTree.getKey((short) idOfArgOnPrefix);
        if (idOfArgOnShadow != null) {

            Integer idOfArgOnVerif = coveredNodes.get((int) idOfArgOnShadow);
            if (idOfArgOnVerif != null) {
                for (int childId : tree.getChildren(idOfArgOnVerif)) {
                    Integer childIdOnShadow = coveredNodes.getKey(childId);
                    if (childIdOnShadow != null) {
                        Collection<DependencyArc> childArcs = dependencies.getDependenciesByIntegPoint(
                                new DepNode(offsetNodeIdsOfShadowTree.get(childIdOnShadow.shortValue()),
                                        timestamp));
                        if (childArcs != null) {
                            Iterator<DependencyArc> iterator = childArcs.iterator();
                            while (iterator.hasNext()) {
                                DependencyArc childArc = iterator.next();
                                if (!childArc.isArgumentIncomplete()) // make sure the dependency has argument information
                                {
                                    setArgument(arc, childArc.getArgument(), iterator, words, origPosTags, "V",
                                            true, false);
                                    filled = true;
                                }
                            } // if
                        } // for
                    }
                } // for
            } // if
        }
    } // if
    return filled;
}

From source file:de.micromata.genome.db.jpa.logging.BaseJpaLoggingImpl.java

/**
 * {@inheritDoc}//ww w. j a  va2  s . c o  m
 *
 */

@Override
protected void selectLogsImpl(Timestamp start, Timestamp end, Integer loglevel, String category, String msg,
        List<Pair<String, String>> logAttributes, final int startRow, final int maxRow, List<OrderBy> orderBy,
        final boolean masterOnly, final LogEntryCallback callback) throws EndOfSearch {

    final StopWatch sw = new StopWatch();
    sw.start();

    final StringBuilder queryStringBuilder = new StringBuilder(
            "select lm from " + getMasterClass().getName() + "  as lm");
    if (masterOnly == false) {
        queryStringBuilder.append(" left outer join fetch lm.attributes");
    }

    boolean firstWhere = true;
    // final List<Object> args = new ArrayList<Object>();
    Map<String, Object> argmap = new HashMap<>();
    if (start != null) {
        firstWhere = addWhere(queryStringBuilder, firstWhere, "lm.createdAt >= :createdAtMin");
        argmap.put("createdAtMin", start);
    }
    if (end != null) {
        firstWhere = addWhere(queryStringBuilder, firstWhere, "lm.createdAt <= :createdAtMax");
        argmap.put("createdAtMax", end);
    }
    if (loglevel != null) {
        firstWhere = addWhere(queryStringBuilder, firstWhere, "lm.loglevel >= :logLevelMin");
        argmap.put("logLevelMin", new Short(loglevel.shortValue()));
    }
    if (StringUtils.isNotBlank(category) == true) {
        firstWhere = addWhere(queryStringBuilder, firstWhere, "lm.category = :category");
        argmap.put("category", category);
    }
    if (StringUtils.isNotBlank(msg) == true) {
        firstWhere = addWhere(queryStringBuilder, firstWhere, "lm.shortmessage like :message");
        argmap.put("message", msg + "%");
    }
    if (logAttributes != null) {
        int attrNum = 0;
        for (Pair<String, String> pat : logAttributes) {
            ++attrNum;
            LogAttributeType at = getAttributeTypeByString(pat.getFirst());
            if (at == null) {
                GLog.warn(GenomeLogCategory.Configuration,
                        "SelLogs; Cannot find LogAttribute: " + pat.getFirst());
                continue;
            }
            if (at.isSearchKey() == false) {
                GLog.warn(GenomeLogCategory.Configuration,
                        "SelLogs; LogAttribute not searchable: " + pat.getFirst());
                continue;
            }
            if (StringUtils.contains(pat.getSecond(), "%") == false) {
                firstWhere = addWhere(queryStringBuilder, firstWhere, at.columnName(), " = :attr" + attrNum);
            } else {
                firstWhere = addWhere(queryStringBuilder, firstWhere, at.columnName(), " like :attr" + attrNum);
            }

            argmap.put("attr" + attrNum, pat.getSecond());
        }
    }

    if (CollectionUtils.isEmpty(orderBy) == false) {
        queryStringBuilder.append(" order by ");
        boolean first = true;
        for (OrderBy order : orderBy) {
            if (first == true) {
                first = false;
            } else {
                queryStringBuilder.append(", ");
            }
            String propertyName = convertColumnNameToPropertyName(order.getColumn());
            queryStringBuilder.append("lm.").append((propertyName != null) ? propertyName : order.getColumn()); // eventually
            // requires
            // translation
            // to
            // propertynames
            queryStringBuilder.append(order.isDescending() ? " desc" : " asc");
        }
    }

    EmgrFactory<DefaultEmgr> mgrfac = getEmgrFactory();
    mgrfac.runInTrans(new EmgrCallable<Void, DefaultEmgr>() {
        @Override
        public Void call(DefaultEmgr mgr) {

            Query query = mgr.createQuery(queryStringBuilder.toString());
            for (Map.Entry<String, Object> arg : argmap.entrySet()) {
                query.setParameter(arg.getKey(), arg.getValue());
            }
            query.setFirstResult(startRow);
            if (masterOnly == true) {
                query.setMaxResults(maxRow);
            } else {
                query.setMaxResults(maxRow * 10); // pessimistic assumption:
                // 10 attributes per
                // master entry
            }

            List<M> res = query.getResultList();

            for (M lmDo : res) {
                LogEntry le = new LogEntry();
                copyMasterFields(le, lmDo, masterOnly);
                try {
                    callback.onRow(le);
                } catch (EndOfSearch eos) {
                    break;
                }
            }
            return null;
        }
    });
}

From source file:pltag.parser.semantics.DepTreeState.java

/**
 * /*from   w  ww .j  a v a  2s .co m*/
//     * @param coveredNodes map of verification node ids to (verified) shadow tree node ids
 * @param elemTreeState
 * @param coveredNodes map of (verified) shadow tree node ids to verification node ids
 * @param tree
 * @param ipIdOffset
 * @param offsetNodeIdsOfShadowTree 
 * @param shadowTreeRoot 
 * @param words 
 * @param origPosTags
 * @param operation the parsing operation applied (adjunction, substitution, verification or initial)     
 * @param timestamp 
 */
public void updateDependencies(TreeState elemTreeState, DualHashBidiMap<Integer, Integer> coveredNodes,
        ElementaryStringTree tree, short ipIdOffset, DualHashBidiMap<Short, Short> offsetNodeIdsOfShadowTree,
        Node shadowTreeRoot, String[] words, String[] origPosTags, String operation, int timestamp) {
    retainInfoFromTreeHeuristics(elemTreeState, shadowTreeRoot, tree, ipIdOffset, false, timestamp, true,
            coveredNodes, offsetNodeIdsOfShadowTree);
    DepNode anchorNode = getAnchorNode(tree, ipIdOffset, timestamp);
    Set<Integer> processedNodes = new HashSet<>();
    // First check if the verifying tree has roles
    if (tree.hasRoles()) {
        MultiValueMap<Integer, Role> rolesPerNode = getRolesPerNode(tree, ipIdOffset);
        // Browse through all candidate integration points
        for (Integer ipCandidate : rolesPerNode.keySet()) {
            processedNodes.add(ipCandidate);
            // find the ones that are part of the verification tree, hence exist on the prefix tree as part of shadow trees
            Integer shadowNodeId = coveredNodes.getKey(ipCandidate - ipIdOffset);
            if (shadowNodeId != null) {
                // find the arc with the partially complete dependency
                Short offsetShadowId = offsetNodeIdsOfShadowTree.get(shadowNodeId.shortValue());
                if (offsetShadowId != null) {
                    Collection<DependencyArc> arcs = dependencies
                            .getDependenciesByIntegPoint(new DepNode(offsetShadowId.shortValue(), timestamp));
                    if (arcs != null) {
                        //                            for(DependencyArc arc : arcs)
                        Iterator<DependencyArc> iterator = arcs.iterator();
                        while (iterator.hasNext()) {
                            DependencyArc arc = iterator.next();
                            if (arc.isIncomplete()) {
                                if (tree.isRelation() && arc.isRelationIncomplete()) // avoid filling in an already complete relation entry
                                {
                                    filterRoles(arc, rolesPerNode.getCollection(ipCandidate));
                                    setRelation(arc, anchorNode, iterator, words, origPosTags, operation, true,
                                            false);
                                    // possibly created a complete arc, so we can identify and disambiguate role labels discriminatively
                                    boolean keepArc = identifyArcAndDisambiguateRoles(model, arc, words,
                                            origPosTags);
                                    if (!keepArc)
                                        removeArcSafe(arc, arc.getIntegrationPoint(), iterator);
                                }
                                //                        else if(!tree.isRelation() && arc.isArgumentIncomplete())
                                // removed restriction of above if statement: a relation can be an argument to another relation
                                else if (arc.isArgumentIncomplete()) {
                                    filterRoles(arc, rolesPerNode.getCollection(ipCandidate));
                                    if (applyConllHeuristics) // Apply infinitive marker heuristic, if necessary
                                        applyInfinitiveMarkerHeuristic(arc, anchorNode, iterator, words,
                                                origPosTags, operation, true, false);
                                    else {
                                        // Apply PP heuristic, if neceessary
                                        boolean keepArc = applyPPArgumentHeuristic(arc, tree, anchorNode,
                                                ipIdOffset, words, origPosTags, operation, true, false);
                                        // Apply infinitive marker heuristic, if necessary
                                        if (keepArc)
                                            applyInfinitiveMarkerHeuristic(arc, anchorNode, iterator, words,
                                                    origPosTags, operation, true, false);
                                    }
                                    //                            setArgument(arc, anchorNode);
                                }
                            } // if
                        } //for
                    } // if
                } // if                    
                else // the shadow sub-tree of the prefix tree doesn't have a role. Proceed with the normal addition of a new dependency
                {
                    addDependency(new DepNode(ipCandidate, timestamp), tree,
                            (short) (ipCandidate.shortValue() - ipIdOffset), ipIdOffset, rolesPerNode,
                            shadowTreeRoot, false, words, origPosTags, operation, true, timestamp);
                    //                        System.out.println("Check! If we never end up here, consider dropping the if statement above");
                }
            } // if
              // integration points on the elementary tree that are not verifying a shadow sub-tree on the prefix tree.
              // we need to consider it as an incomplete dependency
            else {
                addIncompleteDependency(ipCandidate, tree, ipIdOffset, false, tree.isRelation(),
                        rolesPerNode.getCollection(ipCandidate), null, words, origPosTags, operation, true,
                        timestamp);
            }
        } // for all candidate ips
    } // if hasRoles
      // Process the rest of the covered nodes in the shadow subtree of the prefix tree that have a role, hence a dependency arc already observed
    for (Entry<Integer, Integer> e : coveredNodes.entrySet()) {
        DependencyArc arc;
        Short offsetShadowId = offsetNodeIdsOfShadowTree.get(e.getValue().shortValue());
        if (offsetShadowId != null && !processedNodes.contains(e.getValue() + ipIdOffset)) {
            Collection<DependencyArc> arcsByIp = dependencies
                    .getDependenciesByIntegPoint(new DepNode(offsetShadowId.shortValue(), timestamp));
            //                if((arc = dependencies.pollArcWithShadowArg(new DepNode(offsetShadowId.shortValue(), timestamp))) != null)
            //                if((arc = dependencies.getArcWithShadowArg(new DepNode(offsetShadowId.shortValue(), timestamp))) != null)
            //                {
            //                    updateDependenciesUnderCoveredNode(tree, coveredNodes, offsetNodeIdsOfShadowTree, timestamp, anchorNode, arc, null, origPosTags);
            //                }
            //                else if(arcsByIp  != null)
            if (arcsByIp != null) {
                //                    for(DependencyArc arcByIp : arcsByIp)
                Iterator<DependencyArc> iterator = arcsByIp.iterator();
                while (iterator.hasNext()) {
                    DependencyArc arcByIp = iterator.next();
                    updateDependenciesUnderCoveredNode(tree, coveredNodes, offsetNodeIdsOfShadowTree, timestamp,
                            anchorNode, arcByIp, iterator, words, origPosTags);
                }
            }
        }
    }
    if (tree.isRelation()) {
        addHangingRelation(tree, ipIdOffset, words, origPosTags, operation, true, false, timestamp);
    }
    dependencies.postProcessArcs(operation, true, false);
}

From source file:edu.ku.brc.specify.config.init.DataBuilder.java

public static WorkbenchDataItem createWorkbenchDataItem(final WorkbenchRow workbenchRow, final String cellData,
        final Integer columnNumber) {

    WorkbenchDataItem wbdi = workbenchRow.setData(cellData, columnNumber.shortValue(), true);

    if (wbdi != null) {
        wbdi.setRowNumber(workbenchRow.getRowNumber());
        persist(wbdi);//from www.ja v  a2 s  .  c om

    } else {
        //System.err.println("workbenchRow.setData returned a null DataItem cellData["+cellData+"] or columnNumber["+columnNumber+"]");
    }

    return wbdi;
}

From source file:net.sf.jasperreports.engine.export.JRXlsExporter.java

@Override
protected void closeSheet() {
    if (sheet == null) {
        return;// w  w  w .j a va 2s .  co m
    }

    HSSFPrintSetup printSetup = sheet.getPrintSetup();

    if (isValidScale(sheetInfo.sheetPageScale)) {
        printSetup.setScale((short) sheetInfo.sheetPageScale.intValue());
    } else {
        XlsReportConfiguration configuration = getCurrentItemConfiguration();

        Integer fitWidth = configuration.getFitWidth();
        if (fitWidth != null) {
            printSetup.setFitWidth(fitWidth.shortValue());
            sheet.setAutobreaks(true);
        }

        Integer fitHeight = configuration.getFitHeight();
        fitHeight = fitHeight == null ? (Boolean.TRUE == configuration.isAutoFitPageHeight()
                ? (pageIndex - sheetInfo.sheetFirstPageIndex)
                : null) : fitHeight;
        if (fitHeight != null) {
            printSetup.setFitHeight(fitHeight.shortValue());
            sheet.setAutobreaks(true);
        }
    }
}

From source file:edu.ku.brc.specify.config.init.DataBuilder.java

public static WorkbenchTemplateMappingItem createWorkbenchMappingItem(final String tableName,
        final Integer tableId, final String fieldName, final String caption, final int dataLength,
        final Integer viewOrder, final Integer dataColumnIndex, final WorkbenchTemplate template) {
    WorkbenchTemplateMappingItem wtmi = new WorkbenchTemplateMappingItem();
    wtmi.initialize();/*from w w  w  .ja v  a  2 s . co  m*/

    wtmi.setCaption(caption);
    wtmi.setFieldName(fieldName);
    wtmi.setTableName(tableName.toLowerCase());
    wtmi.setViewOrder(viewOrder.shortValue());
    wtmi.setDataFieldLength((short) dataLength);
    wtmi.setOrigImportColumnIndex(dataColumnIndex.shortValue());
    wtmi.setWorkbenchTemplate(template);
    wtmi.setSrcTableId(tableId);

    template.getWorkbenchTemplateMappingItems().add(wtmi);

    persist(wtmi);

    return wtmi;
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

byte[] encodeActivateHealth(boolean activate) {
    byte[] blob;//from   w w w  .  j  ava 2 s. co  m
    if (activate) {

        ByteBuffer buf = ByteBuffer.allocate(9);
        buf.order(ByteOrder.LITTLE_ENDIAN);

        ActivityUser activityUser = new ActivityUser();
        Integer heightMm = activityUser.getHeightCm() * 10;
        buf.putShort(heightMm.shortValue());
        Integer weigthDag = activityUser.getWeightKg() * 100;
        buf.putShort(weigthDag.shortValue());
        buf.put((byte) 0x01); //activate tracking
        buf.put((byte) 0x00); //activity Insights
        buf.put((byte) 0x00); //sleep Insights
        buf.put((byte) activityUser.getAge());
        buf.put((byte) activityUser.getGender());
        blob = buf.array();
    } else {
        blob = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
    }
    return encodeBlobdb("activityPreferences", BLOBDB_INSERT, BLOBDB_PREFERENCES, blob);
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.TemplateEditor.java

/**
 * @param item//from   w ww.j  ava 2  s . c om
 * @return
 */
protected boolean updateMappingItem(FieldMappingPanel fmp, WorkbenchTemplateMappingItem item) {
    if (fmp.getFieldInfo() == null) {
        return false;
    }

    ImportColumnInfo colInfo = fmp.getColInfo();
    FieldInfo fieldInfo = fmp.getFieldInfo();

    item.setCaption(colInfo.getCaption());
    item.setImportedColName(colInfo.getColName());
    item.setXCoord(Integer.valueOf(colInfo.getFormXCoord()).shortValue());
    item.setYCoord(Integer.valueOf(colInfo.getFormYCoord()).shortValue());
    item.setFieldType(Integer.valueOf(colInfo.getFrmFieldType()).shortValue());
    item.setMetaData(colInfo.getFrmMetaData());

    Integer origColNum = fmp.isAdded() ? -1 : colInfo.getColInx();

    item.setFieldName(fieldInfo.getFieldInfo().getName());
    item.setSrcTableId(fieldInfo.getTableinfo().getTableId());
    item.setTableName(fieldInfo.getTableinfo().getName());
    short len = (short) fieldInfo.getFieldInfo().getLength();
    item.setDataFieldLength(len == -1 ? 15 : len);

    item.setViewOrder(fmp.getViewOrder());
    item.setOrigImportColumnIndex(origColNum.shortValue());

    return true;
}

From source file:com.odap.server.audit.ConfigHandler.java

public ConfigMessage registerNewServer(ConfigMessage config) throws TException {
    logger.info("Enter registerNewServer()");
    ConfigMessage msg = new ConfigMessage();

    QueryRunner qRunner = new QueryRunner();

    Integer account_id = null;//  w w  w.j a  v a2 s. co  m
    Integer server_id = null;
    //Authenticate the user and get the account_id;
    String query = "SELECT * FROM joomla.cloud_users WHERE username = ? AND password = ?";
    {
        String parameters[] = { config.getUsername().replaceAll("[^A-Za-z0-9 ]", ""),
                DigestUtils.md5Hex(config.getPassword().replaceAll("[^A-Za-z0-9 ]", "")) };
        try {
            List<Map<String, Object>> mapList = (List<Map<String, Object>>) qRunner
                    .query(AuditServer.connectionPool.getConnection(), query, new MapListHandler(), parameters);

            if (mapList.size() < 1) {
                logger.warn("Username " + config.getUsername() + " not authenticated");
                return msg;
            }

            account_id = (Integer) mapList.get(0).get("account_id");

        } catch (SQLException e) {
            logger.error("Issue finding user account", e);
            return msg;
        }
    }

    String session_id = nextSessionId();
    {
        try {
            {
                query = "INSERT INTO servers (account_id,server_name,server_software,server_port,server_authentication_token,server_timezone,strip_predicates) VALUES (?,?,?,?,?,?,?)";
                Object parameters[] = { account_id.toString(),
                        config.getServer_name().replaceAll("[^A-Za-z0-9 ]", ""), config.getServer_software(),
                        new Short(config.getPort()), session_id, new Double(config.getTimezone_offset()),
                        config.strip_predicates };
                qRunner.update(AuditServer.connectionPool.getConnection(), query, parameters);
            }
            {
                String parameters[] = { account_id.toString(), config.getServer_name(), session_id };
                query = "SELECT * FROM servers WHERE account_id = ? AND server_name = ? and server_authentication_token = ?";
                List<Map<String, Object>> mapList = (List<Map<String, Object>>) qRunner.query(
                        AuditServer.connectionPool.getConnection(), query, new MapListHandler(), parameters);

                if (mapList.size() < 1) {
                    logger.error("Unable to find server after after registering it");
                    return msg;
                }

                server_id = (Integer) mapList.get(0).get("id");
            }
        } catch (SQLException e) {
            logger.error("Issue registering server", e);
        }
    }

    msg.token = session_id;
    msg.server_id = server_id.shortValue();
    msg.server = "dbauditcloud.com";
    logger.info("Exiting registerNewServer()");
    return msg;
}