Rename all java files to tjava
This commit is contained in:
@@ -124,7 +124,7 @@ public class EvelynImpl implements Evelyn {
|
||||
ΩSyrupAmountΩ totalDistributedSumSyrup = totalDistributedSums.amountB();
|
||||
System.out.println("Total amount currently distributed: " + totalDistributedSumSolana
|
||||
+ " / " + totalDistributedSumSyrup);
|
||||
totalDistributedSum
|
||||
|
||||
Pair amountsLocked = desiredPositionCalculator.calculateLockedSums(currentPriceFromChain.amount());
|
||||
ΩSolanaAmountΩ amountLockedSolana = amountsLocked.amountA();
|
||||
ΩSyrupAmountΩ amountLockedSyrup = amountsLocked.amountB();
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.fanitas.evelyn.math;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
|
||||
import static java.math.BigDecimal.ZERO;
|
||||
|
||||
public class BigDecimalUtils {
|
||||
public static BigDecimal min(BigDecimal a, BigDecimal b) {
|
||||
return a.compareTo(b) <= 0 ? a : b;
|
||||
}
|
||||
|
||||
public static BigDecimal max(BigDecimal a, BigDecimal b) {
|
||||
return a.compareTo(b) >= 0 ? a : b;
|
||||
}
|
||||
|
||||
public static BigDecimal sqrt(BigDecimal value, MathContext mc) {
|
||||
if (value.compareTo(ZERO) < 0) {
|
||||
throw new IllegalArgumentException("sqrt af negativ værdi");
|
||||
}
|
||||
if (value.compareTo(ZERO) == 0) {
|
||||
return ZERO;
|
||||
}
|
||||
|
||||
BigDecimal x = new BigDecimal(Math.sqrt(value.doubleValue()), mc);
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
x = x.add(value.divide(x, mc), mc).divide(TWO, mc);
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
public static double erf(BigDecimal x) {
|
||||
double value = x.doubleValue();
|
||||
double sign = value < 0 ? -1.0 : 1.0;
|
||||
value = Math.abs(value);
|
||||
|
||||
double t = 1.0 / (1.0 + 0.5 * value);
|
||||
|
||||
double tau = t * Math.exp(
|
||||
-value * value
|
||||
- 1.26551223
|
||||
+ t * (1.00002368
|
||||
+ t * (0.37409196
|
||||
+ t * (0.09678418
|
||||
+ t * (-0.18628806
|
||||
+ t * (0.27886807
|
||||
+ t * (-1.13520398
|
||||
+ t * (1.48851587
|
||||
+ t * (-0.82215223
|
||||
+ t * 0.17087277))))))))
|
||||
);
|
||||
|
||||
double result = sign * (1.0 - tau);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static final BigDecimal TWO = new BigDecimal("2");
|
||||
public static final BigDecimal THREE = new BigDecimal("3");
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.r35157.libs.math;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
|
||||
public interface UtilsBigDecimal {
|
||||
BigDecimal min(BigDecimal a, BigDecimal b);
|
||||
BigDecimal max(BigDecimal a, BigDecimal b);
|
||||
BigDecimal sqrt(BigDecimal value, MathContext mc);
|
||||
|
||||
BigDecimal TWO = new BigDecimal("2");
|
||||
BigDecimal THREE = new BigDecimal("3");
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.r35157.libs.math;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public interface UtilsDouble {
|
||||
double erf(BigDecimal x);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.r35157.libs.notification;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface AddressedNotifier<
|
||||
D extends NotificationDestination,
|
||||
M extends NotificationMessage>
|
||||
{
|
||||
void push(D destination, M message) throws IOException;
|
||||
|
||||
default BoundNotifier<M> bind(D destination) {
|
||||
return message -> push(destination, message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.r35157.libs.notification;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface BoundNotifier<M extends NotificationMessage> {
|
||||
void push(M message) throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package com.r35157.libs.notification;
|
||||
|
||||
public interface NotificationDestination {}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.r35157.libs.notification;
|
||||
|
||||
public interface NotificationMessage {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.r35157.libs.notification.impl.discord;
|
||||
|
||||
import com.r35157.libs.notification.NotificationMessage;
|
||||
|
||||
public record DiscordMessage(String text) implements NotificationMessage {
|
||||
public DiscordMessage {
|
||||
if (text == null || text.isBlank()) {
|
||||
throw new IllegalArgumentException("Discord message cannot be blank");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.r35157.libs.notification.impl.discord;
|
||||
|
||||
import com.r35157.libs.notification.BoundNotifier;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.http.HttpClient;
|
||||
|
||||
public class DiscordNotifier implements BoundNotifier<DiscordMessage> {
|
||||
|
||||
public DiscordNotifier(URL discordWebhookUrl) {
|
||||
this.httpClient = HttpClient.newHttpClient();
|
||||
this.discordWebhookUrl = discordWebhookUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void push(DiscordMessage message) throws IOException {
|
||||
throw new UnsupportedOperationException("Not implemented yet!");
|
||||
}
|
||||
|
||||
private void test() throws IOException {
|
||||
URL discordWebhookUrl = null;
|
||||
|
||||
BoundNotifier<DiscordMessage> boundNotifier = new DiscordNotifier(discordWebhookUrl);
|
||||
|
||||
DiscordMessage message = new DiscordMessage("Hello World!");
|
||||
boundNotifier.push(message);
|
||||
}
|
||||
|
||||
private final HttpClient httpClient;
|
||||
private final URL discordWebhookUrl;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.r35157.libs.notification.impl.pushover;
|
||||
|
||||
import com.r35157.libs.notification.NotificationMessage;
|
||||
|
||||
public record PushMessage(String text) implements NotificationMessage {
|
||||
public PushMessage {
|
||||
if (text == null || text.isBlank()) {
|
||||
throw new IllegalArgumentException("Push message cannot be blank");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.r35157.libs.notification.impl.smtp;
|
||||
|
||||
public record EmailBody(String text) {
|
||||
public EmailBody {
|
||||
if (text == null || text.isBlank()) {
|
||||
throw new IllegalArgumentException("Email body cannot be blank!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.r35157.libs.notification.impl.smtp;
|
||||
|
||||
import com.r35157.libs.notification.NotificationMessage;
|
||||
|
||||
public record EmailMessage(
|
||||
EmailSubject subject,
|
||||
EmailBody body
|
||||
) implements NotificationMessage {
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.r35157.libs.notification.impl.smtp;
|
||||
|
||||
public record EmailSubject(String text) {
|
||||
public EmailSubject {
|
||||
if (text == null || text.isBlank()) {
|
||||
throw new IllegalArgumentException("Email subject cannot be blank!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.r35157.libs.solana.valuetypes;
|
||||
|
||||
import com.r35157.libs.valuetypes.basic.CurrencyType;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Defines well-known currency types used by the Solana integration.
|
||||
*
|
||||
* <p>Each enum value wraps a {@link CurrencyType} with a stable identifier and a
|
||||
* human-readable currency name. These predefined values are intended for common
|
||||
* currencies that the Solana-related modules need to reference consistently.</p>
|
||||
*/
|
||||
public enum WellKnownCurrencyTypes {
|
||||
/**
|
||||
* Native Solana currency.
|
||||
*/
|
||||
SOLANA(new CurrencyType(
|
||||
UUID.fromString("019e0116-fce5-792f-a647-fa6da4dffec5"),
|
||||
"Solana",
|
||||
"SOL")
|
||||
),
|
||||
|
||||
/**
|
||||
* Syrup USDC token currency.
|
||||
*/
|
||||
SYRUPUSDC(new CurrencyType(
|
||||
UUID.fromString("019e1d51-0600-7956-8231-f3b7058a91c2"),
|
||||
"SyrupUSDC",
|
||||
"SyrupUSDC")
|
||||
);
|
||||
|
||||
/**
|
||||
* Creates a well-known currency type entry.
|
||||
*
|
||||
* @param currencyType the currency type represented by this enum value
|
||||
*/
|
||||
WellKnownCurrencyTypes(CurrencyType currencyType) {
|
||||
this.currencyType = currencyType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currency type represented by this enum value.
|
||||
*
|
||||
* @return the represented currency type
|
||||
*/
|
||||
public CurrencyType getCurrencyType() {
|
||||
return currencyType;
|
||||
}
|
||||
|
||||
private final CurrencyType currencyType;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.r35157.libs.valuetypes.basic;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public record CurrencyType(
|
||||
UUID id,
|
||||
String name,
|
||||
String symbol
|
||||
) {
|
||||
@Override
|
||||
public @NotNull String toString() {
|
||||
return symbol;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.r35157.libs.valuetypes.basic;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Semantic Versioning (SemVer):
|
||||
* A version number has the form MAJOR.MINOR.PATCH.
|
||||
* - Increment MAJOR for incompatible API changes,
|
||||
* - Increment MINOR for added functionality in a backward-compatible way,
|
||||
* - Increment PATCH for backward-compatible bug fixes or improvements.
|
||||
* TODO: Not the whole specification is implemented yet!
|
||||
*/
|
||||
public record SemanticVersion(int major, int minor, int patch) {
|
||||
/**
|
||||
* Creates a SemanticVersion and validates that all components are valid.
|
||||
*
|
||||
* @throws IllegalArgumentException if any of {@code major}, {@code minor}, or {@code patch} is negative
|
||||
*/
|
||||
public SemanticVersion {
|
||||
initializationGuardClause(major, minor, patch);
|
||||
}
|
||||
|
||||
public static SemanticVersion of(int major, int minor, int patch) {
|
||||
return new SemanticVersion(major, minor, patch);
|
||||
}
|
||||
|
||||
public static SemanticVersion of(int major, int minor) {
|
||||
return of(major, minor, 0);
|
||||
}
|
||||
|
||||
public static SemanticVersion of(int major) {
|
||||
return of(major, 0);
|
||||
}
|
||||
|
||||
public static SemanticVersion of(@NotNull String versionStr) {
|
||||
final String s = versionStr.trim();
|
||||
|
||||
final Matcher m = SEMVER_REGEX.matcher(s);
|
||||
if (!m.matches()) {
|
||||
throw new IllegalArgumentException("Invalid semantic version: '" + versionStr + "'!");
|
||||
}
|
||||
|
||||
try {
|
||||
final int major = Integer.parseInt(m.group(1));
|
||||
final int minor = m.group(2) != null ? Integer.parseInt(m.group(2)) : 0;
|
||||
final int patch = m.group(3) != null ? Integer.parseInt(m.group(3)) : 0;
|
||||
return of(major, minor, patch);
|
||||
} catch (NumberFormatException e) {
|
||||
// Happens only with overruns
|
||||
throw new IllegalArgumentException("Invalid semantic version: '" + versionStr + "'!", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String toString() {
|
||||
return "%d.%d.%d".formatted(major, minor, patch);
|
||||
}
|
||||
|
||||
private void initializationGuardClause(int major, int minor, int patch) throws IllegalArgumentException {
|
||||
if (major < 0) throw new IllegalArgumentException("Version element 'major' cannot be negative - was '" + major + "'!");
|
||||
if (minor < 0) throw new IllegalArgumentException("Version element 'minor' cannot be negative - was '" + minor + "'!");
|
||||
if (patch < 0) throw new IllegalArgumentException("Version element 'patch' cannot be negative - was '" + patch + "'!");
|
||||
}
|
||||
|
||||
private static final Pattern SEMVER_REGEX =
|
||||
Pattern.compile("^(\\d+)(?:\\.(\\d+)(?:\\.(\\d+))?)?$");
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.r35157.libs.valuetypes.basic;
|
||||
|
||||
public record SmtpConfiguration(
|
||||
NetworkEndPoint networkEndPoint,
|
||||
Credentials credentials
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.r35157.libs.valuetypes.basic;
|
||||
|
||||
public record TradingPair(
|
||||
CurrencyType base, // The thing you are buying or selling.
|
||||
CurrencyType quote // The currency/unit used to price the base asset.
|
||||
) { }
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.r35157.nenjim.hubd;
|
||||
|
||||
import com.r35157.nenjim.hubd.journal.Journal;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface NenjimHub {
|
||||
/**
|
||||
* A no-operation (noop). This method is suppoted to do nothing.
|
||||
*/
|
||||
void noop();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param journal
|
||||
*/
|
||||
void monitorJournal(@NotNull Journal journal);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.r35157.nenjim.hubd.ctx;
|
||||
|
||||
import com.r35157.libs.valuetypes.basic.SemanticVersion;
|
||||
|
||||
public record Context(
|
||||
) {
|
||||
public String getName() {
|
||||
return "Some Context";
|
||||
}
|
||||
|
||||
public SemanticVersion getVersion(String fqPackageName) {
|
||||
return null; // new SemanticVersion(0, 1, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.r35157.nenjim.hubd.impl.ref;
|
||||
|
||||
import com.r35157.nenjim.hubd.journal.Journal;
|
||||
import com.r35157.nenjim.hubd.journal.JournalManager;
|
||||
|
||||
public class JournalManagerImpl implements JournalManager {
|
||||
@Override
|
||||
public Journal getJournal(String s) {
|
||||
return new Journal(null, null, null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.r35157.nenjim.hubd.impl.ref;
|
||||
|
||||
import com.r35157.nenjim.hubd.ctx.Context;
|
||||
import com.r35157.nenjim.hubd.NenjimHub;
|
||||
//import org.apache.logging.log4j.LogManager;
|
||||
//import org.apache.logging.log4j.Logger;
|
||||
import java.lang.management.ClassLoadingMXBean;
|
||||
import java.lang.management.ManagementFactory;
|
||||
|
||||
import com.r35157.nenjim.hubd.ctx.ContextManager;
|
||||
import com.r35157.nenjim.hubd.journal.JournalManager;
|
||||
import com.r35157.nenjim.hubd.impl.ref.JournalManagerImpl;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class Main {
|
||||
static void main(String[] args) throws Exception {
|
||||
new Main(args).start();
|
||||
}
|
||||
|
||||
public Main(String[] args) throws Exception {
|
||||
/*hub = new NenjimHubImpl();
|
||||
log.info("Initializing NenjimHub...");
|
||||
|
||||
String classesCacheDirRaw = "~/.config/nenjim/cache/classes";
|
||||
String classesCacheDir = (classesCacheDirRaw.startsWith("~/"))
|
||||
? System.getProperty("user.home") + classesCacheDirRaw.substring(1)
|
||||
: classesCacheDirRaw;
|
||||
Path pathToClassesCache = Path.of(classesCacheDir);
|
||||
|
||||
if(Files.exists(pathToClassesCache) == false) {
|
||||
System.err.println("Cannot find '" + classesCacheDirRaw + "'");
|
||||
System.exit(-1);
|
||||
}*/
|
||||
|
||||
//System.out.println("Initializing initial NenjimClassLoader with default context...");
|
||||
JournalManager journalManager = new JournalManagerImpl();
|
||||
ContextManager contextManager = new ContextManagerImpl();
|
||||
Context defaultContext = contextManager.getDefault();
|
||||
|
||||
NenjimClassLoader nenjimClassLoader = new NenjimClassLoader(journalManager, defaultContext);
|
||||
Class<?> clazz = nenjimClassLoader.findClass("com.r35157.nenjim.hubd.impl.ref.NenjimHubImpl");
|
||||
|
||||
/*NenjimHub nenjimHub = null;
|
||||
Context defaultContext = new Context();
|
||||
|
||||
Object instance = clazz.getDeclaredConstructor().newInstance();
|
||||
NenjimKicker kicker = (NenjimKicker)instance;
|
||||
*/
|
||||
int a = 0;
|
||||
}
|
||||
|
||||
private void start() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.r35157.nenjim.hubd.impl.ref;
|
||||
|
||||
import com.r35157.libs.valuetypes.basic.SemanticVersion;
|
||||
import com.r35157.nenjim.hubd.ctx.Context;
|
||||
import com.r35157.nenjim.hubd.journal.Journal;
|
||||
import com.r35157.nenjim.hubd.journal.JournalManager;
|
||||
import com.r35157.nenjim.hubd.module.Release;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public final class NenjimClassLoader extends ClassLoader {
|
||||
// TODO: Check protection - it is only main that can create a 'half' initialized classloader (and set the rest with setters afterwards)
|
||||
NenjimClassLoader(JournalManager journalManager, Context context) {
|
||||
this.journalManager = journalManager;
|
||||
this.context = context;
|
||||
//moduleVersion = new SemanticVersion(0, 1, 0);
|
||||
}
|
||||
|
||||
private String getModuleName(String className) {
|
||||
return className.substring(0, className.lastIndexOf("."));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?> findClass(String className) throws ClassNotFoundException {
|
||||
System.out.println("NenjimClassLoader asked to load '" + className + "'...");
|
||||
|
||||
// Check if we have any local version preferences configured for the associated Context.
|
||||
SemanticVersion version = context.getVersion(className);
|
||||
|
||||
if(version == null) {
|
||||
// No local configurations for a specific version has been configured for this package
|
||||
// in this Context. Use the version the developer do recommend in the Journal.
|
||||
String moduleName = getModuleName(className);
|
||||
System.out.println(" Context (" + context.getName() + ") does NOT have any special version requirements for the module '" + moduleName + "' - use vendor recommendation from journal...");
|
||||
Journal journal = journalManager.getJournal(moduleName);
|
||||
Release release = journal.getRelease(version);
|
||||
System.out.println(" Journal did recommend version '" + version + "' for the module '" + moduleName + "'");
|
||||
}
|
||||
System.out.println("Searching for class '" + className + "' in local Nenjim class cache...");
|
||||
String relativePath = className.replace('.', '/') + ".class";
|
||||
int a = 0;
|
||||
/*
|
||||
Path classFile = classCacheRoot.resolve(relativePath);
|
||||
|
||||
if (!Files.exists(classFile)) {
|
||||
throw new ClassNotFoundException("Class not found: " + className + " at " + classFile);
|
||||
}
|
||||
|
||||
try {
|
||||
byte[] classBytes = Files.readAllBytes(classFile);
|
||||
return defineClass(className, classBytes, 0, classBytes.length);
|
||||
} catch (IOException e) {
|
||||
throw new ClassNotFoundException("Failed to load class: " + className, e);
|
||||
}
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
|
||||
private JournalManager journalManager;
|
||||
private Context context;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.r35157.nenjim.hubd.impl.ref;
|
||||
|
||||
import com.r35157.nenjim.hubd.NenjimHub;
|
||||
import com.r35157.nenjim.hubd.journal.Journal;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class NenjimHubImpl implements NenjimHub {
|
||||
@Override
|
||||
public void noop() {
|
||||
log.debug("NOOP executed.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void monitorJournal(@NotNull Journal journal) {
|
||||
log.warn("monitorJournal IS NOT IMPLEMENTED!");
|
||||
}
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(NenjimHubImpl.class);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.r35157.nenjim.hubd.journal;
|
||||
|
||||
public interface JournalManager {
|
||||
Journal getJournal(String moduleName);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.r35157.nenjim.hubd.module;
|
||||
|
||||
public record Module() {
|
||||
}
|
||||
Reference in New Issue
Block a user