Mega Code Archive

 
Categories / Java / 2D Graphics GUI
 

Tests two polygons for equality If both are null this method returns true

import java.awt.Polygon; import java.util.Arrays; public class Main {   /**    * Tests two polygons for equality.  If both are <code>null</code> this    * method returns <code>true</code>.    *    * @param p1  polygon 1 (<code>null</code> permitted).    * @param p2  polygon 2 (<code>null</code> permitted).    *    * @return A boolean.    */   public static boolean equal(final Polygon p1, final Polygon p2) {       if (p1 == null) {           return (p2 == null);       }       if (p2 == null) {           return false;       }       if (p1.npoints != p2.npoints) {           return false;       }       if (!Arrays.equals(p1.xpoints, p2.xpoints)) {           return false;       }       if (!Arrays.equals(p1.ypoints, p2.ypoints)) {           return false;       }       return true;   } }