Sueta
KI

KinQ

1.0

A LinQ Portation for Java | Easy filter your lists and collections

·Plugin

KinQ
LinQ for Java

What is LinQ ?

With LinQ you can easily filter Lists to your liking.
It's present in C# and uses the Lambda expression for filters.

This library requires Java Language Level 8

Example 1

You've got an array of Players and you want to get the username of everyone

Its pretty easy with KinQ

ArrayList<Player> myPlayerArray = new ArrayList<>();
KinQ kinQ = new KinQ(myPlayerArray);
Collection<String> usernames = kinQ.select("username").toList();

What did I do there ?

You have to create a new Instance of the "KinQ" class.
Pass your list in the constructor.

Then I used the "select(Fieldname)" method.
You only have to pass the fieldname.
You can also enter private fieldnames, Kinq will retrieve the value automatically.

Finally, toList converted everything to a list and returned it.

Example 2
You've got an array of Players and you want to get the players with more that 5 points.

Again its pretty easy with KinQ

ArrayList<Player> myPlayerArray = new ArrayList<>();
KinQ kinQ = new KinQ(myPlayerArray);
Collection<Player> playersWithMatchingScore = kinQ.where(Player.class, player -> player.getScore() > 5).toList();

What did I do there ?

You have to create a new Instance of the "KinQ" class.
Pass your list in the constructor.

Then I used the "where(Class type, Lambda Filter)"method.
You have to pass the filter in lambda expression. Optionally you can pass the type first. So the Lambda expression recognizes which object is being passed to it.

Finally, toList converted everything to a list and returned it.

You can combine these actions to your pleasure.

Please provide me feedback in the comments and tell me new feature ideas and maybe I'll implement them ;)

Similar projects

Plugin →