本文整理汇总了Java中java.util.stream.Stream.count方法的典型用法代码示例。如果您正苦于以下问题:Java Stream.count方法的具体用法?Java Stream.count怎么用?Java Stream.count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.stream.Stream
的用法示例。
在下文中一共展示了Stream.count方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: countBandMembersExternal
import java.util.stream.Stream; //导入方法依赖的package包/类
public static int countBandMembersExternal(List<Artist> artists) {
// BEGIN COUNT_MEMBERS_EXTERNAL
int totalMembers = 0;
for (Artist artist : artists) {
Stream<Artist> members = artist.getMembers();
totalMembers += members.count();
}
// END COUNT_MEMBERS_EXTERNAL
return totalMembers;
}
开发者ID:jinyi233,项目名称:https-github.com-RichardWarburton-java-8-Lambdas-exercises,代码行数:12,代码来源:StreamExercises.java
示例2: loadDefaultAndActiveTheme
import java.util.stream.Stream; //导入方法依赖的package包/类
private void loadDefaultAndActiveTheme()
{
Optional<String> optionalDefaultThemePath =
ApplicationSettings.getSetting(ApplicationSetting.APPLICATION_THEME);
if ( !optionalDefaultThemePath.isPresent() )
{
throw new MissingResourceException(
ApplicationSetting.APPLICATION_THEME.toString() + " was not present in settings.",
this.getClass().getName(),
ApplicationSetting.APPLICATION_THEME.toString());
}
//TODO Check if just name or ends with / \
String tempPath = optionalDefaultThemePath.get();
String defaultThemeDirectoryPath = (tempPath.endsWith("/|\\")) ? tempPath : tempPath + "/";
String defaultThemeName = defaultThemeDirectoryPath.substring(0, defaultThemeDirectoryPath.length() - 1);
String defaultThemePath = themeDirectory + defaultThemeDirectoryPath;
//TODO ensure no duplicate theme names
File defaultThemeDirectory = new File(defaultThemePath);
if ( !defaultThemeDirectory.isDirectory() )
throw new IllegalArgumentException(
"Default theme directory was not a directory. Found: " + defaultThemeDirectory.getAbsolutePath());
Stream<String> themeStream = themes.keySet().stream().filter(themeName -> themeName.equals(defaultThemeName));
if ( themeStream.count() < 1 )
throw new UnsupportedOperationException("Default theme not found.");
themeStream = themes.keySet().stream().filter(themeName -> themeName.equals(defaultThemeName));
defaultTheme = themes.get(themeStream.findFirst().get());
//TODO load active/saved theme from settings file saved json object
}
示例3: newArchive
import java.util.stream.Stream; //导入方法依赖的package包/类
private Archive newArchive(String module, Path path) {
if (path.toString().endsWith(".jmod")) {
return new JmodArchive(module, path);
} else if (path.toString().endsWith(".jar")) {
ModularJarArchive modularJarArchive = new ModularJarArchive(module, path);
Stream<Archive.Entry> signatures = modularJarArchive.entries().filter((entry) -> {
String name = entry.name().toUpperCase(Locale.ENGLISH);
return name.startsWith("META-INF/") && name.indexOf('/', 9) == -1 && (
name.endsWith(".SF") ||
name.endsWith(".DSA") ||
name.endsWith(".RSA") ||
name.endsWith(".EC") ||
name.startsWith("META-INF/SIG-")
);
});
if (signatures.count() != 0) {
if (ignoreSigning) {
System.err.println(taskHelper.getMessage("warn.signing", path));
} else {
throw new IllegalArgumentException(taskHelper.getMessage("err.signing", path));
}
}
return modularJarArchive;
} else if (Files.isDirectory(path)) {
return new DirArchive(path);
} else {
throw new IllegalArgumentException(
taskHelper.getMessage("err.not.modular.format", module, path));
}
}
示例4: checkStreamState
import java.util.stream.Stream; //导入方法依赖的package包/类
void checkStreamState(Stream<StackFrame> stream) {
try {
stream.count();
throw new RuntimeException("IllegalStateException not thrown");
} catch (IllegalStateException e) {
System.out.println("Got expected IllegalStateException: " + e.getMessage());
e.printStackTrace(System.out);
}
}
示例5: testAddRemoveConnectedSwitch
import java.util.stream.Stream; //导入方法依赖的package包/类
/**
* Tests adding and removing connected switches.
*/
@Test
public void testAddRemoveConnectedSwitch() {
// test adding connected switches
boolean addSwitch1 = agent.addConnectedSwitch(dpid1, switch1);
assertThat(addSwitch1, is(true));
boolean addSwitch2 = agent.addConnectedSwitch(dpid2, switch2);
assertThat(addSwitch2, is(true));
boolean addSwitch3 = agent.addConnectedSwitch(dpid3, switch3);
assertThat(addSwitch3, is(true));
// Make sure the listener add callbacks fired
assertThat(switchListener.addedDpids, hasSize(3));
assertThat(switchListener.addedDpids, hasItems(dpid1, dpid2, dpid3));
// Test adding a switch twice - it should fail
boolean addBadSwitch1 = agent.addConnectedSwitch(dpid1, switch1);
assertThat(addBadSwitch1, is(false));
assertThat(controller.connectedSwitches.size(), is(3));
// test querying the switch list
Stream<OpenFlowSwitch> fetchedSwitches =
makeIntoStream(controller.getSwitches());
long switchCount = fetchedSwitches.count();
assertThat(switchCount, is(3L));
// test querying the individual switch
OpenFlowSwitch queriedSwitch = controller.getSwitch(dpid1);
assertThat(queriedSwitch, is(switch1));
// Remove a switch
agent.removeConnectedSwitch(dpid3);
Stream<OpenFlowSwitch> fetchedSwitchesAfterRemove =
makeIntoStream(controller.getSwitches());
long switchCountAfterRemove = fetchedSwitchesAfterRemove.count();
assertThat(switchCountAfterRemove, is(2L));
// Make sure the listener delete callbacks fired
assertThat(switchListener.removedDpids, hasSize(1));
assertThat(switchListener.removedDpids, hasItems(dpid3));
// test querying the removed switch
OpenFlowSwitch queriedSwitchAfterRemove = controller.getSwitch(dpid3);
assertThat(queriedSwitchAfterRemove, nullValue());
}