Skip to content

Commit

Permalink
Cleaned the code, updated README, made the structure more forgiving
Browse files Browse the repository at this point in the history
  • Loading branch information
josua committed Jul 26, 2019
1 parent 3b94ac2 commit bfafa46
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 283 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ int size = array.size();
array.remove(3); // Could be any number

// Set - Could be any number with any object
array.set(4, BdfObject.with("A String"));
array.set(4, BdfObject.withString("A String"));

// Add - Could be any object
array.add(BdfObject.with(53));
array.add(BdfObject.withByte(53));

// Set the array to the bdf object
bdf.setArray(array);
Expand Down Expand Up @@ -147,7 +147,7 @@ Named lists also have Iterator support and are an instance of
BdfNamedList list = new BdfNamedList();

// Set an element with a value
list.set("key1", BdfObject.with(5));
list.set("key1", BdfObject.withInteger(5));

// Get an elements value
int v = list.get("key1").getInteger();
Expand Down Expand Up @@ -191,14 +191,11 @@ class HelloWorld implements IBdfClassManager
{
// Load scripts here

// Create a new named list if the object isn't a named list
bdf.setNamedListIfInvalid();

// Set the iterator if the iterator hasn't been set yet
bdf.getNamedList().setIfUndefined("iterator", BdfObject.withInteger(0));
// Get the named list
BdfNamedList nl = bdf.getNamedList();

// Set the iterator stored in bdf
int iterator = bdf.getNamedList().get("iterator").getInteger();
int iterator = nl.get("iterator").getInteger();
}

@Override
Expand All @@ -207,10 +204,13 @@ class HelloWorld implements IBdfClassManager
// Save scripts here

// Create a named list
bdf.setNamedList();
BdfNamedList nl = new BdfNamedList();

// Set the iterator to the named list
bdf.getNamedList().set("iterator", BdfObject.withInteger(iterator));
nl.set("iterator", BdfObject.withInteger(iterator));

// Store the named list
bdf.setNamedList(nl);
}

public void hello()
Expand Down
Binary file removed db.bdf
Binary file not shown.
1 change: 0 additions & 1 deletion src/bdf/exception/.gitignore

This file was deleted.

11 changes: 0 additions & 11 deletions src/bdf/exception/UndefinedKeyException.java

This file was deleted.

29 changes: 10 additions & 19 deletions src/bdf/types/BdfNamedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.ArrayList;

import bdf.data.BdfDatabase;
import bdf.exception.UndefinedKeyException;
import bdf.util.DataHelpers;

public class BdfNamedList implements IBdfType
Expand Down Expand Up @@ -117,8 +116,14 @@ public BdfObject get(String key)
}
}

// Raise an error
throw new UndefinedKeyException(key);
// Get a bdf object
BdfObject o = new BdfObject();

// Set the bdf object
this.set(key, o);

// Send back the object
return o;
}

public BdfNamedList remove(String key)
Expand All @@ -143,8 +148,8 @@ public BdfNamedList remove(String key)
}
}

// Raise an error
throw new UndefinedKeyException(key);
// Send back nothing
return this;
}

public BdfNamedList set(String key, BdfObject object)
Expand Down Expand Up @@ -178,20 +183,6 @@ public BdfNamedList set(String key, BdfObject object)
return this;
}

public BdfNamedList setIfUndefined(String key, BdfObject object)
{
if(this.contains(key)) return this;
else return this.set(key, object);
}

public BdfNamedList allocIfUndefined(String key) {
return this.setIfUndefined(key, new BdfObject());
}

public BdfNamedList alloc(String key) {
return this.set(key, new BdfObject());
}

public boolean contains(String key)
{
// Convert the key to bytes
Expand Down
Loading

0 comments on commit bfafa46

Please sign in to comment.