poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r619001 - in /poi/trunk/src: documentation/content/xdocs/ java/org/apache/poi/hssf/record/ java/org/apache/poi/hssf/usermodel/ testcases/org/apache/poi/hssf/usermodel/
Date Wed, 06 Feb 2008 14:35:27 GMT
Author: nick
Date: Wed Feb  6 06:35:05 2008
New Revision: 619001

URL: http://svn.apache.org/viewvc?rev=619001&view=rev
Log:
Implement hashCode and equals for HSSFFont and HSSFCellStyle

Modified:
    poi/trunk/src/documentation/content/xdocs/changes.xml
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java
    poi/trunk/src/java/org/apache/poi/hssf/record/FontRecord.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java

Modified: poi/trunk/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/changes.xml?rev=619001&r1=619000&r2=619001&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Wed Feb  6 06:35:05 2008
@@ -36,6 +36,7 @@
 
 		<!-- Don't forget to update status.xml too! -->
         <release version="3.1-beta1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="add">Implement hashCode() and equals(obj)
on HSSFFont and HSSFCellStyle</action>
            <action dev="POI-DEVELOPERS" type="fix">44345 - Implement CountA, CountIf,
Index, Rows and Columns functions</action>
            <action dev="POI-DEVELOPERS" type="fix">44336 - Properly escape sheet names
as required when figuring out the text of formulas</action>
            <action dev="POI-DEVELOPERS" type="add">44326 - Improvements to how SystemOutLogger
and CommonsLogger log messages with exceptions, and avoid an infinite loop with certain log
messages with exceptions</action>

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=619001&r1=619000&r2=619001&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Wed Feb  6 06:35:05 2008
@@ -33,6 +33,7 @@
 	<!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.1-beta1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="add">Implement hashCode() and equals(obj)
on HSSFFont and HSSFCellStyle</action>
            <action dev="POI-DEVELOPERS" type="fix">44345 - Implement CountA, CountIf,
Index, Rows and Columns functions</action>
            <action dev="POI-DEVELOPERS" type="fix">44336 - Properly escape sheet names
as required when figuring out the text of formulas</action>
            <action dev="POI-DEVELOPERS" type="add">44326 - Improvements to how SystemOutLogger
and CommonsLogger log messages with exceptions, and avoid an infinite loop with certain log
messages with exceptions</action>

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java?rev=619001&r1=619000&r2=619001&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java Wed Feb  6 06:35:05
2008
@@ -1814,4 +1814,56 @@
     {
         return sid;
     }
+
+	public int hashCode() {
+		final int prime = 31;
+		int result = 1;
+		result = prime * result + field_1_font_index;
+		result = prime * result + field_2_format_index;
+		result = prime * result + field_3_cell_options;
+		result = prime * result + field_4_alignment_options;
+		result = prime * result + field_5_indention_options;
+		result = prime * result + field_6_border_options;
+		result = prime * result + field_7_palette_options;
+		result = prime * result + field_8_adtl_palette_options;
+		result = prime * result + field_9_fill_palette_options;
+		return result;
+	}
+
+	/**
+	 * Will consider two different records with the same
+	 *  contents as equals, as the various indexes
+	 *  that matter are embedded in the records
+	 */
+	public boolean equals(Object obj) {
+		if (this == obj)
+			return true;
+		if (obj == null)
+			return false;
+		if (obj instanceof ExtendedFormatRecord) {
+			final ExtendedFormatRecord other = (ExtendedFormatRecord) obj;
+			if (field_1_font_index != other.field_1_font_index)
+				return false;
+			if (field_2_format_index != other.field_2_format_index)
+				return false;
+			if (field_3_cell_options != other.field_3_cell_options)
+				return false;
+			if (field_4_alignment_options != other.field_4_alignment_options)
+				return false;
+			if (field_5_indention_options != other.field_5_indention_options)
+				return false;
+			if (field_6_border_options != other.field_6_border_options)
+				return false;
+			if (field_7_palette_options != other.field_7_palette_options)
+				return false;
+			if (field_8_adtl_palette_options != other.field_8_adtl_palette_options)
+				return false;
+			if (field_9_fill_palette_options != other.field_9_fill_palette_options)
+				return false;
+			return true;
+		}
+		return false;
+	}
+    
+    
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/FontRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/FontRecord.java?rev=619001&r1=619000&r2=619001&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/FontRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/FontRecord.java Wed Feb  6 06:35:05 2008
@@ -538,4 +538,37 @@
     {
         return sid;
     }
+
+	public int hashCode() {
+		final int prime = 31;
+		int result = 1;
+		result = prime
+				* result
+				+ ((field_11_font_name == null) ? 0 : field_11_font_name
+						.hashCode());
+		result = prime * result + field_1_font_height;
+		result = prime * result + field_2_attributes;
+		result = prime * result + field_3_color_palette_index;
+		result = prime * result + field_4_bold_weight;
+		result = prime * result + field_5_super_sub_script;
+		result = prime * result + field_6_underline;
+		result = prime * result + field_7_family;
+		result = prime * result + field_8_charset;
+		result = prime * result + field_9_zero;
+		result = prime * result + field_10_font_name_len;
+		return result;
+	}
+
+	/**
+	 * Only returns two for the same exact object -
+	 *  creating a second FontRecord with the same
+	 *  properties won't be considered equal, as 
+	 *  the record's position in the record stream
+	 *  matters.
+	 */
+	public boolean equals(Object obj) {
+		if (this == obj)
+			return true;
+		return false;
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java?rev=619001&r1=619000&r2=619001&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java Wed Feb  6 06:35:05
2008
@@ -20,7 +20,6 @@
 
 import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.ExtendedFormatRecord;
-import org.apache.poi.hssf.record.FormatRecord;
 import org.apache.poi.hssf.util.*;
 
 /**
@@ -913,4 +912,29 @@
     {
         return format.getFillForeground();
     }
+
+	public int hashCode() {
+		final int prime = 31;
+		int result = 1;
+		result = prime * result + ((format == null) ? 0 : format.hashCode());
+		result = prime * result + index;
+		return result;
+	}
+
+	public boolean equals(Object obj) {
+		if (this == obj) return true;
+		if (obj == null) return false;
+		if (obj instanceof HSSFCellStyle) {
+			final HSSFCellStyle other = (HSSFCellStyle) obj;
+			if (format == null) {
+				if (other.format != null)
+					return false;
+			} else if (!format.equals(other.format))
+				return false;
+			if (index != other.index)
+				return false;
+			return true;
+		}
+		return false;
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java?rev=619001&r1=619000&r2=619001&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java Wed Feb  6 06:35:05 2008
@@ -399,5 +399,28 @@
                 "}";
     }
 
+	public int hashCode() {
+		final int prime = 31;
+		int result = 1;
+		result = prime * result + ((font == null) ? 0 : font.hashCode());
+		result = prime * result + index;
+		return result;
+	}
 
+	public boolean equals(Object obj) {
+		if (this == obj) return true;
+		if (obj == null) return false;
+		if (obj instanceof HSSFFont) {
+			final HSSFFont other = (HSSFFont) obj;
+			if (font == null) {
+				if (other.font != null)
+					return false;
+			} else if (!font.equals(other.font))
+				return false;
+			if (index != other.index)
+				return false;
+			return true;
+		}
+		return false;
+	}
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java?rev=619001&r1=619000&r2=619001&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java Wed Feb  6 06:35:05
2008
@@ -137,6 +137,35 @@
         assertEquals("FIRST ROW ", 0, s.getFirstRowNum());
 
     }
+    
+    public void testHashEquals() {
+        HSSFWorkbook     wb   = new HSSFWorkbook();
+        HSSFSheet        s    = wb.createSheet();
+        HSSFCellStyle    cs1  = wb.createCellStyle();
+        HSSFCellStyle    cs2  = wb.createCellStyle();
+        HSSFRow row = s.createRow((short)0);
+        HSSFCell cell1 = row.createCell((short)1);
+        HSSFCell cell2 = row.createCell((short)2);
+        
+        cs1.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
+        cs2.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/dd/yy"));
+        
+        cell1.setCellStyle(cs1);
+        cell1.setCellValue(new Date());
+        
+        cell2.setCellStyle(cs2);
+        cell2.setCellValue(new Date());
+        
+        assertEquals(cs1.hashCode(), cs1.hashCode());
+        assertEquals(cs2.hashCode(), cs2.hashCode());
+        assertTrue(cs1.equals(cs1));
+        assertTrue(cs2.equals(cs2));
+        
+        // Change cs1, hash will alter
+        int hash1 = cs1.hashCode();
+        cs1.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/dd/yy"));
+        assertFalse(hash1 == cs1.hashCode());
+    }
 
     /**
      * TEST NAME:  Test Write Sheet Style <P>



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message