View Javadoc
1   /*
2    * dpkg - Debian Package library and the Debian Package Maven plugin
3    * (c) Copyright 2016 Gerrit Hohl
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18   */
19  package net.sourceforge.javadpkg.store;
20  
21  import java.util.Comparator;
22  
23  /**
24   * <p>
25   * A {@link Comparator} for {@link DataStoreNode}s residing in the same parent
26   * node.
27   * </p>
28   * <p>
29   * Directory nodes (see {@link DataStoreNode#isDirectory()} have a higher
30   * priority than file nodes (see {@link DataStoreNode#isFile()}). Nodes are
31   * compared by their names.
32   * </p>
33   *
34   * @author Gerrit Hohl (gerrit-hohl@users.sourceforge.net)
35   * @version <b>1.0</b>, 23.05.2016 by Gerrit Hohl
36   */
37  public class DataStoreNodeComparator implements Comparator<DataStoreNode> {
38  	
39  	
40  	/**
41  	 * <p>
42  	 * Creates a comparator.
43  	 * </p>
44  	 */
45  	public DataStoreNodeComparator() {
46  		super();
47  	}
48  	
49  	
50  	@Override
51  	public int compare(DataStoreNode o1, DataStoreNode o2) {
52  		if (o1.isDirectory() && o2.isFile())
53  			return -1;
54  		else if (o1.isFile() && o2.isDirectory())
55  			return 1;
56  		
57  		return o1.getName().compareTo(o2.getName());
58  	}
59  
60  
61  }