Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TeeTime-Framework
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nelson Tavares de Sousa
TeeTime-Framework
Commits
aae42993
Commit
aae42993
authored
10 years ago
by
Nelson Tavares de Sousa
Browse files
Options
Downloads
Patches
Plain Diff
added a CountingMap class
parent
a4fd502f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/teetime/stage/DistributedMapCounter.java
+4
-12
4 additions, 12 deletions
src/main/java/teetime/stage/DistributedMapCounter.java
src/main/java/teetime/stage/util/CountingMap.java
+22
-0
22 additions, 0 deletions
src/main/java/teetime/stage/util/CountingMap.java
with
26 additions
and
12 deletions
src/main/java/teetime/stage/DistributedMapCounter.java
+
4
−
12
View file @
aae42993
package
teetime.stage
;
package
teetime.stage
;
import
java.util.HashMap
;
import
java.util.Map
;
import
teetime.framework.AbstractConsumerStage
;
import
teetime.framework.AbstractConsumerStage
;
import
teetime.framework.OutputPort
;
import
teetime.framework.OutputPort
;
import
teetime.stage.util.CountingMap
;
/**
/**
* This counts how many of different elements are sent to this stage. Nothing is forwarded.
* This counts how many of different elements are sent to this stage. Nothing is forwarded.
...
@@ -16,8 +14,8 @@ import teetime.framework.OutputPort;
...
@@ -16,8 +14,8 @@ import teetime.framework.OutputPort;
*/
*/
public
class
DistributedMapCounter
<
T
>
extends
AbstractConsumerStage
<
T
>
{
public
class
DistributedMapCounter
<
T
>
extends
AbstractConsumerStage
<
T
>
{
private
final
Map
<
T
,
Integer
>
counter
=
new
HashMap
<
T
,
Integer
>();
private
final
CountingMap
<
T
>
counter
=
new
CountingMap
<
T
>();
private
final
OutputPort
<
Map
<
T
,
Integer
>>
port
=
createOutputPort
();
private
final
OutputPort
<
CountingMap
<
T
>>
port
=
createOutputPort
();
public
DistributedMapCounter
()
{
public
DistributedMapCounter
()
{
...
@@ -25,13 +23,7 @@ public class DistributedMapCounter<T> extends AbstractConsumerStage<T> {
...
@@ -25,13 +23,7 @@ public class DistributedMapCounter<T> extends AbstractConsumerStage<T> {
@Override
@Override
protected
void
execute
(
final
T
element
)
{
protected
void
execute
(
final
T
element
)
{
if
(
counter
.
containsKey
(
element
))
{
counter
.
increment
(
element
);
Integer
i
=
counter
.
get
(
element
);
i
++;
counter
.
put
(
element
,
i
);
}
else
{
counter
.
put
(
element
,
0
);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/teetime/stage/util/CountingMap.java
0 → 100644
+
22
−
0
View file @
aae42993
package
teetime.stage.util
;
import
java.util.HashMap
;
public
class
CountingMap
<
T
>
extends
HashMap
<
T
,
Integer
>
{
/**
* Generated serialVersionUID
*/
private
static
final
long
serialVersionUID
=
-
8036971796701648200L
;
public
void
increment
(
final
T
key
)
{
if
(
super
.
containsKey
(
key
))
{
Integer
i
=
super
.
get
(
key
);
i
++;
super
.
put
(
key
,
i
);
}
else
{
super
.
put
(
key
,
0
);
}
}
}
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