├── .gitignore
├── .idea
├── Workshop - RefactoringLegacyCode.iml
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── misc.xml
├── modules.xml
├── vcs.xml
└── workspace.xml
├── README.md
├── java
├── .idea
│ ├── compiler.xml
│ ├── encodings.xml
│ ├── java.iml
│ ├── libraries
│ │ ├── hamcrest_core_1_3.xml
│ │ ├── joda_time_2_1.xml
│ │ ├── joda_time_2_1_javadoc.xml
│ │ ├── joda_time_2_1_sources.xml
│ │ └── junit_4_12.xml
│ ├── misc.xml
│ ├── modules.xml
│ └── runConfigurations
│ │ ├── All_in_00FromPushToPull.xml
│ │ ├── All_in_01FromPushToPull.xml
│ │ ├── All_in_02FromPushToPull.xml
│ │ ├── All_in_03FromPushToPull.xml
│ │ ├── All_in_04FromPushToPull.xml
│ │ ├── All_in_05FromPushToPull.xml
│ │ ├── All_in_06FromPushToPull.xml
│ │ ├── All_in_07FromPushToPull.xml
│ │ ├── All_in_08FromPushToPull.xml
│ │ ├── All_in_09FromPushToPull.xml
│ │ ├── All_in_10FromPushToPull.xml
│ │ ├── All_in_11FromPushToPull.xml
│ │ ├── All_in_12FromPushToPull.xml
│ │ ├── All_in_13FromPushToPull.xml
│ │ ├── All_in_14FromPushToPull.xml
│ │ ├── All_in_15FromPushToPull.xml
│ │ └── All_in_16FromPushToPull.xml
├── 00FromPushToPull
│ ├── .classpath
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.core.runtime.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ └── org.eclipse.jdt.ui.prefs
│ ├── 00FromPushToPull.iml
│ ├── src
│ │ └── pushpull
│ │ │ └── BalancesCalculator.java
│ └── test
│ │ └── pushpull
│ │ └── PushPullTest.java
├── 01FromPushToPull
│ ├── .classpath
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.core.runtime.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ └── org.eclipse.jdt.ui.prefs
│ ├── 01FromPushToPull.iml
│ ├── src
│ │ └── pushpull
│ │ │ ├── BalancesCalculator.java
│ │ │ └── ValuesOfMonth.java
│ └── test
│ │ └── pushpull
│ │ └── PushPullTest.java
├── 02FromPushToPull
│ ├── .classpath
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.core.runtime.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ └── org.eclipse.jdt.ui.prefs
│ ├── 02FromPushToPull.iml
│ ├── src
│ │ └── pushpull
│ │ │ ├── BalancesCalculator.java
│ │ │ └── ValuesOfMonth.java
│ └── test
│ │ └── pushpull
│ │ └── PushPullTest.java
├── 03FromPushToPull
│ ├── .classpath
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.core.runtime.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ └── org.eclipse.jdt.ui.prefs
│ ├── 03FromPushToPull.iml
│ ├── src
│ │ └── pushpull
│ │ │ ├── BalancesCalculator.java
│ │ │ └── ValuesOfMonth.java
│ └── test
│ │ └── pushpull
│ │ └── PushPullTest.java
├── 04FromPushToPull
│ ├── .classpath
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.core.runtime.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ └── org.eclipse.jdt.ui.prefs
│ ├── 04FromPushToPull.iml
│ ├── src
│ │ └── pushpull
│ │ │ ├── BalancesCalculator.java
│ │ │ └── ValuesOfMonth.java
│ └── test
│ │ └── pushpull
│ │ └── PushPullTest.java
├── 05FromPushToPull
│ ├── .classpath
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.core.runtime.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ └── org.eclipse.jdt.ui.prefs
│ ├── 05FromPushToPull.iml
│ ├── src
│ │ └── pushpull
│ │ │ ├── BalancesCalculator.java
│ │ │ └── ValuesOfMonth.java
│ └── test
│ │ └── pushpull
│ │ └── PushPullTest.java
├── 06FromPushToPull
│ ├── .classpath
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.core.runtime.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ └── org.eclipse.jdt.ui.prefs
│ ├── 06FromPushToPull.iml
│ ├── src
│ │ └── pushpull
│ │ │ ├── BalancesCalculator.java
│ │ │ └── ValuesOfMonth.java
│ └── test
│ │ └── pushpull
│ │ └── PushPullTest.java
├── 07FromPushToPull
│ ├── .classpath
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.core.runtime.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ └── org.eclipse.jdt.ui.prefs
│ ├── 07FromPushToPull.iml
│ ├── src
│ │ └── pushpull
│ │ │ ├── BalancesCalculator.java
│ │ │ └── ValuesOfMonth.java
│ └── test
│ │ └── pushpull
│ │ └── PushPullTest.java
├── 08FromPushToPull
│ ├── .classpath
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.core.runtime.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ └── org.eclipse.jdt.ui.prefs
│ ├── 08FromPushToPull.iml
│ ├── src
│ │ └── pushpull
│ │ │ ├── BalancesCalculator.java
│ │ │ └── ValuesOfMonth.java
│ └── test
│ │ └── pushpull
│ │ └── PushPullTest.java
├── 09FromPushToPull
│ ├── .classpath
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.core.runtime.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ └── org.eclipse.jdt.ui.prefs
│ ├── 09FromPushToPull.iml
│ ├── src
│ │ └── pushpull
│ │ │ ├── BalancesCalculator.java
│ │ │ └── ValuesOfMonth.java
│ └── test
│ │ └── pushpull
│ │ └── PushPullTest.java
├── 10FromPushToPull
│ ├── .classpath
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.core.runtime.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ └── org.eclipse.jdt.ui.prefs
│ ├── 10FromPushToPull.iml
│ ├── src
│ │ └── pushpull
│ │ │ ├── BalancesCalculator.java
│ │ │ └── ValuesOfMonth.java
│ └── test
│ │ └── pushpull
│ │ └── PushPullTest.java
├── 11FromPushToPull
│ ├── .classpath
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.core.runtime.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ └── org.eclipse.jdt.ui.prefs
│ ├── 11FromPushToPull.iml
│ ├── src
│ │ └── pushpull
│ │ │ ├── BalancesCalculator.java
│ │ │ ├── IValuesOfMonth.java
│ │ │ ├── InitialValuesOfMonth.java
│ │ │ └── ValuesOfMonth.java
│ └── test
│ │ └── pushpull
│ │ └── PushPullTest.java
├── 12FromPushToPull
│ ├── .classpath
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.core.runtime.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ └── org.eclipse.jdt.ui.prefs
│ ├── 12FromPushToPull.iml
│ ├── src
│ │ └── pushpull
│ │ │ ├── BalancesCalculator.java
│ │ │ ├── IValuesOfMonth.java
│ │ │ ├── InitialValuesOfMonth.java
│ │ │ ├── Transactions.java
│ │ │ └── ValuesOfMonth.java
│ └── test
│ │ └── pushpull
│ │ └── PushPullTest.java
├── 13FromPushToPull
│ ├── .classpath
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.core.runtime.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ └── org.eclipse.jdt.ui.prefs
│ ├── 13FromPushToPull.iml
│ ├── src
│ │ └── pushpull
│ │ │ ├── BalancesCalculator.java
│ │ │ ├── IValuesOfMonth.java
│ │ │ ├── InitialValuesOfMonth.java
│ │ │ ├── Transactions.java
│ │ │ └── ValuesOfMonth.java
│ └── test
│ │ └── pushpull
│ │ └── PushPullTest.java
├── 14FromPushToPull
│ ├── .classpath
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.core.runtime.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ └── org.eclipse.jdt.ui.prefs
│ ├── 14FromPushToPull.iml
│ ├── src
│ │ └── pushpull
│ │ │ ├── BalancesCalculator.java
│ │ │ ├── IValuesOfMonth.java
│ │ │ ├── InitialValuesOfMonth.java
│ │ │ ├── Months.java
│ │ │ ├── Transactions.java
│ │ │ └── ValuesOfMonth.java
│ └── test
│ │ └── pushpull
│ │ └── PushPullTest.java
├── 15FromPushToPull
│ ├── .classpath
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.core.runtime.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ └── org.eclipse.jdt.ui.prefs
│ ├── 15FromPushToPull.iml
│ ├── src
│ │ └── pushpull
│ │ │ ├── BalancesCalculator.java
│ │ │ ├── IValuesOfMonth.java
│ │ │ ├── InitialValuesOfMonth.java
│ │ │ ├── Months.java
│ │ │ ├── Transactions.java
│ │ │ ├── ValuesOfMonth.java
│ │ │ └── ValuesOfMonthWithCaching.java
│ └── test
│ │ └── pushpull
│ │ └── PushPullTest.java
├── 16FromPushToPull
│ ├── .classpath
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.core.runtime.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ └── org.eclipse.jdt.ui.prefs
│ ├── 16FromPushToPull.iml
│ ├── src
│ │ └── pushpull
│ │ │ ├── BalancesCalculator.java
│ │ │ ├── IValuesOfMonth.java
│ │ │ ├── InitialValuesOfMonth.java
│ │ │ ├── Months.java
│ │ │ ├── Transactions.java
│ │ │ ├── ValuesOfMonth.java
│ │ │ └── ValuesOfMonthWithCaching.java
│ └── test
│ │ └── pushpull
│ │ └── PushPullTest.java
├── Common
│ ├── .classpath
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.core.runtime.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ └── org.eclipse.jdt.ui.prefs
│ ├── Common.iml
│ ├── lib
│ │ ├── hamcrest-core-1.3.jar
│ │ ├── joda-time-2.1-javadoc.jar
│ │ ├── joda-time-2.1-sources.jar
│ │ ├── joda-time-2.1.jar
│ │ └── junit-4.12.jar
│ ├── src
│ │ └── common
│ │ │ ├── BalancesOfMonthCalculator_API.java
│ │ │ ├── BalancesOfMonth_API.java
│ │ │ └── Transaction_API.java
│ └── test
│ │ └── common
│ │ └── CalculatorTest.java
└── README.md
├── slides
├── .gitignore
├── CodeMechanics.graffle
├── CodeMechanics.pdf
├── Codestruktur.graffle
├── Codestruktur.png
├── DynamischFein.graffle
├── DynamischFein.jpg
├── LocalOptimum.jpg
├── beamercolorthemenicole.sty
├── beamerinnerthemenicole.sty
├── beamerouterthemenicole.sty
├── beramono.sty
├── contents.tex
├── folien.pdf
├── folien.tex
└── ngerman.sty
├── workshopMaterial
├── CompareViews
│ ├── 01-02.jpg
│ ├── 02-03.png
│ ├── 03-04.png
│ ├── 04-05-1.png
│ ├── 04-05-2.png
│ ├── 05-06-1.png
│ ├── 05-06-2.png
│ ├── 06-07-1.png
│ ├── 06-07-2.png
│ ├── 07-08-1.jpg
│ ├── 07-08-2.jpg
│ ├── 08-09.jpg
│ ├── 09-10-1.png
│ ├── 09-10-2.png
│ ├── 10-11-1.png
│ ├── 10-11-2.png
│ ├── 11-12-2.png
│ ├── 11-3.png
│ ├── 11-4.png
│ ├── 12-1.png
│ ├── 12-13.png
│ ├── 13-14-2.png
│ ├── 14-1.png
│ ├── 14-15-2.png
│ ├── 15-1.png
│ ├── 15-16.png
│ └── Push-01.png
├── MikadoTree.graffle
├── MikadoTree.pdf
├── balance.graffle
├── balance.jpg
├── finalAverage.graffle
├── finalAverage.jpg
├── initialAverage.graffle
├── initialAverage.jpg
├── workshopGuide.pdf
└── workshopGuide.tex
└── workshopProposal
├── Einreichung AgileDevPractices 30.9.13.rtf
├── Einreichung XP-Days 2013.rtf
├── Softwerkskammer 11.9.13.txt
├── xp2013_workshop.tex
└── xp2013_workshop_rauch_leidig.pdf
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | *.gz
3 | *.log
4 | *.aux
5 | .gitignore~
6 | EclipseProjects/.metadata/*
7 | .metadata
8 | RemoteSystemsTempFiles
9 | .recommenders
10 | workspace.xml
11 |
--------------------------------------------------------------------------------
/.idea/Workshop - RefactoringLegacyCode.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | 1.8
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | RefactoringLegacyCode
2 | =====================
3 |
4 | Talk about refactoring legacy code. Slides and code examples.
--------------------------------------------------------------------------------
/java/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/java/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/java/.idea/java.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/java/.idea/libraries/hamcrest_core_1_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/java/.idea/libraries/joda_time_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/java/.idea/libraries/joda_time_2_1_javadoc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/java/.idea/libraries/joda_time_2_1_sources.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/java/.idea/libraries/junit_4_12.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/java/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/java/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/java/.idea/runConfigurations/All_in_00FromPushToPull.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/.idea/runConfigurations/All_in_01FromPushToPull.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/.idea/runConfigurations/All_in_02FromPushToPull.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/.idea/runConfigurations/All_in_03FromPushToPull.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/.idea/runConfigurations/All_in_04FromPushToPull.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/.idea/runConfigurations/All_in_05FromPushToPull.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/.idea/runConfigurations/All_in_06FromPushToPull.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/.idea/runConfigurations/All_in_07FromPushToPull.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/.idea/runConfigurations/All_in_08FromPushToPull.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/.idea/runConfigurations/All_in_09FromPushToPull.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/.idea/runConfigurations/All_in_10FromPushToPull.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/.idea/runConfigurations/All_in_11FromPushToPull.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/.idea/runConfigurations/All_in_12FromPushToPull.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/.idea/runConfigurations/All_in_13FromPushToPull.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/.idea/runConfigurations/All_in_14FromPushToPull.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/.idea/runConfigurations/All_in_15FromPushToPull.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/.idea/runConfigurations/All_in_16FromPushToPull.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/00FromPushToPull/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/java/00FromPushToPull/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | bin
--------------------------------------------------------------------------------
/java/00FromPushToPull/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | 00FromPushToPull
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/java/00FromPushToPull/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=ISO-8859-1
3 |
--------------------------------------------------------------------------------
/java/00FromPushToPull/.settings/org.eclipse.core.runtime.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | line.separator=\r\n
3 |
--------------------------------------------------------------------------------
/java/00FromPushToPull/.settings/org.eclipse.jdt.ui.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
3 | formatter_profile=_Legacy
4 | formatter_settings_version=12
5 | sp_cleanup.add_default_serial_version_id=true
6 | sp_cleanup.add_generated_serial_version_id=false
7 | sp_cleanup.add_missing_annotations=true
8 | sp_cleanup.add_missing_deprecated_annotations=true
9 | sp_cleanup.add_missing_methods=false
10 | sp_cleanup.add_missing_nls_tags=false
11 | sp_cleanup.add_missing_override_annotations=true
12 | sp_cleanup.add_missing_override_annotations_interface_methods=true
13 | sp_cleanup.add_serial_version_id=false
14 | sp_cleanup.always_use_blocks=true
15 | sp_cleanup.always_use_parentheses_in_expressions=false
16 | sp_cleanup.always_use_this_for_non_static_field_access=false
17 | sp_cleanup.always_use_this_for_non_static_method_access=false
18 | sp_cleanup.convert_to_enhanced_for_loop=false
19 | sp_cleanup.correct_indentation=false
20 | sp_cleanup.format_source_code=true
21 | sp_cleanup.format_source_code_changes_only=false
22 | sp_cleanup.make_local_variable_final=false
23 | sp_cleanup.make_parameters_final=false
24 | sp_cleanup.make_private_fields_final=true
25 | sp_cleanup.make_type_abstract_if_missing_method=false
26 | sp_cleanup.make_variable_declarations_final=true
27 | sp_cleanup.never_use_blocks=false
28 | sp_cleanup.never_use_parentheses_in_expressions=true
29 | sp_cleanup.on_save_use_additional_actions=true
30 | sp_cleanup.organize_imports=true
31 | sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
32 | sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
33 | sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
34 | sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
35 | sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
36 | sp_cleanup.remove_private_constructors=true
37 | sp_cleanup.remove_trailing_whitespaces=false
38 | sp_cleanup.remove_trailing_whitespaces_all=true
39 | sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
40 | sp_cleanup.remove_unnecessary_casts=true
41 | sp_cleanup.remove_unnecessary_nls_tags=false
42 | sp_cleanup.remove_unused_imports=false
43 | sp_cleanup.remove_unused_local_variables=false
44 | sp_cleanup.remove_unused_private_fields=true
45 | sp_cleanup.remove_unused_private_members=false
46 | sp_cleanup.remove_unused_private_methods=true
47 | sp_cleanup.remove_unused_private_types=true
48 | sp_cleanup.sort_members=false
49 | sp_cleanup.sort_members_all=false
50 | sp_cleanup.use_blocks=false
51 | sp_cleanup.use_blocks_only_for_return_and_throw=false
52 | sp_cleanup.use_parentheses_in_expressions=false
53 | sp_cleanup.use_this_for_non_static_field_access=false
54 | sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
55 | sp_cleanup.use_this_for_non_static_method_access=false
56 | sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
57 |
--------------------------------------------------------------------------------
/java/00FromPushToPull/00FromPushToPull.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/00FromPushToPull/src/pushpull/BalancesCalculator.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.joda.time.LocalDate;
7 |
8 | import common.BalancesOfMonthCalculator_API;
9 | import common.BalancesOfMonth_API;
10 | import common.Transaction_API;
11 |
12 | public class BalancesCalculator implements BalancesOfMonthCalculator_API {
13 |
14 | private final List transactions;
15 |
16 | public BalancesCalculator(List transactions) {
17 | this.transactions = transactions;
18 | }
19 |
20 | @Override
21 | public void fillData(List balancesOfMonthList) {
22 | int balance = 0;
23 |
24 | for (BalancesOfMonth_API balancesOfMonth : balancesOfMonthList) {
25 | int ultimo = balancesOfMonth.getDate().getDayOfMonth();
26 |
27 | double averageBalance = 0;
28 | int dayOfLatestBalance = 1;
29 | List transactionsOfMonth = transactionsOfMonth(balancesOfMonth.getDate());
30 | for (Transaction_API transaction : transactionsOfMonth) {
31 | int day = transaction.getDate().getDayOfMonth();
32 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, day, ultimo);
33 | balance += transaction.getAmount();
34 | dayOfLatestBalance = day;
35 | }
36 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, ultimo + 1, ultimo);
37 |
38 | balancesOfMonth.setBalance(balance);
39 | balancesOfMonth.setAverageBalance((int) averageBalance);
40 | }
41 | }
42 |
43 | private double calculateProportionalBalance(int dayOfLatestBalance, int balance, int day, int daysInMonth) {
44 | int countingDays = day - dayOfLatestBalance;
45 | if (countingDays == 0) {
46 | return 0;
47 | }
48 | double rate = (double) countingDays / daysInMonth;
49 | return (balance * rate);
50 | }
51 |
52 | private List transactionsOfMonth(LocalDate date) {
53 | List results = new ArrayList();
54 | for (Transaction_API transaction : transactions) {
55 | LocalDate dateOfTransaction = transaction.getDate();
56 | if (areSameMonthAndYear(date, dateOfTransaction)) {
57 | results.add(transaction);
58 | }
59 | }
60 | return results;
61 | }
62 |
63 | private boolean areSameMonthAndYear(LocalDate date, LocalDate dateOfTransaction) {
64 | return dateOfTransaction.getMonthOfYear() == date.getMonthOfYear() && dateOfTransaction.getYear() == date.getYear();
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/java/00FromPushToPull/test/pushpull/PushPullTest.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import org.junit.Before;
4 |
5 | import common.CalculatorTest;
6 | import pushpull.BalancesCalculator;
7 |
8 | public class PushPullTest extends CalculatorTest {
9 |
10 | @Before
11 | public void setup() {
12 | calculator = new BalancesCalculator(transactions);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/java/01FromPushToPull/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/java/01FromPushToPull/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | bin
--------------------------------------------------------------------------------
/java/01FromPushToPull/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | 01FromPushToPull
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/java/01FromPushToPull/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=ISO-8859-1
3 |
--------------------------------------------------------------------------------
/java/01FromPushToPull/.settings/org.eclipse.core.runtime.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | line.separator=\r\n
3 |
--------------------------------------------------------------------------------
/java/01FromPushToPull/.settings/org.eclipse.jdt.ui.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
3 | formatter_profile=_Legacy
4 | formatter_settings_version=12
5 | sp_cleanup.add_default_serial_version_id=true
6 | sp_cleanup.add_generated_serial_version_id=false
7 | sp_cleanup.add_missing_annotations=true
8 | sp_cleanup.add_missing_deprecated_annotations=true
9 | sp_cleanup.add_missing_methods=false
10 | sp_cleanup.add_missing_nls_tags=false
11 | sp_cleanup.add_missing_override_annotations=true
12 | sp_cleanup.add_missing_override_annotations_interface_methods=true
13 | sp_cleanup.add_serial_version_id=false
14 | sp_cleanup.always_use_blocks=true
15 | sp_cleanup.always_use_parentheses_in_expressions=false
16 | sp_cleanup.always_use_this_for_non_static_field_access=false
17 | sp_cleanup.always_use_this_for_non_static_method_access=false
18 | sp_cleanup.convert_to_enhanced_for_loop=false
19 | sp_cleanup.correct_indentation=false
20 | sp_cleanup.format_source_code=true
21 | sp_cleanup.format_source_code_changes_only=false
22 | sp_cleanup.make_local_variable_final=false
23 | sp_cleanup.make_parameters_final=false
24 | sp_cleanup.make_private_fields_final=true
25 | sp_cleanup.make_type_abstract_if_missing_method=false
26 | sp_cleanup.make_variable_declarations_final=true
27 | sp_cleanup.never_use_blocks=false
28 | sp_cleanup.never_use_parentheses_in_expressions=true
29 | sp_cleanup.on_save_use_additional_actions=true
30 | sp_cleanup.organize_imports=true
31 | sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
32 | sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
33 | sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
34 | sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
35 | sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
36 | sp_cleanup.remove_private_constructors=true
37 | sp_cleanup.remove_trailing_whitespaces=false
38 | sp_cleanup.remove_trailing_whitespaces_all=true
39 | sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
40 | sp_cleanup.remove_unnecessary_casts=true
41 | sp_cleanup.remove_unnecessary_nls_tags=false
42 | sp_cleanup.remove_unused_imports=false
43 | sp_cleanup.remove_unused_local_variables=false
44 | sp_cleanup.remove_unused_private_fields=true
45 | sp_cleanup.remove_unused_private_members=false
46 | sp_cleanup.remove_unused_private_methods=true
47 | sp_cleanup.remove_unused_private_types=true
48 | sp_cleanup.sort_members=false
49 | sp_cleanup.sort_members_all=false
50 | sp_cleanup.use_blocks=false
51 | sp_cleanup.use_blocks_only_for_return_and_throw=false
52 | sp_cleanup.use_parentheses_in_expressions=false
53 | sp_cleanup.use_this_for_non_static_field_access=false
54 | sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
55 | sp_cleanup.use_this_for_non_static_method_access=false
56 | sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
57 |
--------------------------------------------------------------------------------
/java/01FromPushToPull/01FromPushToPull.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/01FromPushToPull/src/pushpull/BalancesCalculator.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.joda.time.LocalDate;
7 |
8 | import common.BalancesOfMonthCalculator_API;
9 | import common.BalancesOfMonth_API;
10 | import common.Transaction_API;
11 |
12 | public class BalancesCalculator implements BalancesOfMonthCalculator_API {
13 |
14 | private final List transactions;
15 |
16 | public BalancesCalculator(List transactions) {
17 | this.transactions = transactions;
18 | }
19 |
20 | @Override
21 | public void fillData(List balancesOfMonthList) {
22 | ValuesOfMonth valuesOfMonth = new ValuesOfMonth();
23 | int balance = 0;
24 |
25 | for (BalancesOfMonth_API balancesOfMonth : balancesOfMonthList) {
26 | int ultimo = balancesOfMonth.getDate().getDayOfMonth();
27 |
28 | double averageBalance = 0;
29 | int dayOfLatestBalance = 1;
30 | List transactionsOfMonth = transactionsOfMonth(balancesOfMonth.getDate());
31 | for (Transaction_API transaction : transactionsOfMonth) {
32 | int day = transaction.getDate().getDayOfMonth();
33 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, day, ultimo);
34 | balance += transaction.getAmount();
35 | dayOfLatestBalance = day;
36 | }
37 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, ultimo + 1, ultimo);
38 |
39 | valuesOfMonth.setBalanceAndAverage(balance, averageBalance);
40 |
41 | balancesOfMonth.setBalance(valuesOfMonth.getBalance());
42 | balancesOfMonth.setAverageBalance(valuesOfMonth.getAverageBalance());
43 | }
44 | }
45 |
46 | private double calculateProportionalBalance(int dayOfLatestBalance, int balance, int day, int daysInMonth) {
47 | int countingDays = day - dayOfLatestBalance;
48 | if (countingDays == 0) {
49 | return 0;
50 | }
51 | double rate = (double) countingDays / daysInMonth;
52 | return (balance * rate);
53 | }
54 |
55 | private List transactionsOfMonth(LocalDate date) {
56 | List results = new ArrayList();
57 | for (Transaction_API transaction : transactions) {
58 | LocalDate dateOfTransaction = transaction.getDate();
59 | if (areSameMonthAndYear(date, dateOfTransaction)) {
60 | results.add(transaction);
61 | }
62 | }
63 | return results;
64 | }
65 |
66 | private boolean areSameMonthAndYear(LocalDate date, LocalDate dateOfTransaction) {
67 | return dateOfTransaction.getMonthOfYear() == date.getMonthOfYear() && dateOfTransaction.getYear() == date.getYear();
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/java/01FromPushToPull/src/pushpull/ValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | public class ValuesOfMonth {
4 | private int balance;
5 | private double averageBalance;
6 |
7 | public int getBalance() {
8 | return balance;
9 | }
10 |
11 | public int getAverageBalance() {
12 | return (int) averageBalance;
13 | }
14 |
15 | public void setBalanceAndAverage(int balance, double averageBalance) {
16 | this.balance = balance;
17 | this.averageBalance = averageBalance;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/java/01FromPushToPull/test/pushpull/PushPullTest.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import org.junit.Before;
4 |
5 | import common.CalculatorTest;
6 | import pushpull.BalancesCalculator;
7 |
8 | public class PushPullTest extends CalculatorTest {
9 |
10 | @Before
11 | public void setup() {
12 | calculator = new BalancesCalculator(transactions);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/java/02FromPushToPull/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/java/02FromPushToPull/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | bin
--------------------------------------------------------------------------------
/java/02FromPushToPull/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | 02FromPushToPull
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/java/02FromPushToPull/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=ISO-8859-1
3 |
--------------------------------------------------------------------------------
/java/02FromPushToPull/.settings/org.eclipse.core.runtime.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | line.separator=\r\n
3 |
--------------------------------------------------------------------------------
/java/02FromPushToPull/.settings/org.eclipse.jdt.ui.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
3 | formatter_profile=_Legacy
4 | formatter_settings_version=12
5 | sp_cleanup.add_default_serial_version_id=true
6 | sp_cleanup.add_generated_serial_version_id=false
7 | sp_cleanup.add_missing_annotations=true
8 | sp_cleanup.add_missing_deprecated_annotations=true
9 | sp_cleanup.add_missing_methods=false
10 | sp_cleanup.add_missing_nls_tags=false
11 | sp_cleanup.add_missing_override_annotations=true
12 | sp_cleanup.add_missing_override_annotations_interface_methods=true
13 | sp_cleanup.add_serial_version_id=false
14 | sp_cleanup.always_use_blocks=true
15 | sp_cleanup.always_use_parentheses_in_expressions=false
16 | sp_cleanup.always_use_this_for_non_static_field_access=false
17 | sp_cleanup.always_use_this_for_non_static_method_access=false
18 | sp_cleanup.convert_to_enhanced_for_loop=false
19 | sp_cleanup.correct_indentation=false
20 | sp_cleanup.format_source_code=true
21 | sp_cleanup.format_source_code_changes_only=false
22 | sp_cleanup.make_local_variable_final=false
23 | sp_cleanup.make_parameters_final=false
24 | sp_cleanup.make_private_fields_final=true
25 | sp_cleanup.make_type_abstract_if_missing_method=false
26 | sp_cleanup.make_variable_declarations_final=true
27 | sp_cleanup.never_use_blocks=false
28 | sp_cleanup.never_use_parentheses_in_expressions=true
29 | sp_cleanup.on_save_use_additional_actions=true
30 | sp_cleanup.organize_imports=true
31 | sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
32 | sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
33 | sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
34 | sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
35 | sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
36 | sp_cleanup.remove_private_constructors=true
37 | sp_cleanup.remove_trailing_whitespaces=false
38 | sp_cleanup.remove_trailing_whitespaces_all=true
39 | sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
40 | sp_cleanup.remove_unnecessary_casts=true
41 | sp_cleanup.remove_unnecessary_nls_tags=false
42 | sp_cleanup.remove_unused_imports=false
43 | sp_cleanup.remove_unused_local_variables=false
44 | sp_cleanup.remove_unused_private_fields=true
45 | sp_cleanup.remove_unused_private_members=false
46 | sp_cleanup.remove_unused_private_methods=true
47 | sp_cleanup.remove_unused_private_types=true
48 | sp_cleanup.sort_members=false
49 | sp_cleanup.sort_members_all=false
50 | sp_cleanup.use_blocks=false
51 | sp_cleanup.use_blocks_only_for_return_and_throw=false
52 | sp_cleanup.use_parentheses_in_expressions=false
53 | sp_cleanup.use_this_for_non_static_field_access=false
54 | sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
55 | sp_cleanup.use_this_for_non_static_method_access=false
56 | sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
57 |
--------------------------------------------------------------------------------
/java/02FromPushToPull/02FromPushToPull.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/02FromPushToPull/src/pushpull/BalancesCalculator.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.joda.time.LocalDate;
7 |
8 | import common.BalancesOfMonthCalculator_API;
9 | import common.BalancesOfMonth_API;
10 | import common.Transaction_API;
11 |
12 | public class BalancesCalculator implements BalancesOfMonthCalculator_API {
13 |
14 | private final List transactions;
15 |
16 | public BalancesCalculator(List transactions) {
17 | this.transactions = transactions;
18 | }
19 |
20 | @Override
21 | public void fillData(List balancesOfMonthList) {
22 | ValuesOfMonth valuesOfMonth = new ValuesOfMonth();
23 | int balance = 0;
24 |
25 | for (BalancesOfMonth_API balancesOfMonth : balancesOfMonthList) {
26 | LocalDate dateOfMonth = balancesOfMonth.getDate();
27 | List transactionsOfMonth = transactionsOfMonth(dateOfMonth);
28 |
29 | int ultimo = dateOfMonth.getDayOfMonth();
30 |
31 | double averageBalance = 0;
32 | int dayOfLatestBalance = 1;
33 | for (Transaction_API transaction : transactionsOfMonth) {
34 | int day = transaction.getDate().getDayOfMonth();
35 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, day, ultimo);
36 | balance += transaction.getAmount();
37 | dayOfLatestBalance = day;
38 | }
39 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, ultimo + 1, ultimo);
40 |
41 | valuesOfMonth.setBalanceAndAverage(balance, averageBalance);
42 |
43 | balancesOfMonth.setBalance(valuesOfMonth.getBalance());
44 | balancesOfMonth.setAverageBalance(valuesOfMonth.getAverageBalance());
45 | }
46 | }
47 |
48 | private double calculateProportionalBalance(int dayOfLatestBalance, int balance, int day, int daysInMonth) {
49 | int countingDays = day - dayOfLatestBalance;
50 | if (countingDays == 0) {
51 | return 0;
52 | }
53 | double rate = (double) countingDays / daysInMonth;
54 | return (balance * rate);
55 | }
56 |
57 | private List transactionsOfMonth(LocalDate date) {
58 | List results = new ArrayList();
59 | for (Transaction_API transaction : transactions) {
60 | LocalDate dateOfTransaction = transaction.getDate();
61 | if (areSameMonthAndYear(date, dateOfTransaction)) {
62 | results.add(transaction);
63 | }
64 | }
65 | return results;
66 | }
67 |
68 | private boolean areSameMonthAndYear(LocalDate date, LocalDate dateOfTransaction) {
69 | return dateOfTransaction.getMonthOfYear() == date.getMonthOfYear() && dateOfTransaction.getYear() == date.getYear();
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/java/02FromPushToPull/src/pushpull/ValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | public class ValuesOfMonth {
4 | private int balance;
5 | private double averageBalance;
6 |
7 | public int getBalance() {
8 | return balance;
9 | }
10 |
11 | public int getAverageBalance() {
12 | return (int) averageBalance;
13 | }
14 |
15 | public void setBalanceAndAverage(int balance, double averageBalance) {
16 | this.balance = balance;
17 | this.averageBalance = averageBalance;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/java/02FromPushToPull/test/pushpull/PushPullTest.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import org.junit.Before;
4 |
5 | import common.CalculatorTest;
6 | import pushpull.BalancesCalculator;
7 |
8 | public class PushPullTest extends CalculatorTest {
9 |
10 | @Before
11 | public void setup() {
12 | calculator = new BalancesCalculator(transactions);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/java/03FromPushToPull/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/java/03FromPushToPull/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | bin
--------------------------------------------------------------------------------
/java/03FromPushToPull/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | 03FromPushToPull
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/java/03FromPushToPull/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=ISO-8859-1
3 |
--------------------------------------------------------------------------------
/java/03FromPushToPull/.settings/org.eclipse.core.runtime.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | line.separator=\r\n
3 |
--------------------------------------------------------------------------------
/java/03FromPushToPull/.settings/org.eclipse.jdt.ui.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
3 | formatter_profile=_Legacy
4 | formatter_settings_version=12
5 | sp_cleanup.add_default_serial_version_id=true
6 | sp_cleanup.add_generated_serial_version_id=false
7 | sp_cleanup.add_missing_annotations=true
8 | sp_cleanup.add_missing_deprecated_annotations=true
9 | sp_cleanup.add_missing_methods=false
10 | sp_cleanup.add_missing_nls_tags=false
11 | sp_cleanup.add_missing_override_annotations=true
12 | sp_cleanup.add_missing_override_annotations_interface_methods=true
13 | sp_cleanup.add_serial_version_id=false
14 | sp_cleanup.always_use_blocks=true
15 | sp_cleanup.always_use_parentheses_in_expressions=false
16 | sp_cleanup.always_use_this_for_non_static_field_access=false
17 | sp_cleanup.always_use_this_for_non_static_method_access=false
18 | sp_cleanup.convert_to_enhanced_for_loop=false
19 | sp_cleanup.correct_indentation=false
20 | sp_cleanup.format_source_code=true
21 | sp_cleanup.format_source_code_changes_only=false
22 | sp_cleanup.make_local_variable_final=false
23 | sp_cleanup.make_parameters_final=false
24 | sp_cleanup.make_private_fields_final=true
25 | sp_cleanup.make_type_abstract_if_missing_method=false
26 | sp_cleanup.make_variable_declarations_final=true
27 | sp_cleanup.never_use_blocks=false
28 | sp_cleanup.never_use_parentheses_in_expressions=true
29 | sp_cleanup.on_save_use_additional_actions=true
30 | sp_cleanup.organize_imports=true
31 | sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
32 | sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
33 | sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
34 | sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
35 | sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
36 | sp_cleanup.remove_private_constructors=true
37 | sp_cleanup.remove_trailing_whitespaces=false
38 | sp_cleanup.remove_trailing_whitespaces_all=true
39 | sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
40 | sp_cleanup.remove_unnecessary_casts=true
41 | sp_cleanup.remove_unnecessary_nls_tags=false
42 | sp_cleanup.remove_unused_imports=false
43 | sp_cleanup.remove_unused_local_variables=false
44 | sp_cleanup.remove_unused_private_fields=true
45 | sp_cleanup.remove_unused_private_members=false
46 | sp_cleanup.remove_unused_private_methods=true
47 | sp_cleanup.remove_unused_private_types=true
48 | sp_cleanup.sort_members=false
49 | sp_cleanup.sort_members_all=false
50 | sp_cleanup.use_blocks=false
51 | sp_cleanup.use_blocks_only_for_return_and_throw=false
52 | sp_cleanup.use_parentheses_in_expressions=false
53 | sp_cleanup.use_this_for_non_static_field_access=false
54 | sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
55 | sp_cleanup.use_this_for_non_static_method_access=false
56 | sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
57 |
--------------------------------------------------------------------------------
/java/03FromPushToPull/03FromPushToPull.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/03FromPushToPull/src/pushpull/ValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | public class ValuesOfMonth {
4 | private int balance;
5 | private double averageBalance;
6 |
7 | public int getBalance() {
8 | return balance;
9 | }
10 |
11 | public int getAverageBalance() {
12 | return (int) averageBalance;
13 | }
14 |
15 | public void setBalanceAndAverage(int balance, double averageBalance) {
16 | this.balance = balance;
17 | this.averageBalance = averageBalance;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/java/03FromPushToPull/test/pushpull/PushPullTest.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import org.junit.Before;
4 |
5 | import common.CalculatorTest;
6 | import pushpull.BalancesCalculator;
7 |
8 | public class PushPullTest extends CalculatorTest {
9 |
10 | @Before
11 | public void setup() {
12 | calculator = new BalancesCalculator(transactions);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/java/04FromPushToPull/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/java/04FromPushToPull/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | bin
--------------------------------------------------------------------------------
/java/04FromPushToPull/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | 04FromPushToPull
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/java/04FromPushToPull/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=ISO-8859-1
3 |
--------------------------------------------------------------------------------
/java/04FromPushToPull/.settings/org.eclipse.core.runtime.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | line.separator=\r\n
3 |
--------------------------------------------------------------------------------
/java/04FromPushToPull/.settings/org.eclipse.jdt.ui.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
3 | formatter_profile=_Legacy
4 | formatter_settings_version=12
5 | sp_cleanup.add_default_serial_version_id=true
6 | sp_cleanup.add_generated_serial_version_id=false
7 | sp_cleanup.add_missing_annotations=true
8 | sp_cleanup.add_missing_deprecated_annotations=true
9 | sp_cleanup.add_missing_methods=false
10 | sp_cleanup.add_missing_nls_tags=false
11 | sp_cleanup.add_missing_override_annotations=true
12 | sp_cleanup.add_missing_override_annotations_interface_methods=true
13 | sp_cleanup.add_serial_version_id=false
14 | sp_cleanup.always_use_blocks=true
15 | sp_cleanup.always_use_parentheses_in_expressions=false
16 | sp_cleanup.always_use_this_for_non_static_field_access=false
17 | sp_cleanup.always_use_this_for_non_static_method_access=false
18 | sp_cleanup.convert_to_enhanced_for_loop=false
19 | sp_cleanup.correct_indentation=false
20 | sp_cleanup.format_source_code=true
21 | sp_cleanup.format_source_code_changes_only=false
22 | sp_cleanup.make_local_variable_final=false
23 | sp_cleanup.make_parameters_final=false
24 | sp_cleanup.make_private_fields_final=true
25 | sp_cleanup.make_type_abstract_if_missing_method=false
26 | sp_cleanup.make_variable_declarations_final=true
27 | sp_cleanup.never_use_blocks=false
28 | sp_cleanup.never_use_parentheses_in_expressions=true
29 | sp_cleanup.on_save_use_additional_actions=true
30 | sp_cleanup.organize_imports=true
31 | sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
32 | sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
33 | sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
34 | sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
35 | sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
36 | sp_cleanup.remove_private_constructors=true
37 | sp_cleanup.remove_trailing_whitespaces=false
38 | sp_cleanup.remove_trailing_whitespaces_all=true
39 | sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
40 | sp_cleanup.remove_unnecessary_casts=true
41 | sp_cleanup.remove_unnecessary_nls_tags=false
42 | sp_cleanup.remove_unused_imports=false
43 | sp_cleanup.remove_unused_local_variables=false
44 | sp_cleanup.remove_unused_private_fields=true
45 | sp_cleanup.remove_unused_private_members=false
46 | sp_cleanup.remove_unused_private_methods=true
47 | sp_cleanup.remove_unused_private_types=true
48 | sp_cleanup.sort_members=false
49 | sp_cleanup.sort_members_all=false
50 | sp_cleanup.use_blocks=false
51 | sp_cleanup.use_blocks_only_for_return_and_throw=false
52 | sp_cleanup.use_parentheses_in_expressions=false
53 | sp_cleanup.use_this_for_non_static_field_access=false
54 | sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
55 | sp_cleanup.use_this_for_non_static_method_access=false
56 | sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
57 |
--------------------------------------------------------------------------------
/java/04FromPushToPull/04FromPushToPull.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/04FromPushToPull/src/pushpull/ValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | public class ValuesOfMonth {
4 | private int balance;
5 | private double averageBalance;
6 |
7 | public int getBalance() {
8 | return balance;
9 | }
10 |
11 | public int getAverageBalance() {
12 | return (int) averageBalance;
13 | }
14 |
15 | public void setBalanceAndAverage(int balance, double averageBalance) {
16 | this.balance = balance;
17 | this.averageBalance = averageBalance;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/java/04FromPushToPull/test/pushpull/PushPullTest.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import org.junit.Before;
4 |
5 | import common.CalculatorTest;
6 | import pushpull.BalancesCalculator;
7 |
8 | public class PushPullTest extends CalculatorTest {
9 |
10 | @Before
11 | public void setup() {
12 | calculator = new BalancesCalculator(transactions);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/java/05FromPushToPull/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/java/05FromPushToPull/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | bin
--------------------------------------------------------------------------------
/java/05FromPushToPull/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | 05FromPushToPull
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/java/05FromPushToPull/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=ISO-8859-1
3 |
--------------------------------------------------------------------------------
/java/05FromPushToPull/.settings/org.eclipse.core.runtime.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | line.separator=\r\n
3 |
--------------------------------------------------------------------------------
/java/05FromPushToPull/.settings/org.eclipse.jdt.ui.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
3 | formatter_profile=_Legacy
4 | formatter_settings_version=12
5 | sp_cleanup.add_default_serial_version_id=true
6 | sp_cleanup.add_generated_serial_version_id=false
7 | sp_cleanup.add_missing_annotations=true
8 | sp_cleanup.add_missing_deprecated_annotations=true
9 | sp_cleanup.add_missing_methods=false
10 | sp_cleanup.add_missing_nls_tags=false
11 | sp_cleanup.add_missing_override_annotations=true
12 | sp_cleanup.add_missing_override_annotations_interface_methods=true
13 | sp_cleanup.add_serial_version_id=false
14 | sp_cleanup.always_use_blocks=true
15 | sp_cleanup.always_use_parentheses_in_expressions=false
16 | sp_cleanup.always_use_this_for_non_static_field_access=false
17 | sp_cleanup.always_use_this_for_non_static_method_access=false
18 | sp_cleanup.convert_to_enhanced_for_loop=false
19 | sp_cleanup.correct_indentation=false
20 | sp_cleanup.format_source_code=true
21 | sp_cleanup.format_source_code_changes_only=false
22 | sp_cleanup.make_local_variable_final=false
23 | sp_cleanup.make_parameters_final=false
24 | sp_cleanup.make_private_fields_final=true
25 | sp_cleanup.make_type_abstract_if_missing_method=false
26 | sp_cleanup.make_variable_declarations_final=true
27 | sp_cleanup.never_use_blocks=false
28 | sp_cleanup.never_use_parentheses_in_expressions=true
29 | sp_cleanup.on_save_use_additional_actions=true
30 | sp_cleanup.organize_imports=true
31 | sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
32 | sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
33 | sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
34 | sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
35 | sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
36 | sp_cleanup.remove_private_constructors=true
37 | sp_cleanup.remove_trailing_whitespaces=false
38 | sp_cleanup.remove_trailing_whitespaces_all=true
39 | sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
40 | sp_cleanup.remove_unnecessary_casts=true
41 | sp_cleanup.remove_unnecessary_nls_tags=false
42 | sp_cleanup.remove_unused_imports=false
43 | sp_cleanup.remove_unused_local_variables=false
44 | sp_cleanup.remove_unused_private_fields=true
45 | sp_cleanup.remove_unused_private_members=false
46 | sp_cleanup.remove_unused_private_methods=true
47 | sp_cleanup.remove_unused_private_types=true
48 | sp_cleanup.sort_members=false
49 | sp_cleanup.sort_members_all=false
50 | sp_cleanup.use_blocks=false
51 | sp_cleanup.use_blocks_only_for_return_and_throw=false
52 | sp_cleanup.use_parentheses_in_expressions=false
53 | sp_cleanup.use_this_for_non_static_field_access=false
54 | sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
55 | sp_cleanup.use_this_for_non_static_method_access=false
56 | sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
57 |
--------------------------------------------------------------------------------
/java/05FromPushToPull/05FromPushToPull.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/05FromPushToPull/src/pushpull/BalancesCalculator.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.joda.time.LocalDate;
7 |
8 | import common.BalancesOfMonthCalculator_API;
9 | import common.BalancesOfMonth_API;
10 | import common.Transaction_API;
11 |
12 | public class BalancesCalculator implements BalancesOfMonthCalculator_API {
13 |
14 | private final List transactions;
15 |
16 | public BalancesCalculator(List transactions) {
17 | this.transactions = transactions;
18 | }
19 |
20 | @Override
21 | public void fillData(List balancesOfMonthList) {
22 | ValuesOfMonth valuesOfMonth = new ValuesOfMonth();
23 | int balance = 0;
24 |
25 | for (BalancesOfMonth_API balancesOfMonth : balancesOfMonthList) {
26 | LocalDate dateOfMonth = balancesOfMonth.getDate();
27 | List transactionsOfMonth = transactionsOfMonth(dateOfMonth);
28 |
29 | balance = valuesOfMonth.calculateValues(balance, dateOfMonth, transactionsOfMonth);
30 |
31 | balancesOfMonth.setBalance(valuesOfMonth.getBalance());
32 | balancesOfMonth.setAverageBalance(valuesOfMonth.getAverageBalance());
33 | }
34 | }
35 |
36 | private List transactionsOfMonth(LocalDate date) {
37 | List results = new ArrayList();
38 | for (Transaction_API transaction : transactions) {
39 | LocalDate dateOfTransaction = transaction.getDate();
40 | if (areSameMonthAndYear(date, dateOfTransaction)) {
41 | results.add(transaction);
42 | }
43 | }
44 | return results;
45 | }
46 |
47 | private boolean areSameMonthAndYear(LocalDate date, LocalDate dateOfTransaction) {
48 | return dateOfTransaction.getMonthOfYear() == date.getMonthOfYear() && dateOfTransaction.getYear() == date.getYear();
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/java/05FromPushToPull/src/pushpull/ValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.List;
4 | import org.joda.time.LocalDate;
5 | import common.Transaction_API;
6 |
7 | public class ValuesOfMonth {
8 | private int balance;
9 | private double averageBalance;
10 |
11 | public int getBalance() {
12 | return balance;
13 | }
14 |
15 | public int getAverageBalance() {
16 | return (int) averageBalance;
17 | }
18 |
19 | public void setBalanceAndAverage(int balance, double averageBalance) {
20 | this.balance = balance;
21 | this.averageBalance = averageBalance;
22 | }
23 |
24 | int calculateValues(int precedingBalance, LocalDate dateOfMonth, List transactionsOfMonth) {
25 | int balance = precedingBalance;
26 | int ultimo = dateOfMonth.getDayOfMonth();
27 |
28 | double averageBalance = 0;
29 | int dayOfLatestBalance = 1;
30 | for (Transaction_API transaction : transactionsOfMonth) {
31 | int day = transaction.getDate().getDayOfMonth();
32 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, day, ultimo);
33 | balance += transaction.getAmount();
34 | dayOfLatestBalance = day;
35 | }
36 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, ultimo + 1, ultimo);
37 |
38 | setBalanceAndAverage(balance, averageBalance);
39 | return balance;
40 | }
41 |
42 | private double calculateProportionalBalance(int dayOfLatestBalance, int balance, int day, int daysInMonth) {
43 | int countingDays = day - dayOfLatestBalance;
44 | if (countingDays == 0) {
45 | return 0;
46 | }
47 | double rate = (double) countingDays / daysInMonth;
48 | return (balance * rate);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/java/05FromPushToPull/test/pushpull/PushPullTest.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import org.junit.Before;
4 |
5 | import common.CalculatorTest;
6 | import pushpull.BalancesCalculator;
7 |
8 | public class PushPullTest extends CalculatorTest {
9 |
10 | @Before
11 | public void setup() {
12 | calculator = new BalancesCalculator(transactions);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/java/06FromPushToPull/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/java/06FromPushToPull/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | bin
--------------------------------------------------------------------------------
/java/06FromPushToPull/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | 06FromPushToPull
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/java/06FromPushToPull/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=ISO-8859-1
3 |
--------------------------------------------------------------------------------
/java/06FromPushToPull/.settings/org.eclipse.core.runtime.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | line.separator=\r\n
3 |
--------------------------------------------------------------------------------
/java/06FromPushToPull/.settings/org.eclipse.jdt.ui.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
3 | formatter_profile=_Legacy
4 | formatter_settings_version=12
5 | sp_cleanup.add_default_serial_version_id=true
6 | sp_cleanup.add_generated_serial_version_id=false
7 | sp_cleanup.add_missing_annotations=true
8 | sp_cleanup.add_missing_deprecated_annotations=true
9 | sp_cleanup.add_missing_methods=false
10 | sp_cleanup.add_missing_nls_tags=false
11 | sp_cleanup.add_missing_override_annotations=true
12 | sp_cleanup.add_missing_override_annotations_interface_methods=true
13 | sp_cleanup.add_serial_version_id=false
14 | sp_cleanup.always_use_blocks=true
15 | sp_cleanup.always_use_parentheses_in_expressions=false
16 | sp_cleanup.always_use_this_for_non_static_field_access=false
17 | sp_cleanup.always_use_this_for_non_static_method_access=false
18 | sp_cleanup.convert_to_enhanced_for_loop=false
19 | sp_cleanup.correct_indentation=false
20 | sp_cleanup.format_source_code=true
21 | sp_cleanup.format_source_code_changes_only=false
22 | sp_cleanup.make_local_variable_final=false
23 | sp_cleanup.make_parameters_final=false
24 | sp_cleanup.make_private_fields_final=true
25 | sp_cleanup.make_type_abstract_if_missing_method=false
26 | sp_cleanup.make_variable_declarations_final=true
27 | sp_cleanup.never_use_blocks=false
28 | sp_cleanup.never_use_parentheses_in_expressions=true
29 | sp_cleanup.on_save_use_additional_actions=true
30 | sp_cleanup.organize_imports=true
31 | sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
32 | sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
33 | sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
34 | sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
35 | sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
36 | sp_cleanup.remove_private_constructors=true
37 | sp_cleanup.remove_trailing_whitespaces=false
38 | sp_cleanup.remove_trailing_whitespaces_all=true
39 | sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
40 | sp_cleanup.remove_unnecessary_casts=true
41 | sp_cleanup.remove_unnecessary_nls_tags=false
42 | sp_cleanup.remove_unused_imports=false
43 | sp_cleanup.remove_unused_local_variables=false
44 | sp_cleanup.remove_unused_private_fields=true
45 | sp_cleanup.remove_unused_private_members=false
46 | sp_cleanup.remove_unused_private_methods=true
47 | sp_cleanup.remove_unused_private_types=true
48 | sp_cleanup.sort_members=false
49 | sp_cleanup.sort_members_all=false
50 | sp_cleanup.use_blocks=false
51 | sp_cleanup.use_blocks_only_for_return_and_throw=false
52 | sp_cleanup.use_parentheses_in_expressions=false
53 | sp_cleanup.use_this_for_non_static_field_access=false
54 | sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
55 | sp_cleanup.use_this_for_non_static_method_access=false
56 | sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
57 |
--------------------------------------------------------------------------------
/java/06FromPushToPull/06FromPushToPull.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/06FromPushToPull/src/pushpull/BalancesCalculator.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.joda.time.LocalDate;
7 |
8 | import common.BalancesOfMonthCalculator_API;
9 | import common.BalancesOfMonth_API;
10 | import common.Transaction_API;
11 |
12 | public class BalancesCalculator implements BalancesOfMonthCalculator_API {
13 |
14 | private final List transactions;
15 |
16 | public BalancesCalculator(List transactions) {
17 | this.transactions = transactions;
18 | }
19 |
20 | @Override
21 | public void fillData(List balancesOfMonthList) {
22 | ValuesOfMonth valuesOfMonth = new ValuesOfMonth();
23 |
24 | for (BalancesOfMonth_API balancesOfMonth : balancesOfMonthList) {
25 | LocalDate dateOfMonth = balancesOfMonth.getDate();
26 | List transactionsOfMonth = transactionsOfMonth(dateOfMonth);
27 |
28 | int precedingBalance = valuesOfMonth.getBalance();
29 |
30 | valuesOfMonth = new ValuesOfMonth();
31 | valuesOfMonth.calculateValues(precedingBalance, dateOfMonth, transactionsOfMonth);
32 |
33 | balancesOfMonth.setBalance(valuesOfMonth.getBalance());
34 | balancesOfMonth.setAverageBalance(valuesOfMonth.getAverageBalance());
35 | }
36 | }
37 |
38 | private List transactionsOfMonth(LocalDate date) {
39 | List results = new ArrayList();
40 | for (Transaction_API transaction : transactions) {
41 | LocalDate dateOfTransaction = transaction.getDate();
42 | if (areSameMonthAndYear(date, dateOfTransaction)) {
43 | results.add(transaction);
44 | }
45 | }
46 | return results;
47 | }
48 |
49 | private boolean areSameMonthAndYear(LocalDate date, LocalDate dateOfTransaction) {
50 | return dateOfTransaction.getMonthOfYear() == date.getMonthOfYear() && dateOfTransaction.getYear() == date.getYear();
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/java/06FromPushToPull/src/pushpull/ValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.List;
4 | import org.joda.time.LocalDate;
5 | import common.Transaction_API;
6 |
7 | public class ValuesOfMonth {
8 | private int balance;
9 | private double averageBalance;
10 |
11 | public int getBalance() {
12 | return balance;
13 | }
14 |
15 | public int getAverageBalance() {
16 | return (int) averageBalance;
17 | }
18 |
19 | public void setBalanceAndAverage(int balance, double averageBalance) {
20 | this.balance = balance;
21 | this.averageBalance = averageBalance;
22 | }
23 |
24 | void calculateValues(int precedingBalance, LocalDate dateOfMonth, List transactionsOfMonth) {
25 | int balance = precedingBalance;
26 | int ultimo = dateOfMonth.getDayOfMonth();
27 |
28 | double averageBalance = 0;
29 | int dayOfLatestBalance = 1;
30 | for (Transaction_API transaction : transactionsOfMonth) {
31 | int day = transaction.getDate().getDayOfMonth();
32 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, day, ultimo);
33 | balance += transaction.getAmount();
34 | dayOfLatestBalance = day;
35 | }
36 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, ultimo + 1, ultimo);
37 |
38 | setBalanceAndAverage(balance, averageBalance);
39 | }
40 |
41 | private double calculateProportionalBalance(int dayOfLatestBalance, int balance, int day, int daysInMonth) {
42 | int countingDays = day - dayOfLatestBalance;
43 | if (countingDays == 0) {
44 | return 0;
45 | }
46 | double rate = (double) countingDays / daysInMonth;
47 | return (balance * rate);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/java/06FromPushToPull/test/pushpull/PushPullTest.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import org.junit.Before;
4 |
5 | import common.CalculatorTest;
6 | import pushpull.BalancesCalculator;
7 |
8 | public class PushPullTest extends CalculatorTest {
9 |
10 | @Before
11 | public void setup() {
12 | calculator = new BalancesCalculator(transactions);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/java/07FromPushToPull/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/java/07FromPushToPull/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | bin
--------------------------------------------------------------------------------
/java/07FromPushToPull/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | 07FromPushToPull
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/java/07FromPushToPull/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=ISO-8859-1
3 |
--------------------------------------------------------------------------------
/java/07FromPushToPull/.settings/org.eclipse.core.runtime.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | line.separator=\r\n
3 |
--------------------------------------------------------------------------------
/java/07FromPushToPull/.settings/org.eclipse.jdt.ui.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
3 | formatter_profile=_Legacy
4 | formatter_settings_version=12
5 | sp_cleanup.add_default_serial_version_id=true
6 | sp_cleanup.add_generated_serial_version_id=false
7 | sp_cleanup.add_missing_annotations=true
8 | sp_cleanup.add_missing_deprecated_annotations=true
9 | sp_cleanup.add_missing_methods=false
10 | sp_cleanup.add_missing_nls_tags=false
11 | sp_cleanup.add_missing_override_annotations=true
12 | sp_cleanup.add_missing_override_annotations_interface_methods=true
13 | sp_cleanup.add_serial_version_id=false
14 | sp_cleanup.always_use_blocks=true
15 | sp_cleanup.always_use_parentheses_in_expressions=false
16 | sp_cleanup.always_use_this_for_non_static_field_access=false
17 | sp_cleanup.always_use_this_for_non_static_method_access=false
18 | sp_cleanup.convert_to_enhanced_for_loop=false
19 | sp_cleanup.correct_indentation=false
20 | sp_cleanup.format_source_code=true
21 | sp_cleanup.format_source_code_changes_only=false
22 | sp_cleanup.make_local_variable_final=false
23 | sp_cleanup.make_parameters_final=false
24 | sp_cleanup.make_private_fields_final=true
25 | sp_cleanup.make_type_abstract_if_missing_method=false
26 | sp_cleanup.make_variable_declarations_final=true
27 | sp_cleanup.never_use_blocks=false
28 | sp_cleanup.never_use_parentheses_in_expressions=true
29 | sp_cleanup.on_save_use_additional_actions=true
30 | sp_cleanup.organize_imports=true
31 | sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
32 | sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
33 | sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
34 | sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
35 | sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
36 | sp_cleanup.remove_private_constructors=true
37 | sp_cleanup.remove_trailing_whitespaces=false
38 | sp_cleanup.remove_trailing_whitespaces_all=true
39 | sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
40 | sp_cleanup.remove_unnecessary_casts=true
41 | sp_cleanup.remove_unnecessary_nls_tags=false
42 | sp_cleanup.remove_unused_imports=false
43 | sp_cleanup.remove_unused_local_variables=false
44 | sp_cleanup.remove_unused_private_fields=true
45 | sp_cleanup.remove_unused_private_members=false
46 | sp_cleanup.remove_unused_private_methods=true
47 | sp_cleanup.remove_unused_private_types=true
48 | sp_cleanup.sort_members=false
49 | sp_cleanup.sort_members_all=false
50 | sp_cleanup.use_blocks=false
51 | sp_cleanup.use_blocks_only_for_return_and_throw=false
52 | sp_cleanup.use_parentheses_in_expressions=false
53 | sp_cleanup.use_this_for_non_static_field_access=false
54 | sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
55 | sp_cleanup.use_this_for_non_static_method_access=false
56 | sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
57 |
--------------------------------------------------------------------------------
/java/07FromPushToPull/07FromPushToPull.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/07FromPushToPull/src/pushpull/BalancesCalculator.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.joda.time.LocalDate;
7 |
8 | import common.BalancesOfMonthCalculator_API;
9 | import common.BalancesOfMonth_API;
10 | import common.Transaction_API;
11 |
12 | public class BalancesCalculator implements BalancesOfMonthCalculator_API {
13 |
14 | private final List transactions;
15 |
16 | public BalancesCalculator(List transactions) {
17 | this.transactions = transactions;
18 | }
19 |
20 | @Override
21 | public void fillData(List balancesOfMonthList) {
22 | ValuesOfMonth valuesOfMonth = new ValuesOfMonth();
23 |
24 | for (BalancesOfMonth_API balancesOfMonth : balancesOfMonthList) {
25 | LocalDate dateOfMonth = balancesOfMonth.getDate();
26 | List transactionsOfMonth = transactionsOfMonth(dateOfMonth);
27 |
28 | int precedingBalance = valuesOfMonth.getBalance();
29 |
30 | valuesOfMonth = new ValuesOfMonth(precedingBalance, dateOfMonth, transactionsOfMonth);
31 | valuesOfMonth.calculateValues();
32 |
33 | balancesOfMonth.setBalance(valuesOfMonth.getBalance());
34 | balancesOfMonth.setAverageBalance(valuesOfMonth.getAverageBalance());
35 | }
36 | }
37 |
38 | private List transactionsOfMonth(LocalDate date) {
39 | List results = new ArrayList();
40 | for (Transaction_API transaction : transactions) {
41 | LocalDate dateOfTransaction = transaction.getDate();
42 | if (areSameMonthAndYear(date, dateOfTransaction)) {
43 | results.add(transaction);
44 | }
45 | }
46 | return results;
47 | }
48 |
49 | private boolean areSameMonthAndYear(LocalDate date, LocalDate dateOfTransaction) {
50 | return dateOfTransaction.getMonthOfYear() == date.getMonthOfYear() && dateOfTransaction.getYear() == date.getYear();
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/java/07FromPushToPull/src/pushpull/ValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import org.joda.time.LocalDate;
6 | import common.Transaction_API;
7 |
8 | public class ValuesOfMonth {
9 | private int balance;
10 | private double averageBalance;
11 | private final LocalDate dateOfMonth;
12 | private final List transactionsOfMonth;
13 | private final int precedingBalance;
14 |
15 | public ValuesOfMonth() {
16 | this(0, new LocalDate(), new ArrayList());
17 | }
18 |
19 | public ValuesOfMonth(int precedingBalance, LocalDate dateOfMonth, List transactionsOfMonth) {
20 | this.dateOfMonth = dateOfMonth;
21 | this.transactionsOfMonth = transactionsOfMonth;
22 | this.precedingBalance = precedingBalance;
23 | }
24 |
25 | public int getBalance() {
26 | return balance;
27 | }
28 |
29 | public int getAverageBalance() {
30 | return (int) averageBalance;
31 | }
32 |
33 | public void setBalanceAndAverage(int balance, double averageBalance) {
34 | this.balance = balance;
35 | this.averageBalance = averageBalance;
36 | }
37 |
38 | void calculateValues() {
39 | int balance = precedingBalance;
40 | int ultimo = dateOfMonth.getDayOfMonth();
41 |
42 | double averageBalance = 0;
43 | int dayOfLatestBalance = 1;
44 | for (Transaction_API transaction : transactionsOfMonth) {
45 | int day = transaction.getDate().getDayOfMonth();
46 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, day, ultimo);
47 | balance += transaction.getAmount();
48 | dayOfLatestBalance = day;
49 | }
50 |
51 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, ultimo + 1, ultimo);
52 |
53 | setBalanceAndAverage(balance, averageBalance);
54 | }
55 |
56 | private double calculateProportionalBalance(int dayOfLatestBalance, int balance, int day, int daysInMonth) {
57 | int countingDays = day - dayOfLatestBalance;
58 | if (countingDays == 0) {
59 | return 0;
60 | }
61 | double rate = (double) countingDays / daysInMonth;
62 | return (balance * rate);
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/java/07FromPushToPull/test/pushpull/PushPullTest.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import org.junit.Before;
4 |
5 | import common.CalculatorTest;
6 | import pushpull.BalancesCalculator;
7 |
8 | public class PushPullTest extends CalculatorTest {
9 |
10 | @Before
11 | public void setup() {
12 | calculator = new BalancesCalculator(transactions);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/java/08FromPushToPull/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/java/08FromPushToPull/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | bin
--------------------------------------------------------------------------------
/java/08FromPushToPull/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | 08FromPushToPull
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/java/08FromPushToPull/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=ISO-8859-1
3 |
--------------------------------------------------------------------------------
/java/08FromPushToPull/.settings/org.eclipse.core.runtime.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | line.separator=\r\n
3 |
--------------------------------------------------------------------------------
/java/08FromPushToPull/08FromPushToPull.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/08FromPushToPull/src/pushpull/BalancesCalculator.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.joda.time.LocalDate;
7 |
8 | import common.BalancesOfMonthCalculator_API;
9 | import common.BalancesOfMonth_API;
10 | import common.Transaction_API;
11 |
12 | public class BalancesCalculator implements BalancesOfMonthCalculator_API {
13 |
14 | private final List transactions;
15 |
16 | public BalancesCalculator(List transactions) {
17 | this.transactions = transactions;
18 | }
19 |
20 | @Override
21 | public void fillData(List balancesOfMonthList) {
22 | ValuesOfMonth valuesOfMonth = new ValuesOfMonth();
23 |
24 | for (BalancesOfMonth_API balancesOfMonth : balancesOfMonthList) {
25 | LocalDate dateOfMonth = balancesOfMonth.getDate();
26 | List transactionsOfMonth = transactionsOfMonth(dateOfMonth);
27 |
28 | int precedingBalance = valuesOfMonth.getBalance();
29 |
30 | valuesOfMonth = new ValuesOfMonth(precedingBalance, dateOfMonth, transactionsOfMonth);
31 |
32 | balancesOfMonth.setBalance(valuesOfMonth.getBalance());
33 | balancesOfMonth.setAverageBalance(valuesOfMonth.getAverageBalance());
34 | }
35 | }
36 |
37 | private List transactionsOfMonth(LocalDate date) {
38 | List results = new ArrayList();
39 | for (Transaction_API transaction : transactions) {
40 | LocalDate dateOfTransaction = transaction.getDate();
41 | if (areSameMonthAndYear(date, dateOfTransaction)) {
42 | results.add(transaction);
43 | }
44 | }
45 | return results;
46 | }
47 |
48 | private boolean areSameMonthAndYear(LocalDate date, LocalDate dateOfTransaction) {
49 | return dateOfTransaction.getMonthOfYear() == date.getMonthOfYear() && dateOfTransaction.getYear() == date.getYear();
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/java/08FromPushToPull/src/pushpull/ValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.joda.time.LocalDate;
7 |
8 | import common.Transaction_API;
9 |
10 | public class ValuesOfMonth {
11 | private int balance;
12 | private double averageBalance;
13 | private final LocalDate dateOfMonth;
14 | private final List transactionsOfMonth;
15 | private final int precedingBalance;
16 |
17 | public ValuesOfMonth() {
18 | this(0, new LocalDate(), new ArrayList());
19 | }
20 |
21 | public ValuesOfMonth(int precedingBalance, LocalDate dateOfMonth, List transactionsOfMonth) {
22 | this.dateOfMonth = dateOfMonth;
23 | this.transactionsOfMonth = transactionsOfMonth;
24 | this.precedingBalance = precedingBalance;
25 | }
26 |
27 | public int getBalance() {
28 | calculateValues();
29 | return balance;
30 | }
31 |
32 | public int getAverageBalance() {
33 | calculateValues();
34 | return (int) averageBalance;
35 | }
36 |
37 | public void setBalanceAndAverage(int balance, double averageBalance) {
38 | this.balance = balance;
39 | this.averageBalance = averageBalance;
40 | }
41 |
42 | private void calculateValues() {
43 | int balance = precedingBalance;
44 | int ultimo = dateOfMonth.getDayOfMonth();
45 |
46 | double averageBalance = 0;
47 | int dayOfLatestBalance = 1;
48 | for (Transaction_API transaction : transactionsOfMonth) {
49 | int day = transaction.getDate().getDayOfMonth();
50 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, day, ultimo);
51 | balance += transaction.getAmount();
52 | dayOfLatestBalance = day;
53 | }
54 |
55 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, ultimo + 1, ultimo);
56 |
57 | setBalanceAndAverage(balance, averageBalance);
58 | }
59 |
60 | private double calculateProportionalBalance(int dayOfLatestBalance, int balance, int day, int daysInMonth) {
61 | int countingDays = day - dayOfLatestBalance;
62 | if (countingDays == 0) {
63 | return 0;
64 | }
65 | double rate = (double) countingDays / daysInMonth;
66 | return (balance * rate);
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/java/08FromPushToPull/test/pushpull/PushPullTest.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import org.junit.Before;
4 |
5 | import common.CalculatorTest;
6 | import pushpull.BalancesCalculator;
7 |
8 | public class PushPullTest extends CalculatorTest {
9 |
10 | @Before
11 | public void setup() {
12 | calculator = new BalancesCalculator(transactions);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/java/09FromPushToPull/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/java/09FromPushToPull/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | bin
--------------------------------------------------------------------------------
/java/09FromPushToPull/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | 09FromPushToPull
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/java/09FromPushToPull/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=ISO-8859-1
3 |
--------------------------------------------------------------------------------
/java/09FromPushToPull/.settings/org.eclipse.core.runtime.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | line.separator=\r\n
3 |
--------------------------------------------------------------------------------
/java/09FromPushToPull/09FromPushToPull.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/09FromPushToPull/src/pushpull/BalancesCalculator.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.joda.time.LocalDate;
7 |
8 | import common.BalancesOfMonthCalculator_API;
9 | import common.BalancesOfMonth_API;
10 | import common.Transaction_API;
11 |
12 | public class BalancesCalculator implements BalancesOfMonthCalculator_API {
13 |
14 | private final List transactions;
15 |
16 | public BalancesCalculator(List transactions) {
17 | this.transactions = transactions;
18 | }
19 |
20 | @Override
21 | public void fillData(List balancesOfMonthList) {
22 | ValuesOfMonth valuesOfMonth = new ValuesOfMonth();
23 |
24 | for (BalancesOfMonth_API balancesOfMonth : balancesOfMonthList) {
25 | LocalDate dateOfMonth = balancesOfMonth.getDate();
26 | List transactionsOfMonth = transactionsOfMonth(dateOfMonth);
27 |
28 | int precedingBalance = valuesOfMonth.getBalance();
29 |
30 | valuesOfMonth = new ValuesOfMonth(precedingBalance, dateOfMonth, transactionsOfMonth);
31 |
32 | balancesOfMonth.setBalance(valuesOfMonth.getBalance());
33 | balancesOfMonth.setAverageBalance(valuesOfMonth.getAverageBalance());
34 | }
35 | }
36 |
37 | private List transactionsOfMonth(LocalDate date) {
38 | List results = new ArrayList();
39 | for (Transaction_API transaction : transactions) {
40 | LocalDate dateOfTransaction = transaction.getDate();
41 | if (areSameMonthAndYear(date, dateOfTransaction)) {
42 | results.add(transaction);
43 | }
44 | }
45 | return results;
46 | }
47 |
48 | private boolean areSameMonthAndYear(LocalDate date, LocalDate dateOfTransaction) {
49 | return dateOfTransaction.getMonthOfYear() == date.getMonthOfYear() && dateOfTransaction.getYear() == date.getYear();
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/java/09FromPushToPull/src/pushpull/ValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.joda.time.LocalDate;
7 |
8 | import common.Transaction_API;
9 |
10 | public class ValuesOfMonth {
11 | private final LocalDate dateOfMonth;
12 | private final List transactionsOfMonth;
13 | private final int precedingBalance;
14 |
15 | public ValuesOfMonth() {
16 | this(0, new LocalDate(), new ArrayList());
17 | }
18 |
19 | public ValuesOfMonth(int precedingBalance, LocalDate dateOfMonth, List transactionsOfMonth) {
20 | this.dateOfMonth = dateOfMonth;
21 | this.transactionsOfMonth = transactionsOfMonth;
22 | this.precedingBalance = precedingBalance;
23 | }
24 |
25 | public int getBalance() {
26 | int balance = precedingBalance;
27 | for (Transaction_API transaction : transactionsOfMonth) {
28 | balance += transaction.getAmount();
29 | }
30 | return balance;
31 | }
32 |
33 | public int getAverageBalance() {
34 | int balance = precedingBalance;
35 | int ultimo = dateOfMonth.getDayOfMonth();
36 |
37 | double averageBalance = 0;
38 | int dayOfLatestBalance = 1;
39 | for (Transaction_API transaction : transactionsOfMonth) {
40 | int day = transaction.getDate().getDayOfMonth();
41 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, day, ultimo);
42 | balance += transaction.getAmount();
43 | dayOfLatestBalance = day;
44 | }
45 |
46 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, ultimo + 1, ultimo);
47 |
48 | return (int) averageBalance;
49 | }
50 |
51 | private double calculateProportionalBalance(int dayOfLatestBalance, int balance, int day, int daysInMonth) {
52 | int countingDays = day - dayOfLatestBalance;
53 | if (countingDays == 0) {
54 | return 0;
55 | }
56 | double rate = (double) countingDays / daysInMonth;
57 | return (balance * rate);
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/java/09FromPushToPull/test/pushpull/PushPullTest.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import org.junit.Before;
4 |
5 | import common.CalculatorTest;
6 | import pushpull.BalancesCalculator;
7 |
8 | public class PushPullTest extends CalculatorTest {
9 |
10 | @Before
11 | public void setup() {
12 | calculator = new BalancesCalculator(transactions);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/java/10FromPushToPull/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/java/10FromPushToPull/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | bin
--------------------------------------------------------------------------------
/java/10FromPushToPull/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | 10FromPushToPull
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/java/10FromPushToPull/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=ISO-8859-1
3 |
--------------------------------------------------------------------------------
/java/10FromPushToPull/.settings/org.eclipse.core.runtime.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | line.separator=\r\n
3 |
--------------------------------------------------------------------------------
/java/10FromPushToPull/10FromPushToPull.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/10FromPushToPull/src/pushpull/BalancesCalculator.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.joda.time.LocalDate;
7 |
8 | import common.BalancesOfMonthCalculator_API;
9 | import common.BalancesOfMonth_API;
10 | import common.Transaction_API;
11 |
12 | public class BalancesCalculator implements BalancesOfMonthCalculator_API {
13 |
14 | private final List transactions;
15 |
16 | public BalancesCalculator(List transactions) {
17 | this.transactions = transactions;
18 | }
19 |
20 | @Override
21 | public void fillData(List balancesOfMonthList) {
22 | ValuesOfMonth valuesOfMonth = new ValuesOfMonth();
23 |
24 | for (BalancesOfMonth_API balancesOfMonth : balancesOfMonthList) {
25 | LocalDate dateOfMonth = balancesOfMonth.getDate();
26 | List transactionsOfMonth = transactionsOfMonth(dateOfMonth);
27 |
28 | valuesOfMonth = new ValuesOfMonth(valuesOfMonth, dateOfMonth, transactionsOfMonth);
29 |
30 | balancesOfMonth.setBalance(valuesOfMonth.getBalance());
31 | balancesOfMonth.setAverageBalance(valuesOfMonth.getAverageBalance());
32 | }
33 | }
34 |
35 | private List transactionsOfMonth(LocalDate date) {
36 | List results = new ArrayList();
37 | for (Transaction_API transaction : transactions) {
38 | LocalDate dateOfTransaction = transaction.getDate();
39 | if (areSameMonthAndYear(date, dateOfTransaction)) {
40 | results.add(transaction);
41 | }
42 | }
43 | return results;
44 | }
45 |
46 | private boolean areSameMonthAndYear(LocalDate date, LocalDate dateOfTransaction) {
47 | return dateOfTransaction.getMonthOfYear() == date.getMonthOfYear() && dateOfTransaction.getYear() == date.getYear();
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/java/10FromPushToPull/src/pushpull/ValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.joda.time.LocalDate;
7 |
8 | import common.Transaction_API;
9 |
10 | public class ValuesOfMonth {
11 | private final LocalDate dateOfMonth;
12 | private final List transactionsOfMonth;
13 | private final ValuesOfMonth precedingMonth;
14 |
15 | public ValuesOfMonth() {
16 | this(null, new LocalDate(), new ArrayList());
17 | }
18 |
19 | public ValuesOfMonth(ValuesOfMonth precedingMonth, LocalDate dateOfMonth, List transactionsOfMonth) {
20 | this.dateOfMonth = dateOfMonth;
21 | this.transactionsOfMonth = transactionsOfMonth;
22 | this.precedingMonth = precedingMonth;
23 | }
24 |
25 | public int getBalance() {
26 | int balance = precedingMonth == null ? 0 : precedingMonth.getBalance();
27 | for (Transaction_API transaction : transactionsOfMonth) {
28 | balance += transaction.getAmount();
29 | }
30 | return balance;
31 | }
32 |
33 | public int getAverageBalance() {
34 | int balance = precedingMonth == null ? 0 : precedingMonth.getBalance();
35 | int ultimo = dateOfMonth.getDayOfMonth();
36 |
37 | double averageBalance = 0;
38 | int dayOfLatestBalance = 1;
39 | for (Transaction_API transaction : transactionsOfMonth) {
40 | int day = transaction.getDate().getDayOfMonth();
41 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, day, ultimo);
42 | balance += transaction.getAmount();
43 | dayOfLatestBalance = day;
44 | }
45 |
46 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, ultimo + 1, ultimo);
47 |
48 | return (int) averageBalance;
49 | }
50 |
51 | private double calculateProportionalBalance(int dayOfLatestBalance, int balance, int day, int daysInMonth) {
52 | int countingDays = day - dayOfLatestBalance;
53 | if (countingDays == 0) {
54 | return 0;
55 | }
56 | double rate = (double) countingDays / daysInMonth;
57 | return (balance * rate);
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/java/10FromPushToPull/test/pushpull/PushPullTest.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import org.junit.Before;
4 |
5 | import common.CalculatorTest;
6 | import pushpull.BalancesCalculator;
7 |
8 | public class PushPullTest extends CalculatorTest {
9 |
10 | @Before
11 | public void setup() {
12 | calculator = new BalancesCalculator(transactions);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/java/11FromPushToPull/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/java/11FromPushToPull/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | bin
--------------------------------------------------------------------------------
/java/11FromPushToPull/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | 11FromPushToPull
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/java/11FromPushToPull/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=ISO-8859-1
3 |
--------------------------------------------------------------------------------
/java/11FromPushToPull/.settings/org.eclipse.core.runtime.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | line.separator=\r\n
3 |
--------------------------------------------------------------------------------
/java/11FromPushToPull/11FromPushToPull.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/11FromPushToPull/src/pushpull/BalancesCalculator.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.joda.time.LocalDate;
7 |
8 | import common.BalancesOfMonthCalculator_API;
9 | import common.BalancesOfMonth_API;
10 | import common.Transaction_API;
11 |
12 | public class BalancesCalculator implements BalancesOfMonthCalculator_API {
13 |
14 | private final List transactions;
15 |
16 | public BalancesCalculator(List transactions) {
17 | this.transactions = transactions;
18 | }
19 |
20 | @Override
21 | public void fillData(List balancesOfMonthList) {
22 | ValuesOfMonth valuesOfMonth = null;
23 |
24 | for (BalancesOfMonth_API balancesOfMonth : balancesOfMonthList) {
25 | LocalDate dateOfMonth = balancesOfMonth.getDate();
26 | List transactionsOfMonth = transactionsOfMonth(dateOfMonth);
27 |
28 | valuesOfMonth = new ValuesOfMonth(valuesOfMonth == null ? new InitialValuesOfMonth() : valuesOfMonth, dateOfMonth,
29 | transactionsOfMonth);
30 |
31 | balancesOfMonth.setBalance(valuesOfMonth.getBalance());
32 | balancesOfMonth.setAverageBalance(valuesOfMonth.getAverageBalance());
33 | }
34 | }
35 |
36 | private List transactionsOfMonth(LocalDate date) {
37 | List results = new ArrayList();
38 | for (Transaction_API transaction : transactions) {
39 | LocalDate dateOfTransaction = transaction.getDate();
40 | if (areSameMonthAndYear(date, dateOfTransaction)) {
41 | results.add(transaction);
42 | }
43 | }
44 | return results;
45 | }
46 |
47 | private boolean areSameMonthAndYear(LocalDate date, LocalDate dateOfTransaction) {
48 | return dateOfTransaction.getMonthOfYear() == date.getMonthOfYear() && dateOfTransaction.getYear() == date.getYear();
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/java/11FromPushToPull/src/pushpull/IValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | public interface IValuesOfMonth {
4 |
5 | int getBalance();
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/java/11FromPushToPull/src/pushpull/InitialValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | public class InitialValuesOfMonth implements IValuesOfMonth {
4 |
5 | @Override
6 | public int getBalance() {
7 | return 0;
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/java/11FromPushToPull/src/pushpull/ValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.List;
4 |
5 | import org.joda.time.LocalDate;
6 |
7 | import common.Transaction_API;
8 |
9 | public class ValuesOfMonth implements IValuesOfMonth {
10 | private final LocalDate dateOfMonth;
11 | private final List transactionsOfMonth;
12 | private final IValuesOfMonth precedingMonth;
13 |
14 | public ValuesOfMonth(IValuesOfMonth precedingMonth, LocalDate dateOfMonth,
15 | List transactionsOfMonth) {
16 | this.dateOfMonth = dateOfMonth;
17 | this.transactionsOfMonth = transactionsOfMonth;
18 | this.precedingMonth = precedingMonth;
19 | }
20 |
21 | @Override
22 | public int getBalance() {
23 | int balance = precedingMonth.getBalance();
24 | for (Transaction_API transaction : transactionsOfMonth) {
25 | balance += transaction.getAmount();
26 | }
27 | return balance;
28 | }
29 |
30 | public int getAverageBalance() {
31 | int balance = precedingMonth.getBalance();
32 | int ultimo = dateOfMonth.getDayOfMonth();
33 |
34 | double averageBalance = 0;
35 | int dayOfLatestBalance = 1;
36 | for (Transaction_API transaction : transactionsOfMonth) {
37 | int day = transaction.getDate().getDayOfMonth();
38 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, day, ultimo);
39 | balance += transaction.getAmount();
40 | dayOfLatestBalance = day;
41 | }
42 |
43 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, ultimo + 1, ultimo);
44 |
45 | return (int) averageBalance;
46 | }
47 |
48 | private double calculateProportionalBalance(int dayOfLatestBalance, int balance, int day, int daysInMonth) {
49 | int countingDays = day - dayOfLatestBalance;
50 | if (countingDays == 0) {
51 | return 0;
52 | }
53 | double rate = (double) countingDays / daysInMonth;
54 | return (balance * rate);
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/java/11FromPushToPull/test/pushpull/PushPullTest.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import org.junit.Before;
4 |
5 | import common.CalculatorTest;
6 | import pushpull.BalancesCalculator;
7 |
8 | public class PushPullTest extends CalculatorTest {
9 |
10 | @Before
11 | public void setup() {
12 | calculator = new BalancesCalculator(transactions);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/java/12FromPushToPull/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/java/12FromPushToPull/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | bin
--------------------------------------------------------------------------------
/java/12FromPushToPull/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | 12FromPushToPull
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/java/12FromPushToPull/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=ISO-8859-1
3 |
--------------------------------------------------------------------------------
/java/12FromPushToPull/.settings/org.eclipse.core.runtime.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | line.separator=\r\n
3 |
--------------------------------------------------------------------------------
/java/12FromPushToPull/12FromPushToPull.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/12FromPushToPull/src/pushpull/BalancesCalculator.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.List;
4 |
5 | import org.joda.time.LocalDate;
6 |
7 | import common.BalancesOfMonthCalculator_API;
8 | import common.BalancesOfMonth_API;
9 | import common.Transaction_API;
10 |
11 | public class BalancesCalculator implements BalancesOfMonthCalculator_API {
12 |
13 | private final Transactions transactions;
14 |
15 | public BalancesCalculator(List transactions) {
16 | this.transactions = new Transactions(transactions);
17 | }
18 |
19 | @Override
20 | public void fillData(List balancesOfMonthList) {
21 | ValuesOfMonth valuesOfMonth = null;
22 |
23 | for (BalancesOfMonth_API balancesOfMonth : balancesOfMonthList) {
24 | LocalDate dateOfMonth = balancesOfMonth.getDate();
25 | List transactionsOfMonth = transactions.transactionsOfMonth(dateOfMonth);
26 |
27 | valuesOfMonth = new ValuesOfMonth(valuesOfMonth == null ? new InitialValuesOfMonth() : valuesOfMonth, dateOfMonth,
28 | transactionsOfMonth);
29 |
30 | balancesOfMonth.setBalance(valuesOfMonth.getBalance());
31 | balancesOfMonth.setAverageBalance(valuesOfMonth.getAverageBalance());
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/java/12FromPushToPull/src/pushpull/IValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | public interface IValuesOfMonth {
4 |
5 | int getBalance();
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/java/12FromPushToPull/src/pushpull/InitialValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | public class InitialValuesOfMonth implements IValuesOfMonth {
4 |
5 | @Override
6 | public int getBalance() {
7 | return 0;
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/java/12FromPushToPull/src/pushpull/Transactions.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.joda.time.LocalDate;
7 |
8 | import common.Transaction_API;
9 |
10 | public class Transactions {
11 |
12 | private final List transactions;
13 |
14 | public Transactions(List transactions) {
15 | this.transactions = transactions;
16 | }
17 |
18 | List transactionsOfMonth(LocalDate date) {
19 | List results = new ArrayList();
20 | for (Transaction_API transaction : transactions) {
21 | LocalDate dateOfTransaction = transaction.getDate();
22 | if (areSameMonthAndYear(date, dateOfTransaction)) {
23 | results.add(transaction);
24 | }
25 | }
26 | return results;
27 | }
28 |
29 | private boolean areSameMonthAndYear(LocalDate date, LocalDate dateOfTransaction) {
30 | return dateOfTransaction.getMonthOfYear() == date.getMonthOfYear() && dateOfTransaction.getYear() == date.getYear();
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/java/12FromPushToPull/src/pushpull/ValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.List;
4 |
5 | import org.joda.time.LocalDate;
6 |
7 | import common.Transaction_API;
8 |
9 | public class ValuesOfMonth implements IValuesOfMonth {
10 | private final LocalDate dateOfMonth;
11 | private final List transactionsOfMonth;
12 | private final IValuesOfMonth precedingMonth;
13 |
14 | public ValuesOfMonth(IValuesOfMonth precedingMonth, LocalDate dateOfMonth,
15 | List transactionsOfMonth) {
16 | this.dateOfMonth = dateOfMonth;
17 | this.transactionsOfMonth = transactionsOfMonth;
18 | this.precedingMonth = precedingMonth;
19 | }
20 |
21 | @Override
22 | public int getBalance() {
23 | int balance = precedingMonth.getBalance();
24 | for (Transaction_API transaction : transactionsOfMonth) {
25 | balance += transaction.getAmount();
26 | }
27 | return balance;
28 | }
29 |
30 | public int getAverageBalance() {
31 | int balance = precedingMonth.getBalance();
32 | int ultimo = dateOfMonth.getDayOfMonth();
33 |
34 | double averageBalance = 0;
35 | int dayOfLatestBalance = 1;
36 | for (Transaction_API transaction : transactionsOfMonth) {
37 | int day = transaction.getDate().getDayOfMonth();
38 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, day, ultimo);
39 | balance += transaction.getAmount();
40 | dayOfLatestBalance = day;
41 | }
42 |
43 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, ultimo + 1, ultimo);
44 |
45 | return (int) averageBalance;
46 | }
47 |
48 | private double calculateProportionalBalance(int dayOfLatestBalance, int balance, int day, int daysInMonth) {
49 | int countingDays = day - dayOfLatestBalance;
50 | if (countingDays == 0) {
51 | return 0;
52 | }
53 | double rate = (double) countingDays / daysInMonth;
54 | return (balance * rate);
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/java/12FromPushToPull/test/pushpull/PushPullTest.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import org.junit.Before;
4 |
5 | import common.CalculatorTest;
6 | import pushpull.BalancesCalculator;
7 |
8 | public class PushPullTest extends CalculatorTest {
9 |
10 | @Before
11 | public void setup() {
12 | calculator = new BalancesCalculator(transactions);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/java/13FromPushToPull/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/java/13FromPushToPull/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | bin
--------------------------------------------------------------------------------
/java/13FromPushToPull/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | 13FromPushToPull
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/java/13FromPushToPull/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=ISO-8859-1
3 |
--------------------------------------------------------------------------------
/java/13FromPushToPull/.settings/org.eclipse.core.runtime.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | line.separator=\r\n
3 |
--------------------------------------------------------------------------------
/java/13FromPushToPull/13FromPushToPull.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/13FromPushToPull/src/pushpull/BalancesCalculator.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | import org.joda.time.LocalDate;
8 |
9 | import common.BalancesOfMonthCalculator_API;
10 | import common.BalancesOfMonth_API;
11 | import common.Transaction_API;
12 |
13 | public class BalancesCalculator implements BalancesOfMonthCalculator_API {
14 |
15 | private final Transactions transactions;
16 |
17 | private final Map months = new HashMap();
18 |
19 | public BalancesCalculator(List transactions) {
20 | this.transactions = new Transactions(transactions);
21 | }
22 |
23 | @Override
24 | public void fillData(List balancesOfMonthList) {
25 | ValuesOfMonth valuesOfMonth = null;
26 | for (BalancesOfMonth_API balancesOfMonth : balancesOfMonthList) {
27 | LocalDate dateOfMonth = balancesOfMonth.getDate();
28 | List transactionsOfMonth = transactions.transactionsOfMonth(dateOfMonth);
29 |
30 | valuesOfMonth = new ValuesOfMonth(valuesOfMonth == null ? new InitialValuesOfMonth() : valuesOfMonth, dateOfMonth,
31 | transactionsOfMonth);
32 | months.put(dateOfMonth, valuesOfMonth);
33 | }
34 |
35 | for (BalancesOfMonth_API balancesOfMonth : balancesOfMonthList) {
36 | LocalDate dateOfMonth = balancesOfMonth.getDate();
37 |
38 | balancesOfMonth.setBalance(months.get(dateOfMonth).getBalance());
39 | balancesOfMonth.setAverageBalance(months.get(dateOfMonth).getAverageBalance());
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/java/13FromPushToPull/src/pushpull/IValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | public interface IValuesOfMonth {
4 |
5 | int getBalance();
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/java/13FromPushToPull/src/pushpull/InitialValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | public class InitialValuesOfMonth implements IValuesOfMonth {
4 |
5 | @Override
6 | public int getBalance() {
7 | return 0;
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/java/13FromPushToPull/src/pushpull/Transactions.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.joda.time.LocalDate;
7 |
8 | import common.Transaction_API;
9 |
10 | public class Transactions {
11 |
12 | private final List transactions;
13 |
14 | public Transactions(List transactions) {
15 | this.transactions = transactions;
16 | }
17 |
18 | List transactionsOfMonth(LocalDate date) {
19 | List results = new ArrayList();
20 | for (Transaction_API transaction : transactions) {
21 | LocalDate dateOfTransaction = transaction.getDate();
22 | if (areSameMonthAndYear(date, dateOfTransaction)) {
23 | results.add(transaction);
24 | }
25 | }
26 | return results;
27 | }
28 |
29 | private boolean areSameMonthAndYear(LocalDate date, LocalDate dateOfTransaction) {
30 | return dateOfTransaction.getMonthOfYear() == date.getMonthOfYear() && dateOfTransaction.getYear() == date.getYear();
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/java/13FromPushToPull/src/pushpull/ValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.List;
4 |
5 | import org.joda.time.LocalDate;
6 |
7 | import common.Transaction_API;
8 |
9 | public class ValuesOfMonth implements IValuesOfMonth {
10 | private final LocalDate dateOfMonth;
11 | private final List transactionsOfMonth;
12 | private final IValuesOfMonth precedingMonth;
13 |
14 | public ValuesOfMonth(IValuesOfMonth precedingMonth, LocalDate dateOfMonth,
15 | List transactionsOfMonth) {
16 | this.dateOfMonth = dateOfMonth;
17 | this.transactionsOfMonth = transactionsOfMonth;
18 | this.precedingMonth = precedingMonth;
19 | }
20 |
21 | @Override
22 | public int getBalance() {
23 | int balance = precedingMonth.getBalance();
24 | for (Transaction_API transaction : transactionsOfMonth) {
25 | balance += transaction.getAmount();
26 | }
27 | return balance;
28 | }
29 |
30 | public int getAverageBalance() {
31 | int balance = precedingMonth.getBalance();
32 | int ultimo = dateOfMonth.getDayOfMonth();
33 |
34 | double averageBalance = 0;
35 | int dayOfLatestBalance = 1;
36 | for (Transaction_API transaction : transactionsOfMonth) {
37 | int day = transaction.getDate().getDayOfMonth();
38 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, day, ultimo);
39 | balance += transaction.getAmount();
40 | dayOfLatestBalance = day;
41 | }
42 |
43 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, ultimo + 1, ultimo);
44 |
45 | return (int) averageBalance;
46 | }
47 |
48 | private double calculateProportionalBalance(int dayOfLatestBalance, int balance, int day, int daysInMonth) {
49 | int countingDays = day - dayOfLatestBalance;
50 | if (countingDays == 0) {
51 | return 0;
52 | }
53 | double rate = (double) countingDays / daysInMonth;
54 | return (balance * rate);
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/java/13FromPushToPull/test/pushpull/PushPullTest.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import org.junit.Before;
4 |
5 | import common.CalculatorTest;
6 | import pushpull.BalancesCalculator;
7 |
8 | public class PushPullTest extends CalculatorTest {
9 |
10 | @Before
11 | public void setup() {
12 | calculator = new BalancesCalculator(transactions);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/java/14FromPushToPull/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/java/14FromPushToPull/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | bin
--------------------------------------------------------------------------------
/java/14FromPushToPull/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | 14FromPushToPull
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/java/14FromPushToPull/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=ISO-8859-1
3 |
--------------------------------------------------------------------------------
/java/14FromPushToPull/.settings/org.eclipse.core.runtime.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | line.separator=\r\n
3 |
--------------------------------------------------------------------------------
/java/14FromPushToPull/14FromPushToPull.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/14FromPushToPull/src/pushpull/BalancesCalculator.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.List;
4 |
5 | import common.BalancesOfMonthCalculator_API;
6 | import common.BalancesOfMonth_API;
7 | import common.Transaction_API;
8 |
9 | public class BalancesCalculator implements BalancesOfMonthCalculator_API {
10 |
11 | private final Transactions transactions;
12 |
13 | public BalancesCalculator(List transactions) {
14 | this.transactions = new Transactions(transactions);
15 | }
16 |
17 | @Override
18 | public void fillData(List balancesOfMonthList) {
19 | Months months = new Months(balancesOfMonthList, transactions);
20 |
21 | for (BalancesOfMonth_API balancesOfMonth : balancesOfMonthList) {
22 | ValuesOfMonth currentMonth = months.monthFor(balancesOfMonth.getDate());
23 | balancesOfMonth.setBalance(currentMonth.getBalance());
24 | balancesOfMonth.setAverageBalance(currentMonth.getAverageBalance());
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/java/14FromPushToPull/src/pushpull/IValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | public interface IValuesOfMonth {
4 |
5 | int getBalance();
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/java/14FromPushToPull/src/pushpull/InitialValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | public class InitialValuesOfMonth implements IValuesOfMonth {
4 |
5 | @Override
6 | public int getBalance() {
7 | return 0;
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/java/14FromPushToPull/src/pushpull/Months.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | import org.joda.time.LocalDate;
8 |
9 | import common.BalancesOfMonth_API;
10 | import common.Transaction_API;
11 |
12 | public class Months {
13 |
14 | private final Map months = new HashMap();
15 |
16 | public Months(List balancesOfMonthList, Transactions transactions) {
17 | ValuesOfMonth valuesOfMonth = null;
18 | for (BalancesOfMonth_API balancesOfMonth : balancesOfMonthList) {
19 | LocalDate dateOfMonth = balancesOfMonth.getDate();
20 | List transactionsOfMonth = transactions.transactionsOfMonth(dateOfMonth);
21 |
22 | valuesOfMonth = new ValuesOfMonth(valuesOfMonth == null ? new InitialValuesOfMonth() : valuesOfMonth, dateOfMonth,
23 | transactionsOfMonth);
24 | months.put(dateOfMonth, valuesOfMonth);
25 | }
26 | }
27 |
28 | public ValuesOfMonth monthFor(LocalDate dateOfMonth) {
29 | return months.get(dateOfMonth);
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/java/14FromPushToPull/src/pushpull/Transactions.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.joda.time.LocalDate;
7 |
8 | import common.Transaction_API;
9 |
10 | public class Transactions {
11 |
12 | private final List transactions;
13 |
14 | public Transactions(List transactions) {
15 | this.transactions = transactions;
16 | }
17 |
18 | List transactionsOfMonth(LocalDate date) {
19 | List results = new ArrayList();
20 | for (Transaction_API transaction : transactions) {
21 | LocalDate dateOfTransaction = transaction.getDate();
22 | if (areSameMonthAndYear(date, dateOfTransaction)) {
23 | results.add(transaction);
24 | }
25 | }
26 | return results;
27 | }
28 |
29 | private boolean areSameMonthAndYear(LocalDate date, LocalDate dateOfTransaction) {
30 | return dateOfTransaction.getMonthOfYear() == date.getMonthOfYear() && dateOfTransaction.getYear() == date.getYear();
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/java/14FromPushToPull/src/pushpull/ValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.List;
4 |
5 | import org.joda.time.LocalDate;
6 |
7 | import common.Transaction_API;
8 |
9 | public class ValuesOfMonth implements IValuesOfMonth {
10 | private final LocalDate dateOfMonth;
11 | private final List transactionsOfMonth;
12 | private final IValuesOfMonth precedingMonth;
13 |
14 | public ValuesOfMonth(IValuesOfMonth precedingMonth, LocalDate dateOfMonth,
15 | List transactionsOfMonth) {
16 | this.dateOfMonth = dateOfMonth;
17 | this.transactionsOfMonth = transactionsOfMonth;
18 | this.precedingMonth = precedingMonth;
19 | }
20 |
21 | @Override
22 | public int getBalance() {
23 | int balance = precedingMonth.getBalance();
24 | for (Transaction_API transaction : transactionsOfMonth) {
25 | balance += transaction.getAmount();
26 | }
27 | return balance;
28 | }
29 |
30 | public int getAverageBalance() {
31 | int balance = precedingMonth.getBalance();
32 | int ultimo = dateOfMonth.getDayOfMonth();
33 |
34 | double averageBalance = 0;
35 | int dayOfLatestBalance = 1;
36 | for (Transaction_API transaction : transactionsOfMonth) {
37 | int day = transaction.getDate().getDayOfMonth();
38 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, day, ultimo);
39 | balance += transaction.getAmount();
40 | dayOfLatestBalance = day;
41 | }
42 |
43 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, ultimo + 1, ultimo);
44 |
45 | return (int) averageBalance;
46 | }
47 |
48 | private double calculateProportionalBalance(int dayOfLatestBalance, int balance, int day, int daysInMonth) {
49 | int countingDays = day - dayOfLatestBalance;
50 | if (countingDays == 0) {
51 | return 0;
52 | }
53 | double rate = (double) countingDays / daysInMonth;
54 | return (balance * rate);
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/java/14FromPushToPull/test/pushpull/PushPullTest.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import org.junit.Before;
4 |
5 | import common.CalculatorTest;
6 | import pushpull.BalancesCalculator;
7 |
8 | public class PushPullTest extends CalculatorTest {
9 |
10 | @Before
11 | public void setup() {
12 | calculator = new BalancesCalculator(transactions);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/java/15FromPushToPull/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/java/15FromPushToPull/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | bin
--------------------------------------------------------------------------------
/java/15FromPushToPull/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | 15FromPushToPull
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/java/15FromPushToPull/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=ISO-8859-1
3 |
--------------------------------------------------------------------------------
/java/15FromPushToPull/.settings/org.eclipse.core.runtime.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | line.separator=\r\n
3 |
--------------------------------------------------------------------------------
/java/15FromPushToPull/15FromPushToPull.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/15FromPushToPull/src/pushpull/BalancesCalculator.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.List;
4 |
5 | import common.BalancesOfMonthCalculator_API;
6 | import common.BalancesOfMonth_API;
7 | import common.Transaction_API;
8 |
9 | public class BalancesCalculator implements BalancesOfMonthCalculator_API {
10 |
11 | private final Transactions transactions;
12 |
13 | public BalancesCalculator(List transactions) {
14 | this.transactions = new Transactions(transactions);
15 | }
16 |
17 | @Override
18 | public void fillData(List balancesOfMonthList) {
19 | Months months = new Months(balancesOfMonthList, transactions);
20 |
21 | for (BalancesOfMonth_API balancesOfMonth : balancesOfMonthList) {
22 | ValuesOfMonth currentMonth = months.monthFor(balancesOfMonth.getDate());
23 | balancesOfMonth.setBalance(currentMonth.getBalance());
24 | balancesOfMonth.setAverageBalance(currentMonth.getAverageBalance());
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/java/15FromPushToPull/src/pushpull/IValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | public interface IValuesOfMonth {
4 |
5 | int getBalance();
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/java/15FromPushToPull/src/pushpull/InitialValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | public class InitialValuesOfMonth implements IValuesOfMonth {
4 |
5 | @Override
6 | public int getBalance() {
7 | return 0;
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/java/15FromPushToPull/src/pushpull/Months.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | import org.joda.time.LocalDate;
8 |
9 | import common.BalancesOfMonth_API;
10 | import common.Transaction_API;
11 |
12 | public class Months {
13 |
14 | private final Map months = new HashMap();
15 |
16 | public Months(List balancesOfMonthList, Transactions transactions) {
17 | ValuesOfMonth valuesOfMonth = null;
18 | for (BalancesOfMonth_API balancesOfMonth : balancesOfMonthList) {
19 | LocalDate dateOfMonth = balancesOfMonth.getDate();
20 | List transactionsOfMonth = transactions.transactionsOfMonth(dateOfMonth);
21 |
22 | valuesOfMonth = new ValuesOfMonthWithCaching(valuesOfMonth == null ? new InitialValuesOfMonth() : valuesOfMonth,
23 | dateOfMonth, transactionsOfMonth);
24 | months.put(dateOfMonth, valuesOfMonth);
25 | }
26 | }
27 |
28 | public ValuesOfMonth monthFor(LocalDate dateOfMonth) {
29 | return months.get(dateOfMonth);
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/java/15FromPushToPull/src/pushpull/Transactions.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.joda.time.LocalDate;
7 |
8 | import common.Transaction_API;
9 |
10 | public class Transactions {
11 |
12 | private final List transactions;
13 |
14 | public Transactions(List transactions) {
15 | this.transactions = transactions;
16 | }
17 |
18 | List transactionsOfMonth(LocalDate date) {
19 | List results = new ArrayList();
20 | for (Transaction_API transaction : transactions) {
21 | LocalDate dateOfTransaction = transaction.getDate();
22 | if (areSameMonthAndYear(date, dateOfTransaction)) {
23 | results.add(transaction);
24 | }
25 | }
26 | return results;
27 | }
28 |
29 | private boolean areSameMonthAndYear(LocalDate date, LocalDate dateOfTransaction) {
30 | return dateOfTransaction.getMonthOfYear() == date.getMonthOfYear() && dateOfTransaction.getYear() == date.getYear();
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/java/15FromPushToPull/src/pushpull/ValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.List;
4 |
5 | import org.joda.time.LocalDate;
6 |
7 | import common.Transaction_API;
8 |
9 | public class ValuesOfMonth implements IValuesOfMonth {
10 | private final LocalDate dateOfMonth;
11 | private final List transactionsOfMonth;
12 | private final IValuesOfMonth precedingMonth;
13 |
14 | public ValuesOfMonth(IValuesOfMonth precedingMonth, LocalDate dateOfMonth,
15 | List transactionsOfMonth) {
16 | this.dateOfMonth = dateOfMonth;
17 | this.transactionsOfMonth = transactionsOfMonth;
18 | this.precedingMonth = precedingMonth;
19 | }
20 |
21 | @Override
22 | public int getBalance() {
23 | int balance = precedingMonth.getBalance();
24 | for (Transaction_API transaction : transactionsOfMonth) {
25 | balance += transaction.getAmount();
26 | }
27 | return balance;
28 | }
29 |
30 | public int getAverageBalance() {
31 | int balance = precedingMonth.getBalance();
32 | int ultimo = dateOfMonth.getDayOfMonth();
33 |
34 | double averageBalance = 0;
35 | int dayOfLatestBalance = 1;
36 | for (Transaction_API transaction : transactionsOfMonth) {
37 | int day = transaction.getDate().getDayOfMonth();
38 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, day, ultimo);
39 | balance += transaction.getAmount();
40 | dayOfLatestBalance = day;
41 | }
42 |
43 | averageBalance += calculateProportionalBalance(dayOfLatestBalance, balance, ultimo + 1, ultimo);
44 |
45 | return (int) averageBalance;
46 | }
47 |
48 | private double calculateProportionalBalance(int dayOfLatestBalance, int balance, int day, int daysInMonth) {
49 | int countingDays = day - dayOfLatestBalance;
50 | if (countingDays == 0) {
51 | return 0;
52 | }
53 | double rate = (double) countingDays / daysInMonth;
54 | return (balance * rate);
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/java/15FromPushToPull/src/pushpull/ValuesOfMonthWithCaching.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.List;
4 |
5 | import org.joda.time.LocalDate;
6 |
7 | import common.Transaction_API;
8 |
9 | public class ValuesOfMonthWithCaching extends ValuesOfMonth {
10 |
11 | private Integer balanceLazy = null;
12 | private Integer averageBalanceLazy = null;
13 |
14 | public ValuesOfMonthWithCaching(IValuesOfMonth precedingMonth, LocalDate dateOfMonth,
15 | List transactionsOfMonth) {
16 | super(precedingMonth, dateOfMonth, transactionsOfMonth);
17 | }
18 |
19 | @Override
20 | public int getBalance() {
21 | if (balanceLazy == null) {
22 | balanceLazy = Integer.valueOf(super.getBalance());
23 | }
24 | return balanceLazy.intValue();
25 | }
26 |
27 | @Override
28 | public int getAverageBalance() {
29 | if (averageBalanceLazy == null) {
30 | averageBalanceLazy = Integer.valueOf(super.getAverageBalance());
31 | }
32 | return averageBalanceLazy.intValue();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/java/15FromPushToPull/test/pushpull/PushPullTest.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import org.junit.Before;
4 |
5 | import common.CalculatorTest;
6 | import pushpull.BalancesCalculator;
7 |
8 | public class PushPullTest extends CalculatorTest {
9 |
10 | @Before
11 | public void setup() {
12 | calculator = new BalancesCalculator(transactions);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/java/16FromPushToPull/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/java/16FromPushToPull/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | bin
--------------------------------------------------------------------------------
/java/16FromPushToPull/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16FromPushToPull
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/java/16FromPushToPull/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=ISO-8859-1
3 |
--------------------------------------------------------------------------------
/java/16FromPushToPull/.settings/org.eclipse.core.runtime.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | line.separator=\r\n
3 |
--------------------------------------------------------------------------------
/java/16FromPushToPull/16FromPushToPull.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/java/16FromPushToPull/src/pushpull/BalancesCalculator.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.List;
4 |
5 | import common.BalancesOfMonthCalculator_API;
6 | import common.BalancesOfMonth_API;
7 | import common.Transaction_API;
8 |
9 | public class BalancesCalculator implements BalancesOfMonthCalculator_API {
10 |
11 | private final Transactions transactions;
12 |
13 | public BalancesCalculator(List transactions) {
14 | this.transactions = new Transactions(transactions);
15 | }
16 |
17 | @Override
18 | public void fillData(List balancesOfMonthList) {
19 | Months months = new Months(balancesOfMonthList, transactions);
20 |
21 | for (BalancesOfMonth_API balancesOfMonth : balancesOfMonthList) {
22 | ValuesOfMonth currentMonth = months.monthFor(balancesOfMonth.getDate());
23 | balancesOfMonth.setBalance(currentMonth.getBalance());
24 | balancesOfMonth.setAverageBalance(currentMonth.getAverageBalance());
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/java/16FromPushToPull/src/pushpull/IValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | public interface IValuesOfMonth {
4 |
5 | int getBalance();
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/java/16FromPushToPull/src/pushpull/InitialValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | public class InitialValuesOfMonth implements IValuesOfMonth {
4 |
5 | @Override
6 | public int getBalance() {
7 | return 0;
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/java/16FromPushToPull/src/pushpull/Months.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | import org.joda.time.LocalDate;
8 |
9 | import common.BalancesOfMonth_API;
10 | import common.Transaction_API;
11 |
12 | public class Months {
13 |
14 | private final Map months = new HashMap();
15 |
16 | public Months(List balancesOfMonthList, Transactions transactions) {
17 | ValuesOfMonth valuesOfMonth = null;
18 | for (BalancesOfMonth_API balancesOfMonth : balancesOfMonthList) {
19 | LocalDate dateOfMonth = balancesOfMonth.getDate();
20 | List transactionsOfMonth = transactions.transactionsOfMonth(dateOfMonth);
21 |
22 | valuesOfMonth = new ValuesOfMonthWithCaching(valuesOfMonth == null ? new InitialValuesOfMonth() : valuesOfMonth,
23 | dateOfMonth, transactionsOfMonth);
24 | months.put(dateOfMonth, valuesOfMonth);
25 | }
26 | }
27 |
28 | public ValuesOfMonth monthFor(LocalDate dateOfMonth) {
29 | return months.get(dateOfMonth);
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/java/16FromPushToPull/src/pushpull/Transactions.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.joda.time.LocalDate;
7 |
8 | import common.Transaction_API;
9 |
10 | public class Transactions {
11 |
12 | private final List transactions;
13 |
14 | public Transactions(List transactions) {
15 | this.transactions = transactions;
16 | }
17 |
18 | List transactionsOfMonth(LocalDate date) {
19 | List results = new ArrayList();
20 | for (Transaction_API transaction : transactions) {
21 | LocalDate dateOfTransaction = transaction.getDate();
22 | if (areSameMonthAndYear(date, dateOfTransaction)) {
23 | results.add(transaction);
24 | }
25 | }
26 | return results;
27 | }
28 |
29 | private boolean areSameMonthAndYear(LocalDate date, LocalDate dateOfTransaction) {
30 | return dateOfTransaction.getMonthOfYear() == date.getMonthOfYear() && dateOfTransaction.getYear() == date.getYear();
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/java/16FromPushToPull/src/pushpull/ValuesOfMonth.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.List;
4 |
5 | import org.joda.time.LocalDate;
6 | import org.joda.time.chrono.ISOChronology;
7 |
8 | import common.Transaction_API;
9 |
10 | public class ValuesOfMonth implements IValuesOfMonth {
11 | private final LocalDate dateOfMonth;
12 | private final List transactionsOfMonth;
13 | private final IValuesOfMonth precedingMonth;
14 |
15 | public ValuesOfMonth(IValuesOfMonth precedingMonth, LocalDate dateOfMonth,
16 | List transactionsOfMonth) {
17 | this.dateOfMonth = dateOfMonth;
18 | this.transactionsOfMonth = transactionsOfMonth;
19 | this.precedingMonth = precedingMonth;
20 | }
21 |
22 | @Override
23 | public int getBalance() {
24 | int balance = precedingMonth.getBalance();
25 | for (Transaction_API transaction : transactionsOfMonth) {
26 | balance += transaction.getAmount();
27 | }
28 | return balance;
29 | }
30 |
31 | public int getAverageBalance() {
32 | int result = precedingMonth.getBalance();
33 | for (Transaction_API transaction : transactionsOfMonth) {
34 | result += calculateProportion(transaction);
35 | }
36 | return result;
37 | }
38 |
39 | private double calculateProportion(Transaction_API transaction) {
40 | int coveredDays = daysInMonth() - transaction.getDate().getDayOfMonth() + 1;
41 | double rate = (double) coveredDays / daysInMonth();
42 | return (transaction.getAmount() * rate);
43 | }
44 |
45 | private int daysInMonth() {
46 | return ISOChronology.getInstance().dayOfMonth().getMaximumValue(dateOfMonth);
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/java/16FromPushToPull/src/pushpull/ValuesOfMonthWithCaching.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import java.util.List;
4 |
5 | import org.joda.time.LocalDate;
6 |
7 | import common.Transaction_API;
8 |
9 | public class ValuesOfMonthWithCaching extends ValuesOfMonth {
10 |
11 | private Integer balanceLazy = null;
12 | private Integer averageBalanceLazy = null;
13 |
14 | public ValuesOfMonthWithCaching(IValuesOfMonth precedingMonth, LocalDate dateOfMonth,
15 | List transactionsOfMonth) {
16 | super(precedingMonth, dateOfMonth, transactionsOfMonth);
17 | }
18 |
19 | @Override
20 | public int getBalance() {
21 | if (balanceLazy == null) {
22 | balanceLazy = Integer.valueOf(super.getBalance());
23 | }
24 | return balanceLazy.intValue();
25 | }
26 |
27 | @Override
28 | public int getAverageBalance() {
29 | if (averageBalanceLazy == null) {
30 | averageBalanceLazy = Integer.valueOf(super.getAverageBalance());
31 | }
32 | return averageBalanceLazy.intValue();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/java/16FromPushToPull/test/pushpull/PushPullTest.java:
--------------------------------------------------------------------------------
1 | package pushpull;
2 |
3 | import org.junit.Before;
4 |
5 | import common.CalculatorTest;
6 | import pushpull.BalancesCalculator;
7 |
8 | public class PushPullTest extends CalculatorTest {
9 |
10 | @Before
11 | public void setup() {
12 | calculator = new BalancesCalculator(transactions);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/java/Common/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/java/Common/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | bin
3 |
--------------------------------------------------------------------------------
/java/Common/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Common
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/java/Common/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=ISO-8859-1
3 |
--------------------------------------------------------------------------------
/java/Common/.settings/org.eclipse.core.runtime.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | line.separator=\r\n
3 |
--------------------------------------------------------------------------------
/java/Common/.settings/org.eclipse.jdt.ui.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
3 | formatter_profile=_Legacy
4 | formatter_settings_version=12
5 | sp_cleanup.add_default_serial_version_id=true
6 | sp_cleanup.add_generated_serial_version_id=false
7 | sp_cleanup.add_missing_annotations=true
8 | sp_cleanup.add_missing_deprecated_annotations=true
9 | sp_cleanup.add_missing_methods=false
10 | sp_cleanup.add_missing_nls_tags=false
11 | sp_cleanup.add_missing_override_annotations=true
12 | sp_cleanup.add_missing_override_annotations_interface_methods=true
13 | sp_cleanup.add_serial_version_id=false
14 | sp_cleanup.always_use_blocks=true
15 | sp_cleanup.always_use_parentheses_in_expressions=false
16 | sp_cleanup.always_use_this_for_non_static_field_access=false
17 | sp_cleanup.always_use_this_for_non_static_method_access=false
18 | sp_cleanup.convert_to_enhanced_for_loop=false
19 | sp_cleanup.correct_indentation=false
20 | sp_cleanup.format_source_code=true
21 | sp_cleanup.format_source_code_changes_only=false
22 | sp_cleanup.make_local_variable_final=false
23 | sp_cleanup.make_parameters_final=false
24 | sp_cleanup.make_private_fields_final=true
25 | sp_cleanup.make_type_abstract_if_missing_method=false
26 | sp_cleanup.make_variable_declarations_final=true
27 | sp_cleanup.never_use_blocks=false
28 | sp_cleanup.never_use_parentheses_in_expressions=true
29 | sp_cleanup.on_save_use_additional_actions=true
30 | sp_cleanup.organize_imports=true
31 | sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
32 | sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
33 | sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
34 | sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
35 | sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
36 | sp_cleanup.remove_private_constructors=true
37 | sp_cleanup.remove_trailing_whitespaces=false
38 | sp_cleanup.remove_trailing_whitespaces_all=true
39 | sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
40 | sp_cleanup.remove_unnecessary_casts=true
41 | sp_cleanup.remove_unnecessary_nls_tags=false
42 | sp_cleanup.remove_unused_imports=false
43 | sp_cleanup.remove_unused_local_variables=false
44 | sp_cleanup.remove_unused_private_fields=true
45 | sp_cleanup.remove_unused_private_members=false
46 | sp_cleanup.remove_unused_private_methods=true
47 | sp_cleanup.remove_unused_private_types=true
48 | sp_cleanup.sort_members=false
49 | sp_cleanup.sort_members_all=false
50 | sp_cleanup.use_blocks=false
51 | sp_cleanup.use_blocks_only_for_return_and_throw=false
52 | sp_cleanup.use_parentheses_in_expressions=false
53 | sp_cleanup.use_this_for_non_static_field_access=false
54 | sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
55 | sp_cleanup.use_this_for_non_static_method_access=false
56 | sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
57 |
--------------------------------------------------------------------------------
/java/Common/Common.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/java/Common/lib/hamcrest-core-1.3.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/java/Common/lib/hamcrest-core-1.3.jar
--------------------------------------------------------------------------------
/java/Common/lib/joda-time-2.1-javadoc.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/java/Common/lib/joda-time-2.1-javadoc.jar
--------------------------------------------------------------------------------
/java/Common/lib/joda-time-2.1-sources.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/java/Common/lib/joda-time-2.1-sources.jar
--------------------------------------------------------------------------------
/java/Common/lib/joda-time-2.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/java/Common/lib/joda-time-2.1.jar
--------------------------------------------------------------------------------
/java/Common/lib/junit-4.12.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/java/Common/lib/junit-4.12.jar
--------------------------------------------------------------------------------
/java/Common/src/common/BalancesOfMonthCalculator_API.java:
--------------------------------------------------------------------------------
1 | package common;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * we need this interface to simplify testing. @see{BerechnerTest}
7 | */
8 | public interface BalancesOfMonthCalculator_API {
9 |
10 | public abstract void fillData(List balances);
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/java/Common/src/common/BalancesOfMonth_API.java:
--------------------------------------------------------------------------------
1 | package common;
2 |
3 | import org.joda.time.LocalDate;
4 |
5 | public class BalancesOfMonth_API {
6 |
7 | private final LocalDate date;
8 |
9 | private int balance;
10 | private int averageBalance;
11 |
12 | public BalancesOfMonth_API(LocalDate date) {
13 | this.date = date;
14 | }
15 |
16 | public int getBalance() {
17 | return balance;
18 | }
19 |
20 | public int getAverageBalance() {
21 | return averageBalance;
22 | }
23 |
24 | public void setBalance(int balance) {
25 | this.balance = balance;
26 | }
27 |
28 | public void setAverageBalance(int averageBalance) {
29 | this.averageBalance = averageBalance;
30 | }
31 |
32 | public LocalDate getDate() {
33 | return date;
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/java/Common/src/common/Transaction_API.java:
--------------------------------------------------------------------------------
1 | package common;
2 |
3 | import org.joda.time.LocalDate;
4 |
5 | public class Transaction_API {
6 |
7 | private final LocalDate date;
8 | private final int amount;
9 |
10 | public Transaction_API(LocalDate date, int amount) {
11 | this.date = date;
12 | this.amount = amount;
13 | }
14 |
15 | public LocalDate getDate() {
16 | return date;
17 | }
18 |
19 | public int getAmount() {
20 | return amount;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/java/README.md:
--------------------------------------------------------------------------------
1 | # EclipseProjects
2 | This is the accompanying code to the talk.
3 |
4 | ## Structure
5 | The project "Common" is a neccessary prerequisite for all other projects. It contains the shared classes as well as a single regression test. This test is used in all other projects to prove that the overall implementation is still running.
6 |
7 | ## What is it about?
8 | The code gives a simple example of an account. The entries are called "Transaction" (German: Umsatz). The code does not have a relation to an account. It assumes that all entries belong to the same account.
9 |
10 | The code will cluster the entries by month and calculate the balance at the end of the month ("Bestand") and the avarage balance in each month ("Durchschnittsbestand").
11 |
12 | ### How to use the code
13 | The projects show the transformation steps from a typical procedural "push"-style implementation to an object-oriented "pull"-style.
14 |
15 | We start with project "Push". Next we have the numbered projects:
16 |
17 | 1. we start preparing the "extract method" refactoring by introducing a parameter object
18 | 1. we extract the body of the for-loop
19 | 1. we move the method to the parameter object
20 | 1. we slightly change the extracted method by instantiating a new parameter object for each call
21 | 1. we move the method parameters to the constructor
22 | 1. we separate the calculations of each value
23 | 1. we move the logic to the getters, thereby getting rid of their fields
24 | 1. we change the logic of the complicated calculation and add a test for it
25 | 1. ...
26 |
27 | The final code can be seen in project "Pull". Here we added a few more extras. Look around and don't be shy to ask us or comment.
28 |
29 | ## Third party libraries
30 | The code is using [Joda Time](http://joda-time.sourceforge.net/index.html). The library files are inside the lib folder of the "Common" project.
31 |
32 | We are using these classes to not have to hassle with java.util.Date.
33 |
34 |
--------------------------------------------------------------------------------
/slides/.gitignore:
--------------------------------------------------------------------------------
1 | *.aux
2 | *.log
3 | *.nav
4 | *.toc
5 | *.vrb
6 | *.snm
7 | *.out
8 | *~
9 |
--------------------------------------------------------------------------------
/slides/CodeMechanics.graffle:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/slides/CodeMechanics.graffle
--------------------------------------------------------------------------------
/slides/CodeMechanics.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/slides/CodeMechanics.pdf
--------------------------------------------------------------------------------
/slides/Codestruktur.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/slides/Codestruktur.png
--------------------------------------------------------------------------------
/slides/DynamischFein.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/slides/DynamischFein.jpg
--------------------------------------------------------------------------------
/slides/LocalOptimum.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/slides/LocalOptimum.jpg
--------------------------------------------------------------------------------
/slides/beamercolorthemenicole.sty:
--------------------------------------------------------------------------------
1 | \mode
2 |
3 | \definecolor[named]{nicoleDunkelrot}{HTML}{FD2330}
4 |
5 | \setbeamercolor*{structure}{fg=nicoleDunkelrot}
6 | \setbeamercolor*{subtitle}{fg=nicoleDunkelrot}
7 | \setbeamercolor*{author}{parent=normal text}
8 | \setbeamerfont{title}{size=\huge}
9 | \setbeamerfont{subtitle}{size=\Large}
10 | \setbeamerfont{author}{size=\large}
11 | \setbeamerfont{institute}{size=\large}
12 |
13 | \mode
14 |
15 |
--------------------------------------------------------------------------------
/slides/beamerinnerthemenicole.sty:
--------------------------------------------------------------------------------
1 | \mode
2 |
3 | \defbeamertemplate*{title page}{campus}
4 | {
5 | \vskip+3.2cm%
6 | \usebeamercolor[fg]{title}\usebeamerfont{title}\inserttitle%
7 | \\[1em]
8 | \usebeamercolor[fg]{subtitle}\usebeamerfont{subtitle}\insertsubtitle%
9 | \\[3em]
10 | \usebeamercolor[fg]{author}\usebeamerfont{author}\insertauthor%
11 | \\[0.5em]
12 | \usebeamercolor[fg]{institute}\usebeamerfont{institute}\insertinstitute%
13 | }
14 |
15 |
16 | \mode
17 |
18 |
--------------------------------------------------------------------------------
/slides/beamerouterthemenicole.sty:
--------------------------------------------------------------------------------
1 | \mode
2 |
3 | \addtobeamertemplate{frametitle}{\vskip.5cm}{}
4 |
5 | \setbeamersize{text margin left=.5cm,text margin right=.5cm}
6 |
7 | % Kommentar entfernen, um den Hintergrund auf jeder Seite zu haben:
8 | %\usebackgroundtemplate{\includegraphics[width=\paperwidth,height=\paperheight]{background-slide.png}}
9 |
10 | \setbeamertemplate{footline}
11 | {%
12 | }\mode
13 |
14 |
--------------------------------------------------------------------------------
/slides/beramono.sty:
--------------------------------------------------------------------------------
1 | \ProvidesPackage{beramono}[2004/01/31 (WaS)]
2 | \RequirePackage{keyval}
3 | \define@key{Fvm}{scaled}[.9]{%
4 | \def\fvm@Scale{#1}}
5 | \def\ProcessOptionsWithKV#1{%
6 | \let\@tempc\relax
7 | \let\Fvm@tempa\@empty
8 | \@for\CurrentOption:=\@classoptionslist\do{%
9 | \@ifundefined{KV@#1@\CurrentOption}%
10 | {}%
11 | {%
12 | \edef\Fvm@tempa{\Fvm@tempa,\CurrentOption,}%
13 | \@expandtwoargs\@removeelement\CurrentOption
14 | \@unusedoptionlist\@unusedoptionlist
15 | }%
16 | }%
17 | \edef\Fvm@tempa{%
18 | \noexpand\setkeys{#1}{%
19 | \Fvm@tempa\@ptionlist{\@currname.\@currext}%
20 | }%
21 | }%
22 | \Fvm@tempa
23 | \let\CurrentOption\@empty
24 | }
25 | \ProcessOptionsWithKV{Fvm}
26 | \AtEndOfPackage{%
27 | \let\@unprocessedoptions\relax
28 | }
29 | \renewcommand{\ttdefault}{fvm}
30 | \endinput
31 | %%
32 | %% End of file `beramono.sty'.
33 |
--------------------------------------------------------------------------------
/slides/folien.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/slides/folien.pdf
--------------------------------------------------------------------------------
/slides/folien.tex:
--------------------------------------------------------------------------------
1 | \documentclass[utf8]{beamer}
2 | \usecolortheme{seagull}
3 | \usecolortheme{nicole}
4 | \useinnertheme{nicole}
5 | \useoutertheme{nicole}
6 | \setbeamertemplate{navigation symbols}{}
7 | \setbeamercovered{dynamic}
8 |
9 | \AtBeginPart{\frame{\partpage}}
10 |
11 | \author{~}
12 | \title{Restructuring Legacy Code:\\ From ``Big Ball of Mud''\\ To Domain-Driven Design}
13 | \subtitle{~}
14 | \institute{}
15 | \date{}
16 |
17 | \usepackage{ngerman}
18 | %\usepackage[utf8x,utf8]{inputenc}
19 | \usepackage[T1]{fontenc}
20 | \usepackage{textcomp}
21 | \usepackage[scaled=0.82]{beramono} % bitstream vera sans mono
22 |
23 | \usepackage{tikz}
24 | \usetikzlibrary{shapes,backgrounds,mindmap}
25 |
26 | \usepackage{eso-pic}
27 | \makeatletter
28 | \AddToShipoutPicture{%
29 | \begin{tikzpicture}%
30 | % put: x (from left) , y (from bottom)
31 | \put(240,10){\includegraphics[width=4cm]{../../logos/English.png}}%
32 | \end{tikzpicture}%
33 | }
34 | \makeatother
35 |
36 |
37 | \definecolor[named]{keywords}{HTML}{005D35}
38 | \definecolor[named]{comments}{HTML}{808080}
39 | \definecolor[named]{identifiers}{HTML}{FF0000}
40 | \colorlet{blockbackground}{black!10}
41 | \setbeamercolor{blockbackground}{bg=blockbackground}
42 | \definecolor[named]{strings}{HTML}{0000FF}
43 | \usepackage[final]{listings}
44 | \lstset{language=Java,
45 | keywordstyle=\color{keywords},%\bfseries,%RoyalBlue
46 | basicstyle=\footnotesize\ttfamily,
47 | %identifierstyle=\color{identifiers},
48 | commentstyle=\color{comments}\ttfamily\itshape,%Green
49 | stringstyle=\color{strings},
50 | %numbers=left,
51 | %numberstyle=\scriptsize,%\tiny
52 | %stepnumber=1,
53 | %numbersep=8pt,
54 | showstringspaces=false,
55 | breaklines=true,
56 | frameround=ffff,
57 | frame=single,
58 | tabsize=3,
59 | backgroundcolor=\color{blockbackground},
60 | rulecolor=\color{blockbackground},
61 | inputencoding=latin1,
62 | emphstyle=\color{red},
63 | texcl=true,
64 | }
65 |
66 | \begin{document}
67 | {
68 | \usebackgroundtemplate{}
69 | \begin{frame}[t,plain]
70 | \titlepage
71 | \end{frame}
72 | }
73 | \include{contents}
74 | \end{document}
75 |
76 |
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/01-02.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/01-02.jpg
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/02-03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/02-03.png
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/03-04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/03-04.png
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/04-05-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/04-05-1.png
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/04-05-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/04-05-2.png
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/05-06-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/05-06-1.png
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/05-06-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/05-06-2.png
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/06-07-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/06-07-1.png
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/06-07-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/06-07-2.png
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/07-08-1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/07-08-1.jpg
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/07-08-2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/07-08-2.jpg
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/08-09.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/08-09.jpg
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/09-10-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/09-10-1.png
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/09-10-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/09-10-2.png
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/10-11-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/10-11-1.png
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/10-11-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/10-11-2.png
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/11-12-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/11-12-2.png
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/11-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/11-3.png
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/11-4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/11-4.png
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/12-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/12-1.png
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/12-13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/12-13.png
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/13-14-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/13-14-2.png
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/14-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/14-1.png
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/14-15-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/14-15-2.png
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/15-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/15-1.png
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/15-16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/15-16.png
--------------------------------------------------------------------------------
/workshopMaterial/CompareViews/Push-01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/CompareViews/Push-01.png
--------------------------------------------------------------------------------
/workshopMaterial/MikadoTree.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/MikadoTree.pdf
--------------------------------------------------------------------------------
/workshopMaterial/balance.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/balance.jpg
--------------------------------------------------------------------------------
/workshopMaterial/finalAverage.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/finalAverage.jpg
--------------------------------------------------------------------------------
/workshopMaterial/initialAverage.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/initialAverage.jpg
--------------------------------------------------------------------------------
/workshopMaterial/workshopGuide.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopMaterial/workshopGuide.pdf
--------------------------------------------------------------------------------
/workshopProposal/Einreichung AgileDevPractices 30.9.13.rtf:
--------------------------------------------------------------------------------
1 | {\rtf1\ansi\ansicpg1252\cocoartf1187\cocoasubrtf390
2 | {\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\froman\fcharset0 Times-Roman;}
3 | {\colortbl;\red255\green255\blue255;}
4 | \paperw11900\paperh16840\margl1440\margr1440\vieww15920\viewh12060\viewkind0
5 | \pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural
6 |
7 | \f0\fs24 \cf0 Restructuring Code: "From Push to Pull"\
8 | \
9 | This workshop is intended to introduce the participants to a systematic and structured way of performing large restructurings in object-oriented code.\
10 | \
11 | Object-Oriented Design, Refactoring, Restructuring\
12 | \
13 | Nicole Rauch, Andreas Leidig\
14 | \
15 | ------------------------\
16 | \
17 | OO-Design-Workshop: Restructuring Code "From Push to Pull"\
18 | \
19 | \pard\pardeftab720\sa240
20 |
21 | \f1\fs30 \cf0 The restructuring strategy "From Push to Pull" addresses a common coding pattern: Fields in objects are written from multiple locations. The effects: The value of a field at a given time is not clear, and tracking back all the methods that write the field is difficult. We call this way of coding \'93Push\'94 because the code actively pushes its results into some object\'92s fields. The resulting code is rather fragile
22 | \fs24
23 | \fs30 and tends to be buggy.
24 | \fs24 \
25 |
26 | \fs30 Instead, the output values can be calculated on-demand. This way, the algorithms for each value are clearly visible and very descriptional. We call this style \'93Pull\'94 because the values are pulled by other parts of the code. The resulting code has proven to be readable, understandable, testable, changeable and extensible. \
27 | This workshop shows how a large restructuring can be performed in a systematic way. The code becomes object-oriented, with small methods in objects communicating with each other, in one word: the code has become \'93clean code\'94.\
28 | --------------------\
29 | Nicole Rauch is a software developer with a solid background in compiler construction and formal methods. Over the last two years, she worked on the restructuring of large legacy code applications with different technologies. Alongside her occupation as developer, she took part in organizing some self-organized conferences related to agile coaching.\
30 | Andreas Leidig has broad experience in object oriented software development and agile practices. He started programming years ago with Smalltalk and worked as an agile coach for a few years. Nowadays he is developing enterprise software products.\
31 | --------------------\
32 | \
33 | }
--------------------------------------------------------------------------------
/workshopProposal/Softwerkskammer 11.9.13.txt:
--------------------------------------------------------------------------------
1 | OO-Design-Workshop: Restrukturierung von Code "From Push To Pull"
2 |
3 |
4 |
5 | Entwickler finden oft Code vor, der sowohl schwer zu lesen als auch schwer nachzuvollziehen ist. Gleichzeitig bemühen sie sich darum, "Clean Code" zu schreiben, der gewissen Prinzipien folgt, wie z. B. Single Responsibility, Kapselung und Kohärenz. Besonders bei Legacy Code ist dies oft schwer im Code umzusetzen. Es gibt viele Informationen darüber, wie man kleine Refactorings in Legacy Code durchführen kann, aber es gibt nur sehr wenige Anleitungen, die große Restrukturierungen und Redesigns beschreiben und die eine Vision davon vermitteln, wie der resultierende Code aussehen soll.
6 |
7 |
8 | Unsere Restrukturierungs-Strategie richtet sich auf ein häufiges Codierungsmuster: Die Attribute eines Objekts werden mehrfach an vielen Stellen im Code befüllt. Der Effekt: Es ist nicht klar, welchen Wert ein Attribut zu einem gegebenen Zeitpunkt enthält, und es ist schwierig, alle Codestellen zu finden, die das Attribut befüllen. Es ist auch unklar, wie und wann ein Ergebniswert ermittelt wurde, da es keine isolierte Codestelle gibt, die für die Transformation der Eingabewerte in den Ergebniswert zuständig ist. Isolierte Testbarkeit ist quasi nicht gegeben. Wir nennen dieses Codierungsmuster "Push", da der Code sein Ergebnis aktiv in das Attribut hineinschiebt. Dieses Ergebnis wird prozedural und sequentiell ermittelt. Der resultierende Code ist oft fragil und enthält gern Fehler. Es ist schwierig, den Code zu verändern und zu erweitern, und der Versuch endet oft in einer "Shotgun Surgery", bei der die Änderungen über den gesamten Code verstreut sind.
9 |
10 | Anstatt den "Push"-Stil zu verwenden, können die Ergebniswerte bei Bedarf ermittelt werden, wenn sie benötigt werden. Auf diese Weise sind die Algorithmen für jeden Wert klar erkennbar und sehr deskriptiv. Wir nennen diesen Stil "Pull", weil die Werte von anderen Codeteilen "gezogen" werden. Der resultierende Code hat sich als lesbar, verstehbar, testbar, änderbar und erweiterbar erwiesen.
11 |
12 | Dieser Workshop will anhand eines konkreten Beispiels vermitteln, wie eine große Restrukturierung auf systematische, strukturierte und reproduzierbare Art und Weise durchgeführt werden kann, basierend auf kleinen und sicheren Schritten. Wenn die vorgestellte Strategie konsequent durchgeführt wird, folgt der resultierende Code den oben beschriebenen Prinzipien und wird objektorientiert, mit kleinen Methoden in miteinander kommunizierenden Objekten, in einem Wort: Der Code wird zu "Clean Code".
13 |
14 | Voraussetzungen für die Teilnehmer: Java, Git und eine Java IDE. Pro Paar muss ein Laptop vorhanden sein, idealerweise mit externer Tastatur und Maus.
15 |
16 |
17 |
--------------------------------------------------------------------------------
/workshopProposal/xp2013_workshop_rauch_leidig.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicoleRauch/RefactoringLegacyCode/2ecca1bf67e4bd7ecf55217f2259343872ae8892/workshopProposal/xp2013_workshop_rauch_leidig.pdf
--------------------------------------------------------------------------------