Implementing interface question
Why is it that if you define an interface that includes a method that defines a throws clause, then the class that implements the method does not have to define the throws clause in the corresponding method definition.
Cheers,
SB
Actually, you have overridden the interface�s method in your class.
An overriding method may not throw an exception unless the overridden method throws that exception or a superclass of that exception.
But you are not constrained to throw an exception when you override a method.
Also, it is legal to not check for exceptions even if your method�s definition has declared an exception. This is true for any method declaration, not only for the overriding ones.
Similar Messages
-
Implementing interfaces question
I have a really vague question about interfaces....can't really figure out how this works...I know that interfaces only have method definitions and the implementing classes should define those methods.
I am trying to use a DOM parser to parse an XML document. The org.w3c.dom package gives you a list of interfaces like Node, NodeList, Document etc to work on.
Assume that i have the following code in my class:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(invoiceXML);
NodeList itemList = doc.GetElementsByTagName("item");
Here is what I dont understand...doc is of type Document which is an interface. How can you call the method of an interface directly in the 4th line? I thought we are only supposed to call methods on the implementing class...the problem is I dont see an implementing class here...does the builder.parse(invoiceXML) return a Document interface or an object that implements the Document interface? If 'doc' is actually an object that implements the Document interface then it makes sense here...but then will all the methods be automatically implemented in the object created by the api?Here is what I dont understand...doc is of type Document which is an interface. Yes.
How can you call the method of an interface directly in the 4th line? How? Just like that.
I thought we are only supposed to call methods on the implementing class...Methods are applied to objects, not classes.
the problem is I dont see an implementing class here...And you don't need to. Do you need to open up your DVD player and look inside in order to push "play"?
does the builder.parse(invoiceXML) return a Document interface or an object that implements the Document interface? Methods don't return interfaces. They return references to objects (or primitive values).
If 'doc' is actually an object that implements the Document interface then it makes sense here...Eureka!
but then will all the methods be automatically implemented in the object created by the api?"Automatically" is not how to think about it. The Document interface was implemented by some class, the details of which aren't important. What's important is that if you have a reference to an object of type Document, you can apply Document methods to it, according to the API for Document. -
I have to add a main view to the portfolio items and integrate the view WI_DMS of the web dynpro component DMS_DPR to the same. When I try to do it, it says 'WI_DMS does not implement a valid interface". Is there any way to implement the valid interface dynamically? PLease help.
>i have been using ( implementing ) interfaces in the components, for example i used iwd_value_help. however i still have no clarity how WD framework is able to communicate with the component implementing interface iwd_value_help.
Web Dynpro can create a component usage based upon the interface type alone. This is very similar to normal ABAP OO when you create/get an instance of a class but only know the interface. Basically this is polymorphism at the component level.
>the basic question here is, what is wd framework, is it class implementing interfaces generated when we create views and other stuff. and this class( WD fw ) is going to call these implemented methods of the interface??
Simple answer: yes, exactly as you describe. Everything relates back to generated and local classes. The framework can interact with them becuase all the generated classes implement SAP provide framework interfaces. -
Public class implements interface
I am taking my first crack at interfaces: I have superclass A which is a parent of class B, which implements interface C. I need to use class B to make 3 variable instances within class A. I think I will use interface C to make calculations based on the 3 variables. Where do you recommend that I declare and set values for the 3 variables if I need to output the values at the top, in superclass A?
I'm just a little unclear on pulling these objcts together... thanks in advance.I am taking my first crack at interfaces: I have
superclass A which is a parent of class B, which
implements interface C. I need to use class B to make
3 variable instances within class A. I think I will
use interface C to make calculations based on the 3
variables. Where do you recommend that I declare and
set values for the 3 variables if I need to output the
values at the top, in superclass A?
I'm just a little unclear on pulling these objcts
together... thanks in advance. If your variables are going to be used by your superclass A then they had better be declared there. You can work with them whereever you want.
I'm not sure what you are saying about "...use interface C to make calculations based on the 3 variables." You can't do calculations inside an interface. Furthermore, if B extends A and implements C then A and C are going to be completely separate entities. Any reference to C, even if it is actually an object of type B, will not be able to use anything in A--unless you cast it to B, in which case there is no use in making an interface at all.
I probably just confused you, but oh well...
Jeff -
Oracle EBS R12 Pre - Implementations phase question air
Oracle EBS R12 Pre - Implementations phase question air
Posted: Jun 30, 2009 10:22 AM Edit Reply
Dear all Gurus,
We are going to implement Oracle EBS r12, for industrial concern, we have following quires if any peer may suggest.
1) we heard the oracle R12 has build new release with 11g db , is it been practical for choosing it for corporate ???
2) Linux Read hat which version is more stable like 5 releases is compatible with R12 new release?
3) We are also thinking for 64 bit architecture rather than 32 bit, could any one figure out the practical pros and cons for this.
4) We are also wondering about the server machine brand and its configurations like HP DL380 G6, DELL 2850? could any one share abut his experience about the same.
5) What sort of Server configurations (Processor , 2way -4way , RAM , HD and other accessories ) for r12 Multi node setup for 150 clients (DB Server , Apps Server , Test Prod )
6) What should be backup strategies like tap backup and how much space requirements we must have provisioned for retaining almost 2~3 month backup.
7) Application implementations methodologies?
8)
I know to address our queries would be time consuming for you bust peoples , but I would really oblige for being shared your journey this would defiantly the PATH way for other like mentoring for others.
looking forward your valuable instructions ASAP.
Thanks & Best Regards
Muhammad Waseem
Manager IT
Neee-Has Textiles Divisions
31-Q Gulberg II Lahore
Pakistan
92-0333-4240949Duplicate post.
Oracle EBS R12 Pre - Implementations phase question air
Oracle EBS R12 Pre - Implementations phase question air -
Perspective for Java technologies : implementing interface on late.
In Java, to implements the adapter pattern's; we have to create a new class that have a link with the adaptee class and implements the adapter interface.
class MyAdapter implements IAdapter
public MyAdapter( Adaptee a );
}or, if we need protected methods :
class MyAdapter extends implements IAdapter
public MyAdapter( Adaptee a );
}then, to call the method void foo( IAdapter i ); ;
we have to do xxx.foo( new MyAdapter( adaptee ) );it could be simpler if java allowed to implement interfaces after defining the java class.
public class Adaptee
}and then, in another file, something like,
implementation of IAdapter for class Adaptee
}would be equivalent to
public class Adaptee implements IAdapter
}The advantage of the first method is that you can adapt very easy external classes from external jar file.
thank's for coments.An interface is a contract which tells the compiler
that a class that implements it implements a set of
method signature which perform certain actions.That's right, but my idea is not to change the interface, but to change the external class, making it implements the existing interface.
If you overlay an interface on someone else's class,
the signature match (if there is one) could happen by
coincidence. There's no guarantee that a method with
a signature that matches one in your interface
actually has the same function.I didn't say that an external class should be viewed as an interface without a specific implementation of this interface for the external class. But, instead of making a new class extending the first and implementing the interface, just define a specific implementation of the interface for this class, as if it was make at class declaration. -
Hello,
I've recently decided to take a look at AS3, and I was in the
process of seeing what kind of changes I needed to do with my code
to make it AS3 compliant. I did the changes to import the
flash.display.MovieClip class. As I was going through this circular
pattern (compile, flash tells me what's wrong, I correct it...)
this one area has stumped me.
I get the following error: "1045: Interface newI was not
found."
What am I doing wrong? Are Interfaces allowed with AS3 code?
Thanks,
KellyWhile I do not know the problem, it appears AS 3.0 does still
have interface keyword:
"interface definition keyword
Usage
interface InterfaceName [extends InterfaceName ] {}
Language Version : ActionScript 3.0
Player Version : Flash Player 9
Defines an interface. Interfaces are data types that define a
set of methods; the methods must be defined by any class that
implements the interface.
An interface is similar to a class, with the following
important differences:
* Interfaces contain only declarations of methods, not their
implementation. That is, every class that implements an interface
must provide an implementation for each method declared in the
interface.
* Interface method definitions cannot have any attribute
such as public or private, but implemented methods must be marked
as public in the definition of the class that implements the
interface.
* Multiple interfaces can be inherited by an interface by
means of the extends statement, or by a class through the
implements statement.
Unlike ActionScript 2.0, ActionScript 3.0 allows the use of
getter and setter methods in interface definitions.
Note: To use this keyword, you must specify ActionScript 2.0
and Flash Player 6 or later in the Flash tab of your FLA file's
Publish Settings dialog box. This keyword is supported only when
used in external script files, not in scripts written in the
Actions panel.
See also
class
implements
Interfaces"
From
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/
under Statements, Keywords, etc. -
Hi guys. I have a test on array and inheritance and polymorphism. I didn't quite understand what is the benefit of implementing interfaces.
Something like this:
public class static Child extends Parent implement A,B,C
Where A,B,C are interfaces.
I need to get this straigth before the final test tomorrow. Thanks a lot.By implementing an interface, a class declares what it does. This means that the compiler and other classes can determine whether that class is suitable for some operations.
So given your example Child which implements interfaces A, B, and C, there could be another class with method:
public boolean doSomething(A aclass) {
}This method can be given an instance of your "Child" class, or a different class which also implements the A interface.
Interfaces say what a class does, as opposed to how it does it. -
No implementation interfaces created using jaxb 2.0 ?
Hi,
I've downloaded the jaxb 2.0 RI and am trying to follow the short tutorial at http://java.sun.com/developer/technicalArticles/WebServices/jaxb/index.html.
On trying to bind the schema via xsj,sh, which also is meant to generate the implementation interfaces (in an impl directory), I see these aren't created - the other classes are generated OK. Where or how should they be created ?
thanksI am on the same boat. Have you found the answer to this?
Thanks,
Juan -
Design Question - Class Must Implement Interface
I'm not sure how to describe this in summary, really. I'd say that I sort of want multiple inheritance, but I don't want to be shot. :-P So let me describe the situation:
I have an interface, DataEditingComponent<T>. The idea is that anything implementing the interface is capable of allowing the user to edit an object of type T. For example, a DataEditingComponent<Integer> would allow the user to input an integer. A DataEditingComponent<Map<SomeObj,Integer>> might represent an object capable of editing a table describing the number of instances of SomeObj. You get the idea. DataEditingComponent<T> describes three methods: getEditingData():T, setEditingData(T):void, and getDefaultEditingData():T. I'm assuming you can guess what those do.
Well, the practical application of this interface is in the use of a Swing application. It provides a very clean and standardized way of adjusting the contents of components which edit data. Obviously, a JTextField would work about as well as a DataEditingComponent<String>, but for more complicated components (DataEditingComponent<GameWorldMap>, for instance), the standardized interface is very helpful.
Since in practice everything that ever implements DataEditingComponent<T> extends JComponent, it would be nice to declare this as a requirement somehow. However, given that JComponent is extended into a number of various subclasses, I can't just go making DataEditingComponent<T> an abstract subclass.
So far, the only conclusion I've reached is that I can take each and every JComponent subclass and extend it into an abstract subclass which implements DataEditingComponent<T>... but that's very ugly and quickly leads to other problems. And presently, I'm left casting things from one to the other, with which I am also not happy.
So... any way out of this? Have I done something wrong design-wise? Or am I just stuck in a language limitation?
Thanks for reading!I'm not sure how to describe this in summary, really.
I'd say that I sort of want multiple inheritance,
but I don't want to be shot. :-P So let me
describe the situation:
I have an interface, DataEditingComponent<T>. The
idea is that anything implementing the interface is
capable of allowing the user to edit an object of
type T. For example, a DataEditingComponent<Integer>
would allow the user to input an integer. A
DataEditingComponent<Map<SomeObj,Integer>> might
represent an object capable of editing a table
describing the number of instances of SomeObj. You
get the idea. DataEditingComponent<T> describes
three methods: getEditingData():T,
setEditingData(T):void, and
getDefaultEditingData():T. I'm assuming you can
guess what those do.
Well, the practical application of this interface is
in the use of a Swing application. It provides a
very clean and standardized way of adjusting the
contents of components which edit data. Obviously, a
JTextField would work about as well as a
DataEditingComponent<String>, but for more
complicated components
(DataEditingComponent<GameWorldMap>, for instance),
the standardized interface is very helpful.
Since in practice everything that ever implements
DataEditingComponent<T> extends JComponent, it would
be nice to declare this as a requirement somehow.
However, given that JComponent is extended into a
number of various subclasses, I can't just go making
DataEditingComponent<T> an abstract subclass.
So far, the only conclusion I've reached is that I
can take each and every JComponent subclass and
extend it into an abstract subclass which implements
DataEditingComponent<T>... but that's very ugly and
quickly leads to other problems. And presently, I'm
left casting things from one to the other, with which
I am also not happy.
So... any way out of this? Have I done something
wrong design-wise? Or am I just stuck in a language
limitation?Hmm. The component is part of the view. The data is part of the model. Putting them together seems to go against the whole Model-View-Controller concept. You may want to have a look at how Swing separates the editing from the rendering from the model for complicated widgets such as JTable. The editors hava methods such as getEditorComponent() which returns the Component used to edit the data. Everywhere you are currently adding DataEditingComponent instances to your GUI, you can instead call a getDataEditingComponent() method, which can require that the returned object is a JComponent. -
Implements interface method at the derived class
Hi all.
I have a class (Derived) that extends another class (Base).
In the base class (Base) there is a method f() with its implementation.
In the interface (C) there is also f() method exactlly like in the base class (Base).
The derived class (Derived) is implements the interface (C).
My question is:
Do i have to implement the method f() in the derived class (Derived) ?My guess is that you probably have to, even if it's just to call the parent's method.
This all sounds pretty sketchy. Why don't you just make the BASE class implement your interface? -
Implementing interface using Oracle Fusion
Hey All, my company is responding to a tender but one of the things it specifies is that if any middleware is required it should be implemented using Oracle Fusion.
Up until this point I'd never even heard of Oracle Fusion but am trying to get up to speed fast, I need to know just enough to know we can do it and how hard it would be.
To my question then, I guess they want us to use Fusion to build the interface between their existing app and ours, but Fusion seems to be a big stack of products... Can anybody point me to the specific product we would be using to build something like that, and some good resources to get an understanding of it. Also what is the learning curve like with this product suite?
Any help appreciated.
MartynHi Martyn,
Fusion Middleware is a big stack but for integrations you can use SOA suite (or AIA). This in turn is a collection of multiple components. See below for some guidance.
http://docs.oracle.com/cd/E21764_01/integration.1111/e10223/index.htm
http://www.oracle.com/us/technologies/soa/soa-suite/oracle-soa-suite-11g-198758.pdf
Regards,
Neeraj Sehgal -
I'm working through the tutorial and have a question about casting and interfaces.
In the sample code in the tutorial, they cast other as RecanglePlus. This only makes partial sense to me. Given that the getArea() method would only work on basic rectangular/square shapes to begin with, do I still need to cast the 'other' object as a Rectangle? Presumably it would crash if I sent a circle object whether I cast the object or not.
Thank you in advance for any clarification to this.
public class RectanglePlus implements Relatable {
// a method for computing the area of the rectangle
public int getArea() {
return width * height;
// a method to implement Relatable
public int isLargerThan(Relatable other) {
RectanglePlus otherRect = (RectanglePlus)other;
if (this.getArea() < otherRect.getArea())
return -1;
else if (this.getArea() > otherRect.getArea())
return 1;
else
return 0;
{code}robert_t wrote:
I'm working through the tutorial and have a question about casting and interfaces.
In the sample code in the tutorial, they cast other as RecanglePlus. This only makes partial sense to me. Given that the getArea() method would only work on basic rectangular/square shapes to begin with, do I still need to cast the 'other' object as a Rectangle? Presumably it would crash if I sent a circle object whether I cast the object or not.Yes, you would get a ClassCastException if you called that method with anything but a RectanglePlus. If the definition of an interface method depends on methods that aren't part of that interface, then chances are either both or none of those methods should be in the interface. If Area is something that a Relatable is defined to implement, then that getArea method should be part of Relatable. If not, then the interface isn't very useful.
If you had another class Circle that implements Relatable, but doesn't have a getArea method, how would you ever use that common method to compare the two different types? You couldn't. If you make getArea an interface member, then any implementation of Relatable can return it's area, and you can leave the types as Relatable without casting to concrete types. -
Help in implementing interface
I'm a newbie to Java Programming, and I'm faced with a assignment thats require me to implement in JAVA...help desperatly needed.
I post the coding which i have to implement, and this is part of the many i needed to implement. I needed to sample solution to this and I will try to get on from there. Any reply is appreciated.
package graphs;
public interface Edge {
// Returns node that this edge starts from.
// Preconditions:
// None.
// Postconditions:
// None.
public Node fromNode();
// Returns node that this edge points to.
// Preconditions:
// None.
// Postconditions:
// None.
public Node toNode();
// Set the label of this edge.
// Precondtions:
// None.
// Postconditions:
// None.
public void setLabel(Object l);
// Returns the label of this edge.
// Precondtions:
// None.
// Postconditions:
// None.
public Object getLabel();
package graphs;
public interface Node {
public void setLabel(Object l);
public Object getLabel();
e.g of calling class
// Returns unique identity of edge e in the graph.
// Preconditions:
// + The edge e must be an edge of the graph ( hasEdge(e) == true )
// => throws NoSuchEdge on violation.
// Postconditions:
// - The returned integer is in the range 0 ... numEdges() -1
// ( Result >= 0 && Result < numEdges() ).
public int id(Edge e);
// Returns the edge with unique identity id in the graph.
// Preconditions:
// + The graph must contain at least one edge ( numEdges() > 0 )
// throws NoEdges on violation.
// + id must be in the range 0..numEdges() - 1 ( id >= 0 &&
// id < numEdges() ) throws IdOutOfRange on violation.
// Postconditions
// - The returned edge is an edge in the graph ( hasEdge(Result) == true ).
public Edge getEdge(int id);
Regardspackage graphs;
public interface Edge {
// Returns node that this edge starts from.
// Preconditions:
// None.
// Postconditions:
// None.
public Node fromNode();
// Returns node that this edge points to.
// Preconditions:
// None.
// Postconditions:
// None.
public Node toNode();
// Set the label of this edge.
// Precondtions:
// None.
// Postconditions:
// None.
public void setLabel(Object l);
// Returns the label of this edge.
// Precondtions:
// None.
// Postconditions:
// None.
public Object getLabel();
package graphs;
public interface Node {
public void setLabel(Object l);
public Object getLabel();
package graphs;
// Interface for the graph ADT.
// Design by contract style assertions are used to specify semantic
// properties for classes implementing this interface.
// In the absence of language support for assertions, implementing
// classes should check the assertions - implmenting classes extending
// the GraphBase abstract class will automatically include such checks.
// * Nodes within a graph are identified by ids that are unique for
// all nodes in that graph.
// * The ids for nodes with a graph are the integers from 0 to numNodes()-1
// inclusive.
// * A given node is a member of one and only one graph.
// * Edges within a graph are identifed by the ids of the nodes associated
// with the edge
// and by ids that are unique for all edges in that graph.
// * The ids for edges with a graph are the integers from 0 to numEdges()-1
// inclusive.
// * A given edge is a member of one and only one graph.
// * There are no relationships between graphs.
// ALTERNATIVE SPECIFICATION (DO NOT IMPLEMENT)
// * Nodes within a graph are identified by ids that are unique for all
// nodes in that graph.
// * The ids for nodes within a graph are the integers from 0 to
// numNodes()-1 inclusive.
// * A node with id x is a member of any graph having at least x+1 nodes.
// * Edges within a graph are identifed by the ids of the nodes associated
// with the edge and by ids that are unique for all edges in that graph.
// * The ids for edges with a graph are the integers from 0 to numEdges()-1
// inclusive.
// * A given edge e is a member of any graph having:
// - the two nodes associated with e as members.
// - an edge from the first of those two nodes to the second of those
// two nodes.
// * Relationships between graphs may be defined as for sets.
// END OF ALTERNATIVE SPECIFICATION
public interface Graph {
// Number of vertices (nodes).
// Preconditions:
// None.
// Postconditions:
// - The return value >= 0 ( Result >= 0 ).
public int numNodes();
// Return number of edges in the graph.
// Preconditions:
// None.
// Postconditions:
// - The return value >= 0 ( Result >= 0 ).
public int numEdges();
// Indicates whether node n is in the graph.
// Preconditions:
// + The node n is non null ( n != null ).
// Postconditions:
// None.
public boolean hasNode(Node n);
// Indicates whether edge e is in the graph.
// Preconditions:
// + The edge e is non null ( e != null ) => throws NullEdge on violation.
// Postconditions:
// None.
public boolean hasEdge(Edge e);
// Indicates whether there is an edge from node n1 to node n2 in the graph.
// Preconditions:
// + Both nodes must be in the graph ( hasNode(n1) && hasNode(n2) )
// => throws NoSuchNode on violation.
// Postconditions:
// None.
public boolean hasEdge(Node n1, Node n2);
// Returns unique identity of node n in the graph.
// Preconditions:
// + The node n must be a node of the graph ( hasNode(n) == true )
// => throws NoSuchNode on violation.
// Postconditions:
// - The returned integer is in the range 0 ... numNodes() - 1
// ( Result >= 0 && Result < numNodes() ).
public int id(Node n);
// Returns the node with unique identity id in the graph.
// Preconditions:
// + id must be in the range 0..numNodes() - 1 ( id >= 0 &&
// id < numNodes() ) throws IdOutOfRange on violation.
// Postconditions:
// - The returned node is a node in the graph ( hasNode(Result) == true ).
public Node getNode(int id);
// Returns unique identity of edge e in the graph.
// Preconditions:
// + The edge e must be an edge of the graph ( hasEdge(e) == true )
// => throws NoSuchEdge on violation.
// Postconditions:
// - The returned integer is in the range 0 ... numEdges() -1
// ( Result >= 0 && Result < numEdges() ).
public int id(Edge e);
// Returns the edge with unique identity id in the graph.
// Preconditions:
// + The graph must contain at least one edge ( numEdges() > 0 )
// throws NoEdges on violation.
// + id must be in the range 0..numEdges() - 1 ( id >= 0 &&
// id < numEdges() ) throws IdOutOfRange on violation.
// Postconditions
// - The returned edge is an edge in the graph ( hasEdge(Result) == true ).
public Edge getEdge(int id);
// Returns the edge from node n1 to node n2 in the graph.
// Preconditions:
// + Both nodes must be in the graph ( hasNode(n1) && hasNode(n2) )
// => throws NoSuchNode on violation.
// + There must be an edge from n1 to n2 in the graph
// ( hasEdge(n1,n2) == true ) => throws NoSuchEdge on violation.
// Postconditions:
// - The returned edge is in the graph ( hasEdge(Result) == true ).
public Edge getEdge(Node n1, Node n2);
// Returns number of edges from node n.
// Precondions:
// The node n is in the graph ( hasNode(n) == true )
// => throws NoSuchNode on violation.
// Postconditions:
// - The return value is in the range 0 ... number of nodes in
// the graph ( Result >= 0 && Result <= numNodes() ).
public int outDegree(Node n);
// Returns number of edges to node n.
// Precondions:
// + The node n is in the graph ( hasNode(n) == true )
// => throws NoSuchNode on violation.
// Postconditions:
// - The return value is in the range 0 ... number of nodes in the
// graph ( Result >= 0 && Result <= numNodes() ).
public int inDegree(Node n);
// Returns first node in the graph (in order of addition).
// Preconditions:
// None.
// Postconditions:
// - The returned node is null if and only if there are no nodes in
// the graph ( ( Result == null ) == ( numNodes() == 0 ) )
// - The returned node is null or is contained in the graph
// ( Result == null || hasNode(Result) == true ).
// - The returned node has an id of 0
// ( Result == null || id(Result) == 0 ).
public Node firstNode();
// Returns first edge in the graph (in order of addtion).
// Preconditions:
// None.
// Postconditions:
// - The returned edge is null if and only if there are no edges in the
// graph ( ( Result == null ) == ( numEdges() == 0 ) )
// - The returned edge is null or is an edge of the graph
// ( Result == null || hasEdge(Result) == true ).
// - The returned edge is null or has an id of 0
// ( Result == null || id(Result) == 0 ).
public Edge firstEdge();
// Returns first edge from the node, n, which is the edge from source n
// with destination node having the smallest id.
// Preconditions:
// + The node n must be a node of the graph
// ( hasNode(n) == true ) => throws NoSuchNode on violation.
// Postconditions:
// - The returned edge is null if and only if there are no edges from
// the node n ( ( Result == null ) == ( outDegree(n) == 0 ) )
// - The returned edge is null or is an edge of the graph
// ( Result == null || hasEdge(Result) == true ).
// - The returned edge is null or points from the node n
// ( Result == null || Result.fromNode() == n ).
public Edge firstEdgeFrom(Node n);
// Returns first edge to the node, n, which is the edge to destination
// n with source node having the smallest id.
// Preconditions:
// + The node n must be a node of the graph
// ( hasNode(n) == true ) => throws NoSuchNode on violation.
// Postconditions:
// - The returned edge is null if and only if there are no edges to
// the node n ( ( Result == null ) == ( inDegree(n) == 0 ) )
// - The returned edge is an edge of the graph
// ( Result == null || hasEdge(Result) == true ).
// - The returned edge points from the node n
// ( Result == null || Result.fromNode() == n ).
public Edge firstEdgeTo(Node n);
// Returns last edge from the node, n, which is the edge from source n
// with destination node having the largest id.
// Preconditions:
// + The node n must be a node of the graph
// ( hasNode(n) == true ) => throws NoSuchNode on violation.
// Postconditions:
// - The returned edge is null if and only if there are no edges from
// the node n ( ( Result == null ) == ( outDegree(n) == 0 ) )
// - The returned edge is null or is an edge of the graph
// ( Result == null || hasEdge(Result) == true ).
// - The returned edge is null or points from the node n
// ( Result == null || Result.fromNode() == n ).
public Edge lastEdgeFrom(Node n);
// Returns last edge to the node, n, which is the edge to destination
// n with source node having the largest id.
// Preconditions:
// + The node n must be a node of the graph
// ( hasNode(n) == true ) => throws NoSuchNode on violation.
// Postconditions:
// - The returned edge is null if and only if there are no edges to
// the node n ( ( Result == null ) == ( inDegree(n) == 0 ) )
// - The returned edge is an edge of the graph
// ( Result == null || hasEdge(Result) == true ).
// - The returned edge points from the node n
// ( Result == null || Result.fromNode() == n ).
public Edge lastEdgeTo(Node n);
// Returns next node in the graph after node n or null if n is the last
// node.
// Preconditions:
// + The node n must be a node of the graph
// ( hasNode(n) == true ) => throws NoSuchNode on violation.
// Postconditions:
// - The returned node is null or is contained in the graph
// ( Result == null || hasNode(Result) == true ).
// - The returned node is null if and only if the node is the node
// having the maximum id
// ( ( Result == null) == ( id(Result) == numNodes() - 1 ) ).
// - The returned node is null or the id of the returned node is
// equal to the id of n + 1
// ( Result == null || id(Result) == id(n) + 1 ).
public Node nextNode(Node n);
// Returns next edge after e or null if e is the last edge.
// Preconditions:
// + The edge e must be an edge of the graph ( hasEdge(e) == true )
// => throws NoSuchEdge on violation.
// Postconditions:
// - The returned edge is null or is contained in the graph
// ( Result == null || hasEdge(Result) == true )
// - The returned edge is null if and only if e is the edge with the
// maximum id
// ( ( Result == null) == ( id(e) == numEdges() -1 ) ).
// - The returned edge is null or the id of the returned edge is equal
// to the id of e +1
// ( Result == null || id(Result) == id(e) + 1 ).
public Edge nextEdge(Edge e);
// Returns next edge from node n after e or null if e is the last such edge.
// Preconditions:
// + The node n must be an edge of the graph ( hasNode(n) == true )
// => throws NoSuchNode on violation.
// + The edge e must be an edge of the graph ( hasEdge(e) == true )
// => throws NoSuchEdge on violation.
// + The edge e must be an edge from the node n ( e.fromNode() == n )
// => throws NoSuchEdge on violation.
// Postconditions:
// - The returned edge is null or is contained in the graph
// ( Result == null || hasEdge(Result) == true )
// - The returned edge is null or is from the node n
// ( Result == null || Result.fromNode() == n ).
// - The returned edge is null or the id of the node to which the
// returned edge points is greater than the id of the node to
// which e points
// ( Result == null || id(Result.toNode()) > id(e.toNode()) ).
public Edge nextEdgeFrom(Node n, Edge e);
// Returns next edge to node n after e or null if e is the last such edge.
// Preconditions:
// + The node n must be an edge of the graph ( hasNode(n) == true )
// => throws NoSuchNode on violation.
// + The edge e must be an edge of the graph ( hasEdge(e) == true )
// => throws NoSuchEdge on violation.
// + The edge e must be an edge to the node n ( e.toNode() == n )
// => throws NoSuchEdge on violation.
// Postconditions:
// - The returned edge is null or is contained in the graph
// ( Result == null || hasEdge(Result) == true )
// - The returned edge is null or is to the node n
// ( Result == null || Result.toNode() == n ).
// - The returned edge is null or the id of the node from which the
// returned edge points is greater than the id of the node
// from which e points
// ( Result == null || id(Result.fromNode()) > id(e.fromNode()) ).
public Edge nextEdgeTo(Node n, Edge e);
// Create and add a node to the graph with label l.
// Preconditions:
// None.
// Postconditions:
// - The number of nodes has increased by one
// ( numNodes() == old( numNodes() + 1 ) ).
// - The returned node is in the graph ( hasNode(Result) ).
// - The id of the returned node is the maximum id for any node in
// the graph ( id(Result) == numNodes()-1 ).
public Node createNode(Object l);
// Create and adds an edge from node n1 to node n2 with label l
// Preconditions:
// + Both nodes must be in the graph ( hasNode(n1) && hasNode(n2) )
// => throws NoSuchNode on violation.
// + There must not already be such an edge in the graph
// ( hasEdge(n1,n2) == false ) => throws DuplicateEdge on violation.
// Postconditions:
// - The number of edges in the graph is increased by one
// ( numEdges() == old(numEdges()) + 1 )
// - The out degree of node n1 is increased by one
// ( outDegree(n1) == old(outDegree(n1)) + 1 )
// - The in degree of node n2 is increased by one
// ( inDegree(n2) == old(inDegree(n2)) + 1 )
// - The returned edge is from node n1 and to node n2
// ( Result.fromNode() == n1 && Result.toNode() == n2 )
// - The returned edge is in the graph ( hasEdge(Result) == true )
// - The returned edge has label lbl ( Result.getLabel().equal(l) ).
// - The id of the returned edge is the maximum id for any edge in
// the graph ( id(Result) == numEdges()-1 ).
// - The returned edge is either the last edge from node n1 or the next
// edge from node n1 after the returned edge points to a node
// having an id that is greater than the id of the node that
// the returned edge points to.
// ( ( nextEdgeFrom(n1,Result) == null ) ||
// ( id((nextEdgeFrom(n1,Result)).toNode())
// > id(Result.toNode()) ) )
// - The returned edge is either the last edge to node n2 or the next
// edge to node n2 after the returned edge points from a node
// having an id that is greater than the id of the node that
// the returned edge points from.
// ( ( nextEdgeTo(n2,Result) == null ) ||
// ( id((nextEdgeTo(n2,Result)).fromNode())
// > id(Result.fromNode()) ) )
// - The returned is either the first edge from node n1 or the id of the
// node the returned edge points to is greater than the id of the
// node the first edge from node n1 points to
// ( ( firstEdgeFrom(n1) == Result ) ||
// ( id((firstEdgeFrom(n1)).toNode())
// < id(Result.toNode()) ) )
// - The returned is either the first edge from node n1 or the id of the
// node the returned edge points to is greater than the id of the
// node the first edge from node n1 points to
// ( ( firstEdgeTo(n2) == Result ) ||
// ( id((firstEdgeTo(n2)).fromNode())
// < id(Result.fromNode()) ) )
public Edge createEdge(Node n1, Node n2, Object l);
import graphs.*;
public class Printer {
private static Graph make() {
Graph g = new GraphBase(new GraphImp());
// Create some nodes
Node first = g.createNode(new Integer(1));
Node second = g.createNode(new Integer(2));
Node third = g.createNode(new Integer(3));
Node fourth = g.createNode(new Integer(4));
// Create some edges between the nodes
Edge fs = g.createEdge(first, second, new Integer(1));
Edge ff = g.createEdge(first, first, new Integer(2));
Edge ft = g.createEdge(first, third, new Integer(4));
Edge ts = g.createEdge(third, second, new Integer(3));
Edge sf = g.createEdge(second, first, new Integer(5));
Edge s4 = g.createEdge(second, fourth, new Integer(8));
return g;
protected static void print(Graph g) {
System.out.println("Nodes: " + g.numNodes() + " Edges: " + g.numEdges());
// Print graph as a list of adjacency lists.
System.out.println("\nAdjacency lists:");
for ( Node node = g.firstNode(); node != null ; node = g.nextNode(node) ) {
System.out.println("Node " + g.id(node) + " has:");
// Print the node's out edges
if ( g.outDegree(node) == 0 ) {
System.out.println("\tNo out edges");
} else {
System.out.print("\t" + g.outDegree(node) + " out edge" + (g.outDegree(node) > 1 ? "s" : "") + ":");
for ( Edge ed = g.firstEdgeFrom(node); ed != null ; ed = g.nextEdgeFrom(node,ed) ) {
System.out.print(" (" + g.id(ed.fromNode()) + "->" + g.id(ed.toNode()) + ":" + ed.getLabel().toString() + ")");
System.out.println("");
// Print the node's in edges
if ( g.inDegree(node) == 0 ) {
System.out.println("\tNo in edges");
} else {
System.out.print("\t" + g.inDegree(node) + " in edge"+ (g.outDegree(node) > 1 ? "s" : "") +":");
for ( Edge ed = g.firstEdgeTo(node); ed != null; ed = g.nextEdgeTo(node,ed) ) {
System.out.print(" (" + g.id(ed.fromNode()) + "->" + g.id(ed.toNode()) + ":" + ed.getLabel().toString() + ")");
System.out.println("");
// Print graph as an adjacency matrix.
System.out.println("\nAdjacency matrix:");
for(int col = 0; col < g.numNodes(); col++ ) {
System.out.print("\t" + col);
System.out.println("");
for(int row = 0; row < g.numNodes(); row++ ) {
System.out.print(row);
for(int col = 0; col < g.numNodes(); col++ ) {
if ( g.hasEdge(g.getNode(row), g.getNode(col)) ) {
System.out.print("\t" + g.getEdge(g.getNode(row), g.getNode(col)).getLabel().toString());
} else {
System.out.print("\t-");
System.out.println("");
// Print graph as a list of edges
System.out.println("\nEdge list:");
for( int edgeId = 0; edgeId < g.numEdges(); edgeId++ ) {
Edge edge = g.getEdge(edgeId);
System.out.println("Edge " + edgeId + " from " + g.id(edge.fromNode()) + " to " + g.id(edge.toNode()) + " with label " + edge.getLabel().toString());
public static void main(String[] args) {
try {
Graph g = make();
print(g);
} catch(Error e) {
System.err.println("### Execution terminated with errors ###");
Sorry.. I think the questions that's I posted is not complete... I have input more codes to make it more complete. And many thanks to the person that replied... many thanks and hope you can reply to this. Thanks again.
I need to implement only the GraphImp class and I think it should be
public class GraphImp implements Graph, Node, Edge
Implementing Node and Edge is onl used interally in GraphImp and need not to be public.
Any help is appreciated.. and if possible... good programmers out there... please drop me an email to my problem.... million million thanks.. -
Why Re-implements interface?
In Java API, we see such code:
public class ArrayList
extends AbstractList
implements List, RandomAccess, Cloneable, Serializable
My question is, why Sub-class(ArrayList) still declare to re-implement the same inteface(List), since Super-class(AbstractList) already implements it(List)?sateesh12345 wrote:
If any software programmer write the program to understand anyone. A software engineer makes the problem is simple. By writing the interfaces we can easily understand the what the program, and what the main functionality is in the interface.
I have given a sce::
I we have use the different types printers drives for the windows operating system. In the operating system widows os programmers are written the number of interfaces for the different types of print drivers. when ever we want use the hp printer drivers we can install the hp printer drivers in the os.
In os already hp intrerface is there. That purpose is mainly use the intrerfaces.
what ?!?+_
Maybe you are looking for
-
The music that is on the ipod is the same on the computer. The only thing is the I can play all of the music on the ipod without any problems, but I can play less then half the music on the computer. Itunes keeps asking to locate the music because th
-
Moved itunes folder to external drive and now lost playlists
To free space on my hard drive, I moved the folder to my external drive. Now, I successfully can access my music library, but my playlists aren't listed and I can't figure out how to get them/point to them. Any ideas? Thanks! Compaq Windows XP
-
Connect macbookpro to a tv through av or scart?
I am looking for a way to connect my macbook pro to a tv without hdmi/vga/dvi, but with av and scart. Is there an easy/cheap way to do so?
-
New tab positions curser in address bar
I am not sure what happened during some update along the way, but I would to be able to open a new tab and automatically have the cursor position itself in the first text box available, in my instance, the Google text box. I use Google as my homepage
-
How to get a trial version of Adobe Connect for testing?
Hi. We a reseller for Vidyo and wish to test performance of Adobe with Vidyo. Hence want to get a trail version of Adobe Connect to check features like hand raising,polls Descriptive title added by ashish gupta.