<commit_before>/*
 * Copyright  2000-2009 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); 
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License. 
 *
 */
package org.apache.bcel.util;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

/**
 * Responsible for loading (class) files from the CLASSPATH. Inspired by
 * sun.tools.ClassPath.
 *
 * @version $Id$
 * @author  <A HREF="mailto:<EMAIL>"><NAME></A>
 */
public class ClassPath implements Serializable {

    public static final ClassPath SYSTEM_CLASS_PATH = new ClassPath();
    private PathEntry[] paths;
    private String class_path;
    private ClassPath parent;

    public ClassPath(ClassPath parent, String class_path) {
        this(class_path);
        this.parent = parent;
    }

    /**
     * Search for classes in given path.
     */
    public ClassPath(String class_path) {
        this.class_path = class_path;
        List vec = new ArrayList();
        for (StringTokenizer tok = new StringTokenizer(class_path, System
                .getProperty("path.separator")); tok.hasMoreTokens();) {
            String path = tok.nextToken();
            if (!path.equals("")) {
                File file = new File(path);
                try {
                    if (file.exists()) {
                        if (file.isDirectory()) {
                            vec.add(new Dir(path));
                        } else {
                            vec.add(new Zip(new ZipFile(file)));
                        }
                    }
                } catch (IOException e) {
                    System.err.println("CLASSPATH component " + file + ": " + e);
                }
            }
        }
        paths = new PathEntry[vec.size()];
        vec.toArray(paths);
    }


    /**
     * Search for classes in CLASSPATH.
     * @deprecated Use SYSTEM_CLASS_PATH constant
     */
    public ClassPath() {
        this(getClassPath());
    }


    /** @return used class path string
     */
    public String toString() {
        if (parent != null) {
            return parent.toString() + File.pathSeparator + class_path;
        }
        return class_path;
    }

    public int hashCode() {
        if (parent != null) {
            return class_path.hashCode() + parent.hashCode();            
        }
        return class_path.hashCode();
    }


    public boolean equals( Object o ) {
        if (o instanceof ClassPath) {
            ClassPath cp = (ClassPath)o;
            return class_path.toString().equals(cp.toString());
        }
        return false;
    }


    private static final void getPathComponents( String path, List list ) {
        if (path != null) {
            StringTokenizer tok = new StringTokenizer(path, File.pathSeparator);
            while (tok.hasMoreTokens()) {<commit_msg>no need to call toString on a string<commit_after>/*
 * Copyright  2000-2009 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); 
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License. 
 *
 */
package org.apache.bcel.util;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

/**
 * Responsible for loading (class) files from the CLASSPATH. Inspired by
 * sun.tools.ClassPath.
 *
 * @version $Id$
 * @author  <A HREF="mailto:<EMAIL>"><NAME></A>
 */
public class ClassPath implements Serializable {

    public static final ClassPath SYSTEM_CLASS_PATH = new ClassPath();
    private PathEntry[] paths;
    private String class_path;
    private ClassPath parent;

    public ClassPath(ClassPath parent, String class_path) {
        this(class_path);
        this.parent = parent;
    }

    /**
     * Search for classes in given path.
     * 
     * @param class_path
     */
    public ClassPath(String class_path) {
        this.class_path = class_path;
        List vec = new ArrayList();
        for (StringTokenizer tok = new StringTokenizer(class_path, System
                .getProperty("path.separator")); tok.hasMoreTokens();) {
            String path = tok.nextToken();
            if (!path.equals("")) {
                File file = new File(path);
                try {
                    if (file.exists()) {
                        if (file.isDirectory()) {
                            vec.add(new Dir(path));
                        } else {
                            vec.add(new Zip(new ZipFile(file)));
                        }
                    }
                } catch (IOException e) {
                    System.err.println("CLASSPATH component " + file + ": " + e);
                }
            }
        }
        paths = new PathEntry[vec.size()];
        vec.toArray(paths);
    }


    /**
     * Search for classes in CLASSPATH.
     * @deprecated Use SYSTEM_CLASS_PATH constant
     */
    public ClassPath() {
        this(getClassPath());
    }


    /** @return used class path string
     */
    public String toString() {
        if (parent != null) {
            return parent.toString() + File.pathSeparator + class_path;
        }
        return class_path;
    }

    public int hashCode() {
        if (parent != null) {
            return class_path.hashCode() + parent.hashCode();            
        }
        return class_path.hashCode();
    }


    public boolean equals( Object o ) {
        if (o instanceof ClassPath) {
            ClassPath cp = (ClassPath)o;
            return class_path.equals(cp.toString());
        }
        return false;
    }


    private static final void getPathComponents( String path, List list ) {
        if (path != null) {
            StringTokenizer tok = new StringTokenizer(path, File.pathSeparator);
            while (tok.hasMoreTokens()) {
{'fraction_non_alphanumeric': 0.10189730662067135, 'fraction_numerical': 0.00318429083189598, 'mean_word_length': 2.1513377926421406, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1079533', 'n_tokens_mistral': 2078, 'n_tokens_neox': 2025, 'n_words': 603}