/** * Creates a new {@link Tuple} with the desired {@code first} and * {@code second} objects. * * @param first The first object * @param second The second object * @param <K> The type of first object * @param <V> The type of second object * @return The new Tuple */ public static <K, V> Tuple<K, V> of(K first, V second) { return new Tuple<>(first, second); }
/** * Creates a new {@link BiConsumer} that takes the provided * {@link EnchantmentType} and applies it to the generated {@link ItemStack}. * The enchantmentType level is defined by the variable amount provided. * * @param level The variance in enchantmentType level * @param enchantmentType The enchantmentType to add * @return The new biconsumer to apply to an itemstack builder */ public static BiConsumer<ItemStack.Builder, Random> enchantment(VariableAmount level, EnchantmentType enchantmentType) { checkNotNull(level, "VariableAmount cannot be null!"); checkNotNull(enchantmentType, "EnchantmentType cannot be null!"); return enchantments(fixed(1), ImmutableList.of(new Tuple<>(enchantmentType, level))); }
/** * Creates a new {@link BiConsumer} that takes the provided * {@link Collection} of {@link EnchantmentType}s and applies a varying amount * of generated enchantments to the generated {@link ItemStack}. * * @param amount The varying amount of enchantments to use * @param itemEnchantmentTypes The enchantment pool to use * @return The new biconsumer to apply to an itemstack builder */ public static BiConsumer<ItemStack.Builder, Random> enchantmentsWithVanillaLevelVariance(VariableAmount amount, Collection<EnchantmentType> itemEnchantmentTypes) { checkNotNull(amount, "Variable amount cannot be null!"); checkNotNull(itemEnchantmentTypes, "EnchantmentType collection cannot be null!"); List<Tuple<EnchantmentType, VariableAmount>> list = itemEnchantmentTypes.stream() .map(enchantment -> { checkNotNull(enchantment, "EnchantmentType cannot be null!"); final int minimum = enchantment.getMinimumLevel(); final int maximum = enchantment.getMaximumLevel(); return new Tuple<>(enchantment, baseWithRandomAddition(minimum, maximum - minimum)); }) .collect(Collectors.toList()); return enchantments(amount, list); }
protected ImmutableList<T> init(double originalValue, List<T> originalFunctions) { final ImmutableList.Builder<Tuple<M, Double>> modifierMapBuilder = ImmutableList.builder(); final ImmutableList.Builder<T> functionListBuilder = ImmutableList.builder(); final ImmutableMap.Builder<M, Double> mapBuilder = ImmutableMap.builder(); double finalDamage = originalValue; for (T tuple : originalFunctions) { this.modifierFunctions.add(convertTuple(tuple.getModifier(), tuple.getFunction())); double tempDamage = checkNotNull(tuple.getFunction().applyAsDouble(finalDamage)); finalDamage += tempDamage; modifierMapBuilder.add(new Tuple<>(tuple.getModifier(), tempDamage)); mapBuilder.put(tuple.getModifier(), tempDamage); this.modifiers.put(tuple.getModifier(), tempDamage); functionListBuilder.add(convertTuple(tuple.getModifier(), tuple.getFunction())); } this.originalFinalAmount = finalDamage; this.originalModifiers = modifierMapBuilder.build(); this.originalModifierMap = mapBuilder.build(); return functionListBuilder.build(); }
@Test public void testIntersectsRay() { final AABB aabb = new AABB(new Vector3d(0, 0, 0), new Vector3d(2, 2, 2)); Assert.assertEquals(new Tuple<>(new Vector3d(2, 1, 1), new Vector3d(1, 0, 0)), aabb.intersects(new Vector3d(1, 1, 1), new Vector3d(1, 0, 0)).get()); Assert.assertEquals(new Tuple<>(new Vector3d(1, 2, 1), new Vector3d(0, 1, 0)), aabb.intersects(new Vector3d(1, 1, 1), new Vector3d(0, 1, 0)).get()); Assert.assertEquals(new Tuple<>(new Vector3d(1, 1, 2), new Vector3d(0, 0, 1)), aabb.intersects(new Vector3d(1, 1, 1), new Vector3d(0, 0, 1)).get()); Assert.assertEquals(new Tuple<>(new Vector3d(0, 0, 0), new Vector3d(-1, -1, -1).normalize()), aabb.intersects(new Vector3d(-1, -1, -1), new Vector3d(1, 1, 1)).get()); Assert.assertEquals(new Tuple<>(new Vector3d(0, 0, 1), new Vector3d(-1, -1, -0.0).normalize()), aabb.intersects(new Vector3d(-1, -1, 1), new Vector3d(1, 1, 0)).get()); Assert.assertEquals(new Tuple<>(new Vector3d(0, 1, 1), new Vector3d(-1, -0.0, -0.0)), aabb.intersects(new Vector3d(-1, 1, 1), new Vector3d(1, 0, 0)).get()); Assert.assertEquals(new Tuple<>(new Vector3d(2, 1, 1), new Vector3d(1, 0, 0)), aabb.intersects(new Vector3d(3, 1, 1), new Vector3d(-1, 0, 0)).get()); Assert.assertEquals(new Tuple<>(new Vector3d(1, 0, 1), new Vector3d(-0.0, -1, -0.0)), aabb.intersects(new Vector3d(1, -1, 1), new Vector3d(0, 1, 0)).get()); Assert.assertEquals(new Tuple<>(new Vector3d(1, 2, 1), new Vector3d(0, 1, 0)), aabb.intersects(new Vector3d(1, 3, 1), new Vector3d(0, -1, 0)).get()); Assert.assertEquals(new Tuple<>(new Vector3d(1, 1, 0), new Vector3d(-0.0, -0.0, -1)), aabb.intersects(new Vector3d(1, 1, -1), new Vector3d(0, 0, 1)).get()); Assert.assertEquals(new Tuple<>(new Vector3d(1, 1, 2), new Vector3d(0, 0, 1)), aabb.intersects(new Vector3d(1, 1, 3), new Vector3d(0, 0, -1)).get()); Assert.assertFalse(aabb.intersects(new Vector3d(-1, -1, -1), new Vector3d(0, 1, 0)).isPresent()); }
z = direction.getZ() * t + start.getZ(); return Optional.of(new Tuple<>(new Vector3d(x, y, z), normal));
public void load() { cachedTuple = new Tuple<>(wirelessData.shortband, wirelessData.wideband); }
public static <K, V> Tuple<K, V> of(K first, V second) { return new Tuple<>(first, second); }
public void load() { cachedTuple = new Tuple<>(wirelessData.shortband, wirelessData.wideband); }
public final List<Tuple<T, Function<? super Double, Double>>> getModifiers() { ImmutableList.Builder<Tuple<T, Function<? super Double, Double>>> builder = ImmutableList.builder(); for (Tuple<T, Function<? super Double, Double>> entry : this.modifierFunctions) { builder.add(new Tuple<>(entry.getFirst(), entry.getSecond())); } return builder.build(); } }
@Override public final void setOutputDamage(DamageModifier damageModifier, Function<? super Double, Double> function) { checkNotNull(damageModifier, "Damage modifier was null!"); checkNotNull(function, "Function was null!"); int indexToAddTo = 0; boolean addAtEnd = true; for (Iterator<Tuple<DamageModifier, Function<? super Double, Double>>> iterator = this.modifierFunctions.iterator(); iterator.hasNext(); ) { Tuple<DamageModifier, Function<? super Double, Double>> tuple = iterator.next(); if (tuple.getFirst().equals(damageModifier)) { iterator.remove(); addAtEnd = false; break; } indexToAddTo++; } if (addAtEnd) { this.modifierFunctions.add(new Tuple<>(damageModifier, function)); } else { this.modifierFunctions.add(indexToAddTo, new Tuple<>(damageModifier, function)); } this.recalculateDamages(this.baseDamage); }
/** * Creates a new {@link BiConsumer} that takes the provided * {@link Enchantment} and applies it to the generated {@link ItemStack}. * The enchantment level is defined by the variable amount provided. * * @param level The variance in enchantment level * @param enchantment The enchantment to add * @return The new biconsumer to apply to an itemstack builder */ public static BiConsumer<ItemStack.Builder, Random> enchantment(VariableAmount level, Enchantment enchantment) { checkNotNull(level, "VariableAmount cannot be null!"); checkNotNull(enchantment, "Enchantment cannot be null!"); return enchantments(fixed(1), ImmutableList.of(new Tuple<>(enchantment, level))); }
@Override public final void setDamage(DamageModifier damageModifier, Function<? super Double, Double> function) { checkNotNull(damageModifier, "Damage modifier was null!"); checkNotNull(function, "Function was null!"); int indexToAddTo = 0; boolean addAtEnd = true; for (Iterator<Tuple<DamageModifier, Function<? super Double, Double>>> iterator = this.modifierFunctions.iterator(); iterator.hasNext(); ) { Tuple<DamageModifier, Function<? super Double, Double>> tuple = iterator.next(); if (tuple.getFirst().equals(damageModifier)) { iterator.remove(); addAtEnd = false; break; } indexToAddTo++; } if (addAtEnd) { this.modifierFunctions.add(new Tuple<>(damageModifier, function)); } else { this.modifierFunctions.add(indexToAddTo, new Tuple<>(damageModifier, function)); } this.recalculateDamages(this.baseDamage); }
@Override public void addModifierAfter(DamageModifier damageModifier, Function<? super Double, Double> function, Set<DamageModifierType> after) { checkNotNull(damageModifier, "Damage modifier was null!"); checkNotNull(function, "Function was null!"); int indexToAddAfter = -1; int index = 0; for (Tuple<DamageModifier, Function<? super Double, Double>> tuple : this.modifierFunctions) { checkArgument(!tuple.getFirst().equals(damageModifier), "Cannot add a duplicate modifier!"); if (after.contains(tuple.getFirst().getType())) { indexToAddAfter = index; } index++; } if (indexToAddAfter == -1) { this.modifierFunctions.add(new Tuple<>(damageModifier, function)); } else { this.modifierFunctions.add(indexToAddAfter + 1, new Tuple<>(damageModifier, function)); } this.recalculateDamages(this.baseDamage); }
@Override public void addDamageModifierAfter(DamageModifier damageModifier, Function<? super Double, Double> function, Set<DamageModifierType> after) { checkNotNull(damageModifier, "Damage modifier was null!"); checkNotNull(function, "Function was null!"); int indexToAddAfter = -1; int index = 0; for (Tuple<DamageModifier, Function<? super Double, Double>> tuple : this.modifierFunctions) { checkArgument(!tuple.getFirst().equals(damageModifier), "Cannot add a duplicate modifier!"); if (after.contains(tuple.getFirst().getType())) { indexToAddAfter = index; } index++; } if (indexToAddAfter == -1) { this.modifierFunctions.add(new Tuple<>(damageModifier, function)); } else { this.modifierFunctions.add(indexToAddAfter + 1, new Tuple<>(damageModifier, function)); } this.recalculateDamages(this.baseDamage); }
protected ImmutableList<Tuple<T, Function<? super Double, Double>>> init(double originalValue, List<Tuple<T, Function<? super Double, Double>>> originalFunctions) { final ImmutableList.Builder<Tuple<T, Double>> modifierMapBuilder = ImmutableList.builder(); final ImmutableList.Builder<Tuple<T, Function<? super Double, Double>>> functionListBuilder = ImmutableList.builder(); final ImmutableMap.Builder<T, Double> mapBuilder = ImmutableMap.builder(); double finalDamage = originalValue; for (Tuple<T, Function<? super Double, Double>> tuple : originalFunctions) { this.modifierFunctions.add(new Tuple<>(tuple.getFirst(), tuple.getSecond())); double tempDamage = checkNotNull(tuple.getSecond().apply(finalDamage)); finalDamage += tempDamage; modifierMapBuilder.add(new Tuple<>(tuple.getFirst(), tempDamage)); mapBuilder.put(tuple.getFirst(), tempDamage); this.modifiers.put(tuple.getFirst(), tempDamage); functionListBuilder.add(tuple); } this.originalFinalAmount = finalDamage; this.originalModifiers = modifierMapBuilder.build(); this.originalModifierMap = mapBuilder.build(); return functionListBuilder.build(); }
@Override public void addDamageModifierBefore(DamageModifier damageModifier, Function<? super Double, Double> function, Set<DamageModifierType> before) { checkNotNull(damageModifier, "Damage modifier was null!"); checkNotNull(function, "Function was null!"); int indexToAddBefore = -1; int index = 0; for (Tuple<DamageModifier, Function<? super Double, Double>> tuple : this.modifierFunctions) { checkArgument(!tuple.getFirst().equals(damageModifier), "Cannot add a duplicate modifier!"); if (before.contains(tuple.getFirst().getType())) { indexToAddBefore = index; } index++; } if (indexToAddBefore == -1) { this.modifierFunctions.add(new Tuple<>(damageModifier, function)); } else { this.modifierFunctions.add(indexToAddBefore, new Tuple<>(damageModifier, function)); } this.recalculateDamages(this.baseDamage); }
@Override public void addDamageModifierBefore(DamageModifier damageModifier, Function<? super Double, Double> function, Set<DamageModifierType> before) { checkNotNull(damageModifier, "Damage modifier was null!"); checkNotNull(function, "Function was null!"); int indexToAddBefore = -1; int index = 0; for (Tuple<DamageModifier, Function<? super Double, Double>> tuple : this.modifierFunctions) { checkArgument(!tuple.getFirst().equals(damageModifier), "Cannot add a duplicate modifier!"); if (before.contains(tuple.getFirst().getType())) { indexToAddBefore = index; } index++; } if (indexToAddBefore == -1) { this.modifierFunctions.add(new Tuple<>(damageModifier, function)); } else { this.modifierFunctions.add(indexToAddBefore, new Tuple<>(damageModifier, function)); } this.recalculateDamages(this.baseDamage); }
/** * Creates a new {@link BiConsumer} that takes the provided * {@link Collection} of {@link Enchantment}s and applies a varying amount * of generated enchantments to the generated {@link ItemStack}. * * @param amount The varying amount of enchantments to use * @param itemEnchantments The enchantment pool to use * @return The new biconsumer to apply to an itemstack builder */ public static BiConsumer<ItemStack.Builder, Random> enchantmentsWithVanillaLevelVariance(VariableAmount amount, Collection<Enchantment> itemEnchantments) { checkNotNull(amount, "Variable amount cannot be null!"); checkNotNull(itemEnchantments, "Enchantment collection cannot be null!"); List<Tuple<Enchantment, VariableAmount>> list = itemEnchantments.stream() .map(enchantment -> { checkNotNull(enchantment, "Enchantment cannot be null!"); final int minimum = enchantment.getMinimumLevel(); final int maximum = enchantment.getMaximumLevel(); return new Tuple<>(enchantment, baseWithRandomAddition(minimum, maximum - minimum)); }) .collect(Collectors.toList()); return enchantments(amount, list); }
@JsonIgnore @ApiModelProperty(hidden = true) public Tuple<Class[], Object[]> getParsedParameters() { Class[] paramTypes = new Class[parameters.size()]; Object[] paramValues = new Object[parameters.size()]; try { for (int i = 0; i < parameters.size(); i++) { Tuple<Class, Object> tup = parameters.get(i).toObject(); paramTypes[i] = tup.getFirst(); paramValues[i] = tup.getSecond(); } } catch (ClassNotFoundException e) { throw new NotFoundException("Class could not be found: " + e.getMessage()); } catch (NoSuchFieldException e) { throw new NotFoundException("Field could not be found: " + e.getMessage()); } catch (IllegalAccessException e) { throw new ForbiddenException("Access not allowed: " + e.getMessage()); } return new Tuple<>(paramTypes, paramValues); } }