List of usage examples for java.lang Short valueOf
@HotSpotIntrinsicCandidate public static Short valueOf(short s)
From source file:org.apache.hadoop.hive.serde2.fast.RandomRowObjectSource.java
public Object randomObject(int column) { PrimitiveCategory primitiveCategory = primitiveCategories[column]; PrimitiveTypeInfo primitiveTypeInfo = primitiveTypeInfos[column]; switch (primitiveCategory) { case BOOLEAN: return Boolean.valueOf(r.nextInt(1) == 1); case BYTE:// w w w . ja v a 2s. c o m return Byte.valueOf((byte) r.nextInt()); case SHORT: return Short.valueOf((short) r.nextInt()); case INT: return Integer.valueOf(r.nextInt()); case LONG: return Long.valueOf(r.nextLong()); case DATE: return RandomTypeUtil.getRandDate(r); case FLOAT: return Float.valueOf(r.nextFloat() * 10 - 5); case DOUBLE: return Double.valueOf(r.nextDouble() * 10 - 5); case STRING: return RandomTypeUtil.getRandString(r); case CHAR: return getRandHiveChar(r, (CharTypeInfo) primitiveTypeInfo); case VARCHAR: return getRandHiveVarchar(r, (VarcharTypeInfo) primitiveTypeInfo); case BINARY: return getRandBinary(r, 1 + r.nextInt(100)); case TIMESTAMP: return RandomTypeUtil.getRandTimestamp(r); case INTERVAL_YEAR_MONTH: return getRandIntervalYearMonth(r); case INTERVAL_DAY_TIME: return getRandIntervalDayTime(r); case DECIMAL: return getRandHiveDecimal(r, (DecimalTypeInfo) primitiveTypeInfo); default: throw new Error("Unknown primitive category " + primitiveCategory); } }
From source file:org.mifos.application.servicefacade.SavingsServiceFacadeWebTier.java
@Override public void withdraw(SavingsWithdrawalDto savingsWithdrawal) { MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); UserContext userContext = toUserContext(user); SavingsBO savingsAccount = this.savingsDao.findById(savingsWithdrawal.getSavingsId()); try {/*from w ww.ja v a 2 s .c om*/ personnelDao.checkAccessPermission(userContext, savingsAccount.getOfficeId(), savingsAccount.getCustomer().getLoanOfficerId()); } catch (AccountException e) { throw new MifosRuntimeException(e.getMessage(), e); } savingsAccount.updateDetails(userContext); PersonnelBO createdBy = this.personnelDao.findPersonnelById(Short.valueOf((short) user.getUserId())); CustomerBO customer = this.customerDao.findCustomerById(savingsWithdrawal.getCustomerId().intValue()); Money totalAmount = new Money(savingsAccount.getCurrency(), BigDecimal.valueOf(savingsWithdrawal.getAmount())); PaymentData payment = PaymentData.createPaymentData(totalAmount, createdBy, savingsWithdrawal.getModeOfPayment().shortValue(), savingsWithdrawal.getDateOfWithdrawal().toDateMidnight().toDate()); if (savingsWithdrawal.getDateOfReceipt() != null) { payment.setReceiptDate(savingsWithdrawal.getDateOfReceipt().toDateMidnight().toDate()); } payment.setReceiptNum(savingsWithdrawal.getReceiptId()); payment.setCustomer(customer); List<EndOfDayDetail> allEndOfDayDetailsForAccount = savingsDao .retrieveAllEndOfDayDetailsFor(savingsAccount.getCurrency(), savingsWithdrawal.getSavingsId()); MifosCurrency currencyInUse = savingsAccount.getCurrency(); LocalDate dateOfWithdrawal = new LocalDate(payment.getTransactionDate()); Money balanceOnDateOfWithdrawal = calculateAccountBalanceOn(dateOfWithdrawal.plusDays(1), allEndOfDayDetailsForAccount, currencyInUse); if (payment.getTotalAmount().isGreaterThan(balanceOnDateOfWithdrawal)) { throw new BusinessRuleException("errors.insufficentbalance", new String[] { savingsAccount.getGlobalAccountNum() }); } try { this.transactionHelper.startTransaction(); this.transactionHelper.beginAuditLoggingFor(savingsAccount); savingsAccount.withdraw(payment, false); this.savingsDao.save(savingsAccount); this.transactionHelper.commitTransaction(); } catch (AccountException e) { this.transactionHelper.rollbackTransaction(); throw new BusinessRuleException(e.getKey(), e); } finally { this.transactionHelper.closeSession(); } }
From source file:org.mifos.accounts.loan.business.LoanBORedoDisbursalIntegrationTest.java
@Ignore @Test/* w ww . j ava 2 s.c o m*/ public void testRedoLoanApplyWholeMiscPenaltyAfterFullPayment() throws Exception { LoanBO loan = redoLoanWithMondayMeetingAndVerify(userContext, 14, new ArrayList<AccountFeesEntity>()); disburseLoanAndVerify(userContext, loan, 14); LoanTestUtils.assertInstallmentDetails(loan, 1, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 2, 50.9, 0.1, 0.0, 0.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); // make one full repayment applyAndVerifyPayment(userContext, loan, 7, new Money(getCurrency(), "51")); LoanTestUtils.assertInstallmentDetails(loan, 1, 0.0, 0.0, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 2, 50.9, 0.1, 0.0, 0.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); applyCharge(loan, Short.valueOf(AccountConstants.MISC_PENALTY), new Double("33")); LoanTestUtils.assertInstallmentDetails(loan, 1, 0.0, 0.0, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 2, 50.9, 0.1, 0.0, 0.0, 33.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.ednovo.gooru.domain.service.assessment.AssessmentServiceImpl.java
private AssessmentQuestion initQuestion(AssessmentQuestion question, String gooruOQuestionId, boolean copyToOriginal) { if (copyToOriginal) { if (gooruOQuestionId == null) { License license = (License) baseRepository.get(License.class, CREATIVE_COMMONS); question.setLicense(license); ContentType contentType = (ContentType) baseRepository.get(ContentType.class, ContentType.QUESTION); question.setContentType(contentType); if (question.getGooruOid() == null) { question.setGooruOid(UUID.randomUUID().toString()); }/*from w w w .ja va 2s . com*/ ServerValidationUtils.rejectIfNull(question.getQuestionText(), GL0006, QUESTION_TEXT); question.setTitle(question.getQuestionText().substring(0, question.getQuestionText().length() > 1000 ? 999 : question.getQuestionText().length())); // Explicitly set to null to reset any content id sent by // clients question.setContentId(null); question.setCreatedOn(new java.util.Date()); question.setUrl(""); if (question.getSharing() == null) { question.setSharing(PUBLIC); } if (question.getDistinguish() == null) { question.setDistinguish(Short.valueOf("0")); } if (question.getIsFeatured() == null) { question.setIsFeatured(0); } if (question.getTypeName() == null) { question.setTypeName(AssessmentQuestion.TYPE.MULTIPLE_CHOICE.getName()); } if (question.getTypeName().equalsIgnoreCase(AssessmentQuestion.TYPE.MATCH_THE_FOLLOWING.getName()) && question.getAnswers().size() > 0) { for (AssessmentAnswer assessmentAnswer : question.getAnswers()) { for (AssessmentAnswer matchingAnswer : question.getAnswers()) { if (assessmentAnswer.getMatchingSequence() != null && assessmentAnswer.getMatchingSequence() .equals(matchingAnswer.getMatchingSequence()) && !assessmentAnswer.getSequence().equals(matchingAnswer.getSequence())) { // assessmentAnswer.setMatchingAnswer(matchingAnswer); matchingAnswer.setMatchingAnswer(assessmentAnswer); } } } } ResourceType resourceType = null; if (question.getSourceReference() != null && question.getSourceReference().equalsIgnoreCase(ASSESSMENT)) { resourceType = (ResourceType) baseRepository.get(ResourceType.class, ResourceType.Type.AM_ASSESSMENT_QUESTION.getType()); } else { resourceType = (ResourceType) baseRepository.get(ResourceType.class, ResourceType.Type.ASSESSMENT_QUESTION.getType()); } question.setResourceType(resourceType); question.setTypeName(question.getTypeName()); question.setCategory(QUESTION); question.setResourceFormat( this.getCustomTableRepository().getCustomTableValue(RESOURCE_CATEGORY_FORMAT, QUESTION)); } else { AssessmentQuestion existingQuestion = getQuestion(gooruOQuestionId); if (existingQuestion == null) { throw new NotFoundException(ServerValidationUtils.generateErrorMessage(GL0056, RESOURCE), GL0056); } if (question.getQuestionText() != null) { existingQuestion.setQuestionText(question.getQuestionText()); existingQuestion.setTitle( question.getQuestionText().substring(0, question.getQuestionText().length() > 1000 ? 999 : question.getQuestionText().length())); } if (question.getDescription() != null) { existingQuestion.setDescription(question.getDescription()); } if (question.getExplanation() != null) { existingQuestion.setExplanation(question.getExplanation()); } if (question.getConcept() != null) { existingQuestion.setConcept(question.getConcept()); } if (question.getImportCode() != null) { existingQuestion.setImportCode(question.getImportCode()); } if (question.getContentType() != null) { existingQuestion.setContentType(question.getContentType()); } if (question.getTags() != null) { existingQuestion.setTags(question.getTags()); } if (question.getResourceSource() != null && existingQuestion.getResourceSource() != null) { ResourceSource resourceSource = existingQuestion.getResourceSource(); resourceSource.setAttribution(question.getResourceSource().getAttribution()); existingQuestion.setResourceSource(resourceSource); } existingQuestion.setDifficultyLevel(question.getDifficultyLevel()); if (question.getTitle() != null) { existingQuestion.setTitle(question.getTitle()); } existingQuestion.setTimeToCompleteInSecs(question.getTimeToCompleteInSecs()); if (question.getTypeName() != null) { existingQuestion.setTypeName(question.getTypeName()); } if (question.getCategory() != null) { existingQuestion.setCategory(question.getCategory()); } if (question.getSharing() != null) { existingQuestion.setSharing(question.getSharing()); } if (question.getAnswers() != null) { updateAnswerList(question.getAnswers(), existingQuestion.getAnswers()); } if (question.getHints() != null) { updateHintList(question.getHints(), existingQuestion.getHints()); } resourceService.saveOrUpdateResourceTaxonomy(existingQuestion, question.getTaxonomySet()); if (question.getRecordSource() != null) { existingQuestion.setRecordSource(question.getRecordSource()); } question = existingQuestion; } } question.setLastModified(new java.util.Date()); if (question.getConcept() == null) { question.setConcept(""); } if (question.getRecordSource() == null) { question.setRecordSource(Resource.RecordSource.DEFAULT.getRecordSource()); } if (question.getTimeToCompleteInSecs() == null) { question.setTimeToCompleteInSecs(0); } if (question.getExplanation() == null) { question.setExplanation(""); } if (question.getDescription() == null) { question.setDescription(""); } if (question.getSharing() == null) { question.setSharing(PUBLIC); } if (question.getLicense() == null) { question.setLicense(new License()); question.getLicense().setName(CREATIVE_COMMONS); } if (question.getUrl() == null) { question.setUrl(""); } if (question.getQuestionText() == null) { throw new BadRequestException("Question Text is mandatory"); } return question; }
From source file:com.dirkgassen.wator.ui.fragment.NewWorld.java
/** Call the {@link #worldCreator} to create the new world with the entered values. */ private void createWorld() { worldCreator.createWorld(new WorldParameters() .setWidth(Short.valueOf(inputs[WORLD_WIDTH_INPUT].getText().toString())) .setHeight(Short.valueOf(inputs[WORLD_HEIGHT_INPUT].getText().toString())) .setFishBreedTime(Short.valueOf(inputs[FISH_BREED_INPUT].getText().toString())) .setSharkBreedTime(Short.valueOf(inputs[SHARK_BREED_INPUT].getText().toString())) .setSharkStarveTime(Short.valueOf(inputs[SHARK_STARVE_INPUT].getText().toString())) .setInitialFishCount(Short.valueOf(inputs[INITIAL_FISH_COUNT_INPUT].getText().toString())) .setInitialSharkCount(Short.valueOf(inputs[INITIAL_SHARK_COUNT_INPUT].getText().toString()))); }
From source file:org.executequery.gui.importexport.AbstractImportExportWorker.java
/** * Sets the specified value in the specified position for the * specified java.sql.Type within the prepared statement. * * @param value - the value/*from www.ja va2 s . c om*/ * @param index - the position within the statement * @param sqlType - the SQL type * @param trim - whether to trim the whitespace from the value * @param df - the DataFormat object for date values */ protected void setValue(String value, int index, int sqlType, boolean trim, DateFormat df) throws Exception { if (value == null) { prepStmnt.setNull(index, sqlType); } else { switch (sqlType) { case Types.TINYINT: byte _byte = Byte.valueOf(value).byteValue(); prepStmnt.setShort(index, _byte); break; case Types.BIGINT: long _long = Long.valueOf(value).longValue(); prepStmnt.setLong(index, _long); break; case Types.SMALLINT: short _short = Short.valueOf(value).shortValue(); prepStmnt.setShort(index, _short); break; case Types.LONGVARCHAR: case Types.CHAR: case Types.VARCHAR: if (trim) { value = value.trim(); } prepStmnt.setString(index, value); break; case Types.BIT: case Types.BOOLEAN: String booleanValue = value; if ("t".equalsIgnoreCase(value)) { booleanValue = "true"; } else if ("f".equalsIgnoreCase(value)) { booleanValue = "false"; } boolean _boolean = Boolean.valueOf(booleanValue).booleanValue(); prepStmnt.setBoolean(index, _boolean); break; case Types.NUMERIC: case Types.DECIMAL: prepStmnt.setBigDecimal(index, new BigDecimal(value)); break; case Types.REAL: float _float = Float.valueOf(value).floatValue(); prepStmnt.setFloat(index, _float); break; case Types.FLOAT: case Types.DOUBLE: prepStmnt.setDouble(index, Double.parseDouble(value)); break; case Types.INTEGER: prepStmnt.setInt(index, Integer.parseInt(value)); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: // if the date format is null, insert as a char value if (df != null) { java.util.Date j_datetime = df.parse(value); prepStmnt.setDate(index, new java.sql.Date(j_datetime.getTime())); } else { try { prepStmnt.setObject(index, value, sqlType); /* if (sqlType == Types.TIMESTAMP) { prepStmnt.setTimestamp(index, java.sql.Timestamp.valueOf(value)); } else if (sqlType == Types.TIME) { prepStmnt.setTime(index, java.sql.Time.valueOf(value)); } else { prepStmnt.setDate(index, java.sql.Date.valueOf(value)); } */ } // want a more useful message here than what will likely // be returned due to internal driver code on formatting // a SQL date value from string // (ie. could be parsing error, number format etc...) catch (Exception e) { throw new IllegalArgumentException("[ " + MiscUtils.getExceptionName(e) + " ] " + getBundle().getString("AbstractImportExportWorker.dateConversionError")); } } break; case Types.LONGVARBINARY: case Types.BINARY: case Types.BLOB: case Types.CLOB: prepStmnt.setBytes(index, Base64.decode(value)); break; default: prepStmnt.setObject(index, value); break; } } }
From source file:net.sf.ezmorph.bean.BeanMorpherTest.java
public void testMorph_PrimitiveBean_to_ObjectBean() { PrimitiveBean primitiveBean = new PrimitiveBean(); primitiveBean.setPclass(Object.class); primitiveBean.setPstring("MORPH"); morpherRegistry.registerMorpher(new BeanMorpher(ObjectBean.class, morpherRegistry)); ObjectBean objectBean = (ObjectBean) morpherRegistry.morph(ObjectBean.class, primitiveBean); assertNotNull(objectBean);/*from w w w . j a v a2 s . c om*/ assertEquals(Boolean.FALSE, objectBean.getPboolean()); assertEquals(Byte.valueOf("0"), objectBean.getPbyte()); assertEquals(Short.valueOf("0"), objectBean.getPshort()); assertEquals(Integer.valueOf("0"), objectBean.getPint()); assertEquals(Long.valueOf("0"), objectBean.getPlong()); assertEquals(Float.valueOf("0"), objectBean.getPfloat()); assertEquals(Double.valueOf("0"), objectBean.getPdouble()); assertEquals(new Character('\0'), objectBean.getPchar()); assertEquals(null, objectBean.getParray()); assertEquals(null, objectBean.getPlist()); assertEquals(null, objectBean.getPbean()); assertEquals(null, objectBean.getPmap()); assertEquals("MORPH", objectBean.getPstring()); assertEquals(Object.class, objectBean.getPclass()); }
From source file:org.apache.hive.jdbc.BaseJdbcWithMiniLlap.java
@Test(timeout = 60000) public void testDataTypes() throws Exception { createDataTypesTable("datatypes"); RowCollector2 rowCollector = new RowCollector2(); String query = "select * from datatypes"; int rowCount = processQuery(query, 1, rowCollector); assertEquals(3, rowCount);/* w ww. java 2 s . com*/ // Verify schema String[][] colNameTypes = new String[][] { { "datatypes.c1", "int" }, { "datatypes.c2", "boolean" }, { "datatypes.c3", "double" }, { "datatypes.c4", "string" }, { "datatypes.c5", "array<int>" }, { "datatypes.c6", "map<int,string>" }, { "datatypes.c7", "map<string,string>" }, { "datatypes.c8", "struct<r:string,s:int,t:double>" }, { "datatypes.c9", "tinyint" }, { "datatypes.c10", "smallint" }, { "datatypes.c11", "float" }, { "datatypes.c12", "bigint" }, { "datatypes.c13", "array<array<string>>" }, { "datatypes.c14", "map<int,map<int,int>>" }, { "datatypes.c15", "struct<r:int,s:struct<a:int,b:string>>" }, { "datatypes.c16", "array<struct<m:map<string,string>,n:int>>" }, { "datatypes.c17", "timestamp" }, { "datatypes.c18", "decimal(16,7)" }, { "datatypes.c19", "binary" }, { "datatypes.c20", "date" }, { "datatypes.c21", "varchar(20)" }, { "datatypes.c22", "char(15)" }, { "datatypes.c23", "binary" }, }; FieldDesc fieldDesc; assertEquals(23, rowCollector.numColumns); for (int idx = 0; idx < rowCollector.numColumns; ++idx) { fieldDesc = rowCollector.schema.getColumns().get(idx); assertEquals("ColName idx=" + idx, colNameTypes[idx][0], fieldDesc.getName()); assertEquals("ColType idx=" + idx, colNameTypes[idx][1], fieldDesc.getTypeInfo().getTypeName()); } // First row is all nulls Object[] rowValues = rowCollector.rows.get(0); for (int idx = 0; idx < rowCollector.numColumns; ++idx) { assertEquals("idx=" + idx, null, rowValues[idx]); } // Second Row rowValues = rowCollector.rows.get(1); assertEquals(Integer.valueOf(-1), rowValues[0]); assertEquals(Boolean.FALSE, rowValues[1]); assertEquals(Double.valueOf(-1.1d), rowValues[2]); assertEquals("", rowValues[3]); List<?> c5Value = (List<?>) rowValues[4]; assertEquals(0, c5Value.size()); Map<?, ?> c6Value = (Map<?, ?>) rowValues[5]; assertEquals(0, c6Value.size()); Map<?, ?> c7Value = (Map<?, ?>) rowValues[6]; assertEquals(0, c7Value.size()); List<?> c8Value = (List<?>) rowValues[7]; assertEquals(null, c8Value.get(0)); assertEquals(null, c8Value.get(1)); assertEquals(null, c8Value.get(2)); assertEquals(Byte.valueOf((byte) -1), rowValues[8]); assertEquals(Short.valueOf((short) -1), rowValues[9]); assertEquals(Float.valueOf(-1.0f), rowValues[10]); assertEquals(Long.valueOf(-1l), rowValues[11]); List<?> c13Value = (List<?>) rowValues[12]; assertEquals(0, c13Value.size()); Map<?, ?> c14Value = (Map<?, ?>) rowValues[13]; assertEquals(0, c14Value.size()); List<?> c15Value = (List<?>) rowValues[14]; assertEquals(null, c15Value.get(0)); assertEquals(null, c15Value.get(1)); List<?> c16Value = (List<?>) rowValues[15]; assertEquals(0, c16Value.size()); assertEquals(null, rowValues[16]); assertEquals(null, rowValues[17]); assertEquals(null, rowValues[18]); assertEquals(null, rowValues[19]); assertEquals(null, rowValues[20]); assertEquals(null, rowValues[21]); assertEquals(null, rowValues[22]); // Third row rowValues = rowCollector.rows.get(2); assertEquals(Integer.valueOf(1), rowValues[0]); assertEquals(Boolean.TRUE, rowValues[1]); assertEquals(Double.valueOf(1.1d), rowValues[2]); assertEquals("1", rowValues[3]); c5Value = (List<?>) rowValues[4]; assertEquals(2, c5Value.size()); assertEquals(Integer.valueOf(1), c5Value.get(0)); assertEquals(Integer.valueOf(2), c5Value.get(1)); c6Value = (Map<?, ?>) rowValues[5]; assertEquals(2, c6Value.size()); assertEquals("x", c6Value.get(Integer.valueOf(1))); assertEquals("y", c6Value.get(Integer.valueOf(2))); c7Value = (Map<?, ?>) rowValues[6]; assertEquals(1, c7Value.size()); assertEquals("v", c7Value.get("k")); c8Value = (List<?>) rowValues[7]; assertEquals("a", c8Value.get(0)); assertEquals(Integer.valueOf(9), c8Value.get(1)); assertEquals(Double.valueOf(2.2d), c8Value.get(2)); assertEquals(Byte.valueOf((byte) 1), rowValues[8]); assertEquals(Short.valueOf((short) 1), rowValues[9]); assertEquals(Float.valueOf(1.0f), rowValues[10]); assertEquals(Long.valueOf(1l), rowValues[11]); c13Value = (List<?>) rowValues[12]; assertEquals(2, c13Value.size()); List<?> listVal = (List<?>) c13Value.get(0); assertEquals("a", listVal.get(0)); assertEquals("b", listVal.get(1)); listVal = (List<?>) c13Value.get(1); assertEquals("c", listVal.get(0)); assertEquals("d", listVal.get(1)); c14Value = (Map<?, ?>) rowValues[13]; assertEquals(2, c14Value.size()); Map<?, ?> mapVal = (Map<?, ?>) c14Value.get(Integer.valueOf(1)); assertEquals(2, mapVal.size()); assertEquals(Integer.valueOf(12), mapVal.get(Integer.valueOf(11))); assertEquals(Integer.valueOf(14), mapVal.get(Integer.valueOf(13))); mapVal = (Map<?, ?>) c14Value.get(Integer.valueOf(2)); assertEquals(1, mapVal.size()); assertEquals(Integer.valueOf(22), mapVal.get(Integer.valueOf(21))); c15Value = (List<?>) rowValues[14]; assertEquals(Integer.valueOf(1), c15Value.get(0)); listVal = (List<?>) c15Value.get(1); assertEquals(2, listVal.size()); assertEquals(Integer.valueOf(2), listVal.get(0)); assertEquals("x", listVal.get(1)); c16Value = (List<?>) rowValues[15]; assertEquals(2, c16Value.size()); listVal = (List<?>) c16Value.get(0); assertEquals(2, listVal.size()); mapVal = (Map<?, ?>) listVal.get(0); assertEquals(0, mapVal.size()); assertEquals(Integer.valueOf(1), listVal.get(1)); listVal = (List<?>) c16Value.get(1); mapVal = (Map<?, ?>) listVal.get(0); assertEquals(2, mapVal.size()); assertEquals("b", mapVal.get("a")); assertEquals("d", mapVal.get("c")); assertEquals(Integer.valueOf(2), listVal.get(1)); assertEquals(Timestamp.valueOf("2012-04-22 09:00:00.123456789"), rowValues[16]); assertEquals(new BigDecimal("123456789.123456"), rowValues[17]); assertArrayEquals("abcd".getBytes("UTF-8"), (byte[]) rowValues[18]); assertEquals(Date.valueOf("2013-01-01"), rowValues[19]); assertEquals("abc123", rowValues[20]); assertEquals("abc123 ", rowValues[21]); assertArrayEquals("X'01FF'".getBytes("UTF-8"), (byte[]) rowValues[22]); }
From source file:com.xwtec.xwserver.util.json.JSONArray.java
/** * Creates a java array from a JSONArray.<br> *///w w w . j a v a2 s . c om public static Object toArray(JSONArray jsonArray, JsonConfig jsonConfig) { Class objectClass = jsonConfig.getRootClass(); Map classMap = jsonConfig.getClassMap(); if (jsonArray.size() == 0) { return Array.newInstance(objectClass == null ? Object.class : objectClass, 0); } int[] dimensions = JSONArray.getDimensions(jsonArray); Object array = Array.newInstance(objectClass == null ? Object.class : objectClass, dimensions); int size = jsonArray.size(); for (int i = 0; i < size; i++) { Object value = jsonArray.get(i); if (JSONUtils.isNull(value)) { Array.set(array, i, null); } else { Class type = value.getClass(); if (JSONArray.class.isAssignableFrom(type)) { Array.set(array, i, toArray((JSONArray) value, objectClass, classMap)); } else if (String.class.isAssignableFrom(type) || Boolean.class.isAssignableFrom(type) || Character.class.isAssignableFrom(type) || JSONFunction.class.isAssignableFrom(type)) { if (objectClass != null && !objectClass.isAssignableFrom(type)) { value = JSONUtils.getMorpherRegistry().morph(objectClass, value); } Array.set(array, i, value); } else if (JSONUtils.isNumber(type)) { if (objectClass != null && (Byte.class.isAssignableFrom(objectClass) || Byte.TYPE.isAssignableFrom(objectClass))) { Array.set(array, i, Byte.valueOf(String.valueOf(value))); } else if (objectClass != null && (Short.class.isAssignableFrom(objectClass) || Short.TYPE.isAssignableFrom(objectClass))) { Array.set(array, i, Short.valueOf(String.valueOf(value))); } else { Array.set(array, i, value); } } else { if (objectClass != null) { JsonConfig jsc = jsonConfig.copy(); jsc.setRootClass(objectClass); jsc.setClassMap(classMap); Array.set(array, i, JSONObject.toBean((JSONObject) value, jsc)); } else { Array.set(array, i, JSONObject.toBean((JSONObject) value)); } } } } return array; }
From source file:org.mifos.accounts.productdefinition.struts.actionforms.LoanPrdActionFormTest.java
@Test public void shouldAllowPeriodicFeeForNonVariableInstallmentLoanProduct() { String PERIODIC_FEE_2 = "2"; String NON_PERIODIC_FEE = "3"; final FeeDto feeDto = Mockito.mock(FeeDto.class); loanPrdActionForm = new LoanPrdActionForm() { @Override//from www .j a v a2 s . co m FeeDto getFeeDto(@SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") FeeBO fee) { return feeDto; } }; FeeFrequencyEntity feeFrequencyEntity = Mockito.mock(FeeFrequencyEntity.class); MeetingBO meetingBo = Mockito.mock(MeetingBO.class); MeetingDetailsEntity meetingDetailsEntity = Mockito.mock(MeetingDetailsEntity.class); when(periodicFeeRate.isPeriodic()).thenReturn(true); when(periodicFeeRate.getFeeType()).thenReturn(RateAmountFlag.RATE); when(periodicFeeRate.getFeeId()).thenReturn(Short.valueOf(PERIODIC_FEE_2)); when(periodicFeeRate.getFeeName()).thenReturn("periodic fee2"); when((periodicFeeRate).getFeeFormula()).thenReturn(feeFormulaEntity); when(feeFormulaEntity.getFeeFormula()).thenReturn(FeeFormula.INTEREST); when(periodicFeeRate.getFeeFrequency()).thenReturn(feeFrequencyEntity); when(nonPeriodicFeeRate.isPeriodic()).thenReturn(false); when(nonPeriodicFeeRate.getFeeType()).thenReturn(RateAmountFlag.RATE); when(nonPeriodicFeeRate.getFeeId()).thenReturn(Short.valueOf(NON_PERIODIC_FEE)); when(nonPeriodicFeeRate.getFeeName()).thenReturn("non Periodic fee"); when(((RateFeeBO) nonPeriodicFeeRate).getFeeFormula()).thenReturn(feeFormulaEntity); when(feeFormulaEntity.getFeeFormula()).thenReturn(FeeFormula.INTEREST); List<FeeBO> allPrdFees = new ArrayList<FeeBO>(); allPrdFees.add(periodicFeeRate); allPrdFees.add(nonPeriodicFeeRate); when(request.getAttribute(Constants.CURRENTFLOWKEY)).thenReturn(FLOW_KEY); when(request.getSession()).thenReturn(session); when(session.getAttribute(Constants.FLOWMANAGER)).thenReturn(flowManager); when(session.getAttribute(ProductDefinitionConstants.LOANPRDFEE)).thenReturn(allPrdFees); Flow flow = new Flow(); try { when(flowManager.getFromFlow(Mockito.anyString(), Mockito.anyString())).thenReturn(allPrdFees); when(flowManager.getFlowWithValidation(FLOW_KEY)).thenReturn(flow); } catch (PageExpiredException e) { // TODO Auto-generated catch block e.printStackTrace(); } loanPrdActionForm.setCanConfigureVariableInstallments(false); loanPrdActionForm.setPrdOfferinFees(new String[] { PERIODIC_FEE_2, NON_PERIODIC_FEE }); loanPrdActionForm.validateSelectedFeeForVariableInstallment(request, errors); Mockito.verifyZeroInteractions(errors); }