本文整理汇总了Java中com.google.common.math.IntMath.divide方法的典型用法代码示例。如果您正苦于以下问题:Java IntMath.divide方法的具体用法?Java IntMath.divide怎么用?Java IntMath.divide使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.math.IntMath
的用法示例。
在下文中一共展示了IntMath.divide方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addToWorldChunks
import com.google.common.math.IntMath; //导入方法依赖的package包/类
public static void addToWorldChunks(Nation nation)
{
for (Rect r : nation.getRegion().getRects())
{
if (!worldChunks.containsKey(r.getWorld()))
{
worldChunks.put(r.getWorld(), new Hashtable<Vector2i, ArrayList<Nation>>());
}
Hashtable<Vector2i, ArrayList<Nation>> chunks = worldChunks.get(r.getWorld());
for (int i = IntMath.divide(r.getMinX(), 16, RoundingMode.FLOOR); i < IntMath.divide(r.getMaxX(), 16, RoundingMode.FLOOR) + 1; i++)
{
for (int j = IntMath.divide(r.getMinY(), 16, RoundingMode.FLOOR); j < IntMath.divide(r.getMaxY(), 16, RoundingMode.FLOOR) + 1; j++)
{
Vector2i vect = new Vector2i(i, j);
if (!chunks.containsKey(vect))
{
chunks.put(vect, new ArrayList<Nation>());
}
if (!chunks.get(vect).contains(nation))
{
chunks.get(vect).add(nation);
}
}
}
}
}
示例2: splitToNChunks
import com.google.common.math.IntMath; //导入方法依赖的package包/类
/**
* If there are fewer files than chunks, fewer than numChunks will be returned.
*/
private static Iterable<List<Map.Entry<Symbol, File>>> splitToNChunks(
final ImmutableMap<Symbol, File> inputMap, int numChunks) {
checkArgument(numChunks > 0);
final List<Map.Entry<Symbol, File>> emptyChunk = ImmutableList.of();
if (inputMap.isEmpty()) {
return Collections.nCopies(numChunks, emptyChunk);
}
final int chunkSize = IntMath.divide(inputMap.size(), numChunks, RoundingMode.UP);
final ImmutableList<List<Map.Entry<Symbol, File>>> chunks =
ImmutableList.copyOf(splitToChunksOfFixedSize(inputMap, chunkSize));
if (chunks.size() == numChunks) {
return chunks;
} else {
// there weren't enough elements to make the desired number of chunks, so we need to
// pad with empty chunks
final int shortage = numChunks - chunks.size();
final List<List<Map.Entry<Symbol, File>>> padding = Collections.nCopies(shortage, emptyChunk);
return Iterables.concat(chunks, padding);
}
}
示例3: paintComponent
import com.google.common.math.IntMath; //导入方法依赖的package包/类
@Override
protected void paintComponent(Graphics g1)
{
super.paintComponent(g1);
Graphics2D g = (Graphics2D)g1;
int cellsX = IntMath.divide(getWidth(), tileModel.getAvgTileWidth(), RoundingMode.UP);
int cellsY = IntMath.divide(getHeight(), tileModel.getTileHeight(), RoundingMode.UP);
tileModel.setMapWidth(cellsX);
tileModel.setMapHeight(cellsY);
// cut of partly draw hexagons
g.clipRect(0, 0, tileModel.getWorldWidth(), tileModel.getWorldHeight());
drawTiles(g);
Object oldAAhint = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
drawVectorField(g);
drawSelection(g);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldAAhint);
g1.setClip(null);
}
示例4: getTilesInRect
import com.google.common.math.IntMath; //导入方法依赖的package包/类
@Override
public List<Tile> getTilesInRect(int worldX0, int worldY0, int worldX1, int worldY1)
{
int x0 = IntMath.divide(worldX0, tileWidth, RoundingMode.FLOOR);
int y0 = IntMath.divide(worldY0, tileHeight, RoundingMode.FLOOR);
int x1 = IntMath.divide(worldX1, tileWidth, RoundingMode.FLOOR);
int y1 = IntMath.divide(worldY1, tileHeight, RoundingMode.FLOOR);
// Restrict to map bounds
int minX = Math.max(x0, 0);
int maxX = Math.min(x1, mapWidth - 1);
int minY = Math.max(y0, 0);
int maxY = Math.min(y1, mapHeight - 1);
List<Tile> result = new ArrayList<Tile>();
for (int y = minY; y <= maxY; y++)
{
for (int x = minX; y <= maxX; x++)
{
result.add(getTile(x, y));
}
}
return result;
}
示例5: getNation
import com.google.common.math.IntMath; //导入方法依赖的package包/类
public static Nation getNation(Location<World> loc)
{
if (!worldChunks.containsKey(loc.getExtent().getUniqueId()))
{
return null;
}
Vector2i area = new Vector2i(IntMath.divide(loc.getBlockX(), 16, RoundingMode.FLOOR), IntMath.divide(loc.getBlockZ(), 16, RoundingMode.FLOOR));
if (!worldChunks.get(loc.getExtent().getUniqueId()).containsKey(area))
{
return null;
}
for (Nation nation : worldChunks.get(loc.getExtent().getUniqueId()).get(area))
{
if (nation.getRegion().isInside(loc))
{
return nation;
}
}
// for (Entry<Vector2i, ArrayList<Nation>> e : worldChunks.get(loc.getExtent().getUniqueId()).entrySet())
// {
// if (e.getKey().equals(new Vector2i(IntMath.divide(loc.getBlockX(), 16, RoundingMode.FLOOR), IntMath.divide(loc.getBlockZ(), 16, RoundingMode.FLOOR))))
// {
// for (Nation nation : e.getValue())
// {
// if (nation.getRegion().isInside(loc))
// {
// return nation;
// }
// }
// return null;
// }
// }
return null;
}
示例6: divide
import com.google.common.math.IntMath; //导入方法依赖的package包/类
@Benchmark int divide(int reps) {
int tmp = 0;
for (int i = 0; i < reps; i++) {
int j = i & ARRAY_MASK;
tmp += IntMath.divide(ints[j], nonzero[j], mode);
}
return tmp;
}
示例7: DefaultPageImpl
import com.google.common.math.IntMath; //导入方法依赖的package包/类
public DefaultPageImpl(List<T> results, int page, int size) {
this.perPage = size;
this.page = page;
this.totalResults = results.size();
this.totalPages = perPage > 0 ? IntMath.divide(totalResults, perPage, RoundingMode.CEILING) : 0;
this.results = results;
}
示例8: Partition
import com.google.common.math.IntMath; //导入方法依赖的package包/类
public Partition(Collection<T> allItems, Comparator<T> comparator, int itemsPerPartition, int currentPartition) {
this.itemsPerPartition = itemsPerPartition;
this.numPartitions = IntMath.divide(allItems.size(), itemsPerPartition, RoundingMode.CEILING);
this.currentPartitionNumber = Math.min(this.numPartitions, Math.max(1, currentPartition));
this.partitionItems = allItems.stream().sorted(comparator)
.skip((currentPartition - 1) * itemsPerPartition).limit(itemsPerPartition).collect(toList());
}
示例9: getTileAtWorldPos
import com.google.common.math.IntMath; //导入方法依赖的package包/类
@Override
public Optional<Tile> getTileAtWorldPos(int worldX, int worldY)
{
int x = IntMath.divide(worldX, tileWidth, RoundingMode.FLOOR);
int y = IntMath.divide(worldY, tileHeight, RoundingMode.FLOOR);
if (x >= 0 && x < mapWidth && y >= 0 && y < mapHeight)
{
return Optional.of(getTile(x, y));
}
return Optional.absent();
}
示例10: AlternativeProvider
import com.google.common.math.IntMath; //导入方法依赖的package包/类
AlternativeProvider(List<MediaType> mediaTypes, List<CharacterEncoding> characterEncodings, List<Language> languages) {
this.mediaTypes=EntityProvider.of(mediaTypes);
this.characterEncodings=EntityProvider.of(characterEncodings);
this.languages=EntityProvider.of(languages);
this.size=
this.mediaTypes.consumableEntities()*
this.characterEncodings.consumableEntities()*
this.languages.consumableEntities();
this.position=0;
this.buckets=IntMath.divide(this.size,MAX_BUCKETS,RoundingMode.CEILING);
}
示例11: size
import com.google.common.math.IntMath; //导入方法依赖的package包/类
@Override
public int size() {
return IntMath.divide(list.size(), size, RoundingMode.CEILING);
}
示例12: size
import com.google.common.math.IntMath; //导入方法依赖的package包/类
@Override public int size() {
return IntMath.divide(list.size(), size, RoundingMode.CEILING);
}
示例13: base64MaxSize
import com.google.common.math.IntMath; //导入方法依赖的package包/类
private static int base64MaxSize(long n) {
return 4 * IntMath.divide((int) n, 3, CEILING);
}
示例14: AbstractTftpReadTransfer
import com.google.common.math.IntMath; //导入方法依赖的package包/类
public AbstractTftpReadTransfer(@Nonnull SocketAddress remoteAddress, @Nonnull TftpData source, @Nonnegative int blockSize) throws IOException {
super(remoteAddress);
this.source = source;
this.blockSize = blockSize;
this.blockCount = IntMath.divide(source.getSize() + 1, blockSize, RoundingMode.CEILING);
}
示例15: getEncodedLength
import com.google.common.math.IntMath; //导入方法依赖的package包/类
@Override
public int getEncodedLength(String in) {
return IntMath.divide(in.length(), 2, RoundingMode.CEILING);
}