Skip to content

Commit

Permalink
#181 HUDocumentViewSelection streamAll and streamAllRecursive
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Feb 27, 2017
1 parent 72aa05a commit 24c033d
Showing 1 changed file with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,30 +248,29 @@ private void invalidateAllNoNotify()
_recordsSupplier.forget();
documentViewsLoader.getAttributesProvider().invalidateAll();
}

public void addHUsAndInvalidate(final Collection<I_M_HU> husToAdd)
{
if(husToAdd.isEmpty())
if (husToAdd.isEmpty())
{
return;
}

documentViewsLoader.addHUs(husToAdd);
invalidateAll();
}

public void addHUAndInvalidate(final I_M_HU hu)
{
if(hu == null)
if (hu == null)
{
return;
}

documentViewsLoader.addHUs(ImmutableSet.of(hu));
invalidateAll();
}


@Override
public void notifyRecordsChanged(final Set<TableRecordReference> recordRefs)
{
Expand All @@ -285,7 +284,7 @@ public void notifyRecordsChanged(final Set<TableRecordReference> recordRefs)
.filter(recordRef -> I_M_HU.Table_Name.equals(recordRef.getTableName()))
.map(recordRef -> DocumentId.of(recordRef.getRecord_ID()))
.anyMatch(records::contains);
if(!containsSomeRecords)
if (!containsSomeRecords)
{
return;
}
Expand Down Expand Up @@ -356,6 +355,22 @@ public Stream<HUDocumentView> stream()
return records.stream();
}

public Stream<HUDocumentView> streamRecursive()
{
return records.stream()
.map(row -> streamRecursive(row))
.reduce(Stream::concat)
.orElse(Stream.of());
}

private Stream<HUDocumentView> streamRecursive(HUDocumentView row)
{
return row.getIncludedDocuments()
.stream()
.map(includedRow -> streamRecursive(includedRow))
.reduce(Stream.of(row), Stream::concat);
}

public long size()
{
return records.size();
Expand Down Expand Up @@ -468,6 +483,18 @@ public Stream<HUDocumentView> streamByIds(final Collection<DocumentId> documentI
return getRecords().streamByIds(documentIds);
}

/** @return top level rows stream */
public Stream<HUDocumentView> streamAll()
{
return getRecords().stream();
}

/** @return top level rows and included rows recursive stream */
public Stream<HUDocumentView> streamAllRecursive()
{
return getRecords().streamRecursive();
}

@Override
public <T> List<T> retrieveModelsByIds(final Collection<DocumentId> documentIds, final Class<T> modelClass)
{
Expand Down

0 comments on commit 24c033d

Please sign in to comment.