List of usage examples for java.lang Short valueOf
@HotSpotIntrinsicCandidate public static Short valueOf(short s)
From source file:org.mifos.customers.office.business.service.OfficeServiceFacadeWebTier.java
@Override public OfficeDetailsForEdit retrieveOfficeDetailsForEdit(String officeLevel) { List<OfficeDetailsDto> parents = new ArrayList<OfficeDetailsDto>(); if (StringUtils.isNotBlank(officeLevel)) { parents = retrieveActiveParentOffices(Short.valueOf(officeLevel)); }// ww w .j a v a 2 s . c om try { List<OfficeDetailsDto> configuredOfficeLevels = new OfficePersistence().getActiveLevels(); for (OfficeDetailsDto officeDetailsDto : configuredOfficeLevels) { String levelName = ApplicationContextProvider.getBean(MessageLookup.class) .lookup(officeDetailsDto.getLevelNameKey()); officeDetailsDto.setLevelName(levelName); } List<OfficeDetailsDto> statusList = new OfficePersistence().getStatusList(); for (OfficeDetailsDto officeDetailsDto : statusList) { officeDetailsDto.setLevelName(ApplicationContextProvider.getBean(MessageLookup.class) .lookup(officeDetailsDto.getLevelNameKey())); } return new OfficeDetailsForEdit(parents, statusList, configuredOfficeLevels); } catch (PersistenceException e) { throw new MifosRuntimeException(e); } }
From source file:org.apache.ambari.server.controller.internal.HostStackVersionResourceProvider.java
@Override public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { Iterator<Map<String, Object>> iterator = request.getProperties().iterator(); String hostName;// w w w.ja v a2 s .c o m final String desiredRepoVersion; String stackName; String stackVersion; if (request.getProperties().size() > 1) { throw new UnsupportedOperationException("Multiple requests cannot be executed at the same time."); } Map<String, Object> propertyMap = iterator.next(); Set<String> requiredProperties = Sets.newHashSet(HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID, HOST_STACK_VERSION_REPO_VERSION_PROPERTY_ID, HOST_STACK_VERSION_STACK_PROPERTY_ID, HOST_STACK_VERSION_VERSION_PROPERTY_ID); for (String requiredProperty : requiredProperties) { Validate.isTrue(propertyMap.containsKey(requiredProperty), String.format("The required property %s is not defined", requiredProperty)); } String clName = (String) propertyMap.get(HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID); hostName = (String) propertyMap.get(HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID); desiredRepoVersion = (String) propertyMap.get(HOST_STACK_VERSION_REPO_VERSION_PROPERTY_ID); Host host; try { host = getManagementController().getClusters().getHost(hostName); } catch (AmbariException e) { throw new NoSuchParentResourceException(String.format("Can not find host %s", hostName), e); } AmbariManagementController managementController = getManagementController(); AmbariMetaInfo ami = managementController.getAmbariMetaInfo(); stackName = (String) propertyMap.get(HOST_STACK_VERSION_STACK_PROPERTY_ID); stackVersion = (String) propertyMap.get(HOST_STACK_VERSION_VERSION_PROPERTY_ID); final StackId stackId = new StackId(stackName, stackVersion); if (!ami.isSupportedStack(stackName, stackVersion)) { throw new NoSuchParentResourceException(String.format("Stack %s is not supported", stackId)); } Set<Cluster> clusterSet; if (clName == null) { try { clusterSet = getManagementController().getClusters().getClustersForHost(hostName); } catch (AmbariException e) { throw new NoSuchParentResourceException( String.format(("Host %s does not belong to any cluster"), hostName), e); } } else { Cluster cluster; try { cluster = getManagementController().getClusters().getCluster(clName); } catch (AmbariException e) { throw new NoSuchParentResourceException(String.format(("Cluster %s does not exist"), clName), e); } clusterSet = Collections.singleton(cluster); } Cluster cluster; if (clusterSet.isEmpty()) { throw new UnsupportedOperationException(String.format( "Host %s belongs " + "to 0 clusters with stack id %s. Performing %s action failed.", hostName, stackId, INSTALL_PACKAGES_FULL_NAME)); } else if (clusterSet.size() > 1) { throw new UnsupportedOperationException(String.format( "Host %s belongs " + "to %d clusters with stack id %s. Performing %s action on multiple " + "clusters is not supported", hostName, clusterSet.size(), stackId, INSTALL_PACKAGES_FULL_NAME)); } else { cluster = clusterSet.iterator().next(); } RepositoryVersionEntity repoVersionEnt = repositoryVersionDAO.findByStackAndVersion(stackId, desiredRepoVersion); if (repoVersionEnt == null) { throw new IllegalArgumentException( String.format("Repo version %s is not available for stack %s", desiredRepoVersion, stackId)); } HostVersionEntity hostVersEntity = hostVersionDAO.findByClusterStackVersionAndHost(clName, stackId, desiredRepoVersion, hostName); if (hostVersEntity == null) { throw new IllegalArgumentException( String.format("Repo version %s for stack %s is not available for host %s", desiredRepoVersion, stackId, hostName)); } if (hostVersEntity.getState() != RepositoryVersionState.INSTALLED && hostVersEntity.getState() != RepositoryVersionState.INSTALL_FAILED && hostVersEntity.getState() != RepositoryVersionState.OUT_OF_SYNC) { throw new UnsupportedOperationException(String.format( "Repo version %s for stack %s " + "for host %s is in %s state. Can not transition to INSTALLING state", desiredRepoVersion, stackId, hostName, hostVersEntity.getState().toString())); } List<OperatingSystemEntity> operatingSystems = repoVersionEnt.getOperatingSystems(); Map<String, List<RepositoryEntity>> perOsRepos = new HashMap<>(); for (OperatingSystemEntity operatingSystem : operatingSystems) { perOsRepos.put(operatingSystem.getOsType(), operatingSystem.getRepositories()); } // 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)); } // For every host at cluster, determine packages for all installed services List<ServiceOsSpecific.Package> packages = new ArrayList<>(); Set<String> servicesOnHost = new HashSet<>(); 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(stackName, stackVersion, serviceName); } catch (AmbariException e) { throw new SystemException("Can not 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>() { { put("stack_id", stackId.getStackId()); put("repository_version", desiredRepoVersion); put("base_urls", repoList); put("package_list", packageList); } }; // Create custom action RequestResourceFilter filter = new RequestResourceFilter(null, null, Collections.singletonList(hostName)); ActionExecutionContext actionContext = new ActionExecutionContext(cluster.getClusterName(), INSTALL_PACKAGES_ACTION, Collections.singletonList(filter), params); actionContext.setTimeout(Short.valueOf(configuration.getDefaultAgentTaskTimeout(true))); String caption = String.format(INSTALL_PACKAGES_FULL_NAME + " on host %s", hostName); RequestStageContainer req = createRequest(caption); Map<String, String> hostLevelParams = new HashMap<>(); hostLevelParams.put(JDK_LOCATION, getManagementController().getJdkResourceUrl()); // Generate cluster host info String clusterHostInfoJson; try { clusterHostInfoJson = StageUtils.getGson().toJson(StageUtils.getClusterHostInfo(cluster)); } catch (AmbariException e) { throw new SystemException("Could not build cluster topology", e); } Stage stage = stageFactory.createNew(req.getId(), "/tmp/ambari", cluster.getClusterName(), cluster.getClusterId(), caption, clusterHostInfoJson, "{}", StageUtils.getGson().toJson(hostLevelParams)); long stageId = req.getLastStageId() + 1; if (0L == stageId) { stageId = 1L; } stage.setStageId(stageId); req.addStages(Collections.singletonList(stage)); try { actionExecutionHelper.get().addExecutionCommandsToStage(actionContext, stage); } catch (AmbariException e) { throw new SystemException("Can not modify stage", e); } try { hostVersEntity.setState(RepositoryVersionState.INSTALLING); hostVersionDAO.merge(hostVersEntity); cluster.recalculateClusterVersionState(repoVersionEnt); req.persist(); } catch (AmbariException e) { throw new SystemException("Can not persist request", e); } return getRequestStatus(req.getRequestStatusResponse()); }
From source file:org.mifos.accounts.loan.business.LoanBORedoDisbursalIntegrationTest.java
@Ignore @Test/*from w ww .j a v a 2s . c o m*/ public void testRedoLoanApplyWholeMiscFeeBeforeRepayments() throws Exception { LoanBO loan = redoLoanWithMondayMeetingAndVerify(userContext, 14, new ArrayList<AccountFeesEntity>()); disburseLoanAndVerify(userContext, loan, 14); Double feeAmount = new Double("33.0"); Assert.assertTrue(MoneyUtils.isRoundedAmount(feeAmount)); applyCharge(loan, Short.valueOf(AccountConstants.MISC_FEES), feeAmount); Assert.assertFalse(loan.havePaymentsBeenMade()); LoanTestUtils.assertInstallmentDetails(loan, 1, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 2, 50.9, 0.1, 0.0, 33.0, 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.5, 0.5, 0.0, 0.0, 0.0); }
From source file:org.evosuite.testcase.statements.FunctionalMockStatement.java
public void fillWithNullRefs() { for (int i = 0; i < parameters.size(); i++) { VariableReference ref = parameters.get(i); if (ref == null) { Class<?> expected = getExpectedParameterType(i); Object value = null;//ww w. ja v a 2 s .co m if (expected.isPrimitive()) { //can't fill a primitive with null if (expected.equals(Integer.TYPE)) { value = 0; } else if (expected.equals(Float.TYPE)) { value = 0f; } else if (expected.equals(Double.TYPE)) { value = 0d; } else if (expected.equals(Long.TYPE)) { value = 0L; } else if (expected.equals(Boolean.TYPE)) { value = false; } else if (expected.equals(Short.TYPE)) { value = Short.valueOf("0"); } else if (expected.equals(Character.TYPE)) { value = 'a'; } } parameters.set(i, new ConstantValue(tc, new GenericClass(expected), value)); } } }
From source file:org.apache.hadoop.hive.ql.exec.GroupByOperator.java
/** * The size of the element at position 'pos' is returned, if possible. If the * field is of variable length, STRING, a list of such field names for the * field position is maintained, and the size for such positions is then * actually calculated at runtime./*from w w w .ja va 2 s .c o m*/ * * @param pos * the position of the key * @param c * the type of the key * @param f * the field to be added * @return the size of this datatype **/ private int getSize(int pos, Class<?> c, Field f) { if (c.isPrimitive() || c.isInstance(Boolean.valueOf(true)) || c.isInstance(Byte.valueOf((byte) 0)) || c.isInstance(Short.valueOf((short) 0)) || c.isInstance(Integer.valueOf(0)) || c.isInstance(Long.valueOf(0)) || c.isInstance(new Float(0)) || c.isInstance(new Double(0))) { return javaSizePrimitiveType; } if (c.isInstance(new String())) { int idx = 0; varLenFields v = null; for (idx = 0; idx < aggrPositions.size(); idx++) { v = aggrPositions.get(idx); if (v.getAggrPos() == pos) { break; } } if (idx == aggrPositions.size()) { v = new varLenFields(pos, new ArrayList<Field>()); aggrPositions.add(v); } v.getFields().add(f); return javaObjectOverHead; } return javaSizeUnknownType; }
From source file:org.mifos.customers.struts.actionforms.CustomerActionForm.java
public boolean isCustomerTrained() { return StringUtils.isNotBlank(trained) && Short.valueOf(trained).equals(YesNoFlag.YES.getValue()); }
From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java
public void testVerifyNoDateShiftWhenDisbursingAnLsimLoanWithModifiedDisbursalDate() throws Exception { short graceDuration = (short) 0; new DateTimeService().setCurrentDateTime(new LocalDate(2010, 2, 25).toDateTimeAtStartOfDay()); new ConfigurationPersistence() .updateConfigurationKeyValueInteger("repaymentSchedulesIndependentOfMeetingIsEnabled", 1); MeetingBO meeting = TestObjectFactory.createMeeting(new MeetingBuilder().buildMonthlyForDayNumber(1)); center = TestObjectFactory.createCenter(this.getClass().getSimpleName() + " Center", meeting, TestObjectFactory.SAMPLE_BRANCH_OFFICE, PersonnelConstants.TEST_USER, null); group = TestObjectFactory.createNoFeeGroupUnderCenter(this.getClass().getSimpleName() + " Group", CustomerStatus.GROUP_ACTIVE, center); client = TestObjectFactory.createClient(this.getClass().getSimpleName() + " Client", CustomerStatus.CLIENT_ACTIVE, group, null, (String) null, new Date(1222333444000L)); LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering("Loan", ApplicableTo.CLIENTS, new DateTimeService().getCurrentJavaDateTime(), PrdStatus.LOAN_ACTIVE, 300.0, 12.0, (short) 3, InterestType.DECLINING, center.getCustomerMeeting().getMeeting()); List<FeeView> feeViewList = new ArrayList<FeeView>(); boolean loanScheduleIndependentOfMeeting = true; accountBO = loanDao.createLoan(TestUtils.makeUser(), loanOffering, client, AccountState.LOAN_APPROVED, new Money(getCurrency(), "1000.0"), Short.valueOf("6"), new DateMidnight(2010, 3, 5).toDate(), false, // 6 installments 12.0, graceDuration, null, feeViewList, null, DOUBLE_ZERO, DOUBLE_ZERO, SHORT_ZERO, SHORT_ZERO, loanScheduleIndependentOfMeeting); new TestObjectPersistence().persist(accountBO); Assert.assertEquals(6, accountBO.getAccountActionDates().size()); Set<AccountActionDateEntity> actionDateEntities = ((LoanBO) accountBO).getAccountActionDates(); LoanScheduleEntity[] paymentsArray = LoanBOTestUtils.getSortedAccountActionDateEntity(actionDateEntities); Assert.assertEquals(new LocalDate(2010, 4, 1), new LocalDate(paymentsArray[0].getActionDate().getTime())); new DateTimeService().setCurrentDateTime(new LocalDate(2010, 3, 8).toDateTimeAtStartOfDay()); List<PaymentTypeEntity> paymentTypeEntities = new AcceptedPaymentTypeService() .getAcceptedPaymentTypes(TestObjectFactory.TEST_LOCALE); AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(accountBO, new Money(Money.getDefaultCurrency(), new BigDecimal(1000)), "", new DateTimeService().getCurrentJavaDateTime(), paymentTypeEntities.get(0), new DateTimeService().getCurrentJavaDateTime()); ((LoanBO) accountBO).disburseLoan(accountPaymentEntity); actionDateEntities = ((LoanBO) accountBO).getAccountActionDates(); paymentsArray = LoanBOTestUtils.getSortedAccountActionDateEntity(actionDateEntities); Assert.assertEquals(new LocalDate(2010, 4, 1), new LocalDate(paymentsArray[0].getActionDate().getTime())); }
From source file:ca.sqlpower.matchmaker.MatchMakerTestCase.java
/** * Returns a new value that is not equal to oldVal. The returned object * will always be a NEW instance compatible with oldVal. This differs from * {@link #modifyObject(MatchMakerObject, PropertyDescriptor, Object)} in that * this does not take mutability into account. * // w w w. ja v a 2 s .c o m * @param mmo The object to which the property belongs. You might need this * if you have a special case for certain types of objects. * @param property The property that should be modified. It belongs to mmo. * @param oldVal The existing value of the property. */ private Object getNewDifferentValue(MatchMakerObject mmo, PropertyDescriptor property, Object oldVal) throws IOException { Object newVal; // don't init here so compiler can warn if the // following code doesn't always give it a value if (property.getPropertyType() == Integer.TYPE || property.getPropertyType() == Integer.class) { if (oldVal == null) newVal = new Integer(0); else { newVal = ((Integer) oldVal) + 1; } } else if (property.getPropertyType() == Short.TYPE || property.getPropertyType() == Short.class) { if (oldVal == null) newVal = new Short("0"); else { Integer temp = (Short) oldVal + 1; newVal = Short.valueOf(temp.toString()); } } else if (property.getPropertyType() == String.class) { // make sure it's unique newVal = "new " + oldVal; } else if (property.getPropertyType() == Boolean.class || property.getPropertyType() == Boolean.TYPE) { if (oldVal == null) { newVal = new Boolean(false); } else { newVal = new Boolean(!((Boolean) oldVal).booleanValue()); } } else if (property.getPropertyType() == Long.class) { if (oldVal == null) { newVal = new Long(0L); } else { newVal = new Long(((Long) oldVal).longValue() + 1L); } } else if (property.getPropertyType() == BigDecimal.class) { if (oldVal == null) { newVal = new BigDecimal(0); } else { newVal = new BigDecimal(((BigDecimal) oldVal).longValue() + 1L); } } else if (property.getPropertyType() == MungeSettings.class) { newVal = new MungeSettings(); Integer processCount = ((MatchMakerSettings) newVal).getProcessCount(); if (processCount == null) { processCount = new Integer(0); } else { processCount = new Integer(processCount + 1); } ((MatchMakerSettings) newVal).setProcessCount(processCount); } else if (property.getPropertyType() == MergeSettings.class) { newVal = new MergeSettings(); Integer processCount = ((MatchMakerSettings) newVal).getProcessCount(); if (processCount == null) { processCount = new Integer(0); } else { processCount = new Integer(processCount + 1); } ((MatchMakerSettings) newVal).setProcessCount(processCount); } else if (property.getPropertyType() == SQLTable.class) { newVal = new SQLTable(); } else if (property.getPropertyType() == ViewSpec.class) { newVal = new ViewSpec("*", "test_table", "true"); } else if (property.getPropertyType() == File.class) { newVal = File.createTempFile("mmTest", ".tmp"); ((File) newVal).deleteOnExit(); } else if (property.getPropertyType() == PlFolder.class) { newVal = new PlFolder(); } else if (property.getPropertyType() == ProjectMode.class) { if (oldVal == ProjectMode.BUILD_XREF) { newVal = ProjectMode.FIND_DUPES; } else { newVal = ProjectMode.BUILD_XREF; } } else if (property.getPropertyType() == MergeActionType.class) { if (oldVal == MergeActionType.AUGMENT) { newVal = MergeActionType.SUM; } else { newVal = MergeActionType.AUGMENT; } } else if (property.getPropertyType() == MatchMakerTranslateGroup.class) { newVal = new MatchMakerTranslateGroup(); } else if (property.getPropertyType() == MatchMakerObject.class) { newVal = new TestingAbstractMatchMakerObject(); } else if (property.getPropertyType() == SQLColumn.class) { newVal = new SQLColumn(); } else if (property.getPropertyType() == Date.class) { newVal = new Date(); } else if (property.getPropertyType() == List.class) { newVal = new ArrayList(); } else if (property.getPropertyType() == Project.class) { newVal = new Project(); ((Project) newVal).setName("Fake_Project_" + System.currentTimeMillis()); } else if (property.getPropertyType() == SQLIndex.class) { return new SQLIndex("new index", false, "", "HASHED", ""); } else if (property.getPropertyType() == Color.class) { if (oldVal == null) { newVal = new Color(0xFAC157); } else { Color oldColor = (Color) oldVal; newVal = new Color((oldColor.getRGB() + 0xF00) % 0x1000000); } } else if (property.getPropertyType() == ChildMergeActionType.class) { if (oldVal != null && oldVal.equals(ChildMergeActionType.DELETE_ALL_DUP_CHILD)) { newVal = ChildMergeActionType.UPDATE_DELETE_ON_CONFLICT; } else { newVal = ChildMergeActionType.DELETE_ALL_DUP_CHILD; } } else if (property.getPropertyType() == MungeResultStep.class || property.getPropertyType() == DeDupeResultStep.class) { newVal = new DeDupeResultStep(); } else if (property.getPropertyType() == TableMergeRules.class) { if (oldVal == null) { newVal = mmo; } else { newVal = null; } } else if (property.getPropertyType() == PoolFilterSetting.class) { if (oldVal != PoolFilterSetting.EVERYTHING) { newVal = PoolFilterSetting.EVERYTHING; } else { newVal = PoolFilterSetting.INVALID_ONLY; } } else if (property.getPropertyType() == AutoValidateSetting.class) { if (oldVal != AutoValidateSetting.NOTHING) { newVal = AutoValidateSetting.NOTHING; } else { newVal = AutoValidateSetting.SERP_CORRECTABLE; } } else if (property.getPropertyType() == Point.class) { if (oldVal == null) { newVal = new Point(0, 0); } else { newVal = new Point(((Point) oldVal).x + 1, ((Point) oldVal).y + 1); } } else { throw new RuntimeException("This test case lacks a value for " + property.getName() + " (type " + property.getPropertyType().getName() + ") from " + mmo.getClass()); } if (newVal instanceof MatchMakerObject) { ((MatchMakerObject) newVal).setSession(session); } return newVal; }
From source file:org.apache.felix.webconsole.internal.compendium.ConfigManager.java
/** * @throws NumberFormatException/*from w ww . j a v a 2 s .c o m*/ * If the value cannot be converted to a number and type * indicates a numeric type */ private Object getType(int type, String value) { switch (type) { case AttributeDefinition.BYTE: return Byte.valueOf(value); case AttributeDefinition.CHARACTER: char c = (value.length() > 0) ? value.charAt(0) : 0; return new Character(c); case AttributeDefinition.BOOLEAN: return Boolean.valueOf(value); case AttributeDefinition.LONG: return Long.valueOf(value); case AttributeDefinition.INTEGER: return Integer.valueOf(value); case AttributeDefinition.SHORT: return Short.valueOf(value); case AttributeDefinition.DOUBLE: return Double.valueOf(value); case AttributeDefinition.FLOAT: return Float.valueOf(value); default: // includes AttributeDefinition.STRING return value; } }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.common.source.CswFilterDelegate.java
@Override public FilterType propertyIsLessThan(String propertyName, short literal) { isComparisonOperationSupported(ComparisonOperatorType.LESS_THAN); propertyName = mapPropertyName(propertyName); if (isPropertyQueryable(propertyName)) { return cswFilterFactory.buildPropertyIsLessThanFilter(propertyName, Short.valueOf(literal)); } else {/* w w w . j ava2 s . com*/ return new FilterType(); } }