KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lsmp > djep > groupJep > groups > PermutationGroup


1 /* @author rich
2  * Created on 15-Mar-2004
3  *
4  * This code is covered by a Creative Commons
5  * Attribution, Non Commercial, Share Alike license
6  * <a HREF="http://creativecommons.org/licenses/by-nc-sa/1.0">License</a>
7  */

8 package org.lsmp.djep.groupJep.groups;
9
10 import org.lsmp.djep.groupJep.GroupI;
11 import org.lsmp.djep.groupJep.values.*;
12 import org.lsmp.djep.groupJep.interfaces.*;
13
14 /**
15  * The group of permutations.
16  *
17  * TODO not sure if this works, not really tested.
18  *
19  * @author Rich Morris
20  * @see org.lsmp.djep.groupJep.values.Permutation
21  * Created on 15-Mar-2004
22  */

23 public class PermutationGroup extends Group implements GroupI , HasListI {
24
25     protected Permutation zeroPerm;
26     
27     public PermutationGroup(int n)
28     {
29         Integer JavaDoc perm[] = new Integer JavaDoc[n];
30         for(int i=0;i<n;++i)
31             perm[i]=new Integer JavaDoc(i+1);
32         zeroPerm = new Permutation(this,perm);
33     }
34
35     public Number JavaDoc getZERO() {
36         return zeroPerm;
37     }
38
39     public Number JavaDoc getInverse(Number JavaDoc a) {
40         return ((Permutation) a).getInverse();
41     }
42
43     public Number JavaDoc add(Number JavaDoc a, Number JavaDoc b) {
44         return ((Permutation) a).add((Permutation) b);
45     }
46
47     public Number JavaDoc sub(Number JavaDoc a, Number JavaDoc b) {
48         return ((Permutation) a).sub((Permutation) b);
49     }
50
51     public boolean equals(Number JavaDoc a, Number JavaDoc b) {
52         return ((Permutation) a).equals((Permutation) b);
53     }
54
55     public Number JavaDoc valueOf(String JavaDoc s) {
56         return Integer.valueOf(s);
57     }
58
59     public Number JavaDoc valueOf(Number JavaDoc[] eles) {
60         
61         Integer JavaDoc perm[] = new Integer JavaDoc[eles.length];
62         for(int i=0;i<eles.length;++i)
63             perm[i]=new Integer JavaDoc(eles[i].intValue());
64         Permutation res = new Permutation(this,perm);
65         return res;
66     }
67
68     public Number JavaDoc list(Number JavaDoc[] eles) {
69         return this.valueOf(eles);
70     }
71
72 }
73
Popular Tags