@Override
public boolean equals(Object obj) {
- if (!(obj instanceof CustomProperties)) {
- return false;
- }
- return props.equals(((CustomProperties)obj).props);
+ return obj instanceof CustomProperties && props.equals(((CustomProperties) obj).props);
}
@Override
- public void putAll(Map<? extends String, ? extends Object> m) {
- for (Map.Entry<? extends String, ? extends Object> me : m.entrySet()) {
+ public void putAll(Map<? extends String, ?> m) {
+ for (Map.Entry<? extends String, ?> me : m.entrySet()) {
put(me.getKey(), me.getValue());
}
}
* <li>Otherwise find the highest ID and use its value plus one.
* </ul>
*
- * @param customProperty
+ * @param customProperty The {@link CustomProperty} to add.
* @return If there was already a property with the same name, the old property
* @throws ClassCastException
*/
* #getPropertyIntValue} or {@link #getProperty} tried to access
* was available or not. This information might be important for
* callers of {@link #getPropertyIntValue} since the latter
- * returns 0 if the property does not exist. Using {@link
- * #wasNull}, the caller can distiguish this case from a
+ * returns 0 if the property does not exist. Using wasNull,
+ * the caller can distinguish this case from a
* property's real value of 0.
*
* @return {@code true} if the last call to {@link
*/
protected boolean getPropertyBooleanValue(final int id) {
final Boolean b = (Boolean) getProperty(id);
- if (b == null) {
- return false;
- }
- return b.booleanValue();
+ return b != null && b.booleanValue();
}
/**
* properties) and the properties themselves.
*
* @return the section's length in bytes.
- * @throws WritingNotSupportedException
- * @throws IOException
+ * @throws WritingNotSupportedException If the document is opened read-only.
+ * @throws IOException If an error happens while writing.
*/
private int calcSize() throws WritingNotSupportedException, IOException {
sectionBytes.reset();
* property. */
position += p.write(propertyStream, codepage);
} else {
- if (codepage == -1) {
- throw new IllegalPropertySetDataException("Codepage (property 1) is undefined.");
- }
position += writeDictionary(propertyStream, codepage);
}
}
* Writes the section's dictionary.
*
* @param out The output stream to write to.
- * @param dictionary The dictionary.
* @param codepage The codepage to be used to write the dictionary items.
* @return The number of bytes written
* @exception IOException if an I/O exception occurs.
long hashCode = 0;
hashCode += getFormatID().hashCode();
final Property[] pa = getProperties();
- for (int i = 0; i < pa.length; i++) {
- hashCode += pa[i].hashCode();
+ for (Property aPa : pa) {
+ hashCode += aPa.hashCode();
}
return (int) (hashCode & 0x0ffffffffL);
}
}
public String toString(PropertyIDMap idMap) {
- final StringBuffer b = new StringBuffer();
+ final StringBuilder b = new StringBuilder();
final Property[] pa = getProperties();
b.append("\n\n\n");
b.append(getClass().getName());
/**
* Lazy load validations by sheet, since reading the CT* types is expensive
- * @param sheet
+ *
+ * @param sheet The {@link Sheet} to load validations for.
* @return The {@link DataValidation}s for the sheet
*/
private List<? extends DataValidation> getValidations(Sheet sheet) {
/**
* Note that this assumes the cell cached value is up to date and in sync with data edits
- * @param cell
- * @param type
+ *
+ * @param cell The {@link Cell} to check.
+ * @param type The {@link CellType} to check for.
* @return true if the cell or cached cell formula result type match the given type
*/
public static boolean isType(Cell cell, CellType type) {
if (super.isValidValue(cell, context)) {
// we know it is a number in the proper range, now check if it is an int
final double value = cell.getNumericCellValue(); // can't get here without a valid numeric value
- return Double.valueOf(value).compareTo(Double.valueOf((int) value)) == 0;
+ return Double.compare(value, (int) value) == 0;
}
return false;
}
/**
* Note the formula result must either be a boolean result, or anything not in error.
* If boolean, value must be true to pass, anything else valid is also passing, errors fail.
- * @see org.apache.poi.ss.formula.DataValidationEvaluator.ValidationEnum#isValidValue(org.apache.poi.ss.usermodel.Cell, org.apache.poi.ss.usermodel.DataValidationConstraint, org.apache.poi.ss.formula.WorkbookEvaluator)
+ * @see org.apache.poi.ss.formula.DataValidationEvaluator.ValidationEnum#isValidValue(Cell, DataValidationContext)
*/
public boolean isValidValue(Cell cell, DataValidationContext context) {
// unwrapped single value
* Evaluate a numeric formula value as either a constant or numeric expression.
* Note that Excel treats validations with constraint formulas that evaluate to null as valid,
* but evaluations in error or non-numeric are marked invalid.
- * @param formula
- * @param context
+ *
+ * @param formula The text of the formula or a numeric value
+ * @param context The {@link DataValidationContext} which is used for evaluation
* @return numeric value or null if not defined or the formula evaluates to an empty/missing cell.
* @throws NumberFormatException if the formula is non-numeric when it should be
*/
private final CellReference target;
/**
- *
- * @param dv
- * @param dve
- * @param region
- * @param target
+ * Populate the context with the necessary values.
*/
public DataValidationContext(DataValidation dv, DataValidationEvaluator dve, CellRangeAddressBase region, CellReference target) {
this.dv = dv;
{
private int[] _array;
private int _limit;
- private int fillval;
private static final int _default_size = 128;
/**
public IntList(final int initialCapacity)
{
- this(initialCapacity,0);
+ _array = new int[ initialCapacity ];
+ _limit = 0;
}
}
/**
- * create an IntList with a predefined initial size
- *
- * @param initialCapacity the size for the internal array
- */
-
- public IntList(final int initialCapacity, int fillvalue)
- {
- _array = new int[ initialCapacity ];
- if (fillval != 0) {
- fillval = fillvalue;
- fillArray(fillval, _array, 0);
- }
- _limit = 0;
- }
-
- private void fillArray(int val, int[] array, int index) {
- for (int k = index; k < array.length; k++) {
- array[k] = val;
- }
- }
-
- /**
- * add the specfied value at the specified index
+ * add the specified value at the specified index
*
* @param index the index where the new value is to be added
* @param value the new value
: new_size;
int[] new_array = new int[ size ];
- if (fillval != 0) {
- fillArray(fillval, new_array, _array.length);
- }
-
System.arraycopy(_array, 0, new_array, 0, _limit);
_array = new_array;
}
-} // end public class IntList
-
+}
*/
public final class FileHelper {
- /**
- * Get the directory part of the specified file path.
- *
- * @param f
- * File to process.
- * @return The directory path from the specified
- */
- public static File getDirectory(File f) {
- if (f != null) {
- String path = f.getPath();
+ /**
+ * Get the directory part of the specified file path.
+ *
+ * @param f
+ * File to process.
+ * @return The directory path from the specified
+ */
+ public static File getDirectory(File f) {
+ if (f != null) {
+ String path = f.getPath();
int num2 = path.length();
- while (--num2 >= 0) {
- char ch1 = path.charAt(num2);
- if (ch1 == File.separatorChar) {
- return new File(path.substring(0, num2));
- }
- }
- }
- return null;
- }
+ while (--num2 >= 0) {
+ char ch1 = path.charAt(num2);
+ if (ch1 == File.separatorChar) {
+ return new File(path.substring(0, num2));
+ }
+ }
+ }
+ return null;
+ }
- /**
- * Copy a file.
- *
- * @param in
- * The source file.
- * @param out
- * The target location.
- * @throws IOException
- * If an I/O error occur.
- */
- public static void copyFile(File in, File out) throws IOException {
- FileInputStream fis = new FileInputStream(in);
- FileOutputStream fos = new FileOutputStream(out);
- FileChannel sourceChannel = fis.getChannel();
- FileChannel destinationChannel = fos.getChannel();
- sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
- sourceChannel.close();
- destinationChannel.close();
- fos.close();
- fis.close();
- }
-
- /**
- * Get file name from the specified File object.
- */
- public static String getFilename(File file) {
- if (file != null) {
- String path = file.getPath();
- int len = path.length();
- int num2 = len;
- while (--num2 >= 0) {
- char ch1 = path.charAt(num2);
- if (ch1 == File.separatorChar)
- return path.substring(num2 + 1, len);
- }
- }
- return "";
- }
+ /**
+ * Copy a file.
+ *
+ * @param in
+ * The source file.
+ * @param out
+ * The target location.
+ * @throws IOException
+ * If an I/O error occur.
+ */
+ public static void copyFile(File in, File out) throws IOException {
+ try (FileInputStream fis = new FileInputStream(in);
+ FileOutputStream fos = new FileOutputStream(out);
+ FileChannel sourceChannel = fis.getChannel();
+ FileChannel destinationChannel = fos.getChannel()) {
+
+ sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
+ sourceChannel.close();
+ }
+ }
+ /**
+ * Get file name from the specified File object.
+ */
+ public static String getFilename(File file) {
+ if (file != null) {
+ String path = file.getPath();
+ int len = path.length();
+ int num2 = len;
+ while (--num2 >= 0) {
+ char ch1 = path.charAt(num2);
+ if (ch1 == File.separatorChar)
+ return path.substring(num2 + 1, len);
+ }
+ }
+ return "";
+ }
}
package org.apache.poi.hwpf.model;
-import static org.apache.poi.POITestCase.assertReflectEquals;
-
import org.apache.poi.hwpf.HWPFDocFixture;
import org.apache.poi.hwpf.model.types.DOPAbstractType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import static org.apache.poi.POITestCase.assertReflectEquals;
+
// TODO: Add DocumentProperties#equals ???
public final class TestDocumentProperties {
private DocumentProperties _documentProperties;
private HWPFDocFixture _hWPFDocFixture;
- @Test
- public void testReadWrite() throws Exception {
- int size = DOPAbstractType.getSize();
- byte[] buf = new byte[size];
- _documentProperties.serialize(buf, 0);
- DocumentProperties newDocProperties = new DocumentProperties(buf, 0, size);
-
- assertReflectEquals(_documentProperties, newDocProperties);
- }
-
@Before
public void setUp() throws Exception {
- /** TODO verify the constructors*/
+ // TODO verify the constructors
_hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
_hWPFDocFixture.setUp();
_documentProperties = new DocumentProperties(_hWPFDocFixture._tableStream, _hWPFDocFixture._fib.getFcDop(), _hWPFDocFixture._fib.getLcbDop());
_hWPFDocFixture.tearDown();
_hWPFDocFixture = null;
}
+
+ @Test
+ public void testReadWrite() throws Exception {
+ int size = DOPAbstractType.getSize();
+ byte[] buf = new byte[size];
+ _documentProperties.serialize(buf, 0);
+ DocumentProperties newDocProperties = new DocumentProperties(buf, 0, size);
+
+ assertReflectEquals(_documentProperties, newDocProperties);
+ }
}
package org.apache.poi.util;
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* Class to test IntList
*
* @author Marc Johnson
*/
-public final class TestIntList extends TestCase {
-
+public final class TestIntList {
+ @Test
public void testConstructors() {
IntList list = new IntList();
assertTrue(list3.isEmpty());
}
+ @Test
public void testAdd() {
IntList list = new IntList();
int[] testArray =
}
}
+ @Test
public void testAddAll() {
IntList list = new IntList();
assertEquals(list.get(4), empty.get(14));
}
+ @Test
+ public void testAddAllGrow() {
+ IntList list = new IntList(0);
+ IntList addList = new IntList(0);
+ addList.add(1);
+ addList.add(2);
+
+ assertTrue(list.addAll(0, addList));
+ }
+
+ @Test
public void testClear() {
IntList list = new IntList();
}
}
+ @Test
public void testContains() {
IntList list = new IntList();
}
else
{
- assertTrue(!list.contains(j));
+ assertFalse(list.contains(j));
}
}
}
+ @Test
public void testContainsAll() {
IntList list = new IntList();
assertTrue(list.containsAll(list2));
list2.add(10);
assertTrue(list2.containsAll(list));
- assertTrue(!list.containsAll(list2));
+ assertFalse(list.containsAll(list2));
list.add(11);
- assertTrue(!list2.containsAll(list));
- assertTrue(!list.containsAll(list2));
+ assertFalse(list2.containsAll(list));
+ assertFalse(list.containsAll(list2));
}
+ @Test
public void testEquals() {
IntList list = new IntList();
assertEquals(list, list);
//noinspection ObjectEqualsNull
- assertTrue(!list.equals(null));
+ assertFalse(list.equals(null));
IntList list2 = new IntList(200);
assertEquals(list, list2);
list.add(1);
list2.add(1);
list2.add(0);
- assertTrue(!list.equals(list2));
+ assertFalse(list.equals(list2));
list2.removeValue(1);
list2.add(1);
assertEquals(list, list2);
assertEquals(list2, list);
+ assertEquals(list.hashCode(), list2.hashCode());
list2.add(2);
- assertTrue(!list.equals(list2));
- assertTrue(!list2.equals(list));
+ assertFalse(list.equals(list2));
+ assertFalse(list2.equals(list));
}
+ @Test
public void testGet() {
IntList list = new IntList();
}
}
+ @Test
public void testIndexOf() {
IntList list = new IntList();
}
}
+ @Test
public void testIsEmpty() {
IntList list1 = new IntList();
IntList list2 = new IntList(1000);
list1.add(1);
list2.add(2);
list3 = new IntList(list2);
- assertTrue(!list1.isEmpty());
- assertTrue(!list2.isEmpty());
- assertTrue(!list3.isEmpty());
+ assertFalse(list1.isEmpty());
+ assertFalse(list2.isEmpty());
+ assertFalse(list3.isEmpty());
list1.clear();
list2.remove(0);
list3.removeValue(2);
assertTrue(list3.isEmpty());
}
+ @Test
public void testLastIndexOf() {
IntList list = new IntList();
}
}
+ @Test
public void testRemove() {
IntList list = new IntList();
}
}
+ @Test
public void testRemoveValue() {
IntList list = new IntList();
assertTrue(list.removeValue(j));
assertTrue(list.removeValue(j));
}
- assertTrue(!list.removeValue(j));
+ assertFalse(list.removeValue(j));
}
}
+ @Test
public void testRemoveAll() {
IntList list = new IntList();
listOdd.add(j);
}
}
- list.removeAll(listEven);
+
+ assertTrue(list.removeAll(listEven));
assertEquals(list, listOdd);
- list.removeAll(listOdd);
+
+ assertTrue(list.removeAll(listOdd));
assertTrue(list.isEmpty());
- listCopy.removeAll(listOdd);
+
+ assertTrue(listCopy.removeAll(listOdd));
assertEquals(listCopy, listEven);
- listCopy.removeAll(listEven);
+
+ assertTrue(listCopy.removeAll(listEven));
assertTrue(listCopy.isEmpty());
+
+ assertFalse(list.removeAll(listEven));
+ assertFalse(list.removeAll(listOdd));
+ assertFalse(listCopy.removeAll(listEven));
+ assertFalse(listCopy.removeAll(listEven));
}
+ @Test
public void testRetainAll() {
IntList list = new IntList();
listOdd.add(j);
}
}
- list.retainAll(listOdd);
+ assertTrue(list.retainAll(listOdd));
assertEquals(list, listOdd);
- list.retainAll(listEven);
+
+ assertTrue(list.retainAll(listEven));
assertTrue(list.isEmpty());
- listCopy.retainAll(listEven);
+
+ assertTrue(listCopy.retainAll(listEven));
assertEquals(listCopy, listEven);
- listCopy.retainAll(listOdd);
+
+ assertTrue(listCopy.retainAll(listOdd));
assertTrue(listCopy.isEmpty());
+
+ assertFalse(list.retainAll(listOdd));
+ assertFalse(list.retainAll(listEven));
+ assertFalse(listCopy.retainAll(listEven));
+ assertFalse(listCopy.retainAll(listOdd));
}
+ @Test
public void testSet() {
IntList list = new IntList();
}
}
+ @Test
public void testSize() {
IntList list = new IntList();
}
}
+ @Test
public void testToArray() {
IntList list = new IntList();