1.1 Introduction to Bluemint - Auropol/Bluemint GitHub Wiki
Welcome to wiki of the Bluemint project !
Bluemint library is a library targetted on adding methods unavailable in standard version of JDK. The library is in an "embryonic" stage, which means it is highly unstable full of unfunctional code that will be cleaned up by the new unstable releases.
- Introduction to Bluemint
Firstly you need to import the library :
- Gradle
For Gradle, do :
def urlFile = { url, name -> File file = new File("$buildDir/download/${name}.jar") file.parentFile.mkdirs() if (!file.exists()) { new URL(url).withInputStream { downloadStream -> file.withOutputStream { fileOut -> fileOut << downloadStream } } } files(file.absolutePath) } dependencies { compile urlFile('https://github.com/Auropol/Bluemint/releases/download/(tag of the release)/(jarfile of the release)', '(tag of the release)') }
this downloads the library everytime you build your project into a jar file for example.
*Maven
For Maven, do :
mvn install:install-file -Dfile=<https://github.com/Auropol/Bluemint/releases/download/(tag of the release)/(jarfile of the release)> -DgroupId=<me.auropol> -DartifactId=<(tag of the release)> -Dversion=<(version of the jarfile artifact, fe. if the artifact is named "Bluemint-1.0-SNAPSHOT", then the version is "1.0-SNAPSHOT")> -Dpackaging=<jar>
For native Java compiler, use the tools that your IDE has for importing the library. For example, IntelliJ has a function named "Project Structure" that contains "Libraries" section, then click on the "+" button to add the local build artifact (you need to firstly download the library jar).
After this, you can use every tool in the library. For initializing the library, firstly import BluemintInitializer by import me.auropol.bluemint.BluemintInitializer, then add new BluemintInitializer().init() to your main(String[] args) method or other method that has the function of being the main method in your project.
After all of this, you are fully prepared to use Bluemint library !
Now, we will write a simple software that will generate unique story everytime you will refresh it. We will start with importing all the dependencies :
Firstly import Container class which will be used as a package full of strings that will be transported to String array: import me.auropol.bluemint.primitive.Container;
Then import Wrapper class which will be used for generating random numbers from array full of numbers that will be picked by a picker: import me.auropol.bluemint.primitive.Wrapper;
After that, import RandStream interface which will be used for picking strings randomly from String array that will be then combined to create a short story: import me.auropol.bluemint.util.RandStream;.
Alright, we imported all the dependencies, now it is time to code the software:
Firstly, create new class that will contain the code of our simple software: public class Storyteller {
Then, add a method with String or void return type (that depends on whether you want to use the story as a String so that you can use it in another methods as a return type or for filling the String dependency in a constructor scope, or you want use the story as for outputing to a console in a void fe.). Because we want to use the String in a main method, we will output it without creating a String method: public static void main(String[] args) {
After that, add arrays that contain values that you will then pick from the array by a picker that you will output to a String:
final String[] person = Container.manage().createArrayString("Entity", "AI");
final String[] work = Container.manage().createArrayString("Engineer, Astrobiologist", "Xenobiologist", "Drive Engineer", "Fuel Maintainer", "Cargo Manager", "Repairer", "Colonist", "Physicist", "Scientist");
final String[] log = Container.manage().createArrayString("log snippet", "personal information device");
final String[] initWord = Container.manage().createArrayString("Hello, this is", "Hi, that's", "Hi, this is", "Hello, that's");
final String[] arrival = Container.manage().createArrayString("We arrived at", "We are now at");
final String[] starClass = Container.manage().createArrayString("Red dwarf", "White dwarf", "Blue star", "Yellow star" + "Red giant");
final String[] likeStar = Container.manage().createArrayString("like our star", "like a star from sci-fi", "like a star which you can see on an alien world");
final String[] planetClass = Container.manage().createArrayString("Volcanic one", "Bountiful one", "Freezing one", "Irradiated one", "Oceanic one", "Superheated one");
final String[] landingCause = Container.manage().createArrayString("our ship is very damaged and our last chance to save us from dying in space was warping in the nearest system that was in our range", "our mission is to colonize new planets, and this one is great for that", "this planet has a big energetic potential", "we found an interesting flora and fauna on the planet. Some of the fauna is highly intelligent and formed a primitive civilization !", "our ship contains a deadly alien life form, and this is the last chance to get rid of that.");
final String[] wonder = Container.manage().createArrayString("what we will discover here.", "if someone alien for this planet like us wasn't here before us.", "if our mission will be successful after all."); `
final is for defining that this value can equal only this function/field, which means you don't need to use it, and you can replace the String[] by any data value that you want, but remember to convert them to a String, same with String in createArrayString() function, (if String[]is changed to long[] for example, then createArrayString() will be changed to createArrayLong()).
Then you can add other methods to the code that will be converted to String which are not arrays, in my case it is:
final int numYear = Wrapper.wrap().pickRandomlyFromRange(2069, 3969);
final int numPlanet = Wrapper.wrap().pickRandomlyFromRange(1, 9);
final String name = RandStream.generateRandomLetter(true) + RandStream.generateRandomLetter(false) + RandStream.generateRandomLetter(false) + RandStream.generateRandomLetter(false);
final String planetName = RandStream.generateRandomLetter(true) + RandStream.generateRandomLetter(true) + RandStream.generateRandomLetter(true) + RandStream.generateRandomLetter(true) + Wrapper.wrap().pickRandomlyFromRange(1, 20000);
final String starName = RandStream.generateRandomLetter(true) + RandStream.generateRandomLetter(true) + RandStream.generateRandomLetter(true) + RandStream.generateRandomLetter(true) + Wrapper.wrap().pickRandomlyFromRange(1, 20000) + RandStream.generateRandomLetter(false);`
pickRandomlyFromRange() is used for picking random numbers from an
integer array that contains numbers from minimal defined integer to maximal defined integer and generateRandomLetter() is used for generating random characters from an english alphabet, boolean uppercase defines if the character should be uppercase.
Then pick the strings from array by adding Strings that are using pickFrom() method imported from RandStream (you can also use pickInOrder() method, but this method picks values in order from first to last):
String pers = RandStream.pickFrom(person);
String wor = RandStream.pickFrom(work);
String lo = RandStream.pickFrom(log);
String initWor = RandStream.pickFrom(initWord);
String arrivalL = RandStream.pickFrom(arrival);
String starClas = RandStream.pickFrom(starClass);
String likeSta = RandStream.pickFrom(likeStar);
String planeClas = RandStream.pickFrom(planetClass);
String landingCaus = RandStream.pickFrom(landingCause);
String wonde = RandStream.pickFrom(wonder);`
Finally, we can output the result by using a method that outputs the String into a console. We will use System.out.println() method for that, but you can generate a JPanel and output the String to it:
System.out.println("YEAR" + " " + String.valueOf(numYear) + " " + pers + " " + wor + " " + name + " " + "'s" + " " + lo + " "+ "." + " " + "The"
+ " " + lo + " " + "contains" + " " + " " + "this :");
System.out.println(initWor + " " + pers+ " " + wor + " " + name+ " " + ".");
System.out.println(arrivalL+ " " + starName+ " " + "which is a "+ " " + starClas+ " " + likeSta+ " " + ".");
System.out.println("This star system has"+ " " + String.valueOf(numPlanet)+ " " + "planets" + " "+ "and we want to land on the"+ " " + planeClas
+ " "+ "which we named" + " " + planetName + " "+ "because" + " "+ landingCaus + " "+ ".");
System.out.println("I wonder,"+ " " + wonde + " ");`
`" "` is used because Strings do not use whitespace characters for seperating when added toegether.
And finally, add the last bracelets that mark the end of public static void main(String[] args) { and public class Storyteller { :
}}
And that is it ! All the documented code used in the wiki is availible in the Bluemint Project repository.
For more documentation of Bluemint Project, visit other pages that are directly linked to this one.
- List of pages on this wiki
- Bluemint repository link : Bluemint repository