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);
}
}
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();
}
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;
}
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);
}
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();
}
Aggregations