KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgrapht > experimental > isomorphism > comparators > DirectedEdgeWeightOddEvenComparator


1 /* ==========================================
2  * JGraphT : a free Java graph-theory library
3  * ==========================================
4  *
5  * Project Info: http://jgrapht.sourceforge.net/
6  * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
7  *
8  * (C) Copyright 2003-2006, by Barak Naveh and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation; either version 2.1 of the License, or
13  * (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this library; if not, write to the Free Software Foundation,
22  * Inc.,
23  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
24  */

25 /* -----------------
26  * DirectedEdgeWeightOddEvenComparator.java
27  * -----------------
28  * (C) Copyright 2005-2006, by Assaf Lehr and Contributors.
29  *
30  * Original Author: Assaf Lehr
31  * Contributor(s): -
32  *
33  * $Id: DirectedEdgeWeightOddEvenComparator.java 489 2006-07-02 02:05:47Z
34  * perfecthash $
35  *
36  * Changes
37  * -------
38  */

39 package org.jgrapht.experimental.isomorphism.comparators;
40
41 import org.jgrapht.*;
42 import org.jgrapht.experimental.equivalence.*;
43
44
45 /**
46  * eq.set according to the weights of the edges. Uses Graph.getEdgeWeight(Edge)
47  * (cast to integer) and checks odd/even.
48  *
49  * @author Assaf
50  * @since Aug 12, 2005
51  */

52 public class DirectedEdgeWeightOddEvenComparator
53     implements EquivalenceComparator
54 {
55
56     //~ Instance fields -------------------------------------------------------
57

58     private final Graph graph;
59
60     //~ Constructors ----------------------------------------------------------
61

62     public DirectedEdgeWeightOddEvenComparator(Graph graph)
63     {
64         this.graph = graph;
65     }
66
67     //~ Methods ---------------------------------------------------------------
68

69     /* (non-Javadoc)
70      * @see
71      *
72      *
73      *
74      *
75      *
76      * org.jgrapht.experimental.equivalence.EquivalenceComparator#equivalenceCompare(java.lang.Object,
77      * java.lang.Object, java.lang.Object, java.lang.Object)
78      */

79     @SuppressWarnings JavaDoc("unchecked")
80     public boolean equivalenceCompare(
81         Object JavaDoc arg1,
82         Object JavaDoc arg2,
83         Object JavaDoc context1,
84         Object JavaDoc context2)
85     {
86         int int1 = (int) graph.getEdgeWeight(arg1);
87         int int2 = (int) graph.getEdgeWeight(arg2);
88
89         boolean result = ((int1 % 2) == (int2 % 2));
90         return result;
91     }
92
93     /* (non-Javadoc)
94      * @see
95      *
96      *
97      *
98      *
99      *
100      * org.jgrapht.experimental.equivalence.EquivalenceComparator#equivalenceHashcode(java.lang.Object,
101      * java.lang.Object)
102      */

103     @SuppressWarnings JavaDoc("unchecked")
104     public int equivalenceHashcode(Object JavaDoc arg1, Object JavaDoc context)
105     {
106         int int1 = (int) graph.getEdgeWeight(arg1);
107         return int1 % 2;
108     }
109 }
110
Popular Tags