year
string
session
string
utility_classes
list
solution
list
test
dict
2014
a02
[ { "content": "package ex2014.a02.sol1;\n\nimport java.util.Set;\n\n\n\npublic interface Scheduler<T> {\n\t\n\t\n\tvoid add(T t);\n\t\n\t\n\tboolean isExecuting();\n\t\n\t\n\tT getExecutingTask();\n\t\n\t\n\tvoid executeNext();\n\t\n\t\n\tvoid complete();\n\t\n\t\n\tvoid stop();\n\t\n\t\n\tvoid preempt();\n\t\n\...
[ { "content": "package ex2014.a02.sol1;\n\nimport java.util.*;\nimport java.util.function.Supplier;\n\npublic class SchedulerImpl<T> implements Scheduler<T>{\n\t\n\tprivate final LinkedList<T> waitingList = new LinkedList<>();\n\tprivate final LinkedList<T> stoppedList = new LinkedList<>();\n\tprivate Optional<T...
{ "components": { "imports": "package ex2014.a02.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the Scheduler interface given through a SchedulerImpl class\n\t * with a constructor without arguments.\n\t * This scheduler executes processes one at a time...
2014
a03
[ { "content": "package ex2014.a03.sol1;\n\nimport java.io.*;\nimport java.util.*;\n\n\n\npublic interface RandomStatistics{\n\n\t\t\n\tvoid setFileName(String fileName);\n\t\n\t\t\n\tvoid storeSeries(long size) throws IOException;\n\t\n\t\t\n\tdouble loadToMax() throws IOException;\n\t\n\t\t\n\tlong loadToCountS...
[ { "content": "package ex2014.a03.sol1;\n\nimport java.io.*;\nimport java.util.*;\nimport java.util.function.*;\n\n/**\n * Questa soluzione usa le lambda per fattorizzare il comportamento\n * comune delle tre load, ma una soluzione equivalente era ottenibile\n * con uno strategy e le classi anonime.\n */\n\npubl...
{ "components": { "imports": "package ex2014.a03.sol1;\n\nimport static org.junit.Assert.*;\nimport java.io.*;", "private_init": "\t/*\n\t * Implement the RandomStatistics interface given through a RandomStatisticsImpl class with a constructor without arguments.\n\t * This class implements a generator of rand...
2014
a04
[ { "content": "package ex2014.a04.sol1;\n\nimport java.util.*;\n\n\n\npublic interface TicTacToe {\n\t\n\t\n\t\n\tenum Player { X, O };\n\t\n\t\n\t\n\tenum Cell {\n\t\t\n\t\tNW(0,0), N(0,1), NE(0,2),\n\t\tW(1,0), C(1,1), E(1,2),\n\t\tSW(2,0), S(2,1), SE(2,2);\n\t\t\n\t\tpublic static final List<List<Cell>> WINNI...
[ { "content": "package ex2014.a04.sol1;\n\nimport java.util.*;\nimport java.util.stream.Collectors;\nimport static ex2014.a04.sol1.TicTacToe.Cell.*;\n\n/**\n * Questa interfaccia è usata per controllare una partita del gioco TicTacToe (tris).\n * In generale, richiamare un metodo quando non appropriato (ad esemp...
{ "components": { "imports": "package ex2014.a04.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the given TicTacToe interface through a TicTacToeImpl class with a no-argument constructor, which\n\t * implements the management of a Tic Tac Toe game.\n\t ...
2014
a02b
[ { "content": "package ex2014.a02b.sol1;\n\nimport java.util.*;\n\npublic interface TicketDispenser<A> {\n\t\n\t\n\tint getCashDeskSize();\n\t\n\t\n\tint getNextAvailableTicket();\n\t\n\t\n\tint giveNextTicketToAgent(A agent);\n\t\n\t\n\tvoid useCashDesk(int desk);\n\t\n\t\n\tvoid releaseCashDesk(int desk);\n\t\...
[ { "content": "package ex2014.a02b.sol1;\n\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class TicketDispenserImpl<A> implements TicketDispenser<A>{\n\t\n\tprivate List<A> waiting = new ArrayList<>();\n\tprivate int currentTicket = 0;\n\tprivate int nextTicketToServe = 0;\n\tprivate List<Optional<A>...
{ "components": { "imports": "package ex2014.a02b.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the given TicketDispenser interface through a TicketDispenser class with a constructor that accepts\n\t * an integer argument, which represents the number...
2014
a06
[ { "content": "package ex2014.a06.sol1;\n\n\n\npublic interface Lamp {\n\t\n\t\n\t\n\tvoid on() throws IllegalStateException;\n\t\n\t\n\tvoid off();\n\t\n\t\n\tboolean isOn();\n\t\n\t\n\tvoid fail();\n\n}", "filename": "Lamp.java" }, { "content": "package ex2014.a06.sol1;\n\npublic class SimpleLamp i...
[ { "content": "package ex2014.a06.sol1;\n\nimport java.util.Optional;\n\npublic class LampWithRemainingDuration extends AbstractLamp {\n\t\n\tprivate int remainingDuration;\n\t\n\tpublic LampWithRemainingDuration(int remainingDuration){\n\t\tthis.remainingDuration = remainingDuration;\n\t}\n\n\t@Override\n\tprot...
{ "components": { "imports": "package ex2014.a06.sol2;\n\nimport static org.junit.Assert.*;\n\nimport java.util.*;", "private_init": "\t/*\n\t * Consider the Lamp interface that models a light bulb with also a \"fail\" command that models its failure,\n\t * its trivial implementation SimpleLamp provided as an...
2014
a05
[ { "content": "package ex2014.a05.sol1;\n\nimport java.util.*;\n\n\n\npublic interface Roulette {\n\t\n\t\n\tfinal static int SINGLE_BET_WIN_FACTOR = 36; \n\t\n\t\n\t\n\tvoid waitBets();\n\t\n\t\n\tvoid bet(String playerName, int betNumber, int quantity);\n\t\n\t\n\tint drawWinningNumber();\n\t\n\t\n\tvoid debug...
[ { "content": "package ex2014.a05.sol1;\n\nimport java.util.*;\nimport java.util.stream.Collectors;\n\npublic class RouletteImpl implements Roulette{\n\t\n\tprivate boolean betting = false;\n\tprivate final Map<String,List<Pair<Integer,Integer>>> iBets = new HashMap<>();\n\tprivate int lastWin;\n\tprivate final ...
{ "components": { "imports": "package ex2014.a05.sol2;\n\nimport static org.junit.Assert.*;\n\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the Roulette interface given through a RouletteImpl class with a constructor without arguments.\n\t * The comment of Roulette and the tests below are suffi...
2014
a03b
[ { "content": "package ex2014.a03b.sol1;\n\nimport java.io.*;\nimport java.util.*;\n\n\n\npublic interface DiceStatistics{\n\n\t\t\n\tvoid setFileName(String fileName);\n\t\n\t\t\n\tvoid storeSeries(long size,int diceNumber) throws IOException;\n\t\n\t\t\n\tlong loadToLuckyCount() throws IOException;\n\t\n\t\t\...
[ { "content": "package ex2014.a03b.sol1;\n\nimport java.io.*;\nimport java.util.*;\nimport java.util.stream.*;\nimport java.util.function.*;\n\n/**\n */\n\npublic class DiceStatisticsImpl implements DiceStatistics{\n\t\n\tprivate Optional<String> fileName = Optional.empty();\n\n\t@Override\n\tpublic void setFile...
{ "components": { "imports": "package ex2014.a03b.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.io.*;", "private_init": "\t/*\n\t * Implement the DiceStatistics interface given through a DiceStatisticsImpl class with a constructor without arguments.\n\t * This class implements a generator of a seq...
2014
a01b
[ { "content": "package ex2014.a01b.sol1;\n\n\n\npublic interface Aggregator<X> {\n\t\n\tX aggregate(X one, X two);\n}", "filename": "Aggregator.java" }, { "content": "package ex2014.a01b.sol1;\n\n\n\npublic interface ProgressiveAcceptor<X> {\n\t\n\t\n\t\n\tvoid setProgressiveFilter(ProgressiveFilter<...
[ { "content": "package ex2014.a01b.sol1;\n\nimport java.util.*;\n\npublic class ProgressiveAcceptorImpl<X> implements ProgressiveAcceptor<X> {\n\n\tprivate ProgressiveFilter<X> filter;\n\tprivate Aggregator<X> aggregator;\n\tprivate int size = -1;\n\tprivate final List<X> elements = new LinkedList<X>();\n\n\tpri...
{ "components": { "imports": "package ex2014.a01b.sol1;\n\nimport static org.junit.Assert.*;", "private_init": "\t/*\n\t * Implement the ProgressiveAcceptor interface given through a\n\t * ProgressiveAcceptorImpl class with a constructor without arguments.\n\t * The comment to the ProgressiveAcceptor code, an...
2014
a01
[ { "content": "package ex2014.a01.sol1;\n\nimport java.util.*;\n\n\n\npublic interface FibonacciAcceptor {\n\n\t\n\tvoid reset(String sequenceName);\n\t\n\t\n\tboolean consumeNext(long l);\n\t\n\t\n\tList<Long> getCurrentSequence();\n\t\n\t\n\tMap<String,List<Long>> getAllSequences();\n}", "filename": "Fibon...
[ { "content": "package ex2014.a01.sol1;\n\nimport java.util.*;\nimport java.util.stream.*;\n\n/**\n * Qualche nota su questa soluzione\n * - è solo una delle possibili\n * - usa alcune delle funzionalità di Java 8, come gli Optional e gli Stream, ma questo non era necessario\n * - può essere considerata come sol...
{ "components": { "imports": "package ex2014.a01.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the FibonacciAcceptor interface given through a\n\t * FibonacciAcceptorImpl class with a constructor without arguments.\n\t * The comment on the FibonacciAcc...
2015
a04
[ { "content": "package ex2015.a04.sol1;\n\nimport java.util.List;\n\n\npublic interface Tree<X> {\n \n \n int size();\n \n \n X getRoot();\n \n \n List<Tree<X>> getSons();\n \n \n boolean contains(X x);\n \n \n Tree<X> getSubTree(X node);\n \n \n...
[ { "content": "package ex2015.a04.sol1;\n\nimport java.util.*;\nimport java.util.function.Supplier;\n\npublic class TreeFactoryImpl<X> implements TreeFactory<X> {\n\n @Override\n public Tree<X> emptyTree() {\n return new EmptyTree<>();\n }\n\n @Override\n public Tree<X> consTree(X root, Lis...
{ "components": { "imports": "package ex2015.a04.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.*;\n\n/**\n * Implement the TreeFactory interface with a TreeFactoryImpl class with an empty constructor,\n * which implements a Factory for immutable trees, which adhere to the generic Tree interface p...
2015
a03a
[ { "content": "package ex2015.a03a.sol1;\n\nimport java.util.Map;\nimport java.util.Set;\n\n\npublic interface Faculty {\n \n \n void registerCourse(int id, String name);\n \n \n void registerStudent(int id, String name);\n \n \n void associate(int studentId, int courseId);\n \n ...
[ { "content": "package ex2015.a03a.sol1;\n\nimport java.util.*;\nimport java.util.function.Supplier;\nimport java.util.stream.Collectors;\n\npublic class FacultyImpl implements Faculty {\n \n private final Map<Integer,Pair<String,Set<Integer>>> courses = new HashMap<>();\n private final Map<Integer,Pair...
{ "components": { "imports": "package ex2015.a03a.sol1;\n\nimport static org.hamcrest.CoreMatchers.*;\nimport static org.junit.Assert.*;\n\n/**\n * Implement the Faculty interface given through a FacultyImpl class\n * with a constructor without arguments. Models the management of courses in a university,\n * with...
2015
a02b
[ { "content": "package ex2015.a02b.sol1;\n\nimport java.util.*;\n\n\npublic interface Menu {\n\n \n interface Dish {\n\n \n String getName();\n\n \n int getCost();\n \n \n Temperature getTemperature();\n \n \n Optional<String> awarded();...
[ { "content": "package ex2015.a02b.sol1;\n\nimport java.util.*;\nimport java.util.stream.Collectors;\n\npublic class MenuImpl implements Menu {\n \n private final Map<String,Dish> map = new HashMap<>();\n \n public MenuImpl(){}\n\n @Override\n public Dish createDish(String name, int cost, Tempe...
{ "components": { "imports": "package ex2015.a02b.sol1;\n\nimport static org.junit.Assert.*;\nimport static org.hamcrest.CoreMatchers.*;", "private_init": "\t/*\n * Implement the given Menu interface through a MenuImpl class\n * with a constructor without arguments. Models a restaurant menu,\n * w...
2015
a06
[ { "content": "package ex2015.a06.sol1;\n\n\npublic interface Countdown {\n\n \n void decrease(); \n \n \n int getValue();\n \n \n boolean isOver(); \n \n}", "filename": "Countdown.java" }, { "content": "package ex2015.a06.sol1;\n\n\npublic interface PowerCountdown extends ...
[ { "content": "package ex2015.a06.sol1;\n\npublic class StandardCountdown extends AbstractCountdown {\n \n public StandardCountdown(int value) {\n super(value);\n }\n\n @Override\n protected void actualDecrease() {\n this.value--;\n }\n\n @Override\n public boolean isOver() ...
{ "components": { "imports": "package ex2015.a06.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.*;\n\n/**\n * See the documentation of the provided Countdown and PowerCountdown interfaces, which model countdown counters.\n * Implement the Countdown interface with a StandardCountdown class, with a ...
2015
a01a
[ { "content": "package ex2015.a01a.sol1;\n\nimport java.util.*;\n\n\npublic interface CoursesCalendar {\n\t\n\t\n\t\n\tenum Day { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY }\n\t\n\t\n\tenum Room { A, B, C, D, E, MAGNA, VELA, C_ALDO_MORO }\n\t\n\t\n\tList<Integer> possibleSlots();\n\t\n\t\n\tvoid bookRoom(Day ...
[ { "content": "package ex2015.a01a.sol1;\n\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class CoursesCalendarImpl implements CoursesCalendar {\n\t\n\tprivate static final List<Integer> AVAILABLE_SLOTS = Arrays.asList(9,10,11,12,14,15,16,17);\n\tprivate final Map<Pair<Day, Room>, Map<Integer,String>...
{ "components": { "imports": "package ex2015.a01a.sol1;\n\nimport static org.junit.Assert.*;\nimport static ex2015.a01a.sol1.CoursesCalendar.Day.*;\nimport static ex2015.a01a.sol1.CoursesCalendar.Room.*;\nimport static org.hamcrest.CoreMatchers.*;\n\nimport java.util.*;", "private_init": "\t/*\n\t * Implement...
2015
a02a
[ { "content": "package ex2015.a02a.sol1;\n\nimport java.util.*;\n\n\npublic interface League {\n\t\n \n\tvoid addTeam(String teamName);\n\t\n\t\n\tvoid start();\n\t\n\t\n\tvoid storeResults(Map<Pair<String,String>,Pair<Integer,Integer>> results);\n\t\n\t\n\t\n Map<String,Integer> getTable();\n\t\n}", "...
[ { "content": "package ex2015.a02a.sol1;\n\nimport java.util.*;\nimport java.util.stream.*;\nimport java.util.function.*;\n\npublic class LeagueImpl implements League {\n\n private final Map<String, Integer> table = new HashMap<>();\n private boolean started = false;\n\n public LeagueImpl() {\n }\n\n...
{ "components": { "imports": "package ex2015.a02a.sol1;\n\nimport static org.junit.Assert.*;\nimport static org.hamcrest.CoreMatchers.*;\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the League interface given through a LeagueImpl class with a constructor without arguments.\n\t * Model the mana...
2015
a05
[ { "content": "package ex2015.a05.sol1;\n\nimport java.util.List;\n\n\npublic interface CList<X> {\n \n \n int size();\n \n \n X getElem(int pos);\n \n \n boolean contains(X x);\n \n \n CList<X> add(X x, int pos);\n \n \n CList<X> shift(int pos);\n\n \n...
[ { "content": "package ex2015.a05.sol1;\n\nimport java.util.Collections;\nimport java.util.LinkedList;\nimport java.util.List;\n\npublic class CListImpl<X> implements CList<X> {\n \n private List<X> elements;\n private int pos;\n \n CListImpl(List<X> elements, int pos) {\n this.elements = e...
{ "components": { "imports": "package ex2015.a05.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.*;\n\n/**\n * Implement the CListFactory interface with a CListFactoryImpl class with an empty constructor,\n * which implements a Factory for immutable cyclic lists, which adhere to the generic CList i...
2015
a01c
[ { "content": "package ex2015.a01c.sol1;\n\npublic interface MapFactory {\n\t\n\t\n\t<K,V> MultiMap<K,V> empty();\n\t\n\t\n\t<K,V> MultiMap<K,V> unmodifiable(MultiMap<K,V> mmap);\n\n}", "filename": "MapFactory.java" }, { "content": "package ex2015.a01c.sol1;\n\n\n\npublic class Pair<X,Y> {\n\t\n\tpri...
[ { "content": "package ex2015.a01c.sol1;\n\nimport java.util.*;\nimport java.util.stream.*;\n\n\npublic class MultiMapImpl<K,V> implements MultiMap<K, V> {\n\n\tprivate Map<K,Set<V>> mmap = new HashMap<>();\n\t\t\n\tprivate void prepareAddition(K key){\n\t\tthis.mmap.merge(key, new HashSet<>(), (x,y)->x);\n\t}\n...
{ "components": { "imports": "package ex2015.a01c.sol1;\n\nimport static org.junit.Assert.*;\nimport static org.hamcrest.CoreMatchers.*;\n\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the MultiMap interface through a MultiMapImpl class with a constructor without arguments.\n\t * Model a multi-...
2015
a03b
[ { "content": "package ex2015.a03b.sol1;\n\nimport java.util.Map;\n\n\npublic interface ThesesManagement {\n \n enum Status {\n TO_BE_APPROVED, APPROVED, SUBMITTED, CONCLUDED \n }\n \n \n void registerStudent(int studentId, String name);\n \n \n void registerThesis(int thesisId,...
[ { "content": "package ex2015.a03b.sol1;\n\nimport java.util.*;\nimport java.util.function.Supplier;\nimport java.util.stream.Collectors;\n\npublic class ThesesManagementImpl implements ThesesManagement {\n \n private final Map<Integer,Pair<String,Optional<Thesis>>> students = new HashMap<>();\n private...
{ "components": { "imports": "package ex2015.a03b.sol1;\n\nimport static org.junit.Assert.*;\n\n/**\n * Implement the ThesesManagement interface using a TheseManagementImpl class\n * with a constructor without arguments. Models the management of theses\n * of a university course, with methods to register students...
2015
a01b
[ { "content": "package ex2015.a01b.sol1;\n\nimport java.util.Map;\nimport java.util.Set;\nimport java.util.SortedSet;\n\n\npublic interface CoursesManagement {\n\n \n static final int TUTORING_SLOTS = 3;\n\n \n enum Course {\n OBJECT_ORIENTED_PROGRAMMING, OPERATING_SYSTEMS, FOUNDATIONS_OF_INFO...
[ { "content": "package ex2015.a01b.sol1;\n\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class CoursesManagementImpl implements CoursesManagement {\n \n private final Map<Integer, Map<Course, Pair<Optional<String>, Set<String>>>> summary = new HashMap<>();\n \n public CoursesManagementIm...
{ "components": { "imports": "package ex2015.a01b.sol1;\n\nimport static org.hamcrest.CoreMatchers.*;\nimport static org.junit.Assert.*;\n\nimport java.util.*;\nimport java.util.stream.*;\n\nimport ex2015.a01b.sol1.CoursesManagement.Course;\n\n/**\n * Implement the CoursesManagement interface given through a Cour...
2016
a04
[ { "content": "package ex2016.a04.sol1;\n\nimport java.util.*;\n\n\n\ninterface BitIteratorsFactory {\n \n enum Bit {\n ZERO, ONE\n }\n \n \n Iterator<Bit> empty();\n \n \n Iterator<Bit> zeros();\n \n \n Iterator<Bit> ones();\n \n \n Iterator<Bit> fromByteStart...
[ { "content": "package ex2016.a04.sol1;\n\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.NoSuchElementException;\n\npublic class BitIteratorsFactoryImpl implements BitIteratorsFactory {\n\n @Override\n public Iterator<Bit> empty() {\n //return java.util.stream.Stream.<Bit>empt...
{ "components": { "imports": "package ex2016.a04.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\nimport static ex2016.a04.sol1.BitIteratorsFactory.*;\nimport static ex2016.a04.sol1.BitIteratorsFactory.Bit.*;\n\n/**\n * Consult the documentation of the BitIteratorsFactory interface: it models a fa...
2016
a03a
[ { "content": "package ex2016.a03a.sol1;\n\nimport java.util.*;\nimport java.util.function.*;\n\n\n\ninterface BagFactory {\n \n \n <X> Bag<X> empty();\n \n \n <X> Bag<X> fromSet(Set<X> set);\n \n \n <X> Bag<X> fromList(List<X> list);\n \n \n <X> Bag<X> bySupplier(Supplier<X> ...
[ { "content": "package ex2016.a03a.sol1;\n\nimport java.util.*;\nimport java.util.stream.*;\nimport java.util.function.*;\n\n\n/**\n * Qui di seguito si fornisce una implementazione che usa gli Stream\n * Implementazioni analoghe senza gli Stream sono comunque simili\n */\npublic class BagFactoryImpl implements ...
{ "components": { "imports": "package ex2016.a03a.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n/**\n * Consult the documentation of the Bag<X> and BagFactory interfaces.\n * \n * BagFactory (to be implemented in a BagFactory class with a constructor without arguments) models a factory for\n ...
2016
a02b
[ { "content": "package ex2016.a02b.sol1;\n\n\n\npublic interface LuminousDevice extends Device, Luminous {\n \n}", "filename": "LuminousDevice.java" }, { "content": "package ex2016.a02b.sol1;\n\n\npublic interface Luminous {\n \n \n void dim();\n \n \n void brighten();\n \n ...
[ { "content": "package ex2016.a02b.sol1;\n\npublic class LuminousDeviceImpl extends AbstractDevice implements LuminousDevice {\n \n private final int maxIntensity;\n private int intensity = 0;\n \n public LuminousDeviceImpl(int maxIntensity) {\n this.maxIntensity = maxIntensity;\n }\n\n ...
{ "components": { "imports": "package ex2016.a02b.sol1;\n\nimport static org.junit.Assert.*;\n\n/**\n * Please consult the documentation of the provided interfaces (Device, Luminous, LuminousDevice and DeviceFactory).\n * The latter represents a factory for devices of three different types, which must be implemen...
2016
a06
[ { "content": "package pr2016.a06.sol1;\n\nimport java.util.*;\n\n\n\ninterface IntIteratorsFactory {\n \n \n Iterator<Integer> empty();\n \n \n Iterator<Integer> zeros();\n \n \n Iterator<Integer> alternateOneAndZeroIndefinitely();\n \n \n Iterator<Integer> fromTo(int start,...
[ { "content": "package pr2016.a06.sol1;\n\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class IntIteratorsFactoryImpl implements IntIteratorsFactory {\n\n private Iterator<Integer> fromStream(Stream<Integer> stream){\n return stream.iterator();\n }\n \n @Override\n public Itera...
{ "components": { "imports": "package pr2016.a06.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n/**\n * Consult the documentation of the IntIteratorsFactory interface: it models a factory for\n * creating various objects of type java.util.Iterator<Integer>.\n * Implement the factory with an In...
2016
a01a
[ { "content": "package ex2016.a01a.sol1;\n\nimport java.util.*;\n\n\npublic interface Sequence<X> {\n \n \n Optional<X> getAtPosition(int position);\n \n \n int size();\n \n \n List<X> asList();\n \n \n void executeOnAllElements(Executor<X> executor);\n \n\n \n interfa...
[ { "content": "package ex2016.a01a.sol1;\n\nimport java.util.*;\n\npublic class SequenceImpl<X> implements Sequence<X> {\n \n private final List<X> list;\n \n SequenceImpl(List<X> list){\n this.list = Collections.unmodifiableList(list);\n }\n\n @Override\n public Optional<X> getAtPosi...
{ "components": { "imports": "package ex2016.a01a.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n/**\n * See the documentation of the interfaces SequenceBuilder and Sequence.\n * \n * SequenceBuilder (to be implemented in a class SequenceBuilderImpl with a constructor without arguments) models...
2016
a02a
[ { "content": "package ex2016.a02a.sol1;\n\nimport java.util.*;\n\n\n\n\npublic interface MultiQueue<T,Q> {\n \n \n Set<Q> availableQueues();\n \n \n void openNewQueue(Q queue);\n \n \n boolean isQueueEmpty(Q queue);\n \n \n void enqueue(T elem, Q queue);\n \n \n Opti...
[ { "content": "package ex2016.a02a.sol1;\n\nimport java.util.*;\nimport java.util.function.Supplier;\nimport java.util.stream.Collectors;\n\npublic class MultiQueueImpl<T, Q> implements MultiQueue<T, Q> {\n \n private final static Supplier<RuntimeException> ILLEGAL_ARGUMENT_EXCEPTION_SUPPLIER = ()->new Ill...
{ "components": { "imports": "package ex2016.a02a.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n/**\n * See the documentation of the MultiQueue interface, which represents a multiple queue (FIFO), such as at the supermarket\n * where there are multiple cash registers with queues of people wai...
2016
a05
[ { "content": "package pr2016.a05.sol1;\n\n\npublic interface Elevator {\n \n \n int getCurrentFloor();\n \n \n boolean isMoving();\n \n \n boolean isMovingUp();\n \n \n boolean isMovingDown();\n \n \n void call(int floor);\n \n \n void moveToNext();\n ...
[ { "content": "package pr2016.a05.sol1;\n\nimport java.util.*;\n\npublic abstract class AbstractElevator implements Elevator {\n \n protected final NavigableSet<Integer> pending;\n protected boolean up = true;\n protected int floor = 0;\n \n public AbstractElevator() {\n super();\n ...
{ "components": { "imports": "package pr2016.a05.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n/**\n * See the documentation of the Elevator interface: it models an elevator that accepts calls\n * and consequently moves up and down the various floors (floor) of a building.\n * \n * In the man...
2016
a03b
[ { "content": "package ex2016.a03b.sol1;\n\n\npublic interface Clock {\n \n \n Time getTime();\n \n \n void tick();\n \n \n void registerAlarmObserver(Time time, Runnable observer);\n \n \n void registerHoursDeadlineObserver(int hours, Runnable observer);\n \n \n void...
[ { "content": "package ex2016.a03b.sol1;\n\n/*\n * An helper class used by TimeImpl and ClockImpl\n */\npublic class TimeUtils {\n \n public static int N_SECONDS = 60;\n public static int N_MINUTES = 60;\n public static int N_HOURS = 24;\n \n public static boolean correctHours(int hours){\n ...
{ "components": { "imports": "package ex2016.a03b.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.*;\n\n/**\n * Please consult the documentation of the provided Time and Clock interfaces.\n * Time, which must be implemented with a TimeImpl class with a three-argument constructor of type int (hours,...
2016
a01b
[ { "content": "package ex2016.a01b.sol1;\n\nimport java.util.Collection;\n\ninterface Builders {\n \n <X> ListBuilder<X> makeBasicBuilder();\n\n \n <X> ListBuilder<X> makeBuilderWithSize(int size);\n\n \n <X> ListBuilder<X> makeBuilderFromElements(Collection<X> from);\n\n \n <X> ListBuild...
[ { "content": "package ex2016.a01b.sol1;\n\nimport java.util.*;\n\n\npublic class BuildersImpl implements Builders {\n\n @Override\n public <X> ListBuilder<X> makeBasicBuilder() {\n return new BasicBuilder<>();\n }\n\n @Override\n public <X> ListBuilder<X> makeBuilderWithSize(int size) {\n ...
{ "components": { "imports": "package ex2016.a01b.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.*;\n\n/**\n * See the documentation of the Builders and ListBuilder interfaces.\n * \n * Builders (to be implemented in a class BuildersImpl with a constructor without arguments) models a factory for o...
2017
a04
[ { "content": "package a04.sol1;\n\n\npublic interface Player {\n\t\n\t\n\tint getId();\n\t\n\t\n\tString getName();\n}", "filename": "Player.java" }, { "content": "package a04.sol1;\n\n\npublic interface Match {\n\n\t\n\tPlayer getFirstPlayer();\n\n\t\n\tPlayer getSecondPlayer();\n}", "filename"...
[ { "content": "package a04.sol1;\n\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Optional;\nimport java.util.Set;\nimport java.util.stream.Collectors;\n\npublic class TurnamentImpl ...
{ "components": { "imports": "package a04.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n/**\n * In this exercise, a single-elimination tournament will be modeled (with quarter-finals, semi-finals, finals..),\n * with a bracket of the type shown in the figure (tabellone.gif.. the numbers shown...
2017
a03a
[ { "content": "package a03a.sol1;\n\nimport java.util.*;\n\n\npublic interface ExamsManagement {\n\t\n\t\n\tvoid createStudent(int studentId, String name);\n\t\n\t\n\tvoid createExam(String examName, int incrementalId);\n\t\n\t\n\tvoid registerStudent(String examName, int studentId);\n\t\n\t\n\tvoid examStarted(...
[ { "content": "package a03a.sol1;\n\nimport java.util.*;\nimport java.util.function.Predicate;\nimport java.util.function.Supplier;\nimport java.util.stream.Collectors;\n\npublic class ExamsManagementImpl implements ExamsManagement {\n\t\n\tprivate Set<Exam> exams = new HashSet<>();\n\tprivate Set<Student> stude...
{ "components": { "imports": "package a03a.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the ExamsManagement interface provided through an ExamsManagementImpl class with a constructor without arguments.\n\t * Realizes a concept of exam management (call...
2017
a06
[ { "content": "package a06.sol1;\n\nimport java.util.List;\nimport java.util.stream.*;\n\n\npublic interface Sequence<X> {\n\t\n\t\n\tX nextElement();\n\t\n\t\n\tdefault List<X> nextListOfElements(int size) {\n\t\treturn Stream.generate(this::nextElement).limit(size).collect(Collectors.toList());\n\t}\n\t\n}", ...
[ { "content": "package a06.sol1;\n\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.function.BinaryOperator;\nimport java.util.stream.Collectors;\nimport java.util.stream.Stream;\n\n/**\n * @author mirko\n * Soluzione con gli stream...\n */\npublic class SequenceHelpersImpl implements Sequen...
{ "components": { "imports": "package a06.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n/**\n * Please consult the documentation of the provided interfaces:\n * - Sequence<X> models an infinite and sequential source of data of type X\n * - SequenceHelpers models a set of functionalities to cr...
2017
a02a
[ { "content": "package a02a.sol1;\n\n\n\npublic interface SequenceAcceptor {\n\t\n\tstatic enum Sequence {\n\t\tPOWER2, FLIP, RAMBLE, FIBONACCI; \n\t}\n\n\t\n\tvoid reset(Sequence sequence);\n\t\n\t\n\tvoid reset();\n\n\t\n\t\n\tvoid acceptElement(int i);\n\t\t\n}", "filename": "SequenceAcceptor.java" }, ...
[ { "content": "package a02a.sol1;\n\nimport java.util.*;\nimport java.util.stream.Stream;\n\npublic class SequenceAcceptorImpl implements SequenceAcceptor {\n\t\n\tprivate static Map<Sequence,Iterable<Integer>> sequences;\n\t\n\tstatic {\n\t\tsequences = new HashMap<>();\n\t\tsequences.put(Sequence.POWER2, ()->S...
{ "components": { "imports": "package a02a.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the SequenceAcceptor interface provided through a SequenceAcceptorImpl class with a constructor without arguments.\n\t * Implements a concept of consumer of infini...
2017
a02b
[ { "content": "package a02b.sol1;\n\n\n\npublic interface Transducer<X,Y> {\n\t \n\t\n\tvoid provideNextInput(X x);\n\t\n\t\n\t\n\tvoid inputIsOver();\n\n\t\n\t\n\tboolean isNextOutputReady();\n\t\n\t\n\tY getOutputElement();\n\t\n\t\n\tboolean isOutputOver();\n}", "filename": "Transducer.java" }, { ...
[ { "content": "package a02b.sol1;\n\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.function.Supplier;\n\npublic class TransducerImpl<X, Y> implements Transducer<X, Y> {\n\n\tprivate final int maxSize;\n\tprivate Function<List<X>, Y> mapper;\n\tprivate List<X> queue;\n\tprivate boolean in...
{ "components": { "imports": "package a02b.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;", "private_init": "\t/*\n\t * An interface TransducerFactory is provided (to be implemented with a class TransducerFactoryImpl with a constructor without arguments),\n\t * which models a factory for Tran...
2017
a05
[ { "content": "package a05.sol1;\n\n\npublic interface Match {\n\n\t\n\tString getHomeTeam();\n\n\t\n\tString getAwayTeam();\n}", "filename": "Match.java" }, { "content": "package a05.sol1;\n\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\n\npublic class Combinations {...
[ { "content": "package a05.sol1;\n\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Map.Entry;\nimport java.util.Optional;\nimport java.util.Set;\nimport java.util.stream.Collectors;\n\npublic class ChampionshipImpl implements Championship {...
{ "components": { "imports": "package a05.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n/**\n * In this exercise, a championship organized in the Italian style (or rather, similar to Italian) will be modeled, i.e., with N teams\n * (even) that play (N-1)*2 days. A team can play at home or awa...
2017
a03b
[ { "content": "package a03b.sol1;\n\nimport java.util.*;\n\n\npublic interface ExamsManagement {\n\t\n\t\n\tvoid createStudent(int studentId, String name);\n\t\n\t\n\tvoid registerLabEvaluation(int studentId, int evaluation, int exam);\n\t\n\t\n\tvoid registerProjectEvaluation(int studentId, int evaluation, Stri...
[ { "content": "package a03b.sol1;\n\nimport java.util.*;\nimport java.util.function.Predicate;\nimport java.util.stream.Collectors;\n\npublic class ExamsManagementImpl implements ExamsManagement {\n\t\n\tprivate Set<Student> students = new HashSet<>();\n\t\n\tprivate static <T> T searchInSet(Set<T> set, Predicat...
{ "components": { "imports": "package a03b.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the ExamsManagement interface provided through an ExamsManagementImpl class with a constructor without arguments.\n\t * Realizes a concept of grade management for ...
2017
a01b
[ { "content": "package a01b.sol1;\n\n\npublic interface Event<X> {\n\t\n\tint getTime();\n\t\n\tX getValue();\n}", "filename": "Event.java" }, { "content": "package a01b.sol1;\n\nimport java.util.function.Supplier;\n\n\npublic interface TraceFactory {\n\n\t\n\t<X> Trace<X> fromSuppliers(Supplier<Inte...
[ { "content": "package a01b.sol1;\n\nimport java.util.function.Supplier;\nimport java.util.stream.IntStream;\n\npublic class TraceFactoryImpl implements TraceFactory {\n\n\t@Override\n\tpublic <X> Trace<X> fromSuppliers(Supplier<Integer> deltaTime, Supplier<X> value, int size) {\n\t\treturn new TraceImpl<>(IntSt...
{ "components": { "imports": "package a01b.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n/**\n * Please consult the documentation of the provided interfaces/class:\n * - Event<X> models a temporal event with value X\n * - EventImpl<X> is its trivial and usable implementation\n * - Trace<X> mo...
2018
a04
[ { "content": "package a04.sol1;\n\nimport java.util.Optional;\n\n\npublic interface SimpleIterator<T> {\n\n\t\n\tOptional<T> next();\n}", "filename": "SimpleIterator.java" }, { "content": "package a04.sol1;\n\nimport java.util.*;\n\n\n\ninterface IntegerIteratorsFactory {\n \n \n SimpleIter...
[ { "content": "package a04.sol1;\n\nimport java.util.Collections;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Optional;\nimport java.util.Random;\nimport java.util.stream.Stream;\n\npublic class IntegerIteratorsFactoryImpl implements IntegerIteratorsFactory {\n\t\n\t// idea: costruiamo ...
{ "components": { "imports": "package a04.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n/**\n * See the documentation of the SimpleIterator interface, which models an iterator, and that of\n * IntegerIteratorsFactory, a factory for various iterators on integers. Implement the latter through\n...
2018
a03a
[ { "content": "package a03a.sol1;\n\nimport java.util.Map;\n\nimport a03a.sol1.Evaluation.*;\n\n\ninterface EvaluationBuilder {\n\t\n\t\n\tEvaluationBuilder addEvaluationByMap(String course, int student, Map<Question,Result> results);\n\t\n\t\n\tEvaluationBuilder addEvaluationByResults(String course, int student...
[ { "content": "package a03a.sol1;\n\nimport java.util.*;\nimport java.util.Map.Entry;\nimport java.util.stream.Collectors;\nimport a03a.sol1.Evaluation.*;\n\npublic class EvaluationBuilderImpl implements EvaluationBuilder {\n\n\tprivate final Map<Pair<String, Integer>, Map<Question, Result>> map = new HashMap<>(...
{ "components": { "imports": "package a03a.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n/**\n * Please refer to the documentation of the provided interfaces:\n * - Evaluation models the results of the UNIBO student questionnaire for a certain set of courses\n * - EvaluationBuilder models a b...
2018
a02b
[ { "content": "package a02b.sol1;\n\nimport java.util.*;\n\n\npublic interface Tournament {\n\t\n\t\n\tString getName();\n\t\n\t\n\tint getYear();\n\t\t\n\t\n\tint getWeek();\n\n\t\n\tSet<String> getPlayers();\n\t\n\t\n\tOptional<Integer> getResult(String player);\n\t\n\t\n\tString winner();\n\t\n}", "filena...
[ { "content": "package a02b.sol1;\n\nimport java.util.*;\nimport java.util.stream.Collectors;\n\npublic class RankingImpl implements Ranking {\n\t\n\tprivate final List<Tournament> tournaments = new LinkedList<>();\n\t\n\t// Comparatore per tornei come costante\n\tprivate static final Comparator<Tournament> TC =...
{ "components": { "imports": "package a02b.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n\n/**\n * Please consult the documentation of the provided interfaces:\n * - Tournament models the results of a Tennis Tournament\n * - TournamentFactory models a simple factory for tournaments\n * - Rank...
2018
a06
[ { "content": "package a06.sol1;\n\nimport java.util.List;\n\n\npublic interface Parser {\n\t\n\t\n\tboolean acceptToken(String token);\n\t\n\t\n\tboolean inputCompleted();\n\t\n\t\n\tvoid reset();\n\n\t\n\t\n\tdefault boolean acceptAllToEnd(List<String> list) {\n\t\treturn list.stream().allMatch(s -> this.accep...
[ { "content": "package a06.sol1;\n\nimport java.util.Collections;\nimport java.util.List;\nimport java.util.Set;\n\n/**\n * This is a rather advanced solution, which some students may study and enjoy.\n * A simpler solution would be to develop each parser as a variation of the implementation of method oneOf.\n *...
{ "components": { "imports": "package a06.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n/**\n * Consult the documentation of the provided interfaces:\n * - Parser models a parser, i.e. a \"consumer\" of strings (tokens)\n * - ParserFactory models a set of functionalities for creating Parsers\...
2018
a01a
[ { "content": "package a01a.sol1;\n\nimport java.util.List;\nimport java.util.function.Function;\n\n\npublic interface SplitIteratorFactory {\n\t\n\t\n\tSplitIterator<Integer> fromRange(int start, int stop);\n\t\n\t\n\tSplitIterator<Integer> fromRangeNoSplit(int start, int stop);\n\t\n\t\n\t<X> SplitIterator<X> ...
[ { "content": "package a01a.sol1;\n\nimport java.util.List;\nimport java.util.Optional;\nimport java.util.function.Function;\n\npublic class SplitIteratorFactoryImpl implements SplitIteratorFactory {\n\n\t/* \n\t * The iterator should not cache future values!\n\t */\n\t@Override\n\tpublic SplitIterator<Integer> ...
{ "components": { "imports": "package a01a.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n/**\n * Please consult the documentation of the provided interfaces:\n * - SplitIterator<X> models an iterator of elements of type X, with the possibility of \"splitting\" creating a new iterator\n * - Sp...
2018
a02a
[ { "content": "package a02a.sol1;\n\nimport java.util.*;\n\n\npublic interface Tournament {\n\t\n\t\n\tenum Result {\n\t\tWINNER, \n\t\tFINALIST, \n\t\tSEMIFINALIST, \n\t\tQUARTERFINALIST, \n\t\tPARTICIPANT \n\t}\n\t\n\t\n\tenum Type {\n\t\tMAJOR, \n\t\tATP1000, \n\t\tATP500, \n\t\tATP250 \n\t}\n\t\n\t\n\tType ...
[ { "content": "package a02a.sol1;\n\nimport java.util.*;\nimport java.util.Map.Entry;\nimport java.util.stream.Collectors;\n\nimport a02a.sol1.Tournament.Result;\nimport a02a.sol1.Tournament.Type;\n\npublic class TournamentBuilderImpl implements TournamentBuilder {\n\t\n\t// codifico l'associazione torneo-punti ...
{ "components": { "imports": "package a02a.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\nimport a02a.sol1.Tournament.Result;\nimport a02a.sol1.Tournament.Type;\n\n/**\n * Please consult the documentation of the provided interfaces:\n * - Tournament models the results of a Tennis Tournament\n ...
2018
a05
[ { "content": "package a05.sol1;\n\nimport java.util.List;\nimport java.util.Optional;\n\n\npublic interface PowerIterator<T> {\n\n\t\n\tOptional<T> next();\n\t\n\t\n\tList<T> allSoFar();\n\t\n\t\n\t\n\tPowerIterator<T> reversed();\n}", "filename": "PowerIterator.java" }, { "content": "package a05.so...
[ { "content": "package a05.sol1;\n\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Optional;\nimport java.util.Random;\nimport java.util.function.Function;\nimport java.util.function.UnaryOperator;\nimport java.util.stream.Stream;\...
{ "components": { "imports": "package a05.sol1;\n\nimport static org.junit.Assert.*;\nimport org.hamcrest.CoreMatchers;\nimport org.hamcrest.CoreMatchers.*;\nimport java.util.*;\n\n/**\n * Consult the documentation of the PowerIteratorsFactory interface: it models a factory to\n * create various objects of type P...
2018
a03b
[ { "content": "package a03b.sol1;\n\nimport java.util.*;\n\n\npublic interface ConferenceReviewing {\n\t\n\t\n\tenum Question {\n\t\tRELEVANCE, \n\t\tSIGNIFICANCE, \t\n\t\tCONFIDENCE, \t\n\t\tFINAL; \t\n\t}\n\t\t\n\t\n\tvoid loadReview(int article, Map<Question,Integer> scores);\n\t\n\t\n\tvoid lo...
[ { "content": "package a03b.sol1;\n\nimport java.util.*;\nimport java.util.function.Function;\nimport java.util.stream.Collectors;\n\npublic class ConferenceReviewingImpl implements ConferenceReviewing {\n\t\n\tprivate final List<Pair<Integer,Map<Question, Integer>>> reviews = new ArrayList<>();\n\n\t@Override\n...
{ "components": { "imports": "package a03b.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\nimport a03b.sol1.ConferenceReviewing.Question;\n\n/**\n * Consult the documentation of the ConferenceReviewing interface, which models the results of the review process\n * of conference articles. Each ar...
2018
a01b
[ { "content": "package a01b.sol1;\n\nimport java.util.Optional;\n\npublic interface ExamResult {\n\t\n\tenum Kind {\n\t\tRETIRED, FAILED, SUCCEEDED\n\t}\n\t\n\tKind getKind();\n\t\n\tOptional<Integer> getEvaluation();\n\t\n\tboolean cumLaude();\n}", "filename": "ExamResult.java" }, { "content": "pack...
[ { "content": "package a01b.sol1;\n\nimport java.util.Optional;\n\nimport a01b.sol1.ExamResult.Kind;\n\n/**\n * Note: this solution is more verbose than needed, but it is still a good one since\n * it stresses separation of concepts (SRP principle) and avoidance of repetitions.\n * Alternative good solutions are...
{ "components": { "imports": "package a01b.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n/**\n * Consult the provided interfaces (and the corresponding tests below):\n * - ExamResult that models the possible results of a university exam\n * - ExamResultFactory that models a factory to denote/...
2019
a05a
[ { "content": "package a05a.sol1;\n\nimport java.util.*;\n\n\npublic interface IteratorOfListsFactory {\n\t\n\t\n\t<E> IteratorOfLists<E> iterative(E e);\n\t\n\t\n\t<E> IteratorOfLists<E> iterativeOnList(List<E> list);\n\t\n\t\n\t<E> IteratorOfLists<E> iterativeWithPreamble(E e, List<E> preamble);\n\t\t\n}", ...
[ { "content": "package a05a.sol1;\n\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.function.Supplier;\nimport java.util.stream.Collectors;\nimport java.util.stream.IntStream;\nimport java.util.stream.Stream;\n\npublic class Iterat...
{ "components": { "imports": "package a05a.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.List;", "private_init": "\t/*\n\t * Implement the IteratorOfListsFactory interface as indicated in the initFactory method below.\n\t * Implement a factory concept for IteratorOfLists, which in turn models...
2019
a03a
[ { "content": "package a03a.sol1;\n\n\npublic interface RWControllersFactory {\n\t\n\t\n\tRWController createPermissive();\n\t\n\t\n\tRWController createOnlyRead();\n\t\n\t\n\tRWController createMutualExclusion();\n\t\n\t\n\tRWController createManyReadersOrOneWriter();\n\n}", "filename": "RWControllersFactor...
[ { "content": "package a03a.sol1;\n\nimport java.util.*;\n\npublic class RWControllersFactoryImpl implements RWControllersFactory {\n\t\n\tenum State {\n\t\tENTERED, GO_READ, GO_WRITE\n\t}\n\t\n\t// This policy is used to state weather, given certain readers and writers, we can allow a new read/write\n\tinterfac...
{ "components": { "imports": "package a03a.sol1;\n\nimport static org.junit.Assert.*;", "private_init": "\t/*\n\t * Implement the RWControllerFactory interface as indicated in the initFactory method below.\n\t * Implement a factory concept for RWController, which in turn models the controller of a\n\t * resou...
2019
a02b
[ { "content": "package a02b.sol1;\n\npublic interface ExamsFactory {\n\t\n\t\n\tenum SimpleExamActivities {\n\t\tWRITTEN, ORAL, REGISTER\n\t}\n\t\n\t\n\tCourseExam<SimpleExamActivities> simpleExam();\n\n\t\n\tenum OOPExamActivities {\n\t\tLAB_REGISTER, LAB_EXAM, PROJ_PROPOSE, PROJ_SUBMIT, PROJ_EXAM, FINAL_EVALUA...
[ { "content": "package a02b.sol1;\n\nimport java.util.*;\nimport java.util.stream.*;\nimport static a02b.sol1.ExamsFactory.SimpleExamActivities.*;\nimport static a02b.sol1.ExamsFactory.OOPExamActivities.*;\n\npublic class ExamsFactoryImpl implements ExamsFactory {\n\t\n\t// the map associates to an activity thos...
{ "components": { "imports": "package a02b.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\nimport static a02b.sol1.ExamsFactory.SimpleExamActivities.*;\nimport static a02b.sol1.ExamsFactory.OOPExamActivities.*;", "private_init": "\t/*\n\t * Implement the ExamsFactory interface as indicated in...
2019
a06b
[ { "content": "package a06b.sol1;\n\nimport java.util.List;\n\n\npublic interface MiniAssemblyMachine {\n\t\n\t\n\tvoid inc(int register);\n\t\n\t\n\tvoid dec(int register);\n\t\n\t\n\tvoid jnz(int register, int target);\n\t\n\t\n\tvoid ret();\n\t\n\t\n\tList<Integer> execute(List<Integer> registers);\n\t\n}", ...
[ { "content": "package a06b.sol1;\n\nimport java.util.ArrayList;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Optional;\n\npublic class MiniAssemblyMachineImpl implements MiniAssemblyMachine {\n\t\n\tinterface Instruction {\n\t\tPair<Optional<Integer>,List<Integer>> exec(int counter, L...
{ "components": { "imports": "package a06b.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.List;", "private_init": "\t/*\n\t * Implement the MiniAssemblyMachine interface as indicated in the initFactory method below.\n\t * Implement an i...
2019
a01a
[ { "content": "package a01a.sol1;\n\nimport java.util.List;\nimport java.util.Set;\n\npublic interface GraphFactory {\n\n\t\n\t<X> Graph<X> createDirectedChain(List<X> nodes);\n\t\n\t\n\t<X> Graph<X> createBidirectionalChain(List<X> nodes);\n\t\n\t\n\t<X> Graph<X> createDirectedCircle(List<X> nodes);\n\t\n\t\n\t...
[ { "content": "package a01a.sol1;\n\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class GraphFactoryImpl implements GraphFactory {\n\t\n\t/**\n\t * A useful internal factory from a stream of edges..\n\t */\n\tprivate static <X> Graph<X> fromStream(Stream<Pair<X,X>> edgesStream){\n\t\treturn new Grap...
{ "components": { "imports": "package a01a.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the GraphFactory interface as indicated in the initFactory method below.\n\t * Implement a factory concept for directed graphs, where each node is represented by a...
2019
a02a
[ { "content": "package a02a.sol1;\n\nimport java.util.Set;\n\n\npublic interface Workflow<T> {\n\t\n\t\n\tSet<T> getTasks();\n\t\n\t\n\tSet<T> getNextTasksToDo();\n\t\n\t\n\tvoid doTask(T t);\n\t\n\t\n\tboolean isCompleted();\n\n}", "filename": "Workflow.java" }, { "content": "package a02a.sol1;\n\ni...
[ { "content": "package a02a.sol1;\n\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class WorkflowsFactoryImpl implements WorkflowsFactory {\n\t\n\t// the map associates to a task to those it needs to be done before starting\n\tprivate <T> Workflow<T> fromGraph(Map<T,Set<T>> map) {\n\t\treturn new Wor...
{ "components": { "imports": "package a02a.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the WorkflowsFactory interface as indicated in the initFactory method below.\n\t * Create a factory concept for workflows, modeled by the Workflow<T> interface. A ...
2019
a05b
[ { "content": "package a05b.sol1;\n\nimport java.util.Iterator;\nimport java.util.stream.Stream;\n\n\npublic interface IteratorIteratorFactory {\n\t\n\t\n\t<E> Iterator<Iterator<E>> constantWithSingleton(E e);\n\t\n\t\n\t<E> Iterator<Iterator<E>> increasingSizeWithSingleton(E e);\n\t\n\t\n\tIterator<Iterator<Int...
[ { "content": "package a05b.sol1;\n\nimport java.util.Iterator;\nimport java.util.function.Supplier;\nimport java.util.function.UnaryOperator;\nimport java.util.stream.Stream;\n\npublic class IteratorIteratorFactoryImpl implements IteratorIteratorFactory {\n\n\tprivate <E> Iterator<Iterator<E>> withSizes(Supplie...
{ "components": { "imports": "package a05b.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.List;", "private_init": "\t/*\n\t * Implement the IteratorIteratorFactory interface as indicated in the initFactory method below.\n\t * Create a f...
2019
a03b
[ { "content": "package a03b.sol1;\n\nimport java.util.List;\nimport java.util.Optional;\n\n\n\npublic interface PostOffice {\n\t\n\tenum Operation { SEND, RECEIVE }\n\t\n\t\n\tint getTicket(Operation operation);\n\t\n\t\n\tOptional<Operation> deskState(int desk);\n\t\n\t\n\tList<Integer> peopleWaiting();\n\t\n\t...
[ { "content": "package a03b.sol1;\n\nimport java.util.*;\nimport java.util.stream.*;\n\nimport a03b.sol1.PostOffice.Operation;\n\npublic class PostOfficeFactoryImpl implements PostOfficeFactory {\n\t\n\t// This policy is used to state, given a previous operation at a desk, what could be the next one\n\tinterface...
{ "components": { "imports": "package a03b.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.List;\nimport java.util.Optional;\nimport a03b.sol1.PostOffice.Operation;", "private_init": "\t/*\n\t * Implement the PostOfficeFactory interface as indicated in the initFactory method below.\n\t * Realiz...
2019
a06a
[ { "content": "package a06a.sol1;\n\n\npublic interface SRServiceFactory {\n\t\n\t\n\tSRService createMaximumAccess();\n\t\n\t\n\tSRService createWithNoConcurrentAccess();\n\t\n\t\n\tSRService createManyReceiveAndMaxTwoSend();\n\t\n}", "filename": "SRServiceFactory.java" }, { "content": "package a06a...
[ { "content": "package a06a.sol1;\n\nimport java.util.*;\n\npublic class SRServiceFactoryImpl implements SRServiceFactory {\n\t\n\tenum State {\n\t\tENTERED, GO_RECEIVE, GO_SEND\n\t}\n\t\n\t// This policy is used to state weather, given certain receiver and senders, we can allow a new receive/send\n\tinterface P...
{ "components": { "imports": "package a06a.sol1;\n\nimport static org.junit.Assert.*;", "private_init": "\t/*\n\t * Implement the SRServiceFactory interface as indicated in the initFactory method below.\n\t * Create a factory concept for SRService, which in turn models (the counter for) a postal service,\n\t ...
2019
a04b
[ { "content": "package a04b.sol1;\n\n\npublic interface ParsersFactory {\n\t\n\t\n\tParser<Integer> createSequenceParserToCount(String t);\n\t\n\t\n\tParser<String> createNonEmptySequenceParserToString(String t);\n\t\n\t\n\tParser<Integer> createExpressionParserToResult();\n}", "filename": "ParsersFactory.ja...
[ { "content": "package a04b.sol1;\n\nimport java.util.List;\nimport java.util.Optional;\nimport java.util.Set;\n\npublic class ParsersFactoryImpl implements ParsersFactory {\n\t\n\tprivate abstract class AbstractParser<R> implements Parser<R> {\n\t\t\n\t\tprotected boolean correct = true;\n\t\tprotected R result...
{ "components": { "imports": "package a04b.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.List;\n\nimport org.junit.Assert;", "private_init": "\t/*\n\t * A parser is a software component that consumes a sequence of tokens (strings) one by one, and when\n\t * finished, it recognizes whether the...
2019
a01b
[ { "content": "package a01b.sol1;\n\n\n\npublic class Cell<X> {\n\t\n\tprivate int row;\n\tprivate int column;\n\tprivate X value;\n\t\n\tpublic Cell(int row, int column, X value) {\n\t\tsuper();\n\t\tthis.row = row;\n\t\tthis.column = column;\n\t\tthis.value = value;\n\t}\n\n\tpublic int getRow() {\n\t\treturn ...
[ { "content": "package a01b.sol1;\n\nimport java.util.*;\nimport java.util.stream.IntStream;\n\npublic class GridImpl<X> implements Grid<X> {\n\t\n\tprivate Map<Pair<Integer,Integer>,X> map = new HashMap<>();\n\tprivate int rows;\n\tprivate int columns;\n\t\n\tpublic GridImpl(int rows, int columns) {\n\t\tsuper(...
{ "components": { "imports": "package a01b.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the GridFactory interface as indicated in the initFactory method below.\n\t * Implement a factory concept for rectangular grids, where each cell contains a\n\t * v...
2019
a04a
[ { "content": "package a04a.sol1;\n\nimport java.util.List;\n\n\npublic interface SequencesProvider<E> {\n\t\n\t\n\tList<E> nextSequence();\n\t\n\t\n\tboolean hasOtherSequences();\n\t\n\t\n\tvoid reset();\n\n\t\n}", "filename": "SequencesProvider.java" }, { "content": "package a04a.sol1;\n\n\npublic ...
[ { "content": "package a04a.sol1;\n\nimport java.util.Collections;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.function.Supplier;\nimport java.util.stream.Stream;\n\npublic class SequencesProvidersFactoryImpl implements SequencesProvidersFactory {\n\t\n\tprivate static <E> SequencesProv...
{ "components": { "imports": "package a04a.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.List;", "private_init": "\t/*\n\t * Implement the SequencesProvidersFactory interface as indicated in the initFactory method below.\n\t * Implement a factory concept for SequencesProvider, which in turn m...
2020
a04
[ { "content": "package a04.sol1;\n\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Optional;\n\n\npublic interface FunctionalStream<E> {\n\t\n\t\n\tinterface NextResult<E> {\n\t\tE getElement();\n\t\tFunctionalStream<E> getStream();\n\t}\n\t\n\t\n\t\n\tNextResult<E> next();\n\t\n\t\n\tList<...
[ { "content": "package a04.sol1;\n\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.List;\n\n@FunctionalInterface\npublic interface FunctionalStreamTemplate<E> extends FunctionalStream<E> {\n\n\t@Override\n\tdefault List<E> toList(int size) {\n\t\tvar list = new LinkedList<E>();\n\t\tF...
{ "components": { "imports": "package a04.sol1;\n\nimport static org.junit.Assert.assertEquals;\nimport static org.junit.Assert.assertTrue;\nimport java.util.List;", "private_init": "\t/*\n\t * Implement the FunctionalStreamFactory interface as indicated in the initFactory method\n\t * below. Creates a factor...
2020
a03a
[ { "content": "package a03a.sol1;\n\nimport java.util.Set;\nimport java.util.function.BiPredicate;\nimport java.util.function.Function;\nimport java.util.function.Predicate;\n\n\npublic interface GroupingFactory {\n\t\n\t\n\t<G,V> Grouping<G,V> fromPairs(Iterable<Pair<G,V>> values);\n\t\n\t\n\t<V> Grouping<V,V> ...
[ { "content": "package a03a.sol1;\n\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Map;\nimport java.util.Set;\nimport java.util.function.BiPredicate;\nimport java.util.function.Function;\nimport java.util.function.Predicate;\n\npublic class GroupingFactoryImpl implements GroupingFactory...
{ "components": { "imports": "package a03a.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Optional;\nimport java.util.Set;\nimport java.uti...
2020
a02b
[ { "content": "package a02b.sol1;\n\nimport java.util.function.Predicate;\n\n\npublic interface PatternExtractorFactory {\n\t\n\t\n\tPatternExtractor<Integer,Integer> countConsecutiveZeros();\n\t\n\t\n\tPatternExtractor<Double,Double> averageConsecutiveInRange(double min, double max);\n\t\n\t\n\tPatternExtractor...
[ { "content": "package a02b.sol1;\n\nimport java.util.ArrayList;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Optional;\nimport java.util.function.BiPredicate;\nimport java.util.function.Function;\nimport java.util.function.Predicate;\nimport java.util.stream.Stream;\n\npublic class Patt...
{ "components": { "imports": "package a02b.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n/**\n * Please refer to the documentation of the PatternExtractorFactory interface, which models\n * a factory for PatternExtractor, which in turn models a transformer from lists to\n * lists, which works...
2020
a06
[ { "content": "package a06.sol1;\n\nimport java.util.function.BinaryOperator;\nimport java.util.function.Function;\n\n\npublic interface BTree<L> {\n\n\t\n\tboolean isLeaf();\n\t\n\t\n\tL getLeaf();\n\t\n\t\n\tBTree<L> getLeft();\n\t\n\t\n\tBTree<L> getRight();\n\t\n\t\n\tL compute(BinaryOperator<L> function);\n...
[ { "content": "package a06.sol1;\n\nimport java.util.NoSuchElementException;\nimport java.util.function.BinaryOperator;\nimport java.util.function.Function;\n\nclass Cons<L> implements BTree<L>{\n\tprivate final BTree<L> left;\n\tprivate final BTree<L> right;\n\t\n\tpublic Cons(BTree<L> left, BTree<L> right) {\n...
{ "components": { "imports": "package a06.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.List;\nimport java.util.NoSuchElementException;", "private_init": "\t/*\n\t * Implement the BTreeFactory interface as indicated in the\n\t * initFactory method below. Create a factory for BTrees, i.e.,\n\t...
2020
a01a
[ { "content": "package a01a.sol1;\n\nimport java.util.List;\nimport java.util.Set;\n\n\npublic interface Tree<E> {\n\t\n\t\n\tE getRoot();\n\t\n\t\n\tList<Tree<E>> getChildren();\n\t\n\t\n\tSet<E> getLeafs();\n\t\n\t\n\tSet<E> getAll();\n\t\n\t\n\t@Override \n\tString toString();\n\t\n}", "filename": "Tree.j...
[ { "content": "package a01a.sol1;\n\nimport java.util.Collections;\nimport java.util.List;\nimport java.util.Set;\nimport java.util.stream.Collectors;\nimport java.util.stream.Stream;\n\npublic class TreeFactoryImpl implements TreeFactory {\n\n\t@Override\n\tpublic <E> Tree<E> singleValue(E root) {\n\t\treturn n...
{ "components": { "imports": "package a01a.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Set;\nimport java.util.stream.Collectors;", "private_init": "\t/*\n\t * Implement the TreeFactory interface as indicated i...
2020
a02a
[ { "content": "package a02a.sol1;\n\nimport java.util.Iterator;\n\n\npublic interface Scanner<X,Y>{\n\t\n\tY scan(Iterator<X> input);\n}", "filename": "Scanner.java" }, { "content": "package a02a.sol1;\n\n\n\npublic class Pair<X,Y> {\n\t\n\tprivate final X x;\n\tprivate final Y y;\n\t\n\tpublic Pair(...
[ { "content": "package a02a.sol1;\n\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Optional;\nimport java.util.function.BiFunction;\nimport java.util.function.Function;\nimport java.util.function.Predicate;\n\npublic class ScannerFactoryImpl implements Scanner...
{ "components": { "imports": "package a02a.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n/**\n * See the documentation of the ScannerFactory interface, which models\n * a factory for Scanner, which in turn models an object that takes a list\n * and extracts some information from it.\n * \n * ...
2020
a05
[ { "content": "package a05.sol1;\n\n\npublic interface BatteryFactory {\n\t\n\t\n\tBattery createSimpleBattery();\n\t\n\t\n\tBattery createSimpleBatteryByDrop(double energyPerDurationDrop);\n\n\t\n\tBattery createSimpleBatteryWithExponentialDrop();\n\n\t\n\tBattery createSecureBattery();\n\t\n\t\n\tBattery creat...
[ { "content": "package a05.sol1;\n\npublic class RechargableBattery extends BatteryDecorator {\n\t\n\tprivate static final double EFFICIENCY_LOSS = 0.01;\n\tprivate double rechargeValue = 1.0;\n\t\n\tpublic RechargableBattery(AbstractBattery base) {\n\t\tsuper(base);\n\t}\n\t\n\t@Override\n\tpublic void recharge...
{ "components": { "imports": "package a05.sol1;\n\nimport static org.junit.Assert.assertEquals;\nimport static org.junit.Assert.assertTrue;\nimport static org.junit.jupiter.api.Assertions.fail;\n\nimport java.util.List;\n\nimport org.junit.jupiter.api.Assertions;", "private_init": "\t/*\n\t * Implement the ba...
2020
a03c
[ { "content": "package a03c.sol1;\n\nimport java.util.Map;\nimport java.util.Set;\nimport java.util.function.BiFunction;\n\n\n\npublic interface TableFactory {\n\t\n\t\n\t<R,C,V> Table<R,C,V> fromMap(Map<Pair<R,C>,V> map);\n\t\n\t\n\t<R,C,V> Table<R,C,V> fromFunction(Set<R> rows, Set<C> columns, BiFunction<R,C,V...
[ { "content": "package a03c.sol1;\n\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Optional;\nimport java.util.Set;\nimport java.util.function.BiFunction;\nimport java.util.stream.Collectors;\nimport java.util.stream.IntStream;\nimport java.util.stream.Stream;\n\npublic class TableFactoryImp...
{ "components": { "imports": "package a03c.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Optional;\nimport java.util.Set;\nimport java.uti...
2020
a03b
[ { "content": "package a03b.sol1;\n\nimport java.util.Set;\n\n\npublic interface Equivalence<X> {\n\t\n\t\n\tboolean areEquivalent(X x1, X x2);\n\t\n\t\n\tSet<X> domain();\n\t\n\t\n\tSet<X> equivalenceSet(X x);\n\n\t\n\tSet<Set<X>> partition();\n\t\n\t\n\tboolean smallerThan(Equivalence<X> eq);\n\t\t\n}", "f...
[ { "content": "package a03b.sol1;\n\nimport java.util.Collections;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.util.function.BiPredicate;\nimport java.util.function.Function;\nimport java.util.stream.Collectors;\nimport java.util.stream.Stream;\n\npublic class EquivalenceFactoryImpl implements...
{ "components": { "imports": "package a03b.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.Set;", "private_init": "\t/*\n\t * Implement the EquivalenceFactory interface as indicated in the initFactory method\n\t * below. Implement a factory for Equivalence objects, i.e., objects that implement\...
2020
a02c
[ { "content": "package a02c.sol1;\n\nimport java.util.List;\n\n\npublic interface ListSplitter<X>{\n\t\t\n\t\n\tList<List<X>> split(List<X> list);\n\n}", "filename": "ListSplitter.java" }, { "content": "package a02c.sol1;\n\n\n\npublic class Pair<X,Y> {\n\t\n\tprivate final X x;\n\tprivate final Y y;...
[ { "content": "package a02c.sol1;\n\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.Optional;\nimport java.util.function.BiPredicate;\nimport java.util.function.Predicate;\nimport java.util.stream.Stream;\n\npublic class ListSplitterFactoryImpl implements ListSplitterFactory {\n\n\t/**\n\t...
{ "components": { "imports": "package a02c.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n/**\n * Consult the documentation of the ListSplitterFactory interface, which models\n * a factory for ListSplitter, which in turn models a transformer from lists to\n * lists of lists, which works by spl...
2020
a01b
[ { "content": "package a01b.sol1;\n\nimport java.util.Map;\nimport java.util.Set;\nimport java.util.function.Function;\nimport java.util.function.Predicate;\n\n\n\npublic interface MathematicalFunctionsFactory {\n\t\n\t\n\t<A,B> MathematicalFunction<A,B> constant(Predicate<A> domainPredicate, B value);\n\t\n\t\n...
[ { "content": "package a01b.sol1;\n\nimport java.util.Map;\nimport java.util.Optional;\nimport java.util.Set;\nimport java.util.function.Function;\nimport java.util.function.Predicate;\n\npublic class MathematicalFunctionsFactoryImpl implements MathematicalFunctionsFactory {\n\n\t@Override\n\tpublic <A, B> Mathe...
{ "components": { "imports": "package a01b.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n/**\n * Consult the documentation of the MathematicalFunctionFactor interface, which models\n * a factory for MathematicalFunction, which in turn models a mathematical function,\n * which maps elements of...
2021
a04
[ { "content": "package a04.sol1;\n\nimport java.util.List;\nimport java.util.function.Function;\nimport java.util.function.Supplier;\n\n\npublic interface EitherFactory {\n\t\n\t\n\t<A,B> Either<A,B> success(B b);\n\t\n\t\n\t<A,B> Either<A,B> failure(A a);\n\t\n\t\n\t<A> Either<Exception, A> of(Supplier<A> compu...
[ { "content": "package a04.sol1;\n\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.stream.Stream;\nimport java.util.stream.Collectors;\nimport java.util.function.Function;\nimport java.util.function.Supplier;\n\npublic class EitherFactoryImpl implements EitherFactory {\n\n\t@Override\n\tpu...
{ "components": { "imports": "package a04.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.List;\nimport java.util.Optional;", "private_init": "\t/*\n\t * Implement the EitherFactory interface as indicated in the initFactory method below.\n\t * Create a factory for Either<A,B> (\"A or B\"), i.e....
2021
a03a
[ { "content": "package a03a.sol1;\n\nimport java.util.List;\nimport java.util.function.Predicate;\n\n\npublic interface DecisionChainFactory {\n\t\n\t\n\t<A,B> DecisionChain<A,B> oneResult(B b);\n\t\n\t\n\t<A,B> DecisionChain<A,B> simpleTwoWay(Predicate<A> predicate, B positive, B negative);\n\t\n\t\n\t<A,B> Dec...
[ { "content": "package a03a.sol1;\n\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.NoSuchElementException;\nimport java.util.Optional;\nimport java.util.function.Predicate;\nimport java.util.stream.Collectors;\n\npublic class DecisionChainFactoryImpl implements DecisionChainFactory {\n\t...
{ "components": { "imports": "package a03a.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.List;\nimport java.util.Optional;\nimport java.util.function.Predicate;", "private_init": "\t/*\n\t * Implement the DecisionChainFactory interface as indicated in the\n\t * initFactory method below. Creat...
2021
a02b
[ { "content": "package a02b.sol1;\n\npublic interface UniversityProgramFactory {\n\t\n\t\n\tUniversityProgram flexible();\n\t\n\t\n\tUniversityProgram scientific();\n\t\n\t\n\tUniversityProgram shortComputerScience();\n\t\n\t\n\tUniversityProgram realistic();\n\n}", "filename": "UniversityProgramFactory.java...
[ { "content": "package a02b.sol1;\n\nimport static a02b.sol1.UniversityProgram.Sector.*;\n\nimport java.util.Set;\nimport java.util.function.Predicate;\n\nimport a02b.sol1.UniversityProgram.Sector;\n\npublic class UniversityProgramFactoryImpl implements UniversityProgramFactory {\n\t\n\tprivate static Pair<Predi...
{ "components": { "imports": "package a02b.sol1;\n\nimport static a02b.sol1.UniversityProgram.Sector.*;\nimport static org.junit.Assert.*;\n\nimport java.util.List;\nimport java.util.NoSuchElementException;\nimport java.util.Optional;\nimport java.util.Set;", "private_init": "\t/*\n\t * Implement the Universi...
2021
a06
[ { "content": "package a06.sol1;\n\n\npublic interface CirclerFactory {\n\t\n\t\n\t<T> Circler<T> leftToRight(); \n\t\n\t\n\t<T> Circler<T> alternate();\n\t\n\t\n\t<T> Circler<T> stayToLast();\n\t\n\t\n\t<T> Circler<T> leftToRightSkipOne();\n\t\n\t\n\t<T> Circler<T> alternateSkipOne();\n\t\n\t\n\t<T> Circler<T> ...
[ { "content": "package a06.sol1;\n\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.function.Function;\nimport java.util.stream.Stream;\nimport java.util.stream.Collectors;\n\n\n\n/**\n * An alternative solution would be to use template method, with CirclerTemplate\n * being an asbtract clas...
{ "components": { "imports": "package a06.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.List;", "private_init": "\t/*\n\t * Implement the CirclerFactory interface as indicated in the initFactory method below.\n\t * Create a factory for Circler<T> objects, which are objects with functionalitie...
2021
a01a
[ { "content": "package a01a.sol1;\n\nimport java.util.Optional;\n\n\npublic interface Acceptor<E,R> {\n\t\n\t\n\tboolean accept(E e);\n\t\n\t\n\tOptional<R> end();\n}", "filename": "Acceptor.java" }, { "content": "package a01a.sol1;\n\nimport java.util.Optional;\nimport java.util.function.BiFunction;...
[ { "content": "package a01a.sol1;\n\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Optional;\nimport java.util.function.BiFunction;\nimport java.util.function.Function;\nimport java.util.stream.Collectors;\n\n// Soluzione base, senza rimozione ripetizioni via pattern\n\npublic class Acce...
{ "components": { "imports": "package a01a.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.NoSuchElementException;\nimport java.util.Optional;\nimport java.util.function.BiFunction;\nimport java.util.function.Function;", "private_init": "\t/*...
2021
a02a
[ { "content": "package a02a.sol1;\n\nimport java.util.Map;\n\n\npublic interface Diet {\n\t\n\t\n\tenum Nutrient {\n\t\tCARBS, PROTEINS, FAT\n\t}\n\t\n\t\n\tvoid addFood(String name, Map<Nutrient,Integer> nutritionMap);\n\t\n\t\n\tboolean isValid(Map<String, Double> dietMap);\n\n}", "filename": "Diet.java" ...
[ { "content": "package a02a.sol1;\n\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Set;\nimport java.util.function.Predicate;\n\npublic abstract class AbstractDiet implements Diet {\n\t\n\tprivate final Map<String,Map<Nutrient, Integer>> products = new HashMap<>();\n\n\t@Override\n\tpublic v...
{ "components": { "imports": "package a02a.sol1;\n\nimport static a02a.sol1.Diet.Nutrient.*;\nimport static org.junit.Assert.*;\n\nimport java.util.Map;", "private_init": "\t/*\n\t * Implement the DietFactory interface as indicated in the\n\t * initFactory method below. Create a factory for a diet concept, ca...
2021
a05
[ { "content": "package a05.sol1;\n\nimport java.util.Iterator;\nimport java.util.function.Function;\n\n\npublic interface State<S,A> {\n\t\n\t\n\tS nextState(S s);\n\t\n\t\n\tA value(S s);\n\t\n\t\n\t<B> State<S,B> map(Function<A,B> fun);\n\t\n\t\n\tIterator<A> iterator(S s0);\n}", "filename": "State.java" ...
[ { "content": "package a05.sol1;\n\nimport java.util.Iterator;\nimport java.util.function.Function;\nimport java.util.stream.Stream;\n\npublic class StateFactoryImpl implements StateFactory {\n\n\t@Override\n\tpublic <S, A> State<S, A> fromFunction(Function<S, Pair<S, A>> fun) {\n\t\treturn new State<S,A>(){\n\n...
{ "components": { "imports": "package a05.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.Iterator;\n\nimport a05.sol1.StateFactory.CounterOp;", "private_init": "\t/*\n\t * Implement the StateFactory interface as indicated in the initFactory method below.\n\t * Create a factory for State<S,A>, ...
2021
a01c
[ { "content": "package a01c.sol1;\n\n\npublic interface EventHistory<E> {\n\t\n\t\n\tdouble getTimeOfEvent();\n\t\n\t\n\tE getEventContent();\n\t\n\t\n\tboolean moveToNextEvent();\n}", "filename": "EventHistory.java" }, { "content": "package a01c.sol1;\n\nimport java.util.Objects;\n\n\n\npublic class...
[ { "content": "package a01c.sol1;\n\nimport java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.Reader;\nimport java.nio.file.Files;\nimport java.nio.file.Path;\nimport java.util.HashMap;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Map;\nimpo...
{ "components": { "imports": "package a01c.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.io.IOException;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.NoSuchElementException;\nimport java.util.Random;\nimport java.util.function.Supplier;\nimport java.util.stream.Stream;", "priva...
2021
a03c
[ { "content": "package a03c.sol1;\n\n\npublic interface DeterministicParserFactory {\n\n\t\n\tDeterministicParser oneSymbol(String s);\n\t\n\t\n\tDeterministicParser twoSymbols(String s1, String s2);\n\t\n\t\n\tDeterministicParser possiblyEmptyIncreasingSequenceOfPositiveNumbers();\n\t\n\t\n\tDeterministicParser...
[ { "content": "package a03c.sol1;\n\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Optional;\nimport java.util.function.Predicate;\n\npublic class DeterministicParserFactoryImpl implements DeterministicParserFactory {\n\t\n\tprivate static <E> Optional<List<E>> takeTail(List<E> list){\n\...
{ "components": { "imports": "package a03c.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.List;\nimport java.util.Optional;", "private_init": "\t/*\n\t * Implement the DeterministicParserFactory interface as indicated in the method\n\t * initFactory below. Create a factory for DeterministicPar...
2021
a03b
[ { "content": "package a03b.sol1;\n\n\n\npublic interface Lens<S,A> {\n\t\n\t\n\tA get(S s);\n\t\n\t\n\tS set(A a, S s);\n}", "filename": "Lens.java" }, { "content": "package a03b.sol1;\n\nimport java.util.List;\nimport java.util.function.BiFunction;\nimport java.util.function.Function;\n\n\npublic i...
[ { "content": "package a03b.sol1;\n\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.function.BiFunction;\nimport java.util.function.Function;\n\npublic class LensFactoryImpl implements LensFactory {\n\n\tprivate static <E> List<E> copyAndSet(List<E> l, int index, E e){\n\t\tvar lo = new Ar...
{ "components": { "imports": "package a03b.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.NoSuchElementException;\nimport java.util.Optional;\nimport java.util.function.BiFunction;\nimport java.util.function.Function;", "private_init": "\t/*...
2021
a02c
[ { "content": "package a02c.sol1;\n\npublic interface UniversityProgramFactory {\n\t\n\t\n\tUniversityProgram flexible();\n\t\n\t\n\tUniversityProgram fixed();\n\t\n\t\n\tUniversityProgram balanced();\n\t\n\t\n\tUniversityProgram structured();\n\n}", "filename": "UniversityProgramFactory.java" }, { "...
[ { "content": "package a02c.sol1;\n\nimport java.util.Set;\nimport java.util.function.Predicate;\nimport static a02c.sol1.UniversityProgram.Group.*;\n\npublic class UniversityProgramFactoryImpl implements UniversityProgramFactory {\n\n\t@Override\n\tpublic UniversityProgram flexible() {\n\t\treturn new AbstractU...
{ "components": { "imports": "package a02c.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Set;\n\nimport a02c.sol1.UniversityProgram.Group;\n\nimport static a02c.sol1.UniversityProgram.Group.*;", "private_init": "\t/*\n\t * Implement the Univer...
2021
a01b
[ { "content": "package a01b.sol1;\n\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Optional;\nimport java.util.function.Predicate;\n\n\npublic interface EventSequenceProducerHelpers {\n\t\n\t\n\t<E> EventSequenceProducer<E> fromIterator(Iterator<Pair<Double,E>> iterator);\n\t\n\t\n\t<E> Li...
[ { "content": "package a01b.sol1;\n\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.NoSuchElementException;\nimport java.util.Optional;\nimport java.util.function.Predicate;\nimport java.util.function.Supplier;\nimport java.util.stream.Stream;\nimport java.util.stream...
{ "components": { "imports": "package a01b.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.List;\nimport java.util.NoSuchElementException;\nimport java.util.Optional;", "private_init": "\t/*\n\t * Implement the EventSequenceProducerHelpers interface as indicated in the method\n\t * initFactory ...
2022
a04
[ { "content": "package a04.sol1;\n\n\npublic interface BankAccount {\n\n \n int getBalance();\n\n \n void deposit(int amount);\n\n \n boolean withdraw(int amount);\n \n}", "filename": "BankAccount.java" }, { "content": "package a04.sol1;\n\nimport java.util.function.BiPredicate;\nimpor...
[ { "content": "package a04.sol1;\n\nimport java.util.function.BiPredicate;\nimport java.util.function.Predicate;\nimport java.util.function.UnaryOperator;\n\npublic class BankAccountFactoryImpl implements BankAccountFactory {\n\n private static abstract class AbstractBankAccount implements BankAccount {\n ...
{ "components": { "imports": "package a04.sol1;\n\nimport static org.junit.Assert.*;\n\n/**\n * See the documentation of the BankAccountFactory interface, which models\n * a factory for BankAccount, which in turn models a current account with a certain balance,\n * and the possibility of depositing money (deposit...
2022
a02b
[ { "content": "package a02b.sol1;\n\n\npublic interface Cursor<X>{\n\t\t\n\t\n\tX getElement(); \n\t\n\t\n\tboolean advance(); \n\n}", "filename": "Cursor.java" }, { "content": "package a02b.sol1;\n\nimport java.util.List;\nimport java.util.function.Consumer;\n\n\npublic interface CursorHelpers {\n\t...
[ { "content": "package a02b.sol1;\n\nimport java.util.ArrayList;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.function.Consumer;\nimport java.util.stream.Stream;\n\npublic class CursorHelpersImpl implements CursorHelpers {\n\n private <X> Cursor<X> fromNonEmptyIterator(Iterator<X> ite...
{ "components": { "imports": "package a02b.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n/**\n * Please consult the documentation of the CursorHelpers interface, which models\n * helpers (factories and transformers) for Cursor, which in turn models a cursor,\n * essentially equivalent to an i...
2022
a01a
[ { "content": "package a01a.sol1;\n\nimport java.util.List;\nimport java.util.function.Function;\n\n\npublic interface SubsequenceCombinerFactory {\n\n\t\n\tSubsequenceCombiner<Integer,Integer> tripletsToSum();\n\t\n\t\n\t<X> SubsequenceCombiner<X,List<X>> tripletsToList();\n\t\n\t\n\tSubsequenceCombiner<Integer...
[ { "content": "package a01a.sol1;\n\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.function.Function;\nimport java.util.function.Predicate;\n\npublic class SubsequenceCombinerFactoryImpl implements SubsequenceCombinerFactory {\n\n private <X,Y> SubsequenceCombiner<X,Y> generic(Predicat...
{ "components": { "imports": "package a01a.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n/**\n * Please consult the documentation of the SubsequenceCombinerFactory interface, which models\n * a factory for SubsequenceCombiner, which in turn models a transformer from lists to\n * lists, which ...
2022
a02a
[ { "content": "package a02a.sol1;\n\nimport java.util.List;\n\n\npublic interface RecursiveIteratorHelpers {\n \n \n\t<X> RecursiveIterator<X> fromList(List<X> list);\n\n \n\t<X> List<X> toList(RecursiveIterator<X> input, int max);\n\n \n <X,Y> RecursiveIterator<Pair<X,Y>> zip(RecursiveIterator<X>...
[ { "content": "package a02a.sol1;\n\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.function.Supplier;\nimport java.util.function.UnaryOperator;\nimport java.util.stream.Collectors;\nimport java.util.stream.Stream;\n\npublic class RecursiveIteratorHelpersImpl implements RecursiveIteratorHel...
{ "components": { "imports": "package a02a.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n/**\n * Please consult the documentation of the RecursiveIteratorHelpers interface, which models\n * helpers (factories and transformers) for RecursiveIterator, which in turn models an iterator,\n * i.e.,...
2022
a03b
[ { "content": "package a03b.sol1;\n\nimport java.util.Map;\nimport java.util.Optional;\nimport java.util.function.Supplier;\nimport java.util.function.UnaryOperator;\n\n\npublic interface LazyTreeFactory {\n\n \n <X> LazyTree<X> constantInfinite(X value);\n \n \n <X> LazyTree<X> fromMap(X root, Ma...
[ { "content": "package a03b.sol1;\n\nimport java.util.Map;\nimport java.util.NoSuchElementException;\nimport java.util.Optional;\nimport java.util.function.Supplier;\nimport java.util.function.UnaryOperator;\n\npublic class LazyTreeFactoryImpl implements LazyTreeFactory {\n\n @Override\n public <X> LazyTre...
{ "components": { "imports": "package a03b.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\n\n/**\n * See the documentation of the LazyTreeFactory interface, which models\n * a factory for LazyTree, which in turn models a \"lazy\" binary tree, i.e.\n * where the left and right child of a node are ...
2022
a01b
[ { "content": "package a01b.sol1;\n\nimport java.util.List;\nimport java.util.function.Function;\n\n\npublic interface FlattenerFactory {\n\t\n\t\n\tFlattener<Integer,Integer> sumEach();\n\n\t\n\t<X> Flattener<X,X> flattenAll();\n\n\t\n\tFlattener<String, String> concatPairs();\n\n\t\n\t<I,O> Flattener<I,O> each...
[ { "content": "package a01b.sol1;\n\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.function.BiFunction;\nimport java.util.function.Function;\nimport java.util.function.Predicate;\nimport java.util.stream.Collectors;\nimport java.util.stream.IntStream;\nimport java.util.stream.Stream;\n\np...
{ "components": { "imports": "package a01b.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\nimport java.util.stream.Collectors;\n\n/**\n * Consult the documentation of the FlattenerFactory interface, which models\n * a factory for Flattener, which in turn models a transformer from lists of lists t...
2023
a01d
[ { "content": "package a01d.sol1;\n\npublic interface TimetableFactory {\n \n \n Timetable empty();\n}", "filename": "TimetableFactory.java" }, { "content": "package a01d.sol1;\n\nimport java.util.*;\n\n\npublic interface Timetable {\n\n public static enum Day { MON, TUE, WED, THU, FRI }\...
[ { "content": "package a01d.sol1;\n\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class TimetableFactoryImpl implements TimetableFactory {\n\n // An implementation of a Booking as an immutable class with a room, course, day and (single) hour\n // Since it is immutable, we use a record, which a...
{ "components": { "imports": "package a01d.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the TimetableFactory interface as indicated in the initFactory method below.\n\t * Create a factory for a concept of \"weekly university lesson timetable\", captur...
2023
a04
[ { "content": "package a04.sol1;\n\nimport java.util.List;\nimport java.util.Optional;\nimport java.util.function.*;\n\npublic interface ListExtractorFactory {\n\t\n\t\n\t<X> ListExtractor<X, Optional<X>> head();\n\n\t\n\t<X, Y> ListExtractor<X, List<Y>> collectUntil(Function<X,Y> mapper, Predicate<X> stopCondit...
[ { "content": "package a04.sol1;\n\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Optional;\nimport java.util.function.Function;\nimport java.util.function.Predicate;\n\npublic class ListExtractorFactoryImpl implements ListExtractorFactory {\n\n abstract class AbstractListExtractor<X,...
{ "components": { "imports": "package a04.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the ListExtractorFactory interface as indicated in the initFactory\n\t * method below. Create a factory for a ListExtractor concept, captured by the\n\t * interfa...
2023
a03a
[ { "content": "package a03a.sol1;\n\nimport java.util.*;\n\n\n\npublic interface Windowing<X, Y> {\n\n \n Optional<Y> process(X x);\n}", "filename": "Windowing.java" }, { "content": "package a03a.sol1;\n\nimport java.util.List;\n\n\npublic interface WindowingFactory {\n\n \n <X> Windowing...
[ { "content": "package a03a.sol1;\n\nimport java.util.*;\nimport java.util.function.*;\n\npublic class WindowingFactoryImpl implements WindowingFactory {\n\n private <X,Y> Windowing<X,Y> genericWindowing(Predicate<List<X>> ready, Function<List<X>, Y> mapper){\n return new Windowing<X,Y>() {\n\n ...
{ "components": { "imports": "package a03a.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the WindowingFactory interface as indicated in the initFactory method below.\n\t * Create a factory for a Windowing concept, which is a particular type of transf...
2023
a02b
[ { "content": "package a02b.sol1;\n\nimport java.util.List;\n\npublic interface RulesEngineFactory {\n\n \n <T> List<List<T>> applyRule(Pair<T, List<T>> rule, List<T> input);\n\n \n <T> RulesEngine<T> singleRuleEngine(Pair<T, List<T>> rule);\n\n \n <T> RulesEngine<T> cascadingRulesEngine(Pair<T...
[ { "content": "package a02b.sol1;\n\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.stream.Stream;\n\n/*\n * Idea of the solution: a single rule engine can capture all cases!\n * For each element in the input checks which rules can apply, each rule\n * is appli...
{ "components": { "imports": "package a02b.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the RulesEngineFactory interface as indicated in the initFactory method below.\n\t * Create a factory for a \"rules engine\" concept, captured by the RulesEngine...
2023
a01a
[ { "content": "package a01a.sol1;\n\nimport java.util.function.*;\n\npublic interface TimetableFactory {\n\t\n\t\n\tTimetable empty();\n\n\t\n\tTimetable single(String activity, String day);\n\n\t\n\tTimetable join(Timetable table1, Timetable table2);\n\n\t\n\tTimetable cut(Timetable table, BiFunction<String, St...
[ { "content": "package a01a.sol1;\n\nimport java.util.*;\nimport java.util.stream.*;\n\nimport java.util.function.*;\n\npublic class TimetableFactoryImpl implements TimetableFactory {\n\n private static <T> Set<T> addToSet(Set<T> s, T t){\n return concatSet(s, Set.of(t));\n }\n\n private static <...
{ "components": { "imports": "package a01a.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the TimetableFactory interface as indicated in the initFactory\n\t * method below. Create a factory for a timetable concept, captured by the\n\t * Timetable inte...
2023
a02a
[ { "content": "package a02a.sol1;\n\nimport java.util.*;\n\n\npublic interface ListBuilderFactory {\n\n \n <T> ListBuilder<T> empty();\n\n \n <T> ListBuilder<T> fromElement(T t);\n\n \n <T> ListBuilder<T> fromList(List<T> list);\n\n \n <T> ListBuilder<T> join(T start, T stop, List<ListBu...
[ { "content": "package a02a.sol1;\n\nimport java.util.*;\nimport java.util.stream.*;\nimport java.util.function.Function;\n\npublic class ListBuilderFactoryImpl implements ListBuilderFactory {\n\n // a utility function, essentially a flatMap for builders\n private <R,T> ListBuilder<R> flatMap(ListBuilder<T...
{ "components": { "imports": "package a02a.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the ListBuilderFactory interface as indicated in the initFactory method\n\t * below. Create a factory for a ListBuilder concept,\n\t * i.e., an immutable object...
2023
a01c
[ { "content": "package a01c.sol1;\n\nimport java.util.*;\n\npublic interface TimeSheetFactory {\n\t\n\t\n\tTimeSheet ofRawData(List<Pair<String, String>> data);\n\n\t\n\tTimeSheet withBoundsPerActivity(List<Pair<String, String>> data, Map<String, Integer> boundsOnActivities);\n\n\t\n\tTimeSheet withBoundsPerDay(...
[ { "content": "package a01c.sol1;\n\nimport java.util.*;\nimport java.util.stream.*;\n\nimport java.util.function.*;\n\npublic class TimeSheetFactoryImpl implements TimeSheetFactory {\n\n // An implementation of a Timesheet as an immutable class with activities, days, and an association of activities+days to ...
{ "components": { "imports": "package a01c.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the TimeSheetFactory interface as indicated in the initFactory\n\t * method below. Creates a factory for a Timesheet concept, captured by the\n\t * Timesheet inter...
2023
a03b
[ { "content": "package a03b.sol1;\n\nimport java.util.List;\n\n\npublic interface InfiniteIteratorsHelpers {\n\t\n\t\n\t<X> InfiniteIterator<X> of(X x);\n\t\n\t\n\t<X> InfiniteIterator<X> cyclic(List<X> l);\n\t\n\t\n\tInfiniteIterator<Integer> incrementing(int start, int increment);\n\n\t\n\t<X> InfiniteIterator...
[ { "content": "package a03b.sol1;\n\nimport java.util.Collections;\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.stream.Stream;\n\n// Soluzione con stream\npublic class InfiniteIteratorHelpersImpl implements InfiniteIteratorsHelpers {\n\n\tprivate <X> Infinit...
{ "components": { "imports": "package a03b.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the InfiniteIteratorHelpers interface as indicated in the method\n\t * initFactory below. Implement an interface of utility functions for an\n\t * infinite itera...
2023
a02c
[ { "content": "package a02c.sol1;\n\nimport java.util.*;\n\n\n@FunctionalInterface\npublic interface Replacer<T> {\n\n \n List<List<T>> replace(List<T> input, T t);\n\n}", "filename": "Replacer.java" }, { "content": "package a02c.sol1;\n\nimport java.util.*;\n\n\npublic interface ReplacersFacto...
[ { "content": "package a02c.sol1;\n\nimport java.util.*;\nimport java.util.function.*;\nimport java.util.stream.*;\n\npublic class ReplacersFactoryImpl implements ReplacersFactory {\n\n private <T> List<T> replaceAtPosition(int index, List<T> source, List<T> destination){\n var l = new LinkedList<>(sou...
{ "components": { "imports": "package a02c.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the ReplacerFactory interface as indicated in the initFactory method below.\n\t * Create a factory for a Replacer concept, i.e., a functionality that, given a li...
2023
a01b
[ { "content": "package a01b.sol1;\n\nimport java.util.*;\n\npublic interface TimeSheetFactory {\n\t\n\t\n\tTimeSheet flat(int numActivities, int numNames, int hours);\n\n\t\n\tTimeSheet ofListsOfLists(List<String> activities, List<String> days, List<List<Integer>> data);\n\n\t\n\tTimeSheet ofRawData(int numActiv...
[ { "content": "package a01b.sol1;\n\nimport java.util.*;\nimport java.util.stream.*;\n\nimport java.util.function.*;\n\npublic class TimeSheetFactoryImpl implements TimeSheetFactory {\n\n // An implementation of a Timetable as an immutable class with activities, days, and an association of activities+days to ...
{ "components": { "imports": "package a01b.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the TimeSheetFactory interface as indicated in the initFactory\n\t * method below. Implement a factory for a Timesheet concept, captured by the\n\t * Timesheet i...
2024
a03a
[ { "content": "package a03a.sol1;\n\nimport java.util.Set;\n\n\npublic interface Cell<E> {\n\n \n E getResult();\n\n \n boolean isModifiable();\n\n \n Set<Cell<E>> dependsFrom();\n\n \n void write(E value);\n\n}", "filename": "Cell.java" }, { "content": "package a03a.sol1;\n\n...
[ { "content": "package a03a.sol1;\n\nimport java.util.Collections;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Set;\nimport java.util.function.BinaryOperator;\n\npublic class CellsFactoryImpl implements CellsFactory {\n\n private static class ValueCell<E>...
{ "components": { "imports": "package a03a.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the CellsFactory interface as indicated in the init method below.\n\t * Implements a factory for \"cells\" similar to those in a spreadsheet (like Excel),\n\t * wh...
2024
a02b
[ { "content": "package a02b.sol1;\n\nimport java.util.Objects;\n\n\n\npublic class Pair<E1,E2> {\n\t\n\tprivate final E1 e1;\n\tprivate final E2 e2;\n\t\n\tpublic Pair(E1 x, E2 y) {\n\t\tsuper();\n\t\tthis.e1 = x;\n\t\tthis.e2 = y;\n\t}\n\n\tpublic E1 get1() {\n\t\treturn e1;\n\t}\n\n\tpublic E2 get2() {\n\t\tre...
[ { "content": "package a02b.sol1;\n\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Map;\nimport java.util.Set;\nimport java.util.function.Function;\nimport java.util.function.Supplier;\nimport java.util.stream.Collectors;\n\npublic class SimpleDBImpl implements SimpleDB {\n\n // a Tab...
{ "components": { "imports": "package a02b.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the SimpleDB interface as indicated in the init method below.\n\t * Implement a DB made of tables and views (a view shows a part of a table). Read\n\t * the commen...
2024
a01a
[ { "content": "package a01a.sol1;\n\nimport java.util.List;\nimport java.util.Set;\n\n\npublic interface ComposableParserFactory {\n\n \n <X> ComposableParser<X> empty();\n \n \n <X> ComposableParser<X> one(X x);\n \n \n <X> ComposableParser<X> fromList(List<X> list);\n\n \n <X> Com...
[ { "content": "package a01a.sol1;\n\nimport java.util.Collections;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Set;\nimport static java.util.stream.Collectors.*;\nimport java.util.stream.Stream;\n\npublic class ComposableParserFactoryImpl implements ComposableParserFactory {\n\n priv...
{ "components": { "imports": "package a01a.sol1;\n\nimport static org.junit.Assert.*;\n\nimport java.util.*;\nimport java.util.function.Supplier;", "private_init": "\t/*\n\t * Implement the ComposableParserFactory interface as indicated in the method\n\t * initFactory below. Create a factory for a concept of ...
2024
a02a
[ { "content": "package a02a.sol1;\n\nimport java.util.List;\nimport java.util.Optional;\nimport java.util.Set;\n\n\npublic interface SpreadRow {\n\n \n int size();\n\n \n boolean isFormula(int index);\n\n \n boolean isNumber(int index);\n\n \n boolean isEmpty(int index);\n\n \n List...
[ { "content": "package a02a.sol1;\n\nimport java.util.Collections;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Optional;\nimport java.util.Set;\nimport java.util.function.BinaryOperator;\n\npublic class SpreadRowImpl implements SpreadRow {\n\n private static record Cell(BinaryOpera...
{ "components": { "imports": "package a02a.sol1;\n\nimport static org.junit.Assert.*;\nimport java.util.*;", "private_init": "\t/*\n\t * Implement the SpreadRow interface as indicated in the init method below.\n\t * Create a sort of \"excel sheet\" (Spreadsheet) made of a single row.\n\t * Read the comments i...