01: /*
02: * Copyright 2005 by Lars Torunski
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: */
17: package com.torunski.crawler.link;
18:
19: import java.util.Comparator;
20:
21: /**
22: * A link comparator which compares the depth first and then the URI.
23: *
24: * @author Lars Torunski
25: * @version $Revision: 1.1 $
26: */
27: public final class LinkDepthComparator implements Comparator {
28:
29: /**
30: * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
31: */
32: public int compare(Object o1, Object o2) {
33: LinkDepth l1 = (LinkDepth) o1;
34: LinkDepth l2 = (LinkDepth) o2;
35:
36: if (l1.getDepth() != l2.getDepth()) {
37: return l1.getDepth() - l2.getDepth();
38: } else {
39: return l1.getURI().compareTo(l2.getURI());
40: }
41: }
42:
43: }
|