2017-08-03 20:50:53 -07:00
|
|
|
package org.nwapw.abacus.plugin;
|
|
|
|
|
|
|
|
import org.nwapw.abacus.number.NumberInterface;
|
|
|
|
|
2017-08-03 21:05:25 -07:00
|
|
|
import java.util.HashMap;
|
2017-08-03 20:50:53 -07:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
2017-08-04 11:24:07 -07:00
|
|
|
/**
|
|
|
|
* A class that holds data about a number implementation.
|
|
|
|
*/
|
2017-08-03 20:50:53 -07:00
|
|
|
public abstract class NumberImplementation {
|
|
|
|
|
2017-08-04 11:24:07 -07:00
|
|
|
/**
|
|
|
|
* The list of paths through which this implementation can be promoted.
|
|
|
|
*/
|
2017-08-08 10:13:35 -07:00
|
|
|
private Map<Class<? extends NumberInterface>, Function<NumberInterface, NumberInterface>> promotionPaths;
|
2017-08-04 11:24:07 -07:00
|
|
|
/**
|
|
|
|
* The implementation class for this implementation.
|
|
|
|
*/
|
2017-08-03 20:50:53 -07:00
|
|
|
private Class<? extends NumberInterface> implementation;
|
2017-08-04 11:24:07 -07:00
|
|
|
/**
|
|
|
|
* The priority of converting into this number implementation.
|
|
|
|
*/
|
2017-08-03 20:50:53 -07:00
|
|
|
private int priority;
|
|
|
|
|
2017-08-04 11:24:07 -07:00
|
|
|
/**
|
|
|
|
* Creates a new number implementation with the given data.
|
2017-08-04 13:20:57 -07:00
|
|
|
*
|
2017-08-04 11:24:07 -07:00
|
|
|
* @param implementation the implementation class.
|
2017-08-05 16:15:30 -07:00
|
|
|
* @param priority the priority, higher means more likely to be converted into.
|
2017-08-04 11:24:07 -07:00
|
|
|
*/
|
2017-08-04 13:20:57 -07:00
|
|
|
public NumberImplementation(Class<? extends NumberInterface> implementation, int priority) {
|
2017-08-03 21:05:25 -07:00
|
|
|
this.implementation = implementation;
|
|
|
|
this.priority = priority;
|
|
|
|
promotionPaths = new HashMap<>();
|
|
|
|
}
|
|
|
|
|
2017-08-04 11:24:07 -07:00
|
|
|
/**
|
|
|
|
* Gets the list of all promotion paths this implementation can take.
|
2017-08-04 13:20:57 -07:00
|
|
|
*
|
2017-08-04 11:24:07 -07:00
|
|
|
* @return the map of documentation paths.
|
|
|
|
*/
|
2017-08-04 13:20:57 -07:00
|
|
|
public final Map<Class<? extends NumberInterface>, Function<NumberInterface, NumberInterface>> getPromotionPaths() {
|
2017-08-03 22:16:08 -07:00
|
|
|
return promotionPaths;
|
|
|
|
}
|
|
|
|
|
2017-08-04 11:24:07 -07:00
|
|
|
/**
|
|
|
|
* Gets the implementation class used by this implementation.
|
2017-08-04 13:20:57 -07:00
|
|
|
*
|
2017-08-04 11:24:07 -07:00
|
|
|
* @return the implementation class.
|
|
|
|
*/
|
2017-08-04 13:20:57 -07:00
|
|
|
public final Class<? extends NumberInterface> getImplementation() {
|
2017-08-03 22:16:08 -07:00
|
|
|
return implementation;
|
|
|
|
}
|
|
|
|
|
2017-08-04 11:24:07 -07:00
|
|
|
/**
|
|
|
|
* Gets the priority of this number implementation.
|
2017-08-04 13:20:57 -07:00
|
|
|
*
|
2017-08-04 11:24:07 -07:00
|
|
|
* @return the priority.
|
|
|
|
*/
|
2017-08-04 13:20:57 -07:00
|
|
|
public final int getPriority() {
|
2017-08-03 22:16:08 -07:00
|
|
|
return priority;
|
|
|
|
}
|
|
|
|
|
2017-08-04 11:24:07 -07:00
|
|
|
/**
|
|
|
|
* Abstract function to create a new instance from a string.
|
2017-08-04 13:20:57 -07:00
|
|
|
*
|
2017-08-04 11:24:07 -07:00
|
|
|
* @param string the string to create a number from.
|
|
|
|
* @return the resulting number.
|
|
|
|
*/
|
2017-08-03 20:50:53 -07:00
|
|
|
public abstract NumberInterface instanceForString(String string);
|
2017-08-04 11:24:07 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the instance of pi with the given implementation.
|
2017-08-04 13:20:57 -07:00
|
|
|
*
|
2017-08-04 11:24:07 -07:00
|
|
|
* @return pi
|
|
|
|
*/
|
2017-08-03 20:50:53 -07:00
|
|
|
public abstract NumberInterface instanceForPi();
|
|
|
|
|
|
|
|
}
|