当前位置: 首页>>代码示例>>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;未经允许,请勿转载。