Skip to content
This repository has been archived by the owner on Jan 10, 2019. It is now read-only.

InsanusMokrassar/IObjectK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IObject

How to import?

Maven

<dependency>
    <groupId>com.github.insanusmokrassar</groupId>
    <artifactId>IObjectK</artifactId>
    <version>1.11.3</version>
</dependency>

Gradle

implementation 'com.github.insanusmokrassar:IObjectK:1.11.3'

Old Gradle

compile 'com.github.insanusmokrassar:IObjectK:1.11.3'

Versions

Available versions:

  • 1.1
  • 1.3
  • 1.4
  • 1.5
  • 1.6
  • 1.7
  • 1.8
  • 1.9
    • 1.9.1
    • 1.9.2
  • 1.10 - Not recommended
    • 1.10.1 - Not recommended
    • 1.10.2
    • 1.10.3
    • 1.10.4
    • 1.10.5
    • 1.10.6
  • 1.11
    • 1.11.1
    • 1.11.2
    • 1.11.3

What for?

This repository was created for give an opportunity to simplify using objects such as:

  1. JSON
  2. Map/HashMap
  3. Databases (simple)
  4. Some web/local databases via sockets
  5. Some web/local connections
  6. Common databases

JSON and Map/HashMap

JSON - format of data such as

{
  "firstField" : "firstValue",
  "secondField" : [
    "it",
    "is",
    "second",
    "value",
    "as",
    "array"
  ],
  "thirdField" : {
    "it is" : "inner json"
  }
}

It's can be converted to simple iobject.

Databases (simple)

In simple ways database it is repository which contain key-value pairs. It seems that we can create some simple IOStream for work with this repository.

Databases

For common and complicated databases we have CommonIObject

This interface can be used as:

import com.github.insanusmokrassar.IObjectK.interfaces.CommonIObject;
import com.github.insanusmokrassar.IObjectK.exceptions.ReadException;

public class SomeDatabaseStream implements CommonIObject<YourCustomClassAsChooser, Object> {
    //Body of class
    @Override
    public void get(YourCustomClassAsChooser chooser) throws InputException{
        return chooser.choose();
    }
}

public class YourCustomClassAsChooser {
    protected Object[] arguments;
    
    public YourCustomClassAsChooser(Object... argumentsToChoose) {
        this.arguments = argumentsToChoose;
    }
    
    public Object choose() {
        //some choose strategy
        return result;
    }
}

As you can see, you can realise any strategy to get your values - it seems that if you want to add new feature - you may not override old system

Safe operations

If you watch to dependency tree, you can see that CommonIObject is extend to classes:

And all heirs of CommonIObject can put in other methods as safety objects.

For example, if you have some user interface that must only read from database, you can do that as:

import com.github.insanusmokrassar.IObjectK.interfaces.IInputObject;
import com.github.insanusmokrassar.IObjectK.exceptions.ReadException;

public class ExampleClass {
    /**
    * this method can be put instance of SomeDatabaseStream, 
    * but methods to change database state is not accessible for class
    */
    public void someMethod(IInputObject<YourCustomClassAsChooser, Object> inputObject) {
        System.out.println(inputObject.get(someKeyInObject));
    }
}