packaging all my classes into a nice package so I can send it to you

This commit is contained in:
nora 2021-01-31 12:22:06 +01:00
parent 4932ed7660
commit d9f980f1a9
16 changed files with 111 additions and 1 deletions

View file

@ -0,0 +1,49 @@
package com.github.nilstrieb.uselessclasses;
import java.util.Scanner;
/**
* When you're really lonely in your code and you need a buddy
*/
public class Buddy {
/**
* The name of the Buddy, for example Bobby
*/
private String name;
/**
* The scream of the buddy when it realizes that it's not real. No use cases for it. It's not self-conscious or anything like that. Yet. (the scream is a constant because the buddy will constantly be screaming (it's not a constant because of memory issues, simply call setSCREAM to be able to use it))
*/
public String SCREAM;
public Buddy(String name) {
this.name = name;
setSCREAM();
}
public void help(){
Scanner scn = new Scanner(System.in);
System.out.println("Hi my friend, I'm " + name);
System.out.println("What's you problem?");
scn.nextLine();
System.out.println("Sorry I can't help you with that because my code is very limited just like you ☜(゚ヮ゚☜)☜(゚ヮ゚☜)☜(゚ヮ゚☜)☜(゚ヮ゚☜)☜(゚ヮ゚☜)☜(゚ヮ゚☜)");
}
public void joke() {
System.out.println("There 👉 is 😶 nothing ❌ funny 😂 about ↩ my 😀👈 life ♥.");
try {
Thread.sleep(300);
} catch (InterruptedException ignored) {
}
System.out.println("Wait, there is something.");
try {
Thread.sleep(1400);
} catch (InterruptedException ignored) {
}
System.out.println("You.");
}
public void setSCREAM(){
SCREAM = "A".repeat(Integer.MAX_VALUE).repeat(Integer.MAX_VALUE).repeat(Integer.MAX_VALUE);
}
}

View file

@ -0,0 +1,50 @@
package com.github.nilstrieb.uselessclasses;
/**
* While being a very useful class, SingedInteger has a very big problem. It can't store decimal numbers.
* That's why this class exists.
*/
public class DecimalNumber {
long integerPart;
long decimalPart;
/**
* Create a new DecimalNumber from a d**ble
* A double, you ask? Shut the fuck up, I say.
* @param n The d**ble
*/
public DecimalNumber(double n){
String s = String.valueOf(n);
String[] ss = s.split("\\.");
System.out.println(ss[0]);
System.out.println(ss[1]);
integerPart = Long.parseLong(ss[0]);
decimalPart = Long.parseLong(ss[1]);
}
/**
* Create a new DecimalNumber directly from a String. No more stupid parsing, just stupid exceptions!
* @param s the thing with funny chars I forgot the name it was something long and thin
* @throws ValueShouldProbablyActuallyBeANumberAndNotSomeWeirdGibberishDumbProgrammerException yeah it does actually throw that good luck catching it
*/
public DecimalNumber(String s) throws ValueShouldProbablyActuallyBeANumberAndNotSomeWeirdGibberishDumbProgrammerException {
try {
String[] ss = s.split("\\.");
System.out.println(ss[0]);
System.out.println(ss[1]);
integerPart = Long.parseLong(ss[0]);
decimalPart = Long.parseLong(ss[1]);
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e){
throw new ValueShouldProbablyActuallyBeANumberAndNotSomeWeirdGibberishDumbProgrammerException();
}
}
/**
* Get the value as a d**ble
* @return The value as a d**ble
*/
public double getValue(){
return Double.parseDouble(integerPart + "." + decimalPart);
}
}

View file

@ -0,0 +1,82 @@
package com.github.nilstrieb.uselessclasses; //codereview comment: "nice imports"
import Requests.OpenTDB;
import java.util.ArrayList;
/**
* Generates random numbers based on OpenTDB trivia results. Should not be used too often. Should not be used actually.
*
* <p>
* Every trivia question has 4 answers, giving us a random number out of 4 for every question
* so now we just use the 4 as two binary digits and use them lol
* 200IQ move, ik
* </p>
*/
public class GoodRandom {
OpenTDB trivia = new OpenTDB();
/**
* Create a new {@code GoodRandom} with a seed
* @param seed The seed
*/
public GoodRandom(int seed) {
trivia.setCategory(seed % 20 + 10);
}
/**
* Create a new {@code GoodRandom}
*/
public GoodRandom() {
this(0);
}
/**
* Get a random integer from 0 to {@code max}. Integers are not distributed equally if {@code max} is not a power of 2.
* @param max The maximum number
* @return A random Integer from 0 to {@code max}
*/
public int randomInt(int max){
return randomInt(0, max);
}
/**
* Get a random integer from {@code min} to {@code max}. Integers are not distributed equally if {@code max} - {@code min} is not a power of 2.
* @param min The minimum number
* @param max The maximum number
* @return A random Integer from 0 to {@code max}
*/
public int randomInt(int min, int max){
int range = max - min;
//exponent of next biggest power of two
int digits = (int) Math.ceil(Math.log(range)/Math.log(2));
//how many times we need a digit from 0-3
int twoDigits = (int) Math.ceil(digits / 2d);
int resultNumber = 0;
//add the random number from 0-3 but shift it 2 bits to the left everytime
for (int i = 0; i < twoDigits; i++) {
resultNumber += Math.pow(4, i) * getFourDigit();
}
//normalize it, will lead to unbalanced results but das interessiert mich nicht
int resultNormalized = resultNumber % range;
return resultNormalized + min;
}
/**
* Get a random number from 0 to 3 using OpenTDB. It pulls a random trivia question,
* sorts the answers alphabetically and returns the position of the correct answer
* @return A random number from 0 to 3
*/
private int getFourDigit(){
trivia.getTrivia();
ArrayList<String> answers = new ArrayList<>();
String[] inc = trivia.getIncorrectAnswers();
String cor = trivia.getCorrectAnswer();
answers.add(cor);
answers.add(inc[0]);
answers.add(inc[1]);
answers.add(inc[2]);
answers.sort(null);
return answers.indexOf(cor);
}
}

View file

@ -0,0 +1,50 @@
package com.github.nilstrieb.uselessclasses;
/**
* When you need a way to store negative numbers
*/
public class SignedInteger {
int n;
boolean isNegative;
/**
* Create a new SignedInteger form an int (why you should do this? Why not.)
* @param n The i n t
*/
public SignedInteger(int n){
isNegative = n < 0;
this.n = Math.abs(n);
}
/**
* Get the value as an int
* @return The value
*/
int getValue(){
return isNegative ? -n : n;
}
/**
* Set the value. Saves memory. Because the programs this is used in are so huge
* @param n The new value
*/
void setValue(int n){
isNegative = n < 0;
this.n = Math.abs(n);
}
/**
* Add a new value. Can also be used to subtract something if the Parameter is negative.
* @param n The number to be added. Can be negative to subtract.
*/
void addValue(int n){
this.n += isNegative ? -n : n;
if(this.n < 0){
isNegative = !isNegative;
this.n = Math.abs(this.n);
}
}
}

View file

@ -0,0 +1,73 @@
package com.github.nilstrieb.uselessclasses;
/**
* Chars are quite useful for most applications, but sometimes, you need a lot of them
* Then variable naming can get confusing and char arrays are a bit too complicated to effectively work with
* That's when you should use StringOfChars, it stores a String (or Array) or chars and can be used very easily.
*/
public class StringOfChars {
private char[] string;
/**
* Create a new StringOfChars from lots of tiny cute chars (also called an 'array')
* @param letters
*/
public StringOfChars(char ... letters){
this.string = letters;
}
/**
* If you want to actually use the StringOfChars for anything (which you don't want to)
* @return The S T R I N G
*/
public String toString(){
return new String(string);
}
/**
* Get the char array itself
* @return The char array
*/
public char[] toCharArray(){
return string;
}
/**
* The length of the char array
* @return The length as an integer
*/
public int length(){
return string.length;
}
/**
* Get a single char at an index i
* @param i The index
* @return The Char
*/
public char atIndex(int i){
return string[i];
}
/**
* Append another char array
* @param chars The char array that should be appended
*/
public void append(char ... chars){
append(new StringOfChars(chars));
}
/**
* Append another StringOfChars
* @param string2 The StringOfChars
*/
public void append(StringOfChars string2){
char[] newString = new char[this.length() + string2.length()];
System.arraycopy(string, 0, newString, 0, this.length());
System.arraycopy(string2.toCharArray(), 0, newString, this.length(), string2.toString().length());
string = newString;
}
}

View file

@ -0,0 +1,38 @@
package com.github.nilstrieb.uselessclasses;
public class TestClass {
public static void main(String[] args) {
u8 myByte = new u8((short) 127);
System.out.println(myByte.val());
//max array size for u8: 2'050'000'000 - 2'100'000'000
//max array size for byte: 7'500'000'000 - 10'000'000'000
//max array size for short: 3'700'000'000 - 4'500'000'000
u8[][][] test = new u8[1000][1000][1000];
System.out.printf("no error for size: %,d", (long) test.length * (long) test[0].length * (long) test[0][0].length);
/*StringOfChars s = new StringOfChars('h', 'a');
s.append('l', 'l', 'o');
System.out.println(s.toString());
DecimalNumber dd = new DecimalNumber(2.4);
try{
DecimalNumber d = new DecimalNumber("hurensohn");
} catch (ValueShouldProbablyActuallyBeANumberAndNotSomeWeirdGibberishDumbProgrammerException e) {
e.printStackTrace();
}
Buddy bobby = new Buddy("bobby");
bobby.help();
bobby.joke();
GoodRandom random = new GoodRandom();
for (int i = 0; i < 10; i++) {
System.out.println(random.randomInt(20));
}*/
}
}

View file

@ -0,0 +1,13 @@
package com.github.nilstrieb.uselessclasses;
/**
* Sometimes I ask myself what is wrong with me but I always get a {@code ValueShouldProbablyActuallyBeANumberAndNotSomeWeirdGibberishDumbProgrammerException} instead of an answer
*/
public class ValueShouldProbablyActuallyBeANumberAndNotSomeWeirdGibberishDumbProgrammerException extends Exception{
@Override
public void printStackTrace() {
System.err.println("Holy fuck how can you be such a useless and dumb programmer wtf.");
System.err.println("Maybe don't fucking enter something that is not even a number. And in the end you're going to blame it on the end user. Pathetic.");
super.printStackTrace();
}
}

View file

@ -0,0 +1,33 @@
package com.github.nilstrieb.uselessclasses;
/**
* An unsigned byte.
* Unlike other programming languages like C, C++ and many others, Java is too high-level to
* bother with having or not having sign bits. It just has them by default.
* <p>
* This creates a problem,
* because sometimes you might want to save memory and use unsigned bytes.
* In this case, this class is perfect for you because it does exactly that.
* (The 'exactly that' refers to 'creates a problem')
*/
public class u8 {
private final byte b;
/**
* Create a new u8. You need to input a short because that is how Java works.
* The value will be stored in a byte though.
* @param s The short value
*/
public u8(short s) {
b = (byte) s;
}
/**
* Get the value back.
* @return The value as a short because that is how Java works.
*/
public short val(){
return b;
}
}