@Override
 public void allocateFilterResources(GL2 gl) {
   OptionalInt shader = ShaderUtil.createFragmentShader(gl, createSource());
   if (shader.isPresent()) {
     linkedShader = shader.getAsInt();
     OptionalInt program = ShaderUtil.createSingleShaderProgram(gl, linkedShader);
     if (program.isPresent()) {
       linkedProgram = program.getAsInt();
     } else {
       ShaderUtil.deleteShaderProgram(gl, linkedProgram);
       linkedProgram = 0;
     }
   }
 }
    public ListenableFuture<?> partitionPage(Page page) {
      requireNonNull(page, "page is null");

      Page partitionFunctionArgs = getPartitionFunctionArguments(page);
      for (int position = 0; position < page.getPositionCount(); position++) {
        if (nullChannel.isPresent() && page.getBlock(nullChannel.getAsInt()).isNull(position)) {
          for (PageBuilder pageBuilder : pageBuilders) {
            pageBuilder.declarePosition();

            for (int channel = 0; channel < sourceTypes.size(); channel++) {
              Type type = sourceTypes.get(channel);
              type.appendTo(page.getBlock(channel), position, pageBuilder.getBlockBuilder(channel));
            }
          }
        } else {
          int partition = partitionFunction.getPartition(partitionFunctionArgs, position);

          PageBuilder pageBuilder = pageBuilders.get(partition);
          pageBuilder.declarePosition();

          for (int channel = 0; channel < sourceTypes.size(); channel++) {
            Type type = sourceTypes.get(channel);
            type.appendTo(page.getBlock(channel), position, pageBuilder.getBlockBuilder(channel));
          }
        }
      }
      return flush(false);
    }
Exemple #3
0
  @Override
  protected DataBuffer encodeBespoke() {
    int size = 3 * Short.BYTES;
    for (Model model : Arrays.asList(primary, secondary)) {
      size += model.getId().isPresent() ? Short.BYTES : Byte.BYTES;
      size += model.getAnimation().isPresent() ? Short.BYTES : Byte.BYTES;
    }

    DataBuffer buffer = DataBuffer.allocate(size);
    for (OptionalInt optional :
        Arrays.asList(
            primary.getId(), secondary.getId(), primary.getAnimation(), secondary.getAnimation())) {
      if (optional.isPresent()) {
        int id = optional.getAsInt();
        buffer.putByte(id >> 8 + 1);
        buffer.putByte(id);
      } else {
        buffer.putBoolean(false);
      }
    }

    buffer.putShort(scale);
    buffer.putShort(pitch);
    buffer.putShort(roll);

    return buffer.flip().asReadOnlyBuffer();
  }
    public int partOne(Sample gift) {
      for (Map.Entry<Integer, Sample> entry : samples.entrySet()) {
        int sue = entry.getKey();
        Sample sample = entry.getValue();

        boolean found = true;

        for (String compound : gift.knownCompounds()) {
          OptionalInt optional = sample.amount(compound);

          if (!optional.isPresent()) {
            continue;
          }

          int knownAmount = optional.getAsInt();
          int actualAmount = gift.amount(compound).getAsInt();

          if (knownAmount != actualAmount) {
            found = false;
            break;
          }
        }

        if (found) {
          return sue;
        }
      }

      throw new IllegalArgumentException("Failed to find gift: " + gift + ".");
    }
Exemple #5
0
  public static void main(String... args) {

    List<Integer> numbers = Arrays.asList(3, 4, 5, 1, 2);

    Arrays.stream(numbers.toArray()).forEach(System.out::println);
    int calories = Dish.menu.stream().mapToInt(Dish::getCalories).sum();
    System.out.println("Number of calories:" + calories);

    // max and OptionalInt
    OptionalInt maxCalories = Dish.menu.stream().mapToInt(Dish::getCalories).max();

    int max;
    if (maxCalories.isPresent()) {
      max = maxCalories.getAsInt();
    } else {
      // we can choose a default value
      max = 1;
    }
    System.out.println(max);

    // numeric ranges
    IntStream evenNumbers = IntStream.rangeClosed(1, 100).filter(n -> n % 2 == 0);

    System.out.println(evenNumbers.count());

    Stream<int[]> pythagoreanTriples =
        IntStream.rangeClosed(1, 100)
            .boxed()
            .flatMap(
                a ->
                    IntStream.rangeClosed(a, 100)
                        .filter(b -> Math.sqrt(a * a + b * b) % 1 == 0)
                        .boxed()
                        .map(b -> new int[] {a, b, (int) Math.sqrt(a * a + b * b)}));

    pythagoreanTriples.forEach(t -> System.out.println(t[0] + ", " + t[1] + ", " + t[2]));
  }
 @Override
 public String toJson(OptionalInt object) {
   return object.isPresent() ? String.valueOf(object.getAsInt()) : NULL;
 }