Skip to content

Commit

Permalink
Fluent interface in Equation Builder, fixed some code garbage
Browse files Browse the repository at this point in the history
  • Loading branch information
DaceKonn committed Dec 7, 2014
1 parent d291094 commit 8a2e55c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 27 deletions.
44 changes: 28 additions & 16 deletions Equations/src/Equations/EquationBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ public EquationBuilder(EquationBuilder equation)
this.left.add(e.GetCopy());
}

public void ChangeInput(Complex input)
public EquationBuilder ChangeInput(Complex input)
{
CloseAll();
this.input = input;
left.get(0).SetBaseInput(input);
return this;
}

public String GetLeft()
Expand Down Expand Up @@ -75,15 +76,16 @@ public String GetEquationString()
return left.get(0).GetEquationString();
}

public void CloseAll()
public EquationBuilder CloseAll()
{
while (joins.size() > 0 && left.size() > 1)
{
Close();
}
return this;
}

public void Close()
public EquationBuilder Close()
{
if (joins.size() > 0 && left.size() > 1)
{
Expand Down Expand Up @@ -111,74 +113,84 @@ else if(operation == "devide")
left.remove(topLeft);
joins.remove(topJoin);
}
return this;
}

private void Input(Complex input, boolean base)
private EquationBuilder Input(Complex input, boolean base)
{
if (base)
left.add(new BaseInput(input));
else
left.add(new Input(input));
return this;
}

public void Power(Complex param)
public EquationBuilder Power(Complex param)
{
int top = left.size()-1;

EquationElement tmp = new Power(left.get(top), param);
left.set(top, tmp);
return this;
}

public void Sinus()
public EquationBuilder Sinus()
{
int top = left.size()-1;

EquationElement tmp = new Sinus(left.get(top));
left.set(top, tmp);
return this;
}

public void Cosinus()
public EquationBuilder Cosinus()
{
int top = left.size()-1;

EquationElement tmp = new Cosinus(left.get(top));
left.set(top, tmp);
return this;
}

public void Tangens()
public EquationBuilder Tangens()
{
int top = left.size()-1;

EquationElement tmp = new Tangens(left.get(top));
left.set(top, tmp);
return this;
}

public void Add(Complex param, boolean base)
public EquationBuilder Add(Complex param, boolean base)
{
joins.add("add");
Input(param, base);
return this;
}

public void Multiply(Complex param, boolean base)
public EquationBuilder Multiply(Complex param, boolean base)
{
joins.add("multiply");
Input(param, base);
return this;
}

public void Devide(Complex param, boolean base)
public EquationBuilder Devide(Complex param, boolean base)
{
joins.add("devide");
Input(param, base);
return this;
}

public void PredefinedPolinomialSimple(double a, double b, double m, double n)
public EquationBuilder PredefinedPolinomialSimple(double a, double b, double m, double n)
{
Power(new Complex(m, 0.0));
//Multiply(new Complex(a, 0.0), false);
Multiply(new Complex(a, 0.0), false);
Close();
//Add(input, true);
//Power(new Complex(n, 0.0));
//Multiply(new Complex(b, 0.0), false);
Add(input, true);
Power(new Complex(n, 0.0));
Multiply(new Complex(b, 0.0), false);
CloseAll();
return this;
}
}
1 change: 0 additions & 1 deletion Iterations/src/Iterations/Iterate.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public void setInput(Complex input)

public void setEquationPolynomial(Complex input, double ex, double fx, double xpa, double xpb)
{
equation = new Equations.Polynomial(input, ex, fx, xpa, xpb);
eqBuilder = new EquationBuilder(input);
eqBuilder.PredefinedPolinomialSimple(ex, fx, xpa, xpb);
equation_set = true;
Expand Down
7 changes: 4 additions & 3 deletions ProcessingIOverlay/ProcessingIOverlay.iml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="1.7" jdkType="JavaSDK" />
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="BiomorphGenerate" exported="" />
<orderEntry type="library" exported="" name="core" level="project" />
<orderEntry type="library" exported="" name="controlP5" level="project" />
</component>
</module>

</module>
7 changes: 0 additions & 7 deletions ProcessingIOverlay/src/testa.java

This file was deleted.

0 comments on commit 8a2e55c

Please sign in to comment.