Ejemplo n.º 1
0
 /**
  * Constructs a SanitizedConfiguration object and populates the set of instance IDs for the
  * provided {@link org.apache.aurora.scheduler.storage.entities.ITaskConfig}.
  *
  * @param sanitized A sanitized configuration.
  */
 @VisibleForTesting
 public SanitizedConfiguration(IJobConfiguration sanitized) {
   this.sanitized = sanitized;
   this.instanceIds =
       ContiguousSet.create(
           Range.closedOpen(0, sanitized.getInstanceCount()), DiscreteDomain.integers());
 }
  @Test
  public void whenCreateRangeOfIntegersSet_thenCreated() {
    final int start = 10;
    final int end = 30;
    final ContiguousSet<Integer> set =
        ContiguousSet.create(Range.closed(start, end), DiscreteDomain.integers());

    assertEquals(21, set.size());
    assertEquals(10, set.first().intValue());
    assertEquals(30, set.last().intValue());
  }
Ejemplo n.º 3
0
 private static RangeSet<Integer> characterRangesToTokenRanges(
     JavaInput javaInput, List<Range<Integer>> characterRanges) throws FormatterException {
   RangeSet<Integer> tokenRangeSet = TreeRangeSet.create();
   for (Range<Integer> characterRange0 : characterRanges) {
     Range<Integer> characterRange = characterRange0.canonical(DiscreteDomain.integers());
     tokenRangeSet.add(
         javaInput.characterRangeToTokenRange(
             characterRange.lowerEndpoint(),
             characterRange.upperEndpoint() - characterRange.lowerEndpoint()));
   }
   return tokenRangeSet;
 }
Ejemplo n.º 4
0
  @Test
  public void testSubAggregations() throws Exception {
    Set expectedAges =
        new HashSet<>(ContiguousSet.create(Range.closed(20, 40), DiscreteDomain.integers()));
    final String query =
        String.format(
            "SELECT /*! DOCS_WITH_AGGREGATION(10) */"
                + " * FROM %s/account GROUP BY (gender, age), (state) LIMIT 0,10",
            TEST_INDEX);

    Map<String, Set<Integer>> buckets = new HashMap<>();

    SqlElasticSearchRequestBuilder select = getSearchRequestBuilder(query);
    SearchResponse response = (SearchResponse) select.get();
    Aggregations result = response.getAggregations();

    Terms gender = result.get("gender");
    for (Terms.Bucket genderBucket : gender.getBuckets()) {
      String genderKey = genderBucket.getKey();
      buckets.put(genderKey, new HashSet<Integer>());
      Terms ageBuckets = (Terms) genderBucket.getAggregations().get("age");
      for (Terms.Bucket ageBucket : ageBuckets.getBuckets()) {
        buckets.get(genderKey).add(Integer.parseInt(ageBucket.getKey()));
      }
    }

    Assert.assertEquals(2, buckets.keySet().size());
    Assert.assertEquals(expectedAges, buckets.get("m"));
    Assert.assertEquals(expectedAges, buckets.get("f"));

    Terms state = result.get("state");
    for (Terms.Bucket stateBucket : state.getBuckets()) {
      if (stateBucket.getKey().equalsIgnoreCase("ak")) {
        Assert.assertTrue("There are 22 entries for state ak", stateBucket.getDocCount() == 22);
      }
    }

    Assert.assertEquals(response.getHits().totalHits(), 1000);
    Assert.assertEquals(response.getHits().hits().length, 10);
  }
Ejemplo n.º 5
0
  @Test
  public void multipleGroupBysWithSize() throws Exception {
    Set expectedAges =
        new HashSet<Integer>(ContiguousSet.create(Range.closed(20, 40), DiscreteDomain.integers()));

    Map<String, Set<Integer>> buckets = new HashMap<>();

    Aggregations result =
        query(
            String.format(
                "SELECT COUNT(*) FROM %s/account GROUP BY gender, terms('alias'='ageAgg','field'='age','size'=3)",
                TEST_INDEX));
    Terms gender = result.get("gender");
    Assert.assertEquals(2, gender.getBuckets().size());
    for (Terms.Bucket genderBucket : gender.getBuckets()) {

      String genderKey = genderBucket.getKey();
      buckets.put(genderKey, new HashSet<Integer>());
      Terms ageBuckets = genderBucket.getAggregations().get("ageAgg");
      Assert.assertEquals(3, ageBuckets.getBuckets().size());
    }
  }
Ejemplo n.º 6
0
  @Test
  public void multipleGroupByTest() throws Exception {
    Set expectedAges =
        new HashSet<Integer>(ContiguousSet.create(Range.closed(20, 40), DiscreteDomain.integers()));

    Map<String, Set<Integer>> buckets = new HashMap<>();

    Aggregations result =
        query(String.format("SELECT COUNT(*) FROM %s/account GROUP BY gender, age", TEST_INDEX));
    Terms gender = result.get("gender");
    for (Terms.Bucket genderBucket : gender.getBuckets()) {
      String genderKey = genderBucket.getKey();
      buckets.put(genderKey, new HashSet<Integer>());
      Terms ageBuckets = (Terms) genderBucket.getAggregations().get("age");
      for (Terms.Bucket ageBucket : ageBuckets.getBuckets()) {
        buckets.get(genderKey).add(Integer.parseInt(ageBucket.getKey()));
      }
    }

    Assert.assertEquals(2, buckets.keySet().size());
    Assert.assertEquals(expectedAges, buckets.get("m"));
    Assert.assertEquals(expectedAges, buckets.get("f"));
  }
  public class_apc(WorldServer var1, NBTTagCompound var2) {
    this.c =
        new class_le(
            new ChatMessage("entity.EnderDragon.name", new Object[0]),
            class_oh.class_a_in_class_oh.a,
            class_oh.class_b_in_class_oh.a,
            false,
            true);
    this.e = Lists.newArrayList();
    this.g = 0;
    this.h = 0;
    this.i = 0;
    this.j = 0;
    this.k = false;
    this.l = false;
    this.m = null;
    this.n = false;
    this.d = var1;
    if (var2.hasOfType("DragonKilled", 1)) {
      this.m = var2.getUUID("DragonUUID");
      this.k = var2.getBoolean("DragonKilled");
      this.l = var2.getBoolean("PreviouslyKilled");
    } else {
      this.n = true;
      this.k = true;
      this.l = true;
    }

    if (var2.hasOfType("Gateways", 9)) {
      NBTTagList var3 = var2.getList("Gateways", 3);

      for (int var4 = 0; var4 < var3.getSize(); ++var4) {
        this.e.add(Integer.valueOf(var3.getInt(var4)));
      }
    } else {
      this.e.addAll(
          ContiguousSet.create(
              Range.closedOpen(Integer.valueOf(0), Integer.valueOf(20)),
              DiscreteDomain.integers()));
      Collections.shuffle(this.e, new Random(var1.K()));
    }

    this.f =
        class_anq
            .a()
            .a(
                new String[] {
                  "       ", "       ", "       ", "   #   ", "       ", "       ", "       "
                })
            .a(
                new String[] {
                  "       ", "       ", "       ", "   #   ", "       ", "       ", "       "
                })
            .a(
                new String[] {
                  "       ", "       ", "       ", "   #   ", "       ", "       ", "       "
                })
            .a(
                new String[] {
                  "  ###  ", " #   # ", "#     #", "#  #  #", "#     #", " #   # ", "  ###  "
                })
            .a(
                new String[] {
                  "       ", "  ###  ", " ##### ", " ##### ", " ##### ", "  ###  ", "       "
                })
            .a('#', class_ano.a(class_ans.a(Blocks.BEDROCK)))
            .b();
  }
Ejemplo n.º 8
0
/** This interface defines methods common to an {@link Input} or an {@link Output}. */
public abstract class InputOutput {
  private ImmutableList<String> lines = ImmutableList.of();

  protected static final Range<Integer> EMPTY_RANGE = Range.closedOpen(-1, -1);
  private static final CharMatcher NEWLINE_MATCHER = CharMatcher.is('\n');
  private static final DiscreteDomain<Integer> INTEGERS = DiscreteDomain.integers();

  /** Set the lines. */
  protected final void setLines(ImmutableList<String> lines) {
    this.lines = lines;
  }

  /**
   * Get the line count.
   *
   * @return the line count
   */
  public final int getLineCount() {
    return lines.size();
  }

  /**
   * Get a line.
   *
   * @param lineI the line number
   * @return the line
   */
  public final String getLine(int lineI) {
    return lines.get(lineI);
  }

  /** The {@link Range}s of the tokens or comments beginning on each line. */
  protected final List<Range<Integer>> range0s = new ArrayList<>();

  /** The {@link Range}s of the tokens or comments lying on each line, in any part. */
  protected final List<Range<Integer>> ranges = new ArrayList<>();

  /** The {@link Range}s of the tokens or comments ending on each line. */
  protected final List<Range<Integer>> range1s = new ArrayList<>();

  private static void addToRanges(List<Range<Integer>> ranges, int i, int k) {
    while (ranges.size() <= i) {
      ranges.add(EMPTY_RANGE);
    }
    Range<Integer> oldValue = ranges.get(i);
    ranges.set(i, Range.closedOpen(oldValue.isEmpty() ? k : oldValue.lowerEndpoint(), k + 1));
  }

  protected final void computeRanges(List<? extends Input.Tok> toks) {
    int lineI = 0;
    for (Input.Tok tok : toks) {
      String txt = tok.getOriginalText();
      int lineI0 = lineI;
      lineI += NEWLINE_MATCHER.countIn(txt);
      int k = tok.getIndex();
      if (k >= 0) {
        addToRanges(range0s, lineI0, k);
        for (int i = lineI0; i <= lineI; i++) {
          addToRanges(ranges, i, k);
        }
        addToRanges(range1s, lineI0, k);
      }
    }
  }

  /**
   * Given an {@code InputOutput}, compute the map from tok indices to line ranges.
   *
   * @param put the {@code InputOutput}
   * @param kN the number of tokens
   * @return the map from {@link com.google.googlejavaformat.java.JavaInput.Tok} indices to line
   *     ranges in this {@code put}
   */
  public static Map<Integer, Range<Integer>> makeKToIJ(InputOutput put, int kN) {
    Map<Integer, Range<Integer>> map = new HashMap<>();
    int ijN = put.getLineCount();
    LOOP:
    for (int ij = 0; ij <= ijN; ij++) {
      Range<Integer> range = put.getRanges(ij).canonical(INTEGERS);
      for (int k = range.lowerEndpoint(); k < range.upperEndpoint(); k++) {
        if (map.containsKey(k)) {
          map.put(k, Range.closedOpen(map.get(k).lowerEndpoint(), ij + 1));
        } else {
          map.put(k, Range.closedOpen(ij, ij + 1));
        }
        if (k == kN) {
          break LOOP;
        }
      }
    }
    return map;
  }

  /**
   * Get the {@link Range} of {@link Input.Tok}s beginning on a line.
   *
   * @param lineI the line number
   * @return the {@link Range} of {@link Input.Tok}s beginning on the specified line
   */
  public final Range<Integer> getRange0s(int lineI) {
    return 0 <= lineI && lineI < range0s.size() ? range0s.get(lineI) : EMPTY_RANGE;
  }

  /**
   * Get the {@link Range} of {@link Input.Tok}s lying in any part on a line.
   *
   * @param lineI the line number
   * @return the {@link Range} of {@link Input.Tok}s on the specified line
   */
  public final Range<Integer> getRanges(int lineI) {
    return 0 <= lineI && lineI < ranges.size() ? ranges.get(lineI) : EMPTY_RANGE;
  }

  /**
   * Get the {@link Range} of {@link Input.Tok}s ending on a line.
   *
   * @param lineI the line number
   * @return the {@link Range} of {@link Input.Tok}s ending on the specified line
   */
  public final Range<Integer> getRange1s(int lineI) {
    return 0 <= lineI && lineI < range1s.size() ? range1s.get(lineI) : EMPTY_RANGE;
  }

  @Override
  public String toString() {
    return "InputOutput{"
        + "lines="
        + lines
        + ", range0s="
        + range0s
        + ", ranges="
        + ranges
        + ", range1s="
        + range1s
        + '}';
  }
}