You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2022/03/27 09:26:34 UTC
svn commit: r1899240 - in /poi/trunk/poi/src: main/java/org/apache/poi/ss/util/PaneInformation.java test/java/org/apache/poi/ss/util/TestPaneInformation.java
Author: fanningpj
Date: Sun Mar 27 09:26:34 2022
New Revision: 1899240
URL: http://svn.apache.org/viewvc?rev=1899240&view=rev
Log:
[github-314] Add equals and hashcode to PaneInformation. Thanks to Daniel Shuy. This closes #314
Added:
poi/trunk/poi/src/test/java/org/apache/poi/ss/util/TestPaneInformation.java (with props)
Modified:
poi/trunk/poi/src/main/java/org/apache/poi/ss/util/PaneInformation.java
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/util/PaneInformation.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/util/PaneInformation.java?rev=1899240&r1=1899239&r2=1899240&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/util/PaneInformation.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/util/PaneInformation.java Sun Mar 27 09:26:34 2022
@@ -17,6 +17,8 @@
package org.apache.poi.ss.util;
+import java.util.Objects;
+
/**
* Holds information regarding a split plane or freeze plane for a sheet.
*
@@ -31,14 +33,14 @@ public class PaneInformation
public static final byte PANE_LOWER_LEFT = (byte)2;
/** Constant for active pane being the upper left*/
public static final byte PANE_UPPER_LEFT = (byte)3;
-
+
private final short x;
private final short y;
private final short topRow;
private final short leftColumn;
private final byte activePane;
private final boolean frozen;
-
+
public PaneInformation(short x, short y, short top, short left, byte active, boolean frozen) {
this.x = x;
this.y = y;
@@ -56,9 +58,9 @@ public class PaneInformation
* or for a split plane the position of the split in 1/20th of a point.
*/
public short getVerticalSplitPosition() {
- return x;
+ return x;
}
-
+
/**
* Returns the horizontal position of the split.
* @return 0 if there is no horizontal spilt,
@@ -66,25 +68,25 @@ public class PaneInformation
* or for a split plane the position of the split in 1/20th of a point.
*/
public short getHorizontalSplitPosition() {
- return y;
+ return y;
}
-
+
/**
* For a horizontal split returns the top row in the BOTTOM pane.
* @return 0 if there is no horizontal split, or the top row of the bottom pane.
*/
public short getHorizontalSplitTopRow() {
- return topRow;
+ return topRow;
}
-
+
/**
* For a vertical split returns the left column in the RIGHT pane.
* @return 0 if there is no vertical split, or the left column in the RIGHT pane.
*/
public short getVerticalSplitLeftColumn() {
- return leftColumn;
+ return leftColumn;
}
-
+
/**
* Returns the active pane
* @see #PANE_LOWER_RIGHT
@@ -94,12 +96,38 @@ public class PaneInformation
* @return the active pane.
*/
public byte getActivePane() {
- return activePane;
+ return activePane;
}
-
+
/** Returns true if this is a Freeze pane, false if it is a split pane.
*/
public boolean isFreezePane() {
return frozen;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof PaneInformation)) return false;
+
+ PaneInformation that = (PaneInformation) o;
+
+ if (x != that.x) return false;
+ if (y != that.y) return false;
+ if (topRow != that.topRow) return false;
+ if (leftColumn != that.leftColumn) return false;
+ if (activePane != that.activePane) return false;
+ return frozen == that.frozen;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(
+ x,
+ y,
+ topRow,
+ leftColumn,
+ activePane,
+ frozen);
+ }
}
Added: poi/trunk/poi/src/test/java/org/apache/poi/ss/util/TestPaneInformation.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/util/TestPaneInformation.java?rev=1899240&view=auto
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/ss/util/TestPaneInformation.java (added)
+++ poi/trunk/poi/src/test/java/org/apache/poi/ss/util/TestPaneInformation.java Sun Mar 27 09:26:34 2022
@@ -0,0 +1,68 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.util;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+import org.junit.jupiter.api.Test;
+
+final class TestPaneInformation {
+ @Test
+ void testEquals() {
+ PaneInformation pi1 = new PaneInformation((short) 1, (short) 2, (short) 3, (short) 4, (byte) 5, true);
+ PaneInformation p12 = new PaneInformation((short) 1, (short) 2, (short) 3, (short) 4, (byte) 5, true);
+ assertEquals(pi1, p12);
+ assertEquals(pi1.hashCode(), p12.hashCode());
+ }
+
+ @Test
+ void testNotEquals() {
+ PaneInformation pi1 = new PaneInformation((short) 1, (short) 1, (short) 1, (short) 1, (byte) 1, true);
+ PaneInformation pi2 = new PaneInformation((short) 1, (short) 1, (short) 1, (short) 1, (byte) 1, false);
+ PaneInformation pi3 = new PaneInformation((short) 1, (short) 1, (short) 1, (short) 1, (byte) 2, true);
+ PaneInformation pi4 = new PaneInformation((short) 1, (short) 1, (short) 1, (short) 2, (byte) 1, true);
+ PaneInformation pi5 = new PaneInformation((short) 1, (short) 1, (short) 1, (short) 2, (byte) 1, false);
+ PaneInformation pi6 = new PaneInformation((short) 1, (short) 1, (short) 2, (short) 1, (byte) 1, true);
+ PaneInformation pi7 = new PaneInformation((short) 1, (short) 1, (short) 2, (short) 1, (byte) 1, false);
+ PaneInformation pi8 = new PaneInformation((short) 1, (short) 2, (short) 1, (short) 1, (byte) 1, true);
+ PaneInformation pi9 = new PaneInformation((short) 1, (short) 2, (short) 1, (short) 1, (byte) 1, false);
+ PaneInformation pi10 = new PaneInformation((short) 2, (short) 1, (short) 1, (short) 1, (byte) 1, true);
+ PaneInformation pi11 = new PaneInformation((short) 2, (short) 1, (short) 1, (short) 1, (byte) 1, false);
+ assertNotEquals(pi1, pi2);
+ assertNotEquals(pi1, pi3);
+ assertNotEquals(pi1, pi4);
+ assertNotEquals(pi1, pi5);
+ assertNotEquals(pi1, pi6);
+ assertNotEquals(pi1, pi7);
+ assertNotEquals(pi1, pi8);
+ assertNotEquals(pi1, pi9);
+ assertNotEquals(pi1, pi10);
+ assertNotEquals(pi1, pi11);
+ assertNotEquals(pi1.hashCode(), pi2.hashCode());
+ assertNotEquals(pi1.hashCode(), pi3.hashCode());
+ assertNotEquals(pi1.hashCode(), pi4.hashCode());
+ assertNotEquals(pi1.hashCode(), pi5.hashCode());
+ assertNotEquals(pi1.hashCode(), pi6.hashCode());
+ assertNotEquals(pi1.hashCode(), pi7.hashCode());
+ assertNotEquals(pi1.hashCode(), pi8.hashCode());
+ assertNotEquals(pi1.hashCode(), pi9.hashCode());
+ assertNotEquals(pi1.hashCode(), pi10.hashCode());
+ assertNotEquals(pi1.hashCode(), pi11.hashCode());
+ }
+}
Propchange: poi/trunk/poi/src/test/java/org/apache/poi/ss/util/TestPaneInformation.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org