public void start() {
stopwatch.start();
}
@Component или @Service
@Component
public class Qtask extends TimerTask {
private String xtime;
public int hours = 0;
public int minutes = 0;
public int seconds = 0;
public int elapsedTime = 0;
boolean started = false;
@Override
public void run() {
elapsedTime=elapsedTime+1000;
hours = (elapsedTime/3600000);
minutes = (elapsedTime/60000)%60;
seconds = (elapsedTime/1000)%60
// TODO :: set xtime
xtime = String.valueOf(elapsedTime);
}
public String getXtime() {
return this.xtime;
}
}
@Component
public class SocketTextHandler extends TextWebSocketHandler {
@Autowired
private Qtask qtask;
@Override
public void handleTextMessage(WebSocketSession session, TextMessage message)
throws InterruptedException, IOException {
String clientMessage = message.getPayload();
if (clientMessage.startsWith("start")) {
new Timer().scheduleAtFixedRate(qtask, 0, 1000);
try {
Thread.sleep(1000);
session.sendMessage(new TextMessage(qtask.getXtime()));
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Main {
public static void main(String[] args) {
A b = Fabric.getInstance("B");
A c = Fabric.getInstance("C");
System.out.println(b.getString());
System.out.println(c.getString());
}
}
class Fabric {
public static A getInstance(String className) {
return switch (className) {
case "B" -> new B();
case "C" -> new C();
default -> throw new IllegalArgumentException("Unknown class name " + className);
};
}
}
interface A {
String getString();
}
class B implements A {
@Override
public String getString() {
return "bbb";
}
}
class C implements A {
@Override
public String getString() {
return "ccc";
}
}
import org.springframework.web.util.UriUtils;
class Main {
public static void main(String[] args) {
var path = "announce/Театр-Габима-Дело-всей-жизни";
var pathEncoded = UriUtils.encodePath(path, "UTF-8");
System.out.println("https://afisha.orbita.co.il" + pathEncoded);
// https://afisha.orbita.co.ilannounce/%D0%A2%D0%B5%D0%B0%D1%82%D1%80-%D0%93%D0%B0%D0%B1%D0%B8%D0%BC%D0%B0-%D0%94%D0%B5%D0%BB%D0%BE-%D0%B2%D1%81%D0%B5%D0%B9-%D0%B6%D0%B8%D0%B7%D0%BD%D0%B8
}
}
сам тащусь от программирования
public List<Integer> example(int number) {
return switch (number) {
case 5 -> IntStream.range(0, 6).boxed().toList();
case 7 -> IntStream.range(2, 9).boxed().toList();
default -> Collections.emptyList();
};
}
private Map<Integer, List<Integer>> numbers = Map.of(5, List.of(0, 1, 2, 3, 4, 5),
7, List.of(2, 3, 4, 5, 6, 7, 8));
public List<Integer> example(int number) {
return numbers.getOrDefault(number, Collections.emptyList());
}