Esempio n. 1
0
 public void testValues() {
   ImmutableBiMap<String, Integer> bimap =
       ImmutableBiMap.copyOf(ImmutableMap.of("one", 1, "two", 2, "three", 3, "four", 4));
   Set<Integer> values = bimap.values();
   assertEquals(Sets.newHashSet(1, 2, 3, 4), values);
   ASSERT.that(values).hasContentsInOrder(1, 2, 3, 4);
 }
Esempio n. 2
0
 public void testValues() {
   ImmutableBiMap<String, Integer> bimap =
       ImmutableBiMap.copyOf(ImmutableMap.of("one", 1, "two", 2, "three", 3, "four", 4));
   Set<Integer> values = bimap.values();
   assertEquals(Sets.newHashSet(1, 2, 3, 4), values);
   assertThat(values).containsExactly(1, 2, 3, 4).inOrder();
 }
 @Override
 public Set<ByteArrayId> getNaturalSplits() {
   final Set<ByteArrayId> retVal = new HashSet<ByteArrayId>(orderedSfcIndexToTierId.size());
   for (final Byte tier : orderedSfcIndexToTierId.values()) {
     retVal.add(new ByteArrayId(new byte[] {tier}));
   }
   return retVal;
 }
Esempio n. 4
0
  /**
   * Looks through filtered drawables for files not of the target density and replaces them with
   * scaled versions.
   *
   * <p>Any drawables found by this step didn't have equivalents in the target density. If they are
   * of a higher density, we can replicate what Android does and downscale them at compile-time.
   */
  private void scaleUnmatchedDrawables(ExecutionContext context)
      throws IOException, InterruptedException {
    ResourceFilters.Density targetDensity = ResourceFilters.Density.ORDERING.max(targetDensities);

    // Go over all the images that remain after filtering.
    Preconditions.checkNotNull(drawableFinder);
    Collection<Path> drawables =
        drawableFinder.findDrawables(inResDirToOutResDirMap.values(), filesystem);
    for (Path drawable : drawables) {
      if (drawable.toString().endsWith(".9.png")) {
        // Skip nine-patch for now.
        continue;
      }

      ResourceFilters.Qualifiers qualifiers = new ResourceFilters.Qualifiers(drawable);
      ResourceFilters.Density density = qualifiers.density;

      // If the image has a qualifier but it's not the right one.
      Preconditions.checkNotNull(targetDensities);
      if (!targetDensities.contains(density)) {

        // Replace density qualifier with target density using regular expression to match
        // the qualifier in the context of a path to a drawable.
        String fromDensity =
            (density == ResourceFilters.Density.NO_QUALIFIER ? "" : "-") + density.toString();
        Path destination =
            Paths.get(
                MorePaths.pathWithUnixSeparators(drawable)
                    .replaceFirst(
                        "((?:^|/)drawable[^/]*)" + Pattern.quote(fromDensity) + "(-|$|/)",
                        "$1-" + targetDensity + "$2"));

        double factor = targetDensity.value() / density.value();
        if (factor >= 1.0) {
          // There is no point in up-scaling, or converting between drawable and drawable-mdpi.
          continue;
        }

        // Make sure destination folder exists and perform downscaling.
        filesystem.createParentDirs(destination);
        Preconditions.checkNotNull(imageScaler);
        imageScaler.scale(factor, drawable, destination, context);

        // Delete source file.
        filesystem.deleteFileAtPath(drawable);

        // Delete newly-empty directories to prevent missing resources errors in apkbuilder.
        Path parent = drawable.getParent();
        if (filesystem.listFiles(parent).length == 0) {
          filesystem.deleteFileAtPath(parent);
        }
      }
    }
  }