src, List super Integer> dst) {\n",
911 | " dst.clear();\n",
912 | " for (Integer t : src) dst.add(t);\n",
913 | "}"
914 | ]
915 | },
916 | {
917 | "cell_type": "code",
918 | "execution_count": 32,
919 | "metadata": {
920 | "vscode": {
921 | "languageId": "java"
922 | }
923 | },
924 | "outputs": [
925 | {
926 | "data": {
927 | "text/plain": [
928 | "[1, 2, 3]"
929 | ]
930 | },
931 | "execution_count": 32,
932 | "metadata": {},
933 | "output_type": "execute_result"
934 | }
935 | ],
936 | "source": [
937 | "copy(ints, dupInts);\n",
938 | "dupInts"
939 | ]
940 | },
941 | {
942 | "cell_type": "code",
943 | "execution_count": 33,
944 | "metadata": {
945 | "vscode": {
946 | "languageId": "java"
947 | }
948 | },
949 | "outputs": [
950 | {
951 | "data": {
952 | "text/plain": [
953 | "[1, 2, 3]"
954 | ]
955 | },
956 | "execution_count": 33,
957 | "metadata": {},
958 | "output_type": "execute_result"
959 | }
960 | ],
961 | "source": [
962 | "copy(ints, dupNums);\n",
963 | "dupNums"
964 | ]
965 | },
966 | {
967 | "attachments": {},
968 | "cell_type": "markdown",
969 | "metadata": {},
970 | "source": [
971 | "## Schemi riassuntivi \n",
972 | "\n",
973 | "Alcune visualizzazioni possono essere comode per ricordare le relazioni introdotte in questa nota. La prima riprende esattamente le relazioni espresse nella precedente sezione\n",
974 | "\n",
975 | "
\n",
976 | "\n",
977 | "Una bella immagine di [Andrey Tyukin](https://stackoverflow.com/users/2707792/andrey-tyukin) può aiutare a riflettere sulle relazioni tra tipo e le nozioni di produttore e consumatore.\n",
978 | "\n",
979 | "
\n",
980 | "\n",
981 | "Per finire, una immagine tratta dal [tutorial](https://dev.java/learn/generics/wildcards/) può aiutare a ricordare l'ordine indotto da queste relazioni\n",
982 | "\n",
983 | "
"
984 | ]
985 | },
986 | {
987 | "cell_type": "markdown",
988 | "metadata": {},
989 | "source": [
990 | "\n",
991 | "digraph G {\n",
992 | "\n",
993 | " rankdir=\"BT\";\n",
994 | " node [shape=\"rect\"];\n",
995 | "\n",
996 | " gS[label=\"G\"];\n",
997 | " gT[label=\"G\"]; \n",
998 | " gsT[label=\"G super T>\"];\n",
999 | " gsS[label=\"G super S>\"];\n",
1000 | " geT[label=\"G extends T>\"]; \n",
1001 | " geS[label=\"G extends S>\"];\n",
1002 | " \n",
1003 | " gS->gT [style=\"dotted\"];\n",
1004 | " \n",
1005 | " gS -> geS;\n",
1006 | " gT -> geT;\n",
1007 | " \n",
1008 | " gS -> gsS;\n",
1009 | " gT -> gsT;\n",
1010 | " \n",
1011 | " geS -> geT;\n",
1012 | " gsT -> gsS;\n",
1013 | " \n",
1014 | " }\n",
1015 | "
"
1016 | ]
1017 | }
1018 | ],
1019 | "metadata": {
1020 | "kernelspec": {
1021 | "display_name": "Java",
1022 | "language": "java",
1023 | "name": "java"
1024 | },
1025 | "language_info": {
1026 | "codemirror_mode": "java",
1027 | "file_extension": ".jshell",
1028 | "mimetype": "text/x-java-source",
1029 | "name": "Java",
1030 | "pygments_lexer": "java",
1031 | "version": "21.0.5+11-Ubuntu-1ubuntu124.04"
1032 | }
1033 | },
1034 | "nbformat": 4,
1035 | "nbformat_minor": 2
1036 | }
1037 |
--------------------------------------------------------------------------------
/notes/notes.py:
--------------------------------------------------------------------------------
1 | from pathlib import Path
2 | from textwrap import dedent
3 |
4 | from pygments import highlight as pygments_highlight
5 | from pygments.lexers import get_lexer_for_filename
6 | from pygments.formatters import HtmlFormatter
7 |
8 | from IPython.display import HTML
9 |
10 | CURRENT_BRANCH = 'master'
11 | BASE_DIR = '../src/main/java/'
12 | BASE_URL = f'https://github.com/prog2-unimi/notes/blob/{CURRENT_BRANCH}/src/main/java/'
13 |
14 | def find(fragment, lines):
15 | oc = 0
16 | first = -1
17 | for n, line in enumerate(lines, 1):
18 | if fragment in line: first = n
19 | if first != -1:
20 | oc += line.count('{') - line.count('}')
21 | if oc == 0: return first, 1 + n
22 | return None, None
23 |
24 | def show(path, linenos = False, first = None, last = None, highlight = None, fragment = None):
25 | code = (Path(BASE_DIR) / path).read_text()
26 | lines = code.splitlines()
27 | if fragment: first, last = find(fragment, lines)
28 | first = 0 if first is None else first - 1
29 | last = len(lines) if last is None else last - 1
30 | url = BASE_URL + path
31 | if first > 0 or last < len(lines):
32 | url += '#L{}-L{}'.format(first + 1, last)
33 | code = '\n'.join(code.splitlines()[first:last])
34 | if isinstance(highlight, list):
35 | highlight = [l - first for l in highlight]
36 | elif isinstance(highlight, str):
37 | hf, hl = find(highlight, lines)
38 | highlight = list(range(hf - first, hl - first))
39 | lexer = get_lexer_for_filename(path, stripall = False)
40 | formatter = HtmlFormatter(
41 | linenos = 'inline' if linenos else None,
42 | linenostart = 1 if first is None else 1 + first,
43 | cssclass = 'output_html',
44 | nobackground = False,
45 | hl_lines = highlight if highlight else []
46 | )
47 | return HTML('{}[sorgente]'.format(
48 | formatter.get_style_defs('.output_html'),
49 | pygments_highlight(dedent(code), lexer, formatter),
50 | url
51 | ))
--------------------------------------------------------------------------------
/notes/tgerds0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/prog2-unimi/notes/e62ff5bf29b6bf2c4401b6e59970f9ecfab4f298/notes/tgerds0.png
--------------------------------------------------------------------------------
/notes/tgerds1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/prog2-unimi/notes/e62ff5bf29b6bf2c4401b6e59970f9ecfab4f298/notes/tgerds1.png
--------------------------------------------------------------------------------
/publish:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | ./gradlew spotlessApply build
4 | mkdir -p ./docs
5 | for g in notes/*.ipynb; do
6 | note=$(basename $g .ipynb)
7 | if [ $note = Test ]; then continue; fi
8 | echo "Converting $note..."
9 | if grep -q '"mimetype": "text/x-java-source"' "./notes/${note}.ipynb"; then
10 | jupyter nbconvert --execute --ExecutePreprocessor.allow_errors=True --to html "./notes/${note}.ipynb" --template classic
11 | else
12 | jupyter nbconvert --execute --no-prompt --no-input --to html "./notes/${note}.ipynb" --template classic
13 | fi
14 | sed -i -e 's|