/** * Returns a composed {@link TriConsumer} that first applies the {@code before} functions to its * input, and then applies this consumer to the result. If evaluation of either operation throws * an exception, it is relayed to the caller of the composed operation. * * @param <A> The type of the argument to the first given function, and of composed consumer * @param <B> The type of the argument to the second given function, and of composed consumer * @param <C> The type of the argument to the third given function, and of composed consumer * @param before1 The first function to apply before this consumer is applied * @param before2 The second function to apply before this consumer is applied * @param before3 The third function to apply before this consumer is applied * @return A composed {@code TriConsumer} that first applies the {@code before} functions to its * input, and then applies this consumer to the result. * @throws NullPointerException If given argument is {@code null} * @implSpec The input argument of this method is able to handle every type. */ @Nonnull default <A, B, C> TriConsumer<A, B, C> compose( @Nonnull final Function<? super A, ? extends T> before1, @Nonnull final ToIntFunction<? super B> before2, @Nonnull final ToIntFunction<? super C> before3) { Objects.requireNonNull(before1); Objects.requireNonNull(before2); Objects.requireNonNull(before3); return (a, b, c) -> accept(before1.apply(a), before2.applyAsInt(b), before3.applyAsInt(c)); }
@Override public void tick(World world, NBTCompound nbt) { if (++tickLimiter > tickRate) { tickLimiter = 0; List<EntityLiving> mobs = EntitySelector.mobs(world, area.toAABB()); if (mobs.size() >= mobLimit.applyAsInt(world)) return; final Map<Class<? extends EntityLiving>, Integer> mobCounts = new HashMap<>(4); final boolean isPeaceful = world.difficultySetting == EnumDifficulty.PEACEFUL; for (int attempt = 0; attempt < attemptsPerTick; attempt++) { final SpawnEntry<? extends EntityLiving> entry = spawnEntries.getRandomItem(world.rand); final Class<? extends EntityLiving> mobClass = entry.getMobClass(); if (!isPeaceful || !entry.isHostile) { int limit = mobClassLimit.get(mobClass); if (limit == 0 || mobCounts.computeIfAbsent( mobClass, cls -> (int) mobs.stream().filter(entity -> entity.getClass() == mobClass).count()) < limit) { entry.trySpawn(world, attemptsPerMob); } } } } }
static <T> int linearSearch(LinearSeq<T> seq, ToIntFunction<T> comparison) { int idx = 0; for (T current : seq) { int cmp = comparison.applyAsInt(current); if (cmp == 0) { return idx; } else if (cmp < 0) { return -(idx + 1); } idx += 1; } return -(idx + 1); }
public void allRayIntersectionsBreakable( Vec raypt, Vec rayNormalizedDir, ToIntFunction<Tp> cons) { if (!intersectsWithRay(raypt, rayNormalizedDir)) return; for (Tp item : container) { int res = cons.applyAsInt(item); if (res == -1) return; } forAllSubtree( (i, j, k) -> { if (subtree[i][j][k] != null) subtree[i][j][k].allRayIntersectionsBreakable(raypt, rayNormalizedDir, cons); }); }
private <E extends RuntimeException> void assertToIntFunction( ToIntFunction<Object> test, Class<E> type) { assertNotNull(test); try { test.applyAsInt(null); fail(); } catch (RuntimeException e) { assertException(type, e, "null"); } try { Stream.of("1", "2", "3").mapToInt(test); } catch (RuntimeException e) { assertException(type, e, "a"); } }