List of usage examples for java.lang Double MAX_VALUE
double MAX_VALUE
To view the source code for java.lang Double MAX_VALUE.
Click Source Link
From source file:com.redhat.lightblue.metadata.types.DateTypeTest.java
@Test public void testEqualsFalse() { assertFalse(dateType.equals(Double.MAX_VALUE)); }
From source file:edu.oregonstate.eecs.mcplan.domains.voyager.policies.AggressivePolicy.java
@Override public VoyagerAction getAction() { // Locate a large friendly force final ArrayList<Planet> friendly = Voyager.playerPlanets(s_, player_); Collections.sort(friendly, new Comparator<Planet>() { @Override/*from w ww .j a v a2s . co m*/ public int compare(final Planet a, final Planet b) { return b.population(Unit.Soldier) - a.population(Unit.Soldier); } }); final Planet primary = (friendly.isEmpty() ? null : friendly.get(0)); final Planet secondary = (friendly.size() <= 1 ? null : friendly.get(1)); final int primary_force = (primary != null ? primary.population(Unit.Soldier) - garrison_ : 0); final int secondary_force = (secondary != null ? secondary.population(Unit.Soldier) - garrison_ : 0); final int force = primary_force + secondary_force; if (primary != null) { // Sort enemy planets by defense strength per worker final ArrayList<Planet> enemy = Voyager.playerPlanets(s_, player_.enemy()); Collections.sort(enemy, new Comparator<Planet>() { @Override public int compare(final Planet a, final Planet b) { final int[] apop = Voyager.effectivePopulation(s_, a, player_.enemy()); final int[] bpop = Voyager.effectivePopulation(s_, b, player_.enemy()); final double aratio = apop[Unit.Worker.ordinal()] > 0 ? Voyager.defense_strength(apop) / apop[Unit.Worker.ordinal()] : Double.MAX_VALUE; final double bratio = bpop[Unit.Worker.ordinal()] > 0 ? Voyager.defense_strength(bpop) / bpop[Unit.Worker.ordinal()] : Double.MAX_VALUE; return (int) Math.signum(aratio - bratio); } }); // Find the enemy Planet with the best worker ratio that we have // enough forces to take over. for (final Planet p : enemy) { final int[] pop = Voyager.effectivePopulation(s_, p, player_.enemy()); final int d = Voyager.defense_strength(pop); final int a = Voyager.attack_strength(new int[] { 0, primary_force }); if (a > d) { return new LaunchAction(primary, p, new int[] { 0, primary_force }); } } // If there isn't a promising attack available, shift some soldiers for (final Planet p : friendly) { if (!p.equals(primary) && !p.equals(secondary)) { final int soldiers = p.population(Unit.Soldier) - garrison_; if (soldiers > 0) { return new LaunchAction(p, primary, new int[] { 0, soldiers }); } } } } // If there are no soldiers to shift, optimize production for (final Planet p : friendly) { if (p.nextProduced() == Unit.Worker && p.population(Unit.Worker) >= p.capacity) { return new SetProductionAction(p, Unit.Soldier); } } return new NothingAction(); }
From source file:org.yccheok.jstock.charting.Utils.java
/** * Returns daily chart data based on given stock history server. * * @param stockHistoryServer the stock history server * @return list of daily chart data/*from w w w . ja va 2 s. c o m*/ */ public static List<ChartData> getDailyChartData(StockHistoryServer stockHistoryServer) { final int days = stockHistoryServer.size(); List<ChartData> chartDatas = new ArrayList<ChartData>(); double prevPrice = 0; double openPrice = 0; double lastPrice = 0; double highPrice = Double.MIN_VALUE; double lowPrice = Double.MAX_VALUE; long volume = 0; long timestamp = 0; // Just perform simple one to one copy, without performing any // filtering. for (int i = 0; i < days; i++) { final long t = stockHistoryServer.getTimestamp(i); Stock stock = stockHistoryServer.getStock(t); prevPrice = stock.getPrevPrice(); openPrice = stock.getOpenPrice(); lastPrice = stock.getLastPrice(); highPrice = stock.getHighPrice(); lowPrice = stock.getLowPrice(); volume = stock.getVolume(); timestamp = stock.getTimestamp(); ChartData chartData = ChartData.newInstance(prevPrice, openPrice, lastPrice, highPrice, lowPrice, volume, timestamp); chartDatas.add(chartData); } return chartDatas; }
From source file:com.janrain.backplane.server.redisdao.RedisBackplaneMessageDAO.java
@Override public void deleteExpiredMessages() { Jedis jedis = null;/* w ww . ja v a 2 s . co m*/ int cleanedUpCount = 0; try { logger.info("preparing to cleanup v1 messages"); jedis = Redis.getInstance().getWriteJedis(); Set<byte[]> messageMetaBytes = jedis.zrangeByScore(RedisBackplaneMessageDAO.V1_MESSAGES.getBytes(), 0, Double.MAX_VALUE); if (messageMetaBytes != null) { logger.info("scanning " + messageMetaBytes.size() + " v1 messages"); int messageCounter = 0; for (byte[] b : messageMetaBytes) { if (messageCounter++ % 100 == 0) { logger.info("still scanning v1 messages..."); } String metaData = new String(b); String[] segs = metaData.split(" "); String key = segs[2]; // if the message body is not found, it expired and should be removed from indexes if (!jedis.exists(getKey(key))) { delete(key); cleanedUpCount++; } } } } catch (JedisConnectionException jce) { logger.warn("exited message cleanup: " + jce.getMessage()); Redis.getInstance().releaseBrokenResourceToPool(jedis); jedis = null; } catch (Exception e) { logger.warn(e); } finally { logger.info("exiting v1 message cleanup, " + cleanedUpCount + " messages deleted"); Redis.getInstance().releaseToPool(jedis); } }
From source file:org.uma.jmetal.util.point.impl.ArrayPointTest.java
@Test public void shouldGetDimensionValueReturnTheCorrectValue() { int dimension = 5; double[] array = { 1.0, -2.0, 45.5, -323.234, Double.MAX_VALUE }; Point point = new ArrayPoint(dimension); ReflectionTestUtils.setField(point, "point", array); assertEquals(1.0, point.getDimensionValue(0), EPSILON); assertEquals(-2.0, point.getDimensionValue(1), EPSILON); assertEquals(45.5, point.getDimensionValue(2), EPSILON); assertEquals(-323.234, point.getDimensionValue(3), EPSILON); assertEquals(Double.MAX_VALUE, point.getDimensionValue(4), EPSILON); }
From source file:com.opensymphony.xwork2.conversion.impl.NumberConverterTest.java
public void testStringToDoubleConversionPL() throws Exception { // given/* w ww.j a v a2 s . c o m*/ NumberConverter converter = new NumberConverter(); Map<String, Object> context = new HashMap<>(); context.put(ActionContext.LOCALE, new Locale("pl", "PL")); // when has max fraction digits Object value = converter.convertValue(context, null, null, null, "0," + StringUtils.repeat('0', 323) + "49", Double.class); // then does not lose fraction digits assertEquals(Double.MIN_VALUE, value); // when has max integer digits value = converter.convertValue(context, null, null, null, "17976931348623157" + StringUtils.repeat('0', 292) + ",0", Double.class); // then does not lose integer digits assertEquals(Double.MAX_VALUE, value); }
From source file:ddf.catalog.data.dynamic.impl.DynamicMetacardImplTest.java
@Test public void testSetAttribute() throws Exception { Attribute attribute = new AttributeImpl(STRING, "abc"); metacard.setAttribute(attribute);/*from www. j a v a 2 s. c o m*/ assertEquals("abc", baseBean.get(STRING)); attribute = new AttributeImpl(BOOLEAN, true); metacard.setAttribute(attribute); assertEquals(true, baseBean.get(BOOLEAN)); Date d = new Date(System.currentTimeMillis()); attribute = new AttributeImpl(DATE, d); metacard.setAttribute(attribute); assertEquals(d, baseBean.get(DATE)); attribute = new AttributeImpl(SHORT, Short.MIN_VALUE); metacard.setAttribute(attribute); assertEquals(Short.MIN_VALUE, baseBean.get(SHORT)); attribute = new AttributeImpl(INTEGER, Integer.MAX_VALUE); metacard.setAttribute(attribute); assertEquals(Integer.MAX_VALUE, baseBean.get(INTEGER)); attribute = new AttributeImpl(LONG, Long.MAX_VALUE); metacard.setAttribute(attribute); assertEquals(Long.MAX_VALUE, baseBean.get(LONG)); attribute = new AttributeImpl(FLOAT, Float.MAX_VALUE); metacard.setAttribute(attribute); assertEquals(Float.MAX_VALUE, baseBean.get(FLOAT)); attribute = new AttributeImpl(DOUBLE, Double.MAX_VALUE); metacard.setAttribute(attribute); assertEquals(Double.MAX_VALUE, baseBean.get(DOUBLE)); Byte[] bytes = new Byte[] { 0x00, 0x01, 0x02, 0x03 }; attribute = new AttributeImpl(BINARY, bytes); metacard.setAttribute(attribute); assertEquals(bytes, baseBean.get(BINARY)); attribute = new AttributeImpl(XML, XML_STRING); metacard.setAttribute(attribute); assertEquals(XML_STRING, baseBean.get(XML)); attribute = new AttributeImpl(OBJECT, XML_STRING); metacard.setAttribute(attribute); assertEquals(XML_STRING, baseBean.get(OBJECT)); List<Serializable> list = new ArrayList<>(); list.add("123"); list.add("234"); list.add("345"); attribute = new AttributeImpl(STRING_LIST, list); metacard.setAttribute(attribute); assertEquals(list, baseBean.get(STRING_LIST)); }
From source file:com.janrain.backplane.server.dao.redis.RedisBackplaneMessageDAO.java
public void deleteExpiredMessages() { Jedis jedis = null;// w w w . j a v a 2 s. c o m int cleanedUpCount = 0; try { logger.info("preparing to cleanup v1 messages"); jedis = Redis.getInstance().getWriteJedis(); Set<byte[]> messageMetaBytes = jedis.zrangeByScore(RedisBackplaneMessageDAO.V1_MESSAGES.getBytes(), 0, Double.MAX_VALUE); if (messageMetaBytes != null) { logger.info("scanning " + messageMetaBytes.size() + " v1 messages"); int messageCounter = 0; for (byte[] b : messageMetaBytes) { if (messageCounter++ % 100 == 0) { logger.info("still scanning v1 messages..."); } String metaData = new String(b); String[] segs = metaData.split(" "); String key = segs[2]; // if the message body is not found, it expired and should be removed from indexes if (!jedis.exists(getKey(key))) { delete(key); cleanedUpCount++; } } } } catch (JedisConnectionException jce) { logger.warn("exited message cleanup: " + jce.getMessage()); Redis.getInstance().releaseBrokenResourceToPool(jedis); jedis = null; } catch (Exception e) { logger.warn(e); } finally { logger.info("exiting v1 message cleanup, " + cleanedUpCount + " messages deleted"); Redis.getInstance().releaseToPool(jedis); } }
From source file:MathUtil.java
/** * Replacement for missing Math.pow(double, double) * /*from ww w. j ava 2 s.c om*/ * @param x * @param y * @return */ public static double pow(double x, double y) { // Convert the real power to a fractional form int den = 1024; // declare the denominator to be 1024 /* * Conveniently 2^10=1024, so taking the square root 10 times will yield * our estimate for n. In our example n^3=8^2 n^1024 = 8^683. */ int num = (int) (y * den); // declare numerator int iterations = 10; /* * declare the number of square root iterations * associated with our denominator, 1024. */ double n = Double.MAX_VALUE; /* * we initialize our estimate, setting it to * max */ while (n >= Double.MAX_VALUE && iterations > 1) { /* * We try to set our estimate equal to the right hand side of the * equation (e.g., 8^2048). If this number is too large, we will * have to rescale. */ n = x; for (int i = 1; i < num; i++) { n *= x; } /* * here, we handle the condition where our starting point is too * large */ if (n >= Double.MAX_VALUE) { iterations--; /* reduce the iterations by one */ den = (int) (den / 2); /* redefine the denominator */ num = (int) (y * den); // redefine the numerator } } /************************************************* ** We now have an appropriately sized right-hand-side. Starting with * this estimate for n, we proceed. **************************************************/ for (int i = 0; i < iterations; i++) { n = Math.sqrt(n); } // Return our estimate return n; }
From source file:com.redhat.lightblue.metadata.types.DoubleTypeTest.java
@Test public void testEqualsFalse() { assertFalse(doubleType.equals(Double.MAX_VALUE)); }