Java Code Examples for com.google.common.math.IntMath#divide()

The following examples show how to use com.google.common.math.IntMath#divide() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataHandler.java    From Nations with MIT License 6 votes vote down vote up
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);
				}
			}
		}
	}
}
 
Example 2
Source File: DataHandler.java    From Nations with MIT License 5 votes vote down vote up
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;
}
 
Example 3
Source File: GuavaMathUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void should_round_divide_result() {
    int result1 = IntMath.divide(3, 2, RoundingMode.DOWN);
    assertThat(result1, equalTo(1));

    int result2 = IntMath.divide(3, 2, RoundingMode.UP);
    assertThat(result2, equalTo(2));
}
 
Example 4
Source File: AlternativeProvider.java    From ldp4j with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 5
Source File: SearchUtils.java    From fenixedu-cms with GNU Lesser General Public License v3.0 5 votes vote down vote up
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());
}
 
Example 6
Source File: Lists.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public int size() {
  return IntMath.divide(list.size(), size, RoundingMode.CEILING);
}
 
Example 7
Source File: GuavaIntMathUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test(expected = ArithmeticException.class)
public void whenDivideTwoIntegerValues_shouldThrowArithmeticExceptionIfRoundingNotDefinedButNecessary() {
    IntMath.divide(10, 3, RoundingMode.UNNECESSARY);
}
 
Example 8
Source File: GuavaIntMathUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void whenDivideTwoIntegerValues_shouldDivideThemAndReturnTheResultForFloorRounding() {
    int result = IntMath.divide(10, 3, RoundingMode.FLOOR);
    assertEquals(3, result);
}
 
Example 9
Source File: GuavaIntMathUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void whenDivideTwoIntegerValues_shouldDivideThemAndReturnTheResultForCeilingRounding() {
    int result = IntMath.divide(10, 3, RoundingMode.CEILING);
    assertEquals(4, result);
}
 
Example 10
Source File: SDRFieldCodec.java    From ipmi4j with Apache License 2.0 4 votes vote down vote up
@Override
public int getEncodedLength(String in) {
    return IntMath.divide(in.length() * 3, 4, RoundingMode.CEILING);
}
 
Example 11
Source File: SDRFieldCodec.java    From ipmi4j with Apache License 2.0 4 votes vote down vote up
@Override
public int getEncodedLength(String in) {
    return IntMath.divide(in.length(), 2, RoundingMode.CEILING);
}
 
Example 12
Source File: AbstractTftpReadTransfer.java    From tftp4j with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 13
Source File: Lists.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public int size() {
  return IntMath.divide(list.size(), size, RoundingMode.CEILING);
}
 
Example 14
Source File: Lists.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public int size() {
  return IntMath.divide(list.size(), size, RoundingMode.CEILING);
}
 
Example 15
Source File: Lists.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public int size() {
  return IntMath.divide(list.size(), size, RoundingMode.CEILING);
}
 
Example 16
Source File: Lists.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public int size() {
  return IntMath.divide(list.size(), size, RoundingMode.CEILING);
}
 
Example 17
Source File: MathUtils.java    From fastjgame with Apache License 2.0 2 votes vote down vote up
/**
 * 两个int相除,如果余数大于0,则进一
 *
 * @param a int
 * @param b int
 * @return int
 */
public static int divideIntCeil(int a, int b) {
    return IntMath.divide(a, b, RoundingMode.CEILING);
}
 
Example 18
Source File: MathUtil.java    From j360-dubbo-app-all with Apache License 2.0 2 votes vote down vote up
/**
 * 能控制rounding方向的相除.
 * 
 * jdk的'/'运算符,直接向下取整
 */
public static int divide(int p, int q, RoundingMode mode) {
	return IntMath.divide(p, q, mode);
}
 
Example 19
Source File: MathUtil.java    From vjtools with Apache License 2.0 2 votes vote down vote up
/**
 * 能控制rounding方向的int相除.
 * 
 * jdk的'/'运算符,直接向下取整
 */
public static int divide(int p, int q, RoundingMode mode) {
	return IntMath.divide(p, q, mode);
}
 
Example 20
Source File: MathUtil.java    From vjtools with Apache License 2.0 2 votes vote down vote up
/**
 * 能控制rounding方向的int相除.
 * 
 * jdk的'/'运算符,直接向下取整
 */
public static int divide(int p, int q, RoundingMode mode) {
	return IntMath.divide(p, q, mode);
}