Skip to content

Commit

Permalink
1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
maxx111402 committed Sep 24, 2024
1 parent cb1abda commit 4ec0b71
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 1 deletion.
67 changes: 67 additions & 0 deletions src/main/java/org/thesalutyt/ftml/Builder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.thesalutyt.ftml;

import org.thesalutyt.ftml.objects.FTMLObject;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

public class Builder {
private final File file;
private final ArrayList<FTMLObject> fileObjects = new ArrayList<>();

public Builder(File file) {
if (file == null) {
throw new IllegalArgumentException("File cannot be null");
}
if (!file.exists()) {
throw new IllegalArgumentException("File does not exist");
}
if (!file.isFile()) {
throw new IllegalArgumentException("File is not a file");
}

this.file = file;
}

public Builder addObject(FTMLObject object) {
fileObjects.add(object);
return this;
}

public Builder dump() {
FTMLObject[] objects = new FTMLObject[fileObjects.size()];
fileObjects.toArray(objects);
try {
File file = this.file;
FileWriter writer = new FileWriter(file);

for (FTMLObject object : objects) {
writer.write(object.toString() + "\n");
}

writer.close();
} catch (IOException e) {
throw new RuntimeException(e);
}

return this;
}

public boolean delete() {
return this.file.delete();
}

public FTMLObject[] getObjects() {
return fileObjects.toArray(new FTMLObject[0]);
}

public Builder get() {
return this;
}

public File getFile() {
return file;
}
}
31 changes: 31 additions & 0 deletions src/main/java/org/thesalutyt/ftml/converter/ObjectConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.thesalutyt.ftml.converter;

import org.thesalutyt.ftml.objects.FTMLObject;
import org.thesalutyt.ftml.objects.ListObject;
import org.thesalutyt.ftml.objects.ObjectType;

import java.util.List;

public class ObjectConverter {
public static FTMLObject toFtml(Object object, String name) {
if (object instanceof String) {
return new FTMLObject(name, object.toString(), ObjectType.String);
} else if (object instanceof Integer) {
return new FTMLObject(name, Integer.parseInt(object.toString()), ObjectType.Integer);
} else if (object instanceof Double) {
return new FTMLObject(name, Double.parseDouble(object.toString()), ObjectType.Double);
} else if (object instanceof Float) {
return new FTMLObject(name, Float.parseFloat(object.toString()), ObjectType.Float);
} else if (object instanceof Boolean) {
return new FTMLObject(name, Boolean.parseBoolean(object.toString()), ObjectType.Boolean);
}

return null;
}

public static ListObject toFtmlList(Object object, String name) {
if (!(object instanceof List<?> list)) throw new IllegalArgumentException();

return ListObject.of(new FTMLObject(name, list.toString(), ObjectType.List));
}
}
2 changes: 1 addition & 1 deletion src/main/resources/about.ftml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 'FTML'
ftml: 'Fuck This Markup Language'
why_this_name: 'Idk :>'
why_this_name: 'Idk ))'
about: 'This is simple markup language made in like 2 hours'
author: 'TheSALUTYT'
version: 1.0
Expand Down

0 comments on commit 4ec0b71

Please sign in to comment.