id
stringlengths
36
36
text
stringlengths
1
1.25M
78fd3ad7-4e80-4548-8a89-b712d76a7b00
public char getType() { return type; }
33add217-5a3d-4eb0-a322-b4fd4c33daa1
public void setType(char t) { type = t; }
7f1e0760-de46-4120-8bdb-3f98e5bad14a
public Game() { turn = 0; elozoSiker = true; gameWon = false; gui = new GUI(600, 745, this); gui.addText("Initializing....."); }
dfa14cdc-8724-4bfc-8c11-9f9ce53ed4ba
public final void newGame(int boardsize, int tokentowin) { board = new Board(boardsize, tokentowin); elozoSiker = true; turn = 0; gameWon = false; gui.generateTable(board.getSize()); gui.addText("Starting game."); newPlayer(); }
394a6711-27a4-46dd-8c40-34d63abffafa
public final void newPlayer() { Random rdgen = new Random(); int rdnumber = rdgen.nextInt(2); if (rdnumber == 0) { p1 = new Player('o'); p2 = new Player('x'); } else if (rdnumber == 1) { p1 = new Player('x'); p2 = new Player('o'); } gui.addText(p1.getType() + " turn"); }
d135cbed-29d2-4376-ba24-dc0210b1d142
public Player getNextPlayer() { if (turn == 0) { turn = 1; gui.addText(p2.getType() + " turn"); return p1; } else { turn = 0; gui.addText(p1.getType() + " turn"); return p2; } }
3c194ded-1b59-4347-8ac5-0cc41575ea29
public Player getPrevPlayer() { if (turn == 0) { if (!elozoSiker) { gui.addText(p1.getType() + " turn"); } return p2; } else { if (!elozoSiker) { gui.addText(p2.getType() + " turn"); } return p1; } }
255b346f-f532-43b6-adbb-dcbcd7ff5589
public boolean addToken(int x, int y, Token t) { if (board.addToken(x, y, t)) { int i = board.getGameState(x, y, t.getType()); if (i > 0) { endGame(i); gameWon = true; } elozoSiker = true; return true; } else { gui.addText("HIBA: Az a mezo mar foglalt!"); gui.addText(getPrevPlayer().getType() + " turn again!"); elozoSiker = false; return false; } }
349a0c38-0c40-4552-9bdb-89fc072a4ec6
public void endGame(int i) { switch (i) { case 1: gui.addText("And the WINNER is: O!"); break; case 2: gui.addText("And the WINNER is: X!"); break; case 3: gui.addText("The game ended in TIE!"); break; } }
0175b21d-4c67-4c79-b6fd-2d9017d35eec
public boolean getElozoSiker() { return elozoSiker; }
65bcfc94-c207-471e-8cf0-3c8a65851957
public void setElozoSiker(boolean elozoSiker) { this.elozoSiker = elozoSiker; }
a07ed600-c83d-481c-beea-f80434d65373
public boolean isGameWon() { return gameWon; }
4c4b62fe-0793-402a-bfd3-d733b84d272e
public static void main(String[] args) { Game jatek = new Game(); }
efa63f30-f56a-408f-8930-43e036a8003c
public static void main(String[] args) { test(); testRunnable(); testCollections(); }
761ac819-8418-4d05-aded-c22c73add9a2
public static void test() { System.out.println("# Invoking function: 1.1+"); Java11.test(); Java12.test(); Java13.test(); Java14.test(); Java15.test(); Java16.test(); }
31897161-7b6e-4092-80a5-07ec4d758d21
public static void testRunnable() { System.out.println("# Passing Runnable: 1.1+"); final Runnable runnable = new Runnable() { public void run() { System.out.println("runnable: OK"); } }; Java11.testRunnable(runnable); Java12.testRunnable(runnable); Java13.testRunnable(runnable); Java14.testRunnable(runnable); Java15.testRunnable(runnable); Java16.testRunnable(runnable); }
64b40a13-eba5-4640-9880-335486b6eac3
public void run() { System.out.println("runnable: OK"); }
e5a3ac9f-99c4-4eff-a324-e3c26e38a8c0
public static void testCollections() { System.out.println("# Passing Collection: 1.2+"); Collection<Object> collection = new ArrayList<Object>(); collection.add((Object)42); Java11.testCollections(collection); Java12.testCollections(collection); Java13.testCollections(collection); Java14.testCollections(collection); Java15.testCollections(collection); Java16.testCollections(collection); }
6ef11147-e178-4b02-af26-28b8a9a0a803
public static void test() { System.out.println("test: " + JAVA_VERSION); }
43ddc746-6b45-495d-b099-41480a4c0b01
public static void testRunnable(Runnable runnable) { System.out.println("testRunnable: " + JAVA_VERSION); runnable.run(); }
8af5be15-2400-4aa8-b032-f672cb663fa7
public static void testCollections(Collection collection) { System.out.println("testCollections: " + JAVA_VERSION); System.out.println("First Element: " + collection.iterator().next()); }
84eb84e5-de5d-4c6c-ab33-571b478be19a
public static void test() { System.out.println("test: " + JAVA_VERSION); }
61a58134-8a74-45d2-9aa4-a8a0b5d9c503
public static void testRunnable(Runnable runnable) { System.out.println("testRunnable: " + JAVA_VERSION); runnable.run(); }
c4f17c90-89fa-41f6-9f7c-5fc863a56bd0
public static void testCollections(Object collection) { System.out.println("testCollections: " + JAVA_VERSION); System.out.println("toString(): " + collection.toString()); }
bd6b4d06-6cdb-4d20-a540-f62769db20a3
public static void test() { System.out.println("test: " + JAVA_VERSION); }
42888005-da67-4409-8535-f53b70aef10a
public static void testRunnable(Runnable runnable) { System.out.println("testRunnable: " + JAVA_VERSION); runnable.run(); }
388fa28e-ce3c-497a-b54e-8ec76bcda8aa
public static void testCollections(Collection<Object> collection) { System.out.println("testCollections: " + JAVA_VERSION); System.out.println("First Element: " + collection.iterator().next()); }
f479202c-b347-4f3f-a7ae-b928719704e1
public static void test() { System.out.println("test: " + JAVA_VERSION); }
5c544294-1e9b-4198-881a-1b685e24fd6f
public static void testRunnable(Runnable runnable) { System.out.println("testRunnable: " + JAVA_VERSION); runnable.run(); }
e637791c-2a5d-4d2b-b7ce-dca398f3d236
public static void testCollections(Collection collection) { System.out.println("testCollections: " + JAVA_VERSION); System.out.println("First Element: " + collection.iterator().next()); }
df24f005-129b-44c6-b584-e6d2385bc984
public static void test() { System.out.println("test: " + JAVA_VERSION); }
5ac64e41-f6ce-4f4d-bfd0-25e5bf40154f
public static void testRunnable(Runnable runnable) { System.out.println("testRunnable: " + JAVA_VERSION); runnable.run(); }
b6a71bd7-1c12-4e46-8a14-21fca806505f
public static void testCollections(Collection<Object> collection) { System.out.println("testCollections: " + JAVA_VERSION); System.out.println("First Element: " + collection.iterator().next()); }
e40ccd0c-38cf-412d-a52b-1ce26e1dce20
public static void test() { System.out.println("test: " + JAVA_VERSION); }
fb1fa248-8cf7-45d6-9952-9cf4369ec8af
public static void testRunnable(Runnable runnable) { System.out.println("testRunnable: " + JAVA_VERSION); runnable.run(); }
b0e39f91-7d5b-44d3-a639-d27effc8d009
public static void testCollections(Collection collection) { System.out.println("testCollections: " + JAVA_VERSION); System.out.println("First Element: " + collection.iterator().next()); }
f9561b0c-a534-4395-878c-21d55f13f58d
@POST @Path("/{destination}") @Consumes(MediaType.APPLICATION_JSON) @Produces({MediaType.APPLICATION_JSON}) public Integer createConsumer(@PathParam("destination")String destinationName, Consumer consumer) throws JMSException { Destination destination = createDestination(destinationName); getService().addConsumer(destination, consumer); return consumer.getId(); }
f4b0f355-0af3-4def-8d54-4b159dc613f1
@GET @Produces({MediaType.APPLICATION_JSON}) @Path("/{destination}") public HashMap<Integer, Consumer> getConsumers(@PathParam("destination")String destination) { return fetchConsumers(createDestination(destination)); }
adf3175b-9551-4b72-9d1f-2e2de3e1f699
@DELETE @Path("/{destination}/{id}") public void deleteConsumer(@PathParam("destination")String destination, @PathParam("id")Integer id) throws JMSException { getService().deleteConsumer(createDestination(destination), id); }
cbddade9-3fb4-4909-8119-496a1103dcd0
protected Service getService() { return rc.getResource(Service.class); }
a608e2cf-816c-4238-a222-60317b6e7eda
public HashMap<Integer, Consumer> fetchConsumers(Destination destination) { return getService().getConsumers(destination); }
84e02924-d9f5-4c47-b2ea-057ab73ae206
abstract protected Destination createDestination(String destinationName);
b4d7b868-8d49-4457-9784-3b00e305c4ec
public Service() { //TODO config mechanism for connection factory ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616"); messagingAgent = new JMSMessagingAgent(factory); }
b9831f87-9b87-4bad-86aa-75fead36a695
public HashMap<Integer, Consumer> getConsumers(Destination destination) { HashMap<Integer, Consumer> result = consumers.get(destination); if (result == null) { result = new HashMap<Integer, Consumer>(); consumers.put(destination, result); } return result; }
4aedf638-ce4b-4cdf-a912-dd9b75d6e600
public Integer addConsumer(Destination destination, Consumer consumer) throws JMSException { consumer.setService(this); consumer.setConsumer(messagingAgent.createConsumer(destination)); consumer.setId(id.getAndIncrement()); HashMap<Integer, Consumer> consumerList = getConsumers(destination); consumerList.put(consumer.getId(), consumer); return consumer.getId(); }
903b0c3f-2427-4cc0-ab73-f069801f163f
public void deleteConsumer(Destination destination, Integer id) throws JMSException { Consumer consumer = getConsumers(destination).remove(id); if (consumer != null) { consumer.getConsumer().close(); } }
c45d3ff6-ff66-471d-881c-24926c7726f4
public AsyncHttpClient getHttpClient() { return httpClient; }
b69569da-35f6-4d4c-923e-944085e1827f
@Override protected Destination createDestination(String destinationName) { return new ActiveMQTopic(destinationName); }
11ac0537-879c-489b-8306-dd2e92a87913
@Override protected Destination createDestination(String destinationName) { return new ActiveMQQueue(destinationName); }
5e1079a7-8264-4168-b276-0bcf21fdac6a
public JMSMessagingAgent(ConnectionFactory factory) { this.factory = factory; }
8e146ed8-5b37-48c8-9d23-da6dcbeb58ea
public Connection getConnection() throws JMSException { if (connection == null) { connection = factory.createConnection(); connection.start(); } return connection; }
5554ee1b-0378-4cf8-875c-159138611010
public Session getSession() throws JMSException { if (session == null) { session = getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE); } return session; }
c584777b-900c-44be-9e25-a979dbd69be7
public MessageConsumer createConsumer(Destination destination) throws JMSException { return getSession().createConsumer(destination); }
cbb9d388-fcec-4533-8085-4ba998ed4636
public Integer getId() { return id; }
d1a6d871-4f40-4fb9-ba65-2d882427c72c
public void setId(Integer id) { this.id = id; }
0e3db508-0782-4cce-85a8-d64c7ec21f1e
public URL getUrl() { return url; }
9b8b47cc-cf7f-41f0-af23-1ff94f14e3b5
public void setUrl(URL url) { this.url = url; }
6fa6c46e-1ef5-49c1-983c-c48a4ad375c7
public MessageConsumer getConsumer() { return consumer; }
f9c5d5d4-7a3f-4749-961e-f5e5c7396f3e
public void setConsumer(MessageConsumer consumer) throws JMSException { consumer.setMessageListener(new MessageListener() { @Override public void onMessage(Message message) { try { if (message instanceof TextMessage) { System.out.println(((TextMessage)message).getText().trim() + " -> " + url.toString()); AsyncHttpClient.BoundRequestBuilder request = service.getHttpClient().preparePost(url.toString()); request.setBody(((TextMessage) message).getText()); Future<Response> result = request.execute(); Response response = result.get(); System.out.println(response.getStatusCode() + " " + response.getStatusText() + " " + response.getResponseBody()); } //TODO handle other message types } catch (Exception e) { e.printStackTrace(); //TODO should we use transactions instead? throw new RuntimeException(e); } } }); this.consumer = consumer; }
f4d1fd33-2d9f-403c-aaa4-7f836651709f
@Override public void onMessage(Message message) { try { if (message instanceof TextMessage) { System.out.println(((TextMessage)message).getText().trim() + " -> " + url.toString()); AsyncHttpClient.BoundRequestBuilder request = service.getHttpClient().preparePost(url.toString()); request.setBody(((TextMessage) message).getText()); Future<Response> result = request.execute(); Response response = result.get(); System.out.println(response.getStatusCode() + " " + response.getStatusText() + " " + response.getResponseBody()); } //TODO handle other message types } catch (Exception e) { e.printStackTrace(); //TODO should we use transactions instead? throw new RuntimeException(e); } }
3d0f33a7-4f76-465a-b7e9-52ea87e6cbda
public void setService(Service service) { this.service = service; }
c7e914fb-5258-4b68-995a-b0cf28c57928
public TestClient() throws Exception { SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(8181); connector.setServer(server); ServletContextHandler contextHandler = new ServletContextHandler(server, "/", ServletContextHandler.NO_SECURITY); ServletHolder holder = new ServletHolder(); holder.setServlet(new HttpServlet() { @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { StringBuffer jb = new StringBuffer(); String line = null; try { BufferedReader reader = req.getReader(); while ((line = reader.readLine()) != null) jb.append(line); System.out.println(jb.toString()); } catch (Exception e) { System.out.println("Can't read " + e); } } }); contextHandler.addServlet(holder, "/"); server.setConnectors(new Connector[] { connector }); }
10cf604c-461e-434b-89d8-023049d99030
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { StringBuffer jb = new StringBuffer(); String line = null; try { BufferedReader reader = req.getReader(); while ((line = reader.readLine()) != null) jb.append(line); System.out.println(jb.toString()); } catch (Exception e) { System.out.println("Can't read " + e); } }
87ea4212-ddf8-403b-aca7-2fdaa6e3baaa
public void start() throws Exception { server.start(); }
b611b16d-edfa-4ccd-97b2-ae9f0f14032d
public static void main(String[] args) throws Exception { TestClient client = new TestClient(); client.start(); System.in.read(); }
1fe25e13-c4e8-4ae6-a124-4980edb55de1
@Override public void contextInitialized(ServletContextEvent sce) { LOGGER.debug("initializing.."); WebApplicationContext ctx = WebApplicationContextUtils .getWebApplicationContext(sce.getServletContext()); PersonRepository personRepository = ctx.getBean(PersonRepository.class); personRepository.deleteAll(); List<Person> persons = new ArrayList<Person>(); int itemCount = 100; int chunkSize = 25; for (int i = 1; i <= itemCount; i++) { Person p = new Person(); p.setAge((i % 100) + 1); p.setName("name" + i); persons.add(p); if ((i % chunkSize) == 0) { personRepository.save(persons); persons.clear(); } } personRepository.save(persons); }
6c34653d-1a71-42fc-b763-6149e84fcdbb
@Override public void contextDestroyed(ServletContextEvent sce) { }
86de81da-9b50-4f98-82ea-572f6a110bed
Page<Person> findAll(int page, int size);
334d8df9-2b2d-4a18-9d17-c93009d26c38
Page<Person> findByNameLike(String name, int page, int size);
11114129-b28f-48ab-aa99-c259d2a36bfa
Person findById(Integer id);
c8364589-785d-405e-bed5-54499955864a
Person insert(Person person);
f189688e-1820-4df9-bf72-47c52aa4f9ea
Person update(Person person);
72903d3e-1fde-4cc2-8ecc-5836d3e2ca4f
void deleteById(Integer id);
9d3d3685-0250-4ef1-b9ac-3a49b26959b5
@Override @Transactional(readOnly = true) public Page<Person> findAll(int page, int size) { Pageable pageable = new PageRequest(page, size, new Sort( Direction.DESC, "id")); Page<Person> persons = personRepository.findAll(pageable); return persons; }
dd7138b1-6a94-46d7-bfc2-1d028ca2fbed
@Override @Transactional(readOnly = true) public Page<Person> findByNameLike(String name, int page, int size) { Pageable pageable = new PageRequest(page, size, new Sort( Direction.DESC, "id")); String q = "%" + name + "%"; Page<Person> persons = personRepository.findByNameLike(q, pageable); return persons; }
857cf629-843c-47b4-80be-80e7f1a8e105
@Override @Transactional(readOnly = true) public Person findById(Integer id) { Person person = personRepository.findOne(id); return person; }
7f71819c-172c-4036-8a3b-b39933f124c2
@Override @Transactional public Person insert(Person person) { return personRepository.save(person); }
b0351fd2-02c5-46e7-92c8-635ea8b83ae5
@Override @Transactional public Person update(Person person) { return personRepository.save(person); }
50327c87-ab81-4f1a-ac8f-a30dc94ef4c7
@Override @Transactional public void deleteById(Integer id) { personRepository.delete(id); }
b8afcce6-5b97-4ab8-887c-7435ae725ea2
Page<Person> findByNameLike(String name, Pageable pageable);
3590e176-7a9d-486c-9337-0cb4fba56c99
Page<Person> findByNameLike(String name, Pageable pageable);
8e9f37ef-2728-42da-8e14-d195be3de028
@RequestMapping(value = "/list") public String list( @RequestParam(value = "page", required = false) Integer page, Model model) { int pageNum = page != null ? page : DEFAULT_PAGE_NUM; Page<Person> paging = personService.findAll(pageNum, DEFAULT_PAGE_SIZE); model.addAttribute("page", paging); return "/person/list"; }
0e539c6b-4f9a-422e-97b0-1f26cf97765a
@RequestMapping(value = "/form", method = RequestMethod.GET) public @ModelAttribute Person create(Model model) { Person person = new Person(); return person; }
04c3e6ae-59cd-4ed0-93c1-55bc7f416a96
@RequestMapping(value = "/form", method = RequestMethod.POST) public String createOnSubmit(@Valid Person person, BindingResult bindingResult, Model model) { LOGGER.debug("create person={}", person); if (bindingResult.hasErrors()) { LOGGER.warn("validation error={}", bindingResult.getModel()); model.addAllAttributes(bindingResult.getModel()); return "/person/form"; } personService.insert(person); return "redirect:/person/list"; }
adfa16c4-18e4-4fcf-b5a6-47e2f2b84db6
@RequestMapping(value = "/edit/{id}", method = RequestMethod.GET) public String edit(@PathVariable("id") Integer id, Model model) { Person person = personService.findById(id); model.addAttribute(person); return "/person/form"; }
5af709bf-cd84-4af3-b667-b8cfe47a338d
@RequestMapping(value = "/edit", method = RequestMethod.POST) public String editOnSubmit(@Valid Person person, BindingResult bindingResult, Model model) { LOGGER.debug("edit person={}", person); if (bindingResult.hasErrors()) { LOGGER.warn("validation error={}", bindingResult.getModel()); model.addAllAttributes(bindingResult.getModel()); return "/person/form"; } personService.update(person); return "redirect:/person/list"; }
8cfefe95-603a-4427-aef9-18ded42e0dcc
@RequestMapping(value = "/delete/{id}") public String delete( @RequestParam(value = "page", required = false) Integer page, @PathVariable("id") Integer id) { LOGGER.debug("delete id={}", id); personService.deleteById(id); return "redirect:/person/list"; }
3005b27c-fdc3-4ea0-84a3-1825fc02cada
@RequestMapping(value = "/", method = RequestMethod.GET) public String home(Locale locale, Model model) { logger.info("Welcome home! the client locale is " + locale.toString()); Date date = new Date(); DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); String formattedDate = dateFormat.format(date); model.addAttribute("serverTime", formattedDate); return "home"; }
2dc1787f-576e-4572-9585-1f4029226790
public Integer getId() { return id; }
47720219-914f-40a7-91b8-23bebbaaa287
public void setId(Integer id) { this.id = id; }
b137f904-5192-47c7-a8b8-d53fad4d0653
public String getName() { return name; }
960bbb94-509a-4221-a6ea-a6c2f8488c00
public void setName(String name) { this.name = name; }
e2022823-db5d-475c-8c5c-b03b00074f65
public Integer getAge() { return age; }
edef3e8b-8436-428a-b413-16a11edd20e7
public void setAge(Integer age) { this.age = age; }
a1ff6cde-aa6a-42c6-9091-878518351c75
@Override public String toString() { return "Person [id=" + id + ", name=" + name + ", age=" + age + "]"; }
375ea590-a5bd-4a13-b631-76824c1e914e
@Before public void setUp() throws Exception { personRepository.deleteAll(); for (int i = 1; i <= 20; i++) { Person p = new Person(); p.setAge(i % 100); p.setName("name" + i); personRepository.save(p); } personRepository.flush(); }
23bd9838-698b-4aaf-81c2-c9eb38943a6a
@After public void tearDown() throws Exception { }
5ff0163e-7900-4543-ba74-6f2f4c0a54d8
@Test public void testFindAll00() { Page<Person> p = personService.findAll(0, 5); assertNotNull(p); List<Person> persons = p.getContent(); assertNotNull(persons); assertEquals(5, persons.size()); assertEquals(5, p.getNumberOfElements()); assertEquals(0, p.getNumber()); assertEquals(5, p.getSize()); assertEquals(4, p.getTotalPages()); assertEquals(20, p.getTotalElements()); }
77934ab6-7e41-4936-aa75-24bad3f930c2
@Test public void testFindAll01() { Page<Person> p = personService.findAll(1, 5); assertNotNull(p); List<Person> persons = p.getContent(); assertNotNull(persons); assertEquals(5, persons.size()); assertEquals(5, p.getNumberOfElements()); assertEquals(1, p.getNumber()); assertEquals(5, p.getSize()); assertEquals(4, p.getTotalPages()); assertEquals(20, p.getTotalElements()); }
c1775900-868f-4368-b7a7-ab7e65e40d84
@Test public void testFindByNameLike() throws Exception { Page<Person> p = personService.findByNameLike("name1", 0, 5); System.out.println(p.getContent()); assertNotNull(p); assertEquals(5, p.getNumberOfElements()); assertEquals(0, p.getNumber()); assertEquals(5, p.getSize()); assertEquals(3, p.getTotalPages()); assertEquals(11, p.getTotalElements()); }