Skip to content

Commit

Permalink
Adjustments for Java 1.6. Release 0.3.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbe24 committed Sep 23, 2014
1 parent 5f1a541 commit 29415cc
Show file tree
Hide file tree
Showing 28 changed files with 58 additions and 78 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'eclipse'

sourceCompatibility = 1.7
sourceCompatibility = 1.6

group = 'org.beyene'
archivesBaseName = 'sius'
version = '0.2.0-SNAPSHOT'
version = '0.3.0'

sourceSets {
main {
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.deploy
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'signing'

sourceCompatibility = 1.7
sourceCompatibility = 1.6

group = 'org.beyene'
archivesBaseName = 'sius'
version = '0.2.0-SNAPSHOT'
version = '0.3.0'

sourceSets {
main {
Expand Down
9 changes: 5 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.beyene</groupId>
<artifactId>sius</artifactId>
<version>0.2.0-SNAPSHOT</version>
<version>0.3.0</version>
<packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name>
<description>S.I. Unit System Conversion Library</description>
Expand All @@ -12,6 +12,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.6</java.version>
</properties>

<inceptionYear>2014</inceptionYear>
Expand Down Expand Up @@ -45,8 +46,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -168,4 +169,4 @@
<scope>test</scope>
</dependency>
</dependencies>
</project>
</project>
2 changes: 1 addition & 1 deletion src/main/java/org/beyene/sius/cache/Caches.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

public final class Caches {

private static Map<String, Provider> providers = new ConcurrentHashMap<>();
private static Map<String, Provider> providers = new ConcurrentHashMap<String, Provider>();
private static String DEFAULT_PROVIDER_NAME = "<def>";

static {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/beyene/sius/cache/SimpleProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ final class SimpleProvider implements Provider {
@Override
public <D extends Dimension<D>, B extends Unit<D, B, B>, U extends Unit<D, B, U>> Cache<D, B, U> newInstance(
UnitId<D, B, U> id, int capacity) {
return new SimpleCache<>(capacity);
return new SimpleCache<D, B, U>(capacity);
}
}
20 changes: 4 additions & 16 deletions src/main/java/org/beyene/sius/example/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.beyene.sius.example;

import java.util.Arrays;
import java.util.List;

import org.beyene.sius.dimension.Length;
import org.beyene.sius.dimension.Mass;
Expand Down Expand Up @@ -82,7 +83,9 @@ public static void main(String[] args) {
Inch inch = Operation.convert(foot, UnitIdentifier.INCH);
System.out.println(String.format("Converted %s to %s", foot, inch));

System.out.println(String.format("Summands \t= %s", Arrays.<Unit<Length, Meter, ?>>asList(FactoryLength.meter(1000), FactoryLength.mile(1), FactoryLength.meter(1000)).toString()));
@SuppressWarnings("unchecked")
List<Unit<Length, Meter, ?>> lengths = Arrays.<Unit<Length, Meter, ?>>asList(FactoryLength.meter(1000), FactoryLength.mile(1), FactoryLength.meter(1000));
System.out.println(String.format("Summands \t= %s", lengths.toString()));
System.out.println("Sum \t\t= " + Operation.add(FactoryLength.meter(1000), FactoryLength.mile(1), FactoryLength.meter(1000)));

Adder<Length, Meter, Meter> adder = FunctorFactory.sum(UnitIdentifier.METER)
Expand All @@ -101,21 +104,6 @@ public static void main(String[] args) {
System.out.println(adder);
System.out.println(adder.apply());

Meter sameRes = Operation.add(UnitIdentifier.METER,
lengthSecond,
lengthSecond,
lengthSecond,
lengthSecond,
lengthSecond,
lengthSecond,
lengthSecond,
lengthSecond,
lengthSecond,
lengthSecond,
foot,
foot);
System.out.println(sameRes);

ArithmeticMean<Mass, KiloGram, KiloGram> mean = FunctorFactory.mean(UnitIdentifier.KILOGRAM)
.op(FactoryMass.kg(10))
.op(FactoryMass.kg(100))
Expand Down
26 changes: 0 additions & 26 deletions src/main/java/org/beyene/sius/operation/Operation.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import org.beyene.sius.dimension.Dimension;
import org.beyene.sius.dimension.composition.util.Fraction;
import org.beyene.sius.dimension.composition.util.Product;
import org.beyene.sius.operation.functor.Adder;
import org.beyene.sius.operation.functor.FunctorFactory;
import org.beyene.sius.unit.Unit;
import org.beyene.sius.unit.UnitFactory;
import org.beyene.sius.unit.UnitId;
Expand Down Expand Up @@ -98,30 +96,6 @@ public static <D extends Dimension<D>, B extends Unit<D, B, B>, OP1 extends Unit
+ Converter.convert(op2, op1.getIdentifier()).getValue());
}

/**
* Adds (different) units of the same dimension.
*
* @param targetId
* resulting unit
* @param op
* first operand
* @param ops
* further operands
* @return sum
*
* @param <D> dimension
* @param <B> base unit of dimension
* @param <OP> first operands unit
* @param <TARGET_UNIT> target unit
*/
@SafeVarargs
public static <D extends Dimension<D>, B extends Unit<D, B, B>, OP extends Unit<D, B, OP>, TARGET_UNIT extends Unit<D, B, TARGET_UNIT>> TARGET_UNIT add(
UnitId<D, B, TARGET_UNIT> targetId, OP op, Unit<D, B, ?>... ops) {
Adder<D, B, TARGET_UNIT> adder = FunctorFactory.sum(targetId).op(op);
for (Unit<D, B, ?> o : ops)
adder.op(o);
return adder.apply();
}

/**
* Subtracts two (different) units of the same dimension. Result is of same
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class AbstractFunctor<D extends Dimension<D>, B extends Unit<D, B, B>,
private final String functionName;
protected final UnitId<D, B, TARGET_UNIT> targetId;

protected final List<Unit<D, B, ?>> operands = new LinkedList<>();
protected final List<Unit<D, B, ?>> operands = new LinkedList<Unit<D, B, ?>>();
protected TARGET_UNIT cachedResult;

public AbstractFunctor(UnitId<D, B, TARGET_UNIT> targetId, String functionName) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/beyene/sius/unit/UnitFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

public final class UnitFactory {

private static final Map<UnitId<?, ?, ?>, Unit<?, ?, ?>> instanceMapMutable = new HashMap<>();
private static final Map<UnitId<?, ?, ?>, Unit<?, ?, ?>> instanceMapMutable = new HashMap<UnitId<?, ?, ?>, Unit<?, ?, ?>>();

/* initialize map */
static {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/beyene/sius/unit/impl/CelsiusImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class CelsiusImpl extends AbstractUnit<Temperature, Kelvin, Celsius> imple

int sizeStatic = Preferences.getInt("celsius.cache.static.size", 1);
if (sizeStatic > 0)
staticCache = new StaticCache<>(Preferences.getInt("celsius.cache.static.low", 0), sizeStatic, CelsiusImpl.class);
staticCache = new StaticCache<Temperature, Kelvin, Celsius>(Preferences.getInt("celsius.cache.static.low", 0), sizeStatic, CelsiusImpl.class);
else
staticCache = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class FahrenheitImpl extends AbstractUnit<Temperature, Kelvin, Fahrenheit>

int sizeStatic = Preferences.getInt("fahrenheit.cache.static.size", 1);
if (sizeStatic > 0)
staticCache = new StaticCache<>(Preferences.getInt("fahrenheit.cache.static.low", 0), sizeStatic, FahrenheitImpl.class);
staticCache = new StaticCache<Temperature, Kelvin, Fahrenheit>(Preferences.getInt("fahrenheit.cache.static.low", 0), sizeStatic, FahrenheitImpl.class);
else
staticCache = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/beyene/sius/unit/impl/FootImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class FootImpl extends AbstractUnit<Length, Meter, Foot> implements Foot {

int sizeStatic = Preferences.getInt("foot.cache.static.size", 1);
if (sizeStatic > 0)
staticCache = new StaticCache<>(Preferences.getInt("foot.cache.static.low", 0), sizeStatic, FootImpl.class);
staticCache = new StaticCache<Length, Meter, Foot>(Preferences.getInt("foot.cache.static.low", 0), sizeStatic, FootImpl.class);
else
staticCache = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/beyene/sius/unit/impl/HourImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class HourImpl extends AbstractUnit<Time, Second, Hour> implements Hour {

int sizeStatic = Preferences.getInt("hour.cache.static.size", 1);
if (sizeStatic > 0)
staticCache = new StaticCache<>(Preferences.getInt("hour.cache.static.low", 0), sizeStatic, HourImpl.class);
staticCache = new StaticCache<Time, Second, Hour>(Preferences.getInt("hour.cache.static.low", 0), sizeStatic, HourImpl.class);
else
staticCache = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/beyene/sius/unit/impl/InchImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class InchImpl extends AbstractUnit<Length, Meter, Inch> implements Inch {

int sizeStatic = Preferences.getInt("inch.cache.static.size", 1);
if (sizeStatic > 0)
staticCache = new StaticCache<>(Preferences.getInt("inch.cache.static.low", 0), sizeStatic, InchImpl.class);
staticCache = new StaticCache<Length, Meter, Inch>(Preferences.getInt("inch.cache.static.low", 0), sizeStatic, InchImpl.class);
else
staticCache = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/beyene/sius/unit/impl/KelvinImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class KelvinImpl extends AbstractUnit<Temperature, Kelvin, Kelvin> impleme

int sizeStatic = Preferences.getInt("kelvin.cache.static.size", 1);
if (sizeStatic > 0)
staticCache = new StaticCache<>(Preferences.getInt("kelvin.cache.static.low", 0), sizeStatic, KelvinImpl.class);
staticCache = new StaticCache<Temperature, Kelvin, Kelvin>(Preferences.getInt("kelvin.cache.static.low", 0), sizeStatic, KelvinImpl.class);
else
staticCache = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/beyene/sius/unit/impl/KiloGramImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class KiloGramImpl extends AbstractUnit<Mass, KiloGram, KiloGram> implemen

int sizeStatic = Preferences.getInt("kg.cache.static.size", 1);
if (sizeStatic > 0)
staticCache = new StaticCache<>(Preferences.getInt("kg.cache.static.low", 0), sizeStatic, KiloGramImpl.class);
staticCache = new StaticCache<Mass, KiloGram, KiloGram>(Preferences.getInt("kg.cache.static.low", 0), sizeStatic, KiloGramImpl.class);
else
staticCache = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/beyene/sius/unit/impl/MeterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class MeterImpl extends AbstractUnit<Length, Meter, Meter> implements Mete

int sizeStatic = Preferences.getInt("meter.cache.static.size", 1);
if (sizeStatic > 0)
staticCache = new StaticCache<>(Preferences.getInt("meter.cache.static.low", 0), sizeStatic, MeterImpl.class);
staticCache = new StaticCache<Length, Meter, Meter>(Preferences.getInt("meter.cache.static.low", 0), sizeStatic, MeterImpl.class);
else
staticCache = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ final class MeterPerSecondImpl extends AbstractUnit<Speed, MeterPerSecond, Meter

int sizeStatic = Preferences.getInt("mps.cache.static.size", 1);
if (sizeStatic > 0)
staticCache = new StaticCache<>(Preferences.getInt("mps.cache.static.low", 0), sizeStatic, MeterPerSecondImpl.class);
staticCache = new StaticCache<Speed, MeterPerSecond, MeterPerSecond>(Preferences.getInt("mps.cache.static.low", 0), sizeStatic, MeterPerSecondImpl.class);
else
staticCache = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/beyene/sius/unit/impl/MileImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class MileImpl extends AbstractUnit<Length, Meter, Mile> implements Mile {

int sizeStatic = Preferences.getInt("mile.cache.static.size", 1);
if (sizeStatic > 0)
staticCache = new StaticCache<>(Preferences.getInt("mile.cache.static.low", 0), sizeStatic, MileImpl.class);
staticCache = new StaticCache<Length, Meter, Mile>(Preferences.getInt("mile.cache.static.low", 0), sizeStatic, MileImpl.class);
else
staticCache = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final class MilesPerHourImpl extends AbstractUnit<Speed, MeterPerSecond, MilesPe

int sizeStatic = Preferences.getInt("mph.cache.static.size", 1);
if (sizeStatic > 0)
staticCache = new StaticCache<>(Preferences.getInt("mph.cache.static.low", 0), sizeStatic, MilesPerHourImpl.class);
staticCache = new StaticCache<Speed, MeterPerSecond, MilesPerHour>(Preferences.getInt("mph.cache.static.low", 0), sizeStatic, MilesPerHourImpl.class);
else
staticCache = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/beyene/sius/unit/impl/MinuteImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class MinuteImpl extends AbstractUnit<Time, Second, Minute> implements Min

int sizeStatic = Preferences.getInt("minute.cache.static.size", 1);
if (sizeStatic > 0)
staticCache = new StaticCache<>(Preferences.getInt("minute.cache.static.low", 0), sizeStatic, MinuteImpl.class);
staticCache = new StaticCache<Time, Second, Minute>(Preferences.getInt("minute.cache.static.low", 0), sizeStatic, MinuteImpl.class);
else
staticCache = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/beyene/sius/unit/impl/PoundImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class PoundImpl extends AbstractUnit<Mass, KiloGram, Pound> implements Pou

int sizeStatic = Preferences.getInt("pound.cache.static.size", 1);
if (sizeStatic > 0)
staticCache = new StaticCache<>(Preferences.getInt("pound.cache.static.low", 0), sizeStatic, PoundImpl.class);
staticCache = new StaticCache<Mass, KiloGram, Pound>(Preferences.getInt("pound.cache.static.low", 0), sizeStatic, PoundImpl.class);
else
staticCache = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/beyene/sius/unit/impl/SecondImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class SecondImpl extends AbstractUnit<Time, Second, Second> implements Sec

int sizeStatic = Preferences.getInt("second.cache.static.size", 1);
if (sizeStatic > 0)
staticCache = new StaticCache<>(Preferences.getInt("second.cache.static.low", 0), sizeStatic, SecondImpl.class);
staticCache = new StaticCache<Time, Second, Second>(Preferences.getInt("second.cache.static.low", 0), sizeStatic, SecondImpl.class);
else
staticCache = null;
}
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/org/beyene/sius/unit/impl/StaticCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,17 @@ public StaticCache(
for (int k = 0; k < cache.length; k++)
try {
cache[k] = (SELF) implementingClass.getDeclaredConstructor(double.class).newInstance(j++);
} catch (InstantiationException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e) {
// not supposed to happen
} catch (InstantiationException e) {
throw new IllegalStateException(e);
} catch (IllegalAccessException e) {
throw new IllegalStateException(e);
} catch (IllegalArgumentException e) {
throw new IllegalStateException(e);
} catch (InvocationTargetException e) {
throw new IllegalStateException(e);
} catch (NoSuchMethodException e) {
throw new IllegalStateException(e);
} catch (SecurityException e) {
throw new IllegalStateException(e);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/beyene/sius/unit/impl/YardImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class YardImpl extends AbstractUnit<Length, Meter, Yard> implements Yard {

int sizeStatic = Preferences.getInt("yard.cache.static.size", 1);
if (sizeStatic > 0)
staticCache = new StaticCache<>(Preferences.getInt("yard.cache.static.low", 0), sizeStatic, YardImpl.class);
staticCache = new StaticCache<Length, Meter, Yard>(Preferences.getInt("yard.cache.static.low", 0), sizeStatic, YardImpl.class);
else
staticCache = null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/beyene/sius/cache/SimpleCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class SimpleCacheTest {

@Test
public void testLookUp() throws Exception {
SimpleCache<Time, Second, Hour> cache = new SimpleCache<>(5);
SimpleCache<Time, Second, Hour> cache = new SimpleCache<Time, Second, Hour>(5);

double value = 5;
Hour h = FactoryTime.hour(value);
Expand All @@ -41,7 +41,7 @@ public void testLookUp() throws Exception {
@Test
public void testPut() throws Exception {
int size = 10;
SimpleCache<Time, Second, Minute> cache = new SimpleCache<>(size);
SimpleCache<Time, Second, Minute> cache = new SimpleCache<Time, Second, Minute>(size);

int min = 1000;
boolean flag = true;
Expand Down
12 changes: 11 additions & 1 deletion src/test/java/org/beyene/sius/unit/impl/AbstractUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class AbstractUnitTest {
@Before
public void setUp() {
dynamicCache = Caches.newInstance(unitId, 10);
staticCache = new StaticCache<>(0, 10, MeterImpl.class);
staticCache = new StaticCache<Length, Meter, Meter>(0, 10, MeterImpl.class);
m = new MeterImpl(value, dimension, unitId, interfaceClass, dynamicCache, staticCache);
}

Expand Down Expand Up @@ -94,6 +94,16 @@ public void testValueOf() throws Exception {
Meter dynCache1 = m.valueOf(oneThird);
Meter dynCache2 = m.valueOf(oneThird);
Assert.assertTrue(dynCache1 == dynCache2);

m = new MeterImpl(oneThird, dimension, unitId, interfaceClass, null, null);
Meter sameInstance = m.valueOf(oneThird);
Assert.assertTrue(m == sameInstance);

double twoThird = 2d / 3d;
Meter m2 = m.valueOf(twoThird);
Meter notSame = m.valueOf(twoThird);
Assert.assertTrue(m2 != notSame);

}

@Test
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/beyene/sius/unit/impl/StaticCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class StaticCacheTest {
public void testCtor1() throws Exception {
int low = -5;
int size = 10;
StaticCache<Length, Meter, Inch> staticCache = new StaticCache<>(low,
StaticCache<Length, Meter, Inch> staticCache = new StaticCache<Length, Meter, Inch>(low,
size, InchImpl.class);

int start = low;
Expand All @@ -40,7 +40,7 @@ public void testCtor1() throws Exception {
@Test(expected = IllegalStateException.class)
public void testCtor2() throws Exception {
@SuppressWarnings("unused")
StaticCache<Length, Meter, Inch> staticCache = new StaticCache<>(0, 5, Inch.class);
StaticCache<Length, Meter, Inch> staticCache = new StaticCache<Length, Meter, Inch>(0, 5, Inch.class);
Assert.fail("Class parameter has to be class of an interface to throw the expected exception!");
}
}

0 comments on commit 29415cc

Please sign in to comment.