當前位置: 首頁>>代碼示例>>Java>>正文


Java BigDecimal.equals方法代碼示例

本文整理匯總了Java中java.math.BigDecimal.equals方法的典型用法代碼示例。如果您正苦於以下問題:Java BigDecimal.equals方法的具體用法?Java BigDecimal.equals怎麽用?Java BigDecimal.equals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.math.BigDecimal的用法示例。


在下文中一共展示了BigDecimal.equals方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getRatingClass

import java.math.BigDecimal; //導入方法依賴的package包/類
public static String getRatingClass(BigDecimal avgRating) {

        if (avgRating == null || avgRating.equals(BigDecimal.ZERO)) {
            return "0_0";
        }

        double f = avgRating.doubleValue();

        if (avgRating.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue() != avgRating
                .doubleValue()) {
            f = (Math.round(avgRating.doubleValue() * 2 + 0.5f)) / 2.0f;
        }

        if (f > 5) {
            f = 5.0f;
        }

        String v_str = f + "";

        if (v_str.length() > 0) {
            return v_str.replace('.', '_');
        }
        return "0_0";
    }
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:25,代碼來源:RatingCssMapper.java

示例2: doLogic

import java.math.BigDecimal; //導入方法依賴的package包/類
public static boolean doLogic(BigDecimal valueOne, Operator.Logic operator, BigDecimal valueTwo)
{
	switch (operator)
	{
		case EQUALS:
			return valueOne.equals(valueTwo);
		case NOTEQUALS:
			return !valueOne.equals(valueTwo);
		case GREATER:
			BigDecimal max = valueOne.max(valueTwo);
			return max.equals(valueOne);
		case SMALLER:
			BigDecimal min = valueOne.min(valueTwo);
			return min.equals(valueOne);
		default:
			return false;
	}
}
 
開發者ID:DirkDeVisser,項目名稱:pifuck,代碼行數:19,代碼來源:BasicBigDecimal.java

示例3: addTest

import java.math.BigDecimal; //導入方法依賴的package包/類
private static int addTest(BigDecimal arg1, BigDecimal arg2, BigDecimal expectedResult) {
    int failures = 0;
    BigDecimal result = arg1.add(arg2);
    if (!result.equals(expectedResult)) {
        System.out.println("Sum:" +
                arg1 + " + " +
                arg2 + " == " +
                result + "; expected  " +
                expectedResult
        );
        failures++;
    }
    result = arg2.add(arg1);
    if (!result.equals(expectedResult)) {
        System.out.println("Sum:" +
                arg2 + " + " +
                arg1 + " == " +
                result + "; expected  " +
                expectedResult
        );
        failures++;
    }
    return failures;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:25,代碼來源:RangeTests.java

示例4: sqrt

import java.math.BigDecimal; //導入方法依賴的package包/類
public static BigDecimal sqrt(BigDecimal A, final int SCALE) {
    BigDecimal x0 = new BigDecimal("0");
    BigDecimal x1 = new BigDecimal(Math.sqrt(A.doubleValue()));
    while (!x0.equals(x1)) {
        x0 = x1;
        x1 = A.divide(x0, SCALE, ROUND_HALF_UP);
        x1 = x1.add(x0);
        x1 = x1.divide(TWO, SCALE, ROUND_HALF_UP);

    }
    return x1;
}
 
開發者ID:Panzer1119,項目名稱:JAddOn,代碼行數:13,代碼來源:JBigNumber.java

示例5: equals

import java.math.BigDecimal; //導入方法依賴的package包/類
/**
 * Compare two objects for equality, after coercing to the same type if appropriate.
 * 
 * If the objects are identical (including both null) return true.
 * If either object is null, return false.
 * If either object is Boolean, coerce both to Boolean and check equality.
 * Similarly for Enum, String, BigDecimal, Double(Float), Long(Integer, Short, Byte, Character)
 * Otherwise default to using Object.equals().
 * 
 * @param obj0 the first object
 * @param obj1 the second object
 * @return true if the objects are equal
 * @throws ELException
 */
public static final boolean equals(final Object obj0, final Object obj1)
        throws ELException {
    if (obj0 == obj1) {
        return true;
    } else if (obj0 == null || obj1 == null) {
        return false;
    } else if (isBigDecimalOp(obj0, obj1)) {
        BigDecimal bd0 = (BigDecimal) coerceToNumber(obj0, BigDecimal.class);
        BigDecimal bd1 = (BigDecimal) coerceToNumber(obj1, BigDecimal.class);
        return bd0.equals(bd1);
    } else if (isDoubleOp(obj0, obj1)) {
        Double d0 = (Double) coerceToNumber(obj0, Double.class);
        Double d1 = (Double) coerceToNumber(obj1, Double.class);
        return d0.equals(d1);
    } else if (isBigIntegerOp(obj0, obj1)) {
        BigInteger bi0 = (BigInteger) coerceToNumber(obj0, BigInteger.class);
        BigInteger bi1 = (BigInteger) coerceToNumber(obj1, BigInteger.class);
        return bi0.equals(bi1);
    } else         if (isLongOp(obj0, obj1)) {
        Long l0 = (Long) coerceToNumber(obj0, Long.class);
        Long l1 = (Long) coerceToNumber(obj1, Long.class);
        return l0.equals(l1);
    } else if (obj0 instanceof Boolean || obj1 instanceof Boolean) {
        return coerceToBoolean(obj0).equals(coerceToBoolean(obj1));
    } else if (obj0.getClass().isEnum()) {
        return obj0.equals(coerceToEnum(obj1, obj0.getClass()));
    } else if (obj1.getClass().isEnum()) {
        return obj1.equals(coerceToEnum(obj0, obj1.getClass()));
    } else if (obj0 instanceof String || obj1 instanceof String) {
        int lexCompare = coerceToString(obj0).compareTo(coerceToString(obj1));
        return (lexCompare == 0) ? true : false;
    } else {
        return obj0.equals(obj1);
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:50,代碼來源:ELSupport.java

示例6: preHandle

import java.math.BigDecimal; //導入方法依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
		throws Exception {

	log.info("CommonInterceptor requestUri:{}", request.getRequestURI());
	
	HttpSession session = request.getSession();
	
	JSONObject obj = (JSONObject) session.getAttribute("cache_user");
	if (null == obj || obj.isEmpty()) {
		log.info("CommonInterceptor 用戶未登錄");
		request.getRequestDispatcher("/").forward(request, response);
		return false;
	} else {
		BigDecimal state = obj.getBigDecimal("state");
		if(!state.equals(new BigDecimal(0))) {
			log.info("用戶狀態異常,退出係統:state:{}", state);
			WebUtil.chearCache(session);
			request.getRequestDispatcher("/").forward(request, response);
			return false;
		}
		long loginTime = DateUtil.parseDate(obj.getString("loginTime")).getTime();
		long now = System.currentTimeMillis();
		if (null == cacheTime) {
			cacheTime = 10L;
		}
		log.info("cache_user:{}, cacheTime:[{} 分鍾], loginTime:{}, now:{}", obj.toJSONString(), cacheTime, DateUtil.nowStr(loginTime), DateUtil.nowStr(now));
		if (now > (loginTime + cacheTime * 1000 * 60)) {
			log.info("用戶長時間[{} 分鍾]未操作係統,退出係統:loginTime:{},now:{}", cacheTime,  DateUtil.nowStr(loginTime), DateUtil.nowStr(now));
			WebUtil.chearCache(session);
			request.getRequestDispatcher("/").forward(request, response);
			return false;
		}
		obj.put("loginTime", DateUtil.nowStr(now));
		session.setAttribute("cache_user", obj);
	}
	return true;
}
 
開發者ID:iunet,項目名稱:iunet-blog,代碼行數:39,代碼來源:CommonInterceptor.java

示例7: _equalsForBigDecimal

import java.math.BigDecimal; //導入方法依賴的package包/類
static private boolean _equalsForBigDecimal(BigDecimal a, Number b, Class<?> bc)
{
  if (bc == BigInteger.class)
  {
    return a.equals(new BigDecimal((BigInteger) b));
  }

  if ((bc == Double.class) || (bc == Float.class))
  {
    return a.equals(new BigDecimal(b.doubleValue()));
  }

  return a.equals(BigDecimal.valueOf(b.longValue()));
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:15,代碼來源:ComparisonBoundValue.java

示例8: equals

import java.math.BigDecimal; //導入方法依賴的package包/類
/**
 * @param obj0
 * @param obj1
 * @return
 * @throws EvaluationException
 */
public final static boolean equals(final Object obj0, final Object obj1)
        throws ELException {
    if (obj0 == obj1) {
        return true;
    } else if (obj0 == null || obj1 == null) {
        return false;
    } else if (obj0 instanceof Boolean || obj1 instanceof Boolean) {
        return coerceToBoolean(obj0).equals(coerceToBoolean(obj1));
    } else if (obj0.getClass().isEnum()) {
        return obj0.equals(coerceToEnum(obj1, obj0.getClass()));
    } else if (obj1.getClass().isEnum()) {
        return obj1.equals(coerceToEnum(obj0, obj1.getClass()));
    } else if (obj0 instanceof String || obj1 instanceof String) {
        int lexCompare = coerceToString(obj0).compareTo(coerceToString(obj1));
        return (lexCompare == 0) ? true : false;
    }
    if (isBigDecimalOp(obj0, obj1)) {
        BigDecimal bd0 = (BigDecimal) coerceToNumber(obj0, BigDecimal.class);
        BigDecimal bd1 = (BigDecimal) coerceToNumber(obj1, BigDecimal.class);
        return bd0.equals(bd1);
    }
    if (isDoubleOp(obj0, obj1)) {
        Double d0 = (Double) coerceToNumber(obj0, Double.class);
        Double d1 = (Double) coerceToNumber(obj1, Double.class);
        return d0.equals(d1);
    }
    if (isBigIntegerOp(obj0, obj1)) {
        BigInteger bi0 = (BigInteger) coerceToNumber(obj0, BigInteger.class);
        BigInteger bi1 = (BigInteger) coerceToNumber(obj1, BigInteger.class);
        return bi0.equals(bi1);
    }
    if (isLongOp(obj0, obj1)) {
        Long l0 = (Long) coerceToNumber(obj0, Long.class);
        Long l1 = (Long) coerceToNumber(obj1, Long.class);
        return l0.equals(l1);
    } else {
        return obj0.equals(obj1);
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:46,代碼來源:ELSupport.java

示例9: testRoundingFromBigInteger

import java.math.BigDecimal; //導入方法依賴的package包/類
private static int testRoundingFromBigInteger(BigInteger bi, int scale, MathContext mc) {
    int failures = 0;
    BigDecimal bd1 = new BigDecimal(bi,scale, mc);
    BigDecimal bd2 = (new BigDecimal(bi,scale)).round(mc);
    if (!bd1.equals(bd2)) {
        System.out.println("new BigDecimal(BigInteger,int,MathContext):" +
                "BigInteger == " +
                bi + ";  scale == " + scale + "; result == " +
                bd1 + "; expected  == " +
                bd2
        );
        failures++;
    }
    return failures;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:16,代碼來源:RangeTests.java

示例10: minLongConstructorTest

import java.math.BigDecimal; //導入方法依賴的package包/類
private static int minLongConstructorTest(MathContext mc) {
    int failures = 0;
    BigDecimal bd1 = new BigDecimal(Long.MIN_VALUE,mc);
    BigDecimal bd2 = new BigDecimal(Long.MIN_VALUE).round(mc);
    if (!bd1.equals(bd2)) {
        System.out.println("new BigDecimal(long,MathContext):" +
                "long == " +
                Long.MIN_VALUE + "; result == " +
                bd1 + "; expected  == " +
                bd2
        );
        failures++;
    }
    return failures;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:16,代碼來源:RangeTests.java

示例11: intern

import java.math.BigDecimal; //導入方法依賴的package包/類
/**
 * Return a reference to a shared BigDecimal object if the cache holds one of the same value as the BigDecimal
 * passed in.
 * Currently the only BigDecimal cached is zero.
 *
 * @param d The BigDecimal to intern
 * @return A reference to a shared BigDecimal object if the cache holds one of the same value as the BigDecimal
 * passed in.
 */
public BigDecimal intern(BigDecimal d) {
    if (d == null) {
        return d;
    } else if (d.equals(zeroDecimal)) {
        return zeroDecimal;
    } else {
        return d;
    }
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:19,代碼來源:InternMap.java

示例12: equals

import java.math.BigDecimal; //導入方法依賴的package包/類
/**
 * Compare two objects for equality, after coercing to the same type if
 * appropriate.
 *
 * If the objects are identical (including both null) return true. If either
 * object is null, return false. If either object is Boolean, coerce both to
 * Boolean and check equality. Similarly for Enum, String, BigDecimal,
 * Double(Float), Long(Integer, Short, Byte, Character) Otherwise default to
 * using Object.equals().
 *
 * @param obj0
 *            the first object
 * @param obj1
 *            the second object
 * @return true if the objects are equal
 * @throws ELException
 */
public static final boolean equals(final Object obj0, final Object obj1) throws ELException {
	if (obj0 == obj1) {
		return true;
	} else if (obj0 == null || obj1 == null) {
		return false;
	} else if (isBigDecimalOp(obj0, obj1)) {
		BigDecimal bd0 = (BigDecimal) coerceToNumber(obj0, BigDecimal.class);
		BigDecimal bd1 = (BigDecimal) coerceToNumber(obj1, BigDecimal.class);
		return bd0.equals(bd1);
	} else if (isDoubleOp(obj0, obj1)) {
		Double d0 = (Double) coerceToNumber(obj0, Double.class);
		Double d1 = (Double) coerceToNumber(obj1, Double.class);
		return d0.equals(d1);
	} else if (isBigIntegerOp(obj0, obj1)) {
		BigInteger bi0 = (BigInteger) coerceToNumber(obj0, BigInteger.class);
		BigInteger bi1 = (BigInteger) coerceToNumber(obj1, BigInteger.class);
		return bi0.equals(bi1);
	} else if (isLongOp(obj0, obj1)) {
		Long l0 = (Long) coerceToNumber(obj0, Long.class);
		Long l1 = (Long) coerceToNumber(obj1, Long.class);
		return l0.equals(l1);
	} else if (obj0 instanceof Boolean || obj1 instanceof Boolean) {
		return coerceToBoolean(obj0).equals(coerceToBoolean(obj1));
	} else if (obj0.getClass().isEnum()) {
		return obj0.equals(coerceToEnum(obj1, obj0.getClass()));
	} else if (obj1.getClass().isEnum()) {
		return obj1.equals(coerceToEnum(obj0, obj1.getClass()));
	} else if (obj0 instanceof String || obj1 instanceof String) {
		int lexCompare = coerceToString(obj0).compareTo(coerceToString(obj1));
		return (lexCompare == 0) ? true : false;
	} else {
		return obj0.equals(obj1);
	}
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:52,代碼來源:ELSupport.java

示例13: updateQuotePriceVolumeInt

import java.math.BigDecimal; //導入方法依賴的package包/類
/**
    * Update a quote's price and volume
    * 
    * @param symbol
    *            The PK of the quote
    * @param changeFactor
    *            the percent to change the old price by (between 50% and 150%)
    * @param sharedTraded
    *            the ammount to add to the current volume
    * @param publishQuotePriceChange
    *            used by the PingJDBCWrite Primitive to ensure no JMS is used,
    *            should be true for all normal calls to this API
    */
public QuoteDataBean updateQuotePriceVolumeInt(String symbol,
		BigDecimal changeFactor, double sharesTraded,
		boolean publishQuotePriceChange) throws Exception {

	if (TradeConfig.getUpdateQuotePrices() == false)
		return new QuoteDataBean();

	QuoteDataBean quoteData = null;
	Connection conn = null;
	UserTransaction txn = null;
	try {
		if (Log.doTrace())
			Log.trace("TradeDirect:updateQuotePriceVolume - inSession("
					+ this.inSession + ")", symbol, changeFactor,
					new Double(sharesTraded));

		conn = getConn();

		quoteData = getQuoteForUpdate(conn, symbol);
		BigDecimal oldPrice = quoteData.getPrice();
		double newVolume = quoteData.getVolume() + sharesTraded;

		if (oldPrice.equals(TradeConfig.PENNY_STOCK_PRICE)) {
			changeFactor = TradeConfig.PENNY_STOCK_RECOVERY_MIRACLE_MULTIPLIER;
		} else if (oldPrice.compareTo(TradeConfig.MAXIMUM_STOCK_PRICE) > 0) {
			changeFactor = TradeConfig.MAXIMUM_STOCK_SPLIT_MULTIPLIER;
		}

		BigDecimal newPrice = changeFactor.multiply(oldPrice).setScale(2,
				BigDecimal.ROUND_HALF_UP);

		updateQuotePriceVolume(conn, quoteData.getSymbol(), newPrice,
				newVolume);
		quoteData = getQuote(conn, symbol);

		commit(conn);

		if (publishQuotePriceChange) {
			publishQuotePriceChange(quoteData, oldPrice, changeFactor,
					sharesTraded);
		}

	} catch (Exception e) {
		Log
				.error("TradeDirect:updateQuotePriceVolume -- error updating quote price/volume for symbol:"
						+ symbol);
		rollBack(conn, e);
		throw e;
	} finally {
		releaseConn(conn);
	}
	return quoteData;
}
 
開發者ID:WASdev,項目名稱:sample.daytrader3,代碼行數:67,代碼來源:TradeDirect.java

示例14: isEqual

import java.math.BigDecimal; //導入方法依賴的package包/類
/**
 * Compares and returns the result. If one of them or both are null, false
 * is returned.
 * 
 * @param expected
 *            the value to which will be scaled
 * @param comparator
 *            the value to be compared to
 * @return true if the values are equal to the same scale
 */
public static boolean isEqual(BigDecimal expected, BigDecimal comparator) {
    if (expected == null || comparator == null) {
        return false;
    }
    return expected.equals(comparator.setScale(expected.scale(),
            RoundingMode.HALF_UP));
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:18,代碼來源:BigDecimalComparator.java


注:本文中的java.math.BigDecimal.equals方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。