Change return type of getConstraintsByType method (#2838)
changed the return type of getConstraintsByTpye method from Stream<Statement> to List<Statement>
This commit is contained in:
parent
bc540a880e
commit
f32f6a6ea2
@ -29,8 +29,8 @@ import org.wikidata.wdtk.datamodel.interfaces.QuantityValue;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.Statement;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.Value;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* An object that fetches constraints about properties.
|
||||
@ -150,9 +150,9 @@ public interface ConstraintFetcher {
|
||||
* the property to retrieve the constraints for
|
||||
* @param qid
|
||||
* the type of the constraints
|
||||
* @return the stream of matching constraint statements
|
||||
* @return the list of matching constraint statements
|
||||
*/
|
||||
Stream<Statement> getConstraintsByType(PropertyIdValue pid, String qid);
|
||||
List<Statement> getConstraintsByType(PropertyIdValue pid, String qid);
|
||||
|
||||
/**
|
||||
* Retrieves the lower bound of the range
|
||||
|
@ -281,9 +281,12 @@ public class WikidataConstraintFetcher implements ConstraintFetcher {
|
||||
* exist
|
||||
*/
|
||||
protected List<SnakGroup> getSingleConstraint(PropertyIdValue pid, String qid) {
|
||||
Statement statement = getConstraintsByType(pid, qid).findFirst().orElse(null);
|
||||
if (statement != null) {
|
||||
return statement.getClaim().getQualifiers();
|
||||
List<Statement> statementList = getConstraintsByType(pid, qid);
|
||||
if (!statementList.isEmpty()) {
|
||||
Statement statement = statementList.get(0);
|
||||
if (statement != null) {
|
||||
return statement.getClaim().getQualifiers();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -295,14 +298,14 @@ public class WikidataConstraintFetcher implements ConstraintFetcher {
|
||||
* the property to retrieve the constraints for
|
||||
* @param qid
|
||||
* the type of the constraints
|
||||
* @return the stream of matching constraint statements
|
||||
* @return the list of matching constraint statements
|
||||
*/
|
||||
@Override
|
||||
public Stream<Statement> getConstraintsByType(PropertyIdValue pid, String qid) {
|
||||
public List<Statement> getConstraintsByType(PropertyIdValue pid, String qid) {
|
||||
Stream<Statement> allConstraints = getConstraintStatements(pid).stream()
|
||||
.filter(s -> s.getValue() != null && ((EntityIdValue) s.getValue()).getId().equals(qid))
|
||||
.filter(s -> !StatementRank.DEPRECATED.equals(s.getRank()));
|
||||
return allConstraints;
|
||||
return allConstraints.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -14,7 +14,6 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ConflictsWithScrutinizer extends EditScrutinizer {
|
||||
|
||||
@ -65,7 +64,7 @@ public class ConflictsWithScrutinizer extends EditScrutinizer {
|
||||
}
|
||||
|
||||
for(PropertyIdValue propertyId : propertyIdValueValueMap.keySet()){
|
||||
List<Statement> statementList = _fetcher.getConstraintsByType(propertyId, CONFLICTS_WITH_CONSTRAINT_QID).collect(Collectors.toList());
|
||||
List<Statement> statementList = _fetcher.getConstraintsByType(propertyId, CONFLICTS_WITH_CONSTRAINT_QID);
|
||||
for (Statement statement : statementList) {
|
||||
ConflictsWithConstraint constraint = new ConflictsWithConstraint(statement);
|
||||
PropertyIdValue conflictingPid = constraint.conflictingPid;
|
||||
|
@ -40,14 +40,13 @@ public class MultiValueScrutinizer extends EditScrutinizer {
|
||||
|
||||
for (Statement statement : update.getAddedStatements()) {
|
||||
PropertyIdValue pid = statement.getClaim().getMainSnak().getPropertyId();
|
||||
List<Statement> statementList = _fetcher.getConstraintsByType(pid, MULTI_VALUE_CONSTRAINT_QID);
|
||||
if (propertyCount.containsKey(pid)) {
|
||||
propertyCount.put(pid, propertyCount.get(pid) + 1);
|
||||
} else {
|
||||
Statement constraintStatement = _fetcher.getConstraintsByType(pid, MULTI_VALUE_CONSTRAINT_QID).findFirst().orElse(null);
|
||||
if (constraintStatement != null) {
|
||||
MultivalueConstraint constraint = new MultivalueConstraint(constraintStatement);
|
||||
propertyCount.put(pid, 1);
|
||||
}
|
||||
} else if (!statementList.isEmpty()) {
|
||||
Statement constraintStatement = statementList.get(0);
|
||||
MultivalueConstraint constraint = new MultivalueConstraint(constraintStatement);
|
||||
propertyCount.put(pid, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class MockConstraintFetcher implements ConstraintFetcher {
|
||||
|
||||
@ -220,7 +219,7 @@ public class MockConstraintFetcher implements ConstraintFetcher {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<Statement> getConstraintsByType(PropertyIdValue pid, String qid) {
|
||||
public List<Statement> getConstraintsByType(PropertyIdValue pid, String qid) {
|
||||
EntityIdValue entityIdValue = Datamodel.makeWikidataItemIdValue("Q21502838");
|
||||
PropertyIdValue propertyIdValue = Datamodel.makeWikidataPropertyIdValue("P2302");
|
||||
Snak snak = Datamodel.makeValueSnak(propertyIdValue,entityIdValue);
|
||||
@ -247,8 +246,6 @@ public class MockConstraintFetcher implements ConstraintFetcher {
|
||||
Statement statement = Datamodel.makeStatement(claim, referenceList, StatementRank.NORMAL, "P2302$77BD7FE4-C051-4776-855C-543F0CE697D0");
|
||||
List<Statement> statements = Collections.singletonList(statement);
|
||||
|
||||
return statements.stream()
|
||||
.filter(s -> s.getValue() != null && ((EntityIdValue) s.getValue()).getId().equals(qid))
|
||||
.filter(s -> !StatementRank.DEPRECATED.equals(s.getRank()));
|
||||
return statements;
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
@ -67,10 +66,10 @@ public class ConflictsWithScrutinizerTest extends ScrutinizerTest {
|
||||
SnakGroup snakGroup1 = Datamodel.makeSnakGroup(snakList1);
|
||||
SnakGroup snakGroup2 = Datamodel.makeSnakGroup(snakList2);
|
||||
List<SnakGroup> snakGroupList = Arrays.asList(snakGroup1, snakGroup2);
|
||||
Stream<Statement> statementStream = constraintParameterStatementStream(entityIdValue, snakGroupList);
|
||||
List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList);
|
||||
|
||||
ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
|
||||
when(fetcher.getConstraintsByType(conflictsWithPid, "Q21502838")).thenReturn(statementStream);
|
||||
when(fetcher.getConstraintsByType(conflictsWithPid, "Q21502838")).thenReturn(statementList);
|
||||
|
||||
setFetcher(fetcher);
|
||||
scrutinize(updateA);
|
||||
@ -94,10 +93,10 @@ public class ConflictsWithScrutinizerTest extends ScrutinizerTest {
|
||||
SnakGroup snakGroup1 = Datamodel.makeSnakGroup(snakList1);
|
||||
SnakGroup snakGroup2 = Datamodel.makeSnakGroup(snakList2);
|
||||
List<SnakGroup> snakGroupList = Arrays.asList(snakGroup1, snakGroup2);
|
||||
Stream<Statement> statementStream = constraintParameterStatementStream(entityIdValue, snakGroupList);
|
||||
List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList);
|
||||
|
||||
ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
|
||||
when(fetcher.getConstraintsByType(conflictsWithPid, "Q21502838")).thenReturn(statementStream);
|
||||
when(fetcher.getConstraintsByType(conflictsWithPid, "Q21502838")).thenReturn(statementList);
|
||||
|
||||
setFetcher(fetcher);
|
||||
scrutinize(update);
|
||||
@ -123,10 +122,10 @@ public class ConflictsWithScrutinizerTest extends ScrutinizerTest {
|
||||
SnakGroup snakGroup1 = Datamodel.makeSnakGroup(snakList1);
|
||||
SnakGroup snakGroup2 = Datamodel.makeSnakGroup(snakList2);
|
||||
List<SnakGroup> snakGroupList = Arrays.asList(snakGroup1, snakGroup2);
|
||||
Stream<Statement> statementStream = constraintParameterStatementStream(entityIdValue, snakGroupList);
|
||||
List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList);
|
||||
|
||||
ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
|
||||
when(fetcher.getConstraintsByType(conflictsWithPid, "Q21502838")).thenReturn(statementStream);
|
||||
when(fetcher.getConstraintsByType(conflictsWithPid, "Q21502838")).thenReturn(statementList);
|
||||
|
||||
setFetcher(fetcher);
|
||||
scrutinize(updateA);
|
||||
@ -143,11 +142,10 @@ public class ConflictsWithScrutinizerTest extends ScrutinizerTest {
|
||||
|
||||
ItemUpdate updateA = new ItemUpdateBuilder(idA).addStatement(statement).build();
|
||||
|
||||
List<Statement> statements = new ArrayList<>();
|
||||
Stream<Statement> statementStream = statements.stream();
|
||||
List<Statement> statementList = new ArrayList<>();
|
||||
|
||||
ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
|
||||
when(fetcher.getConstraintsByType(propertyWithConflictsPid1, "Q21502838")).thenReturn(statementStream);
|
||||
when(fetcher.getConstraintsByType(propertyWithConflictsPid1, "Q21502838")).thenReturn(statementList);
|
||||
|
||||
setFetcher(fetcher);
|
||||
scrutinize(updateA);
|
||||
@ -177,10 +175,10 @@ public class ConflictsWithScrutinizerTest extends ScrutinizerTest {
|
||||
SnakGroup snakGroup1 = Datamodel.makeSnakGroup(snakList1);
|
||||
SnakGroup snakGroup2 = Datamodel.makeSnakGroup(snakList2);
|
||||
List<SnakGroup> snakGroupList = Arrays.asList(snakGroup1, snakGroup2);
|
||||
Stream<Statement> statementStream = constraintParameterStatementStream(entityIdValue, snakGroupList);
|
||||
List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList);
|
||||
|
||||
ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
|
||||
when(fetcher.getConstraintsByType(conflictsWithPid, "Q21502838")).thenReturn(statementStream);
|
||||
when(fetcher.getConstraintsByType(conflictsWithPid, "Q21502838")).thenReturn(statementList);
|
||||
|
||||
setFetcher(fetcher);
|
||||
scrutinize(updateA);
|
||||
|
@ -16,7 +16,6 @@ import org.wikidata.wdtk.datamodel.interfaces.Value;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
@ -50,9 +49,9 @@ public class MultiValueScrutinizerTest extends ScrutinizerTest {
|
||||
List<Snak> snakList1 = Collections.singletonList(snak);
|
||||
SnakGroup snakGroup = Datamodel.makeSnakGroup(snakList1);
|
||||
List<SnakGroup> snakGroupList = Collections.singletonList(snakGroup);
|
||||
Stream<Statement> statementStream = constraintParameterStatementStream(entityIdValue, snakGroupList);
|
||||
List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList);
|
||||
ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
|
||||
when(fetcher.getConstraintsByType(propertyIdValue, "Q21510857")).thenReturn(statementStream);
|
||||
when(fetcher.getConstraintsByType(propertyIdValue, "Q21510857")).thenReturn(statementList);
|
||||
setFetcher(fetcher);
|
||||
|
||||
scrutinize(update);
|
||||
@ -72,9 +71,9 @@ public class MultiValueScrutinizerTest extends ScrutinizerTest {
|
||||
List<Snak> snakList1 = Collections.singletonList(snak);
|
||||
SnakGroup snakGroup = Datamodel.makeSnakGroup(snakList1);
|
||||
List<SnakGroup> snakGroupList = Collections.singletonList(snakGroup);
|
||||
Stream<Statement> statementStream = constraintParameterStatementStream(entityIdValue, snakGroupList);
|
||||
List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList);
|
||||
ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
|
||||
when(fetcher.getConstraintsByType(propertyIdValue, "Q21510857")).thenReturn(statementStream);
|
||||
when(fetcher.getConstraintsByType(propertyIdValue, "Q21510857")).thenReturn(statementList);
|
||||
setFetcher(fetcher);
|
||||
|
||||
scrutinize(updateA, updateB);
|
||||
@ -94,9 +93,9 @@ public class MultiValueScrutinizerTest extends ScrutinizerTest {
|
||||
List<Snak> snakList1 = Collections.singletonList(snak);
|
||||
SnakGroup snakGroup = Datamodel.makeSnakGroup(snakList1);
|
||||
List<SnakGroup> snakGroupList = Collections.singletonList(snakGroup);
|
||||
Stream<Statement> statementStream = constraintParameterStatementStream(entityIdValue, snakGroupList);
|
||||
List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList);
|
||||
ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
|
||||
when(fetcher.getConstraintsByType(propertyIdValue, "Q21510857")).thenReturn(statementStream);
|
||||
when(fetcher.getConstraintsByType(propertyIdValue, "Q21510857")).thenReturn(statementList);
|
||||
setFetcher(fetcher);
|
||||
|
||||
scrutinize(updateA, updateB);
|
||||
|
@ -44,7 +44,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
@ -96,7 +95,7 @@ public abstract class ScrutinizerTest {
|
||||
scrutinizer.setFetcher(fetcher);
|
||||
}
|
||||
|
||||
public Stream<Statement> constraintParameterStatementStream(ItemIdValue itemIdValue, List<SnakGroup> listSnakGroup) {
|
||||
public List<Statement> constraintParameterStatementList(ItemIdValue itemIdValue, List<SnakGroup> listSnakGroup) {
|
||||
PropertyIdValue propertyIdValue = Datamodel.makeWikidataPropertyIdValue("P2302");
|
||||
Snak snakValue = Datamodel.makeValueSnak(propertyIdValue,itemIdValue);
|
||||
|
||||
@ -108,7 +107,7 @@ public abstract class ScrutinizerTest {
|
||||
Statement statement = Datamodel.makeStatement(claim, referenceList, StatementRank.NORMAL, "P2302$77BD7FE4-C051-4776-855C-543F0CE697D0");
|
||||
List<Statement> statements = Collections.singletonList(statement);
|
||||
|
||||
return statements.stream();
|
||||
return statements;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user