/**
 * Application manipulant des points et points pondérés

 * @author Matthias Colin
 * @version 1.0 (17/03/2009)
 */

public class TestSpecialisation {

	/**
	 * l'application manipule des points et points pondérés et teste les différentes façons de les voir (types)
	 */
	public static void main(String[] args) {
		Point pointA, pointB;
		PointPondere pointPondereA, pointPondereB;
		
		pointA = new Point("A", 0, 0);
		//pointPondereA = pointA;			// pas possible (1) : incompatible types
		System.out.println(pointA);			// OK : A(0, 0)
		//System.out.println((PointPondere) pointA);
			// pas d'erreur de compilation mais à l'exécution :
			// Exception ClassCastException : Point cannot be cast to PointPondere
		//System.out.println(pointPondereA);	// pas possible (cf 1)
		//System.out.println((Point) pointPondereA); // pas possible (cf 1)
		//System.out.println("Poids de A : " + pointA.getPoids());	
			// pas possible : cannot find symbol getPoids() class Point
		//System.out.println("Poids de A : " + pointPondereA.getPoids());  // pas possible (cf 1)
		
		System.out.println();
		pointPondereB = new PointPondere("B", 1, 2, (float) 1.5);
		pointB = pointPondereB;			// OK : 1 PointPondere est aussi un Point
		System.out.println(pointB);		// (2) la méthode toString() de la classe Point est redéfinie dans la
			// classe PointPondere ; pointB référence un PointPondere, c'est donc la méthode de cette classe
			// qui est appelée par le mécanisme de liaison tardive
			// => [B(1, 2) ; 1.5]
		System.out.println((PointPondere) pointB); // (3) pointB est vu comme un PointPondere : c'est donc la méthode toString()
			// de cette classe qui est appelée directement
			// => [B(1, 2) ; 1.5]
		System.out.println(pointPondereB); // idem (3)
			// => [B(1, 2) ; 1.5]
		System.out.println((Point) pointPondereB); // idem (2)
			// => [B(1, 2) ; 1.5]
		//System.out.println("Poids de B : " + pointB.getPoids());
		System.out.println("Poids de B : " + ((PointPondere) pointB).getPoids()); 
			// pas possible : cannot find symbol getPoids() class Point
			// on ne peut y accéder quand B est vu comme un simple point => ((PointPondere) pointB).getPoids()
			// => Poids de B : 1.5
		System.out.println("Poids de B : " + pointPondereB.getPoids());	// OK
			// => Poids de B : 1.5
		
		/* --------------------------------------------------------------------------------*/
		System.out.println();
		pointB = pointA;
		System.out.println("pointA -> " + pointA +
				"  / pointB -> " + pointB);
		System.out.println("pointA == pointB -> " + (pointA == pointB));
		System.out.println("pointA.equals(pointB) -> " + (pointA.equals(pointB)));
		// [java] pointA -> A(0, 0)  / pointB -> A(0, 0)
		// [java] pointA == pointB -> true
		// [java] pointA.equals(pointB) -> true
		
		System.out.println();
		pointB = new Point("A", 0, 0);
		System.out.println("pointA -> " + pointA +
				"  / pointB -> " + pointB);
		System.out.println("pointA == pointB -> " + (pointA == pointB));
		System.out.println("pointA.equals(pointB) -> " + (pointA.equals(pointB)));
		// [java] pointA -> A(0, 0)  / pointB -> A(0, 0)
		// [java] pointA == pointB -> false
		// [java] pointA.equals(pointB) -> true
     
		System.out.println();
		pointPondereA = new PointPondere("B", 1, 2, (float) 4.5);
		System.out.println("pointPondereA -> " + pointPondereA +
				"  / pointPondereB -> " + pointPondereB);
		System.out.println("pointPondereA.equals(pointPondereB) -> "
				+ (pointPondereA.equals(pointPondereB)));
		// [java] pointPondereA -> [B(1, 2) ; 4.5]  / pointPondereB -> [B(1, 2) ; 1.5]
		// [java] pointPondereA.equals(pointPondereB) -> false
     
		System.out.println();
		pointB = pointPondereB;
		System.out.println("pointPondereA -> " + pointPondereA +
				"  / pointB -> " + pointPondereB);
		System.out.println("pointPondereA.equals(pointB) -> " 
				+ (pointPondereA.equals(pointB)));
		System.out.println("pointB.equals(pointPondereA) -> "
				+ (pointB.equals(pointPondereA)));
		// [java] pointPondereA -> [B(1, 2) ; 4.5]  / pointB -> [B(1, 2) ; 1.5]
		// [java] pointPondereA.equals(pointB) -> false
		// [java] pointB.equals(pointPondereA) -> false
     
		System.out.println();
		pointB = new Point("B", 1, 2);
		System.out.println("pointPondereA -> " + pointPondereA +
				"  / pointB -> " + pointB);
		System.out.println("pointPondereA.equals(pointB) -> "
				+ (pointPondereA.equals(pointB)));
		System.out.println("pointB.equals(pointPondereA) -> "
				+ (pointB.equals(pointPondereA)));
		// [java] pointPondereA -> [B(1, 2) ; 4.5]  / pointB -> B(1, 2)
		// [java] pointPondereA.equals(pointB) -> false
		// [java] pointB.equals(pointPondereA) -> true		
	}
}
