TGViewer
Programming ∀ Programming ∀ @programming_everyone · 1.35K subscribers
Post #4186 827
java 21+ silani ko'rsataymi ?

sealed interface PortResult permits Ok, Missing, NotNumeric, OutOfRange {}
record Ok(int port) implements PortResult {}
record Missing() implements PortResult {}
record NotNumeric(String str) implements PortResult {}
record OutOfRange(int value) implements PortResult {}

PortResult parsePort(String str) {
if (str.isEmpty()) return new Missing();
int port;
try {
port = Integer.parseInt(str);
} catch (NumberFormatException e) {
return new NotNumeric(str);
}
if (port < 1 || port > 65535) return new OutOfRange(port);
return new Ok(port);
}
  • 👏 6
  • 😱 3
More from @programming_everyone
  1. Sep 28, 2026mongodb cooked, ceosi survoribti metaga. va stock choq -16% xozir adashmasm 20%gacha tushi…
  2. Sep 26, 2026Masalan hamma cho'qqini zabt etishni istaydi, buning uchun borini berishga xarakat qiladi.…
  3. Sep 26, 2026Kuzatuvlarim davomida shuni tushundimki soft/hard skills kabi mavzular ajratilishi birmunc…
  4. Sep 24, 2026balanced
  5. Sep 23, 2026Yaqinda bo’lgan safarda tog’rda balandlikdan sakrab sirg'anib kettim. Hech qanday jiddiy j…
  6. Sep 23, 2026Leetcode - leetcode competitive programming platform emas. Masalan codeforces, atcoder kab…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →