本文整理匯總了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());
}