Add ExpressionConvertible
This commit is contained in:
parent
1984349661
commit
c3541de871
|
@ -1,2 +1,7 @@
|
||||||
.idea/
|
.idea/
|
||||||
/build
|
/build
|
||||||
|
.gradle/
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
out/
|
|
@ -1,14 +1,13 @@
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
|
apply plugin: 'idea'
|
||||||
|
apply from: "https://github.com/shadowfacts/maven/raw/master/maven.gradle"
|
||||||
|
|
||||||
sourceCompatibility = 1.7
|
sourceCompatibility = 1.7
|
||||||
targetCompatibility = 1.7
|
targetCompatibility = 1.7
|
||||||
|
group = "no.birkett"
|
||||||
|
archivesBaseName = "kiwi"
|
||||||
version = '1.0'
|
version = '1.0'
|
||||||
|
|
||||||
task wrapper(type: Wrapper) {
|
|
||||||
gradleVersion = '1.9'
|
|
||||||
distributionUrl = 'http://services.gradle.org/distributions/gradle-1.9-all.zip'
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
## This file is automatically generated by Android Studio.
|
|
||||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
|
||||||
#
|
|
||||||
# This file must *NOT* be checked into Version Control Systems,
|
|
||||||
# as it contains information specific to your local configuration.
|
|
||||||
#
|
|
||||||
# Location of the SDK. This is only used by Gradle.
|
|
||||||
# For customization when using a Version Control System, please read the
|
|
||||||
# header note.
|
|
||||||
#Sat Jan 31 12:43:25 CET 2015
|
|
||||||
sdk.dir=/Users/alex/sdk
|
|
|
@ -1,4 +1 @@
|
||||||
rootProject.name = 'kiwi-java'
|
rootProject.name = 'kiwi-java'
|
||||||
|
|
||||||
include 'lib'
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import java.util.List;
|
||||||
/**
|
/**
|
||||||
* Created by alex on 30/01/15.
|
* Created by alex on 30/01/15.
|
||||||
*/
|
*/
|
||||||
public class Expression {
|
public class Expression implements ExpressionConvertible {
|
||||||
|
|
||||||
private List<Term> terms;
|
private List<Term> terms;
|
||||||
|
|
||||||
|
@ -69,6 +69,11 @@ public class Expression {
|
||||||
return terms.size() == 0;
|
return terms.size() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Expression toExpression() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package no.birkett.kiwi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author shadowfacts
|
||||||
|
*/
|
||||||
|
public interface ExpressionConvertible {
|
||||||
|
|
||||||
|
Expression toExpression();
|
||||||
|
|
||||||
|
}
|
|
@ -3,7 +3,7 @@ package no.birkett.kiwi;
|
||||||
/**
|
/**
|
||||||
* Created by alex on 30/01/15.
|
* Created by alex on 30/01/15.
|
||||||
*/
|
*/
|
||||||
public class Term {
|
public class Term implements ExpressionConvertible {
|
||||||
|
|
||||||
private Variable variable;
|
private Variable variable;
|
||||||
double coefficient;
|
double coefficient;
|
||||||
|
@ -37,6 +37,11 @@ public class Term {
|
||||||
return coefficient * variable.getValue();
|
return coefficient * variable.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Expression toExpression() {
|
||||||
|
return new Expression(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "variable: (" + variable + ") coefficient: " + coefficient;
|
return "variable: (" + variable + ") coefficient: " + coefficient;
|
||||||
|
|
|
@ -3,7 +3,7 @@ package no.birkett.kiwi;
|
||||||
/**
|
/**
|
||||||
* Created by alex on 30/01/15.
|
* Created by alex on 30/01/15.
|
||||||
*/
|
*/
|
||||||
public class Variable {
|
public class Variable implements ExpressionConvertible {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@ -28,6 +28,11 @@ public class Variable {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Expression toExpression() {
|
||||||
|
return new Expression(new Term(this));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "name: " + name + " value: " + value;
|
return "name: " + name + " value: " + value;
|
||||||
|
|
Loading…
Reference in New Issue