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.mifos.accounts.loan.business.LoanBOIntegrationTest.java

public void testCreateLoanAccountWithDecliningInterestGracePrincipalOnly() throws Exception {

    BigDecimal savedInitialRoundingMode = AccountingRules.getInitialRoundOffMultiple();
    BigDecimal savedFinalRoundingMode = AccountingRules.getFinalRoundOffMultiple();

    AccountingRules.setInitialRoundOffMultiple(new BigDecimal("0.1"));
    AccountingRules.setFinalRoundOffMultiple(new BigDecimal("0.1"));

    try {//from   ww w  .  j  a va 2s.c o m
        short graceDuration = (short) 2;
        MeetingBO meeting = TestObjectFactory.createMeeting(
                TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_SECOND_WEEK, CUSTOMER_MEETING));
        center = TestObjectFactory.createWeeklyFeeCenter(this.getClass().getSimpleName() + " Center", meeting);
        group = TestObjectFactory.createWeeklyFeeGroupUnderCenter(this.getClass().getSimpleName() + " Group",
                CustomerStatus.GROUP_ACTIVE, center);
        LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering("Loan", "L", ApplicableTo.GROUPS,
                new Date(System.currentTimeMillis()), PrdStatus.LOAN_ACTIVE, 300.0, 12.0, (short) 3,
                InterestType.DECLINING, false, false, center.getCustomerMeeting().getMeeting(),
                GraceType.PRINCIPALONLYGRACE, "1", "1");
        List<FeeView> feeViewList = new ArrayList<FeeView>();

        accountBO = loanDao.createLoan(TestUtils.makeUser(), loanOffering, group,
                AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, new Money(getCurrency(), "300.0"),
                Short.valueOf("6"), new Date(System.currentTimeMillis()), false, // 6 installments
                12.0, graceDuration, null, feeViewList, null, DOUBLE_ZERO, DOUBLE_ZERO, SHORT_ZERO, SHORT_ZERO,
                false);
        new TestObjectPersistence().persist(accountBO);
        Assert.assertEquals(6, accountBO.getAccountActionDates().size());

        Map<String, String> fees0 = new HashMap<String, String>();

        Set<AccountActionDateEntity> actionDateEntities = ((LoanBO) accountBO).getAccountActionDates();
        LoanScheduleEntity[] paymentsArray = LoanBOTestUtils
                .getSortedAccountActionDateEntity(actionDateEntities);

        checkLoanScheduleEntity(incrementCurrentDate(14 * 1), "0.0", "1.4", fees0, paymentsArray[0]);

        checkLoanScheduleEntity(incrementCurrentDate(14 * 2), "0.0", "1.4", fees0, paymentsArray[1]);

        checkLoanScheduleEntity(incrementCurrentDate(14 * 3), "74.5", "1.4", fees0, paymentsArray[2]);

        checkLoanScheduleEntity(incrementCurrentDate(14 * 4), "74.8", "1.1", fees0, paymentsArray[3]);

        checkLoanScheduleEntity(incrementCurrentDate(14 * 5), "75.2", "0.7", fees0, paymentsArray[4]);

        checkLoanScheduleEntity(incrementCurrentDate(14 * 6), "75.5", "0.3", fees0, paymentsArray[5]);

        LoanSummaryEntity loanSummaryEntity = ((LoanBO) accountBO).getLoanSummary();
        Assert.assertEquals(new Money(getCurrency(), "300.0"), loanSummaryEntity.getOriginalPrincipal());
    } finally {
        AccountingRules.setInitialRoundOffMultiple(savedInitialRoundingMode);
        AccountingRules.setFinalRoundOffMultiple(savedFinalRoundingMode);
    }
}

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

private AccountBO applyPaymentandRetrieveAccount() throws AccountException, SystemException {
    Date startDate = new Date(System.currentTimeMillis());
    PaymentData paymentData = PaymentData.createPaymentData(
            new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "212.0"),
            accountBO.getPersonnel(), Short.valueOf("1"), startDate);
    paymentData.setReceiptDate(startDate);
    paymentData.setReceiptNum("5435345");

    accountBO.applyPaymentWithPersist(paymentData);
    StaticHibernateUtil.commitTransaction();
    StaticHibernateUtil.closeSession();//from  w  ww .ja  v a  2s .c  om
    return TestObjectFactory.getObject(AccountBO.class, accountBO.getAccountId());
}

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

private AccountBO getLoanAccountWithMiscFeeAndPenalty(final AccountState state, final Date startDate,
        final int disbursalType, final Money miscFee, final Money miscPenalty) {
    LoanBO accountBO = getLoanAccount(state, startDate, disbursalType);
    for (AccountActionDateEntity accountAction : accountBO.getAccountActionDates()) {
        LoanScheduleEntity accountActionDateEntity = (LoanScheduleEntity) accountAction;
        if (accountActionDateEntity.getInstallmentId().equals(Short.valueOf("1"))) {
            accountActionDateEntity.setMiscFee(miscFee);
            accountActionDateEntity.setMiscPenalty(miscPenalty);
            break;
        }//from   ww  w  . j a  v a  2 s  .c o  m
    }
    LoanSummaryEntity loanSummaryEntity = accountBO.getLoanSummary();
    loanSummaryEntity.setOriginalFees(loanSummaryEntity.getOriginalFees().add(miscFee));
    loanSummaryEntity.setOriginalPenalty(loanSummaryEntity.getOriginalPenalty().add(miscPenalty));
    TestObjectPersistence testObjectPersistence = new TestObjectPersistence();
    testObjectPersistence.update(accountBO);
    return testObjectPersistence.getObject(LoanBO.class, accountBO.getAccountId());
}

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

private List<CustomFieldView> getCustomFields() {
    List<CustomFieldView> fields = new ArrayList<CustomFieldView>();
    fields.add(new CustomFieldView(Short.valueOf("5"), "value1", CustomFieldType.ALPHA_NUMERIC));
    return fields;
}

From source file:com.ah.ui.actions.hiveap.HiveApUpdateAction.java

private Map<Long, String> getSimpleUpdateImageIds(Set<Long> selectedIds, boolean forceUpdate) {
    FilterParams filter = null;//from   w  w w. j a va2  s  . c  om
    if (selectedIds != null && !selectedIds.isEmpty()) {
        filter = new FilterParams("id in (:s1)", new Object[] { selectedIds });
    }
    List<?> resList = QueryUtil.executeQuery(
            "select id, hiveApModel, softVer, hardwareRevision from " + HiveAp.class.getSimpleName(), null,
            filter);
    if (resList == null || resList.isEmpty()) {
        return null;
    }

    //get all devices model
    List<Short> allDeviceModels = DevicePropertyManage.getInstance().getAllDeviceKey();

    //mapping between hiveApModel and image file name.
    Map<Short, HiveApImageInfo> model_ImageInfo_Map = new HashMap<>();
    for (Short apModel : allDeviceModels) {
        HiveApImageInfo imageInfo = com.ah.be.config.image.ImageManager.getLatestImageName(apModel);
        if (imageInfo != null) {
            model_ImageInfo_Map.put(apModel, imageInfo);
        }
    }

    //mapping between device ID and image Name.
    Map<Long, String> idImageMap = new HashMap<>();
    Long devcieId;
    Short hiveApModel;
    String softver, hardwareRevision;
    for (Object queryObj : resList) {
        Object[] queryArg = (Object[]) queryObj;
        devcieId = Long.valueOf(queryArg[0].toString());
        hiveApModel = Short.valueOf(queryArg[1].toString());
        softver = queryArg[2].toString();
        hardwareRevision = queryArg[3] != null ? queryArg[3].toString() : null;
        if (hiveApModel == HiveAp.HIVEAP_MODEL_SR2124P && "01".equals(hardwareRevision)) {
            hiveApModel = (short) (0 - HiveAp.HIVEAP_MODEL_SR2124P);
        }

        if (!model_ImageInfo_Map.containsKey(hiveApModel)) {
            continue;
        }
        HiveApImageInfo imageInfo = model_ImageInfo_Map.get(hiveApModel);
        int verCompareInt = NmsUtil.compareSoftwareVersion(imageInfo.getImageVersionNum(), softver);
        if (verCompareInt > 0) {
            idImageMap.put(devcieId, imageInfo.getImageName());
        } else if (verCompareInt == 0 && forceUpdate) {
            idImageMap.put(devcieId, imageInfo.getImageName());
        }
    }

    return idImageMap;
}

From source file:org.apache.ambari.server.controller.AmbariManagementControllerTest.java

@Test
public void testCreateCustomActionNoCluster() throws Exception {
    String hostname1 = "h1";
    String hostname2 = "h2";
    addHost(hostname1);//from  ww w. ja v  a 2 s  .  c om
    addHost(hostname2);

    ambariMetaInfo.addActionDefinition(new ActionDefinition("a1", ActionType.SYSTEM, "", "", "",
            "action def description", TargetHostType.ANY, Short.valueOf("60")));

    Map<String, String> requestProperties = new HashMap<String, String>();
    requestProperties.put(REQUEST_CONTEXT_PROPERTY, "Called from a test");

    Map<String, String> requestParams = new HashMap<String, String>();
    requestParams.put("some_custom_param", "abc");

    // !!! target single host
    List<String> hosts = Arrays.asList(hostname1);
    RequestResourceFilter resourceFilter = new RequestResourceFilter(null, null, hosts);
    List<RequestResourceFilter> resourceFilters = new ArrayList<RequestResourceFilter>();
    resourceFilters.add(resourceFilter);

    ExecuteActionRequest actionRequest = new ExecuteActionRequest(null, null, "a1", resourceFilters, null,
            requestParams, false);
    RequestStatusResponse response = controller.createAction(actionRequest, requestProperties);
    assertEquals(1, response.getTasks().size());
    ShortTaskStatus taskStatus = response.getTasks().get(0);
    Assert.assertEquals(hostname1, taskStatus.getHostName());

    Stage stage = actionDB.getAllStages(response.getRequestId()).get(0);
    Assert.assertNotNull(stage);
    Assert.assertEquals(-1L, stage.getClusterId());

    List<HostRoleCommand> storedTasks = actionDB.getRequestTasks(response.getRequestId());
    Assert.assertEquals(1, storedTasks.size());
    HostRoleCommand task = storedTasks.get(0);
    Assert.assertEquals(RoleCommand.ACTIONEXECUTE, task.getRoleCommand());
    Assert.assertEquals("a1", task.getRole().name());
    Assert.assertEquals(hostname1, task.getHostName());

    ExecutionCommand cmd = task.getExecutionCommandWrapper().getExecutionCommand();
    Type type = new TypeToken<Map<String, String>>() {
    }.getType();
    Map<String, String> commandParamsStage = StageUtils.getGson().fromJson(stage.getCommandParamsStage(), type);
    Assert.assertTrue(commandParamsStage.containsKey("some_custom_param"));
    Assert.assertEquals(null, cmd.getServiceName());
    Assert.assertEquals(null, cmd.getComponentName());

    // !!! target two hosts

    hosts = Arrays.asList(hostname1, hostname2);
    resourceFilter = new RequestResourceFilter(null, null, hosts);
    resourceFilters = new ArrayList<RequestResourceFilter>();
    resourceFilters.add(resourceFilter);

    actionRequest = new ExecuteActionRequest(null, null, "a1", resourceFilters, null, requestParams, false);
    response = controller.createAction(actionRequest, requestProperties);
    assertEquals(2, response.getTasks().size());
    boolean host1Found = false;
    boolean host2Found = false;
    for (ShortTaskStatus sts : response.getTasks()) {
        if (sts.getHostName().equals(hostname1)) {
            host1Found = true;
        } else if (sts.getHostName().equals(hostname2)) {
            host2Found = true;
        }
    }
    Assert.assertTrue(host1Found);
    Assert.assertTrue(host2Found);

    stage = actionDB.getAllStages(response.getRequestId()).get(0);
    Assert.assertNotNull(stage);
    Assert.assertEquals(-1L, stage.getClusterId());

    storedTasks = actionDB.getRequestTasks(response.getRequestId());
    Assert.assertEquals(2, storedTasks.size());
    task = storedTasks.get(0);
    Assert.assertEquals(RoleCommand.ACTIONEXECUTE, task.getRoleCommand());
    Assert.assertEquals("a1", task.getRole().name());
    Assert.assertEquals(hostname1, task.getHostName());

    cmd = task.getExecutionCommandWrapper().getExecutionCommand();
    commandParamsStage = StageUtils.getGson().fromJson(stage.getCommandParamsStage(), type);
    Assert.assertTrue(commandParamsStage.containsKey("some_custom_param"));
    Assert.assertEquals(null, cmd.getServiceName());
    Assert.assertEquals(null, cmd.getComponentName());
}

From source file:uk.submergedcode.SubmergedCore.backup.PlayerBackup.java

/**
 * Convert a json array into an itemstack array
 *
 * @param array The json array to convert
 * @return An itemstack array of the given json array
 *///from  w ww .j av  a2 s.  com
@SuppressWarnings("deprecation")
private ItemStack[] JSONArrayToItemStackArray(JSONArray array) {

    List<ItemStack> items = new ArrayList<ItemStack>(array.size());

    for (Object itemObject : array) {

        if (!(itemObject instanceof JSONObject)) {
            continue;
        }

        JSONObject jsonItem = (JSONObject) itemObject;

        // Parse item
        ItemStack item = new ItemStack(Material.valueOf((String) jsonItem.get("type")));
        item.setAmount(Integer.valueOf((String) jsonItem.get("amount")));
        item.setDurability(Short.valueOf((String) jsonItem.get("durability")));
        item.getData().setData(Byte.valueOf((String) jsonItem.get("data")));

        // Parse enchantments
        JSONArray enchantments = (JSONArray) jsonItem.get("enchantment");
        for (Object enchantmentObject : enchantments) {

            if (!(enchantmentObject instanceof JSONObject)) {
                continue;
            }

            JSONObject jsonEnchantment = (JSONObject) enchantmentObject;
            Enchantment enchantment = Enchantment.getByName((String) jsonEnchantment.get("id"));
            int enchantmentLevel = Integer.valueOf((String) jsonEnchantment.get("level"));
            item.addUnsafeEnchantment(enchantment, enchantmentLevel);
        }

        // Parse metadata
        if (jsonItem.containsKey("metadata")) {

            JSONObject metaData = (JSONObject) jsonItem.get("metadata");

            ItemMeta itemMeta = item.getItemMeta();

            if (metaData.containsKey("displayname")) {
                itemMeta.setDisplayName((String) metaData.get("displayname"));
            }

            if (metaData.containsKey("lores")) {
                List<String> lores = new ArrayList<String>();
                JSONArray jsonLores = (JSONArray) metaData.get("lores");
                for (Object loreObject : jsonLores) {
                    String lore = (String) loreObject;
                    lores.add(lore);
                }
                itemMeta.setLore(lores);
            }

            item.setItemMeta(itemMeta);
        }

        items.add(item);
    }

    int itemIndex = 0;
    ItemStack[] itemArray = new ItemStack[items.size()];
    for (ItemStack item : items) {
        itemArray[itemIndex] = item;
        itemIndex++;
    }

    return itemArray;
}