Search in sources :

Example 96 with LinkedHashSet

use of java.util.LinkedHashSet in project intellij-community by JetBrains.

the class ExternalClasspathClassLoader method parseUrls.

private static String[] parseUrls(String classpathFilePath) {
    Collection<String> roots = new LinkedHashSet<>();
    File file = new File(classpathFilePath);
    try {
        final BufferedReader reader = new BufferedReader(new FileReader(file));
        try {
            while (reader.ready()) {
                roots.add(reader.readLine());
            }
        } finally {
            reader.close();
        }
        //noinspection SSBasedInspection
        return roots.toArray(new String[roots.size()]);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File)

Example 97 with LinkedHashSet

use of java.util.LinkedHashSet in project intellij-community by JetBrains.

the class GutterIconTooltipHelper method composeText.

public static String composeText(@NotNull Iterable<? extends PsiElement> elements, @NotNull String start, @NotNull String pattern, @NotNull String postfix) {
    @NonNls StringBuilder result = new StringBuilder();
    result.append("<html><body>");
    result.append(start);
    Set<String> names = new LinkedHashSet<>();
    for (PsiElement element : elements) {
        String descr = "";
        if (element instanceof PsiClass) {
            String className = ClassPresentationUtil.getNameForClass((PsiClass) element, true);
            descr = MessageFormat.format(pattern, className);
        } else if (element instanceof PsiMethod) {
            String methodName = ((PsiMethod) element).getName();
            PsiClass aClass = ((PsiMethod) element).getContainingClass();
            String className = aClass == null ? "" : ClassPresentationUtil.getNameForClass(aClass, true);
            descr = MessageFormat.format(pattern, methodName, className);
        } else if (element instanceof PsiFile) {
            descr = MessageFormat.format(pattern, ((PsiFile) element).getName());
        }
        names.add(descr);
    }
    @NonNls String sep = "";
    for (String name : names) {
        result.append(sep);
        sep = "<br>";
        result.append(name);
    }
    result.append(postfix);
    result.append("</body></html>");
    return result.toString();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NonNls(org.jetbrains.annotations.NonNls) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 98 with LinkedHashSet

use of java.util.LinkedHashSet in project heron by twitter.

the class PackingPlanBuilder method buildContainerPlans.

/**
   * Estimate the per instance and topology resources for the packing plan based on the ramMap,
   * instance defaults and paddingPercentage.
   *
   * @return container plans
   */
private static Set<PackingPlan.ContainerPlan> buildContainerPlans(Map<Integer, Container> containerInstances, Map<String, ByteAmount> ramMap, Resource instanceDefaults, int paddingPercentage) {
    Set<PackingPlan.ContainerPlan> containerPlans = new LinkedHashSet<>();
    for (Integer containerId : containerInstances.keySet()) {
        Container container = containerInstances.get(containerId);
        if (container.getInstances().size() == 0) {
            continue;
        }
        ByteAmount containerRam = ByteAmount.ZERO;
        ByteAmount containerDiskInBytes = ByteAmount.ZERO;
        double containerCpu = 0;
        // Calculate the resource required for single instance
        Set<PackingPlan.InstancePlan> instancePlans = new HashSet<>();
        for (PackingPlan.InstancePlan instancePlan : container.getInstances()) {
            InstanceId instanceId = new InstanceId(instancePlan.getComponentName(), instancePlan.getTaskId(), instancePlan.getComponentIndex());
            ByteAmount instanceRam;
            if (ramMap.containsKey(instanceId.getComponentName())) {
                instanceRam = ramMap.get(instanceId.getComponentName());
            } else {
                instanceRam = instanceDefaults.getRam();
            }
            containerRam = containerRam.plus(instanceRam);
            // Currently not yet support disk or cpu config for different components,
            // so just use the default value.
            ByteAmount instanceDisk = instanceDefaults.getDisk();
            containerDiskInBytes = containerDiskInBytes.plus(instanceDisk);
            double instanceCpu = instanceDefaults.getCpu();
            containerCpu += instanceCpu;
            // Insert it into the map
            instancePlans.add(new PackingPlan.InstancePlan(instanceId, new Resource(instanceCpu, instanceRam, instanceDisk)));
        }
        containerCpu += (paddingPercentage * containerCpu) / 100;
        containerRam = containerRam.increaseBy(paddingPercentage);
        containerDiskInBytes = containerDiskInBytes.increaseBy(paddingPercentage);
        Resource resource = new Resource(Math.round(containerCpu), containerRam, containerDiskInBytes);
        PackingPlan.ContainerPlan containerPlan = new PackingPlan.ContainerPlan(containerId, instancePlans, resource);
        containerPlans.add(containerPlan);
    }
    return containerPlans;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ByteAmount(com.twitter.heron.common.basics.ByteAmount) InstanceId(com.twitter.heron.spi.packing.InstanceId) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Resource(com.twitter.heron.spi.packing.Resource) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 99 with LinkedHashSet

use of java.util.LinkedHashSet in project intellij-community by JetBrains.

the class StringMatcher method create.

public static StringMatcher create(String target) {
    if (target.length() == 0)
        return ANY;
    if (target.equals(".*"))
        return ANY_PATTERN;
    if (target.equals(NONE.getPattern()))
        return NONE;
    final List<String> branches = StringUtil.split(target, "|");
    final Set<StringMatcher> matchers = new LinkedHashSet<>();
    for (String branch : branches) {
        boolean startsWith = false;
        boolean endsWith = false;
        boolean ignoreCase = false;
        // this assumes the regex is syntactically correct
        if (branch.startsWith("(?i)")) {
            ignoreCase = true;
            branch = branch.substring(2).toLowerCase();
        }
        if (branch.endsWith(".*")) {
            startsWith = true;
            branch = branch.substring(0, branch.length() - 2);
        }
        if (branch.startsWith(".*")) {
            endsWith = true;
            branch = branch.substring(2);
        }
        final boolean m = analyseBranch(branch);
        if (!m) {
            try {
                return new Cache(new Pattern(target));
            } catch (Exception e) {
                return new Any(target, false);
            }
        }
        final StringMatcher matcher;
        if (startsWith && endsWith) {
            matcher = new Contains(branch);
        } else if (startsWith) {
            matcher = new StartsWith(branch);
        } else if (endsWith) {
            matcher = new EndsWith(branch);
        } else {
            matcher = new Equals(branch);
        }
        matchers.add(ignoreCase ? new IgnoreCase(matcher) : matcher);
    }
    return matchers.size() == 1 ? matchers.iterator().next() : MatcherSet.create(matchers);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) StringPattern(com.intellij.patterns.StringPattern)

Example 100 with LinkedHashSet

use of java.util.LinkedHashSet in project intellij-community by JetBrains.

the class MoveMembersTest method performAction.

private void performAction(String sourceClassName, String targetClassName, int[] memberIndices, final String visibility) throws Exception {
    PsiClass sourceClass = myJavaFacade.findClass(sourceClassName, ProjectScope.getProjectScope(myProject));
    assertNotNull("Class " + sourceClassName + " not found", sourceClass);
    PsiClass targetClass = myJavaFacade.findClass(targetClassName, ProjectScope.getProjectScope(myProject));
    assertNotNull("Class " + targetClassName + " not found", targetClass);
    PsiElement[] children = sourceClass.getChildren();
    ArrayList<PsiMember> members = new ArrayList<>();
    for (PsiElement child : children) {
        if (child instanceof PsiMember) {
            members.add(((PsiMember) child));
        }
    }
    LinkedHashSet<PsiMember> memberSet = new LinkedHashSet<>();
    for (int index : memberIndices) {
        PsiMember member = members.get(index);
        assertTrue(member.hasModifierProperty(PsiModifier.STATIC));
        memberSet.add(member);
    }
    MockMoveMembersOptions options = new MockMoveMembersOptions(targetClass.getQualifiedName(), memberSet);
    options.setMemberVisibility(visibility);
    new MoveMembersProcessor(myProject, null, options).run();
    FileDocumentManager.getInstance().saveAllDocuments();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PsiClass(com.intellij.psi.PsiClass) ArrayList(java.util.ArrayList) PsiElement(com.intellij.psi.PsiElement) MockMoveMembersOptions(com.intellij.refactoring.move.moveMembers.MockMoveMembersOptions) PsiMember(com.intellij.psi.PsiMember) MoveMembersProcessor(com.intellij.refactoring.move.moveMembers.MoveMembersProcessor)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)3111 ArrayList (java.util.ArrayList)632 Set (java.util.Set)410 HashSet (java.util.HashSet)334 HashMap (java.util.HashMap)312 Map (java.util.Map)284 List (java.util.List)269 File (java.io.File)266 LinkedHashMap (java.util.LinkedHashMap)257 IOException (java.io.IOException)240 Test (org.junit.Test)239 LinkedList (java.util.LinkedList)139 Collection (java.util.Collection)103 URL (java.net.URL)83 ProcessResult (org.asqatasun.entity.audit.ProcessResult)76 Iterator (java.util.Iterator)73 SourceCodeRemark (org.asqatasun.entity.audit.SourceCodeRemark)73 TreeMap (java.util.TreeMap)70 TreeSet (java.util.TreeSet)70 Collectors (java.util.stream.Collectors)69