import java.util.Collection;
import java.util.List;
import java.util.Set;
+import java.util.stream.Collectors;
import javax.annotation.Nullable;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.Dao;
import org.sonar.db.DatabaseUtils;
import org.sonar.db.DbSession;
// Pagination is done in Java because it's too complex to use SQL pagination in Oracle and MsSQL with the distinct
.skip(query.getPageOffset())
.limit(query.getPageSize())
- .collect(MoreCollectors.toArrayList());
+ .collect(Collectors.toList());
}
public int countUsersByQuery(DbSession dbSession, PermissionQuery query) {
import java.util.List;
import java.util.Map;
import java.util.Random;
+import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.Before;
import org.junit.Rule;
"where u.login='admin'");
List<String> groupNames = rows.stream()
.map(row -> (String) row.get("groupName"))
- .collect(MoreCollectors.toArrayList());
+ .collect(Collectors.toList());
assertThat(groupNames).containsOnly("sonar-administrators", "sonar-users");
}
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
+import java.util.stream.Collectors;
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
.map(itemsById::get)
.flatMap(Collection::stream)
.filter(Objects::nonNull)
- .collect(MoreCollectors.toArrayList());
+ .collect(Collectors.toList());
dbClient.esQueueDao().delete(dbSession, itemsToDelete);
dbSession.commit();
}
import org.sonar.server.qualityprofile.ActiveRuleInheritance;
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
-import static org.sonar.core.util.stream.MoreCollectors.toArrayList;
import static org.sonar.server.qualityprofile.index.ActiveRuleDoc.docIdOf;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_PROFILE_UUID;
import static org.sonar.server.rule.index.RuleIndexDefinition.TYPE_ACTIVE_RULE;
List<EsQueueDto> items = changes.stream()
.map(ActiveRuleChange::getActiveRule)
.map(ar -> newQueueDto(docIdOf(ar.getUuid()), ID_TYPE_ACTIVE_RULE_UUID, ar.getRuleUuid()))
- .collect(toArrayList());
+ .collect(Collectors.toList());
dbClient.esQueueDao().insert(dbSession, items);
dbSession.commit();
.map(QProfileDto::getRulesProfileUuid)
.distinct()
.map(ruleProfileUuid -> newQueueDto(ruleProfileUuid, ID_TYPE_RULE_PROFILE_UUID, null))
- .collect(toArrayList());
+ .collect(Collectors.toList());
dbClient.esQueueDao().insert(dbSession, items);
dbSession.commit();
import java.util.List;
import java.util.Optional;
import java.util.Set;
+import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public void commitAndIndex(DbSession dbSession, Collection<String> ruleUuids) {
List<EsQueueDto> items = ruleUuids.stream()
.map(RuleIndexer::createQueueDtoForRule)
- .collect(MoreCollectors.toArrayList());
+ .collect(Collectors.toList());
dbClient.esQueueDao().insert(dbSession, items);
dbSession.commit();
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.stream.Collectors;
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest;
import org.elasticsearch.action.index.IndexRequest;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
public void delete(DbSession dbSession, Collection<String> viewUuids) {
List<EsQueueDto> items = viewUuids.stream()
.map(l -> EsQueueDto.create(TYPE_VIEW.format(), l))
- .collect(MoreCollectors.toArrayList());
+ .collect(Collectors.toList());
dbClient.esQueueDao().insert(dbSession, items);
dbSession.commit();
package org.sonar.server.platform;
import java.util.List;
+import java.util.stream.Collectors;
import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.process.systeminfo.SystemInfoSection;
import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
import org.sonar.server.ce.http.CeHttpClient;
List<ProtobufSystemInfo.Section> sections = stream(systemInfoSections)
.map(SystemInfoSection::toProtobuf)
- .collect(MoreCollectors.toArrayList());
+ .collect(Collectors.toList());
ceHttpClient.retrieveSystemInfo()
.ifPresent(ce -> sections.addAll(ce.getSectionsList()));
import org.springframework.beans.factory.annotation.Autowired;
import static java.util.Collections.emptyList;
-import static org.sonar.core.util.stream.MoreCollectors.toArrayList;
/**
* Populates the types "authorization" of each index requiring entity
private Collection<EsQueueDto> insertIntoEsQueue(DbSession dbSession, Collection<String> projectUuids) {
List<EsQueueDto> items = indexTypeByFormat.values().stream()
.flatMap(indexType -> projectUuids.stream().map(projectUuid -> EsQueueDto.create(indexType.format(), AuthorizationDoc.idOf(projectUuid), null, projectUuid)))
- .collect(toArrayList());
+ .collect(Collectors.toList());
dbClient.esQueueDao().insert(dbSession, items);
return items;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.utils.System2;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
@Test
public void delete_only_the_1000_first_projects() {
userSession.logIn().addPermission(ADMINISTER);
- List<String> keys = IntStream.range(0, 1_010).mapToObj(i -> "key" + i).collect(MoreCollectors.toArrayList());
+ List<String> keys = IntStream.range(0, 1_010).mapToObj(i -> "key" + i).collect(Collectors.toList());
keys.forEach(key -> db.components().insertPrivateProject(p -> p.setKey(key)).getMainBranchComponent());
ws.newRequest()
ImmutableList.Builder<MeasureDto> measuresBuilder = ImmutableList.builder();
List<MeasureDto> filteredMeasures = measures.stream()
.filter(measure -> analysisUuids.contains(measure.getAnalysisUuid()))
- .collect(MoreCollectors.toArrayList());
+ .collect(Collectors.toList());
measuresBuilder.addAll(filteredMeasures);
measuresBuilder.addAll(computeBestValues(filteredMeasures));
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.sonar.api.utils.System2;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
changes = getChangesFromRulesToBeRemoved(dbSession, profile, getRulesDifference(activeRules, parentActiveRules));
- Collection<String> parentRuleUuids = parentActiveRules.stream().map(ActiveRuleDto::getRuleUuid).collect(MoreCollectors.toArrayList());
+ Collection<String> parentRuleUuids = parentActiveRules.stream().map(ActiveRuleDto::getRuleUuid).collect(Collectors.toList());
RuleActivationContext context = ruleActivator.createContextForUserProfile(dbSession, profile, parentRuleUuids);
for (ActiveRuleDto parentActiveRule : parentActiveRules) {
private static List<OrgActiveRuleDto> getRulesDifference(Collection<OrgActiveRuleDto> rulesCollection1, Collection<OrgActiveRuleDto> rulesCollection2) {
Collection<String> rulesCollection2Uuids = rulesCollection2.stream()
.map(ActiveRuleDto::getRuleUuid)
- .collect(MoreCollectors.toArrayList());
+ .collect(Collectors.toList());
return rulesCollection1.stream()
.filter(rule -> !rulesCollection2Uuids.contains(rule.getRuleUuid()))
private List<ActiveRuleChange> getChangesFromRulesToBeRemoved(DbSession dbSession, QProfileDto profile, List<OrgActiveRuleDto> rules) {
List<ActiveRuleChange> changes = new ArrayList<>();
- Collection<String> ruleUuids = rules.stream().map(ActiveRuleDto::getRuleUuid).collect(MoreCollectors.toArrayList());
+ Collection<String> ruleUuids = rules.stream().map(ActiveRuleDto::getRuleUuid).collect(Collectors.toList());
RuleActivationContext context = ruleActivator.createContextForUserProfile(dbSession, profile, ruleUuids);
for (OrgActiveRuleDto activeRule : rules) {
return Collectors.toCollection(() -> EnumSet.noneOf(enumClass));
}
- /**
- * Delegates to {@link java.util.stream.Collectors#toCollection(Supplier)}.
- */
- public static <T> Collector<T, ?, ArrayList<T>> toArrayList() {
- return java.util.stream.Collectors.toCollection(ArrayList::new);
- }
-
- /**
- * Does {@code java.util.stream.MoreCollectors.toCollection(() -> new ArrayList<>(size));} which is equivalent to
- * {@link #toArrayList()} but avoiding array copies when the size of the resulting list is already known.
- *
- * <p>Note: using this method with a parallel stream will likely not have the expected memory usage benefit as all
- * processing threads will use a ArrayList with a capacity large enough for the final size.</p>
- *
- * @see java.util.stream.Collectors#toList()
- * @see java.util.stream.Collectors#toCollection(Supplier)
- */
public static <T> Collector<T, ?, ArrayList<T>> toArrayList(int size) {
return java.util.stream.Collectors.toCollection(() -> new ArrayList<>(size));
}
- /**
- * Delegates to {@link java.util.stream.Collectors#toCollection(Supplier)}.
- */
public static <T> Collector<T, ?, HashSet<T>> toHashSet() {
return java.util.stream.Collectors.toCollection(HashSet::new);
}
- /**
- * Does {@code java.util.stream.MoreCollectors.toCollection(() -> new HashSet<>(size));} which is equivalent to
- * {@link #toHashSet()} but avoiding array copies when the size of the resulting set is already known.
- *
- * <p>Note: using this method with a parallel stream will likely not have the expected memory usage benefit as all
- * processing threads will use a HashSet with a capacity large enough for the final size.</p>
- *
- * @see java.util.stream.Collectors#toSet()
- * @see java.util.stream.Collectors#toCollection(Supplier)
- */
public static <T> Collector<T, ?, HashSet<T>> toHashSet(int size) {
return java.util.stream.Collectors.toCollection(() -> new HashSet<>(size));
}
.isEmpty();
}
- @Test
- public void toArrayList_builds_an_ArrayList() {
- List<Integer> res = Stream.of(1, 2, 3, 4, 5).collect(toArrayList());
- assertThat(res).isInstanceOf(ArrayList.class)
- .containsExactly(1, 2, 3, 4, 5);
- }
-
- @Test
- public void toArrayList_parallel_stream() {
- assertThat(HUGE_LIST.parallelStream().collect(toArrayList())).isEqualTo(HUGE_LIST);
- }
-
@Test
public void toArrayList_with_size_builds_an_ArrayList() {
List<Integer> res = Stream.of(1, 2, 3, 4, 5).collect(toArrayList(30));