Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
live-coding-fr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Gitlab will be unavailable Friday, April 11 at 12:00 a.m. for an update.
Show more breadcrumbs
twitch
live-coding-fr
Merge requests
!10
Something went wrong on our end
Resolve "Init String calculator project"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Init String calculator project"
11-init-string-calculator-project
into
master
Overview
0
Commits
2
Pipelines
0
Changes
3
Merged
Colin DAMON
requested to merge
11-init-string-calculator-project
into
master
4 years ago
Overview
0
Commits
2
Pipelines
0
Changes
3
Expand
Closes
#11 (closed)
Edited
4 years ago
by
Colin DAMON
0
0
Merge request reports
Viewing commit
95bad854
Prev
Next
Show latest version
3 files
+
134
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
95bad854
Live implementation
· 95bad854
Colin DAMON
authored
4 years ago
stringCalculator/src/main/java/fr/ippon/stringcalculator/Calculator.java
0 → 100644
+
41
−
0
Options
package
fr.ippon.stringcalculator
;
import
java.math.BigDecimal
;
import
java.util.function.BinaryOperator
;
public
class
Calculator
{
public
static
String
sum
(
String
first
,
String
second
)
{
return
operate
(
first
,
second
,
BigDecimal:
:
add
);
}
public
static
String
substract
(
String
first
,
String
second
)
{
return
operate
(
first
,
second
,
BigDecimal:
:
subtract
);
}
private
static
String
operate
(
String
first
,
String
second
,
BinaryOperator
<
BigDecimal
>
operation
)
{
notNull
(
first
);
notNull
(
second
);
return
operation
.
apply
(
toBigDecimal
(
first
),
toBigDecimal
(
second
))
.
toPlainString
();
}
private
static
BigDecimal
toBigDecimal
(
String
value
)
{
if
(
value
.
isBlank
())
{
return
BigDecimal
.
ZERO
;
}
return
new
BigDecimal
(
value
.
replace
(
","
,
"."
));
}
private
static
void
notNull
(
String
first
)
{
if
(
first
==
null
)
{
throw
new
IllegalArgumentException
();
}
}
}
Loading