// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.internal.statistic.customUsageCollectors;

import com.intellij.internal.statistic.UsagesCollector;
import com.intellij.internal.statistic.beans.GroupDescriptor;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import com.intellij.openapi.application.ExperimentalFeature;
import com.intellij.openapi.application.Experiments;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;

import java.util.Set;

/**
 * @author Konstantin Bulenkov
 */
public class ExperimentalFeaturesUsageCollector extends UsagesCollector {
  private static final GroupDescriptor GROUP_ID = GroupDescriptor.create("Experimental Features");

  @NotNull
  @Override
  public Set<UsageDescriptor> getUsages() {
    Set<UsageDescriptor> usages = new THashSet<>();
    for (ExperimentalFeature feature : Experiments.EP_NAME.getExtensions()) {
      usages.add(new UsageDescriptor(feature.id, Experiments.isFeatureEnabled(feature.id) ? 1 : 0));
    }
    return usages;
  }

  @NotNull
  @Override
  public GroupDescriptor getGroupId() {
    return GROUP_ID;
  }
}

@@ -432,141 +432,100 @@
 ment
-alFeature;%0Aimport com.intellij.openapi.application.Experiments;%0Aimport gnu.trove.THashSet;%0Aimport org.jetbrains.annotations.NotNull;%0A
+s;%0Aimport org.jetbrains.annotations.NotNull;%0A%0Aimport java.util.Arrays;%0Aimport java.util.Set;
 %0Aimp
@@ -538,19 +538,33 @@
 va.util.
-Set
+stream.Collectors
 ;%0A%0A/**%0A 
@@ -846,95 +846,29 @@
     
-Set%3CUsageDescriptor%3E usages = new THashSet%3C%3E();%0A    for (ExperimentalFeature feature : 
+return Arrays.stream(
 Expe
@@ -903,135 +903,141 @@
 s())
- %7B
 %0A      
-usages.add(new UsageDescriptor(feature.id, Experiments.isFeatureEnabled(feature.id) ? 1 : 0));%0A    %7D%0A    return usages
+.filter(f -%3E Experiments.isFeatureEnabled(f.id))%0A      .map(f -%3E new UsageDescriptor(f.id))%0A      .collect(Collectors.toSet())
 ;%0A  

clean up. Do not send empty usage descriptors