├── .gitignore
├── Ejercicios
├── Ejercicios01.pdf
├── Ejercicios02.pdf
├── Ejercicios03.pdf
└── Ejercicios04.pdf
├── Extras
├── cheat_sheet_java8.png
├── davechild_regular-expressions.pdf
├── java01.png
├── java02.png
├── java03.png
├── kotlin01.png
├── kotlin02.png
├── scope.png
├── scope01.jpeg
├── scope2.png
├── scope3.png
└── xantier_kotlin_collection-extensions.pdf
├── README.md
├── Soluciones
├── 01-Func-FuncExtension
│ ├── .gitignore
│ ├── .idea
│ │ ├── .gitignore
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── kotlinc.xml
│ │ └── misc.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ └── Main.kt
├── 02-Func-Lambda
│ ├── .gitignore
│ ├── .idea
│ │ ├── .gitignore
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── kotlinc.xml
│ │ └── misc.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ └── Main.kt
├── 03-Func-SobrecargaOperadores
│ ├── .gitignore
│ ├── .idea
│ │ ├── .gitignore
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── kotlinc.xml
│ │ └── misc.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ └── Main.kt
├── 04-Func-Personas
│ ├── .gitignore
│ ├── .idea
│ │ ├── .gitignore
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── kotlinc.xml
│ │ └── misc.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ ├── Main.kt
│ │ ├── extensions
│ │ └── Estudiante.kt
│ │ └── models
│ │ └── Estudiante.kt
├── 05-Func-Inline
│ ├── .gitignore
│ ├── .idea
│ │ ├── .gitignore
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── kotlinc.xml
│ │ └── misc.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ └── Main.kt
├── 06-Func-Infix
│ ├── .gitignore
│ ├── .idea
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── kotlinc.xml
│ │ ├── misc.xml
│ │ └── workspace.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ └── Main.kt
├── 07-Func-Receiver
│ ├── .gitignore
│ ├── .idea
│ │ ├── .gitignore
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── kotlinc.xml
│ │ └── misc.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ └── Main.kt
├── 08-Func-ScopeFunc
│ ├── .gitignore
│ ├── .idea
│ │ ├── .gitignore
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── kotlinc.xml
│ │ └── misc.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ └── Main.kt
├── 09-Gen-Inicial
│ ├── .gitignore
│ ├── .idea
│ │ ├── .gitignore
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── kotlinc.xml
│ │ └── misc.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ ├── Main.kt
│ │ └── types
│ │ ├── Box.kt
│ │ ├── Pair.kt
│ │ └── Triple.kt
├── 10-Gen-Repository
│ ├── .gitignore
│ ├── .idea
│ │ ├── .gitignore
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── kotlinc.xml
│ │ └── misc.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ ├── Main.kt
│ │ ├── models
│ │ └── Persona.kt
│ │ └── repositories
│ │ ├── crud
│ │ └── CrudRepository.kt
│ │ └── personas
│ │ └── PersonasRepository.kt
├── 11-Gen-Varianza-Restricciones-Refied
│ ├── .gitignore
│ ├── .idea
│ │ ├── .gitignore
│ │ ├── .name
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── kotlinc.xml
│ │ ├── misc.xml
│ │ └── uiDesigner.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ ├── Refied.kt
│ │ ├── Restricciones.kt
│ │ └── Varianza.kt
├── 12-Colecciones-Listas
│ ├── .gitignore
│ ├── .idea
│ │ ├── .gitignore
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── kotlinc.xml
│ │ └── misc.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ ├── Main.kt
│ │ ├── models
│ │ └── Persona.kt
│ │ └── repositories
│ │ ├── FunctionalGenericRepository.kt
│ │ ├── crud
│ │ └── CrudRepository.kt
│ │ └── personas
│ │ └── PersonasRepository.kt
├── 13-Colecciones-Pila
│ ├── .gitignore
│ ├── .idea
│ │ ├── .gitignore
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── kotlinc.xml
│ │ └── misc.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ ├── Main.kt
│ │ ├── Pila.kt
│ │ └── Stack.kt
├── 14-Colecciones-Cola
│ ├── .gitignore
│ ├── .idea
│ │ ├── .gitignore
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── kotlinc.xml
│ │ └── misc.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ ├── Cola.kt
│ │ ├── Main.kt
│ │ └── Queue.kt
├── 15-Colecciones-Conjuntos
│ ├── .gitignore
│ ├── .idea
│ │ ├── .gitignore
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── kotlinc.xml
│ │ └── misc.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ ├── Main.kt
│ │ └── Persona.kt
├── 16-Comparable-Comparator
│ ├── .gitignore
│ ├── .idea
│ │ ├── .gitignore
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── kotlinc.xml
│ │ └── misc.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ ├── Main.kt
│ │ └── Persona.kt
├── 17-Colecciones-Mapas
│ ├── .gitignore
│ ├── .idea
│ │ ├── .gitignore
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── kotlinc.xml
│ │ └── misc.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ └── Main.kt
├── 18-Palindromo
│ ├── .gitignore
│ ├── .idea
│ │ ├── .gitignore
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── kotlinc.xml
│ │ └── misc.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ └── Main.kt
├── 19-Colecciones-Repository
│ ├── .gitignore
│ ├── .idea
│ │ ├── .gitignore
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── kotlinc.xml
│ │ └── misc.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ ├── CrudRepository.kt
│ │ ├── Main.kt
│ │ ├── Persona.kt
│ │ ├── PersonasExceptions.kt
│ │ ├── PersonasMapRepository.kt
│ │ ├── PersonasRepository.kt
│ │ ├── PersonasSetRepository.kt
│ │ └── PesonasListRepository.kt
├── 20-PlanificadorProcesosPrioridad
│ ├── .gitignore
│ ├── .idea
│ │ ├── .gitignore
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── kotlinc.xml
│ │ ├── misc.xml
│ │ └── uiDesigner.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ │ ├── main
│ │ └── kotlin
│ │ │ ├── Cola.kt
│ │ │ ├── ColaProcesosLista.kt
│ │ │ ├── ColaProcesosPrioritariosLista.kt
│ │ │ ├── ColaProcesosPrioritariosMap.kt
│ │ │ ├── ColaProcesosPrioritariosTreeMapList.kt
│ │ │ ├── ColaProcesosPrioritariosTreeMapMap.kt
│ │ │ ├── ColaProcesosPrioritariosTreeSet.kt
│ │ │ ├── Main.kt
│ │ │ ├── Planificador.kt
│ │ │ ├── Proceso.kt
│ │ │ └── ProcesosFactory.kt
│ │ └── test
│ │ └── kotlin
│ │ ├── ColaProcesosListaTest.kt
│ │ ├── ColaProcesosPrioritariosListaTest.kt
│ │ └── ColaProcesosPrioritariosTreeSetTest.kt
├── 22-CacheLimitada
│ ├── .gitignore
│ ├── .idea
│ │ ├── .gitignore
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── kotlinc.xml
│ │ └── misc.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ ├── Main.kt
│ │ ├── Vehiculo.kt
│ │ └── cache
│ │ └── Cache.kt
├── 23-RepositorioCacheable
│ ├── .gitignore
│ ├── .idea
│ │ ├── .gitignore
│ │ ├── gradle.xml
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── kotlinc.xml
│ │ ├── misc.xml
│ │ └── uiDesigner.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ ├── Main.kt
│ │ ├── exceptions
│ │ └── VehiculoException.kt
│ │ ├── models
│ │ └── Vehiculo.kt
│ │ ├── repositories
│ │ ├── cache
│ │ │ ├── Cache.kt
│ │ │ └── CacheImpl.kt
│ │ ├── crud
│ │ │ └── CrudRepository.kt
│ │ └── vehiculos
│ │ │ ├── VehiculosRepository.kt
│ │ │ └── VehiculosRepositoryImpl.kt
│ │ └── services
│ │ ├── VehiculosService.kt
│ │ └── VehiculosServiceImpl.kt
└── 24-Matrix
│ ├── .gitignore
│ ├── .idea
│ ├── .gitignore
│ ├── gradle.xml
│ ├── inspectionProfiles
│ │ └── Project_Default.xml
│ ├── kotlinc.xml
│ └── misc.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ └── src
│ └── main
│ └── kotlin
│ ├── Main.kt
│ ├── controllers
│ └── TheMatrixController.kt
│ ├── factories
│ ├── GenericoFactory.kt
│ └── SmithFactory.kt
│ ├── models
│ ├── Generico.kt
│ ├── Localizacion.kt
│ ├── Neo.kt
│ ├── Persona.kt
│ ├── Personaje.kt
│ └── Smith.kt
│ └── repositories
│ ├── cola
│ ├── Cola.kt
│ └── ColaImpl.kt
│ └── matriz
│ ├── Matriz.kt
│ └── MatrizImpl.kt
└── images
├── 01.png
├── 02.png
├── 03.png
├── 04.png
├── 05.png
├── 06.png
├── 07.png
├── colecciones.webp
├── secuences.webp
├── secuences01.webp
├── secuencias.png
└── sql-collections.png
/.gitignore:
--------------------------------------------------------------------------------
1 | *.pptx
2 | *.docx
3 | .DS_Store
4 | /Ejercicios/*.docx
5 | upload.sh
6 | /Soluciones/2021-2022
7 | /Soluciones/2022-2023
8 | *.docx
9 | /Ejemplos/2022-2023
10 |
--------------------------------------------------------------------------------
/Ejercicios/Ejercicios01.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Ejercicios/Ejercicios01.pdf
--------------------------------------------------------------------------------
/Ejercicios/Ejercicios02.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Ejercicios/Ejercicios02.pdf
--------------------------------------------------------------------------------
/Ejercicios/Ejercicios03.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Ejercicios/Ejercicios03.pdf
--------------------------------------------------------------------------------
/Ejercicios/Ejercicios04.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Ejercicios/Ejercicios04.pdf
--------------------------------------------------------------------------------
/Extras/cheat_sheet_java8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Extras/cheat_sheet_java8.png
--------------------------------------------------------------------------------
/Extras/davechild_regular-expressions.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Extras/davechild_regular-expressions.pdf
--------------------------------------------------------------------------------
/Extras/java01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Extras/java01.png
--------------------------------------------------------------------------------
/Extras/java02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Extras/java02.png
--------------------------------------------------------------------------------
/Extras/java03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Extras/java03.png
--------------------------------------------------------------------------------
/Extras/kotlin01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Extras/kotlin01.png
--------------------------------------------------------------------------------
/Extras/kotlin02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Extras/kotlin02.png
--------------------------------------------------------------------------------
/Extras/scope.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Extras/scope.png
--------------------------------------------------------------------------------
/Extras/scope01.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Extras/scope01.jpeg
--------------------------------------------------------------------------------
/Extras/scope2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Extras/scope2.png
--------------------------------------------------------------------------------
/Extras/scope3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Extras/scope3.png
--------------------------------------------------------------------------------
/Extras/xantier_kotlin_collection-extensions.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Extras/xantier_kotlin_collection-extensions.pdf
--------------------------------------------------------------------------------
/Soluciones/01-Func-FuncExtension/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/Soluciones/01-Func-FuncExtension/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Soluciones/01-Func-FuncExtension/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Soluciones/01-Func-FuncExtension/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/01-Func-FuncExtension/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/01-Func-FuncExtension/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Soluciones/01-Func-FuncExtension/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.21"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | testImplementation("org.jetbrains.kotlin:kotlin-test")
14 | }
15 |
16 | tasks.test {
17 | useJUnitPlatform()
18 | }
19 | kotlin {
20 | jvmToolchain(21)
21 | }
--------------------------------------------------------------------------------
/Soluciones/01-Func-FuncExtension/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/01-Func-FuncExtension/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/01-Func-FuncExtension/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/01-Func-FuncExtension/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Jan 17 20:54:14 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/01-Func-FuncExtension/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "Func-FuncExtension"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/02-Func-Lambda/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/Soluciones/02-Func-Lambda/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Soluciones/02-Func-Lambda/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Soluciones/02-Func-Lambda/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/02-Func-Lambda/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/02-Func-Lambda/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Soluciones/02-Func-Lambda/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.21"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | testImplementation("org.jetbrains.kotlin:kotlin-test")
14 | }
15 |
16 | tasks.test {
17 | useJUnitPlatform()
18 | }
19 | kotlin {
20 | jvmToolchain(21)
21 | }
--------------------------------------------------------------------------------
/Soluciones/02-Func-Lambda/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/02-Func-Lambda/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/02-Func-Lambda/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/02-Func-Lambda/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Jan 17 20:08:21 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/02-Func-Lambda/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/Soluciones/02-Func-Lambda/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "Func-Lambda"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/03-Func-SobrecargaOperadores/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/Soluciones/03-Func-SobrecargaOperadores/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Soluciones/03-Func-SobrecargaOperadores/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Soluciones/03-Func-SobrecargaOperadores/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/03-Func-SobrecargaOperadores/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/03-Func-SobrecargaOperadores/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Soluciones/03-Func-SobrecargaOperadores/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.21"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | testImplementation("org.jetbrains.kotlin:kotlin-test")
14 | }
15 |
16 | tasks.test {
17 | useJUnitPlatform()
18 | }
19 | kotlin {
20 | jvmToolchain(21)
21 | }
--------------------------------------------------------------------------------
/Soluciones/03-Func-SobrecargaOperadores/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/03-Func-SobrecargaOperadores/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/03-Func-SobrecargaOperadores/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/03-Func-SobrecargaOperadores/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Jan 18 15:53:30 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/03-Func-SobrecargaOperadores/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "Fun-SobrecargaOperadores"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/04-Func-Personas/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/Soluciones/04-Func-Personas/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Soluciones/04-Func-Personas/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Soluciones/04-Func-Personas/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/04-Func-Personas/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/04-Func-Personas/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Soluciones/04-Func-Personas/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.21"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | testImplementation("org.jetbrains.kotlin:kotlin-test")
14 | }
15 |
16 | tasks.test {
17 | useJUnitPlatform()
18 | }
19 | kotlin {
20 | jvmToolchain(21)
21 | }
--------------------------------------------------------------------------------
/Soluciones/04-Func-Personas/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/04-Func-Personas/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/04-Func-Personas/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/04-Func-Personas/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Jan 18 15:28:56 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/04-Func-Personas/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "Fun-Personas"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/04-Func-Personas/src/main/kotlin/Main.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | import dev.joseluisgs.extensions.esAprobado
4 | import dev.joseluisgs.extensions.filter
5 | import dev.joseluisgs.extensions.media
6 | import dev.joseluisgs.extensions.not
7 | import dev.joseluisgs.models.Estudiante
8 |
9 | fun main() {
10 | println("Hello Student!")
11 |
12 | val e1 = Estudiante("Jose", 10.0)
13 | println(e1)
14 | println(e1.esAprobado())
15 | val e2 = Estudiante("Pedro", 4.99)
16 | println(e2)
17 | println(e2.esAprobado())
18 |
19 | var estudiantesArray = arrayOf(e1, e2)
20 | estudiantesArray.forEach {
21 | println(it)
22 | }
23 | estudiantesArray.forEach {
24 | println("$it es aprobado: ${it.esAprobado()}")
25 | }
26 |
27 | val aprobados = estudiantesArray.filter {
28 | it.esAprobado()
29 | }
30 | aprobados.forEach {
31 | println(it)
32 | }
33 |
34 | val suspensos = estudiantesArray.filter {
35 | !it.esAprobado()
36 | }
37 | suspensos.forEach {
38 | println(it)
39 | }
40 |
41 | val notables = estudiantesArray.filter {
42 | it.nota >= 7.0 && it.nota < 9.0
43 | }
44 | notables.forEach {
45 | println(it)
46 | }
47 |
48 | println("La media es: ${estudiantesArray.media()}")
49 |
50 | val e3 = Estudiante("Juan", 5.0)
51 | val e4 = Estudiante("Ana", 6.0)
52 |
53 | estudiantesArray = estudiantesArray + e3
54 | estudiantesArray = estudiantesArray + e4
55 |
56 | println(estudiantesArray.contentToString())
57 |
58 | var suspensos2 = estudiantesArray.filter {
59 | !it.esAprobado()
60 | }
61 | println(suspensos2.contentToString())
62 | var suspensos3 = !estudiantesArray
63 | println(suspensos3.contentToString())
64 |
65 | }
--------------------------------------------------------------------------------
/Soluciones/04-Func-Personas/src/main/kotlin/extensions/Estudiante.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.extensions
2 |
3 | import dev.joseluisgs.models.Estudiante
4 |
5 | fun Estudiante.esAprobado(limite: Double = 5.0): Boolean {
6 | return this.nota >= limite
7 | }
8 |
9 | fun Array.forEach(action: (e: Estudiante) -> Unit) {
10 | for (e in this) {
11 | action(e)
12 | }
13 | }
14 |
15 | fun Array.filter(predicate: (e: Estudiante) -> Boolean): Array {
16 | val aux: Array = arrayOfNulls(this.size)
17 |
18 | var i = 0
19 | for (e in this) {
20 | if (predicate(e)) {
21 | aux[i] = e
22 | i++
23 | }
24 | }
25 |
26 | // contamos los nulos
27 | var nulos = 0
28 | for (e in aux) {
29 | if (e == null) {
30 | nulos++
31 | }
32 | }
33 |
34 | // creamos el array final
35 | val final: Array = arrayOfNulls(this.size - nulos)
36 | var j = 0
37 | for (e in aux) {
38 | if (e != null) {
39 | final[j] = e
40 | j++
41 | }
42 | }
43 |
44 | return final
45 | }
46 |
47 | fun Array.media(): Double {
48 | var media = 0.0
49 | for (e in this) {
50 | media += e.nota
51 | }
52 | return media / this.size
53 | }
54 |
55 | operator fun Estudiante.plus(estudiante: Estudiante): Estudiante {
56 | return Estudiante(this.nombre + estudiante.nombre, this.nota + estudiante.nota)
57 | }
58 |
59 |
60 | operator fun Array.plus(estudiante: Estudiante): Array {
61 | val aux: Array = arrayOfNulls(this.size + 1)
62 | for (i in this.indices) {
63 | aux[i] = this[i]
64 | }
65 | aux[this.size] = estudiante
66 | return aux
67 | }
68 |
69 | operator fun Array.not(): Array {
70 | val aux: Array = arrayOfNulls(this.size)
71 | // Quitamos los suspensos
72 | var i = 0
73 | for (e in this) {
74 | if (!e.esAprobado()) {
75 | aux[i] = e
76 | i++
77 | }
78 | }
79 | // Quitamos los nulos
80 | var nulos = 0
81 | for (e in aux) {
82 | if (e == null) {
83 | nulos++
84 | }
85 | }
86 | // creamos el array final
87 | val final: Array = arrayOfNulls(this.size - nulos)
88 | var j = 0
89 | for (e in aux) {
90 | if (e != null) {
91 | final[j] = e
92 | j++
93 | }
94 | }
95 | return final
96 | }
--------------------------------------------------------------------------------
/Soluciones/04-Func-Personas/src/main/kotlin/models/Estudiante.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.models
2 |
3 | data class Estudiante(val nombre: String, val nota: Double)
--------------------------------------------------------------------------------
/Soluciones/05-Func-Inline/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/Soluciones/05-Func-Inline/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Soluciones/05-Func-Inline/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Soluciones/05-Func-Inline/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/05-Func-Inline/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/05-Func-Inline/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Soluciones/05-Func-Inline/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.21"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | testImplementation("org.jetbrains.kotlin:kotlin-test")
14 | }
15 |
16 | tasks.test {
17 | useJUnitPlatform()
18 | }
19 | kotlin {
20 | jvmToolchain(21)
21 | }
--------------------------------------------------------------------------------
/Soluciones/05-Func-Inline/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/05-Func-Inline/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/05-Func-Inline/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/05-Func-Inline/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Jan 19 17:15:12 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/05-Func-Inline/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/Soluciones/05-Func-Inline/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "Fun-Inline"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/05-Func-Inline/src/main/kotlin/Main.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | fun myRepeat(times: Int, action: (Int) -> Unit) {
4 | for (i in 0.. Unit) {
10 | for (i in 0..
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Soluciones/06-Func-Infix/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/06-Func-Infix/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/06-Func-Infix/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Soluciones/06-Func-Infix/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
51 |
52 |
53 |
54 |
55 | 1701964927500
56 |
57 |
58 | 1701964927500
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/Soluciones/06-Func-Infix/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.21"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | testImplementation("org.jetbrains.kotlin:kotlin-test")
14 | }
15 |
16 | tasks.test {
17 | useJUnitPlatform()
18 | }
19 | kotlin {
20 | jvmToolchain(21)
21 | }
--------------------------------------------------------------------------------
/Soluciones/06-Func-Infix/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/06-Func-Infix/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/06-Func-Infix/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/06-Func-Infix/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Jan 19 17:55:05 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/06-Func-Infix/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/Soluciones/06-Func-Infix/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "Fun-Infix"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/06-Func-Infix/src/main/kotlin/Main.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | infix fun String.repetir(veces: Int): String {
4 | var resultado = ""
5 | for (i in 0..veces) {
6 | resultado += this
7 | }
8 | return resultado
9 | }
10 |
11 | infix fun String.mayusculas(position: Int): String {
12 | return this[position].uppercaseChar().toString()
13 | }
14 |
15 | infix fun Int.sumar(numero: Int): Int {
16 | return this + numero
17 | }
18 |
19 | infix fun Int.restar(numero: Int): Int {
20 | return this - numero
21 | }
22 |
23 | fun main() {
24 | println("Hello World!")
25 | println("Hello World!" repetir 3)
26 | println("Hello World!".repetir(3))
27 | println("Hello World!".mayusculas(3))
28 | println("Hello World!" mayusculas 3)
29 |
30 | println(1 + 2)
31 | println(1 sumar 2)
32 | println(1 restar 2)
33 | println(1 - 2)
34 | }
--------------------------------------------------------------------------------
/Soluciones/07-Func-Receiver/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/Soluciones/07-Func-Receiver/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Soluciones/07-Func-Receiver/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Soluciones/07-Func-Receiver/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/07-Func-Receiver/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/07-Func-Receiver/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Soluciones/07-Func-Receiver/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.21"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | testImplementation("org.jetbrains.kotlin:kotlin-test")
14 | }
15 |
16 | tasks.test {
17 | useJUnitPlatform()
18 | }
19 | kotlin {
20 | jvmToolchain(21)
21 | }
--------------------------------------------------------------------------------
/Soluciones/07-Func-Receiver/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/07-Func-Receiver/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/07-Func-Receiver/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/07-Func-Receiver/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Jan 19 18:07:59 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/07-Func-Receiver/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "Fun-Receiver"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/08-Func-ScopeFunc/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/Soluciones/08-Func-ScopeFunc/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Soluciones/08-Func-ScopeFunc/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Soluciones/08-Func-ScopeFunc/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/08-Func-ScopeFunc/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/08-Func-ScopeFunc/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Soluciones/08-Func-ScopeFunc/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.21"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | testImplementation("org.jetbrains.kotlin:kotlin-test")
14 | }
15 |
16 | tasks.test {
17 | useJUnitPlatform()
18 | }
19 | kotlin {
20 | jvmToolchain(21)
21 | }
--------------------------------------------------------------------------------
/Soluciones/08-Func-ScopeFunc/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/08-Func-ScopeFunc/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/08-Func-ScopeFunc/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/08-Func-ScopeFunc/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Jan 23 15:36:59 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/08-Func-ScopeFunc/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "Fun-ScopeFunc"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/09-Gen-Inicial/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/Soluciones/09-Gen-Inicial/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Soluciones/09-Gen-Inicial/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Soluciones/09-Gen-Inicial/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/09-Gen-Inicial/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/09-Gen-Inicial/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Soluciones/09-Gen-Inicial/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.21"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | testImplementation("org.jetbrains.kotlin:kotlin-test")
14 | }
15 |
16 | tasks.test {
17 | useJUnitPlatform()
18 | }
19 | kotlin {
20 | jvmToolchain(21)
21 | }
--------------------------------------------------------------------------------
/Soluciones/09-Gen-Inicial/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/09-Gen-Inicial/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/09-Gen-Inicial/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/09-Gen-Inicial/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Jan 24 20:20:30 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/09-Gen-Inicial/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "Gen-Inicial"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/09-Gen-Inicial/src/main/kotlin/Main.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | import dev.joseluisgs.types.Box
4 | import dev.joseluisgs.types.Pair
5 |
6 | fun main() {
7 | val b1 = Box(1)
8 | val b2 = Box("Hola")
9 | val b3 = Box(1.0)
10 |
11 | val p1 = Pair(1, "Hola")
12 | val p2 = Pair("Hola", 1)
13 | val p3 = Pair("Hola", "Hola")
14 |
15 | printPairConcretos(p1)
16 | printPair(p2)
17 |
18 | val t1 = Triple(1, "Hola", 1.0)
19 | val t2 = Triple("Hola", 1, 1.0)
20 | val t3 = Triple("Hola", "Hola", "Hola")
21 |
22 | val locura = Triple(Triple(1, "Hola", Box(1.0)), Pair("Hola", 1), Pair("Hola", "Hola"))
23 | }
24 |
25 | fun printPairConcretos(pair: Pair) {
26 | println("Pair: ${pair.first} ${pair.second}")
27 | }
28 |
29 | fun printPair(pair: Pair) {
30 | println("Pair: ${pair.first} ${pair.second}")
31 | }
32 |
--------------------------------------------------------------------------------
/Soluciones/09-Gen-Inicial/src/main/kotlin/types/Box.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.types
2 |
3 | class Box(var item: T) {
4 | fun getItem(): T {
5 | return item
6 | }
7 |
8 | fun setItem(item: T) {
9 | this.item = item
10 | }
11 | }
--------------------------------------------------------------------------------
/Soluciones/09-Gen-Inicial/src/main/kotlin/types/Pair.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.types
2 |
3 | data class Pair(var first: T, var second: R)
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/09-Gen-Inicial/src/main/kotlin/types/Triple.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.types
2 |
3 | data class Triple(var first: T, var second: R, var third: S)
--------------------------------------------------------------------------------
/Soluciones/10-Gen-Repository/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/Soluciones/10-Gen-Repository/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Soluciones/10-Gen-Repository/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Soluciones/10-Gen-Repository/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/10-Gen-Repository/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/10-Gen-Repository/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Soluciones/10-Gen-Repository/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.21"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | testImplementation("org.jetbrains.kotlin:kotlin-test")
14 | }
15 |
16 | tasks.test {
17 | useJUnitPlatform()
18 | }
19 | kotlin {
20 | jvmToolchain(21)
21 | }
--------------------------------------------------------------------------------
/Soluciones/10-Gen-Repository/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/10-Gen-Repository/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/10-Gen-Repository/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/10-Gen-Repository/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Jan 24 20:40:23 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/10-Gen-Repository/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "Gen-Repository"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/10-Gen-Repository/src/main/kotlin/Main.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | import dev.joseluisgs.models.Persona
4 | import dev.joseluisgs.repositories.personas.PersonasRepository
5 |
6 | fun main() {
7 | val personasRepository = PersonasRepository()
8 |
9 | println("Consultamos todas las personas: ")
10 | personasRepository.getAll().forEach { persona ->
11 | println(persona)
12 | }
13 |
14 | println("Creamos una nueva persona: ")
15 | var personaToSaved = Persona(name = "Pepe", email = "pepe@gmail.com")
16 | var personaSaved = personasRepository.save(personaToSaved)
17 | println(personaSaved)
18 |
19 | println("Consultamos todas las personas: ")
20 | personasRepository.getAll().forEach { persona ->
21 | println(persona)
22 | }
23 |
24 | println("Consultamos una persona por su id: 1")
25 | personasRepository.getById(1)?.let { persona ->
26 | println(persona)
27 | } ?: println("No existe la persona")
28 |
29 | println("Consultamos una persona por su id: 99")
30 | personasRepository.getById(99)?.let { persona ->
31 | println(persona)
32 | } ?: println("No existe la persona")
33 |
34 | println("Creamos otra persona: ")
35 | personaToSaved = Persona(name = "Ana", email = "ana@gmail.com")
36 | personaSaved = personasRepository.save(personaToSaved)
37 | println(personaSaved)
38 |
39 | println("Consultamos todas las personas: ")
40 | personasRepository.getAll().forEach { persona ->
41 | println(persona)
42 | }
43 |
44 | println("Actualizamos una persona por su id: 1")
45 | val personaToUpdate = Persona(name = "Jose", email = "jose@gmail.com")
46 | personasRepository.update(1, personaToUpdate)?.let { persona ->
47 | println(persona)
48 | } ?: println("No existe la persona")
49 |
50 | println("Actualizamos una persona por su id: 99")
51 | personasRepository.update(99, personaToUpdate)?.let { persona ->
52 | println(persona)
53 | } ?: println("No existe la persona")
54 |
55 | println("Consultamos todas las personas: ")
56 | personasRepository.getAll().forEach { persona ->
57 | println(persona)
58 | }
59 |
60 | println("Borramos una persona por su id: 1")
61 | personasRepository.delete(1)?.let { persona ->
62 | println(persona)
63 | } ?: println("No existe la persona")
64 |
65 | println("Borramos una persona por su id: 99")
66 | personasRepository.delete(99)?.let { persona ->
67 | println(persona)
68 | } ?: println("No existe la persona")
69 |
70 | println("Consultamos todas las personas: ")
71 | personasRepository.getAll().forEach { persona ->
72 | println(persona)
73 | }
74 | }
--------------------------------------------------------------------------------
/Soluciones/10-Gen-Repository/src/main/kotlin/models/Persona.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.models
2 |
3 | data class Persona(var name: String, var email: String) {
4 | var id: Int = 0
5 |
6 | override fun toString(): String {
7 | return "Persona(id=$id, name='$name', email='$email')"
8 | }
9 | }
--------------------------------------------------------------------------------
/Soluciones/10-Gen-Repository/src/main/kotlin/repositories/crud/CrudRepository.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.repositories.crud
2 |
3 | interface CrudRepository {
4 | fun getAll(): Array
5 | fun getById(key: ID): T?
6 | fun save(value: T): T
7 | fun update(key: ID, value: T): T?
8 | fun delete(key: ID): T?
9 | }
--------------------------------------------------------------------------------
/Soluciones/10-Gen-Repository/src/main/kotlin/repositories/personas/PersonasRepository.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.repositories.personas
2 |
3 | import dev.joseluisgs.models.Persona
4 | import dev.joseluisgs.repositories.crud.CrudRepository
5 |
6 | class PersonasRepository : CrudRepository {
7 | private var personas: Array = arrayOfNulls(10)
8 | private var key: Int = 0
9 |
10 | override fun getAll(): Array {
11 | // Creamos un nuevo array con el tamaño de los elementos no nulos
12 | /* val personasNoNulas = Array(personas.size - contarNulos()) { i ->
13 | personas[i]!!
14 | }
15 | return personasNoNulas*/
16 | return personas.filterNotNull().toTypedArray()
17 | }
18 |
19 | override fun getById(key: Int): Persona? {
20 | return personas.firstOrNull { it?.id == key }
21 | }
22 |
23 | override fun delete(key: Int): Persona? {
24 | // sacamos su indice
25 | var persona: Persona? = null
26 | this.personas.indexOfFirst { it?.id == key }
27 | .takeIf { it != -1 }
28 | ?.let {
29 | // Si existe lo borramos
30 | persona = personas[it]
31 | personas[it] = null
32 | }.also {
33 | // Redimensionamos el array si hay mas de 10 nulos
34 | if (personas.count { it == null } > 10) {
35 | personas = personas.filterNotNull().toTypedArray()
36 | }
37 | }
38 | return persona
39 | }
40 |
41 | override fun update(key: Int, value: Persona): Persona? {
42 | return getById(key)?.apply {
43 | name = value.name
44 | email = value.email
45 | }
46 | }
47 |
48 | override fun save(value: Persona): Persona {
49 | // Si el array está lleno (no tiene nulos)
50 | if (personas.count { it == null } == 0) {
51 | // Redimensionamos el array
52 | personas = personas.copyOf(personas.size + 10)
53 | }
54 | // Añadimos el elemento en el primer nulo que encontremos
55 | val index = personas.indexOfFirst { it == null }
56 | key++ // Incrementamos la clave
57 | value.id = key // Asignamos la clave
58 | personas[index] = value // Asignamos el valor
59 | return value // Devolvemos el valor
60 | }
61 |
62 |
63 | }
--------------------------------------------------------------------------------
/Soluciones/11-Gen-Varianza-Restricciones-Refied/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/Soluciones/11-Gen-Varianza-Restricciones-Refied/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Soluciones/11-Gen-Varianza-Restricciones-Refied/.idea/.name:
--------------------------------------------------------------------------------
1 | Gen-Varianza
--------------------------------------------------------------------------------
/Soluciones/11-Gen-Varianza-Restricciones-Refied/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Soluciones/11-Gen-Varianza-Restricciones-Refied/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/11-Gen-Varianza-Restricciones-Refied/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/11-Gen-Varianza-Restricciones-Refied/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Soluciones/11-Gen-Varianza-Restricciones-Refied/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.22"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | testImplementation("org.jetbrains.kotlin:kotlin-test")
14 | }
15 |
16 | tasks.test {
17 | useJUnitPlatform()
18 | }
19 | kotlin {
20 | jvmToolchain(21)
21 | }
--------------------------------------------------------------------------------
/Soluciones/11-Gen-Varianza-Restricciones-Refied/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/11-Gen-Varianza-Restricciones-Refied/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/11-Gen-Varianza-Restricciones-Refied/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/11-Gen-Varianza-Restricciones-Refied/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Jan 31 18:06:52 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/11-Gen-Varianza-Restricciones-Refied/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "Gen-Varianza"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/11-Gen-Varianza-Restricciones-Refied/src/main/kotlin/Refied.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | // Los tipos genéricos no se pueden usar en tiempo de ejecución
4 | // por lo que no podemos usar T::class.simpleName directamente
5 | // para ello usamos el modificador reified que nos permite
6 | // usar el tipo genérico en tiempo de ejecución
7 |
8 | // Al ser inline el compilador sustituye el código en tiempo de compilación
9 | // por lo que no se genera código extra, y el modificador reified nos permite
10 | // usar el tipo genérico en tiempo de ejecución
11 |
12 | /*fun printType() {
13 | println(T::class.simpleName)
14 | }*/
15 |
16 | inline fun printTypeRefied() {
17 | println(T::class.simpleName)
18 | }
19 |
20 | fun main() {
21 | // printType()
22 | // printType()
23 | // printType()
24 | // printType()
25 | printTypeRefied()
26 | printTypeRefied()
27 | printTypeRefied()
28 | printTypeRefied()
29 | printTypeRefied>()
30 | }
--------------------------------------------------------------------------------
/Soluciones/12-Colecciones-Listas/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/Soluciones/12-Colecciones-Listas/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Soluciones/12-Colecciones-Listas/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Soluciones/12-Colecciones-Listas/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/12-Colecciones-Listas/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/12-Colecciones-Listas/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Soluciones/12-Colecciones-Listas/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.22"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | testImplementation("org.jetbrains.kotlin:kotlin-test")
14 | }
15 |
16 | tasks.test {
17 | useJUnitPlatform()
18 | }
19 | kotlin {
20 | jvmToolchain(21)
21 | }
--------------------------------------------------------------------------------
/Soluciones/12-Colecciones-Listas/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/12-Colecciones-Listas/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/12-Colecciones-Listas/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/12-Colecciones-Listas/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Jan 31 20:58:40 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/12-Colecciones-Listas/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "Colecciones-Listas"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/12-Colecciones-Listas/src/main/kotlin/models/Persona.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.models
2 |
3 | data class Persona(var name: String, var email: String) {
4 | var id: Int = 0
5 |
6 | override fun toString(): String {
7 | return "Persona(id=$id, name='$name', email='$email')"
8 | }
9 | }
--------------------------------------------------------------------------------
/Soluciones/12-Colecciones-Listas/src/main/kotlin/repositories/FunctionalGenericRepository.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.repositories
2 |
3 | class CrudRepository(private val items: MutableList = mutableListOf()) {
4 |
5 | // Create
6 | fun create(item: T): T {
7 | items.add(item)
8 | return item
9 | }
10 |
11 | // Read
12 | fun read(predicate: (T) -> Boolean): List {
13 | return items.filter(predicate)
14 | }
15 |
16 | // Update
17 | fun update(predicate: (T) -> Boolean, transform: (T) -> T): List {
18 | return items.mapIndexedNotNull { index, item ->
19 | if (predicate(item)) {
20 | items[index] = transform(item)
21 | items[index]
22 | } else {
23 | null
24 | }
25 | }
26 | }
27 |
28 | // Delete
29 | fun delete(predicate: (T) -> Boolean): List {
30 | return items.filter(predicate).onEach {
31 | items.remove(it)
32 | }
33 | }
34 |
35 | // List all items
36 | fun listAll(): List = items.toList()
37 | }
38 |
39 | // Ejemplo de uso
40 | data class User(val id: Int, var name: String)
41 |
42 | fun main() {
43 | val userRepository = CrudRepository()
44 |
45 | // Crear usuarios
46 | userRepository.create(User(1, "Juan"))
47 | userRepository.create(User(2, "Ana"))
48 | userRepository.create(User(3, "Luis"))
49 |
50 | // Leer usuarios con un criterio específico
51 | val usersNamedAna = userRepository.read { it.name == "Ana" }
52 | println(usersNamedAna) // Debería imprimir todos los usuarios llamados "Ana"
53 |
54 | // usuario con id = 2
55 | val userWithId2 = userRepository.read { it.id == 2 }
56 | println(userWithId2) // Debería imprimir el usuario con id 2
57 |
58 | // Actualizar usuarios con un criterio específico
59 | userRepository.update({ it.id == 1 }) { it.copy(name = "Juan Actualizado") }
60 |
61 | // Eliminar usuarios con un criterio específico
62 | userRepository.delete { it.id == 2 }
63 |
64 | // Listar todos los usuarios
65 | val allUsers = userRepository.listAll()
66 | println(allUsers) // Debería imprimir todos los usuarios excepto el usuario con id 2
67 | }
68 |
--------------------------------------------------------------------------------
/Soluciones/12-Colecciones-Listas/src/main/kotlin/repositories/crud/CrudRepository.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.repositories.crud
2 |
3 | interface CrudRepository {
4 | fun getAll(): List // no quiero que se pueda modificar
5 | fun getById(key: ID): T?
6 | fun save(value: T): T
7 | fun update(key: ID, value: T): T?
8 | fun delete(key: ID): T?
9 | }
--------------------------------------------------------------------------------
/Soluciones/12-Colecciones-Listas/src/main/kotlin/repositories/personas/PersonasRepository.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.repositories.personas
2 |
3 | import dev.joseluisgs.models.Persona
4 | import dev.joseluisgs.repositories.crud.CrudRepository
5 |
6 | class PersonasRepository : CrudRepository {
7 | private var personas = mutableListOf()
8 | private var key: Int = 0
9 |
10 | override fun getAll(): List {
11 | return personas.toList()
12 | }
13 |
14 | override fun getById(key: Int): Persona? {
15 | return personas.firstOrNull { it.id == key }
16 | }
17 |
18 | override fun delete(key: Int): Persona? {
19 | // sacamos su indice
20 | var persona: Persona? = null
21 | val index = personas.indexOfFirst { it.id == key }
22 | if (index != -1) {
23 | persona = personas[index]
24 | personas.removeAt(index)
25 | }
26 | return persona
27 | }
28 |
29 | override fun update(key: Int, value: Persona): Persona? {
30 | return getById(key)?.apply {
31 | name = value.name
32 | email = value.email
33 | }
34 | }
35 |
36 | override fun save(value: Persona): Persona {
37 | // Si el array está lleno (no tiene nulos)
38 | key++ // Incrementamos la clave
39 | value.id = key // Asignamos la clave
40 | personas.add(value) // Añadimos el valor
41 | return value // Devolvemos el valor
42 | }
43 |
44 |
45 | }
--------------------------------------------------------------------------------
/Soluciones/13-Colecciones-Pila/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/Soluciones/13-Colecciones-Pila/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Soluciones/13-Colecciones-Pila/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Soluciones/13-Colecciones-Pila/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/13-Colecciones-Pila/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/13-Colecciones-Pila/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Soluciones/13-Colecciones-Pila/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.22"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | testImplementation("org.jetbrains.kotlin:kotlin-test")
14 | }
15 |
16 | tasks.test {
17 | useJUnitPlatform()
18 | }
19 | kotlin {
20 | jvmToolchain(21)
21 | }
--------------------------------------------------------------------------------
/Soluciones/13-Colecciones-Pila/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/13-Colecciones-Pila/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/13-Colecciones-Pila/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/13-Colecciones-Pila/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Feb 01 15:26:57 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/13-Colecciones-Pila/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "Colecciones-Pila"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/13-Colecciones-Pila/src/main/kotlin/Main.kt:
--------------------------------------------------------------------------------
1 | fun main() {
2 | val pila = Pila()
3 |
4 | pila.push(1)
5 | pila.push(2)
6 | pila.push(3)
7 | println(pila.peek())
8 | println(pila.pop())
9 |
10 | while (!pila.isEmpty()) {
11 | println(pila.pop())
12 | }
13 |
14 | println(pila.isEmpty())
15 | }
--------------------------------------------------------------------------------
/Soluciones/13-Colecciones-Pila/src/main/kotlin/Pila.kt:
--------------------------------------------------------------------------------
1 | class Pila : Stack {
2 | private val elementos = mutableListOf()
3 |
4 | override fun push(element: T) {
5 | elementos.add(element)
6 | }
7 |
8 | override fun pop(): T? {
9 | if (isEmpty()) {
10 | return null
11 | }
12 | return elementos.removeAt(elementos.size - 1)
13 | }
14 |
15 | override fun peek(): T? {
16 | if (isEmpty()) {
17 | return null
18 | }
19 | return elementos[elementos.size - 1]
20 | }
21 |
22 | override fun isEmpty(): Boolean {
23 | return elementos.isEmpty()
24 | }
25 |
26 | override fun size(): Int {
27 | return elementos.size
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Soluciones/13-Colecciones-Pila/src/main/kotlin/Stack.kt:
--------------------------------------------------------------------------------
1 | interface Stack {
2 | fun push(element: T)
3 | fun pop(): T?
4 | fun peek(): T?
5 | fun isEmpty(): Boolean
6 | fun size(): Int
7 | }
--------------------------------------------------------------------------------
/Soluciones/14-Colecciones-Cola/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/Soluciones/14-Colecciones-Cola/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Soluciones/14-Colecciones-Cola/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Soluciones/14-Colecciones-Cola/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/14-Colecciones-Cola/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/14-Colecciones-Cola/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Soluciones/14-Colecciones-Cola/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.22"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | testImplementation("org.jetbrains.kotlin:kotlin-test")
14 | }
15 |
16 | tasks.test {
17 | useJUnitPlatform()
18 | }
19 | kotlin {
20 | jvmToolchain(21)
21 | }
--------------------------------------------------------------------------------
/Soluciones/14-Colecciones-Cola/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/14-Colecciones-Cola/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/14-Colecciones-Cola/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/14-Colecciones-Cola/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Feb 01 15:33:03 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/14-Colecciones-Cola/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "Colecciones-Cola"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/14-Colecciones-Cola/src/main/kotlin/Cola.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | class Cola : Queue {
4 | private val elementos = mutableListOf()
5 |
6 | override fun enqueue(element: T) {
7 | elementos.add(element)
8 | }
9 |
10 | override fun dequeue(): T? {
11 | return if (elementos.isNotEmpty())
12 | elementos.removeAt(0)
13 | else null
14 | }
15 |
16 | override fun peek(): T? {
17 | return if (elementos.isNotEmpty())
18 | elementos[0]
19 | else null
20 | }
21 |
22 | override fun isEmpty(): Boolean {
23 | return elementos.isEmpty()
24 | }
25 |
26 | override fun size(): Int {
27 | return elementos.size
28 | }
29 | }
--------------------------------------------------------------------------------
/Soluciones/14-Colecciones-Cola/src/main/kotlin/Main.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | fun main() {
4 | val cola = Cola()
5 | cola.enqueue(1)
6 | cola.enqueue(2)
7 | cola.enqueue(3)
8 |
9 | println(cola.peek())
10 | println(cola.dequeue())
11 |
12 | while (!cola.isEmpty()) {
13 | println(cola.dequeue())
14 | }
15 |
16 | println(cola.isEmpty())
17 | }
--------------------------------------------------------------------------------
/Soluciones/14-Colecciones-Cola/src/main/kotlin/Queue.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | interface Queue {
4 | fun enqueue(element: T)
5 | fun dequeue(): T?
6 | fun peek(): T?
7 | fun isEmpty(): Boolean
8 | fun size(): Int
9 | }
--------------------------------------------------------------------------------
/Soluciones/15-Colecciones-Conjuntos/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/Soluciones/15-Colecciones-Conjuntos/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Soluciones/15-Colecciones-Conjuntos/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Soluciones/15-Colecciones-Conjuntos/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/15-Colecciones-Conjuntos/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/15-Colecciones-Conjuntos/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Soluciones/15-Colecciones-Conjuntos/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.22"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | testImplementation("org.jetbrains.kotlin:kotlin-test")
14 | }
15 |
16 | tasks.test {
17 | useJUnitPlatform()
18 | }
19 | kotlin {
20 | jvmToolchain(21)
21 | }
--------------------------------------------------------------------------------
/Soluciones/15-Colecciones-Conjuntos/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/15-Colecciones-Conjuntos/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/15-Colecciones-Conjuntos/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/15-Colecciones-Conjuntos/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Feb 02 18:05:47 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/15-Colecciones-Conjuntos/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "Colecciones-Conjuntos"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/15-Colecciones-Conjuntos/src/main/kotlin/Main.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | import java.util.*
4 |
5 | fun main() {
6 | val p = Persona("José Luis", 29, "12345678Z", 1000.0)
7 | val p2 = Persona("Ana", 22, "12345678Z", 800.0)
8 | val p3 = Persona("José Luis", 29, "12345678Z", 1000.0)
9 |
10 | val personasLista = listOf(p, p, p, p, p, p, p, p2, p3)
11 | println("Con list:")
12 | personasLista.forEach { println(it) }
13 |
14 | println("Con Set:")
15 | val personasSet = setOf(p, p, p, p, p, p, p, p2, p3)
16 | personasSet.forEach { println(it) }
17 |
18 | val personasHashSet = HashSet()
19 | personasHashSet.add(p)
20 | personasHashSet.add(p)
21 | personasHashSet.add(p2)
22 | personasHashSet.add(p3)
23 |
24 | println("Con HashSet:")
25 | personasHashSet.forEach { println(it) }
26 |
27 |
28 | val personasTreeSet = TreeSet { p1, p2 -> p1.edad.compareTo(p2.edad) }
29 | personasTreeSet.add(p)
30 | personasTreeSet.add(p)
31 | personasTreeSet.add(p2)
32 | personasTreeSet.add(p3)
33 |
34 | println("Con TreeSet:")
35 | personasTreeSet.forEach { println(it) }
36 | }
--------------------------------------------------------------------------------
/Soluciones/15-Colecciones-Conjuntos/src/main/kotlin/Persona.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | data class Persona(val nombre: String, val edad: Int, val dni: String, val salario: Double)
4 |
--------------------------------------------------------------------------------
/Soluciones/16-Comparable-Comparator/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/Soluciones/16-Comparable-Comparator/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Soluciones/16-Comparable-Comparator/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Soluciones/16-Comparable-Comparator/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/16-Comparable-Comparator/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/16-Comparable-Comparator/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Soluciones/16-Comparable-Comparator/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.22"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | testImplementation("org.jetbrains.kotlin:kotlin-test")
14 | }
15 |
16 | tasks.test {
17 | useJUnitPlatform()
18 | }
19 | kotlin {
20 | jvmToolchain(21)
21 | }
--------------------------------------------------------------------------------
/Soluciones/16-Comparable-Comparator/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/16-Comparable-Comparator/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/16-Comparable-Comparator/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/16-Comparable-Comparator/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Feb 02 17:46:16 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/16-Comparable-Comparator/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "Comparable-Comparator"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/16-Comparable-Comparator/src/main/kotlin/Main.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | fun main() {
4 | val listaPersonas = listOf(
5 | Persona("Jose", 30),
6 | Persona("Luis", 20),
7 | Persona("Ana", 25)
8 | )
9 |
10 | if (listaPersonas[0] > listaPersonas[1]) {
11 | println("${listaPersonas[0]} es mayor que ${listaPersonas[1]}")
12 | } else {
13 | println("${listaPersonas[0]} es menor que ${listaPersonas[1]}")
14 | }
15 |
16 | println("Ordenamos la lista de personas por edad")
17 | val listaOrdenada = listaPersonas.sorted()
18 | listaOrdenada.forEach { println(it) }
19 |
20 | val comparatorNombre = Comparator { p1, p2 ->
21 | p1.nombre.compareTo(p2.nombre)
22 | }
23 |
24 | // comparator por edad descendente
25 | val comparatorEdad = Comparator { p1, p2 ->
26 | p2.edad.compareTo(p1.edad)
27 | }
28 |
29 | println("Ordenamos la lista de personas por nombre")
30 | val listaOrdenadaNombre = listaPersonas.sortedWith(comparatorNombre)
31 | listaOrdenadaNombre.forEach { println(it) }
32 |
33 | println("Ordenamos la lista de personas por edad descendente")
34 | val listaOrdenadaEdad = listaPersonas.sortedWith(comparatorEdad)
35 | listaOrdenadaEdad.forEach { println(it) }
36 |
37 | val listaOrdenadaEdadDescendente = listaPersonas.sortedWith { p1, p2 -> p2.edad.compareTo(p1.edad) }
38 | listaOrdenadaEdadDescendente.forEach { println(it) }
39 |
40 | val listaOrdenadaEdadDescendente2 = listaPersonas.sortedBy { it.edad } // Hace el comparator
41 | listaOrdenadaEdadDescendente2.forEach { println(it) }
42 | }
--------------------------------------------------------------------------------
/Soluciones/16-Comparable-Comparator/src/main/kotlin/Persona.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | data class Persona(val nombre: String, val edad: Int) : Comparable {
4 | override fun compareTo(other: Persona): Int {
5 | return this.edad - other.edad
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/Soluciones/17-Colecciones-Mapas/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/Soluciones/17-Colecciones-Mapas/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Soluciones/17-Colecciones-Mapas/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Soluciones/17-Colecciones-Mapas/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/17-Colecciones-Mapas/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/17-Colecciones-Mapas/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Soluciones/17-Colecciones-Mapas/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.22"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | testImplementation("org.jetbrains.kotlin:kotlin-test")
14 | }
15 |
16 | tasks.test {
17 | useJUnitPlatform()
18 | }
19 | kotlin {
20 | jvmToolchain(21)
21 | }
--------------------------------------------------------------------------------
/Soluciones/17-Colecciones-Mapas/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/17-Colecciones-Mapas/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/17-Colecciones-Mapas/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/17-Colecciones-Mapas/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Feb 05 15:33:29 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/17-Colecciones-Mapas/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "Colecciones-Mapas"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/18-Palindromo/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/Soluciones/18-Palindromo/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Soluciones/18-Palindromo/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Soluciones/18-Palindromo/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/18-Palindromo/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/18-Palindromo/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Soluciones/18-Palindromo/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.22"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | testImplementation("org.jetbrains.kotlin:kotlin-test")
14 | }
15 |
16 | tasks.test {
17 | useJUnitPlatform()
18 | }
19 | kotlin {
20 | jvmToolchain(21)
21 | }
--------------------------------------------------------------------------------
/Soluciones/18-Palindromo/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/18-Palindromo/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/18-Palindromo/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/18-Palindromo/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Feb 05 16:35:12 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/18-Palindromo/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "Palindromo"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/18-Palindromo/src/main/kotlin/Main.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | fun main() {
4 | val p1 = "Se verla al reves"
5 | val p2 = "Anita lava la tina"
6 |
7 | println(p1)
8 | println("Iterativo: $p1 es palindromo: ${palindromoIterativo(p1)}")
9 | println("Funciones: $p1 es palindromo: ${palindromoFunciones(p1)}")
10 | println("Pilas y Colas: $p1 es palindromo: ${palindromePilasYColas(p1)}")
11 | println("Pilas y Colas Extensiones: $p1 es palindromo: ${palindromePilasYColasExtensiones(p1)}")
12 |
13 | println()
14 | println(p2)
15 | println("Iterativo: $p2 es palindromo: ${palindromoIterativo(p2)}")
16 | println("Funciones: $p2 es palindromo: ${palindromoFunciones(p2)}")
17 | println("Pilas y Colas: $p2 es palindromo: ${palindromePilasYColas(p2)}")
18 | println("Pilas y Colas Extensiones: $p2 es palindromo: ${palindromePilasYColasExtensiones(p2)}")
19 |
20 | }
21 |
22 | fun palindromoIterativo(palabra: String): Boolean {
23 | val palabraLimpia = palabra.replace(" ", "").lowercase()
24 | val longitud = palabraLimpia.length
25 | for (i in 0 until longitud / 2) {
26 | if (palabraLimpia[i] != palabraLimpia[longitud - i - 1]) {
27 | return false
28 | }
29 | }
30 | return true
31 | }
32 |
33 | fun palindromoFunciones(palabra: String): Boolean {
34 | val palabraLimpia = palabra.replace(" ", "").lowercase()
35 | return palabraLimpia == palabraLimpia.reversed()
36 | }
37 |
38 | fun palindromePilasYColas(palabra: String): Boolean {
39 | val palabraLimpia = palabra.replace(" ", "").lowercase()
40 | val longitud = palabraLimpia.length
41 | val pila = mutableListOf()
42 | val cola = mutableListOf()
43 | for (i in 0 until longitud) {
44 | pila.add(palabraLimpia[i])
45 | cola.add(palabraLimpia[longitud - i - 1])
46 | }
47 | return pila == cola
48 | }
49 |
50 | // funcioens de extensionpara crear una pila en un array list de char
51 | fun MutableList.push(element: Char) = this.add(element)
52 | fun MutableList.pop() = this.removeAt(this.size - 1)
53 |
54 | // funcioens de extension para crear una cola en un array list de char
55 | fun MutableList.enqueue(element: Char) = this.add(element)
56 | fun MutableList.dequeue() = this.removeAt(0)
57 |
58 | fun palindromePilasYColasExtensiones(palabra: String): Boolean {
59 | val palabraLimpia = palabra.replace(" ", "").lowercase()
60 | val longitud = palabraLimpia.length
61 | val pila = mutableListOf()
62 | val cola = mutableListOf()
63 | for (i in 0 until longitud) {
64 | pila.push(palabraLimpia[i])
65 | cola.enqueue(palabraLimpia[i])
66 | }
67 | return pila == cola
68 | }
--------------------------------------------------------------------------------
/Soluciones/19-Colecciones-Repository/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/Soluciones/19-Colecciones-Repository/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Soluciones/19-Colecciones-Repository/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Soluciones/19-Colecciones-Repository/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/19-Colecciones-Repository/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/19-Colecciones-Repository/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Soluciones/19-Colecciones-Repository/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.22"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | testImplementation("org.jetbrains.kotlin:kotlin-test")
14 | }
15 |
16 | tasks.test {
17 | useJUnitPlatform()
18 | }
19 | kotlin {
20 | jvmToolchain(21)
21 | }
--------------------------------------------------------------------------------
/Soluciones/19-Colecciones-Repository/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/19-Colecciones-Repository/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/19-Colecciones-Repository/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/19-Colecciones-Repository/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Feb 05 15:43:17 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/19-Colecciones-Repository/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "Colecciones-Repository"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/19-Colecciones-Repository/src/main/kotlin/CrudRepository.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | interface CrudRepository {
4 | fun findAll(): List
5 | fun findById(id: ID): T?
6 | fun save(t: T): T
7 | fun update(id: ID, t: T): T?
8 | fun delete(id: ID): T?
9 | }
--------------------------------------------------------------------------------
/Soluciones/19-Colecciones-Repository/src/main/kotlin/Main.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | fun main() {
4 | println("Hello World!")
5 | }
--------------------------------------------------------------------------------
/Soluciones/19-Colecciones-Repository/src/main/kotlin/Persona.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | import java.time.LocalDateTime
4 |
5 | data class Persona(
6 | val id: Int = 0,
7 | val nombre: String,
8 | val edad: Int,
9 | val createdAt: LocalDateTime = LocalDateTime.now(),
10 | val updatedAt: LocalDateTime = LocalDateTime.now()
11 | ) {
12 | companion object {
13 | private var nextId = 0
14 | fun getNextId() = nextId++
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Soluciones/19-Colecciones-Repository/src/main/kotlin/PersonasExceptions.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | sealed class PersonasExceptions(message: String) : Exception(message) {
4 | class PersonaNotFoundException(id: Int) : PersonasExceptions("Persona no encontrada, con id: $id")
5 | class PersonaSaveException(persona: Persona) : PersonasExceptions("Error al guardar la persona: $persona")
6 | }
--------------------------------------------------------------------------------
/Soluciones/19-Colecciones-Repository/src/main/kotlin/PersonasMapRepository.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | import java.time.LocalDateTime
4 | import java.util.*
5 |
6 | class PersonasMapRepository : PersonasRepository {
7 | // val personas: MutableMap = mutableMapOf()
8 | val personas: TreeMap = TreeMap()
9 |
10 | override fun findAll(): List {
11 | // return personas.toSortedMap().values.toList()
12 | // return personas.values.sortedBy { it.id }.toList()
13 | return personas.values.toList()
14 | }
15 |
16 | override fun findById(id: Int): Persona? {
17 | return personas[id]
18 | }
19 |
20 | override fun findByNombre(nombre: String): List {
21 | return personas.values.filter { it.nombre.contains(nombre, ignoreCase = true) }
22 | }
23 |
24 | override fun save(t: Persona): Persona {
25 | val personaToSave = t.copy(
26 | id = Persona.getNextId(),
27 | createdAt = LocalDateTime.now(),
28 | updatedAt = LocalDateTime.now()
29 | )
30 | personas[personaToSave.id] = personaToSave
31 | return personaToSave
32 | }
33 |
34 | override fun update(id: Int, t: Persona): Persona? {
35 | return personas[id]?.let {
36 | val personaToUpdate = t.copy(
37 | id = it.id,
38 | createdAt = it.createdAt,
39 | updatedAt = LocalDateTime.now()
40 | )
41 | personas[id] = personaToUpdate
42 | return personaToUpdate
43 | }
44 | }
45 |
46 | override fun delete(id: Int): Persona? {
47 | return personas.remove(id)
48 | }
49 | }
--------------------------------------------------------------------------------
/Soluciones/19-Colecciones-Repository/src/main/kotlin/PersonasRepository.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | interface PersonasRepository : CrudRepository {
4 | fun findByNombre(nombre: String): List
5 |
6 | }
--------------------------------------------------------------------------------
/Soluciones/19-Colecciones-Repository/src/main/kotlin/PersonasSetRepository.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | import java.time.LocalDateTime
4 | import java.util.*
5 |
6 | class PersonasSetRepository : PersonasRepository {
7 | // private val personas = mutableSetOf()
8 | private val personas: TreeSet = TreeSet { p1, p2 -> p1.id.compareTo(p2.id) }
9 |
10 | override fun findAll(): List {
11 | // return personas.sortedBy { it.id }.toList()
12 | return personas.toList()
13 | }
14 |
15 | override fun findById(id: Int): Persona? {
16 | return personas.find { it.id == id }
17 | }
18 |
19 | override fun findByNombre(nombre: String): List {
20 | return personas.filter { it.nombre.contains(nombre, ignoreCase = true) }
21 | }
22 |
23 | override fun save(t: Persona): Persona {
24 | val personaToSave = t.copy(
25 | id = Persona.getNextId(),
26 | createdAt = LocalDateTime.now(),
27 | updatedAt = LocalDateTime.now()
28 | )
29 | personas.add(personaToSave)
30 | return personaToSave
31 | }
32 |
33 | override fun update(id: Int, t: Persona): Persona? {
34 | return personas.find { it.id == id }?.let {
35 | personas.remove(it)
36 | val personaToUpdate = t.copy(
37 | id = it.id,
38 | nombre = t.nombre,
39 | edad = t.edad,
40 | createdAt = it.createdAt,
41 | updatedAt = LocalDateTime.now()
42 | )
43 | personas.add(personaToUpdate)
44 | return personaToUpdate
45 | }
46 | }
47 |
48 | override fun delete(id: Int): Persona? {
49 | return personas.find { it.id == id }?.let {
50 | personas.remove(it)
51 | return it
52 | }
53 | }
54 | }
--------------------------------------------------------------------------------
/Soluciones/19-Colecciones-Repository/src/main/kotlin/PesonasListRepository.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | import java.time.LocalDateTime
4 |
5 | class PesonasListRepository : PersonasRepository {
6 |
7 | private val personas = mutableListOf()
8 |
9 | override fun findAll(): List {
10 | return personas.sortedBy { it.id }.toList()
11 | }
12 |
13 | override fun findById(id: Int): Persona? {
14 | return personas.find { it.id == id }
15 | }
16 |
17 | override fun findByNombre(nombre: String): List {
18 | return personas.filter { it.nombre.contains(nombre, ignoreCase = true) }
19 | }
20 |
21 | override fun save(t: Persona): Persona {
22 | val personaToSave = t.copy(
23 | id = Persona.getNextId(),
24 | createdAt = LocalDateTime.now(),
25 | updatedAt = LocalDateTime.now()
26 | )
27 | personas.add(personaToSave)
28 | return personaToSave
29 | }
30 |
31 | override fun update(id: Int, t: Persona): Persona? {
32 | val index = personas.indexOfFirst { it.id == id }
33 | if (index != -1) {
34 | val personaToUpdate = t.copy(
35 | id = id,
36 | nombre = t.nombre,
37 | edad = t.edad,
38 | createdAt = personas[index].createdAt,
39 | updatedAt = LocalDateTime.now()
40 | )
41 | personas[index] = personaToUpdate
42 | return personaToUpdate
43 | }
44 | return null
45 | }
46 |
47 | override fun delete(id: Int): Persona? {
48 | return personas.find { it.id == id }?.let {
49 | personas.remove(it)
50 | return it
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.22"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | testImplementation("org.jetbrains.kotlin:kotlin-test")
14 | }
15 |
16 | tasks.test {
17 | useJUnitPlatform()
18 | }
19 | kotlin {
20 | jvmToolchain(21)
21 | }
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/20-PlanificadorProcesosPrioridad/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Feb 06 15:49:35 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "PlanificadorProcesosPrioridad"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/src/main/kotlin/Cola.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | interface Cola {
4 | fun enqueue(elemento: T)
5 | fun dequeue(): T?
6 | fun isEmpty(): Boolean
7 | fun first(): T?
8 | fun size(): Int
9 | override fun toString(): String
10 | }
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/src/main/kotlin/ColaProcesosLista.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | class ColaProcesosLista : Cola {
4 | private val cola: MutableList = mutableListOf()
5 |
6 | override fun enqueue(elemento: Proceso) {
7 | cola.add(elemento)
8 | }
9 |
10 | override fun dequeue(): Proceso? {
11 | return cola.removeFirst()
12 | }
13 |
14 | override fun isEmpty(): Boolean {
15 | return cola.isEmpty()
16 | }
17 |
18 | override fun first(): Proceso {
19 | return cola.first()
20 | }
21 |
22 | override fun size(): Int {
23 | return cola.size
24 | }
25 |
26 | override fun toString(): String {
27 | // return cola.joinToString(separator = ", ", prefix = "[", postfix = "]", limit = 10, truncated = "...")
28 | return cola.toString()
29 | }
30 | }
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/src/main/kotlin/ColaProcesosPrioritariosLista.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | class ColaProcesosPrioritariosLista : Cola {
4 | private val cola: MutableList = mutableListOf()
5 |
6 | override fun enqueue(elemento: Proceso) {
7 | cola.add(elemento)
8 | // cola.sortBy { it.prioridad }
9 | }
10 |
11 | override fun dequeue(): Proceso? {
12 | // return cola.removeFirst()
13 | return cola.minByOrNull { it.prioridad }?.let {
14 | cola.remove(it)
15 | it
16 | }
17 | }
18 |
19 | override fun isEmpty(): Boolean {
20 | return cola.isEmpty()
21 | }
22 |
23 | override fun first(): Proceso {
24 | return cola.first()
25 | }
26 |
27 | override fun size(): Int {
28 | return cola.size
29 | }
30 |
31 | override fun toString(): String {
32 | // return cola.joinToString(separator = ", ", prefix = "[", postfix = "]", limit = 10, truncated = "...")
33 | return cola.toString()
34 | }
35 | }
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/src/main/kotlin/ColaProcesosPrioritariosMap.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | class ColaProcesosPrioritariosMap : Cola {
4 | private val cola = mutableMapOf()
5 |
6 | override fun enqueue(elemento: Proceso) {
7 | cola[elemento.id] = elemento
8 | }
9 |
10 | override fun dequeue(): Proceso? {
11 | return cola.values.minByOrNull { it.prioridad }?.also {
12 | cola.remove(it.id) // como estamos usando el id como clave, lo eliminamos
13 | }
14 | }
15 |
16 | override fun isEmpty(): Boolean {
17 | return cola.isEmpty()
18 | }
19 |
20 | override fun first(): Proceso {
21 | return cola.values.first()
22 | }
23 |
24 | override fun size(): Int {
25 | return cola.size
26 | }
27 |
28 | override fun toString(): String {
29 | //return cola.values.joinToString(separator = ", ", prefix = "[", postfix = "]", limit = 10, truncated = "...")
30 | return cola.toString()
31 | }
32 | }
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/src/main/kotlin/ColaProcesosPrioritariosTreeMapList.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | import java.util.*
4 |
5 | class ColaProcesosPrioritariosTreeMapList : Cola {
6 | private val cola: TreeMap> = TreeMap()
7 |
8 | override fun enqueue(elemento: Proceso) {
9 | /*if (cola.containsKey(elemento.prioridad)) {
10 | cola[elemento.prioridad]?.add(elemento)
11 | } else {
12 | cola[elemento.prioridad] = mutableListOf(elemento)
13 | }*/
14 | // Lo importante de saberse el API de las colecciones :)
15 | // cola.computeIfAbsent(elemento.prioridad) { mutableListOf() }.add(elemento)
16 |
17 | // Otra forma de hacerlo
18 | cola.containsKey(elemento.prioridad).let {
19 | cola[elemento.prioridad]?.add(elemento)
20 | } ?: run {
21 | cola[elemento.prioridad] = mutableListOf(elemento)
22 | }
23 |
24 | }
25 |
26 | override fun dequeue(): Proceso? {
27 | /* val first = cola.values.firstOrNull()
28 | val proceso = first?.removeAt(0)
29 | if (first?.isEmpty() == true) {
30 | cola.remove(cola.firstKey())
31 | }
32 | return proceso*/
33 |
34 | // Otra forma de hacerlo
35 | return cola.values.firstOrNull()?.let {
36 | val proceso = it.removeAt(0)
37 | if (it.isEmpty()) {
38 | cola.remove(cola.firstKey())
39 | }
40 | proceso
41 | }
42 | }
43 |
44 | override fun isEmpty(): Boolean {
45 | return cola.isEmpty()
46 | }
47 |
48 | override fun first(): Proceso {
49 | return cola.values.first().first()
50 | }
51 |
52 | override fun size(): Int {
53 | return cola.values.sumOf { it.size }
54 | }
55 |
56 | override fun toString(): String {
57 | //return cola.values.joinToString(separator = ", ", prefix = "[", postfix = "]", limit = 10, truncated = "...")
58 | return cola.toString()
59 | }
60 | }
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/src/main/kotlin/ColaProcesosPrioritariosTreeMapMap.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | import java.util.*
4 |
5 | class ColaProcesosPrioritariosTreeMapMap : Cola {
6 | // podria ser un hashMap, o un MutableMap por defecto
7 | private val cola: TreeMap> = TreeMap()
8 |
9 | override fun enqueue(elemento: Proceso) {
10 | /*val prioridad = elemento.prioridad
11 | val procesos = cola.getOrPut(prioridad) { TreeMap() }
12 | val id = elemento.id
13 | procesos[id] = elemento*/
14 |
15 | // Otra forma de hacerlo
16 | cola.computeIfAbsent(elemento.prioridad) { TreeMap() }[elemento.id] = elemento
17 |
18 | }
19 |
20 | override fun dequeue(): Proceso {
21 | // forma más rapida de hacerlo
22 | /*val prioridad = cola.firstKey()
23 | val procesos = cola[prioridad]
24 | val proceso = procesos?.values?.first()
25 | if (procesos != null) {
26 | if (procesos.size > 1) {
27 | procesos.remove(proceso?.id)
28 | } else {
29 | cola.remove(prioridad)
30 | }
31 | }
32 | return proceso*/
33 |
34 | // otra forma con programación funcional
35 | return cola.values.first().values.first().also {
36 | cola.values.first().remove(it.id)
37 | if (cola.values.first().isEmpty()) {
38 | cola.remove(cola.firstKey())
39 | }
40 | }
41 | }
42 |
43 | override fun isEmpty(): Boolean {
44 | return cola.isEmpty()
45 | }
46 |
47 | override fun first(): Proceso {
48 | return cola.values.first().values.first()
49 | }
50 |
51 | override fun size(): Int {
52 | return cola.values.sumOf { it.size }
53 | }
54 |
55 | override fun toString(): String {
56 | //return cola.values.joinToString(separator = ", ", prefix = "[", postfix = "]", limit = 10, truncated = "...")
57 | return cola.toString()
58 | }
59 | }
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/src/main/kotlin/ColaProcesosPrioritariosTreeSet.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | import java.util.*
4 |
5 | class ColaProcesosPrioritariosTreeSet : Cola {
6 | private val cola = TreeSet { p1, p2 ->
7 | // Si la prioridad es distinta, ordenamos por prioridad
8 | if (p1.prioridad != p2.prioridad) {
9 | p1.prioridad.compareTo(p2.prioridad)
10 | } else {
11 | // Si la prioridad es igual, ordenamos por tiempo
12 | p1.id.compareTo(p2.id)
13 | }
14 | }
15 |
16 | override fun enqueue(elemento: Proceso) {
17 | cola.add(elemento)
18 | }
19 |
20 | override fun dequeue(): Proceso? {
21 | return cola.removeFirst()
22 | }
23 |
24 | override fun isEmpty(): Boolean {
25 | return cola.isEmpty()
26 | }
27 |
28 | override fun first(): Proceso? {
29 | return cola.first()
30 | }
31 |
32 | override fun size(): Int {
33 | return cola.size
34 | }
35 |
36 | override fun toString(): String {
37 | return cola.joinToString(separator = ", ", prefix = "[", postfix = "]", limit = 10, truncated = "...")
38 | }
39 | }
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/src/main/kotlin/Planificador.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | import kotlin.system.measureTimeMillis
4 |
5 | class Planificador(
6 | private val colaProcesos: Cola,
7 | private val quatum: Int = 2,
8 | private var numEjecuciones: Int = 0,
9 | private var numTiempoEjecucion: Int = 0
10 | ) {
11 |
12 | fun agregarProceso(proceso: Proceso) {
13 | colaProcesos.enqueue(proceso)
14 | }
15 |
16 | fun ejecutar() {
17 | val time = measureTimeMillis {
18 | while (!colaProcesos.isEmpty()) {
19 | val proceso = colaProcesos.dequeue()
20 | println("Ejecutando proceso: $proceso")
21 | proceso?.let {
22 | it.tiempo -= quatum
23 | numEjecuciones++
24 | numTiempoEjecucion += quatum
25 | if (it.isActive) {
26 | println("Proceso: $proceso, tiempo restante: ${it.tiempo}")
27 | // Simulamos que el 25% de ls veces cambia la prioridad de 1..9
28 | /*if ((1..100).random() <= 25) {
29 | it.prioridad = (1..9).random()
30 | println("Proceso: $proceso, cambio de prioridad a: ${it.prioridad}")
31 | }*/
32 | colaProcesos.enqueue(it)
33 | } else {
34 | println("Proceso: $proceso, terminado")
35 | }
36 | }
37 | }
38 | }
39 | println("Numero de ejecuciones: $numEjecuciones")
40 | println("Numero de tiempo de ejecucion: $numTiempoEjecucion")
41 | println("Tiempo total de ejecucion: $time")
42 | }
43 |
44 | fun size(): Int {
45 | return colaProcesos.size()
46 | }
47 |
48 | override fun toString(): String {
49 | return colaProcesos.toString()
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/src/main/kotlin/Proceso.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | import java.time.LocalDateTime
4 |
5 | data class Proceso(
6 | val id: Int,
7 | private var _tiempo: Int = (1..20).random(),
8 | private var _prioridad: Int = (1..9).random(),
9 | val createdAt: LocalDateTime = LocalDateTime.now(),
10 | var updatedAt: LocalDateTime = LocalDateTime.now()
11 | ) {
12 | var tiempo: Int
13 | get() = _tiempo
14 | set(value) {
15 | _tiempo = if (value < 0) {
16 | 0
17 | } else {
18 | value
19 | }
20 | updatedAt = LocalDateTime.now()
21 | }
22 |
23 | var prioridad: Int
24 | get() = _prioridad
25 | set(value) {
26 | _prioridad = if (value < 1) {
27 | 1
28 | } else if (value > 9) {
29 | 9
30 | } else {
31 | value
32 | }
33 | }
34 |
35 | val isActive: Boolean
36 | get() = _tiempo > 0
37 |
38 | override fun toString(): String {
39 | return "Proceso(id=$id, tiempo=$tiempo, prioridad=$prioridad, createdAt=$createdAt, updatedAt=$updatedAt)"
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/src/main/kotlin/ProcesosFactory.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | object ProcesosFactory {
4 | fun create(): Proceso {
5 | return Proceso(
6 | id = nextId,
7 | _tiempo = (1..20).random(),
8 | _prioridad = (1..9).random()
9 | )
10 | }
11 |
12 | private var lastId = 1
13 | private val nextId: Int
14 | get() = lastId++
15 | }
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/src/test/kotlin/ColaProcesosListaTest.kt:
--------------------------------------------------------------------------------
1 | import dev.joseluisgs.ColaProcesosLista
2 | import dev.joseluisgs.Proceso
3 | import org.junit.jupiter.api.Assertions.assertEquals
4 | import org.junit.jupiter.api.BeforeEach
5 | import org.junit.jupiter.api.Test
6 |
7 | class ColaProcesosListaTest {
8 |
9 | var cola = ColaProcesosLista()
10 |
11 | @BeforeEach
12 | fun setUp() {
13 | cola = ColaProcesosLista()
14 | cola.enqueue(Proceso(1, 1, 3))
15 | cola.enqueue(Proceso(2, 2, 1))
16 | cola.enqueue(Proceso(3, 3, 2))
17 | }
18 |
19 | @Test
20 | fun enqueue() {
21 | cola.enqueue(Proceso(4, 4, 4))
22 | org.junit.jupiter.api.assertAll(
23 | { assertEquals(4, cola.size()) },
24 | { assertEquals(3, cola.first().prioridad) },
25 | { assertEquals(1, cola.first().tiempo) },
26 | { assertEquals(1, cola.first().id) }
27 | )
28 | }
29 |
30 | @Test
31 | fun dequeue() {
32 | val p = cola.dequeue()
33 | org.junit.jupiter.api.assertAll(
34 | { assertEquals(2, cola.size()) },
35 | { assertEquals(1, p?.id) },
36 | { assertEquals(3, p?.prioridad) },
37 | { assertEquals(1, p?.tiempo) },
38 | { assertEquals(2, cola.first().id) },
39 | { assertEquals(1, cola.first().prioridad) },
40 | { assertEquals(2, cola.first().tiempo) }
41 | )
42 | }
43 |
44 | @Test
45 | fun isEmpty() {
46 | cola.dequeue()
47 | cola.dequeue()
48 | cola.dequeue()
49 | org.junit.jupiter.api.assertAll(
50 | { assertEquals(true, cola.isEmpty()) }
51 | )
52 | }
53 |
54 | @Test
55 | fun first() {
56 | org.junit.jupiter.api.assertAll(
57 | { assertEquals(1, cola.first().id) },
58 | { assertEquals(3, cola.first().prioridad) },
59 | { assertEquals(1, cola.first().tiempo) }
60 | )
61 | }
62 |
63 | @Test
64 | fun size() {
65 | org.junit.jupiter.api.assertAll(
66 | { assertEquals(3, cola.size()) }
67 | )
68 | }
69 | }
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/src/test/kotlin/ColaProcesosPrioritariosListaTest.kt:
--------------------------------------------------------------------------------
1 | import dev.joseluisgs.ColaProcesosPrioritariosLista
2 | import dev.joseluisgs.Proceso
3 | import org.junit.jupiter.api.Assertions.assertEquals
4 | import org.junit.jupiter.api.BeforeEach
5 | import org.junit.jupiter.api.Test
6 |
7 | class ColaProcesosPrioritariosListaTest {
8 |
9 | var cola = ColaProcesosPrioritariosLista()
10 |
11 | @BeforeEach
12 | fun setUp() {
13 | cola = ColaProcesosPrioritariosLista()
14 | cola.enqueue(Proceso(1, 1, 3))
15 | cola.enqueue(Proceso(2, 2, 1))
16 | cola.enqueue(Proceso(3, 3, 2))
17 | }
18 |
19 | @Test
20 | fun enqueue() {
21 | cola.enqueue(Proceso(4, 4, 4))
22 | // Cuidado con los test que dependen del orden si esta puesto que se ordene en insercción o en salida
23 | org.junit.jupiter.api.assertAll(
24 | { assertEquals(4, cola.size()) },
25 | { assertEquals(1, cola.first().id) },
26 | { assertEquals(3, cola.first().prioridad) },
27 | { assertEquals(1, cola.first().tiempo) }
28 | )
29 | }
30 |
31 | @Test
32 | fun dequeue() {
33 | val p = cola.dequeue()
34 | org.junit.jupiter.api.assertAll(
35 | { assertEquals(2, cola.size()) },
36 | { assertEquals(2, p?.id) },
37 | { assertEquals(1, p?.prioridad) },
38 | { assertEquals(2, p?.tiempo) }
39 | )
40 | }
41 |
42 | @Test
43 | fun isEmpty() {
44 | cola.dequeue()
45 | cola.dequeue()
46 | cola.dequeue()
47 | org.junit.jupiter.api.assertAll(
48 | { assertEquals(true, cola.isEmpty()) }
49 | )
50 | }
51 |
52 | @Test
53 | fun first() {
54 | org.junit.jupiter.api.assertAll(
55 | { assertEquals(1, cola.first().id) },
56 | { assertEquals(3, cola.first().prioridad) },
57 | { assertEquals(1, cola.first().tiempo) }
58 | )
59 | }
60 |
61 | @Test
62 | fun size() {
63 | org.junit.jupiter.api.assertAll(
64 | { assertEquals(3, cola.size()) }
65 | )
66 | }
67 | }
--------------------------------------------------------------------------------
/Soluciones/20-PlanificadorProcesosPrioridad/src/test/kotlin/ColaProcesosPrioritariosTreeSetTest.kt:
--------------------------------------------------------------------------------
1 | import dev.joseluisgs.ColaProcesosPrioritariosTreeSet
2 | import dev.joseluisgs.Proceso
3 | import org.junit.jupiter.api.Assertions.assertEquals
4 | import org.junit.jupiter.api.BeforeEach
5 | import org.junit.jupiter.api.Test
6 | import org.junit.jupiter.api.assertAll
7 |
8 | class ColaProcesosPrioritariosTreeSetTest {
9 | var cola = ColaProcesosPrioritariosTreeSet()
10 |
11 | @BeforeEach
12 | fun setUp() {
13 | cola = ColaProcesosPrioritariosTreeSet()
14 | cola.enqueue(Proceso(1, 1, 3))
15 | cola.enqueue(Proceso(2, 2, 1))
16 | cola.enqueue(Proceso(3, 3, 2))
17 | }
18 |
19 | @Test
20 | fun enqueue() {
21 | cola.enqueue(Proceso(4, 4, 4))
22 | assertAll(
23 | { assertEquals(4, cola.size()) },
24 | { assertEquals(2, cola.first()?.id) },
25 | { assertEquals(1, cola.first()?.prioridad) },
26 | { assertEquals(2, cola.first()?.tiempo) }
27 | )
28 | }
29 |
30 | @Test
31 | fun dequeue() {
32 | val p = cola.dequeue()
33 | assertAll(
34 | { assertEquals(2, cola.size()) },
35 | { assertEquals(2, p?.id) },
36 | { assertEquals(1, p?.prioridad) },
37 | { assertEquals(2, p?.tiempo) },
38 | { assertEquals(3, cola.first()?.id) },
39 | { assertEquals(3, cola.first()?.tiempo) },
40 | { assertEquals(2, cola.first()?.prioridad) },
41 | )
42 | }
43 |
44 | @Test
45 | fun isEmpty() {
46 | cola.dequeue()
47 | cola.dequeue()
48 | cola.dequeue()
49 | assertAll(
50 | { assertEquals(true, cola.isEmpty()) }
51 | )
52 | }
53 |
54 | @Test
55 | fun first() {
56 | assertAll(
57 | { assertEquals(2, cola.first()?.id) },
58 | { assertEquals(1, cola.first()?.prioridad) },
59 | { assertEquals(2, cola.first()?.tiempo) }
60 | )
61 | }
62 |
63 | @Test
64 | fun size() {
65 | assertAll(
66 | { assertEquals(3, cola.size()) }
67 | )
68 | }
69 | }
--------------------------------------------------------------------------------
/Soluciones/22-CacheLimitada/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/Soluciones/22-CacheLimitada/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Soluciones/22-CacheLimitada/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Soluciones/22-CacheLimitada/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/22-CacheLimitada/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/22-CacheLimitada/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Soluciones/22-CacheLimitada/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.22"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | testImplementation("org.jetbrains.kotlin:kotlin-test")
14 | }
15 |
16 | tasks.test {
17 | useJUnitPlatform()
18 | }
19 | kotlin {
20 | jvmToolchain(21)
21 | }
--------------------------------------------------------------------------------
/Soluciones/22-CacheLimitada/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/22-CacheLimitada/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/22-CacheLimitada/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/22-CacheLimitada/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Feb 08 15:54:28 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/22-CacheLimitada/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "CacheLimitada"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/22-CacheLimitada/src/main/kotlin/Main.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | import dev.joseluisgs.cache.Cache
4 |
5 | fun main() {
6 | val cache = Cache()
7 |
8 | val vehiculo1 = Vehiculo("1234ABC", "Seat", "Ibiza", "Blanco", 12000.0)
9 | val vehiculo2 = Vehiculo("5678DEF", "Renault", "Clio", "Azul", 10000.0)
10 | val vehiculo3 = Vehiculo("1010GHI", "Ford", "Focus", "Rojo", 15000.0)
11 | val vehiculo4 = Vehiculo("1212JKL", "Fiat", "Punto", "Verde", 8000.0)
12 | val vehiculo5 = Vehiculo("1313MNO", "Opel", "Corsa", "Amarillo", 11000.0)
13 | val vehiculo6 = Vehiculo("1414PQR", "Volkswagen", "Jetta", "Azul", 13000.0)
14 | val vehiculo7 = Vehiculo("1515TUV", "Volkswagen", "Jetta", "Rojo", 14000.0)
15 |
16 | cache.put(vehiculo1.matricula, vehiculo1)
17 | cache.put(vehiculo2.matricula, vehiculo2)
18 | cache.put(vehiculo3.matricula, vehiculo3)
19 | cache.put(vehiculo4.matricula, vehiculo4)
20 | cache.put(vehiculo1.matricula, vehiculo1)
21 | cache.put(vehiculo4.matricula, vehiculo4)
22 | cache.put(vehiculo5.matricula, vehiculo5)
23 | cache.put(vehiculo6.matricula, vehiculo6)
24 | cache.put(vehiculo4.matricula, vehiculo4)
25 | cache.put(vehiculo7.matricula, vehiculo7)
26 | cache.put(vehiculo6.matricula, vehiculo6)
27 |
28 | println(cache)
29 |
30 | }
--------------------------------------------------------------------------------
/Soluciones/22-CacheLimitada/src/main/kotlin/Vehiculo.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | data class Vehiculo(
4 | val matricula: String,
5 | val marca: String,
6 | val modelo: String,
7 | val color: String,
8 | val precio: Double
9 | )
--------------------------------------------------------------------------------
/Soluciones/22-CacheLimitada/src/main/kotlin/cache/Cache.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.cache
2 |
3 | import java.time.LocalDateTime
4 |
5 | data class CacheItem(
6 | val value: T,
7 | val updatedAt: LocalDateTime = LocalDateTime.now(),
8 | ) : Comparable> {
9 | override fun compareTo(other: CacheItem): Int {
10 | return this.updatedAt.compareTo(other.updatedAt)
11 | }
12 |
13 | override fun toString(): String {
14 | return "CacheItem(value=$value, updatedAt=$updatedAt)"
15 | }
16 | }
17 |
18 | class Cache(private val maxSize: Int = 3) {
19 | private val items: MutableMap> = mutableMapOf()
20 |
21 | fun get(key: ID): T? {
22 | return items[key]?.let { cacheItem ->
23 | // Actualiza la fecha de 'updatedAt' cuando se accede al elemento
24 | items[key] = cacheItem.copy(updatedAt = LocalDateTime.now())
25 | cacheItem.value
26 | }
27 | }
28 |
29 | fun put(key: ID, value: T) {
30 | // Si la clave ya existe, simplemente actualiza el valor y la fecha de actualización
31 | items[key]?.let {
32 | items[key] = it.copy(value = value, updatedAt = LocalDateTime.now())
33 | } ?: run {
34 | // Si no existe y el tamaño es mayor que el máximo, elimina el más antiguo
35 | if (items.size >= maxSize) {
36 | removeOldestItem()
37 | }
38 | // Agrega el nuevo elemento al caché
39 | items[key] = CacheItem(value)
40 | }
41 | }
42 |
43 | private fun removeOldestItem() {
44 | // Encuentra la clave del elemento más antiguo y elimínalo
45 | items.minByOrNull { it.value.updatedAt }?.key?.let { oldestKey ->
46 | items.remove(oldestKey)
47 | }
48 | }
49 |
50 | override fun toString(): String {
51 | // ordena los elementos por fecha de actualización
52 | val sortedItems = items.entries.sortedBy { it.value }
53 | return "Cache(items=$sortedItems)"
54 | }
55 | }
--------------------------------------------------------------------------------
/Soluciones/23-RepositorioCacheable/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/Soluciones/23-RepositorioCacheable/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Soluciones/23-RepositorioCacheable/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Soluciones/23-RepositorioCacheable/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/23-RepositorioCacheable/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/23-RepositorioCacheable/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Soluciones/23-RepositorioCacheable/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.22"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | // https://mvnrepository.com/artifact/org.lighthousegames/logging
14 | implementation("org.lighthousegames:logging:1.3.0")
15 | implementation("ch.qos.logback:logback-classic:1.4.14")
16 |
17 | testImplementation("org.jetbrains.kotlin:kotlin-test")
18 | }
19 |
20 | tasks.test {
21 | useJUnitPlatform()
22 | }
23 | kotlin {
24 | jvmToolchain(21)
25 | }
--------------------------------------------------------------------------------
/Soluciones/23-RepositorioCacheable/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/23-RepositorioCacheable/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/23-RepositorioCacheable/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/23-RepositorioCacheable/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Feb 09 16:06:00 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/23-RepositorioCacheable/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "RepositorioCacheable"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/23-RepositorioCacheable/src/main/kotlin/exceptions/VehiculoException.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.exceptions
2 |
3 | sealed class VehiculoException(message: String) : Exception(message) {
4 | // No existe el vehículo
5 | class VehiculoNoEncontradoException(matricula: String) :
6 | VehiculoException("Vehículo con matricula: $matricula no encontrado")
7 |
8 | // Violación de clave primaria
9 | class VehiculoMatriculaYaExisteException(matricula: String) :
10 | VehiculoException("Vehículo con matricula: $matricula ya existe")
11 |
12 | // Violación de clave foránea
13 | class VehiculoNoValidoException(matricula: String, message: String) :
14 | VehiculoException("Vehículo con matricula: $matricula no es válido: $message")
15 | }
--------------------------------------------------------------------------------
/Soluciones/23-RepositorioCacheable/src/main/kotlin/models/Vehiculo.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.models
2 |
3 | import java.time.LocalDate
4 | import java.time.LocalDateTime
5 |
6 | /**
7 | * Modelo de Vehiculo
8 | */
9 | data class Vehiculo(
10 | val matricula: String,
11 | val marca: String,
12 | val modelo: String,
13 | val color: String,
14 | val precio: Double,
15 | val fechaMatriculacion: LocalDate,
16 | val vendido: Boolean = false,
17 | val createdAt: LocalDateTime = LocalDateTime.now(),
18 | val updatedAt: LocalDateTime = LocalDateTime.now()
19 | )
--------------------------------------------------------------------------------
/Soluciones/23-RepositorioCacheable/src/main/kotlin/repositories/cache/Cache.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.repositories.cache
2 |
3 | interface Cache {
4 | fun put(key: ID, value: T)
5 | fun get(key: ID): T?
6 | fun remove(key: ID)
7 | fun clear()
8 | }
--------------------------------------------------------------------------------
/Soluciones/23-RepositorioCacheable/src/main/kotlin/repositories/cache/CacheImpl.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.repositories.cache
2 |
3 | import org.lighthousegames.logging.logging
4 |
5 | /**
6 | * Clase que representa un cache limitada a un número de elementos máximo
7 | * @param T Tipo de elementos que se almacenarán en el cache
8 | */
9 |
10 | private val logger = logging()
11 |
12 | class CacheImpl(private val maxElements: Int = 5) {
13 | private val elements = mutableMapOf()
14 |
15 | /**
16 | * Añade un elemento al cache
17 | * @param key Clave del elemento
18 | * @param value Valor del elemento
19 | */
20 | fun put(key: ID, value: T) {
21 | logger.debug { "Añadiendo elemento al cache con key: $key" }
22 | // Si el cache está lleno, eliminamos el primer elemento
23 |
24 | elements[key]?.let { elements.remove(key) }
25 |
26 | if (elements.size >= maxElements) {
27 | logger.debug { "Cache completo, eliminando el primer elemento" }
28 | elements.remove(elements.keys.first())
29 | }
30 |
31 | logger.debug { "Añadiendo elemento al cache" }
32 | elements[key] = value
33 | }
34 |
35 | /**
36 | * Obtiene un elemento del cache
37 | * @param key Clave del elemento
38 | * @return Valor del elemento
39 | */
40 | fun get(key: ID): T? {
41 | logger.debug { "Obteniendo elemento del cache con key: $key" }
42 | return elements[key]
43 | }
44 |
45 | /**
46 | * Elimina un elemento del cache
47 | * @param key Clave del elemento
48 | */
49 | fun remove(key: ID) {
50 | logger.debug { "Eliminando elemento del cache con key: $key" }
51 | elements.remove(key)
52 | }
53 |
54 | /**
55 | * Limpia el cache
56 | */
57 | fun clear() {
58 | elements.clear()
59 | }
60 | }
--------------------------------------------------------------------------------
/Soluciones/23-RepositorioCacheable/src/main/kotlin/repositories/crud/CrudRepository.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.repositories.crud
2 |
3 | interface CrudRepository {
4 | fun findAll(): List
5 | fun findById(id: ID): T?
6 | fun save(entity: T): T
7 | fun update(id: ID, entity: T): T?
8 | fun deleteById(id: ID): T?
9 | fun deleteAll()
10 | }
--------------------------------------------------------------------------------
/Soluciones/23-RepositorioCacheable/src/main/kotlin/repositories/vehiculos/VehiculosRepository.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.repositories.vehiculos
2 |
3 | import dev.joseluisgs.models.Vehiculo
4 | import dev.joseluisgs.repositories.crud.CrudRepository
5 |
6 | interface VehiculosRepository : CrudRepository {
7 | fun findByMarca(marca: String): List
8 | fun findByAñoMatriculacion(añoMatriculacion: Int): List
9 | fun findByVendido(vendido: Boolean): List
10 | }
--------------------------------------------------------------------------------
/Soluciones/23-RepositorioCacheable/src/main/kotlin/services/VehiculosService.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.services
2 |
3 | import dev.joseluisgs.models.Vehiculo
4 |
5 | interface VehiculosService {
6 | fun findByMarca(marca: String): List
7 | fun findByAñoMatriculacion(añoMatriculacion: Int): List
8 | fun findByVendido(vendido: Boolean): List
9 | fun findAll(page: Int? = null, pageSize: Int = 10): List
10 | fun findById(id: String): Vehiculo
11 | fun create(vehiculo: Vehiculo): Vehiculo
12 | fun update(vehiculo: Vehiculo): Vehiculo
13 | fun delete(id: String): Vehiculo
14 | }
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.22"
3 | }
4 |
5 | group = "dev.joseluisgs"
6 | version = "1.0-SNAPSHOT"
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | testImplementation("org.jetbrains.kotlin:kotlin-test")
14 | }
15 |
16 | tasks.test {
17 | useJUnitPlatform()
18 | }
19 | kotlin {
20 | jvmToolchain(21)
21 | }
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
2 |
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/Soluciones/24-Matrix/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Feb 12 17:16:07 CET 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3 | }
4 | rootProject.name = "Matrix"
5 |
6 |
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/src/main/kotlin/Main.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs
2 |
3 | import dev.joseluisgs.controllers.TheMatrixController
4 |
5 | fun main() {
6 | println("Bienvenid@ a Matrix!\n")
7 | // Leemos la dimension de la matriz
8 |
9 | val config = initConfig()
10 | // var dimension = 5;
11 | println()
12 | println("Iniciando The Matrix con dimension: ${config["dimension"]}x${config["dimension"]} y tiempo ${config["time"]}s")
13 | // Controlador de la lógica del programa
14 | val theMatrix = TheMatrixController.getInstance(config)
15 | // iniciamos los elementos del sistema
16 | theMatrix.init()
17 | // imprimimos la matriz...
18 | // theMatrix.print();
19 | // iniciamos la simulacion
20 | theMatrix.simulate()
21 | // informe de resultados
22 | theMatrix.report()
23 | }
24 |
25 | /**
26 | * Inicializamos la configuración del programa.
27 | *
28 | * @return dimension de la matriz
29 | */
30 | private fun initConfig(): Map {
31 | return mutableMapOf("dimension" to readDimension(), "time" to readTime())
32 | }
33 |
34 |
35 | // Leemos los valores de la matriz interactuando con el usuario
36 | // Opciones de filtro con valores posibles. Expresiones regulares.
37 | // https://www.vogella.com/tutorials/JavaRegularExpressions/article.html
38 | private fun readDimension(): Int {
39 | var input: String
40 | // Expresion regular para validar el formato de la entrada
41 | // caracteres que representa un digito entre 5 y 9, y dos caracteres que son 1 y 0, es decir 10.
42 | val regex = "[5-9]|10"
43 | do {
44 | println("Introduce la dimension de la matriz [5-10]: ")
45 | input = readln()
46 | if (!input.matches(regex.toRegex())) {
47 | println("Error: La dimension debe estar entre 5 y 10\n")
48 | }
49 | } while (!input.matches(regex.toRegex()))
50 | return input.toInt()
51 | }
52 |
53 | private fun readTime(): Int {
54 | var input: String
55 | // Expresion regular para validar el formato de la entrada
56 | // carcter que va desde 2 hasta 9, siguiente caracter que es un digito entre 0 y 9,
57 | // o tres caracteres que son 1 0 0, es decir 100.
58 | val regex = "[2-9][0-9]|100"
59 | do {
60 | println("Introduce el tiempo de ejecución en segundos [20-100]: ")
61 | input = readln()
62 | if (!input.matches(regex.toRegex())) {
63 | println("Error: El tiempo de ejecución debe estar entre 20 y 100\n")
64 | }
65 | } while (!input.matches(regex.toRegex()))
66 | return input.toInt()
67 | }
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/src/main/kotlin/factories/GenericoFactory.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.factories
2 |
3 | import dev.joseluisgs.models.Generico
4 | import dev.joseluisgs.models.Localizacion
5 |
6 |
7 | class GenericoFactory {
8 | /**
9 | * Crea un objeto de tipo Generico con datos aleatorios.
10 | *
11 | * @return Objeto de tipo Generico.
12 | */
13 | companion object {
14 | fun createRandom(): Generico {
15 | val nombre = listOf("Pepe", "Juan", "Maria", "Jose", "Ana", "Sonia")
16 | val ciudad = listOf("Madrid", "New York", "Pekin", "Leganés", "Londres", "Paris")
17 | val localizacion = Localizacion(
18 | -1,
19 | -1,
20 | ciudad.random()
21 | )
22 | return Generico(
23 | nombre.random(),
24 | localizacion
25 | )
26 | }
27 | }
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/src/main/kotlin/factories/SmithFactory.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.factories
2 |
3 | import dev.joseluisgs.models.Localizacion
4 | import dev.joseluisgs.models.Smith
5 |
6 |
7 | class SmithFactory {
8 | /**
9 | * Crea un Smith aleatorio.
10 | *
11 | * @return Smith aleatorio.
12 | */
13 |
14 | companion object {
15 | fun createRandom(): Smith {
16 | val ciudad = listOf("Madrid", "New York", "Pekin", "Leganés", "Londres", "Paris")
17 | val localizacion = Localizacion(
18 | -1,
19 | -1,
20 | ciudad.random()
21 | )
22 | return Smith(
23 | localizacion, // Solo infecta en las 8 direcciones: N, NE, E, SE, S, SW, W, NW
24 | (0..7).random() // Dirección aleatoria
25 | )
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/src/main/kotlin/models/Generico.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.models
2 |
3 | class Generico(nombre: String, localizacion: Localizacion) : Persona(nombre, localizacion), Personaje {
4 | var probMorir: Float = (0..100).random().toFloat()
5 | set(value) {
6 | field = value
7 | if (value < 0) {
8 | field = 0f
9 | }
10 | }
11 |
12 |
13 | override fun toString(): String {
14 | return "\uD83E\uDD28"
15 | }
16 |
17 | override fun mostrar(): String {
18 | // Usando DecimalFormat
19 | //
20 | // DecimalFormat df = new DecimalFormat("#.00");
21 | // System.out.println(df.format(number));
22 | // /* Salida : 1.42*/
23 | //Usando String.Format
24 | //
25 | //System.out.println(String.format("%.2f", number));
26 | ///* Salida : 1.42*/
27 |
28 | return "Generico{id=$id, nombre='$nombre', localizacion=$localizacion, createdAt=$createdAt, probMorir=${
29 | String.format(
30 | "%.2f",
31 | probMorir
32 | )
33 | }}"
34 | }
35 |
36 | override fun pedir() {
37 | println(this.toString())
38 | }
39 |
40 | override fun generar() {
41 | println("Generando un nuevo Generico")
42 | }
43 |
44 | }
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/src/main/kotlin/models/Localizacion.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.models
2 |
3 | data class Localizacion(
4 | var longitud: Int,
5 | var latitud: Int,
6 | var ciudad: String,
7 | )
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/src/main/kotlin/models/Neo.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.models
2 |
3 | class Neo : Persona("Neo", Localizacion(0, 0, "Luis Vives")), Personaje {
4 | val isElegido: Boolean
5 | /**
6 | * Método que devuelve una probabilidad de que el personaje indique si es el Elegido.
7 | *
8 | * @return
9 | */
10 | get() = (0..100).random() > 50
11 |
12 | override fun toString(): String {
13 | return "\uD83D\uDE0E"
14 | }
15 |
16 | override fun mostrar(): String {
17 | return "Neo{id=$id, nombre='$nombre', localizacion=$localizacion, createdAt=$createdAt, isElegido=$isElegido}"
18 |
19 | }
20 |
21 | override fun pedir() {
22 | println(this.toString())
23 | }
24 |
25 | override fun generar() {
26 | println("Generando un nuevo Neo")
27 | }
28 | }
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/src/main/kotlin/models/Persona.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.models
2 |
3 | import java.time.LocalDateTime
4 |
5 |
6 | abstract class Persona(var nombre: String, var localizacion: Localizacion) : Comparable {
7 | var id: Int
8 | protected set
9 |
10 | var createdAt: LocalDateTime
11 | protected set
12 |
13 | init {
14 | this.createdAt = LocalDateTime.now()
15 | this.id = ++contador
16 | }
17 |
18 | companion object {
19 | private var contador = 0
20 | }
21 |
22 | override fun toString(): String {
23 | return "Persona(nombre='$nombre', id=$id, createdAt=$createdAt)"
24 | }
25 |
26 | override fun compareTo(other: Persona?): Int {
27 | return this.id - other!!.id
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/src/main/kotlin/models/Personaje.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.models
2 |
3 | interface Personaje {
4 | fun mostrar(): String
5 |
6 | fun pedir()
7 |
8 | fun generar()
9 | }
10 |
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/src/main/kotlin/models/Smith.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.models
2 |
3 | class Smith(localizacion: Localizacion, val probInfectar: Int) : Persona("Smith", localizacion), Personaje {
4 | init {
5 | nombre = "$nombre-$id"
6 | }
7 |
8 | override fun toString(): String {
9 | return "\uD83D\uDE08"
10 | }
11 |
12 | override fun mostrar(): String {
13 | return "Smith{id=$id, nombre='$nombre', localizacion=$localizacion, createdAt=$createdAt, probInfectar=$probInfectar}"
14 | }
15 |
16 | override fun pedir() {
17 | println(this.toString())
18 | }
19 |
20 | override fun generar() {
21 | println("Generando un nuevo Smith")
22 | }
23 | }
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/src/main/kotlin/repositories/cola/Cola.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.repositories.cola
2 |
3 | interface Cola {
4 | fun queue(elem: T)
5 |
6 | fun dequeue(): T
7 |
8 | fun isEmpty(): Boolean
9 |
10 | fun size(): Int
11 |
12 | fun first(): T
13 |
14 | operator fun get(index: Int): T
15 | }
16 |
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/src/main/kotlin/repositories/cola/ColaImpl.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.repositories.cola
2 |
3 | class ColaImpl : Cola {
4 | private val cola: ArrayDeque = ArrayDeque()
5 | override fun queue(elem: T) {
6 | cola.addLast(elem)
7 | }
8 |
9 | override fun dequeue(): T {
10 | return cola.removeFirst()
11 | }
12 |
13 | override fun isEmpty(): Boolean {
14 | return cola.isEmpty()
15 | }
16 |
17 | override fun size(): Int {
18 | return cola.size
19 | }
20 |
21 | override fun first(): T {
22 | return cola.first()
23 | }
24 |
25 | override fun get(index: Int): T {
26 | return cola.elementAt(index)
27 | }
28 |
29 | override fun toString(): String {
30 | return "ColaImp(cola=$cola)"
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Soluciones/24-Matrix/src/main/kotlin/repositories/matriz/Matriz.kt:
--------------------------------------------------------------------------------
1 | package dev.joseluisgs.repositories.matriz
2 |
3 | interface Matriz {
4 | operator fun get(row: Int, col: Int): T?
5 |
6 | operator fun set(row: Int, col: Int, value: T?)
7 |
8 | val rows: Int
9 |
10 | val cols: Int
11 |
12 | fun clear()
13 |
14 | fun addRows(numberOfRows: Int)
15 |
16 | fun addCols(numberOfCols: Int)
17 |
18 | fun removeRows(numberOfRows: Int)
19 |
20 | fun removeCols(numberOfCols: Int)
21 |
22 | override fun toString(): String
23 |
24 | fun clone(): Matriz
25 | }
26 |
--------------------------------------------------------------------------------
/images/01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/images/01.png
--------------------------------------------------------------------------------
/images/02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/images/02.png
--------------------------------------------------------------------------------
/images/03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/images/03.png
--------------------------------------------------------------------------------
/images/04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/images/04.png
--------------------------------------------------------------------------------
/images/05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/images/05.png
--------------------------------------------------------------------------------
/images/06.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/images/06.png
--------------------------------------------------------------------------------
/images/07.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/images/07.png
--------------------------------------------------------------------------------
/images/colecciones.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/images/colecciones.webp
--------------------------------------------------------------------------------
/images/secuences.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/images/secuences.webp
--------------------------------------------------------------------------------
/images/secuences01.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/images/secuences01.webp
--------------------------------------------------------------------------------
/images/secuencias.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/images/secuencias.png
--------------------------------------------------------------------------------
/images/sql-collections.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joseluisgs/Programacion-06-2023-2024/45f1c43604d4c37e830d5055c9b22499338f8e8e/images/sql-collections.png
--------------------------------------------------------------------------------