Convert some Functions/Predicates to streams & lambdas (2)
Change-Id: I6558525ed5df1da588fcf69d177952e4f692cc2d
This commit is contained in:
		@@ -17,7 +17,6 @@ package com.google.gerrit.server.index;
 | 
			
		||||
import static com.google.gerrit.server.git.QueueProvider.QueueType.BATCH;
 | 
			
		||||
import static com.google.gerrit.server.git.QueueProvider.QueueType.INTERACTIVE;
 | 
			
		||||
 | 
			
		||||
import com.google.common.base.Function;
 | 
			
		||||
import com.google.common.collect.FluentIterable;
 | 
			
		||||
import com.google.common.collect.ImmutableCollection;
 | 
			
		||||
import com.google.common.collect.ImmutableList;
 | 
			
		||||
@@ -110,19 +109,11 @@ public class IndexModule extends LifecycleModule {
 | 
			
		||||
            accounts,
 | 
			
		||||
            changes);
 | 
			
		||||
    Set<String> expected = FluentIterable.from(ALL_SCHEMA_DEFS)
 | 
			
		||||
        .transform(new Function<SchemaDefinitions<?>, String>() {
 | 
			
		||||
          @Override
 | 
			
		||||
          public String apply(SchemaDefinitions<?> in) {
 | 
			
		||||
            return in.getName();
 | 
			
		||||
          }
 | 
			
		||||
        }).toSet();
 | 
			
		||||
        .transform(SchemaDefinitions::getName)
 | 
			
		||||
        .toSet();
 | 
			
		||||
    Set<String> actual = FluentIterable.from(result)
 | 
			
		||||
        .transform(new Function<IndexDefinition<?, ?, ?>, String>() {
 | 
			
		||||
          @Override
 | 
			
		||||
          public String apply(IndexDefinition<?, ?, ?> in) {
 | 
			
		||||
            return in.getName();
 | 
			
		||||
          }
 | 
			
		||||
        }).toSet();
 | 
			
		||||
        .transform(IndexDefinition::getName)
 | 
			
		||||
        .toSet();
 | 
			
		||||
    if (!expected.equals(actual)) {
 | 
			
		||||
      throw new ProvisionException(
 | 
			
		||||
          "need index definitions for all schemas: "
 | 
			
		||||
 
 | 
			
		||||
@@ -14,14 +14,12 @@
 | 
			
		||||
 | 
			
		||||
package com.google.gerrit.server.index.account;
 | 
			
		||||
 | 
			
		||||
import com.google.common.base.Function;
 | 
			
		||||
import com.google.common.base.Predicates;
 | 
			
		||||
import com.google.common.base.Strings;
 | 
			
		||||
import com.google.common.collect.FluentIterable;
 | 
			
		||||
import com.google.common.collect.Iterables;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountExternalId;
 | 
			
		||||
import com.google.gerrit.server.account.AccountState;
 | 
			
		||||
import com.google.gerrit.server.account.WatchConfig.ProjectWatchKey;
 | 
			
		||||
import com.google.gerrit.server.index.FieldDef;
 | 
			
		||||
import com.google.gerrit.server.index.FieldType;
 | 
			
		||||
import com.google.gerrit.server.index.SchemaUtil;
 | 
			
		||||
@@ -47,13 +45,7 @@ public class AccountField {
 | 
			
		||||
        @Override
 | 
			
		||||
        public Iterable<String> get(AccountState input, FillArgs args) {
 | 
			
		||||
          return Iterables.transform(
 | 
			
		||||
              input.getExternalIds(),
 | 
			
		||||
              new Function<AccountExternalId, String>() {
 | 
			
		||||
                @Override
 | 
			
		||||
                public String apply(AccountExternalId in) {
 | 
			
		||||
                  return in.getKey().get();
 | 
			
		||||
                }
 | 
			
		||||
              });
 | 
			
		||||
              input.getExternalIds(), id -> id.getKey().get());
 | 
			
		||||
        }
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
@@ -68,12 +60,7 @@ public class AccountField {
 | 
			
		||||
              fullName,
 | 
			
		||||
              Iterables.transform(
 | 
			
		||||
                  input.getExternalIds(),
 | 
			
		||||
                  new Function<AccountExternalId, String>() {
 | 
			
		||||
                    @Override
 | 
			
		||||
                    public String apply(AccountExternalId in) {
 | 
			
		||||
                      return in.getEmailAddress();
 | 
			
		||||
                    }
 | 
			
		||||
                  }));
 | 
			
		||||
                  AccountExternalId::getEmailAddress));
 | 
			
		||||
 | 
			
		||||
          // Additional values not currently added by getPersonParts.
 | 
			
		||||
          // TODO(dborowitz): Move to getPersonParts and remove this hack.
 | 
			
		||||
@@ -108,23 +95,11 @@ public class AccountField {
 | 
			
		||||
        @Override
 | 
			
		||||
        public Iterable<String> get(AccountState input, FillArgs args) {
 | 
			
		||||
          return FluentIterable.from(input.getExternalIds())
 | 
			
		||||
            .transform(
 | 
			
		||||
                new Function<AccountExternalId, String>() {
 | 
			
		||||
                  @Override
 | 
			
		||||
                  public String apply(AccountExternalId in) {
 | 
			
		||||
                    return in.getEmailAddress();
 | 
			
		||||
                  }
 | 
			
		||||
                })
 | 
			
		||||
            .transform(AccountExternalId::getEmailAddress)
 | 
			
		||||
            .append(
 | 
			
		||||
                Collections.singleton(input.getAccount().getPreferredEmail()))
 | 
			
		||||
            .filter(Predicates.notNull())
 | 
			
		||||
            .transform(
 | 
			
		||||
                new Function<String, String>() {
 | 
			
		||||
                  @Override
 | 
			
		||||
                  public String apply(String in) {
 | 
			
		||||
                    return in.toLowerCase();
 | 
			
		||||
                  }
 | 
			
		||||
                })
 | 
			
		||||
            .transform(String::toLowerCase)
 | 
			
		||||
            .toSet();
 | 
			
		||||
        }
 | 
			
		||||
      };
 | 
			
		||||
@@ -153,12 +128,8 @@ public class AccountField {
 | 
			
		||||
        @Override
 | 
			
		||||
        public Iterable<String> get(AccountState input, FillArgs args) {
 | 
			
		||||
          return FluentIterable.from(input.getProjectWatches().keySet())
 | 
			
		||||
              .transform(new Function<ProjectWatchKey, String>() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public String apply(ProjectWatchKey in) {
 | 
			
		||||
              return in.project().get();
 | 
			
		||||
            }
 | 
			
		||||
          }).toSet();
 | 
			
		||||
              .transform(k -> k.project().get())
 | 
			
		||||
              .toSet();
 | 
			
		||||
        }
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -15,10 +15,11 @@
 | 
			
		||||
package com.google.gerrit.server.index.change;
 | 
			
		||||
 | 
			
		||||
import static com.google.common.base.MoreObjects.firstNonNull;
 | 
			
		||||
 | 
			
		||||
import static java.nio.charset.StandardCharsets.UTF_8;
 | 
			
		||||
import static java.util.stream.Collectors.toSet;
 | 
			
		||||
 | 
			
		||||
import com.google.common.annotations.VisibleForTesting;
 | 
			
		||||
import com.google.common.base.Function;
 | 
			
		||||
import com.google.common.base.Optional;
 | 
			
		||||
import com.google.common.base.Splitter;
 | 
			
		||||
import com.google.common.collect.ImmutableList;
 | 
			
		||||
@@ -246,13 +247,9 @@ public class ChangeField {
 | 
			
		||||
        @Override
 | 
			
		||||
        public Iterable<String> get(ChangeData input, FillArgs args)
 | 
			
		||||
            throws OrmException {
 | 
			
		||||
          return ImmutableSet.copyOf(Iterables.transform(input.hashtags(),
 | 
			
		||||
              new Function<String, String>() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public String apply(String input) {
 | 
			
		||||
              return input.toLowerCase();
 | 
			
		||||
            }
 | 
			
		||||
          }));
 | 
			
		||||
          return input.hashtags().stream()
 | 
			
		||||
              .map(String::toLowerCase)
 | 
			
		||||
              .collect(toSet());
 | 
			
		||||
        }
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
@@ -263,13 +260,9 @@ public class ChangeField {
 | 
			
		||||
        @Override
 | 
			
		||||
        public Iterable<byte[]> get(ChangeData input, FillArgs args)
 | 
			
		||||
            throws OrmException {
 | 
			
		||||
          return ImmutableSet.copyOf(Iterables.transform(input.hashtags(),
 | 
			
		||||
              new Function<String, byte[]>() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public byte[] apply(String hashtag) {
 | 
			
		||||
              return hashtag.getBytes(UTF_8);
 | 
			
		||||
            }
 | 
			
		||||
          }));
 | 
			
		||||
          return input.hashtags().stream()
 | 
			
		||||
              .map(t -> t.getBytes(UTF_8))
 | 
			
		||||
              .collect(toSet());
 | 
			
		||||
        }
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
@@ -656,13 +649,7 @@ public class ChangeField {
 | 
			
		||||
        @Override
 | 
			
		||||
        public Iterable<Integer> get(ChangeData input, FillArgs args)
 | 
			
		||||
            throws OrmException {
 | 
			
		||||
          return Iterables.transform(input.starredBy(),
 | 
			
		||||
              new Function<Account.Id, Integer>() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public Integer apply(Account.Id accountId) {
 | 
			
		||||
              return accountId.get();
 | 
			
		||||
            }
 | 
			
		||||
          });
 | 
			
		||||
          return Iterables.transform(input.starredBy(), Account.Id::get);
 | 
			
		||||
        }
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
@@ -675,14 +662,12 @@ public class ChangeField {
 | 
			
		||||
        @Override
 | 
			
		||||
        public Iterable<String> get(ChangeData input, FillArgs args)
 | 
			
		||||
            throws OrmException {
 | 
			
		||||
          return Iterables.transform(input.stars().entries(),
 | 
			
		||||
              new Function<Map.Entry<Account.Id, String>, String>() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public String apply(Map.Entry<Account.Id, String> e) {
 | 
			
		||||
              return StarredChangesUtil.StarField.create(
 | 
			
		||||
                  e.getKey(), e.getValue()).toString();
 | 
			
		||||
            }
 | 
			
		||||
          });
 | 
			
		||||
          return Iterables.transform(
 | 
			
		||||
              input.stars().entries(),
 | 
			
		||||
              (Map.Entry<Account.Id, String> e) -> {
 | 
			
		||||
                return StarredChangesUtil.StarField.create(
 | 
			
		||||
                    e.getKey(), e.getValue()).toString();
 | 
			
		||||
              });
 | 
			
		||||
        }
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
@@ -738,13 +723,9 @@ public class ChangeField {
 | 
			
		||||
        @Override
 | 
			
		||||
        public Iterable<Integer> get(ChangeData input, FillArgs args)
 | 
			
		||||
            throws OrmException {
 | 
			
		||||
          return ImmutableSet.copyOf(Iterables.transform(input.editsByUser(),
 | 
			
		||||
              new Function<Account.Id, Integer>() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public Integer apply(Account.Id account) {
 | 
			
		||||
              return account.get();
 | 
			
		||||
            }
 | 
			
		||||
          }));
 | 
			
		||||
          return input.editsByUser().stream()
 | 
			
		||||
              .map(Account.Id::get)
 | 
			
		||||
              .collect(toSet());
 | 
			
		||||
        }
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
@@ -756,13 +737,9 @@ public class ChangeField {
 | 
			
		||||
        @Override
 | 
			
		||||
        public Iterable<Integer> get(ChangeData input, FillArgs args)
 | 
			
		||||
            throws OrmException {
 | 
			
		||||
          return ImmutableSet.copyOf(Iterables.transform(input.draftsByUser(),
 | 
			
		||||
              new Function<Account.Id, Integer>() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public Integer apply(Account.Id account) {
 | 
			
		||||
              return account.get();
 | 
			
		||||
            }
 | 
			
		||||
          }));
 | 
			
		||||
          return input.draftsByUser().stream()
 | 
			
		||||
              .map(Account.Id::get)
 | 
			
		||||
              .collect(toSet());
 | 
			
		||||
        }
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,6 @@ import static com.google.gerrit.server.index.change.ChangeField.CHANGE;
 | 
			
		||||
import static com.google.gerrit.server.index.change.ChangeField.PROJECT;
 | 
			
		||||
 | 
			
		||||
import com.google.common.annotations.VisibleForTesting;
 | 
			
		||||
import com.google.common.base.Function;
 | 
			
		||||
import com.google.common.collect.ImmutableSet;
 | 
			
		||||
import com.google.common.collect.Iterables;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.Change;
 | 
			
		||||
@@ -94,12 +93,9 @@ public class IndexedChangeQuery extends IndexedQuery<Change.Id, ChangeData>
 | 
			
		||||
      public Iterator<ChangeData> iterator() {
 | 
			
		||||
        return Iterables.transform(
 | 
			
		||||
            rs,
 | 
			
		||||
            new Function<ChangeData, ChangeData>() {
 | 
			
		||||
              @Override
 | 
			
		||||
              public ChangeData apply(ChangeData cd) {
 | 
			
		||||
                fromSource.put(cd, currSource);
 | 
			
		||||
                return cd;
 | 
			
		||||
              }
 | 
			
		||||
            cd -> {
 | 
			
		||||
              fromSource.put(cd, currSource);
 | 
			
		||||
              return cd;
 | 
			
		||||
            }).iterator();
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user