📄 projection.java
字号:
package toocom.ocgl;
import java.net.*;
import java.io.*;
import java.util.*;
import toocom.exceptions.*;
/**
* This class represents a projection from a graph into another one.
*
* @author Fr閐閞ic F黵st
*/
public class Projection{
private Graph g1,g2;
// Projection table : idFrom (g1) /idInto (g2)
private IdTable proj;
/** Creates a Projection from g1 into g2. */
public Projection(Graph g1, Graph g2){
this.g1 = g1;
this.g2 = g2;
this.proj = new IdTable();
}
public Graph getProjectedGraph(){
return g1;
}
public Graph getTargetGraph(){
return g2;
}
/** Add a correspondance between the two graphs if the two id exists in the corresponding
* graphs. */
public void setCorrespondance(int idFrom,int idInto){
proj.put(idFrom,idInto);
}
/** Returns a table which contains the couple of id (idFrom (g1) / idTo (g2)) that
* represent the projection. */
public IdTable getCorrespondances(){
return this.proj;
}
/** Returns the id of the conceptual primitive, of the graph in which the projection is
* done, which is the image of the primitive with the given id in the projected graph.
* Returns -1 if any correspondance exist. */
public int getCorrespondance(int idFrom){
return proj.get(idFrom);
}
/** Returns true if p1 and p2 are reciprocal, that is p1:G1->G2 and p2:G2->G1 and
* the couples of nodes of p1 and p2 are the same, but inverted.*/
public static boolean reciprocalProjections(Projection p1, Projection p2){
if(p1.getProjectedGraph().equals(p2.getTargetGraph()) &&
p1.getTargetGraph().equals(p2.getProjectedGraph()) &&
p1.getCorrespondances().size()==p2.getCorrespondances().size()){
boolean result = true;
for(Enumeration e1 = p1.getCorrespondances().keys();e1.hasMoreElements();){
int id1 = ((Integer) e1.nextElement()).intValue();
int id2 = p1.getCorrespondance(id1);
if(p2.getCorrespondance(id2) != id1) result = false;
}
return result;
}
else return false;
}
public String toString(Language l){
return ("(" + g1.getTerm(l) + "," + g2.getTerm(l) + ")" + proj.toString());
}
public String toString(){
return this.proj.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -