Skip to content

Commit ad3a38e

Browse files
committed
Publish part 8
1 parent 009b1c6 commit ad3a38e

File tree

10 files changed

+82
-86
lines changed

10 files changed

+82
-86
lines changed

course-settings.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ const courseSettings = {
2828
{ separator: true, title: "Java Programming I" },
2929
],
3030
sidebarFuturePages: [
31-
{ separator: true, title: "Java Programming II" },
32-
{ title: "Part 8", tba: "17.3." },
3331
{ title: "Part 9", tba: "24.3." },
3432
{ title: "Part 10", tba: "31.3." },
3533
{ title: "Part 11", tba: "7.4." },

data/part-8/1-recap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
path: '/part-8/1-recap'
33
#title: 'Lyhyt kertaus'
44
title: 'Short recap'
5-
hidden: true
5+
hidden: false
66
---
77

88
<!-- <text-box variant='learningObjectives' name='Oppimistavoitteet'>

data/part-8/2-hash-map.md

Lines changed: 44 additions & 44 deletions
Large diffs are not rendered by default.

data/part-8/3-similarity-of-objects.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
path: "/part-8/3-similarity-of-objects"
33
title: "Similarity of objects"
4-
hidden: true
4+
hidden: false
55
---
66

77
<!-- <text-box variant='learningObjectives' name='Oppimistavoitteet'>
@@ -391,7 +391,7 @@ Olemme tähän mennessä käyttäneet HashMapin avaimina ainoastaan String- ja I
391391

392392
In addition to `equals`, the `hashCode` method can also be used for **approximate comparison of objects**. The method creates from the object a "hash code", i.e, a number, that tells a bit about the object's content. If two objects have the same hash value, they may be equal. On the other hand, if two objects have different hash values, they are certainly unequal.
393393

394-
Hash codes are used in HashMaps, for instance. HashMap's internal behavior is based on the fact that key-value pairs are stored in an array of lists based on the key's hash value. Each array index points to a list. The hash value identifies the array index, whereby the list located at the array index is traversed. The value associated with the key will be returned if, and only if, the exact same value is found in the list (equality comparison is done using the equals method). This way, the search only needs to consider a fraction of the keys stored in the hash table.
394+
Hash codes are used in HashMaps, for instance. HashMap's internal behavior is based on the fact that key-value pairs are stored in an array of lists based on the key's hash value. Each array index points to a list. The hash value identifies the array index, whereby the list located at the array index is traversed. The value associated with the key will be returned if, and only if, the exact same value is found in the list (equality comparison is done using the equals method). This way, the search only needs to consider a fraction of the keys stored in the hash map.
395395

396396
So far, we've only used String and Integer-type objects as HashMap keys, which have conveniently had ready-made `hashCode` methods implemented. Let's create an example where this is not the case: we'll continue with the books and keep track of the books that are on loan. We'll implement the book keeping with a HashMap. The key is the book and the value attached to the book is a string that tells the borrower's name:
397397

@@ -433,7 +433,7 @@ Jotta HashMap toimisi haluamallamme tavalla, eli palauttaisi lainaajan kun avaim
433433
434434
Olemme aiemmin käyttäneet `String`-olioita menestyksekkäästi HashMapin avaimena, joten voimme päätellä että `String`-luokassa on oma järkevästi toimiva `hashCode`-toteutus. _Delegoidaan_, eli siirretään laskemisvastuu `String`-oliolle. -->
435435

436-
We find the borrower when searching for the same object that was given as a key to the hash table's `put` method. However, when searching by the exact same book but with a different object,a borrwer isn't found, and we get the _null_ reference instead. The reason lies in the default implementation of the `hashCode` method in the `Object` class. The default implementation creates a `hashCode` value based on the object's reference, which means that books having the same content that are nonetheless different objects get different results from the hashCode method. As such, the object is not being searched for in the right place.
436+
We find the borrower when searching for the same object that was given as a key to the hash map's `put` method. However, when searching by the exact same book but with a different object,a borrwer isn't found, and we get the _null_ reference instead. The reason lies in the default implementation of the `hashCode` method in the `Object` class. The default implementation creates a `hashCode` value based on the object's reference, which means that books having the same content that are nonetheless different objects get different results from the hashCode method. As such, the object is not being searched for in the right place.
437437

438438
For the HashMap to work in thw way we want it to, that is, to return the borrower when given an object with the correct _content_ (not necessarily the same object as the original key), the class that's the key must overwrite the `hashCode` method in addition to the `equals` method. The method must be overwritten so that it gives the same numerical result for all objects with the same content. Also, some objects with different contents may get the same result from the hashCode method. However, with the HashMap's performance in mind, it is essential that objects with different contents get the same hash value as rarely as possible.
439439

@@ -499,7 +499,7 @@ public int hashCode() {
499499

500500
<!-- Nyt kirjan käyttö hajautustaulun avaimena on mahdollista. Samalla aiemmin kohtaamamme ongelma ratkeaa ja kirjojen lainaajat löytyvät: -->
501501

502-
It's now possible to use the book as the hash table's key. This way the problem we faced earlier gets solved and the book borrowers are found:
502+
It's now possible to use the book as the hash map's key. This way the problem we faced earlier gets solved and the book borrowers are found:
503503

504504
<!-- ```java
505505
HashMap<Kirja, String> lainaajat = new HashMap<>();

data/part-8/4-grouping-data-using-hash-maps.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
path: '/part-8/4-grouping-data-using-hash-maps'
33
title: 'Grouping data using hash maps'
4-
hidden: true
4+
hidden: false
55
---
66

77
<!-- <text-box variant='learningObjectives' name='Oppimistavoitteet'>
@@ -12,13 +12,13 @@ hidden: true
1212
</text-box> -->
1313
<text-box variant='learningObjectives' name='Learning Objectives'>
1414

15-
- You know how to use a list as a hash table's value
16-
- You know how to categorize data using a hash table
15+
- You know how to use a list as a hash map's value
16+
- You know how to categorize data using a hash map
1717

1818
</text-box>
1919

2020
<!-- Hajautustaulu sisältää korkeintaan yhden arvon yhtä avainta kohti. Seuraavassa esimerkissä tallennamme henkilöiden puhelinnumeroita hajautustauluun. -->
21-
A hash table has at most one value per each key. In the following example, we store the phone numbers of people into the hash table.
21+
A hash map has at most one value per each key. In the following example, we store the phone numbers of people into the hash map.
2222

2323

2424
<!-- ```java
@@ -61,7 +61,7 @@ Pekka's number: 09-111333
6161
Koska hajautustaulun avaimet ja arvot voivat olla mitä tahansa muuttujia, myös listojen käyttäminen hajautustaulun arvona on mahdollista. Useamman arvon lisääminen yhdelle avaimelle onnistuu liittämällä avaimeen lista. Muutetaan puhelinnumeroiden tallennustapaa seuraavasti: -->
6262
What if we wanted to assign multiple values ​​to a single key, such as multiple phone numbers for a given person?
6363

64-
Since keys and values ​​in a hash table can be any variable, it is also possible to use lists as values in a hash table. You can add more values ​​to a single key by attaching a list to the key. Let's change the way the numbers are stored in the following way:
64+
Since keys and values ​​in a hash map can be any variable, it is also possible to use lists as values in a hash map. You can add more values ​​to a single key by attaching a list to the key. Let's change the way the numbers are stored in the following way:
6565

6666
<!-- ```java
6767
HashMap<String, ArrayList<String>> puhelinnumerot = new HashMap<>();
@@ -71,7 +71,7 @@ HashMap<String, ArrayList<String>> phoneNumbers = new HashMap<>();
7171
```
7272

7373
<!-- Nyt hajautustaulussa on jokaiseen avaimeen liitettynä lista. Vaikka new-komento luo hajautustaulun, ei hajautustaulu sisällä alussa yhtäkään listaa. Ne on luotava tarvittaessa erikseen. -->
74-
Each key of the hash table now has a list attached to it. Although the new command creates a hash table, the hash table initially does not contain a single list. They need to be created separately as needed.
74+
Each key of the hash map now has a list attached to it. Although the new command creates a hash map, the hash map initially does not contain a single list. They need to be created separately as needed.
7575

7676
<!-- ```java
7777
HashMap<String, ArrayList<String>> puhelinnumerot = new HashMap<>();
@@ -112,7 +112,7 @@ Pekka's number: [040-12348765, 09-111333]
112112
</sample-output>
113113

114114
<!-- Määrittelimme muuttujan puhelinnumero tyypiksi `HashMap<String, ArrayList<String>>`. Tämä tarkoittaa hajautustaulua, joka käyttää avaimena merkkijonoa ja arvona merkkijonoja sisältävää listaa. Hajautustauluun lisättävät arvot ovat siis konkreettisia listoja. -->
115-
We define the type of the phone number as `HashMap<String, ArrayList<String>>`. This refers to a hash table that uses a string as a key and a list containing strings as its value. As such, the values added to the hash table are concrete lists.
115+
We define the type of the phone number as `HashMap<String, ArrayList<String>>`. This refers to a hash map that uses a string as a key and a list containing strings as its value. As such, the values added to the hash map are concrete lists.
116116

117117
<!-- ```java
118118
// liitetään Pekka-nimeen ensin tyhjä ArrayList

data/part-8/5-tiedon-nopea-hakeminen-ja-tiedon-ryhmittely.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
path: '/part-8/5-fast-data-fetching-and-grouping-information'
33
title: 'Fast data fetching and grouping information'
4-
hidden: true
4+
hidden: false
55
---
66

77
<!--
@@ -22,6 +22,4 @@ Vastaa vielä lopuksi seuraavaan kahdeksannen osan osaamistavoitteita tarkastele
2222

2323
The eighth part also started the second part of this course. If you just jumped in, welcome aboard! Finally, please take a moment to answer a self-reflective survey on the learning goals of the eighth part.
2424

25-
26-
27-
<quiz id='3d7f8b1d-8221-559d-91ab-ffbee0220842'></quiz>
25+
<quiz id='ce5dd5bb-4a47-5e73-96b2-6c93fb65134f'></quiz>

data/part-8/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
path: '/part-8'
33
title: 'Part 8'
44
overview: true
5-
hidden: true
5+
hidden: false
66
---
77

88
<please-login></please-login>

src/components/Sidebar.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,12 @@ class Sidebar extends React.Component {
135135
)
136136
let content = content2.concat(edges)
137137
content = content.concat(futurePages)
138-
if (CourseSettings.default.splitCourses) {
139-
let middlepoint = content.findIndex(o => o.title === "Osa 7")
140-
content.splice(middlepoint + 1, 0, {
141-
separator: true,
142-
title: "Ohjelmoinnin jatkokurssi",
143-
})
144-
}
138+
139+
let middlepoint = content.findIndex(o => o.title === "Part 7")
140+
content.splice(middlepoint + 1, 0, {
141+
separator: true,
142+
title: "Java Programming II",
143+
})
145144

146145
return (
147146
<MobileWrapperOrFragment mobileMenuOpen={this.props.mobileMenuOpen}>

src/services/moocfi.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -231,20 +231,8 @@ async function getCourse() {
231231
return CourseSettings.default.tmcCourse
232232
}
233233
const variant = await getCourseVariant()
234-
if (variant === "nodl") {
235-
return "2019-ohjelmointi-nodl"
236-
}
237-
if (variant === "ohja-dl") {
238-
return "2019-mooc-vain-jatkokurssi"
239-
}
240-
if (variant === "ohja-nodl") {
241-
return "2019-mooc-vain-jatkokurssi-nodl"
242-
}
243-
if (variant === "kesa-dl") {
244-
return "2019-ohjelmointi-kesa"
245-
}
246-
if (variant === "kesa-ohja-dl") {
247-
return "2019-mooc-vain-jatkokurssi-kesa"
234+
if (variant === "ii") {
235+
return "java-programming-ii"
248236
}
249237
return CourseSettings.default.tmcCourse
250238
}

src/services/quizzes.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import axios from "axios"
2-
import { accessToken } from "./moocfi"
2+
import { accessToken, getCourseVariant } from "./moocfi"
33
import CourseSettings from "../../course-settings"
44

5-
const id = CourseSettings.default.quizzesId
5+
// const id = CourseSettings.quizzesId
66
const language = CourseSettings.default.language
77

88
const quizzesLanguage = language === "en" ? "en_US" : "fi_FI"
99

1010
export async function fetchQuizzesProgress() {
11+
let id = CourseSettings.default.quizzesId
12+
const courseVariant = await getCourseVariant()
13+
14+
if (courseVariant === "ii") {
15+
id = "7d32559c-5b3d-4c30-bd8e-11e8408359fd"
16+
}
1117
const response = await axios.get(
1218
`https://quizzes.mooc.fi/api/v1/courses/${id}/users/current/progress`,
1319
{ headers: { Authorization: `Bearer ${accessToken()}` } },
@@ -16,6 +22,13 @@ export async function fetchQuizzesProgress() {
1622
}
1723

1824
export async function fetchQuizNames() {
25+
let id = CourseSettings.default.quizzesId
26+
const courseVariant = await getCourseVariant()
27+
28+
if (courseVariant === "ii") {
29+
id = "7d32559c-5b3d-4c30-bd8e-11e8408359fd"
30+
}
31+
1932
const response = await axios.get(
2033
`https://quizzes.mooc.fi/api/v1/quizzes/${id}/titles/${quizzesLanguage}`,
2134
)

0 commit comments

Comments
 (0)