Created
February 3, 2013 18:26
-
-
Save Fabszn/4702987 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package codeStory2013; | |
import java.util.*; | |
/** | |
* . | |
* | |
* @author fsznajderman | |
* date : 03/02/13 | |
*/ | |
public class Scalaskel { | |
private List<Integer> bars = new ArrayList<Integer>(); | |
private List<Integer> qixs = new ArrayList<Integer>(); | |
private List<Integer> bazs = new ArrayList<Integer>(); | |
public Scalaskel() { | |
bars = range(Cent.BAR.getVal()); | |
qixs = range(Cent.QIX.getVal()); | |
bazs = range(Cent.BAZ.getVal()); | |
} | |
public Map<Cent, Integer> compute(final Integer sum) { | |
//bar | |
Integer barVal = isInDomain(sum, bars, Cent.BAR); | |
//qix | |
Integer qixVal = isInDomain(sum, qixs, Cent.QIX); | |
//baz | |
Integer bazVal = isInDomain(sum, bazs, Cent.BAZ); | |
final Map<Cent, Integer> result = new HashMap<Cent, Integer>(); | |
if (barVal != null) { | |
result.put(Cent.BAR, barVal); | |
} | |
if (qixVal != null) { | |
result.put(Cent.QIX, qixVal); | |
} | |
if (bazVal != null) { | |
result.put(Cent.BAZ, bazVal); | |
} | |
result.put(Cent.FOO, sum); | |
return result; | |
} | |
private Integer isInDomain(final Integer sum, final List l, final Cent cents) { | |
int idx = l.indexOf(sum); | |
if (idx != -1) { | |
return idx; | |
} | |
return null; | |
} | |
private List<Integer> range(final Integer step) { | |
final List<Integer> r = new ArrayList<Integer>(); | |
for (int i = 0; i < 100; i = i + step) { | |
r.add(i); | |
} | |
return r; | |
} | |
} | |
enum Cent { | |
FOO( 1), | |
BAR(7), | |
QIX(11), | |
BAZ(21); | |
private int val; | |
Cent(int val) { | |
this.val = val; | |
} | |
public int getVal() { | |
return val; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment