本文整理汇总了Java中ch.lambdaj.Lambda类的典型用法代码示例。如果您正苦于以下问题:Java Lambda类的具体用法?Java Lambda怎么用?Java Lambda使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Lambda类属于ch.lambdaj包,在下文中一共展示了Lambda类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calculateCloud
import ch.lambdaj.Lambda; //导入依赖的package包/类
private Map<String, Integer> calculateCloud(List<String> texts, WordTokenizer tokenizer) {
final Map<String, Integer> cloud = new HashMap<>();
for(String text : texts) {
final List<String> words = Lambda.filter(stopWordFilter, tokenizer.tokenize(sanitizer.sanitize(text)));
for(String word : words) {
word = StringUtils.trimToEmpty(word).toLowerCase();
if(StringUtils.isNotBlank(word)) {
if(cloud.containsKey(word)) {
cloud.put(word, cloud.get(word) + 1);
} else {
cloud.put(word, 1);
}
}
}
}
return cloud;
}
示例2: testStatusMessageService
import ch.lambdaj.Lambda; //导入依赖的package包/类
@Test
public void testStatusMessageService() {
statusMessageService.error(ERROR_MSG, MODULE_NAME, TIMEOUT);
statusMessageService.warn(WARNING_MSG, MODULE_NAME, TIMEOUT);
statusMessageService.debug(DEBUG_MSG, MODULE_NAME, TIMEOUT);
List<StatusMessage> messages = statusMessageService.getActiveMessages();
messages = Lambda.filter(having(on(StatusMessage.class).getTimeout(), equalTo(TIMEOUT)), messages);
assertFalse(messages.isEmpty());
StatusMessage msg = findMsgByText(messages, ERROR_MSG);
assertEquals(Level.ERROR, msg.getLevel());
assertEquals(MODULE_NAME, msg.getModuleName());
msg = findMsgByText(messages, WARNING_MSG);
assertEquals(Level.WARN, msg.getLevel());
assertEquals(MODULE_NAME, msg.getModuleName());
msg = findMsgByText(messages, DEBUG_MSG);
assertEquals(Level.DEBUG, msg.getLevel());
assertEquals(MODULE_NAME, msg.getModuleName());
}
示例3: shouldReturnEnrollmentsThatMatchGivenStatus
import ch.lambdaj.Lambda; //导入依赖的package包/类
@Test
public void shouldReturnEnrollmentsThatMatchGivenStatus() {
DateTime now = now();
createEnrollment("entity_1", "IPTI Schedule", "IPTI 1", now, now(), new Time(8, 10), EnrollmentStatus.COMPLETED, null);
createEnrollment("entity_2", "Delivery", "Default", now, now(), new Time(8, 10), EnrollmentStatus.DEFAULTED, null);
createEnrollment("entity_3", "IPTI Schedule", "IPTI 1", now, now(), new Time(8, 10), EnrollmentStatus.UNENROLLED, null);
createEnrollment("entity_4", "IPTI Schedule", "IPTI 1", now, now(), new Time(8, 10), EnrollmentStatus.ACTIVE, null);
List<Enrollment> filteredEnrollments = enrollmentDataService.findByStatus(EnrollmentStatus.ACTIVE);
assertEquals(asList(new String[] { "entity_4"}), Lambda.extract(filteredEnrollments, on(Enrollment.class).getExternalId()));
filteredEnrollments = enrollmentDataService.findByStatus(EnrollmentStatus.DEFAULTED);
assertNotNull(filteredEnrollments.get(0).getSchedule());
assertEquals(asList(new String[] { "entity_2"}), Lambda.extract(filteredEnrollments, on(Enrollment.class).getExternalId()));
}
示例4: getCurrentId
import ch.lambdaj.Lambda; //导入依赖的package包/类
private long getCurrentId(Map<String, Long> stepReferences, Deque<Step> steps) {
Long currentId;
long max = Lambda.max(stepReferences);
Map.Entry maxEntry = selectFirst(stepReferences.entrySet(),
having(on(Map.Entry.class).getValue(), equalTo(max)));
String referenceKey = (String) (maxEntry).getKey();
Step step = null;
for (Step stepItem : steps) {
if (stepItem.getName().equals(referenceKey)) {
step = stepItem;
break;
}
}
if (step == null || !step.isParallelLoop()) {
// the reference is not a step or is not a parallel loop step
currentId = max + NUMBER_OF_STEP_EXECUTION_STEPS;
} else {
//async step
currentId = max + NUMBER_OF_STEP_EXECUTION_STEPS + NUMBER_OF_PARALLEL_LOOP_EXECUTION_STEPS;
}
return currentId;
}
示例5: ParallelAcceptanceTestSuite
import ch.lambdaj.Lambda; //导入依赖的package包/类
public ParallelAcceptanceTestSuite() {
Integer agentPosition = Integer.parseInt(System.getProperty("parallel.agent.number"));
Integer agentCount = Integer.parseInt(System.getProperty("parallel.agent.total"));
List storyPaths = storyPaths();
failIfAgentIsNotConfiguredCorrectly(agentPosition, agentCount);
failIfThereAreMoreAgentsThanStories(agentCount, storyPaths.size());
int reminder = storyPaths.size() % agentCount; // The reminder should work out to be either be zero or one.
int storiesPerAgent = storyPaths.size() / agentCount;
int startPos = storiesPerAgent * (agentPosition - 1);
int endPos = startPos + storiesPerAgent;
if (agentPosition == agentCount)
{
// In the case of an uneven number the last agent picks up the extra story file.
endPos += reminder;
}
List stories = storyPaths.subList(startPos, endPos);
outputWhichStoriesAreBeingRun(stories);
findStoriesCalled(Lambda.join(stories, ";"));
}
示例6: complete
import ch.lambdaj.Lambda; //导入依赖的package包/类
@Override
public int complete(String buffer, int cursor, List<CharSequence> candidates) {
Preconditions.checkNotNull(candidates);
String text = contextualBuffer(buffer, cursor);
List<String> commands = Lambda.filter(StringStartsWith.startsWith(text), this.commands);
if(commands.size()>0) {
candidates.addAll(commands);
if(candidates.size()==1) {
candidates.set(0, candidates.get(0) + " ");
}
return candidates.isEmpty() ? -1 : 0;
} else if(text.contains(" ")) {
int insertion = text.lastIndexOf(" ") + 1;
String tailBuffer = text.substring(insertion);
List<String> files = Lambda.convert(Lambda.convert(SpashFileSystem.get().ls(this.session.getWorkingDir()).collect(), new PropertyExtractor<Object, Path>("fileName")), new DefaultStringConverter());
files = Lambda.filter(StringStartsWith.startsWith(tailBuffer), files);
candidates.addAll(files);
if(candidates.size()==1) {
candidates.set(0, candidates.get(0) + " ");
}
return candidates.isEmpty() ? -1 : insertion;
}
return -1;
}
示例7: map
import ch.lambdaj.Lambda; //导入依赖的package包/类
@Override
public <R> SpashCollection<R> map(final SerializableFunction<T, R> f) {
return new SpashCollectionListAdapter<>(Lambda.convert(target, new Converter<T, R>() {
@Override
public R convert(T t) {
return f.apply(t);
}
}));
}
示例8: filter
import ch.lambdaj.Lambda; //导入依赖的package包/类
@Override
public SpashCollection<T> filter(final SerializableFunction<T, Boolean> condition) {
return new SpashCollectionListAdapter<>(Lambda.filter(new BaseMatcher<T>() {
@Override
public boolean matches(Object o) {
return condition.apply((T) o);
}
@Override
public void describeTo(Description description) {
}
}, target));
}
示例9: execute
import ch.lambdaj.Lambda; //导入依赖的package包/类
@Override
public CommandResult execute(ExecutionContext ctx) {
List<String> args = this.getArguments();
if(args.size()==0) {
return CommandResult.error(this, "Missing argument");
} else if(args.size()==1) {
// pipe mode
SpashCollection<String> prev = ctx.getPreviousCommandResult() != null ? ctx.getPreviousCommandResult().getContent() : null;
if(prev==null) {
prev = new SpashCollectionEmptyAdapter<>();
}
return execute(ctx, prev);
} else {
// cat mode
String catCmdString = "cat " + Lambda.join(args.subList(1, args.size()), " ");
Command cat = CommandFactory.getInstance().getCommand(catCmdString);
CommandResult res = cat.execute(ctx);
if(!res.isSuccess()) {
return CommandResult.error(this, res.getErrorMessage());
}
return execute(ctx, res.getContent());
}
}
示例10: ExpressionTokenizer
import ch.lambdaj.Lambda; //导入依赖的package包/类
public ExpressionTokenizer(String arg) {
if(arg==null) {
throw new IllegalArgumentException("Null string");
}
if(containsUnquoted(arg, "||")) {
throw new IllegalArgumentException("Unexpected sequence: '||'");
}
if(containsUnquoted(arg, ">>>")) {
throw new IllegalArgumentException("Unexpected sequence: '>>>'");
}
List<String> piped = splitUnquoted(arg, "|");
LinkedList<String> exprs = new LinkedList<>(Lambda.convert(piped, new Converter<String, String>() {
@Override
public String convert(String s) {
return s.trim();
}
}));
this.commandStrings = new ArrayList<>();
while(!exprs.isEmpty()) {
String expr = exprs.poll();
Integer start = minPositive(indexOfUnquoted(expr, " "), indexOfUnquoted(expr, "\t"), indexOfUnquoted(expr, "\r"), indexOfUnquoted(expr, "\n"));
if(start==null) {
this.commandStrings.add(expr.trim());
continue;
}
int idx = indexOfUnquoted(expr, ">", start);
if(idx>0) {
String first = expr.substring(0, idx).trim();
this.commandStrings.add(first);
exprs.addFirst(expr.substring(idx).trim());
} else {
this.commandStrings.add(expr.trim());
}
}
}
示例11: findMsgByText
import ch.lambdaj.Lambda; //导入依赖的package包/类
private StatusMessage findMsgByText(List<StatusMessage> messages, String text) {
List<StatusMessage> found = Lambda.filter(having(on(StatusMessage.class).getText(), equalTo(text)), messages);
assertTrue("No matching message for: " + text, found.size() > 0);
assertFalse("Found more then one matching message for: " + text, found.size() > 1);
return found.get(0);
}
示例12: verifyMultiLookup
import ch.lambdaj.Lambda; //导入依赖的package包/类
private void verifyMultiLookup(int lookupParam, String... expectedStrings)
throws Exception {
HttpGet get = new HttpGet(ENTITY_URL + "?lookup=byInt&intField=" + lookupParam +
"&sort=strField&order=ASC");
String responseBody = getHttpClient().execute(get, new BasicResponseHandler());
RestResponse response = OBJECT_MAPPER.readValue(responseBody, RestResponse.class);
List strings = Lambda.extract(response.getData(), PropertyUtils.getProperty(on(RestProjection.class), "strField"));
assertEquals(asList(expectedStrings), strings);
}
示例13: shouldReturnEnrollmentsThatMatchAGivenExternalId
import ch.lambdaj.Lambda; //导入依赖的package包/类
@Test
public void shouldReturnEnrollmentsThatMatchAGivenExternalId() {
DateTime now = now();
createEnrollment("entity_1", "IPTI Schedule", "IPTI 1", now, now(), new Time(8, 10), EnrollmentStatus.ACTIVE, null);
createEnrollment("entity_1", "Delivery", "Default", now, now(), new Time(8, 10), EnrollmentStatus.ACTIVE, null);
createEnrollment("entity_2", "IPTI Schedule", "IPTI 1", now, now(), new Time(8, 10), EnrollmentStatus.ACTIVE, null);
createEnrollment("entity_3", "IPTI Schedule", "IPTI 1", now, now(), new Time(8, 10), EnrollmentStatus.ACTIVE, null);
List<Enrollment> filteredEnrollments = enrollmentDataService.findByExternalId("entity_1");
assertNotNull(filteredEnrollments.get(0).getSchedule());
assertEquals(asList(new String[] { "entity_1", "entity_1"}), Lambda.extract(filteredEnrollments, on(Enrollment.class).getExternalId()));
}
示例14: shouldFindenrollmentDataServiceThatMatchesGivenScheduleNames
import ch.lambdaj.Lambda; //导入依赖的package包/类
@Test
public void shouldFindenrollmentDataServiceThatMatchesGivenScheduleNames() {
createEnrollment("entity_1", "IPTI Schedule", "IPTI 1", now(), now(), new Time(DateUtil.now().toLocalTime()), EnrollmentStatus.ACTIVE, null);
createEnrollment("entity_2", "Absolute Schedule", "milestone1", now(), now(), new Time(DateUtil.now().toLocalTime()), EnrollmentStatus.ACTIVE, null);
createEnrollment("entity_3", "Relative Schedule", "milestone1", now(), now(), new Time(DateUtil.now().toLocalTime()), EnrollmentStatus.ACTIVE, null);
createEnrollment("entity_4", "Relative Schedule", "milestone1", now(), now(), new Time(DateUtil.now().toLocalTime()), EnrollmentStatus.ACTIVE, null);
List<Enrollment> filteredEnrollments = allEnrollments.findBySchedule(asList(new String[]{"IPTI Schedule", "Relative Schedule"}));
assertEquals(3, filteredEnrollments.size());
assertEquals(asList(new String[]{"entity_1", "entity_3", "entity_4"}), Lambda.extract(filteredEnrollments, on(Enrollment.class).getExternalId()));
assertEquals(asList(new String[] {"IPTI Schedule", "Relative Schedule", "Relative Schedule"}), Lambda.extract(filteredEnrollments, on(Enrollment.class).getScheduleName()));
}
示例15: shouldReturnEnrollmentsThatWereCompletedDuringTheGivenTimeRange
import ch.lambdaj.Lambda; //导入依赖的package包/类
@Test
public void shouldReturnEnrollmentsThatWereCompletedDuringTheGivenTimeRange() {
LocalDate today = today();
scheduleTrackingService.enroll(new EnrollmentRequest().setExternalId("entity_1").setScheduleName("IPTI Schedule").setPreferredAlertTime(new Time(8, 10)).setReferenceDate(today).setReferenceTime(null).setEnrollmentDate(today).setEnrollmentTime(null).setStartingMilestoneName("IPTI 1").setMetadata(null));
scheduleTrackingService.enroll(new EnrollmentRequest().setExternalId("entity_2").setScheduleName("IPTI Schedule").setPreferredAlertTime(new Time(8, 10)).setReferenceDate(today.minusWeeks(2)).setReferenceTime(null).setEnrollmentDate(today.minusWeeks(2)).setEnrollmentTime(null).setStartingMilestoneName("IPTI 1").setMetadata(null));
scheduleTrackingService.fulfillCurrentMilestone("entity_2", "IPTI Schedule", today.minusDays(2), new Time(0, 0));
scheduleTrackingService.fulfillCurrentMilestone("entity_2", "IPTI Schedule", today.minusDays(1), new Time(0, 0));
scheduleTrackingService.enroll(new EnrollmentRequest().setExternalId("entity_3").setScheduleName("IPTI Schedule").setPreferredAlertTime(new Time(8, 10)).setReferenceDate(today).setReferenceTime(null).setEnrollmentDate(today).setEnrollmentTime(null).setStartingMilestoneName("IPTI 2").setMetadata(null));
scheduleTrackingService.fulfillCurrentMilestone("entity_3", "IPTI Schedule", today, new Time(0, 0));
scheduleTrackingService.enroll(new EnrollmentRequest().setExternalId("entity_4").setScheduleName("IPTI Schedule").setPreferredAlertTime(new Time(8, 10)).setReferenceDate(today.minusYears(2)).setReferenceTime(null).setEnrollmentDate(today).setEnrollmentTime(null).setStartingMilestoneName("IPTI 1").setMetadata(null));
scheduleTrackingService.enroll(new EnrollmentRequest().setExternalId("entity_5").setScheduleName("IPTI Schedule").setPreferredAlertTime(new Time(8, 10)).setReferenceDate(today.minusWeeks(2)).setReferenceTime(null).setEnrollmentDate(today.minusWeeks(2)).setEnrollmentTime(null).setStartingMilestoneName("IPTI 1").setMetadata(null));
scheduleTrackingService.fulfillCurrentMilestone("entity_5", "IPTI Schedule", today.minusDays(10), new Time(0, 0));
scheduleTrackingService.fulfillCurrentMilestone("entity_5", "IPTI Schedule", today.minusDays(9), new Time(0, 0));
DateTime start = newDateTime(today.minusWeeks(1), new Time(0, 0));
DateTime end = newDateTime(today, new Time(0, 0));
List<Enrollment> filteredEnrollments = allEnrollments.completedDuring(start, end);
List<String> extractedEnrollments = Lambda.extract(filteredEnrollments, on(Enrollment.class).getExternalId());
Collections.sort(extractedEnrollments);
assertNotNull(filteredEnrollments.get(0).getSchedule());
assertEquals(asList(new String[] { "entity_2", "entity_3" }), extractedEnrollments);
}