Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jvstd1
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
jvstd1
Commits
8fa435ee
Commit
8fa435ee
authored
Oct 16, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
emps.funkcyjnie - początek
parent
23470d07
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
251 additions
and
0 deletions
+251
-0
Employee.java
src/main/java/emps/streamy/Employee.java
+150
-0
ObslugaCSV.java
src/main/java/emps/streamy/ObslugaCSV.java
+38
-0
P0_WypiszObiekty.java
src/main/java/emps/streamy/P0_WypiszObiekty.java
+10
-0
P1_WypiszWybranePola.java
src/main/java/emps/streamy/P1_WypiszWybranePola.java
+24
-0
P2_WypiszBogatych.java
src/main/java/emps/streamy/P2_WypiszBogatych.java
+29
-0
No files found.
src/main/java/emps/streamy/Employee.java
0 → 100644
View file @
8fa435ee
package
emps
.
streamy
;
import
java.time.LocalDate
;
import
java.util.Objects
;
public
class
Employee
{
private
int
employeeId
;
private
String
firstName
;
private
String
lastName
;
private
String
jobTitle
;
private
int
salary
;
private
LocalDate
hireDate
;
private
String
departmentName
;
private
String
address
;
private
String
postalCode
;
private
String
city
;
private
String
country
;
public
Employee
(
int
employeeId
,
String
firstName
,
String
lastName
,
String
jobTitle
,
int
salary
,
LocalDate
hireDate
,
String
departmentName
,
String
address
,
String
postalCode
,
String
city
,
String
country
)
{
this
.
employeeId
=
employeeId
;
this
.
firstName
=
firstName
;
this
.
lastName
=
lastName
;
this
.
jobTitle
=
jobTitle
;
this
.
salary
=
salary
;
this
.
hireDate
=
hireDate
;
this
.
departmentName
=
departmentName
;
this
.
address
=
address
;
this
.
postalCode
=
postalCode
;
this
.
city
=
city
;
this
.
country
=
country
;
}
public
int
getEmployeeId
()
{
return
employeeId
;
}
public
void
setEmployeeId
(
int
employeeId
)
{
this
.
employeeId
=
employeeId
;
}
public
String
getFirstName
()
{
return
firstName
;
}
public
void
setFirstName
(
String
firstName
)
{
this
.
firstName
=
firstName
;
}
public
String
getLastName
()
{
return
lastName
;
}
public
void
setLastName
(
String
lastName
)
{
this
.
lastName
=
lastName
;
}
public
String
getJobTitle
()
{
return
jobTitle
;
}
public
void
setJobTitle
(
String
jobTitle
)
{
this
.
jobTitle
=
jobTitle
;
}
public
int
getSalary
()
{
return
salary
;
}
public
void
setSalary
(
int
salary
)
{
this
.
salary
=
salary
;
}
public
LocalDate
getHireDate
()
{
return
hireDate
;
}
public
void
setHireDate
(
LocalDate
hireDate
)
{
this
.
hireDate
=
hireDate
;
}
public
String
getDepartmentName
()
{
return
departmentName
;
}
public
void
setDepartmentName
(
String
departmentName
)
{
this
.
departmentName
=
departmentName
;
}
public
String
getAddress
()
{
return
address
;
}
public
void
setAddress
(
String
address
)
{
this
.
address
=
address
;
}
public
String
getPostalCode
()
{
return
postalCode
;
}
public
void
setPostalCode
(
String
postalCode
)
{
this
.
postalCode
=
postalCode
;
}
public
String
getCity
()
{
return
city
;
}
public
void
setCity
(
String
city
)
{
this
.
city
=
city
;
}
public
String
getCountry
()
{
return
country
;
}
public
void
setCountry
(
String
country
)
{
this
.
country
=
country
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
Employee
employee
=
(
Employee
)
o
;
return
employeeId
==
employee
.
employeeId
&&
salary
==
employee
.
salary
&&
Objects
.
equals
(
firstName
,
employee
.
firstName
)
&&
Objects
.
equals
(
lastName
,
employee
.
lastName
)
&&
Objects
.
equals
(
jobTitle
,
employee
.
jobTitle
)
&&
Objects
.
equals
(
hireDate
,
employee
.
hireDate
)
&&
Objects
.
equals
(
departmentName
,
employee
.
departmentName
)
&&
Objects
.
equals
(
address
,
employee
.
address
)
&&
Objects
.
equals
(
postalCode
,
employee
.
postalCode
)
&&
Objects
.
equals
(
city
,
employee
.
city
)
&&
Objects
.
equals
(
country
,
employee
.
country
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
employeeId
,
firstName
,
lastName
,
jobTitle
,
salary
,
hireDate
,
departmentName
,
address
,
postalCode
,
city
,
country
);
}
@Override
public
String
toString
()
{
return
"Employee{"
+
"employeeId="
+
employeeId
+
", firstName='"
+
firstName
+
'\''
+
", lastName='"
+
lastName
+
'\''
+
", jobTitle='"
+
jobTitle
+
'\''
+
", salary="
+
salary
+
", hireDate="
+
hireDate
+
", departmentName='"
+
departmentName
+
'\''
+
", address='"
+
address
+
'\''
+
", postalCode='"
+
postalCode
+
'\''
+
", city='"
+
city
+
'\''
+
", country='"
+
country
+
'\''
+
'}'
;
}
}
src/main/java/emps/streamy/ObslugaCSV.java
0 → 100644
View file @
8fa435ee
package
emps
.
streamy
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.time.LocalDate
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Scanner
;
public
class
ObslugaCSV
{
// to jest klasa narzędziowa - tu są tylko metody statyczne
// mogą zakazać tworzenia obiektów tej klasy oznaczając konstruktor jako prywatny
private
ObslugaCSV
()
{
}
public
static
List
<
Employee
>
readCSV
(
File
file
)
throws
FileNotFoundException
{
List
<
Employee
>
emps
=
new
ArrayList
<>();
try
(
Scanner
scanner
=
new
Scanner
(
file
))
{
scanner
.
nextLine
();
while
(
scanner
.
hasNextLine
())
{
String
line
=
scanner
.
nextLine
();
String
[]
fields
=
line
.
split
(
";"
,
-
1
);
Employee
emp
=
new
Employee
(
Integer
.
parseInt
(
fields
[
0
]),
fields
[
1
],
fields
[
2
],
fields
[
3
],
Integer
.
parseInt
(
fields
[
4
]),
LocalDate
.
parse
(
fields
[
5
]),
fields
[
6
],
fields
[
7
],
fields
[
8
],
fields
[
9
],
fields
[
10
]);
emps
.
add
(
emp
);
}
}
return
emps
;
}
public
static
List
<
Employee
>
readCSV
(
String
path
)
throws
FileNotFoundException
{
return
readCSV
(
new
File
(
path
));
}
public
static
List
<
Employee
>
readCSV
()
throws
FileNotFoundException
{
return
readCSV
(
"pliki/emps.csv"
);
}
}
src/main/java/emps/streamy/P0_WypiszObiekty.java
0 → 100644
View file @
8fa435ee
package
emps
.
streamy
;
import
java.io.FileNotFoundException
;
public
class
P0_WypiszObiekty
{
public
static
void
main
(
String
[]
args
)
throws
FileNotFoundException
{
ObslugaCSV
.
readCSV
().
forEach
(
System
.
out
::
println
);
}
}
src/main/java/emps/streamy/P1_WypiszWybranePola.java
0 → 100644
View file @
8fa435ee
package
emps
.
streamy
;
import
java.io.FileNotFoundException
;
import
java.util.List
;
public
class
P1_WypiszWybranePola
{
public
static
void
main
(
String
[]
args
)
throws
FileNotFoundException
{
List
<
Employee
>
emps
=
ObslugaCSV
.
readCSV
();
System
.
out
.
println
(
"Wczytano "
+
emps
.
size
()
+
" rekordów."
);
// emps.forEach(emp -> System.out.println(emp.getFirstName()
// + " " + emp.getLastName() + " zarabia " + emp.getSalary()));
// Też OK:
// emps.stream()
// .forEach(emp -> System.out.println(emp.getFirstName()
// + " " + emp.getLastName() + " zarabia " + emp.getSalary()));
emps
.
stream
()
.
map
(
emp
->
emp
.
getFirstName
()
+
" "
+
emp
.
getLastName
()
+
" zarabia "
+
emp
.
getSalary
())
.
forEach
(
System
.
out
::
println
);
}
}
src/main/java/emps/streamy/P2_WypiszBogatych.java
0 → 100644
View file @
8fa435ee
package
emps
.
streamy
;
import
java.io.FileNotFoundException
;
import
java.util.List
;
public
class
P2_WypiszBogatych
{
public
static
final
int
GRANICA_ZAROBKOW
=
10000
;
public
static
void
main
(
String
[]
args
)
throws
FileNotFoundException
{
List
<
Employee
>
emps
=
ObslugaCSV
.
readCSV
();
System
.
out
.
println
(
"Wczytano "
+
emps
.
size
()
+
" rekordów."
);
System
.
out
.
println
(
"Pracownicy zarabiający co najmniej "
+
GRANICA_ZAROBKOW
+
":"
);
emps
.
stream
()
.
filter
(
emp
->
emp
.
getSalary
()
>=
GRANICA_ZAROBKOW
)
.
forEach
(
emp
->
System
.
out
.
println
(
emp
.
getFirstName
()
+
" "
+
emp
.
getLastName
()
+
" zarabia "
+
emp
.
getSalary
()));
System
.
out
.
println
(
"\n----------------\n"
);
emps
.
parallelStream
()
.
filter
(
emp
->
emp
.
getSalary
()
>=
GRANICA_ZAROBKOW
)
.
map
(
emp
->
emp
.
getFirstName
()
+
" "
+
emp
.
getLastName
()
+
" zarabia "
+
emp
.
getSalary
())
.
forEachOrdered
(
System
.
out
::
println
);
System
.
out
.
println
(
"\nLista nadal zawiera "
+
emps
.
size
()
+
" elementów."
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment