git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896305 13f79535-47bb-0310-9956-ffa450edef68tags/REL_5_2_0
return relationshipsByID.values().iterator(); | return relationshipsByID.values().iterator(); | ||||
} | } | ||||
/** | |||||
* Get this collection's spliterator. | |||||
* | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<PackageRelationship> spliterator() { | |||||
return relationshipsByID.values().spliterator(); | |||||
} | |||||
/** | /** | ||||
* Get an iterator of a collection with all relationship with the specified | * Get an iterator of a collection with all relationship with the specified | ||||
* type. | * type. |
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Optional; | import java.util.Optional; | ||||
import java.util.Spliterator; | |||||
import java.util.function.Function; | import java.util.function.Function; | ||||
import java.util.function.Predicate; | import java.util.function.Predicate; | ||||
* is the highest level text separation mechanism. | * is the highest level text separation mechanism. | ||||
*/ | */ | ||||
@Beta | @Beta | ||||
public class XDDFTextParagraph { | |||||
public class XDDFTextParagraph implements Iterable<XDDFTextRun> { | |||||
private XDDFTextBody _parent; | private XDDFTextBody _parent; | ||||
private XDDFParagraphProperties _properties; | private XDDFParagraphProperties _properties; | ||||
private final CTTextParagraph _p; | private final CTTextParagraph _p; | ||||
return _runs; | return _runs; | ||||
} | } | ||||
@Override | |||||
public Iterator<XDDFTextRun> iterator() { | public Iterator<XDDFTextRun> iterator() { | ||||
return _runs.iterator(); | return _runs.iterator(); | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<XDDFTextRun> spliterator() { | |||||
return _runs.spliterator(); | |||||
} | |||||
/** | /** | ||||
* Append a line break. | * Append a line break. | ||||
* | * |
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Optional; | import java.util.Optional; | ||||
import java.util.Spliterator; | |||||
import java.util.function.Function; | import java.util.function.Function; | ||||
import java.util.function.Predicate; | import java.util.function.Predicate; | ||||
return getTextParagraphs().iterator(); | return getTextParagraphs().iterator(); | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<XSLFTextParagraph> spliterator() { | |||||
return getTextParagraphs().spliterator(); | |||||
} | |||||
@Override | @Override | ||||
public String getText() { | public String getText() { | ||||
StringBuilder out = new StringBuilder(); | StringBuilder out = new StringBuilder(); |
package org.apache.poi.xssf.streaming; | package org.apache.poi.xssf.streaming; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.Spliterator; | |||||
import org.apache.poi.ss.usermodel.ClientAnchor; | import org.apache.poi.ss.usermodel.ClientAnchor; | ||||
import org.apache.poi.ss.usermodel.Comment; | import org.apache.poi.ss.usermodel.Comment; | ||||
public Iterator<XSSFShape> iterator() { | public Iterator<XSSFShape> iterator() { | ||||
return _drawing.getShapes().iterator(); | return _drawing.getShapes().iterator(); | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<XSSFShape> spliterator() { | |||||
return _drawing.getShapes().spliterator(); | |||||
} | |||||
} | } | ||||
import java.util.Map.Entry; | import java.util.Map.Entry; | ||||
import java.util.NoSuchElementException; | import java.util.NoSuchElementException; | ||||
import java.util.SortedMap; | import java.util.SortedMap; | ||||
import java.util.Spliterator; | |||||
import java.util.Spliterators; | |||||
import java.util.TreeMap; | import java.util.TreeMap; | ||||
import org.apache.poi.ss.SpreadsheetVersion; | import org.apache.poi.ss.SpreadsheetVersion; | ||||
return new CellIterator(); | return new CellIterator(); | ||||
} | } | ||||
public Spliterator<Cell> allCellsSpliterator() | |||||
{ | |||||
return Spliterators.spliterator(allCellsIterator(), getLastCellNum(), 0); | |||||
} | |||||
public boolean hasCustomHeight() | public boolean hasCustomHeight() | ||||
{ | { | ||||
return _height!=-1; | return _height!=-1; | ||||
this._collapsed = collapsed; | this._collapsed = collapsed; | ||||
} | } | ||||
//begin of interface implementation | //begin of interface implementation | ||||
/** | |||||
* {@inheritDoc} | |||||
*/ | |||||
@Override | |||||
public Iterator<Cell> iterator() | |||||
{ | |||||
return new FilledCellIterator(); | |||||
} | |||||
/** | /** | ||||
* Use this to create new cells within the row and return it. | * Use this to create new cells within the row and return it. | ||||
* <p> | * <p> | ||||
@Override | @Override | ||||
public Iterator<Cell> cellIterator() | public Iterator<Cell> cellIterator() | ||||
{ | { | ||||
return iterator(); | |||||
return new FilledCellIterator(); | |||||
} | |||||
/** | |||||
* Create a spliterator over the cells from [0, getLastCellNum()). | |||||
* Includes blank cells, excludes empty cells | |||||
* | |||||
* Returns a spliterator over all filled cells (created via Row.createCell()) | |||||
* Throws ConcurrentModificationException if cells are added, moved, or | |||||
* removed after the spliterator is created. | |||||
* | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
@SuppressWarnings("unchecked") | |||||
public Spliterator<Cell> spliterator() { | |||||
return (Spliterator<Cell>)(Spliterator<? extends Cell>) _cells.values().spliterator(); | |||||
} | } | ||||
/** | /** |
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.Set; | import java.util.Set; | ||||
import java.util.Spliterator; | |||||
import java.util.TreeMap; | import java.util.TreeMap; | ||||
import org.apache.poi.ss.SpreadsheetVersion; | import org.apache.poi.ss.SpreadsheetVersion; | ||||
} | } | ||||
//start of interface implementation | //start of interface implementation | ||||
@Override | |||||
public Iterator<Row> iterator() { | |||||
return rowIterator(); | |||||
} | |||||
/** | /** | ||||
* Create a new row within the sheet and return the high level representation | * Create a new row within the sheet and return the high level representation | ||||
* | * | ||||
return result; | return result; | ||||
} | } | ||||
/** | |||||
* Returns a spliterator of the physical rows | |||||
* | |||||
* @return a spliterator of the PHYSICAL rows. Meaning the 3rd element may not | |||||
* be the third row if say for instance the second row is undefined. | |||||
* | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
@SuppressWarnings("unchecked") | |||||
public Spliterator<Row> spliterator() { | |||||
return (Spliterator<Row>)(Spliterator<? extends Row>) _rows.values().spliterator(); | |||||
} | |||||
/** | /** | ||||
* Flag indicating whether the sheet displays Automatic Page Breaks. | * Flag indicating whether the sheet displays Automatic Page Breaks. | ||||
* | * |
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.NoSuchElementException; | import java.util.NoSuchElementException; | ||||
import java.util.Spliterator; | |||||
import org.apache.commons.compress.archivers.ArchiveOutputStream; | import org.apache.commons.compress.archivers.ArchiveOutputStream; | ||||
import org.apache.commons.compress.archivers.zip.Zip64Mode; | import org.apache.commons.compress.archivers.zip.Zip64Mode; | ||||
return new SheetIterator<>(); | return new SheetIterator<>(); | ||||
} | } | ||||
/** | |||||
* Returns a spliterator of the sheets in the workbook | |||||
* in sheet order. Includes hidden and very hidden sheets. | |||||
* | |||||
* @return a spliterator of the sheets. | |||||
* | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<Sheet> spliterator() { | |||||
return _wb.spliterator(); | |||||
} | |||||
protected final class SheetIterator<T extends Sheet> implements Iterator<T> { | protected final class SheetIterator<T extends Sheet> implements Iterator<T> { | ||||
final private Iterator<XSSFSheet> it; | final private Iterator<XSSFSheet> it; | ||||
@SuppressWarnings("unchecked") | @SuppressWarnings("unchecked") | ||||
} | } | ||||
} | } | ||||
/** | |||||
* Alias for {@link #sheetIterator()} to allow | |||||
* foreach loops | |||||
*/ | |||||
@Override | |||||
public Iterator<Sheet> iterator() { | |||||
return sheetIterator(); | |||||
} | |||||
/** | /** | ||||
* Get the Sheet object at the given index. | * Get the Sheet object at the given index. | ||||
* | * |
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Spliterator; | |||||
import javax.xml.namespace.QName; | import javax.xml.namespace.QName; | ||||
return getShapes().iterator(); | return getShapes().iterator(); | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<XSSFShape> spliterator() { | |||||
return getShapes().spliterator(); | |||||
} | |||||
/** | /** | ||||
* @return the sheet associated with the drawing | * @return the sheet associated with the drawing | ||||
*/ | */ |
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.Objects; | import java.util.Objects; | ||||
import java.util.Set; | import java.util.Set; | ||||
import java.util.Spliterator; | |||||
import java.util.TreeMap; | import java.util.TreeMap; | ||||
import org.apache.poi.ss.SpreadsheetVersion; | import org.apache.poi.ss.SpreadsheetVersion; | ||||
} | } | ||||
/** | /** | ||||
* Alias for {@link #cellIterator()} to allow foreach loops: | |||||
* <blockquote><pre> | |||||
* for(Cell cell : row){ | |||||
* ... | |||||
* } | |||||
* </pre></blockquote> | |||||
* Cell spliterator over the physically defined cells | |||||
* | * | ||||
* @return an iterator over cells in this row. | |||||
* @return a spliterator over cells in this row. | |||||
* | |||||
* @since POI 5.2.0 | |||||
*/ | */ | ||||
@Override | @Override | ||||
public Iterator<Cell> iterator() { | |||||
return cellIterator(); | |||||
@SuppressWarnings("unchecked") | |||||
public Spliterator<Cell> spliterator() { | |||||
return (Spliterator<Cell>)(Spliterator<? extends Cell>)_cells.values().spliterator(); | |||||
} | } | ||||
/** | /** |
package org.apache.poi.xssf.usermodel; | package org.apache.poi.xssf.usermodel; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.Spliterator; | |||||
import org.apache.poi.openxml4j.opc.PackageRelationship; | import org.apache.poi.openxml4j.opc.PackageRelationship; | ||||
import org.apache.poi.ss.usermodel.ShapeContainer; | import org.apache.poi.ss.usermodel.ShapeContainer; | ||||
return getDrawing().getShapes(this).iterator(); | return getDrawing().getShapes(this).iterator(); | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<XSSFShape> spliterator() { | |||||
return getDrawing().getShapes(this).spliterator(); | |||||
} | |||||
@Override | @Override | ||||
public String getShapeName() { | public String getShapeName() { | ||||
return ctGroup.getNvGrpSpPr().getCNvPr().getName(); | return ctGroup.getNvGrpSpPr().getCNvPr().getName(); |
} | } | ||||
/** | /** | ||||
* Alias for {@link #rowIterator()} to | |||||
* allow foreach loops | |||||
* @return a spliterator of the PHYSICAL rows. Meaning the 3rd element may not | |||||
* be the third row if say for instance the second row is undefined. | |||||
* Call getRowNum() on each row if you care which one it is. | |||||
* | |||||
* @since POI 5.2.0 | |||||
*/ | */ | ||||
@Override | @Override | ||||
public Iterator<Row> iterator() { | |||||
return rowIterator(); | |||||
@SuppressWarnings("unchecked") | |||||
public Spliterator<Row> spliterator() { | |||||
return (Spliterator<Row>)(Spliterator<? extends Row>) _rows.values().spliterator(); | |||||
} | } | ||||
/** | /** |
import java.util.List; | import java.util.List; | ||||
import java.util.Locale; | import java.util.Locale; | ||||
import java.util.Optional; | import java.util.Optional; | ||||
import java.util.Spliterator; | |||||
import java.util.function.Function; | import java.util.function.Function; | ||||
import java.util.function.Predicate; | import java.util.function.Predicate; | ||||
return _paragraphs.iterator(); | return _paragraphs.iterator(); | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<XSSFTextParagraph> spliterator() { | |||||
return _paragraphs.spliterator(); | |||||
} | |||||
/** | /** | ||||
* Returns the text from all paragraphs in the shape. Paragraphs are | * Returns the text from all paragraphs in the shape. Paragraphs are | ||||
* separated by new lines. | * separated by new lines. |
import java.util.Locale; | import java.util.Locale; | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.NoSuchElementException; | import java.util.NoSuchElementException; | ||||
import java.util.Spliterator; | |||||
import java.util.regex.Pattern; | import java.util.regex.Pattern; | ||||
import javax.xml.namespace.QName; | import javax.xml.namespace.QName; | ||||
return sheetIterator(); | return sheetIterator(); | ||||
} | } | ||||
/** | |||||
* Returns a spliterator of the sheets in the workbook | |||||
* in sheet order. Includes hidden and very hidden sheets. | |||||
* | |||||
* @return a spliterator of the sheets. | |||||
* | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
@SuppressWarnings("unchecked") | |||||
public Spliterator<Sheet> spliterator() { | |||||
return (Spliterator<Sheet>)(Spliterator<? extends Sheet>) sheets.spliterator(); | |||||
} | |||||
private final class SheetIterator<T extends Sheet> implements Iterator<T> { | private final class SheetIterator<T extends Sheet> implements Iterator<T> { | ||||
final private Iterator<T> it; | final private Iterator<T> it; | ||||
@SuppressWarnings("unchecked") | @SuppressWarnings("unchecked") |
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Spliterator; | |||||
import org.apache.poi.ooxml.POIXMLDocumentPart; | import org.apache.poi.ooxml.POIXMLDocumentPart; | ||||
import org.apache.poi.util.Internal; | import org.apache.poi.util.Internal; | ||||
return paragraphs.iterator(); | return paragraphs.iterator(); | ||||
} | } | ||||
/** | |||||
* Get a spliterator over the {@link XWPFParagraph}s in the footnote. | |||||
* @return Spliterator over the paragraph list. | |||||
* | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<XWPFParagraph> spliterator() { | |||||
return paragraphs.spliterator(); | |||||
} | |||||
/** | /** | ||||
* Get the list of {@link XWPFTable}s in the footnote. | * Get the list of {@link XWPFTable}s in the footnote. | ||||
* @return List of tables | * @return List of tables |
import java.util.LinkedList; | import java.util.LinkedList; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.Spliterator; | |||||
import javax.xml.namespace.QName; | import javax.xml.namespace.QName; | ||||
return bodyElements.iterator(); | return bodyElements.iterator(); | ||||
} | } | ||||
/** | |||||
* returns a Spliterator with paragraphs and tables | |||||
* | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
public Spliterator<IBodyElement> getBodyElementsSpliterator() { | |||||
return bodyElements.spliterator(); | |||||
} | |||||
@Override | @Override | ||||
public List<XWPFParagraph> getParagraphs() { | public List<XWPFParagraph> getParagraphs() { | ||||
return Collections.unmodifiableList(paragraphs); | return Collections.unmodifiableList(paragraphs); | ||||
return tables.iterator(); | return tables.iterator(); | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
public Spliterator<XWPFTable> getTablesSpliterator() { | |||||
return tables.spliterator(); | |||||
} | |||||
public Iterator<XWPFParagraph> getParagraphsIterator() { | public Iterator<XWPFParagraph> getParagraphsIterator() { | ||||
return paragraphs.iterator(); | return paragraphs.iterator(); | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
public Spliterator<XWPFParagraph> getParagraphsSpliterator() { | |||||
return paragraphs.spliterator(); | |||||
} | |||||
/** | /** | ||||
* Returns the paragraph that of position pos | * Returns the paragraph that of position pos | ||||
*/ | */ |
assertEquals(2, row0.getRowNum(), "Row 2 knows its row number"); | assertEquals(2, row0.getRowNum(), "Row 2 knows its row number"); | ||||
assertEquals(1, sheet.getRowNum(row1), "Sheet knows Row 1's row number"); | assertEquals(1, sheet.getRowNum(row1), "Sheet knows Row 1's row number"); | ||||
assertEquals(2, sheet.getRowNum(row0), "Sheet knows Row 2's row number"); | assertEquals(2, sheet.getRowNum(row0), "Sheet knows Row 2's row number"); | ||||
assertEquals(row1, sheet.iterator().next(), "Sheet row iteratation order should be ascending"); | |||||
assertEquals(row1, sheet.iterator().next(), "Sheet row iteration order should be ascending"); | |||||
sheet.spliterator().tryAdvance(row -> | |||||
assertEquals(row1, row, "Sheet row iteration order should be ascending")); | |||||
wb.close(); | wb.close(); | ||||
} | } |
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.Optional; | import java.util.Optional; | ||||
import java.util.Spliterator; | |||||
import java.util.function.Function; | import java.util.function.Function; | ||||
import java.util.function.Predicate; | import java.util.function.Predicate; | ||||
import java.util.function.Supplier; | import java.util.function.Supplier; | ||||
return getEscherRecords().iterator(); | return getEscherRecords().iterator(); | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<EscherRecord> spliterator() { | |||||
return getEscherRecords().spliterator(); | |||||
} | |||||
/** | /** | ||||
* Get access to the atoms inside Textboxes | * Get access to the atoms inside Textboxes | ||||
*/ | */ |
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Spliterator; | |||||
import org.apache.logging.log4j.LogManager; | import org.apache.logging.log4j.LogManager; | ||||
import org.apache.logging.log4j.Logger; | import org.apache.logging.log4j.Logger; | ||||
return getShapes().iterator(); | return getShapes().iterator(); | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<HSLFShape> spliterator() { | |||||
return getShapes().spliterator(); | |||||
} | |||||
@Override | @Override | ||||
public boolean removeShape(HSLFShape shape) { | public boolean removeShape(HSLFShape shape) { | ||||
// TODO: implement! | // TODO: implement! |
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Spliterator; | |||||
import org.apache.poi.ddf.EscherContainerRecord; | import org.apache.poi.ddf.EscherContainerRecord; | ||||
import org.apache.poi.ddf.EscherDgRecord; | import org.apache.poi.ddf.EscherDgRecord; | ||||
return getShapes().iterator(); | return getShapes().iterator(); | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<HSLFShape> spliterator() { | |||||
return getShapes().spliterator(); | |||||
} | |||||
/** | /** | ||||
* @return whether shapes on the master sheet should be shown. By default master graphics is turned off. | * @return whether shapes on the master sheet should be shown. By default master graphics is turned off. |
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Spliterator; | |||||
import java.util.function.Consumer; | import java.util.function.Consumer; | ||||
import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||
return _runs.iterator(); | return _runs.iterator(); | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<HSLFTextRun> spliterator() { | |||||
return _runs.spliterator(); | |||||
} | |||||
@Override | @Override | ||||
public Double getLeftMargin() { | public Double getLeftMargin() { | ||||
Integer val = null; | Integer val = null; |
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Spliterator; | |||||
import org.apache.logging.log4j.LogManager; | import org.apache.logging.log4j.LogManager; | ||||
import org.apache.logging.log4j.Logger; | import org.apache.logging.log4j.Logger; | ||||
return _paragraphs.iterator(); | return _paragraphs.iterator(); | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<HSLFTextParagraph> spliterator() { | |||||
return _paragraphs.spliterator(); | |||||
} | |||||
@Override | @Override | ||||
public Insets2D getInsets() { | public Insets2D getInsets() { | ||||
return new Insets2D(getTopInset(), getLeftInset(), getBottomInset(), getRightInset()); | return new Insets2D(getTopInset(), getLeftInset(), getBottomInset(), getRightInset()); |
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.NoSuchElementException; | import java.util.NoSuchElementException; | ||||
import java.util.Spliterator; | |||||
import java.util.Spliterators; | |||||
import java.util.function.Supplier; | import java.util.function.Supplier; | ||||
import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||
import java.util.stream.StreamSupport; | import java.util.stream.StreamSupport; | ||||
}; | }; | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<byte[]> spliterator() { | |||||
return Spliterators.spliterator(iterator(), getNumberOfElementsInArray(), 0); | |||||
} | |||||
@Override | @Override | ||||
public Map<String, Supplier<?>> getGenericProperties() { | public Map<String, Supplier<?>> getGenericProperties() { | ||||
return GenericRecordUtil.getGenericProperties( | return GenericRecordUtil.getGenericProperties( |
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.Spliterator; | |||||
import java.util.function.Supplier; | import java.util.function.Supplier; | ||||
import org.apache.logging.log4j.LogManager; | import org.apache.logging.log4j.LogManager; | ||||
return Collections.unmodifiableList(_childRecords).iterator(); | return Collections.unmodifiableList(_childRecords).iterator(); | ||||
} | } | ||||
/** | |||||
* @return a spliterator over the child records | |||||
* | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<EscherRecord> spliterator() { | |||||
return _childRecords.spliterator(); | |||||
} | |||||
/** | /** | ||||
* replaces the internal child list with the contents of the supplied {@code childRecords} | * replaces the internal child list with the contents of the supplied {@code childRecords} |
import java.util.HashMap; | import java.util.HashMap; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.Spliterator; | |||||
import java.util.function.Supplier; | import java.util.function.Supplier; | ||||
import org.apache.poi.common.usermodel.GenericRecord; | import org.apache.poi.common.usermodel.GenericRecord; | ||||
return _breaks.iterator(); | return _breaks.iterator(); | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
public final Spliterator<Break> getBreaksSpliterator() { | |||||
return _breaks.spliterator(); | |||||
} | |||||
/** | /** | ||||
* Adds the page break at the specified parameters | * Adds the page break at the specified parameters | ||||
* @param main Depending on sid, will determine row or column to put page break (zero-based) | * @param main Depending on sid, will determine row or column to put page break (zero-based) |
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.Spliterator; | |||||
import java.util.TreeMap; | import java.util.TreeMap; | ||||
import org.apache.poi.hssf.model.RecordStream; | import org.apache.poi.hssf.model.RecordStream; | ||||
return _rowRecords.values().iterator(); | return _rowRecords.values().iterator(); | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
public Spliterator<RowRecord> getSpliterator() { | |||||
return _rowRecords.values().spliterator(); | |||||
} | |||||
public int findStartOfRowOutlineGroup(int row) { | public int findStartOfRowOutlineGroup(int row) { | ||||
// Find the start of the group. | // Find the start of the group. | ||||
RowRecord rowRecord = this.getRow( row ); | RowRecord rowRecord = this.getRow( row ); | ||||
return _valuesAgg.iterator(); | return _valuesAgg.iterator(); | ||||
} | } | ||||
/** | |||||
* Returns a spliterator for the cell values | |||||
* | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
public Spliterator<CellValueRecordInterface> getCellValueSpliterator() { | |||||
return _valuesAgg.spliterator(); | |||||
} | |||||
public IndexRecord createIndexRecord(int indexRecordOffset, int sizeOfInitialSheetRecords) { | public IndexRecord createIndexRecord(int indexRecordOffset, int sizeOfInitialSheetRecords) { | ||||
IndexRecord result = new IndexRecord(); | IndexRecord result = new IndexRecord(); | ||||
result.setFirstRow(_firstrow); | result.setFirstRow(_firstrow); |
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.NoSuchElementException; | import java.util.NoSuchElementException; | ||||
import java.util.Spliterator; | |||||
import java.util.Spliterators; | |||||
import org.apache.poi.hssf.model.RecordStream; | import org.apache.poi.hssf.model.RecordStream; | ||||
import org.apache.poi.hssf.record.BlankRecord; | import org.apache.poi.hssf.record.BlankRecord; | ||||
public Iterator<CellValueRecordInterface> iterator() { | public Iterator<CellValueRecordInterface> iterator() { | ||||
return new ValueIterator(); | return new ValueIterator(); | ||||
} | } | ||||
/** | |||||
* value spliterator | |||||
* | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<CellValueRecordInterface> spliterator() { | |||||
return Spliterators.spliterator(iterator(), getPhysicalNumberOfCells(), 0); | |||||
} | |||||
} | } |
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.Objects; | import java.util.Objects; | ||||
import java.util.Spliterator; | |||||
import java.util.function.Supplier; | import java.util.function.Supplier; | ||||
import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||
return null; | return null; | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
public Spliterator<FormatRun> formatSpliterator() { | |||||
if (field_4_format_runs != null) { | |||||
return field_4_format_runs.spliterator(); | |||||
} | |||||
return null; | |||||
} | |||||
public void removeFormatRun(FormatRun r) { | public void removeFormatRun(FormatRun r) { | ||||
field_4_format_runs.remove(r); | field_4_format_runs.remove(r); | ||||
if (field_4_format_runs.size() == 0) { | if (field_4_format_runs.size() == 0) { |
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.Set; | import java.util.Set; | ||||
import java.util.Spliterator; | |||||
import org.apache.poi.ddf.EscherComplexProperty; | import org.apache.poi.ddf.EscherComplexProperty; | ||||
import org.apache.poi.ddf.EscherContainerRecord; | import org.apache.poi.ddf.EscherContainerRecord; | ||||
return _shapes.iterator(); | return _shapes.iterator(); | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<HSSFShape> spliterator() { | |||||
return _shapes.spliterator(); | |||||
} | |||||
protected HSSFSheet getSheet() { | protected HSSFSheet getSheet() { | ||||
return _sheet; | return _sheet; | ||||
} | } |
{ | { | ||||
return new CellIterator(); | return new CellIterator(); | ||||
} | } | ||||
/** | |||||
* Alias for {@link #cellIterator} to allow | |||||
* foreach loops | |||||
*/ | |||||
@Override | |||||
public Iterator<Cell> iterator() { | |||||
return cellIterator(); | |||||
} | |||||
/** | /** | ||||
* An iterator over the (physical) cells in the row. | * An iterator over the (physical) cells in the row. |
import java.util.Collections; | import java.util.Collections; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Spliterator; | |||||
import org.apache.poi.ddf.DefaultEscherRecordFactory; | import org.apache.poi.ddf.DefaultEscherRecordFactory; | ||||
import org.apache.poi.ddf.EscherBoolProperty; | import org.apache.poi.ddf.EscherBoolProperty; | ||||
public Iterator<HSSFShape> iterator() { | public Iterator<HSSFShape> iterator() { | ||||
return shapes.iterator(); | return shapes.iterator(); | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<HSSFShape> spliterator() { | |||||
return shapes.spliterator(); | |||||
} | |||||
} | } |
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.Spliterator; | |||||
import java.util.TreeMap; | import java.util.TreeMap; | ||||
import java.util.TreeSet; | import java.util.TreeSet; | ||||
} | } | ||||
/** | /** | ||||
* Alias for {@link #rowIterator()} to allow | |||||
* foreach loops | |||||
* @return a spliterator of the PHYSICAL rows. Meaning the 3rd element may not | |||||
* be the third row if say for instance the second row is undefined. | |||||
* Call getRowNum() on each row if you care which one it is. | |||||
* | |||||
* @since POI 5.2.0 | |||||
*/ | */ | ||||
@Override | @Override | ||||
public Iterator<Row> iterator() { | |||||
return rowIterator(); | |||||
@SuppressWarnings("unchecked") // can this clumsy generic syntax be improved? | |||||
public Spliterator<Row> spliterator() { | |||||
return (Spliterator<Row>)(Spliterator<? extends Row>) _rows.values().spliterator(); | |||||
} | } | ||||
/** | /** | ||||
* used internally in the API to get the low level Sheet record represented by this | * used internally in the API to get the low level Sheet record represented by this | ||||
* Object. | * Object. |
import java.util.Map; | import java.util.Map; | ||||
import java.util.NoSuchElementException; | import java.util.NoSuchElementException; | ||||
import java.util.Set; | import java.util.Set; | ||||
import java.util.Spliterator; | |||||
import java.util.regex.Pattern; | import java.util.regex.Pattern; | ||||
import org.apache.commons.codec.digest.DigestUtils; | import org.apache.commons.codec.digest.DigestUtils; | ||||
} | } | ||||
/** | /** | ||||
* Alias for {@link #sheetIterator()} to allow | |||||
* foreach loops | |||||
* Returns a spliterator of the sheets in the workbook | |||||
* in sheet order. Includes hidden and very hidden sheets. | |||||
* | |||||
* @return a spliterator of the sheets. | |||||
* | |||||
* @since POI 5.2.0 | |||||
*/ | */ | ||||
@Override | @Override | ||||
public Iterator<Sheet> iterator() { | |||||
return sheetIterator(); | |||||
@SuppressWarnings("unchecked") | |||||
public Spliterator<Sheet> spliterator() { | |||||
return (Spliterator<Sheet>)(Spliterator<? extends Sheet>) _sheets.spliterator(); | |||||
} | } | ||||
private final class SheetIterator<T extends Sheet> implements Iterator<T> { | private final class SheetIterator<T extends Sheet> implements Iterator<T> { |
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.Set; | import java.util.Set; | ||||
import java.util.Spliterator; | |||||
import org.apache.poi.hpsf.ClassID; | import org.apache.poi.hpsf.ClassID; | ||||
import org.apache.poi.poifs.dev.POIFSViewable; | import org.apache.poi.poifs.dev.POIFSViewable; | ||||
return getEntries(); | return getEntries(); | ||||
} | } | ||||
/** | |||||
* Returns a Spliterator over all the entries | |||||
* | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<Entry> spliterator() { | |||||
return _entries.spliterator(); | |||||
} | |||||
/* ********** END begin implementation of POIFSViewable ********** */ | /* ********** END begin implementation of POIFSViewable ********** */ | ||||
} // end public class DirectoryNode | } // end public class DirectoryNode | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.NoSuchElementException; | import java.util.NoSuchElementException; | ||||
import java.util.Set; | import java.util.Set; | ||||
import java.util.Spliterator; | |||||
import java.util.Spliterators; | |||||
import org.apache.poi.hpsf.ClassID; | import org.apache.poi.hpsf.ClassID; | ||||
return getEntries(); | return getEntries(); | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<Entry> spliterator() { | |||||
return Spliterators.spliterator(iterator(), getEntryCount(), 0); | |||||
} | |||||
@Override | @Override | ||||
public int getEntryCount() { | public int getEntryCount() { | ||||
int size = directory.getEntryCount(); | int size = directory.getEntryCount(); |
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Set; | import java.util.Set; | ||||
import java.util.Spliterator; | |||||
/** | /** | ||||
* Directory property | * Directory property | ||||
public Iterator<Property> iterator() { | public Iterator<Property> iterator() { | ||||
return getChildren(); | return getChildren(); | ||||
} | } | ||||
/** | |||||
* Get a spliterator over the children of this Parent; all elements | |||||
* are instances of Property. | |||||
* | |||||
* @return Spliterator of children; may refer to an empty collection | |||||
* | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<Property> spliterator() { | |||||
return _children.spliterator(); | |||||
} | |||||
/** | /** | ||||
* Add a new child to the collection of children | * Add a new child to the collection of children |
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Objects; | import java.util.Objects; | ||||
import java.util.Spliterator; | |||||
/** | /** | ||||
* Definition of a custom geometric shape | * Definition of a custom geometric shape | ||||
return paths.iterator(); | return paths.iterator(); | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<PathIf> spliterator() { | |||||
return paths.spliterator(); | |||||
} | |||||
public Path getTextBounds(){ | public Path getTextBounds(){ | ||||
return textBounds; | return textBounds; | ||||
} | } |
import java.util.HashSet; | import java.util.HashSet; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.Spliterator; | |||||
import java.util.Spliterators; | |||||
import java.util.regex.Matcher; | import java.util.regex.Matcher; | ||||
import java.util.regex.Pattern; | import java.util.regex.Pattern; | ||||
} | } | ||||
}; | }; | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
default Spliterator<Integer> indexSpliterator() { | |||||
return Spliterators.spliterator(indexIterator(), getSize(), 0); | |||||
} | |||||
default Iterator<Integer> reverseIndexIterator() { | default Iterator<Integer> reverseIndexIterator() { | ||||
return new Iterator<Integer>() { | return new Iterator<Integer>() { | ||||
int pos = getSize() - 1; | int pos = getSize() - 1; | ||||
} | } | ||||
}; | }; | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
default Spliterator<Integer> reverseIndexSpliterator() { | |||||
return Spliterators.spliterator(reverseIndexIterator(), getSize(), 0); | |||||
} | |||||
} | } | ||||
private static final class RowVector implements ValueVector { | private static final class RowVector implements ValueVector { |
package org.apache.poi.ss.usermodel; | package org.apache.poi.ss.usermodel; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.Spliterator; | |||||
import java.util.Spliterators; | |||||
/** | /** | ||||
* High level representation of a row of a spreadsheet. | * High level representation of a row of a spreadsheet. | ||||
*/ | */ | ||||
Iterator<Cell> cellIterator(); | Iterator<Cell> cellIterator(); | ||||
/** | |||||
* Alias for {@link #cellIterator()} to allow foreach loops: | |||||
* <blockquote><pre> | |||||
* for(Cell cell : row){ | |||||
* ... | |||||
* } | |||||
* </pre></blockquote> | |||||
* | |||||
* @return an iterator over cells in this row. | |||||
*/ | |||||
@Override | |||||
default Iterator<Cell> iterator() { | |||||
return cellIterator(); | |||||
} | |||||
/** | |||||
* @return Cell spliterator of the physically defined cells. Note element 4 may | |||||
* actually be row cell depending on how many are defined! | |||||
* | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
default Spliterator<Cell> spliterator() { | |||||
return Spliterators.spliterator(cellIterator(), getPhysicalNumberOfCells(), 0); | |||||
} | |||||
/** | /** | ||||
* Returns the Sheet this row belongs to | * Returns the Sheet this row belongs to | ||||
* | * |
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.Spliterator; | |||||
import java.util.Spliterators; | |||||
import org.apache.poi.ss.util.CellAddress; | import org.apache.poi.ss.util.CellAddress; | ||||
import org.apache.poi.ss.util.CellRangeAddress; | import org.apache.poi.ss.util.CellRangeAddress; | ||||
*/ | */ | ||||
Iterator<Row> rowIterator(); | Iterator<Row> rowIterator(); | ||||
/** | |||||
* Alias for {@link #rowIterator()} to allow foreach loops | |||||
*/ | |||||
@Override | |||||
default Iterator<Row> iterator() { | |||||
return rowIterator(); | |||||
} | |||||
/** | |||||
* Returns a spliterator of the physical rows | |||||
* | |||||
* @return a spliterator of the PHYSICAL rows. Meaning the 3rd element may not | |||||
* be the third row if say for instance the second row is undefined. | |||||
* | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
default Spliterator<Row> spliterator() { | |||||
return Spliterators.spliterator(rowIterator(), getPhysicalNumberOfRows(), 0); | |||||
} | |||||
/** | /** | ||||
* Control if Excel should be asked to recalculate all formulas on this sheet | * Control if Excel should be asked to recalculate all formulas on this sheet | ||||
* when the workbook is opened. | * when the workbook is opened. |
import java.io.OutputStream; | import java.io.OutputStream; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Spliterator; | |||||
import java.util.Spliterators; | |||||
import org.apache.poi.ss.SpreadsheetVersion; | import org.apache.poi.ss.SpreadsheetVersion; | ||||
import org.apache.poi.ss.formula.EvaluationWorkbook; | import org.apache.poi.ss.formula.EvaluationWorkbook; | ||||
*/ | */ | ||||
Iterator<Sheet> sheetIterator(); | Iterator<Sheet> sheetIterator(); | ||||
/** | |||||
* Alias for {@link #sheetIterator()} to allow foreach loops | |||||
*/ | |||||
@Override | |||||
default Iterator<Sheet> iterator() { | |||||
return sheetIterator(); | |||||
} | |||||
/** | |||||
* Returns a spliterator of the sheets in the workbook | |||||
* in sheet order. Includes hidden and very hidden sheets. | |||||
* | |||||
* @return a spliterator of the sheets. | |||||
* | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
default Spliterator<Sheet> spliterator() { | |||||
return Spliterators.spliterator(sheetIterator(), getNumberOfSheets(), 0); | |||||
} | |||||
/** | /** | ||||
* Get the number of spreadsheets in the workbook | * Get the number of spreadsheets in the workbook | ||||
* | * |
import java.util.Map; | import java.util.Map; | ||||
import java.util.NoSuchElementException; | import java.util.NoSuchElementException; | ||||
import java.util.Set; | import java.util.Set; | ||||
import java.util.Spliterator; | |||||
import java.util.Spliterators; | |||||
import java.util.function.Supplier; | import java.util.function.Supplier; | ||||
import org.apache.poi.common.Duplicatable; | import org.apache.poi.common.Duplicatable; | ||||
return new RowMajorCellAddressIterator(this); | return new RowMajorCellAddressIterator(this); | ||||
} | } | ||||
/** | |||||
* Returns a spliterator over the CellAddresses in this cell range in row-major order. | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<CellAddress> spliterator() { | |||||
return Spliterators.spliterator(iterator(), getNumberOfCells(), 0); | |||||
} | |||||
/** | /** | ||||
* Iterates over the cell addresses in a cell range in row major order | * Iterates over the cell addresses in a cell range in row major order | ||||
* | * |
import java.lang.reflect.Array; | import java.lang.reflect.Array; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Spliterator; | |||||
import java.util.stream.Stream; | import java.util.stream.Stream; | ||||
import org.apache.poi.ss.usermodel.Cell; | import org.apache.poi.ss.usermodel.Cell; | ||||
public Iterator<K> iterator() { | public Iterator<K> iterator() { | ||||
return Stream.of(_flattenedArray).iterator(); | return Stream.of(_flattenedArray).iterator(); | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
@Override | |||||
public Spliterator<K> spliterator() { | |||||
return Stream.of(_flattenedArray).spliterator(); | |||||
} | |||||
} | } |
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.Spliterator; | |||||
import org.apache.poi.common.Duplicatable; | import org.apache.poi.common.Duplicatable; | ||||
* update | * update | ||||
*/ | */ | ||||
public class IntMapper<T> implements Duplicatable { | |||||
public class IntMapper<T> implements Duplicatable, Iterable<T> { | |||||
private final List<T> elements; | private final List<T> elements; | ||||
private final Map<T, Integer> valueKeyMap; | private final Map<T, Integer> valueKeyMap; | ||||
return elements.iterator(); | return elements.iterator(); | ||||
} | } | ||||
/** | |||||
* @since POI 5.2.0 | |||||
*/ | |||||
public Spliterator<T> spliterator() { | |||||
return elements.spliterator(); | |||||
} | |||||
@Override | @Override | ||||
public IntMapper<T> copy() { | public IntMapper<T> copy() { | ||||
return new IntMapper<>(this); | return new IntMapper<>(this); |
import static org.junit.jupiter.api.Assertions.assertNull; | import static org.junit.jupiter.api.Assertions.assertNull; | ||||
import static org.junit.jupiter.api.Assertions.assertSame; | import static org.junit.jupiter.api.Assertions.assertSame; | ||||
import static org.junit.jupiter.api.Assertions.assertTrue; | import static org.junit.jupiter.api.Assertions.assertTrue; | ||||
import static org.junit.jupiter.api.Assertions.fail; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Spliterator; | |||||
import org.apache.poi.ddf.EscherBoolProperty; | import org.apache.poi.ddf.EscherBoolProperty; | ||||
import org.apache.poi.ddf.EscherContainerRecord; | import org.apache.poi.ddf.EscherContainerRecord; | ||||
assertEquals(s1, iter.next()); | assertEquals(s1, iter.next()); | ||||
assertEquals(s2, iter.next()); | assertEquals(s2, iter.next()); | ||||
assertFalse(iter.hasNext()); | assertFalse(iter.hasNext()); | ||||
Spliterator<HSSFShape> spliter = patriarch.spliterator(); | |||||
spliter.tryAdvance(s -> assertEquals(s1, s)); | |||||
spliter.tryAdvance(s -> assertEquals(s2, s)); | |||||
assertFalse(spliter.tryAdvance(s -> fail())); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
assertEquals(0, count); | assertEquals(0, count); | ||||
// verify that spliterator behaves correctly | |||||
assertEquals(0, node.spliterator().getExactSizeIfKnown()); | |||||
// verify behavior of isEmpty | // verify behavior of isEmpty | ||||
assertTrue(node.isEmpty()); | assertTrue(node.isEmpty()); | ||||
} | } | ||||
assertEquals(2, count); | assertEquals(2, count); | ||||
// verify that spliterator behaves correctly | |||||
assertEquals(2, node.spliterator().getExactSizeIfKnown()); | |||||
// verify behavior of isEmpty | // verify behavior of isEmpty | ||||
assertFalse(node.isEmpty()); | assertFalse(node.isEmpty()); | ||||
import static org.junit.jupiter.api.Assertions.assertFalse; | import static org.junit.jupiter.api.Assertions.assertFalse; | ||||
import static org.junit.jupiter.api.Assertions.assertThrows; | import static org.junit.jupiter.api.Assertions.assertThrows; | ||||
import static org.junit.jupiter.api.Assertions.assertTrue; | import static org.junit.jupiter.api.Assertions.assertTrue; | ||||
import static org.junit.jupiter.api.Assertions.fail; | |||||
import java.io.ByteArrayInputStream; | import java.io.ByteArrayInputStream; | ||||
import java.io.FileNotFoundException; | import java.io.FileNotFoundException; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.NoSuchElementException; | import java.util.NoSuchElementException; | ||||
import java.util.Spliterator; | |||||
import org.junit.jupiter.api.BeforeEach; | import org.junit.jupiter.api.BeforeEach; | ||||
import org.junit.jupiter.api.Test; | import org.junit.jupiter.api.Test; | ||||
assertEquals(dirB, i.next()); | assertEquals(dirB, i.next()); | ||||
assertEquals(eRoot, i.next()); | assertEquals(eRoot, i.next()); | ||||
assertThrows(NoSuchElementException.class, i::next, "Should throw NoSuchElementException when depleted"); | assertThrows(NoSuchElementException.class, i::next, "Should throw NoSuchElementException when depleted"); | ||||
Spliterator<Entry> s = d.spliterator(); | |||||
s.tryAdvance(entry -> assertEquals(dirA, entry)); | |||||
s.tryAdvance(entry -> assertEquals(dirB, entry)); | |||||
s.tryAdvance(entry -> assertEquals(eRoot, entry)); | |||||
assertFalse(s.tryAdvance(entry -> fail("Should be depleted")), "Should return false when depleted"); | |||||
} | } | ||||
@Test | @Test | ||||
assertEquals(dirB, i.next()); | assertEquals(dirB, i.next()); | ||||
assertThrows(NoSuchElementException.class, i::next, "Should throw NoSuchElementException when depleted"); | assertThrows(NoSuchElementException.class, i::next, "Should throw NoSuchElementException when depleted"); | ||||
Spliterator<Entry> s1 = d1.spliterator(); | |||||
s1.tryAdvance(entry -> assertEquals(dirA, entry)); | |||||
s1.tryAdvance(entry -> assertEquals(dirB, entry)); | |||||
assertFalse(s1.tryAdvance(entry -> fail("Should be depleted")), "Should return false when depleted"); | |||||
// Filter more | // Filter more | ||||
excl = Arrays.asList("NotThere", "AlsoNotThere", eRoot.getName(), dirA.getName()); | excl = Arrays.asList("NotThere", "AlsoNotThere", eRoot.getName(), dirA.getName()); | ||||
assertEquals(dirB, i.next()); | assertEquals(dirB, i.next()); | ||||
assertThrows(NoSuchElementException.class, i::next, "Should throw NoSuchElementException when depleted"); | assertThrows(NoSuchElementException.class, i::next, "Should throw NoSuchElementException when depleted"); | ||||
Spliterator<Entry> s2 = d2.spliterator(); | |||||
s2.tryAdvance(entry -> assertEquals(dirB, entry)); | |||||
assertFalse(s2.tryAdvance(entry -> fail("Should be depleted")), "Should return false when depleted"); | |||||
// Filter everything | // Filter everything | ||||
excl = Arrays.asList("NotThere", eRoot.getName(), dirA.getName(), dirB.getName()); | excl = Arrays.asList("NotThere", eRoot.getName(), dirA.getName(), dirB.getName()); | ||||
FilteringDirectoryNode d3 = new FilteringDirectoryNode(fs.getRoot(), excl); | FilteringDirectoryNode d3 = new FilteringDirectoryNode(fs.getRoot(), excl); | ||||
i = d3.getEntries(); | i = d3.getEntries(); | ||||
assertThrows(NoSuchElementException.class, i::next, "Should throw NoSuchElementException when depleted"); | assertThrows(NoSuchElementException.class, i::next, "Should throw NoSuchElementException when depleted"); | ||||
Spliterator<Entry> s3 = d3.spliterator(); | |||||
assertFalse(s3.tryAdvance(entry -> fail("Should be depleted")), "Should return false when depleted"); | |||||
} | } | ||||
@Test | @Test |
children.add(iter.next()); | children.add(iter.next()); | ||||
} | } | ||||
assertEquals(count, children.size()); | assertEquals(count, children.size()); | ||||
assertEquals(count, _property.spliterator().getExactSizeIfKnown()); | |||||
if (count != 0) | if (count != 0) | ||||
{ | { | ||||
boolean[] found = new boolean[ count ]; | boolean[] found = new boolean[ count ]; |
import java.awt.geom.Path2D; | import java.awt.geom.Path2D; | ||||
import java.awt.geom.Rectangle2D; | import java.awt.geom.Rectangle2D; | ||||
import java.util.stream.StreamSupport; | |||||
import org.junit.jupiter.api.Assertions; | |||||
import org.junit.jupiter.api.Test; | import org.junit.jupiter.api.Test; | ||||
class TestPresetGeometries { | class TestPresetGeometries { | ||||
Path2D path = p.getPath(ctx); | Path2D path = p.getPath(ctx); | ||||
assertNotNull(path); | assertNotNull(path); | ||||
} | } | ||||
StreamSupport.stream(geom.spliterator(), true) | |||||
.map(p -> p.getPath(ctx)) | |||||
.forEach(Assertions::assertNotNull); | |||||
} | } | ||||
// we get the same instance on further calls | // we get the same instance on further calls |
import static org.junit.jupiter.api.Assertions.assertSame; | import static org.junit.jupiter.api.Assertions.assertSame; | ||||
import static org.junit.jupiter.api.Assertions.assertThrows; | import static org.junit.jupiter.api.Assertions.assertThrows; | ||||
import static org.junit.jupiter.api.Assertions.assertTrue; | import static org.junit.jupiter.api.Assertions.assertTrue; | ||||
import static org.junit.jupiter.api.Assertions.fail; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.Spliterator; | |||||
import org.apache.poi.ss.ITestDataProvider; | import org.apache.poi.ss.ITestDataProvider; | ||||
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy; | import org.apache.poi.ss.usermodel.Row.MissingCellPolicy; | ||||
wb.close(); | wb.close(); | ||||
} | } | ||||
/** | |||||
* Test adding cells to a row in various places and see if we can find them again. | |||||
*/ | |||||
@Test | |||||
void testSpliterator() throws IOException { | |||||
Workbook wb = _testDataProvider.createWorkbook(); | |||||
Sheet sheet = wb.createSheet(); | |||||
Row row = sheet.createRow(0); | |||||
// One cell at the beginning | |||||
Cell cell1 = row.createCell(1); | |||||
Spliterator<Cell> split = row.spliterator(); | |||||
assertTrue(split.tryAdvance(cell -> assertSame(cell1, cell))); | |||||
assertFalse(split.tryAdvance(cell -> fail())); | |||||
// Add another cell at the end | |||||
Cell cell2 = row.createCell(99); | |||||
split = row.spliterator(); | |||||
assertTrue(split.tryAdvance(cell -> assertSame(cell1, cell))); | |||||
assertTrue(split.tryAdvance(cell -> assertSame(cell2, cell))); | |||||
// Add another cell at the beginning | |||||
Cell cell3 = row.createCell(0); | |||||
split = row.spliterator(); | |||||
assertTrue(split.tryAdvance(cell -> assertSame(cell3, cell))); | |||||
assertTrue(split.tryAdvance(cell -> assertSame(cell1, cell))); | |||||
assertTrue(split.tryAdvance(cell -> assertSame(cell2, cell))); | |||||
// Replace cell1 | |||||
Cell cell4 = row.createCell(1); | |||||
split = row.spliterator(); | |||||
assertTrue(split.tryAdvance(cell -> assertSame(cell3, cell))); | |||||
assertTrue(split.tryAdvance(cell -> assertSame(cell4, cell))); | |||||
assertTrue(split.tryAdvance(cell -> assertSame(cell2, cell))); | |||||
assertFalse(split.tryAdvance(cell -> fail())); | |||||
// Add another cell, specifying the cellType | |||||
Cell cell5 = row.createCell(2, CellType.STRING); | |||||
split = row.spliterator(); | |||||
assertNotNull(cell5); | |||||
assertTrue(split.tryAdvance(cell -> assertSame(cell3, cell))); | |||||
assertTrue(split.tryAdvance(cell -> assertSame(cell4, cell))); | |||||
assertTrue(split.tryAdvance(cell -> assertSame(cell5, cell))); | |||||
assertTrue(split.tryAdvance(cell -> assertSame(cell2, cell))); | |||||
assertEquals(CellType.STRING, cell5.getCellType()); | |||||
wb.close(); | |||||
} | |||||
@Test | @Test | ||||
void testRowStyle() throws IOException { | void testRowStyle() throws IOException { | ||||
Workbook wb1 = _testDataProvider.createWorkbook(); | Workbook wb1 = _testDataProvider.createWorkbook(); |
import java.util.Map; | import java.util.Map; | ||||
import java.util.Map.Entry; | import java.util.Map.Entry; | ||||
import java.util.Set; | import java.util.Set; | ||||
import java.util.Spliterator; | |||||
import org.apache.poi.common.usermodel.HyperlinkType; | import org.apache.poi.common.usermodel.HyperlinkType; | ||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; | import org.apache.poi.hssf.usermodel.HSSFWorkbook; | ||||
assertSame(row1, it.next()); | assertSame(row1, it.next()); | ||||
assertTrue(it.hasNext()); | assertTrue(it.hasNext()); | ||||
assertSame(row2, it.next()); | assertSame(row2, it.next()); | ||||
Spliterator<Row> split = sheet.spliterator(); | |||||
assertTrue(split.tryAdvance(row -> assertSame(row1, row))); | |||||
assertTrue(split.tryAdvance(row -> assertSame(row2, row))); | |||||
assertEquals(1, sheet.getLastRowNum()); | assertEquals(1, sheet.getLastRowNum()); | ||||
// Test row creation with non consecutive index | // Test row creation with non consecutive index | ||||
Row row2_ovrewritten_ref = it2.next(); | Row row2_ovrewritten_ref = it2.next(); | ||||
assertSame(row2_ovrewritten, row2_ovrewritten_ref); | assertSame(row2_ovrewritten, row2_ovrewritten_ref); | ||||
assertEquals(100.0, row2_ovrewritten_ref.getCell(0).getNumericCellValue(), 0.0); | assertEquals(100.0, row2_ovrewritten_ref.getCell(0).getNumericCellValue(), 0.0); | ||||
Spliterator<Row> split2 = sheet.spliterator(); | |||||
assertTrue(split2.tryAdvance(row -> assertSame(row1, row))); | |||||
assertTrue(split2.tryAdvance(row -> { | |||||
assertSame(row2_ovrewritten, row); | |||||
assertEquals(100.0, row.getCell(0).getNumericCellValue(), 0.0); | |||||
})); | |||||
} | } | ||||
} | } | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.ConcurrentModificationException; | import java.util.ConcurrentModificationException; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.Spliterator; | |||||
import org.apache.poi.hssf.HSSFTestDataSamples; | import org.apache.poi.hssf.HSSFTestDataSamples; | ||||
import org.apache.poi.ss.ITestDataProvider; | import org.apache.poi.ss.ITestDataProvider; | ||||
wb.createSheet("Sheet2"); | wb.createSheet("Sheet2"); | ||||
Iterator<Sheet> it = wb.sheetIterator(); | Iterator<Sheet> it = wb.sheetIterator(); | ||||
Spliterator<Sheet> split = wb.spliterator(); | |||||
it.next(); | it.next(); | ||||
split.tryAdvance(sheet -> {}); | |||||
wb.setSheetOrder("Sheet2", 1); | wb.setSheetOrder("Sheet2", 1); | ||||
// Iterator order should be fixed when iterator is created | // Iterator order should be fixed when iterator is created | ||||
assertThrows(ConcurrentModificationException.class, it::next); | assertThrows(ConcurrentModificationException.class, it::next); | ||||
// Spliterator order should be fixed when spliterator is created | |||||
assertThrows(ConcurrentModificationException.class, () -> split.tryAdvance(sheet -> {})); | |||||
} | } | ||||
} | } | ||||
wb.createSheet("Sheet2"); | wb.createSheet("Sheet2"); | ||||
Iterator<Sheet> it = wb.sheetIterator(); | Iterator<Sheet> it = wb.sheetIterator(); | ||||
Spliterator<Sheet> split = wb.spliterator(); | |||||
it.next(); | |||||
split.tryAdvance(sheet -> {}); | |||||
wb.removeSheetAt(1); | wb.removeSheetAt(1); | ||||
// Iterator order should be fixed when iterator is created | // Iterator order should be fixed when iterator is created | ||||
assertThrows(ConcurrentModificationException.class, it::next); | assertThrows(ConcurrentModificationException.class, it::next); | ||||
// Spliterator order should be fixed when spliterator is created | |||||
assertThrows(ConcurrentModificationException.class, () -> split.tryAdvance(sheet -> {})); | |||||
} | } | ||||
} | } | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.NoSuchElementException; | import java.util.NoSuchElementException; | ||||
import java.util.Spliterator; | |||||
import java.util.stream.StreamSupport; | |||||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; | import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; | ||||
import org.apache.poi.hssf.record.TestcaseRecordInputStream; | import org.apache.poi.hssf.record.TestcaseRecordInputStream; | ||||
import org.apache.poi.util.LittleEndianOutputStream; | import org.apache.poi.util.LittleEndianOutputStream; | ||||
import org.junit.jupiter.api.Assertions; | |||||
import org.junit.jupiter.api.Test; | import org.junit.jupiter.api.Test; | ||||
final class TestCellRangeAddress { | final class TestCellRangeAddress { | ||||
assertEquals(4, count); | assertEquals(4, count); | ||||
} | } | ||||
@Test | |||||
void spliterator() { | |||||
final CellRangeAddress A1_B2 = new CellRangeAddress(0, 1, 0, 1); | |||||
// the cell address iterator iterates in row major order | |||||
final Spliterator<CellAddress> spliter = A1_B2.spliterator(); | |||||
spliter.tryAdvance(addr -> | |||||
assertEquals(new CellAddress(0, 0), addr, "A1")); | |||||
spliter.tryAdvance(addr -> | |||||
assertEquals(new CellAddress(0, 1), addr, "B1")); | |||||
spliter.tryAdvance(addr -> | |||||
assertEquals(new CellAddress(1, 0), addr, "A2")); | |||||
spliter.tryAdvance(addr -> | |||||
assertEquals(new CellAddress(1, 1), addr, "B2")); | |||||
assertFalse(spliter.tryAdvance(addr -> fail())); | |||||
// stream | |||||
long count = StreamSupport.stream(A1_B2.spliterator(), false) | |||||
.peek(Assertions::assertNotNull) | |||||
.count(); | |||||
assertEquals(4, count); | |||||
} | |||||
private static void assertIntersects(CellRangeAddress regionA, CellRangeAddress regionB) { | private static void assertIntersects(CellRangeAddress regionA, CellRangeAddress regionB) { | ||||
if (!(regionA.intersects(regionB) && regionB.intersects(regionA))) { | if (!(regionA.intersects(regionB) && regionB.intersects(regionA))) { | ||||
final String A = regionA.formatAsString(); | final String A = regionA.formatAsString(); |