当前位置: 首页>>代码示例>>Java>>正文


Java DoubleMath.roundToInt方法代码示例

本文整理汇总了Java中com.google.common.math.DoubleMath.roundToInt方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleMath.roundToInt方法的具体用法?Java DoubleMath.roundToInt怎么用?Java DoubleMath.roundToInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.math.DoubleMath的用法示例。


在下文中一共展示了DoubleMath.roundToInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
public BufferedImage create(String hash, int size) {
    Preconditions.checkArgument(size > 0 && StringUtils.isNotBlank(hash));

    boolean[][] array = genartor.getBooleanValueArray(hash);


    int ratio = DoubleMath.roundToInt(size / 5.0, RoundingMode.HALF_UP);

    BufferedImage identicon = new BufferedImage(ratio * 5, ratio * 5, BufferedImage.TYPE_INT_ARGB);
    Graphics graphics = identicon.getGraphics();

    graphics.setColor(genartor.getBackgroundColor()); // 背景色
    graphics.fillRect(0, 0, identicon.getWidth(), identicon.getHeight());

    graphics.setColor(genartor.getForegroundColor()); // 图案前景色
    for (int i = 0; i < 6; i++) {
        for (int j = 0; j < 5; j++) {
            if (array[i][j]) {
                graphics.fillRect(j * ratio, i * ratio, ratio, ratio);
            }
        }
    }

    return identicon;
}
 
开发者ID:superhj1987,项目名称:awesome-identicon,代码行数:26,代码来源:Identicon.java

示例2: addPath

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
static void addPath(Graph<?> graph, Point... points) {
  final List<Point> newPoints = newArrayList();
  for (int i = 0; i < points.length - 1; i++) {
    final double dist = Point.distance(points[i], points[i + 1]);
    final Point unit = Point.divide(Point.diff(points[i + 1], points[i]),
        dist);
    final int numPoints = DoubleMath.roundToInt(dist / POINT_DISTANCE,
        RoundingMode.FLOOR);
    for (int j = 0; j < numPoints; j++) {
      final double factor = j * POINT_DISTANCE;
      newPoints.add(new Point(points[i].x + factor * unit.x, points[i].y
          + factor * unit.y));
    }
  }
  newPoints.add(points[points.length - 1]);
  Graphs.addPath(graph, newPoints.toArray(new Point[newPoints.size()]));
}
 
开发者ID:JDevlieghere,项目名称:MAS,代码行数:18,代码来源:FactoryExample.java

示例3: place

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
private static <C extends Command> List<CommandBlock<C>> place(List<? extends C> chain,
    Vec3I min, Vec3I max, Orientation3 orientation) throws NotEnoughSpaceException {
  checkNotNull(chain, "chain == null!");
  checkNotNull(min, "min == null!");
  checkNotNull(max, "max == null!");
  checkNotNull(orientation, "orientation == null!");
  checkArgument(min.x < max.x, "min.x >= max.x!");
  checkArgument(min.z < max.y, "min.y >= max.y!");
  checkArgument(min.z < max.y, "min.z >= max.z!");

  int deltaX = max.x - min.x;
  int deltaY = max.y - min.y;
  int deltaZ = max.z - min.z;

  // Initialized to minimal side length of a cube that can hold all commands
  int sideLength = DoubleMath.roundToInt(Math.cbrt(chain.size()), CEILING);
  while (true) {
    // -1 because the corners of getSpaceFillingCurve are inclusive
    Vec3I estimatedMax = Vec3I.min(max, min.plus(new Vec3I(sideLength - 1)));
    List<Vec3I> curve = getSpaceFillingCurve(min, estimatedMax, orientation);
    try {
      return ChainPlacer.place(chain, curve);
    } catch (NotEnoughSpaceException ex) {
      if (sideLength > max(deltaX, deltaY, deltaZ)) {
        throw ex;
      }
      sideLength++;
    }
  }
}
 
开发者ID:Energyxxer,项目名称:Vanilla-Injection,代码行数:31,代码来源:CommandBlockPlacer.java

示例4: getInterval

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
/**
 * recalculate interval(in hours) if total number of partitions greater than maximum number of allowed partitions
 *
 * @param difference in range
 * @param hour interval (ex: 4 hours)
 * @param Maximum number of allowed partitions
 * @return calculated interval in hours
 */
private int getInterval(long diffInMilliSecs, long hourInterval, int maxIntervals) {
  int totalHours = DoubleMath.roundToInt((double) diffInMilliSecs / (60 * 60 * 1000), RoundingMode.CEILING);
  int totalIntervals = DoubleMath.roundToInt((double) totalHours / hourInterval, RoundingMode.CEILING);
  if (totalIntervals > maxIntervals) {
    hourInterval = DoubleMath.roundToInt((double) totalHours / maxIntervals, RoundingMode.CEILING);
  }
  return Ints.checkedCast(hourInterval) + 1;
}
 
开发者ID:Hanmourang,项目名称:Gobblin,代码行数:17,代码来源:HourWatermark.java

示例5: getInterval

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
/**
 * recalculate interval(in hours) if total number of partitions greater than maximum number of allowed partitions
 *
 * @param difference in range
 * @param hour interval (ex: 4 hours)
 * @param Maximum number of allowed partitions
 * @return calculated interval in hours
 */

private int getInterval(long diffInMilliSecs, long hourInterval, int maxIntervals) {

  long totalHours = DoubleMath.roundToInt((double) diffInMilliSecs / (60 * 60 * 1000),
          RoundingMode.CEILING);
  long totalIntervals = DoubleMath.roundToInt((double) totalHours / hourInterval, RoundingMode.CEILING);
  if (totalIntervals > maxIntervals) {
    hourInterval = DoubleMath.roundToInt((double) totalHours / maxIntervals, RoundingMode.CEILING);
  }
  return Ints.checkedCast(hourInterval);
}
 
开发者ID:Hanmourang,项目名称:Gobblin,代码行数:20,代码来源:TimestampWatermark.java

示例6: getInterval

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
/**
 * recalculate interval(in hours) if total number of partitions greater than maximum number of allowed partitions
 *
 * @param difference in range
 * @param hour interval (ex: 4 hours)
 * @param Maximum number of allowed partitions
 * @return calculated interval in days
 */
private int getInterval(long diffInMilliSecs, long hourInterval, int maxIntervals) {
  long dayInterval = TimeUnit.HOURS.toDays(hourInterval);
  int totalHours = DoubleMath.roundToInt((double) diffInMilliSecs / (60 * 60 * 1000), RoundingMode.CEILING);
  int totalIntervals = DoubleMath.roundToInt((double) totalHours / (dayInterval * 24), RoundingMode.CEILING);
  if (totalIntervals > maxIntervals) {
    hourInterval = DoubleMath.roundToInt((double) totalHours / maxIntervals, RoundingMode.CEILING);
    dayInterval = TimeUnit.HOURS.toDays(hourInterval);
  }
  return Ints.checkedCast(dayInterval) + 1;
}
 
开发者ID:Hanmourang,项目名称:Gobblin,代码行数:19,代码来源:DateWatermark.java

示例7: getBooleanValueArray

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
@Override
public boolean[][] getBooleanValueArray(String hash) {
    Preconditions.checkArgument(StringUtils.isNotBlank(hash) && hash.length() >= 16,
            "illegal argument hash:not null and size >= 16");

    this.hash = hash;

    boolean[][] array = new boolean[6][5];

    //初始化字符串
    for (int i = 0; i < 6; i++) {
        for (int j = 0; j < 5; j++) {
            array[i][j] = false;
        }
    }

    for (int i = 0; i < hash.length(); i += 2) {
        int s = i / 2; //只取hash字符串偶数编号(从0开始)的字符

        boolean v =
                DoubleMath.roundToInt(Integer.parseInt(hash.charAt(i) + "", 16) / 10.0, RoundingMode.HALF_UP) > 0 ? true : false;
        if (s % 3 == 0) {
            array[s / 3][0] = v;
            array[s / 3][4] = v;
        } else if (s % 3 == 1) {
            array[s / 3][1] = v;
            array[s / 3][3] = v;
        } else {
            array[s / 3][2] = v;
        }
    }

    this.booleanValueArray = array;

    return this.booleanValueArray;
}
 
开发者ID:superhj1987,项目名称:awesome-identicon,代码行数:37,代码来源:DefaultGenerator.java

示例8: roundToInt

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
@Benchmark int roundToInt(int reps) {
  int tmp = 0;
  for (int i = 0; i < reps; i++) {
    int j = i & ARRAY_MASK;
    tmp += DoubleMath.roundToInt(doubleInIntRange[j], mode);
  }
  return tmp;
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:9,代码来源:DoubleMathRoundingBenchmark.java

示例9: getInterval

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
/**
 * recalculate interval(in hours) if total number of partitions greater than maximum number of allowed partitions
 *
 * @param difference in range
 * @param hour interval (ex: 4 hours)
 * @param Maximum number of allowed partitions
 * @return calculated interval in hours
 */
private static int getInterval(long diffInMilliSecs, long hourInterval, int maxIntervals) {
  int totalHours = DoubleMath.roundToInt((double) diffInMilliSecs / (60 * 60 * 1000), RoundingMode.CEILING);
  int totalIntervals = DoubleMath.roundToInt((double) totalHours / hourInterval, RoundingMode.CEILING);
  if (totalIntervals > maxIntervals) {
    hourInterval = DoubleMath.roundToInt((double) totalHours / maxIntervals, RoundingMode.CEILING);
  }
  return Ints.checkedCast(hourInterval);
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:17,代码来源:HourWatermark.java

示例10: getInterval

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
/**
 * recalculate interval(in hours) if total number of partitions greater than maximum number of allowed partitions
 *
 * @param difference in range
 * @param hour interval (ex: 4 hours)
 * @param Maximum number of allowed partitions
 * @return calculated interval in hours
 */

private static int getInterval(long diffInMilliSecs, long hourInterval, int maxIntervals) {

  long totalHours = DoubleMath.roundToInt((double) diffInMilliSecs / (60 * 60 * 1000), RoundingMode.CEILING);
  long totalIntervals = DoubleMath.roundToInt((double) totalHours / hourInterval, RoundingMode.CEILING);
  if (totalIntervals > maxIntervals) {
    hourInterval = DoubleMath.roundToInt((double) totalHours / maxIntervals, RoundingMode.CEILING);
  }
  return Ints.checkedCast(hourInterval);
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:19,代码来源:TimestampWatermark.java

示例11: getInterval

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
/**
 * recalculate interval(in hours) if total number of partitions greater than maximum number of allowed partitions
 *
 * @param difference in range
 * @param hour interval (ex: 4 hours)
 * @param Maximum number of allowed partitions
 * @return calculated interval in days
 */
private static int getInterval(long diffInMilliSecs, long hourInterval, int maxIntervals) {
  long dayInterval = TimeUnit.HOURS.toDays(hourInterval);
  int totalHours = DoubleMath.roundToInt((double) diffInMilliSecs / (60 * 60 * 1000), RoundingMode.CEILING);
  int totalIntervals = DoubleMath.roundToInt((double) totalHours / (dayInterval * 24), RoundingMode.CEILING);
  if (totalIntervals > maxIntervals) {
    hourInterval = DoubleMath.roundToInt((double) totalHours / maxIntervals, RoundingMode.CEILING);
    dayInterval = DoubleMath.roundToInt((double) hourInterval / 24, RoundingMode.CEILING);
  }
  return Ints.checkedCast(dayInterval);
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:19,代码来源:DateWatermark.java

示例12: getColor

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
@Override
public Color getColor(double x, double y) {

	if (colorMaps == null)
		initializeColorMap();

	checkRanges(x, y);

	double df = 1 / 3.0;

	int indexX = DoubleMath.roundToInt(x / df, RoundingMode.FLOOR);
	int indexY = DoubleMath.roundToInt(y / df, RoundingMode.FLOOR);
	double fx = 3.0 * (x % df);
	double fy = 3.0 * (y % df);

	// explicitly test for this corner cases -> rounding errors
	if (x == 1.0)
	{
		indexX = 2;
		fx = 1.0;
	}

	if (y == 1.0)
	{
		indexY = 2;
		fy = 1.0;
	}

	return colorMaps[indexX][indexY].getColor(fx, fy);
}
 
开发者ID:igd-iva,项目名称:colormap-explorer,代码行数:31,代码来源:RobertsonAndOCallaghan1.java

示例13: mapXToScreen

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
private int mapXToScreen(double val, int width)
{
	double min = stats.getMin();
	double max = stats.getMax();
	
	int barWidth = width - 2 * insetX;
	
	int value = DoubleMath.roundToInt(barWidth * (val - min) / (max - min), RoundingMode.HALF_UP);

	if (!metric.moreIsBetter())
		value = barWidth - value;	// maybe we have to subtract 1px here
	
	return value;
}
 
开发者ID:igd-iva,项目名称:colormap-explorer,代码行数:15,代码来源:JStatBar.java

示例14: copyStreams

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
private static long copyStreams(final InputStream from, final OutputStream to,
        final FileStreamingProgressListener progressListener, final long start, final long length,
        final String filename) throws IOException {

    final long startMillis = System.currentTimeMillis();
    LOG.trace("Start of copy-streams of file {} from {} to {}", filename, start, length);

    Preconditions.checkNotNull(from);
    Preconditions.checkNotNull(to);
    final byte[] buf = new byte[BUFFER_SIZE];
    long total = 0;
    int progressPercent = 1;

    ByteStreams.skipFully(from, start);

    long toRead = length;
    boolean toContinue = true;
    long shippedSinceLastEvent = 0;

    while (toContinue) {
        final int r = from.read(buf);
        if (r == -1) {
            break;
        }

        toRead -= r;
        if (toRead > 0) {
            to.write(buf, 0, r);
            total += r;
            shippedSinceLastEvent += r;
        } else {
            to.write(buf, 0, (int) toRead + r);
            total += toRead + r;
            shippedSinceLastEvent += toRead + r;
            toContinue = false;
        }

        if (progressListener != null) {
            final int newPercent = DoubleMath.roundToInt(total * 100.0 / length, RoundingMode.DOWN);

            // every 10 percent an event
            if (newPercent == 100 || newPercent > progressPercent + 10) {
                progressPercent = newPercent;
                progressListener.progress(length, shippedSinceLastEvent, total);
                shippedSinceLastEvent = 0;
            }
        }
    }

    final long totalTime = System.currentTimeMillis() - startMillis;

    if (total < length) {
        throw new FileStreamingFailedException(filename + ": " + (length - total)
                + " bytes could not be written to client, total time on write: !" + totalTime + " ms");
    }

    LOG.trace("Finished copy-stream of file {} with length {} in {} ms", filename, length, totalTime);

    return total;
}
 
开发者ID:eclipse,项目名称:hawkbit,代码行数:61,代码来源:FileStreamingUtil.java

示例15: roundToInt

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
private static int roundToInt(double s) {
    return DoubleMath.roundToInt(s, RoundingMode.HALF_EVEN);
}
 
开发者ID:anonl,项目名称:nvlist,代码行数:4,代码来源:OffscreenRenderTask.java


注:本文中的com.google.common.math.DoubleMath.roundToInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。