1/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package vogar;
18
19import java.io.File;
20import java.util.ArrayList;
21import java.util.Arrays;
22import java.util.Collection;
23import java.util.List;
24import vogar.util.Strings;
25
26/**
27 * A list of jar files and directories.
28 */
29public final class Classpath {
30
31    private final List<File> elements = new ArrayList<File>();
32
33    public static Classpath of(File... files) {
34        return of(Arrays.asList(files));
35    }
36
37    public static Classpath of(Collection<File> files) {
38        Classpath result = new Classpath();
39        result.elements.addAll(files);
40        return result;
41    }
42
43    public void addAll(File... elements) {
44        addAll(Arrays.asList(elements));
45    }
46
47    public void addAll(Collection<File> elements) {
48        this.elements.addAll(elements);
49    }
50
51    public void addAll(Classpath anotherClasspath) {
52        this.elements.addAll(anotherClasspath.elements);
53    }
54
55    public Collection<File> getElements() {
56        return elements;
57    }
58
59    public boolean isEmpty() {
60        return elements.isEmpty();
61    }
62
63    public boolean contains(File file) {
64        return elements.contains(file);
65    }
66
67    @Override public String toString() {
68        return Strings.join(elements, ":");
69    }
70}
71