parent
bca738318e
commit
02dc9b28bf
@ -0,0 +1,84 @@
|
||||
package Bin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class System {
|
||||
private Map<String, Note> notesMap;
|
||||
private int storageLimit; // in bytes
|
||||
|
||||
public System(int storageLimit) {
|
||||
this.notesMap = new HashMap<>();
|
||||
this.storageLimit = storageLimit;
|
||||
}
|
||||
|
||||
public List<Note> getDeletedNotes() {
|
||||
List<Note> deletedNotes = new ArrayList<>();
|
||||
for (Note note : notesMap.values()) {
|
||||
if (note.isDeleted()) {
|
||||
deletedNotes.add(note);
|
||||
}
|
||||
}
|
||||
return deletedNotes;
|
||||
}
|
||||
|
||||
public void restoreNote(String noteId) {
|
||||
Note note = notesMap.get(noteId);
|
||||
if (note != null && note.isDeleted()) {
|
||||
note.setDeletedAt(null);
|
||||
}
|
||||
}
|
||||
|
||||
public void permanentlyDeleteNote(String noteId) {
|
||||
notesMap.remove(noteId);
|
||||
}
|
||||
|
||||
public void cleanUpOldNotes() {
|
||||
notesMap.entrySet().removeIf(entry -> entry.getValue().isDeleted());
|
||||
}
|
||||
|
||||
public void checkStorageLimit() {
|
||||
long totalSize = 0;
|
||||
for (Note note : notesMap.values()) {
|
||||
for (Image image : note.getImages()) {
|
||||
// Here you would need some way to determine the size of each file.
|
||||
// For demonstration purposes, let's assume each image path represents 1MB.
|
||||
totalSize += 1024 * 1024;
|
||||
}
|
||||
}
|
||||
if (totalSize > storageLimit) {
|
||||
System.out.println("Storage limit exceeded.");
|
||||
} else {
|
||||
System.out.println("Storage within limits.");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean validateImage(String imagePath) {
|
||||
// Implement actual image validation logic here
|
||||
return true; // Placeholder implementation
|
||||
}
|
||||
|
||||
public Blob generateThumbnail(String imagePath) {
|
||||
// Implement actual thumbnail generation logic here
|
||||
byte[] thumbnailData = new byte[0]; // Placeholder data
|
||||
return new Blob(thumbnailData);
|
||||
}
|
||||
|
||||
public void saveImageWithNoteBinding(String noteId, String imagePath) {
|
||||
Note note = notesMap.get(noteId);
|
||||
if (note != null && validateImage(imagePath)) {
|
||||
Blob thumbnail = generateThumbnail(imagePath);
|
||||
Image image = new Image(imagePath, thumbnail, new Date());
|
||||
note.getImages().add(image);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,66 @@
|
||||
package net.micode.notes.model;
|
||||
|
||||
class Blob {
|
||||
private byte[] data;
|
||||
|
||||
public Blob(byte[] data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public byte[] getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(byte[] data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
public class Image {
|
||||
private String path;
|
||||
private Blob thumbnail;
|
||||
private Date uploadTime;
|
||||
|
||||
public Image(String path, Blob thumbnail, Date uploadTime) {
|
||||
this.path = path;
|
||||
this.thumbnail = thumbnail;
|
||||
this.uploadTime = uploadTime;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public Blob getThumbnail() {
|
||||
return thumbnail;
|
||||
}
|
||||
|
||||
public void setThumbnail(Blob thumbnail) {
|
||||
this.thumbnail = thumbnail;
|
||||
}
|
||||
|
||||
public Date getUploadTime() {
|
||||
return uploadTime;
|
||||
}
|
||||
|
||||
public void setUploadTime(Date uploadTime) {
|
||||
this.uploadTime = uploadTime;
|
||||
}
|
||||
|
||||
public Blob getPreview() {
|
||||
// Return the thumbnail as the preview
|
||||
return thumbnail;
|
||||
}
|
||||
|
||||
public Object getMetadata() {
|
||||
// Create a metadata object with relevant information
|
||||
Map<String, Object> metadata = new HashMap<>();
|
||||
metadata.put("path", path);
|
||||
metadata.put("uploadTime", uploadTime);
|
||||
// Add more metadata fields if necessary
|
||||
return metadata;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue