Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dev-oo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Samuel Turpin
dev-oo
Commits
888d5935
Commit
888d5935
authored
10 months ago
by
Samuel Turpin
Browse files
Options
Downloads
Patches
Plain Diff
td10 générique
parent
67371a73
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/td10/Couple.java
+33
-0
33 additions, 0 deletions
src/td10/Couple.java
src/td10/Duo.java
+102
-0
102 additions, 0 deletions
src/td10/Duo.java
src/td10/Main.java
+36
-0
36 additions, 0 deletions
src/td10/Main.java
with
171 additions
and
0 deletions
src/td10/Couple.java
0 → 100644
+
33
−
0
View file @
888d5935
package
td10
;
public
class
Couple
<
T
,
S
>
{
private
T
first
;
private
S
second
;
public
Couple
(
T
t
,
S
s
)
{
this
.
first
=
t
;
this
.
second
=
s
;
}
public
T
getFirst
()
{
return
this
.
first
;
}
public
S
getSecond
()
{
return
this
.
second
;
}
public
boolean
sameAs
(
Couple
<
T
,
S
>
other
)
{
return
this
.
first
.
equals
(
other
.
first
)
&&
this
.
second
.
equals
(
other
.
second
);
}
public
static
<
T
,
S
>
boolean
sameCouples
(
Couple
<
T
,
S
>
c1
,
Couple
<
T
,
S
>
c2
)
{
return
c1
.
sameAs
(
c2
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/td10/Duo.java
0 → 100644
+
102
−
0
View file @
888d5935
package
td10
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.List
;
/**
* Duo
*/
public
class
Duo
<
E
>
{
private
E
one
;
private
E
two
;
public
Duo
(
E
e1
,
E
e2
)
{
this
.
one
=
e1
;
this
.
two
=
e2
;
}
public
Duo
(
E
e1
)
{
this
(
e1
,
null
);
}
public
E
getFirst
()
{
return
this
.
one
;
}
public
E
getSecond
()
{
return
this
.
two
;
}
public
void
swap
()
{
E
newOne
=
this
.
two
;
E
newSecond
=
this
.
one
;
this
.
one
=
newOne
;
this
.
two
=
newSecond
;
}
public
boolean
identicalElements
()
{
if
(
this
.
one
==
null
&&
this
.
two
==
null
)
{
return
true
;
}
if
(
this
.
one
==
null
)
{
return
false
;
}
return
this
.
one
.
equals
(
this
.
two
);
}
public
boolean
orderedEquals
(
Duo
<
E
>
otherDuo
)
{
return
this
.
one
.
equals
(
otherDuo
.
getFirst
())
&&
this
.
two
.
equals
(
otherDuo
.
getSecond
());
}
public
boolean
reverseEquals
(
Duo
<
E
>
otherDuo
)
{
return
this
.
one
.
equals
(
otherDuo
.
getSecond
())
&&
this
.
two
.
equals
(
otherDuo
.
getFirst
());
}
public
boolean
nonOrderedEquals
(
Duo
<
E
>
otherDuo
)
{
return
this
.
reverseEquals
(
otherDuo
)
||
this
.
orderedEquals
(
otherDuo
);
}
public
static
<
E
>
void
mixDuos
(
Duo
<
E
>
d1
,
Duo
<
E
>
d2
)
{
E
tmp
=
d1
.
one
;
d1
.
one
=
d2
.
two
;
d2
.
two
=
tmp
;
}
public
static
<
E
>
List
<
Duo
<
E
>>
randomDuos
(
List
<
E
>
elements
)
{
Collections
.
shuffle
(
elements
);
List
<
Duo
<
E
>>
duos
=
new
ArrayList
<
Duo
<
E
>>();
while
(
elements
.
size
()
>
1
)
{
duos
.
add
(
new
Duo
<
E
>(
elements
.
remove
(
0
),
elements
.
remove
(
0
)));
}
if
(
elements
.
size
()
==
1
)
{
duos
.
add
(
new
Duo
<
E
>(
elements
.
remove
(
0
)));
}
return
duos
;
}
@Override
public
String
toString
()
{
return
this
.
one
+
" et "
+
this
.
two
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/td10/Main.java
0 → 100644
+
36
−
0
View file @
888d5935
package
td10
;
public
class
Main
{
public
static
void
main
(
String
[]
args
)
{
//testDuos();
testCouple
();
}
private
static
void
testCouple
()
{
Couple
<
String
,
String
>
c1
=
new
Couple
<
String
,
String
>(
"alice"
,
"bruno"
);
Couple
<
String
,
String
>
c2
=
new
Couple
<
String
,
String
>(
"alice"
,
"polo"
);
System
.
out
.
println
(
c1
.
sameAs
(
c2
));
System
.
out
.
println
(
Couple
.
sameCouples
(
c1
,
c2
));
}
private
static
void
testDuos
()
{
Duo
<
String
>
duoStr
=
new
Duo
<
String
>(
"bruno"
,
"alice"
);
System
.
out
.
println
(
duoStr
);
duoStr
.
swap
();
System
.
out
.
println
(
duoStr
);
Duo
<
Boolean
>
duoBool
=
new
Duo
<
Boolean
>(
false
,
true
);
System
.
out
.
println
(
duoBool
);
duoBool
.
swap
();
System
.
out
.
println
(
duoBool
);
Duo
<
Integer
>
d1
=
new
Duo
<
Integer
>(
1
,
2
);
Duo
<
Integer
>
d2
=
new
Duo
<
Integer
>(
2
,
1
);
System
.
out
.
println
(
d1
.
orderedEquals
(
d2
));
System
.
out
.
println
(
d1
.
nonOrderedEquals
(
d2
));
}
}
\ No newline at end of file
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