Skip to content

Commit 7ff88ba

Browse files
committed
first commit
0 parents  commit 7ff88ba

11 files changed

Lines changed: 1648 additions & 0 deletions

File tree

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Compiled class files
2+
*.class
3+
4+
# Log files
5+
*.log
6+
7+
# Temp files
8+
*.tmp
9+
10+
# Package Files
11+
*.jar
12+
*.war
13+
*.nar
14+
*.ear
15+
*.zip
16+
*.tar.gz
17+
*.rar
18+
19+
# Virtual machine crash logs
20+
hs_err_pid*
21+
22+
# Out folder, result of ./build
23+
out/
24+
25+
# VS Code files
26+
.vscode/

LICENCE.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2025 Bruno RNS
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# JavaIterables Library
2+
3+
Welcome to **JavaIterables**, the library that brings Python-like `list` and `dict` functionality to Java! Say goodbye to boilerplate code and hello to clean, efficient data manipulation. Whether you're managing collections or building complex data structures, `List` and `Dict` have got your back.
4+
5+
---
6+
7+
## What Does It Do?
8+
9+
- **`List`**: Think of it as a Java-powered `list` from Python. Append, remove, sort, reverse, and more—all with ease.
10+
- **`Dict`**: A key-value store that feels like Python's `dict`. Add, update, search, and sort your data like a pro.
11+
12+
---
13+
14+
## Why Use It?
15+
16+
Because Java deserves to be fun too! With JavaIterables, you can:
17+
18+
- Write less code.
19+
- Handle collections like a Pythonista.
20+
- Impress your colleagues with clean, readable Java.
21+
22+
---
23+
24+
## Quick Examples
25+
26+
### **Using `List`**
27+
28+
```java
29+
import javaiterables.List;
30+
31+
public class Main {
32+
public static void main(String[] args) {
33+
List myList = new List();
34+
myList.append("Java");
35+
myList.append("is");
36+
myList.append("awesome!");
37+
38+
System.out.println("Original List:");
39+
myList.show();
40+
41+
myList.reverse();
42+
System.out.println("Reversed List:");
43+
myList.show();
44+
}
45+
}
46+
```
47+
48+
### **Using `Dict`**
49+
50+
```java
51+
import javaiterables.Dict;
52+
53+
public class Main {
54+
public static void main(String[] args) {
55+
Dict myDict = new Dict();
56+
myDict.add("language", "Java");
57+
myDict.add("type", "Object-Oriented");
58+
myDict.add("fun", true);
59+
60+
System.out.println("Dictionary Contents:");
61+
System.out.println("Language: " + myDict.get("language"));
62+
System.out.println("Type: " + myDict.get("type"));
63+
System.out.println("Is it fun? " + String.valueOf(myDict.get("fun")));
64+
}
65+
}
66+
```
67+
68+
---
69+
70+
## Ready-to-Use `.jar`
71+
72+
No need to compile anything! Just grab the precompiled `javaiterables.jar` from the release section and add it to your project:
73+
74+
1. **As a module**: Add `requires javaiterables;` to your `module-info.java`.
75+
2. **Without modules**: Add the `.jar` to your classpath and import the classes directly.
76+
77+
---
78+
79+
## Licence
80+
81+
This library is open-source and available under the MIT License. Feel free to use, modify, and distribute it as needed.
82+
83+
## Want More Details?
84+
85+
Check out the [full documentation](./docs/README.md) for a deep dive into all the features, methods, and examples.
86+
87+
## Special Thanks
88+
89+
- My programming professor
90+
- Family and friends
91+
- Everybody that helped me anyway
92+
93+
And of course, you, who is going to try this amazing library!

build

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
# Configuration
4+
5+
MODULE_NAME="javaiterables"
6+
SRC_DIR="src/$MODULE_NAME"
7+
OUT_DIR="out"
8+
JAR_NAME="$MODULE_NAME.jar"
9+
10+
cd "$(dirname "$0")"
11+
12+
# Clean previous build
13+
14+
echo "Cleaning previous build..."
15+
rm -rf "$OUT_DIR"
16+
mkdir -p "$OUT_DIR"
17+
18+
# Compile module
19+
20+
echo "Compiling Module: '$MODULE_NAME'..."
21+
22+
javac -d "$OUT_DIR" \
23+
"src/$MODULE_NAME/module-info.java" \
24+
src/$MODULE_NAME/javaiterables/*.java
25+
26+
27+
if [ $? -ne 0 ]; then
28+
29+
echo "Error while compiling, aborting..."
30+
exit 1
31+
32+
fi
33+
34+
# Generate .jar file
35+
echo "Generating jar package '$JAR_NAME'..."
36+
jar --create \
37+
--file "$JAR_NAME" \
38+
--module-version 1.0 \
39+
-C "$OUT_DIR" .
40+
41+
# Perguntar ao usuário se deseja executar o teste
42+
read -p "Wants to run tests 'tests/test.sh'? (s/N): " respond
43+
44+
if [[ "$respond" == "s" || "$respond" == "S" ]]; then
45+
46+
echo "Executing tests..."
47+
bash ./tests/test "$JAR_NAME"
48+
49+
fi
50+
51+
echo "Build finished, exiting..."

dependencies.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
openJDK only (no extern libraries)

docs/README.md

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# JavaIterables Library Documentation
2+
3+
The **JavaIterables** library provides two main classes, `List` and `Dict`, which offer flexible and powerful data structures for managing collections of data. These classes are designed to be like Python's `list` and `dict` while being implemented in Java.
4+
5+
---
6+
7+
## Table of Contents
8+
9+
1. Building from source
10+
2. Usage
11+
3. Classes
12+
- List
13+
- Dict
14+
4. Examples
15+
- Using `List`
16+
- Using `Dict`
17+
5. Testing
18+
6. License
19+
20+
---
21+
22+
## Building from source
23+
24+
1. Compile the library and package it into a `.jar` file:
25+
26+
```bash
27+
cd javaiterables-main/
28+
./build
29+
```
30+
31+
It will generate a `javaiterables.jar` on `out` directory.
32+
33+
2. Add the `javaiterables.jar` file to your project's classpath.
34+
35+
---
36+
37+
## Usage
38+
39+
You can use the library in two ways:
40+
41+
1. **As a module**:
42+
Add the following to your `module-info.java`:
43+
44+
```java
45+
module yourmodule {
46+
requires javaiterables;
47+
}
48+
```
49+
50+
2. **Without modules**:
51+
Add the `.jar` file to your classpath and import the classes directly:
52+
53+
```java
54+
import javaiterables.List;
55+
import javaiterables.Dict;
56+
```
57+
58+
---
59+
60+
## Classes
61+
62+
### **List**
63+
64+
The `List` class is a flexible data structure for managing ordered collections of elements. It supports various data types and provides methods for manipulation, iteration, and analysis.
65+
66+
#### **List Methods**
67+
68+
| Method | Description |
69+
|---------------------------------|-----------------------------------------------------------------------------|
70+
| `void append(Object val)` | Adds an element to the end of the list. |
71+
| `void remove(int index)` | Removes the element at the specified index. |
72+
| `Object get(int index)` | Retrieves the element at the specified index. |
73+
| `void set(int index, Object val)` | Replaces the element at the specified index with a new value. |
74+
| `int len()` | Returns the number of elements in the list. |
75+
| `void reverse()` | Reverses the order of elements in the list. |
76+
| `boolean isEqualTo(List list)` | Checks if the current list is equal to another list. |
77+
| `void clear()` | Removes all elements from the list. |
78+
| `List copyList()` | Creates a copy of the current list. |
79+
| `boolean contains(Object val)` | Checks if the list contains a specific value. |
80+
| `void extend(List list)` | Appends all elements from another list to the current list. |
81+
| `void insert(int index, Object val)` | Inserts an element at the specified index. |
82+
| `void show()` | Prints the list in a readable format. |
83+
| `double sum()` | Returns the sum of all numeric elements in the list. |
84+
| `double avg()` | Returns the average of all numeric elements in the list. |
85+
| `double min()` | Returns the smallest numeric element in the list. |
86+
| `double max()` | Returns the largest numeric element in the list. |
87+
| `String uniteListString(String sep)` | Joins all elements into a single string, separated by the given delimiter. |
88+
| `java.util.List<Object> listIterate()` | Returns a Java `List` containing all elements. |
89+
| `Object[] arrayIterate()` | Returns an array containing all elements. |
90+
| `List sort(boolean ascending)` | Returns a sorted version of the list (ascending or descending). |
91+
92+
---
93+
94+
### **Dict**
95+
96+
The `Dict` class is a key-value data structure similar to Python's `dict`. It allows for efficient storage and retrieval of data based on unique keys.
97+
98+
#### **Dict Methods**
99+
100+
| Method | Description |
101+
|---------------------------------|-----------------------------------------------------------------------------|
102+
| `void add(String key, Object value)` | Adds a key-value pair to the dictionary. |
103+
| `void set(String key, Object value)` | Updates the value associated with a key. |
104+
| `Object get(String key)` | Retrieves the value associated with a key. |
105+
| `void remove(String key)` | Removes a key-value pair from the dictionary. |
106+
| `void anullValue(String key)` | Sets the value of a key to `null`. |
107+
| `void sortByKeys(boolean ascending)` | Sorts the dictionary by its keys (ascending or descending). |
108+
| `void sortByValues(boolean ascending)` | Sorts the dictionary by its values (ascending or descending). |
109+
| `List keys()` | Returns a `List` of all keys in the dictionary. |
110+
| `List values()` | Returns a `List` of all values in the dictionary. |
111+
| `void restart()` | Resets the internal iterator for the dictionary. |
112+
| `void clear()` | Removes all key-value pairs from the dictionary. |
113+
| `List next(int step)` | Retrieves the next key-value pair based on the internal iterator. |
114+
| `int size()` | Returns the number of key-value pairs in the dictionary. |
115+
| `boolean containsKey(String key)` | Checks if the dictionary contains a specific key. |
116+
| `boolean containsValue(Object value)` | Checks if the dictionary contains a specific value. |
117+
| `boolean contains(Object any)` | Checks if the dictionary contains a specific key or value. |
118+
| `boolean isEqualTo(Dict other)` | Checks if the current dictionary is equal to another dictionary. |
119+
120+
---
121+
122+
## Examples
123+
124+
### **Using `List`**
125+
126+
```java
127+
import javaiterables.List;
128+
129+
public class Main {
130+
public static void main(String[] args) {
131+
List myList = new List();
132+
myList.append("Hello");
133+
myList.append(42);
134+
myList.append(3.14);
135+
136+
System.out.println("List contents:");
137+
for (int i = 0; i < myList.len(); i++) {
138+
System.out.println(myList.get(i));
139+
}
140+
141+
myList.sort(true); // Ascending is the variable which is given as true
142+
System.out.println("Sorted list:");
143+
myList.show();
144+
}
145+
}
146+
```
147+
148+
---
149+
150+
### **Using `Dict`**
151+
152+
```java
153+
import javaiterables.Dict;
154+
155+
public class Main {
156+
public static void main(String[] args) {
157+
Dict myDict = new Dict();
158+
myDict.add("name", "Alice");
159+
myDict.add("age", 30);
160+
myDict.add("height", 5.5);
161+
162+
System.out.println("Dictionary contents:");
163+
System.out.println("Name: " + myDict.get("name"));
164+
System.out.println("Age: " + myDict.get("age"));
165+
System.out.println("Height: " + myDict.get("height"));
166+
167+
myDict.remove("age");
168+
System.out.println("After removing 'age':");
169+
System.out.println("Contains 'age': " + myDict.containsKey("age"));
170+
}
171+
}
172+
```
173+
174+
---
175+
176+
## Testing
177+
178+
The library includes a `Test` class in the tests package to validate the functionality of `List` and `Dict`. To run the tests:
179+
180+
1. Compile the tests:
181+
182+
```bash
183+
javac -cp ./out/javaiterables.jar -d out ./tests/Test.java
184+
```
185+
186+
2. Run the tests:
187+
188+
```bash
189+
java -cp ./out/javaiterables.jar:out ./tests.Test
190+
```
191+
192+
3. Log file:
193+
194+
Look into the file test.log in the folder tests to see the last results of the tests.
195+
196+
---
197+
198+
## License
199+
200+
This library is open-source and available under the [MIT License](https://opensource.org/licenses/MIT). Feel free to use, modify, and distribute it as needed.

0 commit comments

Comments
 (0)