Sobes.tech

public class Accumulator { private Map<String, Object> data = new HashMap<>(); // current data set private List<Map<String, Object>> dataList = new ArrayList<>(); // batch of data private Map<Instant, String> responses = new HashMap<>(); // responses from the server receiving data private int dataId; /** * Adds a field field with value to the set */ public void add(String field, String value) { data.put(field, value); } /** * Returns the value by the field name */ public <T> T get(String field) { return (T) data.get(field); } /** * Returns responses from the server receiving data */ public String getResponses() { String out = ""; for (String resp : responses.values()) { out += "; " + resp; } return out; } /** * Completes the current data set and sends it to the batch */ public synchronized void push() { dataList.add(data); if (dataList.size() == 100) { send(); dataList.clear(); } data = new HashMap<>(); data.put("id", dataId++); } /** * Sends the batch to the data receiving server */ private void send() { RestTemplate restTemplate = new RestTemplate(); HttpEntity<List<Map<String, Object>>> request = new HttpEntity<>(dataList); String url = "localhost:20808/msg/incoming"; ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, request, String.class); responses.put(Instant.now(), response.getBody()); } }

Senior
159

public static void main(String args[]) { checkMap(new HashMap<>()); checkMap(new LinkedHashMap<>()); checkMap(new TreeMap<>()); } private static void checkMap(Map<Person, String> map) { System.out.println("Checking " + map.getClass()); Person ivan = new Person("Иван"); Person peter = new Person("Пётр"); Person maria1 = new Person("Мария"); Person maria2 = new Person("Мария"); map.put(ivan, ivan.name); map.put(peter, peter.name); map.put(maria1, maria1.name); map.put(maria2, maria2.name); // iterate and println for (Map.Entry<Person, String> entry : map.entrySet()) { System.out.println(entry); } // maria1.setName("Анна-Мария"); // maria2.setName("Анна-Мария"); System.out.println(map.get(maria1)); System.out.println(map.get(maria2)); System.out.println("==================================="); }

Senior
159

Can you list the main methods of the ExecutorService interface and explain their purpose?

Junior — Middle
159

How do you assess your level — mid or senior?

Senior
159

В чем разница между WHERE и HAVING?

Senior
159

//Given two beans. An exception occurred during the third iteration in method m1. How many records will be in the database? public class BeanA() { private BeanB b; @Transactional public void m1(List<Integer> list) { for (Integer i : list) { b.m2(i); } } } public class BeanB() { @Transactional public void m2(Integer i) { // Add record to table } }

Senior
158

What collection should be used to store the history of visited pages without duplicates while preserving order?

Senior
158

If we use POST, but HTTP (not HTTPS) — what then?

Senior
158

What is a memory leak in Java? What algorithm is used to find it?

Senior
158

What is the difference between @Bean and @Service annotations in Spring Framework?

Junior — Middle
157

What does the reduce method do?

Senior
157

What skills or knowledge are you aiming to develop in the near future?

Junior — Middle
157

How do you implement object comparison methods and hash code calculations in your code?

Junior — Middle
157

Which collection would you use to implement a stack data structure?

Junior — Middle
156

Under what conditions will the finally block not be called during program execution?

Junior — Middle
156

How were your development processes structured at your previous workplace? How did tasks come in?

Senior
155

What is the limitation on the number of Stream applications in Java?

Junior — Middle
155

How to subscribe to Flux/Mono in reactive programming? What options are available?

Senior
155
/17