-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from yvasyliev/dev
Dev
- Loading branch information
Showing
23 changed files
with
193 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/java/api/longpoll/bots/helpers/attachments/UploadableFilesSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package api.longpoll.bots.helpers.attachments; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* Supplies a list of {@link UploadableFile}. | ||
*/ | ||
public class UploadableFilesSupplier implements Supplier<List<UploadableFile>> { | ||
/** | ||
* List of {@code peer_id}. | ||
*/ | ||
private final List<Integer> peerIds = new ArrayList<>(); | ||
|
||
/** | ||
* List of {@link UploadableFile} factories. | ||
*/ | ||
private final List<Function<Integer, UploadableFile>> uploadableFileFactories = new ArrayList<>(); | ||
|
||
/** | ||
* Adds {@code peer_id} to the list. | ||
* | ||
* @param peerId message {@code peer_id}. | ||
*/ | ||
public void addPeerId(Integer peerId) { | ||
this.peerIds.add(peerId); | ||
} | ||
|
||
/** | ||
* Adds list of {@code peer_id} to the list. | ||
* | ||
* @param peerIds list of message {@code peer_id}. | ||
*/ | ||
public void addPeerIds(List<Integer> peerIds) { | ||
this.peerIds.addAll(peerIds); | ||
} | ||
|
||
/** | ||
* Adds {@link UploadableFile} factory to the list. | ||
* | ||
* @param uploadableFileFactory {@link UploadableFile} factory. | ||
*/ | ||
public void addUploadableFileFactory(Function<Integer, UploadableFile> uploadableFileFactory) { | ||
this.uploadableFileFactories.add(uploadableFileFactory); | ||
} | ||
|
||
/** | ||
* Gets {@link Stream<UploadableFile>}. | ||
* | ||
* @param peerId message {@code peer_id}. | ||
* @return {@link Stream<UploadableFile>}. | ||
*/ | ||
private Stream<UploadableFile> getUploadableFiles(Integer peerId) { | ||
return uploadableFileFactories.stream() | ||
.map(uploadableFileFactory -> uploadableFileFactory.apply(peerId)); | ||
} | ||
|
||
@Override | ||
public List<UploadableFile> get() { | ||
return peerIds.stream() | ||
.flatMap(this::getUploadableFiles) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.