Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FUCoin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DistributedSystems4Students
FUCoin
Commits
62e143ca
Commit
62e143ca
authored
8 years ago
by
Kim Kern
Browse files
Options
Downloads
Patches
Plain Diff
fix AggregationContextBuilder
parent
cd591a05
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/fucoin/actions/aggregation/AggregationContext.java
+36
-16
36 additions, 16 deletions
...n/java/fucoin/actions/aggregation/AggregationContext.java
with
36 additions
and
16 deletions
src/main/java/fucoin/actions/aggregation/AggregationContext.java
+
36
−
16
View file @
62e143ca
...
...
@@ -39,21 +39,26 @@ public class AggregationContext implements Serializable {
public
AggregationContext
aggregate
(
AggregationContext
neighborContext
)
{
double
[]
aggregatedValues
=
getFunction
().
apply
(
neighborContext
.
getValues
(),
getValues
());
AggregationContext
aggregatedContext
=
new
AggregationContextBuilder
(
getFunction
(),
getValueExtractor
(),
getAltValueExtractor
(),
aggregatedValues
,
resultExtractor
)
.
setCurrentExchanges
(
getCurrentExchanges
()
+
1
)
.
setMaxExchanges
(
getMaxExchanges
())
.
setUuid
(
getUuid
())
.
build
();
AggregationContext
aggregatedContext
=
new
AggregationContextBuilder
(
getFunction
(),
aggregatedValues
)
.
setCurrentExchanges
(
getCurrentExchanges
()
+
1
)
.
setValueExtractor
(
getValueExtractor
())
.
setValueAltExtractor
(
getValueAltExtractor
())
.
setMaxExchanges
(
getMaxExchanges
())
.
setUuid
(
getUuid
())
.
setResultExtractor
(
resultExtractor
)
.
build
();
System
.
out
.
println
(
"Aggregation: "
+
Arrays
.
toString
(
getValues
())
+
" + "
+
Arrays
.
toString
(
neighborContext
.
getValues
())
+
" = "
+
aggregatedValues
);
return
aggregatedContext
;
}
public
AggregationContext
initContext
(
AbstractWallet
wallet
,
boolean
useValueExtractor
)
{
double
[]
initValues
=
useValueExtractor
?
getValueExtractor
().
apply
(
wallet
)
:
get
Alt
ValueExtractor
().
apply
(
wallet
);
AggregationContext
initContext
=
new
AggregationContextBuilder
(
getFunction
(),
getValueExtractor
(),
getAltValueExtractor
(),
initValues
,
resultExtractor
)
double
[]
initValues
=
useValueExtractor
?
getValueExtractor
().
apply
(
wallet
)
:
getValue
Alt
Extractor
().
apply
(
wallet
);
AggregationContext
initContext
=
new
AggregationContextBuilder
(
getFunction
(),
initValues
)
.
setMaxExchanges
(
getMaxExchanges
())
.
setValueExtractor
(
getValueExtractor
())
.
setValueAltExtractor
(
getValueAltExtractor
())
.
setUuid
(
getUuid
())
.
setResultExtractor
(
resultExtractor
)
.
build
();
return
initContext
;
}
...
...
@@ -85,7 +90,7 @@ public class AggregationContext implements Serializable {
return
valueExtractor
;
}
private
Function
<
AbstractWallet
,
double
[]>
get
Alt
ValueExtractor
()
{
private
Function
<
AbstractWallet
,
double
[]>
getValue
Alt
Extractor
()
{
return
valueAltExtractor
;
}
...
...
@@ -104,23 +109,23 @@ public class AggregationContext implements Serializable {
public
static
class
AggregationContextBuilder
{
private
final
AggregationFunction
function
;
private
final
double
[]
values
;
private
final
Function
<
AbstractWallet
,
double
[]>
valueExtractor
;
private
final
Function
<
AbstractWallet
,
double
[]>
valueAltExtractor
;
private
Function
<
AbstractWallet
,
double
[]>
valueExtractor
;
private
Function
<
AbstractWallet
,
double
[]>
valueAltExtractor
;
private
int
currentExchanges
;
private
int
maxExchanges
;
private
UUID
uuid
;
private
Function
<
double
[],
Double
>
resultExtractor
;
public
AggregationContextBuilder
(
AggregationFunction
function
,
Function
<
AbstractWallet
,
double
[]>
valueExtractor
,
Function
<
AbstractWallet
,
double
[]>
valueAltExtractor
,
double
[]
values
,
Function
<
double
[],
Double
>
resultExtractor
)
{
public
AggregationContextBuilder
(
AggregationFunction
function
,
double
[]
values
)
{
this
.
function
=
function
;
this
.
valueExtractor
=
v
al
ueExtractor
;
this
.
valueAltExtractor
=
value
Alt
Extractor
;
this
.
valueExtractor
=
w
al
let
->
new
double
[]
{
wallet
.
getAmount
()
}
;
this
.
valueAltExtractor
=
this
.
valueExtractor
;
this
.
values
=
values
;
this
.
currentExchanges
=
0
;
this
.
maxExchanges
=
20
;
this
.
uuid
=
UUID
.
randomUUID
();
this
.
resultExtractor
=
resultExtractor
;
this
.
resultExtractor
=
valuesArray
->
valuesArray
[
0
]
;
}
public
AggregationContextBuilder
setCurrentExchanges
(
int
currentExchanges
)
{
...
...
@@ -138,6 +143,21 @@ public class AggregationContext implements Serializable {
return
this
;
}
public
AggregationContextBuilder
setResultExtractor
(
Function
<
double
[],
Double
>
resultExtractor
)
{
this
.
resultExtractor
=
resultExtractor
;
return
this
;
}
public
AggregationContextBuilder
setValueExtractor
(
Function
<
AbstractWallet
,
double
[]>
valueExtractor
)
{
this
.
valueExtractor
=
valueExtractor
;
return
this
;
}
public
AggregationContextBuilder
setValueAltExtractor
(
Function
<
AbstractWallet
,
double
[]>
valueAltExtractor
)
{
this
.
valueAltExtractor
=
valueAltExtractor
;
return
this
;
}
public
AggregationContext
build
()
{
return
new
AggregationContext
(
function
,
valueExtractor
,
valueAltExtractor
,
values
,
currentExchanges
,
maxExchanges
,
uuid
,
resultExtractor
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment