text:
<!--
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License. -->

<parameters>
    <required>
        <harmony.home description="Path to Harmony Runtime"
            value="${drlvm.parameters.shared.jvm.location}"/>
        <harmony.name description="Harmony name in JAPI report"
            value="Harmony"/>
        <ri.home description="Path to RI Runtime"
            value="${java.home}"/>
        <ri.name description="RI name in JAPI report"
            value="RI"/>
        <japi.home description="Path to JAPI tool" />
    </required>

    <external>
<!-- FIXME
        <japi
            url="http://www.kaffe.org/~stuart/japi/japitools-0.9.7.zip"
            md5="b35a6c1767c116999a1f3d205174429c"
            dir="japitools-0.9.7"/>
-->
    </external>

    <shared/>
    <cc/>
</parameters>


text:
package org.bremersee.pagebuilder;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;
import org.assertj.core.api.SoftAssertions;
import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension;
import org.bremersee.comparator.ValueComparator;
import org.bremersee.comparator.model.SortOrder;
import org.bremersee.pagebuilder.PageBuilder.SortTarget;
import org.bremersee.pagebuilder.testmodel.Address;
import org.bremersee.pagebuilder.testmodel.Animal;
import org.bremersee.pagebuilder.testmodel.Cat;
import org.bremersee.pagebuilder.testmodel.Dog;
import org.bremersee.pagebuilder.testmodel.Person;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.NullHandling;
import org.springframework.data.domain.Sort.Order;

/**
 * The page builder test.
 *
 * @author Christian Bremer
 */
@ExtendWith(SoftAssertionsExtension.class)
class PageBuilderTest {

  /**
   * Source filter.
   *
   * @param softly the softly
   */
  @Test
  void sourceFilter(SoftAssertions softly) {
    List<Integer> entries = List.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    List<Integer> expected = List.of(2, 4, 6, 8, 10);
    Page<Integer> actual = new PageBuilder<Integer, Integer>()
        .sourceEntries(entries.stream())
        .sourceFilter(i -> i % 2 == 0)
        .pageable(null, SortTarget.SOURCE_ENTRIES)
        .build();
    softly.assertThat(actual)
        .isNotNull()
        .containsExactlyElementsOf(expected);
    softly.assertThat(actual.getTotalElements())
        .isEqualTo(expected.size()); // expected size, because filtered entries are not counted
    softly.assertThat(actual.getNumber())
        .isEqualTo(0);
    softly.assertThat(actual.getSize())
        .isGreaterThanOrEqualTo(expected.size());
    softly.assertThat(actual.getPageable().getSort())
        .isEqualTo(Sort.unsorted());
  }

  /**
   * Source sort fn.
   *
   * @param softly the softly
   */
  @Test
  void sourceSortFn(SoftAssertions softly) {
    List<Integer> entries = List.of(2, 4, 6, 8, 10, 9, 7, 5, 3, 1);
    List<Integer> expected = List.of(1, 2, 3, 4, 5, 6, 7, 8, 9);
    Page<Integer> actual = new PageBuilder<Integer, Integer>()
        .sourceEntries(entries)
        .pageable(0, 9,
            SortTarget.SOURCE_ENTRIES,
            List.of(new SortOrder(null, true, false, false)))
        .sourceSortFn(ValueComparator::new)
        .targetSortFn(null)
        .build();
    softly.assertThat(actual)
        .isNotNull()
        .containsExactlyElementsOf(expected);
    softly.assertThat(actual.getTotalElements())
        .isEqualTo(entries.size());
    softly.assertThat(actual.getNumber())
        .isEqualTo(0);
    softly.assertThat(actual.getSize())
        .isEqualTo(9);
    softly.assertThat(actual.getTotalPages())
        .isEqualTo(2);
    softly.assertThat(actual.getPageable().getSort())
        .isEqualTo(Sort.unsorted()); // sorting of source entries is not put into the page
  }

  /**
   * Pageable.
   *
   * @param softly the softly
   */
  @Test
  void pageable(SoftAssertions softly) {
    List<Address> entries = List.of(
        new Address("Paris"),
        new Address("London"),
        new Address("Berlin"),
        new Address("New York"));
    List<Address> expected = List.of(new Address("Berlin"), new Address("London"));
    Page<Address> actual = new PageBuilder<Address, Address>()
        .sourceEntries(entries.iterator())
        .pageable(0, 2,
            List.of(new SortOrder("city", true, true, false)))
        .build();
    softly.assertThat(actual)
        .isNotNull()
        .containsExactlyElementsOf(expected);
    softly.assertThat(actual.getTotalElements())
        .isEqualTo(entries.size());
    softly.assertThat(actual.getNumber())
        .isEqualTo(0);
    softly.assertThat(actual.getSize())
        .isEqualTo(2);
    softly.assertThat(actual.getTotalPages())
        .isEqualTo(2);
    softly.assertThat(actual.getPageable().getSort())
        .isEqualTo(Sort.by(Order.by("city")
            .with(Direction.ASC)
            .ignoreCase()
            .with(NullHandling.NULLS_LAST)));

    actual = new PageBuilder<Address, Address>()
        .sourceEntries(entries.iterator())
        .pageable(2, 2)
        .build();
    softly.assertThat(actual)
        .isEmpty();
    softly.assertThat(actual.getNumber())
        .isEqualTo(2);
    softly.assertThat(actual.getSize())
        .isEqualTo(2);
  }

  /**
   * Pageable with page request.
   *
   * @param softly the softly
   */
  @Test
  void pageableWithPageRequest(SoftAssertions softly) {
    List<Address> entries = List.of(
        new Address("Paris"),
        new Address("London"),
        new Address("Berlin"),
        new Address("New York"));
    List<Address> expected = List.of(new Address("New York"), new Address("Paris"));
    Page<Address> actual = new PageBuilder<Address, Address>()
        .sourceEntries(entries.iterator())
        .pageable(PageRequest.of(1, 2, Sort.by(Direction.ASC, "city")))
        .build();
    softly.assertThat(actual)
        .isNotNull()
        .containsExactlyElementsOf(expected);
    softly.assertThat(actual.getTotalElements())
        .isEqualTo(entries.size());
    softly.assertThat(actual.getNumber())
        .isEqualTo(1);
    softly.assertThat(actual.getSize())
        .isEqualTo(2);
    softly.assertThat(actual.getTotalPages())
        .isEqualTo(2);
    softly.assertThat(actual.getPageable().getSort())
        .isEqualTo(Sort.by(Order.by("city").with(Direction.ASC).with(NullHandling.NULLS_LAST)));

    actual = new PageBuilder<Address, Address>()
        .sourceEntries(entries.iterator())
        .pageable(PageRequest.of(2, 2), SortTarget.SOURCE_ENTRIES)
        .build();
    softly.assertThat(actual)
        .isEmpty();
    softly.assertThat(actual.getNumber())
        .isEqualTo(2);
    softly.assertThat(actual.getSize())
        .isEqualTo(2);
  }

  /**
   * Converter.
   */
  @Test
  void converter() {
    List<Address> expected = List.of(
        new Address("London"),
        new Address("Berlin"),
        new Address("New York"));
    List<Person> entries = List.of(
        new Person("", "", expected.get(0)),
        new Person("", "", expected.get(1)),
        new Person("", "", expected.get(2))
    );
    Page<Address> actual = new PageBuilder<Person, Address>()
        .sourceEntries(entries)
        .converter(Person::getAddress)
        .build();
    assertThat(actual)
        .containsExactlyElementsOf(expected);
  }

  /**
   * Target filter.
   *
   * @param softly the softly
   */
  @Test
  void targetFilter(SoftAssertions softly) {
    List<Person> entries = List.of(
        new Person("", "", new Address("London")),
        new Person("", "", new Address("Berlin")),
        new Person("", "", new Address("New York")));
    List<Address> expected = List.of(
        new Address("Berlin"),
        new Address("London"));
    Page<Address> actual = new PageBuilder<Person, Address>()
        .sourceEntries(entries)
        .converter(Person::getAddress)
        .targetFilter(address -> !address.getCity().contains(" "))
        .pageable(0, Integer.MAX_VALUE,
            SortTarget.TARGET_ENTRIES,
            new SortOrder("city", true, true, false))
        .build();
    softly.assertThat(actual)
        .containsExactlyElementsOf(expected);
    softly.assertThat(actual.getPageable().getSort())
        .isEqualTo(Sort.by(Sort.Order.by("city")
            .with(Direction.ASC)
            .ignoreCase()
            .with(NullHandling.NULLS_LAST)));
  }

  /**
   * Target sort fn.
   *
   * @param softly the softly
   */
  @Test
  void targetSortFn(SoftAssertions softly) {
    List<Animal> entries = List.of(
        new Cat("Garfield"),
        new Dog("Snoopy"),
        new Cat("Tom"),
        new Dog("Struppi"));
    List<Animal> expected = List.of(
        new Dog("Struppi"),
        new Dog("Snoopy"),
        new Cat("Tom"),
        new Cat("Garfield"));
    Page<Animal> actual = new PageBuilder<Animal, Animal>()
        .sourceEntries(entries)
        .pageable(0, Integer.MAX_VALUE,
            new SortOrder("_type", true, false, false),
            new SortOrder("name", false, true, false))
        .targetSortFn(sortOrder -> {
          if ("_type".equals(sortOrder.getField())) {
            return (o1, o2) -> o1 instanceof Dog && o2 instanceof Dog
                || o1 instanceof Cat && o2 instanceof Cat
                ? 0
                : o1 instanceof Dog ? -1 : 1;
          }
          return new ValueComparator(sortOrder);
        })
        .build();
    softly.assertThat(actual)
        .containsExactlyElementsOf(expected);
    softly.assertThat(actual.getPageable().getSort())
        .isEqualTo(Sort.by(
            Sort.Order.by("_type")
                .with(Direction.ASC)
                .with(NullHandling.NULLS_LAST),
            Sort.Order.by("name")
                .with(Direction.DESC)
                .ignoreCase()
                .with(NullHandling.NULLS_LAST)));

    expected = List.of(
        new Cat("Garfield"),
        new Dog("Snoopy"),
        new Dog("Struppi"),
        new Cat("Tom"));
    actual = new PageBuilder<Animal, Animal>()
        .sourceEntries(entries)
        .pageable(0, Integer.MAX_VALUE,
            new SortOrder("name", true, true, false))
        .targetSortFn(null)
        .build();
    softly.assertThat(actual)
        .containsExactlyElementsOf(expected);
  }
}

redpajama_set_name: RedPajamaGithub


text:
namespace ArangoDB.Internal.VelocyStream
{
    /// <author>Mark - mark at arangodb.com</author>
    public class Chunk
    {
        private readonly long messageId;

        private readonly long messageLength;

        private readonly int chunkX;

        private readonly int contentOffset;

        private readonly int contentLength;

        public Chunk(long messageId, int chunkX, long messageLength, int contentOffset, int
             contentLength)
        {
            this.messageId = messageId;
            this.chunkX = chunkX;
            this.messageLength = messageLength;
            this.contentOffset = contentOffset;
            this.contentLength = contentLength;
        }

        public Chunk(long messageId, int chunkIndex, int numberOfChunks, long messageLength
            , int contentOffset, int contentLength)
            : this(messageId, chunkX(chunkIndex, numberOfChunks), messageLength, contentOffset
                , contentLength)
        {
        }

        private static int chunkX(int chunkIndex, int numberOfChunks)
        {
            int chunkX;
            if (numberOfChunks == 1)
            {
                chunkX = 3;
            }
            else
            {
                // last byte: 0000 0011
                if (chunkIndex == 0)
                {
                    chunkX = (numberOfChunks << 1) + 1;
                }
                else
                {
                    chunkX = chunkIndex << 1;
                }
            }
            return chunkX;
        }

        public virtual long getMessageId()
        {
            return this.messageId;
        }

        public virtual long getMessageLength()
        {
            return this.messageLength;
        }

        public virtual bool isFirstChunk()
        {
            return 1 == (chunkX & unchecked((int)0x1));
        }

        public virtual int getChunk()
        {
            return chunkX >> 1;
        }

        public virtual int getChunkX()
        {
            return chunkX;
        }

        public virtual int getContentOffset()
        {
            return this.contentOffset;
        }

        public virtual int getContentLength()
        {
            return this.contentLength;
        }
    }
}


text:
package io.flutter.analytics;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;

import com.intellij.util.IncorrectOperationException;
import com.jetbrains.lang.dart.ide.completion.DartCompletionTimerExtension;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.time.Instant;

/**
 * Implementation of the {@link DartCompletionTimerExtension} which allows the Flutter plugin to
 * measure the total time to present a code completion to the user.
 */
public class DartCompletionTimerListener extends DartCompletionTimerExtension {
  @Nullable FlutterAnalysisServerListener dasListener;
  @Nullable Long startTimeMS;

  @Override
  public void dartCompletionStart() {
    if (dasListener == null) {
      try {
        Project project = ProjectManager.getInstance().getDefaultProject();
        dasListener = FlutterAnalysisServerListener.getInstance(project);
      } catch (IncorrectOperationException ex) {
        return;
      }
    }
    startTimeMS = Instant.now().toEpochMilli();
  }

  @Override
  public void dartCompletionEnd() {
    if (dasListener != null && startTimeMS != null) {
      long durationTimeMS = Instant.now().toEpochMilli() - startTimeMS;
      dasListener.logE2ECompletionSuccessMS(durationTimeMS); // test: logE2ECompletionSuccessMS()
      startTimeMS = null;
    }
  }

  /**
   * The parameters match those of {@link org.dartlang.analysis.server.protocol.RequestError}, they
   * are not used currently because our hypothesis is that this method will never be called.
   */
  @Override
  public void dartCompletionError(
    @NotNull String code, @NotNull String message, @NotNull String stackTrace) {
    if (dasListener != null && startTimeMS != null) {
      long durationTimeMS = Instant.now().toEpochMilli() - startTimeMS;
      dasListener.logE2ECompletionErrorMS(durationTimeMS); // test: logE2ECompletionErrorMS()
      startTimeMS = null;
    }
  }
}