Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

JAVA - Search based on any combination of attributes

User_67OC0Nov 2 2022

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>

Comments

Post Details

Added on Nov 2 2022
1 comment
382 views