本文整理汇总了Java中org.apache.commons.collections4.IteratorUtils类的典型用法代码示例。如果您正苦于以下问题:Java IteratorUtils类的具体用法?Java IteratorUtils怎么用?Java IteratorUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IteratorUtils类属于org.apache.commons.collections4包,在下文中一共展示了IteratorUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findAll
import org.apache.commons.collections4.IteratorUtils; //导入依赖的package包/类
@Override
public Page<T> findAll(final Set<T> groups, final String criteria, final Pageable pageable, final Map<String, Comparator<T>> customComparators) {
// Create the set with the right comparator
final List<Sort.Order> orders = IteratorUtils.toList(ObjectUtils.defaultIfNull(pageable.getSort(), new ArrayList<Sort.Order>()).iterator());
orders.add(DEFAULT_ORDER);
final Sort.Order order = orders.get(0);
Comparator<T> comparator = customComparators.get(order.getProperty());
if (order.getDirection() == Direction.DESC) {
comparator = Collections.reverseOrder(comparator);
}
final Set<T> result = new TreeSet<>(comparator);
// Filter the groups, filtering by the criteria
addFilteredByPattern(groups, criteria, result);
// Apply in-memory pagination
return inMemoryPagination.newPage(result, pageable);
}
示例2: receiveLocked
import org.apache.commons.collections4.IteratorUtils; //导入依赖的package包/类
/**
* Just received a locked message. Must acknowledge it.
*
* @param from
* The node that sent the locked message.
* @param to
* The node that must acknowledge the locked message.
*/
private void receiveLocked(Node from, Node to) {
MUnlockBroadcast mu = new MUnlockBroadcast(from, to);
Transport t = ((Transport) this.node.getProtocol(FastConfig.getTransport(PreventiveCausalBroadcast.pid)));
APeerSampling ps = (APeerSampling) this.node.getProtocol(FastConfig.getLinkable(PreventiveCausalBroadcast.pid));
List<Node> neighborhood = IteratorUtils.toList(ps.getAliveNeighbors().iterator());
if (neighborhood.contains(from)) {
t.send(this.node, from, mu, PreventiveCausalBroadcast.pid);
} else {
// just to check if it cannot send message because it has no
PreventiveCausalBroadcast fcb = (PreventiveCausalBroadcast) from.getProtocol(PreventiveCausalBroadcast.pid);
if (fcb.buffers.containsKey(to)) {
System.out.println("NOT COOL");
}
}
}
示例3: ProjectConfigurationBuilder
import org.apache.commons.collections4.IteratorUtils; //导入依赖的package包/类
public ProjectConfigurationBuilder(ProjectConfiguration projectConfiguration) {
if (projectConfiguration == null) {
admins = new ArrayList<>();
users = new ArrayList<>();
stackConfigurations = new HashSet<>();
} else {
identifier = projectConfiguration.getIdentifier();
entityIdentifier = projectConfiguration.getEntityIdentifier();
name = projectConfiguration.getName();
userService = projectConfiguration.getUserService();
admins = IteratorUtils.toList(projectConfiguration.getTeamLeaders());
users = IteratorUtils.toList(projectConfiguration.getUsers());
stackConfigurations = new HashSet<>(projectConfiguration.getStackConfigurations());
}
}
示例4: RightEndpointActor
import org.apache.commons.collections4.IteratorUtils; //导入依赖的package包/类
public RightEndpointActor() {
receive(ReceiveBuilder.match(UserAdminRightRequestMsg.class, msg -> {
ProjectConfiguration projectConfiguration = msg.projectConfiguration;
User user = msg.getRequester();
List<User> users = IteratorUtils.toList(projectConfiguration.getTeamLeaders());
boolean valid = false;
if (CollectionUtils.isNotEmpty(users)) {
if (LOGGER.isDebugEnabled()) {
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().setPrettyPrinting().create();
LOGGER.debug("lookup right for user Id '{}' on following projectConfig:\n{}", user.getIdentifier(), gson.toJson(projectConfiguration));
}
valid = users.stream().filter(u -> u.getIdentifier().equals(user.getIdentifier())).findFirst().isPresent();
}
sender().tell(new RightRequestResultMsg(user, msg, valid), self());
getContext().stop(self());
})
.matchAny(this::unhandled).build());
}
示例5: removeUserToOrganisation
import org.apache.commons.collections4.IteratorUtils; //导入依赖的package包/类
@Override
public void removeUserToOrganisation(String userIdentifier, String organisationIdentifier) {
if (isBlank(userIdentifier)) {
throw new IllegalArgumentException("userIdentifier must be defined.");
}
if (isBlank(organisationIdentifier)) {
throw new IllegalArgumentException("organisationIdentifier must be defined.");
}
organisationStore.removeUserToOrganisation(userIdentifier, organisationIdentifier);
User user = getUserByIdentifier(userIdentifier);
removeUserToOrganisationOnUserRedis(organisationIdentifier, user);
OrganisationStoreModel organisationStoreModel = organisationStore.getOrganisationById(organisationIdentifier);
organisationStoreModel.getProjectConfigurations().stream()
.forEach(projectConfigurationId -> {
ProjectConfigurationStoreModel projectConfigurationModel = projectStore.getProjectConfigurationById(projectConfigurationId);
ProjectConfiguration projectConfiguration = convertToProjectConfiguration(projectConfigurationModel);
ProjectConfigurationBuilder builder = new ProjectConfigurationBuilder(projectConfiguration);
List<User> users = IteratorUtils.toList(projectConfiguration.getUsers());
users.remove(user);
builder.setUsers(users);
updateProjectConfiguration(builder.build());
});
}
示例6: addAdminToOrganisation
import org.apache.commons.collections4.IteratorUtils; //导入依赖的package包/类
@Override
public void addAdminToOrganisation(String userIdentifier, String organisationIdentifier) {
if (isBlank(userIdentifier)) {
throw new IllegalArgumentException("userIdentifier must be defined.");
}
if (isBlank(organisationIdentifier)) {
throw new IllegalArgumentException("organisationIdentifier must be defined.");
}
User adminUser = getUserByIdentifier(userIdentifier);
organisationStore.addAdminToOrganisation(userIdentifier, organisationIdentifier);
addUserToOrganisationOnUserRedis(organisationIdentifier, adminUser);
OrganisationStoreModel organisationStoreModel = organisationStore.getOrganisationById(organisationIdentifier);
organisationStoreModel.getProjectConfigurations().stream()
.forEach(projectConfigurationId -> {
ProjectConfigurationStoreModel projectConfigurationModel = projectStore.getProjectConfigurationById(projectConfigurationId);
ProjectConfiguration projectConfiguration = convertToProjectConfiguration(projectConfigurationModel);
ProjectConfigurationBuilder builder = new ProjectConfigurationBuilder(projectConfiguration);
List<User> teamLeaders = IteratorUtils.toList(projectConfiguration.getTeamLeaders());
teamLeaders.add(adminUser);
builder.setAdmins(teamLeaders);
updateProjectConfiguration(builder.build());
});
}
示例7: removeAdminToOrganisation
import org.apache.commons.collections4.IteratorUtils; //导入依赖的package包/类
@Override
public void removeAdminToOrganisation(String userIdentifier, String organisationIdentifier) {
if (isBlank(userIdentifier)) {
throw new IllegalArgumentException("userIdentifier must be defined.");
}
if (isBlank(organisationIdentifier)) {
throw new IllegalArgumentException("organisationIdentifier must be defined.");
}
User adminUser = getUserByIdentifier(userIdentifier);
organisationStore.removeAdminToOrganisation(userIdentifier, organisationIdentifier);
removeUserToOrganisationOnUserRedis(organisationIdentifier, getUserByIdentifier(userIdentifier));
OrganisationStoreModel organisationStoreModel = organisationStore.getOrganisationById(organisationIdentifier);
organisationStoreModel.getProjectConfigurations().stream()
.forEach(projectConfigurationId -> {
ProjectConfigurationStoreModel projectConfigurationModel = projectStore.getProjectConfigurationById(projectConfigurationId);
ProjectConfiguration projectConfiguration = convertToProjectConfiguration(projectConfigurationModel);
ProjectConfigurationBuilder builder = new ProjectConfigurationBuilder(projectConfiguration);
List<User> teamLeaders = IteratorUtils.toList(projectConfiguration.getTeamLeaders());
teamLeaders.remove(adminUser);
builder.setAdmins(teamLeaders);
updateProjectConfiguration(builder.build());
}
);
}
示例8: createRegisterSerialisationFormat_returnsRSFFromEntireRegister
import org.apache.commons.collections4.IteratorUtils; //导入依赖的package包/类
@Test
public void createRegisterSerialisationFormat_returnsRSFFromEntireRegister() {
when(register.getItemIterator()).thenReturn(Arrays.asList(item1, item2).iterator());
when(register.getDerivationEntryIterator(IndexFunctionConfiguration.IndexNames.METADATA)).thenReturn(Collections.emptyIterator());
when(register.getEntryIterator()).thenReturn(Arrays.asList(entry1, entry2).iterator());
RegisterProof expectedRegisterProof = new RegisterProof(new HashValue(HashingAlgorithm.SHA256, "1231234"), 46464);
when(register.getRegisterProof()).thenReturn(expectedRegisterProof);
RegisterSerialisationFormat actualRSF = sutCreator.create(register);
List<RegisterCommand> actualCommands = IteratorUtils.toList(actualRSF.getCommands());
verify(register, times(1)).getItemIterator();
verify(register, times(1)).getEntryIterator();
verify(register, times(1)).getRegisterProof();
assertThat(actualCommands.size(), equalTo(6));
assertThat(actualCommands, contains(
assertEmptyRootHashCommand,
addItem1Command,
addItem2Command,
appendEntry1Command,
appendEntry2Command,
new RegisterCommand("assert-root-hash", Collections.singletonList("sha-256:1231234"))
));
}
示例9: createRegisterSerialisationFormat_returnsRSFFromEntireIndex
import org.apache.commons.collections4.IteratorUtils; //导入依赖的package包/类
@Test
public void createRegisterSerialisationFormat_returnsRSFFromEntireIndex() {
when(register.getItemIterator()).thenReturn(Arrays.asList(item1, item2).iterator());
when(register.getDerivationEntryIterator(IndexNames.METADATA)).thenReturn(Collections.emptyIterator());
when(register.getDerivationEntryIterator("index")).thenReturn(Arrays.asList(entry1, entry2).iterator());
RegisterSerialisationFormat actualRSF = sutCreator.create(register, "index");
List<RegisterCommand> actualCommands = IteratorUtils.toList(actualRSF.getCommands());
verify(register, times(1)).getItemIterator();
verify(register, times(1)).getDerivationEntryIterator("index");
assertThat(actualCommands.size(), equalTo(5));
assertThat(actualCommands, contains(
assertEmptyRootHashCommand,
addItem1Command,
addItem2Command,
appendEntry1Command,
appendEntry2Command
));
}
示例10: createRegisterSerialisationFormat_whenCalledWithBoundary_returnsPartialRSFRegister
import org.apache.commons.collections4.IteratorUtils; //导入依赖的package包/类
@Test
public void createRegisterSerialisationFormat_whenCalledWithBoundary_returnsPartialRSFRegister() {
RegisterProof oneEntryRegisterProof = new RegisterProof(new HashValue(HashingAlgorithm.SHA256, "oneEntryInRegisterHash"), 1);
RegisterProof twoEntriesRegisterProof = new RegisterProof(new HashValue(HashingAlgorithm.SHA256, "twoEntriesInRegisterHash"), 2);
when(register.getItemIterator(1, 2)).thenReturn(Collections.singletonList(item1).iterator());
when(register.getEntryIterator(1, 2)).thenReturn(Collections.singletonList(entry1).iterator());
when(register.getRegisterProof(1)).thenReturn(oneEntryRegisterProof);
when(register.getRegisterProof(2)).thenReturn(twoEntriesRegisterProof);
RegisterSerialisationFormat actualRSF = sutCreator.create(register, 1, 2);
List<RegisterCommand> actualCommands = IteratorUtils.toList(actualRSF.getCommands());
verify(register, times(1)).getItemIterator(1, 2);
verify(register, times(1)).getEntryIterator(1, 2);
assertThat(actualCommands.size(), equalTo(4));
assertThat(actualCommands, contains(
new RegisterCommand("assert-root-hash", Collections.singletonList(oneEntryRegisterProof.getRootHash().encode())),
addItem1Command,
appendEntry1Command,
new RegisterCommand("assert-root-hash", Collections.singletonList(twoEntriesRegisterProof.getRootHash().encode()))
));
}
示例11: createRegisterSerialisationFormat_throwsAnExceptionForUnknownMapperType
import org.apache.commons.collections4.IteratorUtils; //导入依赖的package包/类
@Test
public void createRegisterSerialisationFormat_throwsAnExceptionForUnknownMapperType() throws Exception {
when(register.getItemIterator()).thenReturn(Arrays.asList(item1, item2).iterator());
when(register.getDerivationEntryIterator(IndexFunctionConfiguration.IndexNames.METADATA)).thenReturn(Collections.emptyIterator());
when(register.getEntryIterator()).thenReturn(Arrays.asList(entry1, entry2).iterator());
RegisterProof expectedRegisterProof = new RegisterProof(new HashValue(HashingAlgorithm.SHA256, "1231234"), 28828);
when(register.getRegisterProof()).thenReturn(expectedRegisterProof);
expectedException.expect(RuntimeException.class);
expectedException.expectMessage("Mapper not registered for class: uk.gov.register.util.HashValue");
RSFCreator creatorWithoutMappers = new RSFCreator();
RegisterSerialisationFormat rsf = creatorWithoutMappers.create(register);
IteratorUtils.toList(rsf.getCommands());
}
示例12: comparePathFilters
import org.apache.commons.collections4.IteratorUtils; //导入依赖的package包/类
private Map<PathNodeFilterSet, PathNodeFilterSet> comparePathFilters(final Set<PathNodeFilterSet> filters1,
final Set<PathNodeFilterSet> filters2, final Map<Path, Path> pathMap) {
if (filters1.size() == 0) return new HashMap<>();
final Iterator<PathNodeFilterSet> iterator = filters1.iterator();
final PathNodeFilterSet filter1 = iterator.next();
iterator.remove();
try {
for (final PathNodeFilterSet filter2 : IteratorUtils
.asIterable(pool.getEqualFilters(filter1).stream().filter(f -> filters2.contains(f)).iterator())) {
final Map<Path, Path> tmpPathMap = new HashMap<>(pathMap);
if (PathNodeFilterSet.equals(filter1, filter2, tmpPathMap)) {
final Map<PathNodeFilterSet, PathNodeFilterSet> filterMap =
comparePathFilters(filters1, filters2, tmpPathMap);
if (null != filterMap) {
filterMap.put(filter1, filter2);
return filterMap;
}
}
}
return null;
} finally {
filters1.add(filter1);
}
}
示例13: getUsed
import org.apache.commons.collections4.IteratorUtils; //导入依赖的package包/类
/**
* Returns input tuples already used in a test case that bind the given variable, considering
* only tuples that are (not) once-only
*/
public Iterator<Tuple> getUsed( VarDef var, final boolean onceOnly)
{
return
getBinds
( IteratorUtils.filteredIterator
( getUsed(),
new Predicate<Tuple>()
{
public boolean evaluate( Tuple tuple)
{
return tuple.isOnce() == onceOnly;
}
}),
var);
}
示例14: getIncluded
import org.apache.commons.collections4.IteratorUtils; //导入依赖的package包/类
/**
* Returns the set of input variables to be included in this combination.
*/
public String[] getIncluded()
{
return
IteratorUtils.toArray
( IteratorUtils.transformedIterator
( includedVars_.iterator(),
new Transformer<VarNamePattern,String>()
{
public String transform( VarNamePattern pattern)
{
return pattern.toString();
}
}),
String.class);
}
示例15: getExcluded
import org.apache.commons.collections4.IteratorUtils; //导入依赖的package包/类
/**
* Returns the set of input variables to be excluded from this combination.
*/
public String[] getExcluded()
{
return
IteratorUtils.toArray
( IteratorUtils.transformedIterator
( excludedVars_.iterator(),
new Transformer<VarNamePattern,String>()
{
public String transform( VarNamePattern pattern)
{
return pattern.toString();
}
}),
String.class);
}