use of java.util.TreeSet in project jodd by oblac.
the class ClassLoaderUtil method getDefaultClasspath.
/**
* Returns default class path from all available <code>URLClassLoader</code>
* in classloader hierarchy. The following is added to the classpath list:
* <ul>
* <li>file URLs from <code>URLClassLoader</code> (other URL protocols are ignored)</li>
* <li>inner entries from containing <b>manifest</b> files (if exist)</li>
* <li>bootstrap classpath</li>
* </ul>
*/
public static File[] getDefaultClasspath(ClassLoader classLoader) {
Set<File> classpaths = new TreeSet<>();
while (classLoader != null) {
if (classLoader instanceof URLClassLoader) {
URL[] urls = ((URLClassLoader) classLoader).getURLs();
for (URL u : urls) {
File f = FileUtil.toFile(u);
if ((f != null) && f.exists()) {
try {
f = f.getCanonicalFile();
boolean newElement = classpaths.add(f);
if (newElement) {
addInnerClasspathItems(classpaths, f);
}
} catch (IOException ignore) {
}
}
}
}
classLoader = classLoader.getParent();
}
String bootstrap = SystemUtil.getSunBootClassPath();
if (bootstrap != null) {
String[] bootstrapFiles = StringUtil.splitc(bootstrap, File.pathSeparatorChar);
for (String bootstrapFile : bootstrapFiles) {
File f = new File(bootstrapFile);
if (f.exists()) {
try {
f = f.getCanonicalFile();
boolean newElement = classpaths.add(f);
if (newElement) {
addInnerClasspathItems(classpaths, f);
}
} catch (IOException ignore) {
}
}
}
}
File[] result = new File[classpaths.size()];
return classpaths.toArray(result);
}
use of java.util.TreeSet in project pcgen by PCGen.
the class MultiClassFacet method getMultiClassXPMultiplier.
/**
* Returns the multi-class XP multiplier for the Player Character identified
* by the given CharID.
*
* @param id
* The CharID identifying the Player Character for which the
* multi-class XP multipler is to be returned
* @return The multi-class XP multiplier for the Player Character identified
* by the given CharID
*/
public double getMultiClassXPMultiplier(CharID id) {
Set<PCClass> unfavoredClasses = new HashSet<>();
SortedSet<PCClass> favored = new TreeSet<>(CDOMObjectUtilities.CDOM_SORTER);
favored.addAll(favoredClassFacet.getSet(id));
SortedSet<PCClass> aList = favored;
boolean hasAny = hasAnyFavoredClassFacet.contains(id, Boolean.TRUE);
PCClass maxClass = null;
PCClass secondClass = null;
int maxClassLevel = 0;
int secondClassLevel = 0;
double xpMultiplier = 1.0;
for (PCClass pcClass : classFacet.getSet(id)) {
if (!pcClass.hasXPPenalty()) {
continue;
}
String subClassKey = subClassFacet.get(id, pcClass);
PCClass evalClass = pcClass;
if (subClassKey != null && !subClassKey.equals("None")) {
evalClass = pcClass.getSubClassKeyed(subClassKey);
}
if (!aList.contains(evalClass)) {
unfavoredClasses.add(pcClass);
int pcClassLevel = classFacet.getLevel(id, pcClass);
if (pcClassLevel > maxClassLevel) {
if (hasAny) {
secondClassLevel = maxClassLevel;
secondClass = maxClass;
}
maxClassLevel = pcClassLevel;
maxClass = pcClass;
} else if ((pcClassLevel > secondClassLevel) && (hasAny)) {
secondClassLevel = pcClassLevel;
secondClass = pcClass;
}
}
}
if ((hasAny) && (secondClassLevel > 0)) {
maxClassLevel = secondClassLevel;
unfavoredClasses.remove(maxClass);
maxClass = secondClass;
}
if (maxClassLevel > 0) {
unfavoredClasses.remove(maxClass);
int xpPenalty = 0;
for (PCClass aClass : unfavoredClasses) {
if ((maxClassLevel - (classFacet.getLevel(id, aClass))) > 1) {
++xpPenalty;
}
}
xpMultiplier = 1.0 - (xpPenalty * 0.2);
if (xpMultiplier < 0) {
xpMultiplier = 0;
}
}
return xpMultiplier;
}
use of java.util.TreeSet in project OpenAM by OpenRock.
the class FileEditor method deleteLines.
public boolean deleteLines(DeletePattern pattern) throws Exception {
Set matchPatterns = new HashSet();
matchPatterns.add(pattern);
Map patternOccurrances = getPatternOccurences(matchPatterns);
boolean success = false;
if (patternOccurrances.size() == 1) {
// Just one match should be
// found
TreeSet removeLines = addSuccessiveDeleteLines(matchPatterns, patternOccurrances);
success = deleteLineNumbers(removeLines);
}
return success;
}
use of java.util.TreeSet in project OpenAM by OpenRock.
the class FileEditor method deleteLines.
/**
*
* @param matchPatterns
* a Set of DeletePatterns
* @return true if all the patterns were found and deleted. False if some
* patterns were not found. In such cases no changes are made to
* the file.
* @throws Exception
*/
public boolean deleteLines(Set matchPatterns) throws Exception {
boolean success = false;
Map patternOccurrances = getPatternOccurences(matchPatterns);
if (patternOccurrances.size() == matchPatterns.size()) {
TreeSet removeLines = addSuccessiveDeleteLines(matchPatterns, patternOccurrances);
success = deleteLineNumbers(removeLines);
}
return success;
}
use of java.util.TreeSet in project OpenAM by OpenRock.
the class FileEditor method addSuccessiveDeleteLines.
private TreeSet addSuccessiveDeleteLines(Set matchPatterns, Map patternOccurrances) {
TreeSet removeLines = new TreeSet(patternOccurrances.values());
Iterator iter = matchPatterns.iterator();
while (iter.hasNext()) {
DeletePattern dp = (DeletePattern) iter.next();
Integer lineNumber = (Integer) patternOccurrances.get(dp.getPattern());
int numSuccessiveLines = dp.getNumberOfSuccessiveLines();
for (int i = 1; i <= numSuccessiveLines; i++) {
removeLines.add(new Integer(lineNumber.intValue() + i));
}
}
return removeLines;
}
Aggregations