use of java.util.function.Predicate in project LiveLessons by douglascraigschmidt.
the class TestDataFactory method getSharedInput.
/**
* Return the input data in the given @a filename as a list of
* SharedStrings.
*/
public static List<CharSequence> getSharedInput(String filename, String splitter) {
try {
// Convert the filename into a pathname.
URI uri = ClassLoader.getSystemResource(filename).toURI();
// Open the file and get all the bytes.
CharSequence bytes = new String(Files.readAllBytes(Paths.get(uri)));
return // the file into a list of Strings.
Pattern.compile(splitter).splitAsStream(bytes).filter(((Predicate<String>) String::isEmpty).negate()).map(string -> new SharedString(string.toCharArray())).collect(toList());
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of java.util.function.Predicate in project LiveLessons by douglascraigschmidt.
the class TestDataFactory method getSharedInput.
/**
* Return the input data in the given @a filename as a list of
* SharedStrings.
*/
public static List<CharSequence> getSharedInput(String filename, String splitter) {
try {
// Convert the filename into a pathname.
URI uri = ClassLoader.getSystemResource(filename).toURI();
// Open the file and get all the bytes.
CharSequence bytes = new String(Files.readAllBytes(Paths.get(uri)));
return // the file into a list of Strings.
Pattern.compile(splitter).splitAsStream(bytes).filter(((Predicate<String>) String::isEmpty).negate()).map(string -> new SharedString(string.toCharArray())).collect(toList());
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of java.util.function.Predicate in project protoman by spotify.
the class SemverSchemaVersioner method hasMinorVersionChange.
/**
* File additions, removals and renames are considered minor version changes. As are any
* formatting/comment changes to proto files. I.e. adding a type, adding a field, etc. are
* considered minor version changes.
*/
private static boolean hasMinorVersionChange(final String protoPackage, final DescriptorSet current, final DescriptorSet candidate) {
final Predicate<FileDescriptor> predicate = fileDescriptor -> Objects.equals(fileDescriptor.protoPackage(), protoPackage);
final ImmutableMap<String, FileDescriptor> currentFileDescriptors = current.fileDescriptors().stream().filter(predicate).collect(toImmutableMap(FileDescriptor::fullName, Function.identity()));
final ImmutableMap<String, FileDescriptor> candidateFileDescriptors = candidate.fileDescriptors().stream().filter(predicate).collect(toImmutableMap(FileDescriptor::fullName, Function.identity()));
if (!Objects.equals(currentFileDescriptors.keySet(), candidateFileDescriptors.keySet())) {
// .proto files were added or removed
return true;
}
// descriptors. I.e. formatting changes are usually not considered minor version changes.
return currentFileDescriptors.keySet().stream().anyMatch(key -> {
// No files were added or removed, thus currentFd and candidateFd should always be
// non-null
final FileDescriptor currentFd = currentFileDescriptors.get(key);
final FileDescriptor candidateFd = candidateFileDescriptors.get(key);
assert currentFd != null && candidateFd != null;
final DescriptorProtos.FileDescriptorProto currentFdProto = currentFd.toProto().toBuilder().clearSourceCodeInfo().build();
final DescriptorProtos.FileDescriptorProto candidateFdProto = candidateFd.toProto().toBuilder().clearSourceCodeInfo().build();
return !Objects.equals(currentFdProto, candidateFdProto);
});
}
use of java.util.function.Predicate in project protoman by spotify.
the class SemverSchemaVersioner method hasPatchVersionChange.
private static boolean hasPatchVersionChange(final String protoPackage, final DescriptorSet current, final DescriptorSet candidate) {
final Predicate<FileDescriptor> predicate = fileDescriptor -> Objects.equals(fileDescriptor.protoPackage(), protoPackage);
final ImmutableMap<String, FileDescriptor> currentFileDescriptors = current.fileDescriptors().stream().filter(predicate).collect(toImmutableMap(FileDescriptor::fullName, Function.identity()));
final ImmutableMap<String, FileDescriptor> candidateFileDescriptors = candidate.fileDescriptors().stream().filter(predicate).collect(toImmutableMap(FileDescriptor::fullName, Function.identity()));
return currentFileDescriptors.keySet().stream().anyMatch(key -> {
final FileDescriptor currentFd = currentFileDescriptors.get(key);
final FileDescriptor candidateFd = candidateFileDescriptors.get(key);
assert currentFd != null && candidateFd != null;
return !Objects.equals(currentFd.toProto(), candidateFd.toProto());
});
}
use of java.util.function.Predicate in project JGroups by belaban.
the class MessageBatchTest method testRemoveWithFilter.
public void testRemoveWithFilter() {
Predicate<Message> filter = msg -> msg != null && msg.isTransientFlagSet(Message.TransientFlag.OOB_DELIVERED);
MessageBatch batch = new MessageBatch(10);
for (int i = 1; i <= 10; i++) {
Message msg = new Message(null, i);
if (i % 2 == 0)
msg.setTransientFlag(Message.TransientFlag.OOB_DELIVERED);
batch.add(msg);
}
System.out.println("batch = " + batch);
assert batch.size() == 10;
batch.remove(filter);
System.out.println("batch = " + batch);
assert batch.size() == 5;
for (int i = 0; i < 5; i++) batch.add(new Message(null, i).setTransientFlag(Message.TransientFlag.OOB_DELIVERED));
System.out.println("batch = " + batch);
batch.replace(filter, null, false);
assert batch.size() == 9;
}
Aggregations