Skip to content

Commit

Permalink
Update readme for 1.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
thegatesdev committed Apr 24, 2023
1 parent fa76503 commit ad3c53c
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

A clean type safe data structure.

Updated for **1.4.2**

## About

Maple is used as a replacement for the Spigot Configuration API, and used in my own projects to help read extensive amounts of data.
Maple is used as a replacement for the Spigot Configuration API, and used in my own projects to help read extensive
amounts of data.

## Usage

### Element data

A DataElement can have a *parent* and a *name*.
The *parent* is set by the parent when added in a structure. It is used to identify where the element lives.
The *name* can be set manually, or by the structure it is in. If the name is set, manually or by the parent, it can not be changed.
The *name* can be set manually, or by the structure it is in. If the name is set, manually or by the parent, it can not
be changed.

- `new DataMap()` This creates a new DataMap with its data *unset*.
- `new DataMap("Timmy")` This creates a new DataMap with its data *set*, the parent is defaulted to *null*.
Expand All @@ -35,12 +39,25 @@ map.put("integer_entry", new DataPrimitive(3));
DataElement el = map.get("map_entry");
// Get specific primitive value from map:
int i = map.get("integer_entry", Integer.class);
// Or
int x = map.getInt("integer_entry");
// Find in map structure
DataElement nestedEntry = map.navigate("map_entry", "nested_map_entry");
// If you are very sure about what the element type is
DataList surelyThisIsAList = map.getList("map_entry"); // ElementException!!
```

#### Indexed DataMap

From version **1.4.2**, DataMap implements IndexedElement, meaning you can access elements by integer index.

// And more ..
Since DataMap uses LinkedHashMap by default in the background, the elements will be insertion ordered.

```java
// ( Using the code above )
// Access map elements by index:
map.get(0).isMap() // True
map.get(1).intValue() // 3
```

### DataList
Expand All @@ -58,23 +75,6 @@ DataElement el = list.get(0);
Iterator<DataMap> mapsInList = list.iterator(DataMap.class);
// Get a list of primitive elements values of a certain type:
List<String> stringPrimitives = list.primitiveList(String.class);

// And more ..
```

### DataArray

*A normal static sized array*

```java
// Create array that can hold 20 elements.
DataArray array = new DataArray(20);
// Set elements:
array.set(0, new DataPrimitive("hello world"));
// Get elements:
DataElement element = array.get(0);

// And more ..
```

### DataPrimitive
Expand All @@ -93,8 +93,6 @@ primitive.isNumberValue() // false
// Get value or throw
String stringValue = primitive.requireValue(String.class); // "hello world"
int intValue = primitive.requireValue(Integer.class); // ElementException with appropriate message.

// And more ..
```

### DataNull
Expand All @@ -106,4 +104,5 @@ for type checking without the occasional NullPointerException.

### ElementException

This exception should mostly be used to notify the end user that they did something unexpected, for example when using assertion methods.
This exception should mostly be used to notify the end user that they did something unexpected, for example when using
assertion methods.

0 comments on commit ad3c53c

Please sign in to comment.