01: /*
02: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
07: *
08: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
09: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
10: * the license for the specific language governing your rights and limitations.
11: *
12: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
13: */
14: package org.pentaho.reportdesigner.lib.common.graph;
15:
16: import org.jetbrains.annotations.NotNull;
17:
18: import java.util.Comparator;
19:
20: public class GraphSizeComparator implements Comparator<Graph> {
21:
22: private boolean ascending;
23:
24: public GraphSizeComparator(boolean ascending) {
25: this .ascending = ascending;
26: }
27:
28: public int compare(@NotNull
29: Graph g1, @NotNull
30: Graph g2) {
31: int g1Size = g1.getNumberOfVertices();
32: int g2Size = g2.getNumberOfVertices();
33: if (g1Size < g2Size) {
34: return ascending ? -1 : 1;
35: } else if (g1Size > g2Size) {
36: return ascending ? 1 : -1;
37: } else {
38: return 0;
39: }
40: }
41:
42: }
|