List of usage examples for java.util.stream Collectors toList
public static <T> Collector<T, ?, List<T>> toList()
From source file:com.github.steveash.guavate.GuavateTest.java
@Test public void test_stream_Optional() { Optional<String> optional = Optional.of("foo"); List<String> test1 = Guavate.stream(optional).collect(Collectors.toList()); assertEquals(test1, ImmutableList.of("foo")); Optional<String> empty = Optional.empty(); List<String> test2 = Guavate.stream(empty).collect(Collectors.toList()); assertEquals(test2, ImmutableList.of()); }
From source file:com.techcavern.wavetact.eventListeners.ConnectListener.java
public void onConnect(ConnectEvent event) throws Exception { String NickServCommand = DatabaseUtils.getNetwork(IRCUtils.getNetworkNameByNetwork(event.getBot())) .getValue(NETWORKS.NICKSERVCOMMAND); String NickServNick = DatabaseUtils.getNetwork(IRCUtils.getNetworkNameByNetwork(event.getBot())) .getValue(NETWORKS.NICKSERVNICK); if (NickServNick == null) { NickServNick = "NickServ"; }/* w w w . j a v a 2 s . co m*/ if (NickServCommand != null) { event.getBot().sendRaw().rawLine("PRIVMSG " + NickServNick + " :" + NickServCommand); } TimeUnit.SECONDS.sleep(10); Registry.messageQueue.get(event.getBot()).addAll(Arrays .asList(StringUtils.split(DatabaseUtils.getNetwork(IRCUtils.getNetworkNameByNetwork(event.getBot())) .getValue(NETWORKS.CHANNELS), ", ")) .stream().map(channel -> ("JOIN :" + channel)).collect(Collectors.toList())); TimeUnit.SECONDS.sleep(10); ListenerManager listenerManager = event.getBot().getConfiguration().getListenerManager(); listenerManager.getListeners().stream() .filter(lis -> !(lis instanceof ConnectListener || lis instanceof CoreHooks)) .forEach(listener -> listenerManager.removeListener(listener)); listenerManager.addListener(new ChanMsgListener()); listenerManager.addListener(new PartListener()); listenerManager.addListener(new PrivMsgListener()); listenerManager.addListener(new KickListener()); listenerManager.addListener(new BanListener()); listenerManager.addListener(new JoinListener()); listenerManager.addListener(new FunMsgListener()); listenerManager.addListener(new RelayMsgListener()); listenerManager.addListener(new InviteListener()); listenerManager.addListener(new TellMsgListener()); listenerManager.addListener(new NoticeListener()); listenerManager.addListener(new ActionListener()); listenerManager.addListener(new CTCPListener()); IRCUtils.sendLogChanMsg(event.getBot(), "[Connection Successful]"); }
From source file:de.wpsverlinden.dupfind.DupeFinder.java
public Collection<FileEntry> getDupesOf(String path) { FileEntry info = (FileEntry) fileIndex.get(path); if (info == null) { outputPrinter.println("Could not find \"" + path + "\" in index"); return Collections.EMPTY_LIST; }/*from w w w. j ava 2 s . c om*/ Collection<FileEntry> dupes = fileIndex.values().parallelStream() .filter((e) -> !(e.getPath().equals(info.getPath()))).filter((e) -> (e.getSize() == info.getSize())) .filter((e) -> (e.getHash().equals(info.getHash()))).collect(Collectors.toList()); return dupes; }
From source file:pt.ist.fenix.ui.spring.BookmarksController.java
@RequestMapping public String bookmarks(Model model) { model.addAttribute("bookmarks", Authenticate.getUser().getBookmarksSet().stream() .sorted(Comparator.comparing(cat -> cat.getSite().getName().getContent())) .collect(Collectors.toList())); final Student student = AccessControl.getPerson().getStudent(); if (student != null) { model.addAttribute("courses", student.getActiveRegistrationsIn(ExecutionSemester.readActualExecutionSemester()).stream() .flatMap(registration -> registration .getAttendingExecutionCoursesForCurrentExecutionPeriod().stream()) .collect(Collectors.toList())); }/*from w w w.j a v a 2s . co m*/ return "fenix-learning/bookmarks"; }
From source file:org.obiba.mica.file.rest.DraftFileAccessResource.java
@GET @Path("/{path:.*}") public List<AclDto> get(@PathParam("path") String path) { String basePath = normalizePath(path); subjectAclService.checkPermission("/draft/file", "EDIT", basePath); return subjectAclService.findByResourceInstance(resource, basePath).stream() .map(a -> AclDto.newBuilder().setType(a.getType().name()).setPrincipal(a.getPrincipal()) .setResource(resource).setRole(PermissionsUtils.asRole(a.getActions())) .setInstance(FileUtils.decode(basePath)).build()) .collect(Collectors.toList()); }
From source file:com.devicehive.dao.riak.model.RiakDeviceEquipment.java
public static List<RiakDeviceEquipment> convertToEntity(List<DeviceEquipmentVO> equipment) { if (equipment == null) { return Collections.emptyList(); }/*from w w w .j a v a2 s . co m*/ return equipment.stream().map(RiakDeviceEquipment::convertToEntity).collect(Collectors.toList()); }
From source file:co.mafiagame.engine.command.StartElectionCommand.java
@Override public ResultMessage execute(EmptyContext context) { validateGameNotNull(context);/*from ww w . ja va2s . c o m*/ Game game = context.getGame(); game.update(); if (game.getElectionMood() != ElectionMood.NONE) throw new ElectionAlreadyStarted(); game.startElection(false); List<String> users = game.getPlayers().stream().map(Player::getAccount).map(Account::getUsername) .collect(Collectors.toList()); return new ResultMessage(new Message("election.started") .setOptions(game.makeOption(Constants.CMD.VOTE, true)).setToUsers(users), ChannelType.GENERAL, context.getInterfaceContext()); }
From source file:com.baasbox.service.user.FriendShipService.java
public static List<ODocument> getFollowing(String username, QueryParams criteria) throws SqlInjectionException { OUser me = UserService.getOUserByUsername(username); Set<ORole> roles = me.getRoles(); List<String> usernames = roles.parallelStream().map(ORole::getName) .filter((x) -> x.startsWith(RoleDao.FRIENDS_OF_ROLE)) .map((m) -> StringUtils.difference(RoleDao.FRIENDS_OF_ROLE, m)).collect(Collectors.toList()); if (username.isEmpty()) { return Collections.emptyList(); } else {// www . ja va 2s. c o m List<ODocument> followers = UserService.getUserProfileByUsernames(usernames, criteria); return followers; } }
From source file:org.obiba.mica.web.model.LocalizedStringDtos.java
@NotNull List<Mica.LocalizedStringDtos> asDtoList(@NotNull Collection<LocalizedString> localizedStrings) { return localizedStrings.stream().map(localizedString -> Mica.LocalizedStringDtos.newBuilder() .addAllLocalizedStrings(asDto(localizedString)).build()).collect(Collectors.toList()); }
From source file:com.yahoo.bard.webservice.config.ConfigResourceLoader.java
/** * Use a string pattern to load configurations matching a resource name from the class path and parse into * Configuration objects.//from ww w . j a va 2 s.c o m * * @param name The class path address of a resource ('/foo' means a resource named foo in the default package) * * @return A list of configurations corresponding to the matching class path resource * * @throws IOException if any resources cannot be read from the class path successfully. */ public List<Configuration> loadConfigurations(String name) throws IOException { return loadResourcesWithName(name).map(this::loadConfigFromResource).collect(Collectors.toList()); }