Search in sources :

Example 1 with GroupDescriptor

use of com.intellij.internal.statistic.beans.GroupDescriptor in project intellij-community by JetBrains.

the class StatisticsUploadAssistantTest method createDescriptors.

protected static Map<GroupDescriptor, Set<UsageDescriptor>> createDescriptors(String... strs) {
    Map<GroupDescriptor, Set<UsageDescriptor>> set = new LinkedHashMap<>();
    for (String str : strs) {
        final List<String> list = StringUtil.split(str, ":");
        final GroupDescriptor g = GroupDescriptor.create(list.get(0));
        if (!set.containsKey(g)) {
            set.put(g, new LinkedHashSet<>());
        }
        set.get(g).add(createDescriptor(list.get(1), Integer.parseInt(list.get(2))));
    }
    return set;
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) GroupDescriptor(com.intellij.internal.statistic.beans.GroupDescriptor) LinkedHashMap(com.intellij.util.containers.hash.LinkedHashMap)

Example 2 with GroupDescriptor

use of com.intellij.internal.statistic.beans.GroupDescriptor in project intellij-community by JetBrains.

the class StatisticsUploadAssistantTest method assertMapEquals.

private static <T extends UsageDescriptor> void assertMapEquals(@NotNull Map<GroupDescriptor, Set<T>> expected, @NotNull Map<GroupDescriptor, Set<UsageDescriptor>> actual) {
    assertEquals(expected.size(), actual.size());
    for (Map.Entry<GroupDescriptor, Set<T>> expectedEntry : expected.entrySet()) {
        final GroupDescriptor expectedGroupDescriptor = expectedEntry.getKey();
        assertTrue(actual.containsKey(expectedGroupDescriptor));
        assertSetEquals(expectedEntry.getValue(), actual.get(expectedEntry.getKey()));
    }
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) LinkedHashMap(com.intellij.util.containers.hash.LinkedHashMap) Map(java.util.Map) HashMap(com.intellij.util.containers.hash.HashMap) GroupDescriptor(com.intellij.internal.statistic.beans.GroupDescriptor)

Example 3 with GroupDescriptor

use of com.intellij.internal.statistic.beans.GroupDescriptor in project intellij-community by JetBrains.

the class StatisticsUploadAssistantTest method createPatchDescriptor.

private static void createPatchDescriptor(Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages, String groupId, double priority, String key, int i) {
    final GroupDescriptor groupDescriptor = GroupDescriptor.create(groupId, priority);
    if (!patchedUsages.containsKey(groupDescriptor)) {
        patchedUsages.put(groupDescriptor, new LinkedHashSet<>());
    }
    patchedUsages.get(groupDescriptor).add(new PatchedUsage(key, i));
}
Also used : PatchedUsage(com.intellij.internal.statistic.beans.PatchedUsage) GroupDescriptor(com.intellij.internal.statistic.beans.GroupDescriptor)

Example 4 with GroupDescriptor

use of com.intellij.internal.statistic.beans.GroupDescriptor in project intellij-community by JetBrains.

the class ApplicationStatisticsPersistenceComponent method getState.

@Override
public Element getState() {
    Element element = new Element("state");
    for (Map.Entry<GroupDescriptor, Map<String, CollectedUsages>> appData : getApplicationData().entrySet()) {
        Element groupElement = new Element(GROUP_TAG);
        groupElement.setAttribute(GROUP_NAME_ATTR, appData.getKey().getId());
        boolean isEmptyGroup = true;
        for (Map.Entry<String, CollectedUsages> projectData : appData.getValue().entrySet()) {
            Element projectElement = new Element(PROJECT_TAG);
            projectElement.setAttribute(PROJECT_ID_ATTR, projectData.getKey());
            final CollectedUsages projectDataValue = projectData.getValue();
            if (!projectDataValue.usages.isEmpty()) {
                projectElement.setAttribute(VALUES_ATTR, joinUsages(projectDataValue.usages));
                projectElement.setAttribute(COLLECTION_TIME_TAG, String.valueOf(projectDataValue.collectionTime));
                groupElement.addContent(projectElement);
                isEmptyGroup = false;
            }
        }
        if (!isEmptyGroup) {
            element.addContent(groupElement);
        }
    }
    return element;
}
Also used : Element(org.jdom.Element) Map(java.util.Map) GroupDescriptor(com.intellij.internal.statistic.beans.GroupDescriptor)

Example 5 with GroupDescriptor

use of com.intellij.internal.statistic.beans.GroupDescriptor in project intellij-community by JetBrains.

the class ApplicationStatisticsPersistenceComponent method loadState.

@Override
public void loadState(Element element) {
    for (Element groupElement : element.getChildren(GROUP_TAG)) {
        GroupDescriptor groupDescriptor = GroupDescriptor.create(groupElement.getAttributeValue(GROUP_NAME_ATTR));
        List<Element> projectsList = groupElement.getChildren(PROJECT_TAG);
        for (Element projectElement : projectsList) {
            String projectId = projectElement.getAttributeValue(PROJECT_ID_ATTR);
            String frameworks = projectElement.getAttributeValue(VALUES_ATTR);
            if (!StringUtil.isEmptyOrSpaces(projectId) && !StringUtil.isEmptyOrSpaces(frameworks)) {
                Set<UsageDescriptor> frameworkDescriptors = new THashSet<>();
                for (String key : StringUtil.split(frameworks, TOKENIZER)) {
                    UsageDescriptor descriptor = getUsageDescriptor(key);
                    if (descriptor != null) {
                        frameworkDescriptors.add(descriptor);
                    }
                }
                long collectionTime;
                try {
                    collectionTime = Long.valueOf(projectElement.getAttributeValue(COLLECTION_TIME_TAG));
                } catch (NumberFormatException ignored) {
                    collectionTime = 0;
                }
                getApplicationData(groupDescriptor).put(projectId, new CollectedUsages(frameworkDescriptors, collectionTime));
            }
        }
    }
}
Also used : Element(org.jdom.Element) UsageDescriptor(com.intellij.internal.statistic.beans.UsageDescriptor) GroupDescriptor(com.intellij.internal.statistic.beans.GroupDescriptor) THashSet(gnu.trove.THashSet)

Aggregations

GroupDescriptor (com.intellij.internal.statistic.beans.GroupDescriptor)6 Map (java.util.Map)3 Set (java.util.Set)3 Element (org.jdom.Element)3 LinkedHashMap (com.intellij.util.containers.hash.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 PatchedUsage (com.intellij.internal.statistic.beans.PatchedUsage)1 UsageDescriptor (com.intellij.internal.statistic.beans.UsageDescriptor)1 HashMap (com.intellij.util.containers.hash.HashMap)1 THashSet (gnu.trove.THashSet)1