Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.iliar.RobertoBot.RandomPicture;
- import java.io.File;
- import java.io.FilenameFilter;
- import java.util.ArrayList;
- import java.util.Random;
- import ru.iliar.RobertoBot.SystemConfiguration;
- public class RandomPicture implements FilenameFilter {
- /** Список каталогов с изображениями */
- private static final String[] SOURCE_FOLDERS = {
- "DeviantArt",
- "Patreon",
- "Fan-Art (SFW)",
- "EasterEggs",
- "Paper Sketches"
- };
- /** Список запрещенных файлов */
- private static final String[] HIDDEN_FILES = {
- "desktop.ini",
- ".DS_Store",
- "Icon\r",
- "2017_11_01 Multiwoofer (game).jpg",
- "2017_07_27 Transistor Sword Render.png",
- "2014.08.07 Beach Party Trio.zip",
- "2004.04.24 ThreeGirls600800.jpg",
- "2004.05.16 Tiger.jpg",
- "2005.01.27 SexyKitty.jpg",
- "2006.02.07 Peeping Tom.jpg",
- "2006.04.14 Topless Vanilla Fanart.jpg",
- "2006.05.01 Stylized painting of a nude.jpg",
- "2006.10.12 Spotted Kitty Sketch.jpg",
- "2007.09.05 What Are You Looking At.jpg",
- "2008.03.24 Yosh Fanart - Melting IceCream.jpg",
- "2008.08.11 The Basitin Ritual of Return.jpg",
- "2008.12.17 Darn that Pesky Basitin Magic.jpg",
- "2017.09.10 Private Muse.png", //Слишком большой файл, добавлена JPG версия
- "2018.03.13 Sleeping Maddie.png", //Слишком большой файл, добавлена JPG версия
- "[AsanoNisshoku] 2017.12.25 Dragon in Pants (original).gif", //Слишком большой файл
- "[Andromeda38] 2016.11.11 Natani and Keith.tiff", //Несовместимый формат
- "[infinitedge2u] 2016.12.06 Boop! (original).png", //Слишком большой файл
- "[DarthKeidran] 2017.12.20 TwoKinds - The Last Journey (original).jpg", //Слишком большой файл
- "[DarthKeidran] 2018.03.08 Shingeki No Kyodran - Titan Nibbly (Spring Snow) (original).jpg", //Слишком большой файл
- };
- /** Список каталогов с изображениями */
- public ArrayList<File> sourceFolders;
- /** Принудительная установка не случайной картинки */
- private File unrandomPicture;
- /** Генератор случайных чисел */
- private Random random;
- /** Конструктор класса */
- public RandomPicture() {
- super();
- random = new Random(System.currentTimeMillis());
- sourceFolders = new ArrayList<File>();
- for (String folder : SOURCE_FOLDERS) {
- sourceFolders.add(new File(SystemConfiguration.MAIN_FOLDER + File.separator + folder));
- }
- }
- /** Метод сортировщика файлов */
- public boolean accept(File dir, String name) {
- for (String hiddenFile : HIDDEN_FILES) {
- if (name.equalsIgnoreCase(hiddenFile)) {
- return(false);
- }
- }
- return(true);
- }
- /** Возвращает файл случайного изобржаения */
- public File getRandomPicture() {
- if (unrandomPicture != null) {
- File result = unrandomPicture;
- unrandomPicture = null;
- return( result );
- }
- ArrayList<File> allFiles = getPool();
- return(allFiles.get(random.nextInt(allFiles.size())));
- }
- /**
- * @param unrandomPicture the unrandomPicture to set
- */
- public void setUnrandomPicture(File unrandomPicture) {
- this.unrandomPicture = unrandomPicture;
- }
- /**
- * Возвращает массив изображений
- * @return
- */
- public ArrayList<File> getPool() {
- ArrayList<File> allFiles;
- allFiles = new ArrayList<File>();
- for (File folder : sourceFolders) {
- File[] filderFiles = folder.listFiles(this);
- for (File file : filderFiles) {
- if ( file.isFile() ) {
- allFiles.add(file);
- }
- }
- }
- return(allFiles);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement