text
stringclasses
10 values
metadata
dict
<java8_code>: public class Example { public static void main(String[] args) { int x = 10; System.out.println(x); } } <java17_code>: public class Example { public static void main(String[] args) { var x = 10; System.out.println(x); } } <junit_test>: import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; public class ExampleTest { @Test void testMain() { Example.main(new String[]{}); } }
{ "input_language": "java8", "output_language": "java17", "source": "unified_chip2", "test_type": "JUnitTest" }
<java8_code>: public class SwitchExample { public static void main(String[] args) { int day = 1; String dayName; switch (day) { case 1: dayName = "Monday"; break; case 2: dayName = "Tuesday"; break; default: dayName = "Other"; } System.out.println(dayName); } } <java17_code>: public class SwitchExample { public static void main(String[] args) { int day = 1; String dayName = switch (day) { case 1 -> "Monday"; case 2 -> "Tuesday"; default -> "Other"; }; System.out.println(dayName); } } <junit_test>: import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; public class SwitchExampleTest { @Test void testSwitch() { assertEquals("Monday", SwitchExample.getDayName(1)); assertEquals("Other", SwitchExample.getDayName(3)); } }
{ "input_language": "java8", "output_language": "java17", "source": "unified_chip2", "test_type": "JUnitTest" }
<java8_code>: public class Person { private final String name; private final int age; public Person(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public int getAge() { return age; } } <java17_code>: public record Person(String name, int age) { } <junit_test>: import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; public class PersonTest { @Test void testPersonRecord() { var person = new Person("John", 30); assertEquals("John", person.name()); assertEquals(30, person.age()); } }
{ "input_language": "java8", "output_language": "java17", "source": "unified_chip2", "test_type": "JUnitTest" }
<java8_code>: public abstract class Shape { } public final class Circle extends Shape { } public final class Square extends Shape { } <java17_code>: public sealed class Shape permits Circle, Square { } public final class Circle extends Shape { } public final class Square extends Shape { } <junit_test>: import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; public class ShapeTest { @Test void testShapes() { Shape shape = new Circle(); assertTrue(shape instanceof Circle); shape = new Square(); assertTrue(shape instanceof Square); } }
{ "input_language": "java8", "output_language": "java17", "source": "unified_chip2", "test_type": "JUnitTest" }
<java8_code>: List<String> list = new ArrayList<>(); list.add("apple"); list.add("orange"); for (String fruit : list) { System.out.println(fruit); } <java17_code>: var list = List.of("apple", "orange"); list.forEach(System.out::println); <junit_test>: import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; import java.util.List; public class ListTest { @Test void testList() { var list = List.of("apple", "orange"); assertEquals(2, list.size()); assertTrue(list.contains("apple")); } }
{ "input_language": "java8", "output_language": "java17", "source": "unified_chip2", "test_type": "JUnitTest" }
<java8_code>: Path path = Paths.get("/tmp/file.txt"); try { List<String> lines = Files.readAllLines(path); lines.forEach(System.out::println); } catch (IOException e) { e.printStackTrace(); } <java17_code>: var path = Path.of("/tmp/file.txt"); try { var lines = Files.readAllLines(path); lines.forEach(System.out::println); } catch (IOException e) { e.printStackTrace(); } <junit_test>: import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; public class FileTest { @Test void testFileRead() throws Exception { var path = Path.of("/tmp/file.txt"); var lines = Files.readAllLines(path); assertFalse(lines.isEmpty()); } }
{ "input_language": "java8", "output_language": "java17", "source": "unified_chip2", "test_type": "JUnitTest" }
<java8_code>: List<Integer> numbers = Arrays.asList(1, 2, 3, 4); Optional<Integer> max = numbers.stream().max(Integer::compareTo); System.out.println(max.orElse(-1)); <java17_code>: var numbers = List.of(1, 2, 3, 4); var max = numbers.stream().max(Integer::compareTo); System.out.println(max.orElse(-1)); <junit_test>: import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; import java.util.List; import java.util.Optional; public class StreamTest { @Test void testMaxValue() { var numbers = List.of(1, 2, 3, 4); var max = numbers.stream().max(Integer::compareTo); assertEquals(4, max.orElse(-1)); } }
{ "input_language": "java8", "output_language": "java17", "source": "unified_chip2", "test_type": "JUnitTest" }
<java8_code>: public class OldThread { public static void main(String[] args) { Thread t = new Thread(new Runnable() { public void run() { System.out.println("Hello from a thread"); } }); t.start(); } } <java17_code>: public class NewThread { public static void main(String[] args) { var t = new Thread(() -> System.out.println("Hello from a thread")); t.start(); } <junit_test>: import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; public class ThreadTest { @Test void testThread() { var t = new Thread(() -> System.out.println("Hello from a thread")); t.start(); } }
{ "input_language": "java8", "output_language": "java17", "source": "unified_chip2", "test_type": "JUnitTest" }
<java8_code>: Comparator<String> comparator = new Comparator<String>() { @Override public int compare(String s1, String s2) { return s1.compareTo(s2); } }; <java17_code>: Comparator<String> comparator = String::compareTo; <junit_test>: import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; import java.util.Comparator; public class ComparatorTest { @Test void testComparator() { Comparator<String> comparator = String::compareTo; assertEquals(0, comparator.compare("apple", "apple")); assertTrue(comparator.compare("apple", "banana") < 0); } }
{ "input_language": "java8", "output_language": "java17", "source": "unified_chip2", "test_type": "JUnitTest" }
<java8_code>: Stream.of(1, 2, 3, 4).filter(i -> i % 2 == 0).forEach(System.out::println); <java17_code>: var stream = Stream.of(1, 2, 3, 4); stream.filter(i -> i % 2 == 0).forEach(System.out::println); <junit_test>: import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; import java.util.stream.Stream; public class StreamTest { @Test void testStreamFilter() { var stream = Stream.of(1, 2, 3, 4); assertTrue(stream.filter(i -> i % 2 == 0).findAny().isPresent()); } }
{ "input_language": "java8", "output_language": "java17", "source": "unified_chip2", "test_type": "JUnitTest" }
README.md exists but content is empty.
Downloads last month
35