Discussions
Categories
- 385.5K All Categories
- 4.9K Data
- 2.5K Big Data Appliance
- 2.4K Data Science
- 453.4K Databases
- 223.2K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 47 Multilingual Engine
- 606 MySQL Community Space
- 486 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.2K ORDS, SODA & JSON in the Database
- 585 SQLcl
- 4K SQL Developer Data Modeler
- 188K SQL & PL/SQL
- 21.5K SQL Developer
- 46 Data Integration
- 46 GoldenGate
- 298.4K Development
- 4 Application Development
- 20 Developer Projects
- 166 Programming Languages
- 295K Development Tools
- 150 DevOps
- 3.1K QA/Testing
- 646.7K Java
- 37 Java Learning Subscription
- 37.1K Database Connectivity
- 201 Java Community Process
- 108 Java 25
- 22.2K Java APIs
- 138.3K Java Development Tools
- 165.4K Java EE (Java Enterprise Edition)
- 22 Java Essentials
- 176 Java 8 Questions
- 86K Java Programming
- 82 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 208 Java User Groups
- 25 JavaScript - Nashorn
- Programs
- 667 LiveLabs
- 41 Workshops
- 10.3K Software
- 6.7K Berkeley DB Family
- 3.6K JHeadstart
- 6K Other Languages
- 2.3K Chinese
- 207 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 474 Portuguese
JAVA - Search based on any combination of attributes

We have a file system FileSystem that contains files in the form of the matrix. Each of these files have the following 4 attributes:
- size;
- name;
- timeCreated;
- permission;
I need implement a way to search in your file system based on any combination of attributes
- eg: all files that have Permission W and created before 18-05-2022
- eg2: all files with name containg "asd"
- The filesystem matrix has to be traversed in reversed diagonal ( ⬋ ) :
- eg for matrix :
- 123456789
- the traversal should be :
[1 2 4 3 5 7 6 8 9]
How would be the best way to do that?
Thanks in advance :)
Code:
package util.filesystem; import java.time.LocalDateTime; public enum FileSystem { FILE_SYSTEM; public static File[][] files = new File[5][5]; static { for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { long size = 1000 * (i+j); String name = "file" + i + j; final LocalDateTime creationTime = LocalDateTime.of(2022, 12, i+j+1, 12, 12); Permissions permission = Permissions.values()[(10*i+j) % 3]; files[i][j] = new File(size, name, creationTime, permission); } } } } package util.filesystem; import java.time.LocalDateTime; import lombok.AllArgsConstructor; import lombok.Data; @Data @AllArgsConstructor public class File { private long size; private String name; private LocalDateTime timeCreated; private Permissions permission; } package util.filesystem; public enum Permissions { R, W , RW } <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>Teste</groupId> <artifactId>Teste</artifactId> <version>0.0.1-SNAPSHOT</version> <build> <sourceDirectory>src</sourceDirectory> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> <properties> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.24</version> <scope>provided</scope> </dependency> </dependencies> </project>
Answers
-
Hello @User_67OC0
1) you need a method on the enum to return the 2 dimension array you just created
2) if you learned about stream and lambda expression then you can get stream of that array and use the filter and use predicate to get the files that only apply to those rule you mentioned
3) if you did not learn about step 2 yet then no problem
a) for this one eg: all files that have Permission W and created before 18-05-2022
using 2 nested loop check each file if it has the right permission or not and also check https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalDate.html#isBefore(java.time.chrono.ChronoLocalDate) to check if the creation date is before that date or not
you could create method in your File class to take permission as parameter and return true or false based on the file that called it
maybe create arraylist to hold the files that follow the rule and return that arraylist
b) eg2: all files with name containg "asd" you can use https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html#contains(java.lang.CharSequence)
for a and b you need to create getter method for your file class or create method that return boolean and it check the rule you want
- c) The filesystem matrix has to be traversed in reversed diagonal ( ⬋ ) :
- eg for matrix :
- 123456789
- the traversal should be :
[1 2 4 3 5 7 6 8 9]
it would be better to draw matrix as
1 2 3
4 5 6
7 8 9
what the out put you want cause the output you mentioned is not the reversed diagonal
hope that help and have a nice day :)
- c) The filesystem matrix has to be traversed in reversed diagonal ( ⬋ ) :