Search in sources :

Example 96 with TreeSet

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);
}
Also used : TreeSet(java.util.TreeSet) URLClassLoader(java.net.URLClassLoader) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) File(java.io.File) URL(java.net.URL)

Example 97 with TreeSet

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;
}
Also used : TreeSet(java.util.TreeSet) PCClass(pcgen.core.PCClass) HashSet(java.util.HashSet)

Example 98 with TreeSet

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;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) TreeSet(java.util.TreeSet) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 99 with TreeSet

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;
}
Also used : TreeSet(java.util.TreeSet) HashMap(java.util.HashMap) Map(java.util.Map)

Example 100 with TreeSet

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;
}
Also used : TreeSet(java.util.TreeSet) Iterator(java.util.Iterator)

Aggregations

TreeSet (java.util.TreeSet)3785 ArrayList (java.util.ArrayList)833 Test (org.junit.Test)544 HashMap (java.util.HashMap)500 HashSet (java.util.HashSet)428 Set (java.util.Set)422 Map (java.util.Map)401 IOException (java.io.IOException)374 File (java.io.File)339 List (java.util.List)320 TreeMap (java.util.TreeMap)229 Iterator (java.util.Iterator)189 SortedSet (java.util.SortedSet)186 LinkedList (java.util.LinkedList)110 LinkedHashSet (java.util.LinkedHashSet)106 Date (java.util.Date)94 Collection (java.util.Collection)90 Comparator (java.util.Comparator)85 Test (org.testng.annotations.Test)81 Text (org.apache.hadoop.io.Text)79