List of usage examples for java.lang Short valueOf
@HotSpotIntrinsicCandidate public static Short valueOf(short s)
From source file:org.apache.hadoop.hbase.io.HbaseObjectWritable.java
/** * Read a {@link Writable}, {@link String}, primitive type, or an array of * the preceding.//from w ww . j a v a 2s . c om * @param in * @param objectWritable * @param conf * @return the object * @throws IOException */ @SuppressWarnings("unchecked") public static Object readObject(DataInput in, HbaseObjectWritable objectWritable, Configuration conf) throws IOException { Class<?> declaredClass = CODE_TO_CLASS.get(WritableUtils.readVInt(in)); Object instance; if (declaredClass.isPrimitive()) { // primitive types if (declaredClass == Boolean.TYPE) { // boolean instance = Boolean.valueOf(in.readBoolean()); } else if (declaredClass == Character.TYPE) { // char instance = Character.valueOf(in.readChar()); } else if (declaredClass == Byte.TYPE) { // byte instance = Byte.valueOf(in.readByte()); } else if (declaredClass == Short.TYPE) { // short instance = Short.valueOf(in.readShort()); } else if (declaredClass == Integer.TYPE) { // int instance = Integer.valueOf(in.readInt()); } else if (declaredClass == Long.TYPE) { // long instance = Long.valueOf(in.readLong()); } else if (declaredClass == Float.TYPE) { // float instance = Float.valueOf(in.readFloat()); } else if (declaredClass == Double.TYPE) { // double instance = Double.valueOf(in.readDouble()); } else if (declaredClass == Void.TYPE) { // void instance = null; } else { throw new IllegalArgumentException("Not a primitive: " + declaredClass); } } else if (declaredClass.isArray()) { // array if (declaredClass.equals(byte[].class)) { instance = Bytes.readByteArray(in); } else if (declaredClass.equals(Result[].class)) { instance = Result.readArray(in); } else { int length = in.readInt(); instance = Array.newInstance(declaredClass.getComponentType(), length); for (int i = 0; i < length; i++) { Array.set(instance, i, readObject(in, conf)); } } } else if (declaredClass.equals(Array.class)) { //an array not declared in CLASS_TO_CODE Class<?> componentType = readClass(conf, in); int length = in.readInt(); instance = Array.newInstance(componentType, length); for (int i = 0; i < length; i++) { Array.set(instance, i, readObject(in, conf)); } } else if (List.class.isAssignableFrom(declaredClass)) { // List int length = in.readInt(); instance = new ArrayList(length); for (int i = 0; i < length; i++) { ((ArrayList) instance).add(readObject(in, conf)); } } else if (declaredClass == String.class) { // String instance = Text.readString(in); } else if (declaredClass.isEnum()) { // enum instance = Enum.valueOf((Class<? extends Enum>) declaredClass, Text.readString(in)); } else if (declaredClass == Message.class) { String className = Text.readString(in); try { declaredClass = getClassByName(conf, className); instance = tryInstantiateProtobuf(declaredClass, in); } catch (ClassNotFoundException e) { LOG.error("Can't find class " + className, e); throw new IOException("Can't find class " + className, e); } } else { // Writable or Serializable Class instanceClass = null; int b = (byte) WritableUtils.readVInt(in); if (b == NOT_ENCODED) { String className = Text.readString(in); try { instanceClass = getClassByName(conf, className); } catch (ClassNotFoundException e) { LOG.error("Can't find class " + className, e); throw new IOException("Can't find class " + className, e); } } else { instanceClass = CODE_TO_CLASS.get(b); } if (Writable.class.isAssignableFrom(instanceClass)) { Writable writable = WritableFactories.newInstance(instanceClass, conf); try { writable.readFields(in); } catch (Exception e) { LOG.error("Error in readFields", e); throw new IOException("Error in readFields", e); } instance = writable; if (instanceClass == NullInstance.class) { // null declaredClass = ((NullInstance) instance).declaredClass; instance = null; } } else { int length = in.readInt(); byte[] objectBytes = new byte[length]; in.readFully(objectBytes); ByteArrayInputStream bis = null; ObjectInputStream ois = null; try { bis = new ByteArrayInputStream(objectBytes); ois = new ObjectInputStream(bis); instance = ois.readObject(); } catch (ClassNotFoundException e) { LOG.error("Class not found when attempting to deserialize object", e); throw new IOException("Class not found when attempting to " + "deserialize object", e); } finally { if (bis != null) bis.close(); if (ois != null) ois.close(); } } } if (objectWritable != null) { // store values objectWritable.declaredClass = declaredClass; objectWritable.instance = instance; } return instance; }
From source file:org.apache.hadoop.hbase.security.access.HbaseObjectWritableFor96Migration.java
/** * Read a {@link Writable}, {@link String}, primitive type, or an array of * the preceding.//w w w . j av a 2s.c o m * @param in * @param objectWritable * @param conf * @return the object * @throws IOException */ @SuppressWarnings("unchecked") static Object readObject(DataInput in, HbaseObjectWritableFor96Migration objectWritable, Configuration conf) throws IOException { Class<?> declaredClass = CODE_TO_CLASS.get(WritableUtils.readVInt(in)); Object instance; if (declaredClass.isPrimitive()) { // primitive types if (declaredClass == Boolean.TYPE) { // boolean instance = Boolean.valueOf(in.readBoolean()); } else if (declaredClass == Character.TYPE) { // char instance = Character.valueOf(in.readChar()); } else if (declaredClass == Byte.TYPE) { // byte instance = Byte.valueOf(in.readByte()); } else if (declaredClass == Short.TYPE) { // short instance = Short.valueOf(in.readShort()); } else if (declaredClass == Integer.TYPE) { // int instance = Integer.valueOf(in.readInt()); } else if (declaredClass == Long.TYPE) { // long instance = Long.valueOf(in.readLong()); } else if (declaredClass == Float.TYPE) { // float instance = Float.valueOf(in.readFloat()); } else if (declaredClass == Double.TYPE) { // double instance = Double.valueOf(in.readDouble()); } else if (declaredClass == Void.TYPE) { // void instance = null; } else { throw new IllegalArgumentException("Not a primitive: " + declaredClass); } } else if (declaredClass.isArray()) { // array if (declaredClass.equals(byte[].class)) { instance = Bytes.readByteArray(in); } else { int length = in.readInt(); instance = Array.newInstance(declaredClass.getComponentType(), length); for (int i = 0; i < length; i++) { Array.set(instance, i, readObject(in, conf)); } } } else if (declaredClass.equals(Array.class)) { //an array not declared in CLASS_TO_CODE Class<?> componentType = readClass(conf, in); int length = in.readInt(); instance = Array.newInstance(componentType, length); for (int i = 0; i < length; i++) { Array.set(instance, i, readObject(in, conf)); } } else if (List.class.isAssignableFrom(declaredClass)) { // List int length = in.readInt(); instance = new ArrayList(length); for (int i = 0; i < length; i++) { ((ArrayList) instance).add(readObject(in, conf)); } } else if (declaredClass == String.class) { // String instance = Text.readString(in); } else if (declaredClass.isEnum()) { // enum instance = Enum.valueOf((Class<? extends Enum>) declaredClass, Text.readString(in)); } else if (declaredClass == Message.class) { String className = Text.readString(in); try { declaredClass = getClassByName(conf, className); instance = tryInstantiateProtobuf(declaredClass, in); } catch (ClassNotFoundException e) { LOG.error("Can't find class " + className, e); throw new IOException("Can't find class " + className, e); } } else if (Scan.class.isAssignableFrom(declaredClass)) { int length = in.readInt(); byte[] scanBytes = new byte[length]; in.readFully(scanBytes); ClientProtos.Scan.Builder scanProto = ClientProtos.Scan.newBuilder(); instance = ProtobufUtil.toScan(scanProto.mergeFrom(scanBytes).build()); } else { // Writable or Serializable Class instanceClass = null; int b = (byte) WritableUtils.readVInt(in); if (b == NOT_ENCODED) { String className = Text.readString(in); try { instanceClass = getClassByName(conf, className); } catch (ClassNotFoundException e) { LOG.error("Can't find class " + className, e); throw new IOException("Can't find class " + className, e); } } else { instanceClass = CODE_TO_CLASS.get(b); } if (Writable.class.isAssignableFrom(instanceClass)) { Writable writable = WritableFactories.newInstance(instanceClass, conf); try { writable.readFields(in); } catch (Exception e) { LOG.error("Error in readFields", e); throw new IOException("Error in readFields", e); } instance = writable; if (instanceClass == NullInstance.class) { // null declaredClass = ((NullInstance) instance).declaredClass; instance = null; } } else { int length = in.readInt(); byte[] objectBytes = new byte[length]; in.readFully(objectBytes); ByteArrayInputStream bis = null; ObjectInputStream ois = null; try { bis = new ByteArrayInputStream(objectBytes); ois = new ObjectInputStream(bis); instance = ois.readObject(); } catch (ClassNotFoundException e) { LOG.error("Class not found when attempting to deserialize object", e); throw new IOException("Class not found when attempting to " + "deserialize object", e); } finally { if (bis != null) bis.close(); if (ois != null) ois.close(); } } } if (objectWritable != null) { // store values objectWritable.declaredClass = declaredClass; objectWritable.instance = instance; } return instance; }
From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java
public void testCreateLoanAccountWithDecliningInterestGraceAllRepaymentsWithLsimOn() throws Exception { 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", ApplicableTo.GROUPS, new Date(System.currentTimeMillis()), 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, 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, loanScheduleIndependentOfMeeting); 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 * (0 + graceDuration)), "49.6", "1.4", fees0, paymentsArray[0]);/*from ww w . j av a 2s. c om*/ checkLoanScheduleEntity(incrementCurrentDate(14 * (1 + graceDuration)), "49.8", "1.2", fees0, paymentsArray[1]); checkLoanScheduleEntity(incrementCurrentDate(14 * (2 + graceDuration)), "50.0", "1.0", fees0, paymentsArray[2]); checkLoanScheduleEntity(incrementCurrentDate(14 * (3 + graceDuration)), "50.3", "0.7", fees0, paymentsArray[3]); checkLoanScheduleEntity(incrementCurrentDate(14 * (4 + graceDuration)), "50.5", "0.5", fees0, paymentsArray[4]); checkLoanScheduleEntity(incrementCurrentDate(14 * (5 + graceDuration)), "49.8", "0.2", fees0, paymentsArray[5]); LoanSummaryEntity loanSummaryEntity = ((LoanBO) accountBO).getLoanSummary(); Assert.assertEquals(new Money(getCurrency(), "300.0"), loanSummaryEntity.getOriginalPrincipal()); }
From source file:ezbake.data.elastic.thrift.SearchResult.java
public Object getFieldValue(_Fields field) { switch (field) { case MATCHING_DOCUMENTS: return getMatchingDocuments(); case TOTAL_HITS: return Long.valueOf(getTotalHits()); case OFFSET:/* ww w .j a v a 2 s . c o m*/ return Integer.valueOf(getOffset()); case PAGESIZE: return Short.valueOf(getPagesize()); case ACTUAL_QUERY: return getActualQuery(); case FACETS: return getFacets(); case HIGHLIGHTS: return getHighlights(); } throw new IllegalStateException(); }
From source file:org.batoo.jpa.core.impl.instance.ManagedInstance.java
/** * Increments the version of the instance. * //from w w w . j a va 2 s .c o m * @param connection * the connection * @param commit * true if version update should be committed immediately * @throws SQLException * thrown in case of an underlying SQL error * * @since 2.0.0 */ public void incrementVersion(Connection connection, boolean commit) throws SQLException { if (!this.type.getRootType().hasVersionAttribute()) { return; } final EntityTypeImpl<? super X> rootType = this.type.getRootType(); final BasicAttribute<? super X, ?> version = rootType.getVersionAttribute(); if (this.oldVersion == null) { switch (this.type.getVersionType()) { case SHORT: final short shortValue = (((Number) version.get(this.instance)).shortValue()); this.oldVersion = shortValue; version.set(this.instance, shortValue + 1); ManagedInstance.LOG.debug("Version upgraded instance: {0} - {1}", this, shortValue); break; case SHORT_OBJECT: final Short shortObjValue = version.get(this.instance) == null ? 0 : // Short.valueOf((((Number) version.get(this.instance)).shortValue())); this.oldVersion = shortObjValue; version.set(this.instance, shortObjValue + 1); ManagedInstance.LOG.debug("Version upgraded instance: {0} - {1}", this, shortObjValue); break; case INT: final int intValue = (((Number) version.get(this.instance)).intValue()); this.oldVersion = intValue; version.set(this.instance, intValue + 1); ManagedInstance.LOG.debug("Version upgraded instance: {0} - {1}", this, intValue); break; case INT_OBJECT: final Integer intObjValue = version.get(this.instance) == null ? 0 : // Integer.valueOf(((Number) version.get(this.instance)).intValue()); this.oldVersion = intObjValue; version.set(this.instance, intObjValue + 1); ManagedInstance.LOG.debug("Version upgraded instance: {0} - {1}", this, intObjValue); break; case LONG: final long longValue = (((Number) version.get(this.instance)).longValue()); this.oldVersion = longValue; version.set(this.instance, longValue + 1); ManagedInstance.LOG.debug("Version upgraded instance: {0} - {1}", this, longValue); break; case LONG_OBJECT: final Long longObjValue = version.get(this.instance) == null ? 0l : // Long.valueOf((((Number) version.get(this.instance)).longValue())); this.oldVersion = longObjValue; version.set(this.instance, longObjValue + 1); ManagedInstance.LOG.debug("Version upgraded instance: {0} - {1}", this, longObjValue); break; case TIMESTAMP: final Timestamp value = new Timestamp(System.currentTimeMillis()); this.oldVersion = version.get(this.instance); version.set(this.instance, value); ManagedInstance.LOG.debug("Version upgraded instance: {0} - {1}", this, value); } } if (commit) { final Object newVersion = version.get(this.instance); rootType.performVersionUpdate(connection, this, this.oldVersion, newVersion); ManagedInstance.LOG.debug("Version committed instance: {0} - {1} -> {2}", this, this.oldVersion, newVersion); this.oldVersion = null; } else { this.changed(); } }
From source file:org.ednovo.gooru.infrastructure.persistence.hibernate.taxonomy.TaxonomyRepositoryHibernate.java
@Override public List<Code> findTaxonomyMappings(List<Code> codeIdList, boolean excludeTaxonomyPreference) { // Please don not change - there is a reason to specify this query // string here rather than a static string.... String findCurriculum = "SELECT distinct c.label,c.display_order, c.code,c.description, c.type_id, c.code_id, c.depth, c.root_node_id,c.display_code FROM code c inner join taxonomy_association t on c.code_id = t.target_code_id where t.source_code_id in ("; if (codeIdList.size() == 0) { return null; }//from w w w.j a v a2 s . co m Object[] a = new Object[codeIdList.size()]; for (int i = 0; i < codeIdList.size(); i++) { if (i < (codeIdList.size() - 1)) { findCurriculum = findCurriculum + "?,"; } else { findCurriculum = findCurriculum + "?)"; } a[i] = codeIdList.get(i).getCodeId(); } findCurriculum += " and active_flag =1 and " + generateOrgAuthSqlQueryWithData("c."); if (UserGroupSupport.getTaxonomyPreference() != null && !excludeTaxonomyPreference) { findCurriculum += " and c.root_node_id in (" + UserGroupSupport.getTaxonomyPreference() + ")"; } List<Code> codeList = new ArrayList<Code>(); List<Map<String, Object>> rows = getJdbcTemplateReadOnly().queryForList(findCurriculum, a); for (Map<?, ?> row : rows) { Code code = new Code(); code.setCode((String) row.get("code")); code.setDescription((String) row.get("description")); code.setCodeId((Integer) row.get("code_id")); code.setDepth(Short.valueOf(row.get("depth").toString())); code.setLabel((String) row.get("label")); code.setDisplayOrder(new Integer(row.get("display_order").toString())); code.setRootNodeId((Integer) row.get("root_node_id")); code.setdisplayCode((String) row.get("display_code")); CodeType codeType = new CodeType(); codeType.setTypeId((Integer) row.get("type_id")); code.setCodeType(codeType); List<Code> parentCodeList = new ArrayList<Code>(); List<Code> parentList = findParentTaxonomyCodesByCodeId(code.getCodeId(), parentCodeList); code.setParentsList(parentList); codeList.add(code); } return codeList.size() == 0 ? null : codeList; }
From source file:org.mifos.accounts.loan.business.LoanBORedoDisbursalIntegrationTest.java
@Ignore @Test/* w w w. j av a2 s . co m*/ public void testRedoLoanApplyWholeMiscFeeAfterFullPayment() 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_FEES), 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, 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:com.ebay.nest.io.sede.thrift.TCTLSeparatedProtocol.java
@Override public short readI16() throws TException { String val = readString(); lastPrimitiveWasNullFlag = val == null; try {/*from w ww. j a v a 2 s. c o m*/ return val == null || val.isEmpty() ? 0 : Short.valueOf(val).shortValue(); } catch (NumberFormatException e) { lastPrimitiveWasNullFlag = true; return 0; } }
From source file:org.energy_home.jemma.ah.internal.configurator.Configuratore.java
private Object getInstance(String type, String value) { if ((type == null) || ((type != null) && (type.equals("String")))) { return value; } else if (type.equals("Integer")) { return Integer.valueOf(value); } else if (type.equals("Boolean")) { return Boolean.valueOf(value); } else if (type.equals("Double")) { return Double.valueOf(value); } else if (type.equals("Short")) { return Short.valueOf(value); } else if (type.equals("Long")) { return Long.valueOf(value); } else if (type.equals("Float")) { return Float.valueOf(value); } else if (type.equals("Character")) { return Character.valueOf(value.charAt(0)); } else if (type.equals("int")) { return Integer.parseInt(value); } else if (type.equals("short")) { return Short.parseShort(value); } else if (type.equals("boolean")) { return Boolean.parseBoolean(value); } else if (type.equals("double")) { return Double.parseDouble(value); } else if (type.equals("long")) { return Long.parseLong(value); } else if (type.equals("float")) { return Float.parseFloat(value); } else if (type.equals("char")) { return value.charAt(0); }/*from w ww. j a v a 2s . co m*/ return value; }