|
| 1 | +/* |
| 2 | + * #%L |
| 3 | + * SciJava Common shared library for SciJava software. |
| 4 | + * %% |
| 5 | + * Copyright (C) 2009 - 2017 Board of Regents of the University of |
| 6 | + * Wisconsin-Madison, Broad Institute of MIT and Harvard, Max Planck |
| 7 | + * Institute of Molecular Cell Biology and Genetics, University of |
| 8 | + * Konstanz, and KNIME GmbH. |
| 9 | + * %% |
| 10 | + * Redistribution and use in source and binary forms, with or without |
| 11 | + * modification, are permitted provided that the following conditions are met: |
| 12 | + * |
| 13 | + * 1. Redistributions of source code must retain the above copyright notice, |
| 14 | + * this list of conditions and the following disclaimer. |
| 15 | + * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 16 | + * this list of conditions and the following disclaimer in the documentation |
| 17 | + * and/or other materials provided with the distribution. |
| 18 | + * |
| 19 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE |
| 23 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 | + * POSSIBILITY OF SUCH DAMAGE. |
| 30 | + * #L% |
| 31 | + */ |
| 32 | + |
| 33 | +package org.scijava.io.location; |
| 34 | + |
| 35 | +import java.io.IOException; |
| 36 | +import java.util.Collections; |
| 37 | +import java.util.Set; |
| 38 | + |
| 39 | +/** |
| 40 | + * A {@link Location} that offers methods to browse other locations relative to |
| 41 | + * it. |
| 42 | + * |
| 43 | + * @author Gabriel Einsdorf |
| 44 | + * @author Curtis Rueden |
| 45 | + */ |
| 46 | +public interface BrowsableLocation extends Location { |
| 47 | + |
| 48 | + /** |
| 49 | + * Obtains a location pointing to the parent directory of this one. |
| 50 | + * |
| 51 | + * @return the parent location of this one, or <code>null</code> if this |
| 52 | + * location has no parent. |
| 53 | + * @throws IOException if something goes wrong obtaining the parent. |
| 54 | + */ |
| 55 | + BrowsableLocation parent() throws IOException; |
| 56 | + |
| 57 | + /** |
| 58 | + * Obtains a collection of locations for whom this location is the parent. |
| 59 | + * Note that this will only succeed if calls to {@link #isDirectory()} on this |
| 60 | + * location return <code>true</code>. |
| 61 | + * |
| 62 | + * @return A set containing the children of this location, or |
| 63 | + * {@link Collections#EMPTY_SET} if this location has no children. |
| 64 | + * @throws IOException if something goes wrong obtaining the children. |
| 65 | + * @throws IllegalArgumentException if this location is not a directory (i.e., |
| 66 | + * {@link #isDirectory()} returns false). |
| 67 | + */ |
| 68 | + Set<BrowsableLocation> children() throws IOException; |
| 69 | + |
| 70 | + /** |
| 71 | + * Obtains a location relative to this one, which will be configured |
| 72 | + * like the current location, but point to a the file specified by the |
| 73 | + * <code>path</code> parameter. |
| 74 | + * |
| 75 | + * @param path the relative path of the desired location. |
| 76 | + * @return A location that points to the specified file location. |
| 77 | + * @throws IOException if something goes wrong obtaining the sibling |
| 78 | + */ |
| 79 | + BrowsableLocation sibling(String path) throws IOException; |
| 80 | + |
| 81 | + /** |
| 82 | + * Tests whether this location is a <b>directory</b>, meaning that it can have |
| 83 | + * children. It is recommended to use this method before calling |
| 84 | + * {@link #child(String)} or {@link #children()}, to ensure those calls |
| 85 | + * succeed. |
| 86 | + * |
| 87 | + * @return True iff the location represents a directory. |
| 88 | + */ |
| 89 | + boolean isDirectory(); |
| 90 | + |
| 91 | + /** |
| 92 | + * Obtains a location with the given name, for whom this location is the |
| 93 | + * parent. Note that this will only succeed if calls to {@link #isDirectory()} |
| 94 | + * on this location return <code>true</code>. |
| 95 | + * |
| 96 | + * @param name the name of the child |
| 97 | + * @return a location pointing to the child |
| 98 | + * @throws IOException if something goes wrong obtaining the child. |
| 99 | + * @throws IllegalArgumentException if this location is not a directory (i.e., |
| 100 | + * {@link #isDirectory()} returns false). |
| 101 | + */ |
| 102 | + BrowsableLocation child(String name) throws IOException; |
| 103 | +} |
0 commit comments