-
public class StoreController { private List<Store> stores = new ArrayList<>(); @GetMapping("/{storeId}/products") public List<Product> getStoreProducts(@PathVariable Long storeId) { Store store = findStoreById(storeId); if (store != null) { return store.getProducts(); } return new ArrayList<>(); } @PostMapping public Store addStore(@RequestBody Store store) { store.setId(generateStoreId()); stores.add(store); return store; } private Store findStoreById(Long storeId) { return stores.stream() .filter(store -> store.getId().equals(storeId)) .findFirst() .orElse(null); } private Long generateStoreId() { return Long.valueOf(stores.size() + 1); } }SharedPreferences sharedPreferences = getSharedPreferences("user_data", Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); Gson gson = new Gson(); String couponsJson = gson.toJson(user.getCoupons()); editor.putString("user_coupons", couponsJson); editor.apply();public class TimeBasedActionManager { private Timer timer; private boolean isOpen = false; public void startTimedAction() { int openHour = 8; // 8 AM int closeHour = 18; // 6 PM timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { Calendar calendar = Calendar.getInstance(); int currentHour = calendar.get(Calendar.HOUR_OF_DAY); if (currentHour >= openHour && currentHour < closeHour) { if (!isOpen) { open(); } } else { if (isOpen) { close(); } } } }, 0, 60000); } private void open() { isOpen = true; System.out.println("Open at " + getCurrentTime()); } private void close() { isOpen = false; System.out.println("Close at " + getCurrentTime()); } private String getCurrentTime() { Calendar calendar = Calendar.getInstance(); int currentHour = calendar.get(Calendar.HOUR_OF_DAY); int currentMinute = calendar.get(Calendar.MINUTE); return String.format("%02d:%02d", currentHour, currentMinute); } public static void main(String[] args) { TimeBasedActionManager actionManager = new TimeBasedActionManager(); actionManager.startTimedAction(); } }