Calculator++ core module

This commit is contained in:
serso
2012-09-20 12:07:55 +04:00
parent f909b49c7c
commit 33db715776
12 changed files with 1140 additions and 1091 deletions

View File

@@ -0,0 +1,17 @@
package org.solovyev.math.units;
import org.jetbrains.annotations.NotNull;
/**
* User: serso
* Date: 4/21/12
* Time: 7:54 PM
*/
public interface Unit<V> {
@NotNull
V getValue();
@NotNull
UnitType<V> getUnitType();
}

View File

@@ -0,0 +1,42 @@
package org.solovyev.math.units;
import org.jetbrains.annotations.NotNull;
/**
* User: serso
* Date: 4/21/12
* Time: 7:53 PM
*/
public interface UnitConverter<T> {
boolean isSupported(@NotNull UnitType<?> from, @NotNull UnitType<T> to);
@NotNull
Unit<T> convert(@NotNull Unit<?> from, @NotNull UnitType<T> toType);
public static class Dummy implements UnitConverter<Object> {
@NotNull
private static final Dummy instance = new Dummy();
@NotNull
public static <T> UnitConverter<T> getInstance() {
return (UnitConverter<T>)instance;
}
private Dummy() {
}
@Override
public boolean isSupported(@NotNull UnitType<?> from, @NotNull UnitType<Object> to) {
return false;
}
@NotNull
@Override
public Unit<Object> convert(@NotNull Unit<?> from, @NotNull UnitType<Object> toType) {
throw new IllegalArgumentException();
}
}
}

View File

@@ -0,0 +1,42 @@
package org.solovyev.math.units;
import org.jetbrains.annotations.NotNull;
/**
* User: serso
* Date: 4/21/12
* Time: 8:01 PM
*/
public class UnitImpl<V> implements Unit<V> {
@NotNull
private V value;
@NotNull
private UnitType<V> unitType;
private UnitImpl() {
}
@NotNull
public static <V> Unit<V> newInstance(@NotNull V value, @NotNull UnitType<V> unitType) {
final UnitImpl<V> result = new UnitImpl<V>();
result.value = value;
result.unitType = unitType;
return result;
}
@NotNull
@Override
public V getValue() {
return this.value;
}
@NotNull
@Override
public UnitType<V> getUnitType() {
return unitType;
}
}

View File

@@ -0,0 +1,16 @@
package org.solovyev.math.units;
import org.jetbrains.annotations.NotNull;
/**
* User: serso
* Date: 4/21/12
* Time: 7:55 PM
*/
public interface UnitType<V> {
@NotNull
Class<V> getUnitValueClass();
boolean equals(@NotNull Object o);
}