import java.util.*; /** An abstract class for the representation of graphs with Objects as entries. */ public abstract class Graph implements Combiner { protected int size; /** Constructs a graph with a given adjacency matrix, assuming that the matrix is not null and is not of size 0 The entries are not initialized; this is the job of the concrete subclasses. @param entries the desired adjacency matrix */ public Graph(Object[][] entries) { if (entries.length > 0) size = entries[0].length; else size = 0; } /** @return the number of vertices in the graph */ public int size() { return size; } /** return the weight for a given edge @param row the source of the edge @param col the destination of the edge */ public abstract Object getEntry(int row, int col); /** find the edges with a given source vertex @param i the vertex @return a List of the edges */ protected abstract List getRow(int i); /** find the edges with a given destination vertex @param i the vertex @return a List of the edges */ protected abstract List getColumn(int i); /** an abstract method for applying a row of an adjacency matrix of a graph to a column -- that is, a method for processing all sets of pairs of edges {(x,i),(i,y)}. @param g the graph @return a new graph resulting from the processing */ protected abstract Object[][] combine(Graph g); } // end abstract class Graph