IDEADEV-41116: exploded war artefact: add warning for dependent module
[fedora-idea.git] / java / idea-ui / src / com / intellij / openapi / roots / ui / configuration / LibrariesAlphaComparator.java
blob43928ee4928e2ae8777540e7f199ab6b425080ee
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package com.intellij.openapi.roots.ui.configuration;
18 import com.intellij.openapi.roots.OrderRootType;
19 import com.intellij.openapi.roots.libraries.Library;
20 import com.intellij.openapi.vfs.VirtualFile;
22 import java.util.Comparator;
24 /**
25 * @author Eugene Zhuravlev
26 * Date: Jan 14, 2004
28 public class LibrariesAlphaComparator implements Comparator<Library> {
29 public static LibrariesAlphaComparator INSTANCE = new LibrariesAlphaComparator();
31 public int compare(Library library1, Library library2) {
32 String name1 = library1.getName();
33 if (name1 != null && name1.length() == 0) {
34 name1 = null;
36 String name2 = library2.getName();
37 if (name2 != null && name2.length() == 0) {
38 name2 = null;
40 if (name1 == null && name2 == null) {
41 final VirtualFile[] files1 = library1.getFiles(OrderRootType.CLASSES);
42 final VirtualFile[] files2 = library2.getFiles(OrderRootType.CLASSES);
43 name1 = files1.length > 0? files1[0].getName() : null;
44 name2 = files2.length > 0? files2[0].getName() : null;
46 return compareNames(name1, name2);
49 public int compareNames(String name1, String name2) {
50 if (name1 == null && name2 == null) {
51 return 0;
53 else if (name1 == null) {
54 return -1;
56 else if (name2 == null) {
57 return +1;
59 else {
60 return name1.compareToIgnoreCase(name2);