From 79c9424b49346f8554bc66f7c4d09ca35f43725e Mon Sep 17 00:00:00 2001 From: Preveen Padmanabhan Date: Sat, 17 Jun 2023 21:00:48 +0530 Subject: [PATCH] added various projects --- ASTExample/ASTExample.java | 84 ++++++++++++++ ASTExample/ASTExample.java.using.sun.tools | 103 ++++++++++++++++++ DisjointSet/Main.java | 34 ++++++ DisjointSet/disjointset/DisjointSet.java | 44 ++++++++ HelloWorld/HelloWorld.java | 7 ++ Kruskal/Main.java | 31 ++++++ Kruskal/Makefile | 14 +++ Kruskal/kruskal/DisjointSet.java | 74 +++++++++++++ Kruskal/kruskal/Edge.java | 24 ++++ camel-hello-world/pom.xml | 60 ++++++++++ .../src/main/java/com/example/App.java | 27 +++++ .../src/test/java/com/example/AppTest.java | 38 +++++++ .../target/maven-archiver/pom.properties | 3 + .../compile/default-compile/createdFiles.lst | 2 + .../compile/default-compile/inputFiles.lst | 1 + .../default-testCompile/createdFiles.lst | 1 + .../default-testCompile/inputFiles.lst | 1 + .../TEST-com.example.AppTest.xml | 61 +++++++++++ .../surefire-reports/com.example.AppTest.txt | 4 + er-cannot-be-written/Example.java | 8 ++ .../Example.java.not-reproduced | 8 ++ ex-annotation/example-test-annotation/pom.xml | 18 +++ .../src/main/java/com/example/App.java | 13 +++ .../src/test/java/com/example/AppTest.java | 38 +++++++ ex-annotation/string-constants/pom.xml | 38 +++++++ .../src/main/java/com/example/App.java | 22 ++++ .../src/main/java/com/example/Constants.java | 12 ++ .../main/java/com/example/StringConstant.java | 10 ++ .../src/test/java/com/example/AppTest.java | 38 +++++++ .../example/StringConstantCheckerTest.java | 29 +++++ .../target/maven-archiver/pom.properties | 3 + .../compile/default-compile/createdFiles.lst | 3 + .../compile/default-compile/inputFiles.lst | 3 + .../default-testCompile/createdFiles.lst | 2 + .../default-testCompile/inputFiles.lst | 2 + .../TEST-com.example.AppTest.xml | 61 +++++++++++ ...-com.example.StringConstantCheckerTest.xml | 61 +++++++++++ .../surefire-reports/com.example.AppTest.txt | 4 + .../com.example.StringConstantCheckerTest.txt | 4 + hw/HelloWorld.java | 5 + java17switch/test.java | 21 ++++ .../MeasurementConverter.java | 62 +++++++++++ .../solar-module-editor/pom.xml | 29 +++++ .../com/example/SolarModuleEditorGui.java | 64 +++++++++++ .../src/test/java/com/example/AppTest.java | 38 +++++++ .../target/maven-archiver/pom.properties | 5 + .../compile/default-compile/createdFiles.lst | 2 + .../compile/default-compile/inputFiles.lst | 1 + .../default-testCompile/createdFiles.lst | 1 + .../default-testCompile/inputFiles.lst | 1 + .../TEST-com.example.AppTest.xml | 65 +++++++++++ .../surefire-reports/com.example.AppTest.txt | 4 + 52 files changed, 1288 insertions(+) create mode 100644 ASTExample/ASTExample.java create mode 100644 ASTExample/ASTExample.java.using.sun.tools create mode 100644 DisjointSet/Main.java create mode 100644 DisjointSet/disjointset/DisjointSet.java create mode 100644 HelloWorld/HelloWorld.java create mode 100644 Kruskal/Main.java create mode 100644 Kruskal/Makefile create mode 100644 Kruskal/kruskal/DisjointSet.java create mode 100644 Kruskal/kruskal/Edge.java create mode 100644 camel-hello-world/pom.xml create mode 100644 camel-hello-world/src/main/java/com/example/App.java create mode 100644 camel-hello-world/src/test/java/com/example/AppTest.java create mode 100644 camel-hello-world/target/maven-archiver/pom.properties create mode 100644 camel-hello-world/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst create mode 100644 camel-hello-world/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst create mode 100644 camel-hello-world/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst create mode 100644 camel-hello-world/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst create mode 100644 camel-hello-world/target/surefire-reports/TEST-com.example.AppTest.xml create mode 100644 camel-hello-world/target/surefire-reports/com.example.AppTest.txt create mode 100644 er-cannot-be-written/Example.java create mode 100644 er-cannot-be-written/Example.java.not-reproduced create mode 100644 ex-annotation/example-test-annotation/pom.xml create mode 100644 ex-annotation/example-test-annotation/src/main/java/com/example/App.java create mode 100644 ex-annotation/example-test-annotation/src/test/java/com/example/AppTest.java create mode 100644 ex-annotation/string-constants/pom.xml create mode 100644 ex-annotation/string-constants/src/main/java/com/example/App.java create mode 100644 ex-annotation/string-constants/src/main/java/com/example/Constants.java create mode 100644 ex-annotation/string-constants/src/main/java/com/example/StringConstant.java create mode 100644 ex-annotation/string-constants/src/test/java/com/example/AppTest.java create mode 100644 ex-annotation/string-constants/src/test/java/com/example/StringConstantCheckerTest.java create mode 100644 ex-annotation/string-constants/target/maven-archiver/pom.properties create mode 100644 ex-annotation/string-constants/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst create mode 100644 ex-annotation/string-constants/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst create mode 100644 ex-annotation/string-constants/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst create mode 100644 ex-annotation/string-constants/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst create mode 100644 ex-annotation/string-constants/target/surefire-reports/TEST-com.example.AppTest.xml create mode 100644 ex-annotation/string-constants/target/surefire-reports/TEST-com.example.StringConstantCheckerTest.xml create mode 100644 ex-annotation/string-constants/target/surefire-reports/com.example.AppTest.txt create mode 100644 ex-annotation/string-constants/target/surefire-reports/com.example.StringConstantCheckerTest.txt create mode 100644 hw/HelloWorld.java create mode 100644 java17switch/test.java create mode 100644 measurement_converter/MeasurementConverter.java create mode 100644 solar_module_model/solar-module-editor/pom.xml create mode 100644 solar_module_model/solar-module-editor/src/main/java/com/example/SolarModuleEditorGui.java create mode 100644 solar_module_model/solar-module-editor/src/test/java/com/example/AppTest.java create mode 100644 solar_module_model/solar-module-editor/target/maven-archiver/pom.properties create mode 100644 solar_module_model/solar-module-editor/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst create mode 100644 solar_module_model/solar-module-editor/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst create mode 100644 solar_module_model/solar-module-editor/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst create mode 100644 solar_module_model/solar-module-editor/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst create mode 100644 solar_module_model/solar-module-editor/target/surefire-reports/TEST-com.example.AppTest.xml create mode 100644 solar_module_model/solar-module-editor/target/surefire-reports/com.example.AppTest.txt diff --git a/ASTExample/ASTExample.java b/ASTExample/ASTExample.java new file mode 100644 index 0000000..4963cf8 --- /dev/null +++ b/ASTExample/ASTExample.java @@ -0,0 +1,84 @@ +import java.io.IOException; +import java.io.StringWriter; +import java.util.Collections; +import javax.tools.Diagnostic; +import javax.tools.JavaCompiler; +import javax.tools.JavaCompiler.CompilationTask; +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; +import javax.tools.ToolProvider; + +public class ASTExample { + public static void main(String[] args) throws IOException { + String sourceCode = "public class HelloWorld {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Hello, world!\");\n" + + " }\n" + + "}"; + + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + Iterable compilationUnits = + Collections.singletonList(new StringJavaFileObject("HelloWorld", sourceCode)); + CompilationTask task = compiler.getTask(null, null, null, null, null, compilationUnits); + Iterable asts = + task.parse(); + + // Print the AST for debugging + for (CompilationUnitTree ast : asts) { + StringWriter writer = new StringWriter(); + ast.accept(new PrettyPrintVisitor(writer), null); + System.out.println(writer.toString()); + } + } + + private static class StringJavaFileObject extends SimpleJavaFileObject { + private final String code; + + public StringJavaFileObject(String name, String code) { + super(toURI(name), Kind.SOURCE); + this.code = code; + } + + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + return code; + } + + private static java.net.URI toURI(String name) { + return java.net.URI.create("string:///" + name.replace('.', '/') + Kind.SOURCE.extension); + } + } + + private static class PrettyPrintVisitor extends TreeScanner { + private final StringWriter writer; + + public PrettyPrintVisitor(StringWriter writer) { + this.writer = writer; + } + + @Override + public Void visitCompilationUnit(CompilationUnitTree node, Void p) { + writer.write(node.getPackageName().toString()); + writer.write("\n"); + super.visitCompilationUnit(node, p); + return null; + } + + @Override + public Void visitClass(ClassTree node, Void p) { + writer.write(node.getSimpleName().toString()); + writer.write("\n"); + super.visitClass(node, p); + return null; + } + + @Override + public Void visitMethod(MethodTree node, Void p) { + writer.write(node.getName().toString()); + writer.write("\n"); + super.visitMethod(node, p); + return null; + } + } +} + diff --git a/ASTExample/ASTExample.java.using.sun.tools b/ASTExample/ASTExample.java.using.sun.tools new file mode 100644 index 0000000..fbce363 --- /dev/null +++ b/ASTExample/ASTExample.java.using.sun.tools @@ -0,0 +1,103 @@ +import com.sun.source.tree.CompilationUnitTree; +import com.sun.source.util.JavacTask; +import com.sun.tools.javac.api.JavacTool; + +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +public class ASTExample { + public static void main(String[] args) throws IOException { + String sourceCode = "public class HelloWorld {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Hello, world!\");\n" + + " }\n" + + "}"; + + JavaCompiler compiler = JavacTool.create(); + JavaFileObject sourceFile = new SourceFileObject("HelloWorld.java", sourceCode); + JavacTask task = (JavacTask) compiler.getTask(null, null, null, null, null, + Iterable.of(sourceFile)); + CompilationUnitTree ast = task.parse().iterator().next(); + + // Print the AST for debugging + System.out.println(ast); + } + + private static class SourceFileObject implements JavaFileObject { + private final String name; + private final String source; + + public SourceFileObject(String name, String source) { + this.name = name; + this.source = source; + } + + @Override + public Kind getKind() { + return Kind.SOURCE; + } + + @Override + public boolean isNameCompatible(String simpleName, Kind kind) { + return true; + } + + @Override + public NestingKind getNestingKind() { + return null; + } + + @Override + public Modifier getAccessLevel() { + return null; + } + + @Override + public URI toUri() { + return null; + } + + @Override + public String getName() { + return name; + } + + @Override + public InputStream openInputStream() throws IOException { + return new ByteArrayInputStream(source.getBytes(StandardCharsets.UTF_8)); + } + + @Override + public OutputStream openOutputStream() throws IOException { + return null; + } + + @Override + public Reader openReader(boolean ignoreEncodingErrors) throws IOException { + return new InputStreamReader(openInputStream()); + } + + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { + return source; + } + + @Override + public Writer openWriter() throws IOException { + return null; + } + + @Override + public long getLastModified() { + return 0; + } + + @Override + public boolean delete() { + return false; + } + } +} + diff --git a/DisjointSet/Main.java b/DisjointSet/Main.java new file mode 100644 index 0000000..d1e2da4 --- /dev/null +++ b/DisjointSet/Main.java @@ -0,0 +1,34 @@ +import disjointset.DisjointSet; + +class Main { + public static void printSets(int[] universe, DisjointSet ds) { + + for (int i : universe) { + System.out.println(ds.Find(i) + " "); + } + + System.out.println(); + } + + public static void main(String[] args) { + // universe of items + int[] universe = { 1, 2, 3, 4, 5}; + + // initialize disjointset class + DisjointSet ds = new DisjointSet(); + + // create a singleton for each element + ds.makeSet(universe); + printSets(universe, ds); + + ds.Union(4, 3); // 4 and 3 are in the same set + printSets(universe, ds); + + ds.Union(2, 1); // 1 and 2 are in the same set + printSets(universe, ds); + + ds.Union(1, 3); // 1, 2, 3, 4 are in the same set + printSets(universe, ds); + + } +} diff --git a/DisjointSet/disjointset/DisjointSet.java b/DisjointSet/disjointset/DisjointSet.java new file mode 100644 index 0000000..d70aae4 --- /dev/null +++ b/DisjointSet/disjointset/DisjointSet.java @@ -0,0 +1,44 @@ +package disjointset; + +import java.util.HashMap; +import java.util.Map; + + +public class DisjointSet { + private Map parent = new HashMap(); + + // perform makeset operation + public void makeSet(int[] universe) + { + // create n disjoint sets, one for each item + for(int i: universe) { + parent.put(i, i); + } + } + + // Find the root of the set to which k belongs + public int Find(int k) + { + // if k is the root + if (parent.get(k) == k) { + return k; + } + + // recur until we find the root + return Find(parent.get(k)); + + + } + + // return the union of two subsets + public void Union(int a, int b) + { + int x = Find(a); + int y = Find(b); + + parent.put(x, y); + + System.out.println("joining " + x + " and " + y); + } + +} diff --git a/HelloWorld/HelloWorld.java b/HelloWorld/HelloWorld.java new file mode 100644 index 0000000..d8808f1 --- /dev/null +++ b/HelloWorld/HelloWorld.java @@ -0,0 +1,7 @@ +public class HelloWorld { + static String greeting = "Hello, Java World!"; + + public static void main(String[] args) { + System.out.println(greeting); + } +} diff --git a/Kruskal/Main.java b/Kruskal/Main.java new file mode 100644 index 0000000..f043ba2 --- /dev/null +++ b/Kruskal/Main.java @@ -0,0 +1,31 @@ +import kruskal.DisjointSet; +import kruskal.Edge; +import java.util.*; + +public class Main { + public static void main(String[] args) { + + Random random = new Random(); + + List edges = Arrays.asList( + new Edge(0, 1, 7), new Edge(1, 2, 8), new Edge(0, 3, 5), + new Edge(1, 3, 9), new Edge(1, 4, 7), new Edge(2, 4, 5), + new Edge(3, 4, 15), new Edge(3, 5, 6), new Edge(4, 5, 8), + new Edge(4, 6, 9), new Edge(5, 6, 1)); + + for(Edge edge : edges) { + edge.setWeight(random.nextInt(20)); + } + + System.out.println(edges); + + // total number of nodes in the graph (labelled 0 to 6) + int n = 7; + + // Construct graph + List e = DisjointSet.runKruskalAlgorithm(edges, n); + System.out.println("MST:"); + System.out.println(e); + } + +} diff --git a/Kruskal/Makefile b/Kruskal/Makefile new file mode 100644 index 0000000..ff9655d --- /dev/null +++ b/Kruskal/Makefile @@ -0,0 +1,14 @@ +build: + javac Main.java + +run: + java Main + +make: + vi Makefile + +edit: + vi Main.java + +view: + cat Makefile diff --git a/Kruskal/kruskal/DisjointSet.java b/Kruskal/kruskal/DisjointSet.java new file mode 100644 index 0000000..5fa80da --- /dev/null +++ b/Kruskal/kruskal/DisjointSet.java @@ -0,0 +1,74 @@ +package kruskal; +import java.util.*; +import kruskal.Edge; + +public class DisjointSet { + + Map parent = new HashMap(); + + + public void makeSet(int n) { + // Create 'n' disjoint sets (one for each vertex) + for (int i = 0; i < n; i++) { + parent.put(i, i); + } + + } + + // Find the root of the set to which k belongs + public int Find(int k) { + if(parent.get(k) == k) { + return k; + } + + // recur for the parent until we find the root + + return Find(parent.get(k)); + } + + // Perform union of two subsets + public void Union(int a, int b) { + int x = Find(a); + int y = Find(b); + + parent.put(a, b); + } + + // + public static List runKruskalAlgorithm(List edges, int n) { + + // Stores edges in parent MST + List MST = new ArrayList<>(); + + // Initialize disjoint class + // Create a singleton set for each element in the universe + DisjointSet ds = new DisjointSet(); + ds.makeSet(n); + + int index = 0; + + // Sort edges by increasing weight + Collections.sort(edges, Comparator.comparingInt(e -> e.weight)); + + // MST contains exactly V-1 values + while (MST.size() != n - 1) { + + // Consider next edge with minimum weight from the graph + Edge next_edge = edges.get(index++); + + // Find the root of the two sets to which two end points // Vertices of the next edge belongs + int x = ds.Find(next_edge.src); + int y = ds.Find(next_edge.dest); + + // If both end points have different parents, they belong + // to different connected components and can be included in the MST + if (x != y) { + MST.add(next_edge); + ds.Union(x, y); + } + + } + + return MST; + } +} diff --git a/Kruskal/kruskal/Edge.java b/Kruskal/kruskal/Edge.java new file mode 100644 index 0000000..73f15af --- /dev/null +++ b/Kruskal/kruskal/Edge.java @@ -0,0 +1,24 @@ +package kruskal; + +public class Edge +{ + int src, dest, weight; + + public Edge(int src, int dest, int weight) { + this.src = src; + this.dest = dest; + this.weight = weight; + + } + + @Override + public String toString() { + + return "(" + src + ", " + dest + ", " + weight + ")"; + } + + public void setWeight(int w) { + this.weight = w; + } + +} diff --git a/camel-hello-world/pom.xml b/camel-hello-world/pom.xml new file mode 100644 index 0000000..8257139 --- /dev/null +++ b/camel-hello-world/pom.xml @@ -0,0 +1,60 @@ + + 4.0.0 + com.example + camel-hello-world + jar + 1.0-SNAPSHOT + camel-hello-world + http://maven.apache.org + + + junit + junit + 3.8.1 + test + + + org.apache.camel + camel-core + 3.14.0 + + + org.apache.camel + camel-stream + 3.14.0 + + + org.slf4j + slf4j-simple + 1.7.32 + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + false + + + com.example.App + + + + + + + + + + diff --git a/camel-hello-world/src/main/java/com/example/App.java b/camel-hello-world/src/main/java/com/example/App.java new file mode 100644 index 0000000..e9fe622 --- /dev/null +++ b/camel-hello-world/src/main/java/com/example/App.java @@ -0,0 +1,27 @@ +package com.example; + +/** + * Hello world! + * + */ +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.impl.DefaultCamelContext; + +public class App { + public static void main(String[] args) throws Exception { + CamelContext context = new DefaultCamelContext(); + + context.addRoutes(new RouteBuilder() { + public void configure() { + from("direct:start").to("stream:out"); + } + }); + + context.start(); + context.createProducerTemplate().sendBody("direct:start", "Hello, World!"); + Thread.sleep(1000); + context.stop(); + } +} + diff --git a/camel-hello-world/src/test/java/com/example/AppTest.java b/camel-hello-world/src/test/java/com/example/AppTest.java new file mode 100644 index 0000000..474710c --- /dev/null +++ b/camel-hello-world/src/test/java/com/example/AppTest.java @@ -0,0 +1,38 @@ +package com.example; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/camel-hello-world/target/maven-archiver/pom.properties b/camel-hello-world/target/maven-archiver/pom.properties new file mode 100644 index 0000000..9bb331b --- /dev/null +++ b/camel-hello-world/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=camel-hello-world +groupId=com.example +version=1.0-SNAPSHOT diff --git a/camel-hello-world/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/camel-hello-world/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..0b42d49 --- /dev/null +++ b/camel-hello-world/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,2 @@ +com/example/App.class +com/example/App$1.class diff --git a/camel-hello-world/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/camel-hello-world/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..79f958a --- /dev/null +++ b/camel-hello-world/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1 @@ +/Users/preveen/prevlabs/java/camel-hello-world/src/main/java/com/example/App.java diff --git a/camel-hello-world/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/camel-hello-world/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000..5f400a6 --- /dev/null +++ b/camel-hello-world/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1 @@ +com/example/AppTest.class diff --git a/camel-hello-world/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/camel-hello-world/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..e9b740a --- /dev/null +++ b/camel-hello-world/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +/Users/preveen/prevlabs/java/camel-hello-world/src/test/java/com/example/AppTest.java diff --git a/camel-hello-world/target/surefire-reports/TEST-com.example.AppTest.xml b/camel-hello-world/target/surefire-reports/TEST-com.example.AppTest.xml new file mode 100644 index 0000000..854e0f8 --- /dev/null +++ b/camel-hello-world/target/surefire-reports/TEST-com.example.AppTest.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/camel-hello-world/target/surefire-reports/com.example.AppTest.txt b/camel-hello-world/target/surefire-reports/com.example.AppTest.txt new file mode 100644 index 0000000..141ddbf --- /dev/null +++ b/camel-hello-world/target/surefire-reports/com.example.AppTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: com.example.AppTest +------------------------------------------------------------------------------- +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.021 s - in com.example.AppTest diff --git a/er-cannot-be-written/Example.java b/er-cannot-be-written/Example.java new file mode 100644 index 0000000..584ec92 --- /dev/null +++ b/er-cannot-be-written/Example.java @@ -0,0 +1,8 @@ +public class Example { + public static void main(String[] args) { + final String str = "Hello World"; // Declare string as final + str = str.toUpperCase(); // Attempt to modify string + System.out.println(str); + } +} + diff --git a/er-cannot-be-written/Example.java.not-reproduced b/er-cannot-be-written/Example.java.not-reproduced new file mode 100644 index 0000000..6f5c4c5 --- /dev/null +++ b/er-cannot-be-written/Example.java.not-reproduced @@ -0,0 +1,8 @@ +public class Example { + public static void main(String[] args) { + String str = "Hello World"; + str.toUpperCase(); // Attempt to modify string + System.out.println(str); // Output: "Hello World" + } +} + diff --git a/ex-annotation/example-test-annotation/pom.xml b/ex-annotation/example-test-annotation/pom.xml new file mode 100644 index 0000000..65d5987 --- /dev/null +++ b/ex-annotation/example-test-annotation/pom.xml @@ -0,0 +1,18 @@ + + 4.0.0 + com.example + example-test-annotation + jar + 1.0-SNAPSHOT + example-test-annotation + http://maven.apache.org + + + junit + junit + 3.8.1 + test + + + diff --git a/ex-annotation/example-test-annotation/src/main/java/com/example/App.java b/ex-annotation/example-test-annotation/src/main/java/com/example/App.java new file mode 100644 index 0000000..b6bcb1d --- /dev/null +++ b/ex-annotation/example-test-annotation/src/main/java/com/example/App.java @@ -0,0 +1,13 @@ +package com.example; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} diff --git a/ex-annotation/example-test-annotation/src/test/java/com/example/AppTest.java b/ex-annotation/example-test-annotation/src/test/java/com/example/AppTest.java new file mode 100644 index 0000000..474710c --- /dev/null +++ b/ex-annotation/example-test-annotation/src/test/java/com/example/AppTest.java @@ -0,0 +1,38 @@ +package com.example; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/ex-annotation/string-constants/pom.xml b/ex-annotation/string-constants/pom.xml new file mode 100644 index 0000000..f132290 --- /dev/null +++ b/ex-annotation/string-constants/pom.xml @@ -0,0 +1,38 @@ + + 4.0.0 + com.example + string-constants + jar + 1.0-SNAPSHOT + string-constants + http://maven.apache.org + + + junit + junit + 4.13.2 + test + + + org.junit.jupiter + junit-jupiter-api + 5.8.1 + test + + + + + + + org.codehaus.mojo + exec-maven-plugin + 3.0.0 + + com.example.App + + + + + + diff --git a/ex-annotation/string-constants/src/main/java/com/example/App.java b/ex-annotation/string-constants/src/main/java/com/example/App.java new file mode 100644 index 0000000..b657536 --- /dev/null +++ b/ex-annotation/string-constants/src/main/java/com/example/App.java @@ -0,0 +1,22 @@ +package com.example; + +/** + * Hello world! + * + */ +import java.lang.reflect.Field; + +public class App { + @StringConstant(value = "HELLO_WORLD", description = "A greeting message") + public static final String MESSAGE = "Hello, world!"; + + public static void main(String[] args) throws Exception { + Field field = App.class.getField("MESSAGE"); + if (field.isAnnotationPresent(StringConstant.class)) { + StringConstant annotation = field.getAnnotation(StringConstant.class); + System.out.println(annotation.value() + ": " + MESSAGE); + System.out.println("Description: " + annotation.description()); + } + } +} + diff --git a/ex-annotation/string-constants/src/main/java/com/example/Constants.java b/ex-annotation/string-constants/src/main/java/com/example/Constants.java new file mode 100644 index 0000000..213f344 --- /dev/null +++ b/ex-annotation/string-constants/src/main/java/com/example/Constants.java @@ -0,0 +1,12 @@ +package com.example; + +public class Constants { + @StringConstant(value = "HELLO_WORLD", description = "A friendly greeting") + public static final String HELLO_WORLD = "Hello, world!"; + + @StringConstant(value = "GOODBYE_WORLD", description = "A farewell message") + public static final String GOODBYE_WORLD = "Goodbye, world!"; + + public static final String GREETING = "Welcome!"; // Not annotated +} + diff --git a/ex-annotation/string-constants/src/main/java/com/example/StringConstant.java b/ex-annotation/string-constants/src/main/java/com/example/StringConstant.java new file mode 100644 index 0000000..ef010b3 --- /dev/null +++ b/ex-annotation/string-constants/src/main/java/com/example/StringConstant.java @@ -0,0 +1,10 @@ +package com.example; +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface StringConstant { + String value() default ""; + String description() default ""; +} + diff --git a/ex-annotation/string-constants/src/test/java/com/example/AppTest.java b/ex-annotation/string-constants/src/test/java/com/example/AppTest.java new file mode 100644 index 0000000..474710c --- /dev/null +++ b/ex-annotation/string-constants/src/test/java/com/example/AppTest.java @@ -0,0 +1,38 @@ +package com.example; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/ex-annotation/string-constants/src/test/java/com/example/StringConstantCheckerTest.java b/ex-annotation/string-constants/src/test/java/com/example/StringConstantCheckerTest.java new file mode 100644 index 0000000..eebc0c7 --- /dev/null +++ b/ex-annotation/string-constants/src/test/java/com/example/StringConstantCheckerTest.java @@ -0,0 +1,29 @@ +package com.example; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.lang.reflect.Field; + +public class StringConstantCheckerTest { + @Test + public void testStringConstants() throws Exception { + // Get the list of annotated string constants from the Constants class + Field[] fields = Constants.class.getFields(); + + // Check that each annotated string constant is not empty + for (Field field : fields) { + if (field.isAnnotationPresent(StringConstant.class)) { + String value = (String) field.get(null); + StringConstant annotation = field.getAnnotation(StringConstant.class); + Assertions.assertFalse(value.isEmpty(), + "The " + field.getName() + " string constant is empty"); + Assertions.assertFalse(annotation.value().isEmpty(), + "The " + field.getName() + " string constant annotation value is empty"); + Assertions.assertFalse(annotation.description().isEmpty(), + "The " + field.getName() + " string constant annotation description is empty"); + } + } + } +} + diff --git a/ex-annotation/string-constants/target/maven-archiver/pom.properties b/ex-annotation/string-constants/target/maven-archiver/pom.properties new file mode 100644 index 0000000..d3a2096 --- /dev/null +++ b/ex-annotation/string-constants/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=string-constants +groupId=com.example +version=1.0-SNAPSHOT diff --git a/ex-annotation/string-constants/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/ex-annotation/string-constants/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..4f08bd2 --- /dev/null +++ b/ex-annotation/string-constants/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,3 @@ +com/example/Constants.class +com/example/StringConstant.class +com/example/App.class diff --git a/ex-annotation/string-constants/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/ex-annotation/string-constants/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..3cbe0eb --- /dev/null +++ b/ex-annotation/string-constants/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,3 @@ +/Users/preveen/prevlabs/java/ex-annotation/string-constants/src/main/java/com/example/Constants.java +/Users/preveen/prevlabs/java/ex-annotation/string-constants/src/main/java/com/example/App.java +/Users/preveen/prevlabs/java/ex-annotation/string-constants/src/main/java/com/example/StringConstant.java diff --git a/ex-annotation/string-constants/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/ex-annotation/string-constants/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000..920275e --- /dev/null +++ b/ex-annotation/string-constants/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1,2 @@ +com/example/AppTest.class +com/example/StringConstantCheckerTest.class diff --git a/ex-annotation/string-constants/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/ex-annotation/string-constants/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..fc248a6 --- /dev/null +++ b/ex-annotation/string-constants/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1,2 @@ +/Users/preveen/prevlabs/java/ex-annotation/string-constants/src/test/java/com/example/StringConstantCheckerTest.java +/Users/preveen/prevlabs/java/ex-annotation/string-constants/src/test/java/com/example/AppTest.java diff --git a/ex-annotation/string-constants/target/surefire-reports/TEST-com.example.AppTest.xml b/ex-annotation/string-constants/target/surefire-reports/TEST-com.example.AppTest.xml new file mode 100644 index 0000000..fa8f72d --- /dev/null +++ b/ex-annotation/string-constants/target/surefire-reports/TEST-com.example.AppTest.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ex-annotation/string-constants/target/surefire-reports/TEST-com.example.StringConstantCheckerTest.xml b/ex-annotation/string-constants/target/surefire-reports/TEST-com.example.StringConstantCheckerTest.xml new file mode 100644 index 0000000..50fbe2d --- /dev/null +++ b/ex-annotation/string-constants/target/surefire-reports/TEST-com.example.StringConstantCheckerTest.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ex-annotation/string-constants/target/surefire-reports/com.example.AppTest.txt b/ex-annotation/string-constants/target/surefire-reports/com.example.AppTest.txt new file mode 100644 index 0000000..bc69e91 --- /dev/null +++ b/ex-annotation/string-constants/target/surefire-reports/com.example.AppTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: com.example.AppTest +------------------------------------------------------------------------------- +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.009 s - in com.example.AppTest diff --git a/ex-annotation/string-constants/target/surefire-reports/com.example.StringConstantCheckerTest.txt b/ex-annotation/string-constants/target/surefire-reports/com.example.StringConstantCheckerTest.txt new file mode 100644 index 0000000..5854a3e --- /dev/null +++ b/ex-annotation/string-constants/target/surefire-reports/com.example.StringConstantCheckerTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: com.example.StringConstantCheckerTest +------------------------------------------------------------------------------- +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.044 s - in com.example.StringConstantCheckerTest diff --git a/hw/HelloWorld.java b/hw/HelloWorld.java new file mode 100644 index 0000000..87bf2b8 --- /dev/null +++ b/hw/HelloWorld.java @@ -0,0 +1,5 @@ +class HelloWorld { + public static void main(String[] args) { + System.out.println("Hello Java World!"); + } +} diff --git a/java17switch/test.java b/java17switch/test.java new file mode 100644 index 0000000..fd1cc2e --- /dev/null +++ b/java17switch/test.java @@ -0,0 +1,21 @@ +import java.io.IOException; + +public class test { + public static void main(String[] args) { + try { + fun(); + } catch (Exception e) { + System.out.println(e); + } + } + + public static int fun() throws IOException { + int i = 10; + + return switch (i) { + case 10 -> throw new IOException(); + case 11 -> i + 10; + default -> i+ 20; + }; + } +} diff --git a/measurement_converter/MeasurementConverter.java b/measurement_converter/MeasurementConverter.java new file mode 100644 index 0000000..a10fbbd --- /dev/null +++ b/measurement_converter/MeasurementConverter.java @@ -0,0 +1,62 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +public class MeasurementConverter extends JFrame implements ActionListener { + // GUI components + private JLabel inchLabel, mmLabel; + private JTextField inchTextField, mmTextField; + private JButton inchToMmButton, mmToInchButton; + + // Constructor + public MeasurementConverter() { + super("Measurement Converter"); + + // Set up GUI components + inchLabel = new JLabel("Inches:"); + inchTextField = new JTextField(10); + mmLabel = new JLabel("Millimeters:"); + mmTextField = new JTextField(10); + inchToMmButton = new JButton("Convert Inches to Millimeters"); + mmToInchButton = new JButton("Convert Millimeters to Inches"); + + // Set up layout + setLayout(new GridLayout(3, 2)); + add(inchLabel); + add(inchTextField); + add(mmLabel); + add(mmTextField); + add(inchToMmButton); + add(mmToInchButton); + + // Add action listeners to buttons + inchToMmButton.addActionListener(this); + mmToInchButton.addActionListener(this); + + // Set up frame + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setSize(400, 150); + setVisible(true); + } + + // ActionListener method + public void actionPerformed(ActionEvent e) { + if (e.getSource() == inchToMmButton) { + // Convert inches to millimeters + double inches = Double.parseDouble(inchTextField.getText()); + double millimeters = inches * 25.4; + mmTextField.setText(String.format("%.2f", millimeters)); + } else if (e.getSource() == mmToInchButton) { + // Convert millimeters to inches + double millimeters = Double.parseDouble(mmTextField.getText()); + double inches = millimeters / 25.4; + inchTextField.setText(String.format("%.2f", inches)); + } + } + + // Main method + public static void main(String[] args) { + new MeasurementConverter(); + } +} + diff --git a/solar_module_model/solar-module-editor/pom.xml b/solar_module_model/solar-module-editor/pom.xml new file mode 100644 index 0000000..bccb6d4 --- /dev/null +++ b/solar_module_model/solar-module-editor/pom.xml @@ -0,0 +1,29 @@ + + 4.0.0 + com.example + solar-module-editor + jar + 1.0-SNAPSHOT + solar-module-editor + http://maven.apache.org + + 1.8 + 1.8 + + + + + junit + junit + 3.8.1 + test + + + org.json + json + 20210307 + + + + diff --git a/solar_module_model/solar-module-editor/src/main/java/com/example/SolarModuleEditorGui.java b/solar_module_model/solar-module-editor/src/main/java/com/example/SolarModuleEditorGui.java new file mode 100644 index 0000000..b11e8b7 --- /dev/null +++ b/solar_module_model/solar-module-editor/src/main/java/com/example/SolarModuleEditorGui.java @@ -0,0 +1,64 @@ +package com.example; + +/** + * Hello world! + * + */ + +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.FileWriter; +import java.io.IOException; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JTextField; + +import org.json.JSONObject; + +public class SolarModuleEditorGui extends JFrame { + private JLabel currentModelLabel = new JLabel("Current Model: "); + private JTextField currentModelField = new JTextField(20); + private JLabel newModelLabel = new JLabel("New Model: "); + private JTextField newModelField = new JTextField(20); + private JButton updateButton = new JButton("Update"); + + public SolarModuleEditorGui() { + super("Solar Module Editor"); + setLayout(new FlowLayout()); + add(currentModelLabel); + add(currentModelField); + add(newModelLabel); + add(newModelField); + add(updateButton); + + updateButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + String currentModel = currentModelField.getText(); + String newModel = newModelField.getText(); + + JSONObject modelJson = new JSONObject(); + modelJson.put("currentModel", currentModel); + modelJson.put("newModel", newModel); + + try (FileWriter file = new FileWriter("solar_module_model.json")) { + file.write(modelJson.toString()); + JOptionPane.showMessageDialog(null, "Model updated successfully."); + } catch (IOException ex) { + JOptionPane.showMessageDialog(null, "Error updating model."); + } + } + }); + } + + public static void main(String[] args) { + SolarModuleEditorGui editor = new SolarModuleEditorGui(); + editor.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + editor.setSize(400, 100); + editor.setVisible(true); + } +} + diff --git a/solar_module_model/solar-module-editor/src/test/java/com/example/AppTest.java b/solar_module_model/solar-module-editor/src/test/java/com/example/AppTest.java new file mode 100644 index 0000000..474710c --- /dev/null +++ b/solar_module_model/solar-module-editor/src/test/java/com/example/AppTest.java @@ -0,0 +1,38 @@ +package com.example; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/solar_module_model/solar-module-editor/target/maven-archiver/pom.properties b/solar_module_model/solar-module-editor/target/maven-archiver/pom.properties new file mode 100644 index 0000000..5a7ebe9 --- /dev/null +++ b/solar_module_model/solar-module-editor/target/maven-archiver/pom.properties @@ -0,0 +1,5 @@ +#Generated by Maven +#Thu Feb 02 09:34:57 IST 2023 +groupId=com.example +artifactId=solar-module-editor +version=1.0-SNAPSHOT diff --git a/solar_module_model/solar-module-editor/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/solar_module_model/solar-module-editor/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..7fd21ad --- /dev/null +++ b/solar_module_model/solar-module-editor/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,2 @@ +com/example/SolarModuleEditorGui.class +com/example/SolarModuleEditorGui$1.class diff --git a/solar_module_model/solar-module-editor/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/solar_module_model/solar-module-editor/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..a295c94 --- /dev/null +++ b/solar_module_model/solar-module-editor/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1 @@ +/Users/preveen/prevlabs/java/solar_module_model/solar-module-editor/src/main/java/com/example/SolarModuleEditorGui.java diff --git a/solar_module_model/solar-module-editor/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/solar_module_model/solar-module-editor/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000..5f400a6 --- /dev/null +++ b/solar_module_model/solar-module-editor/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1 @@ +com/example/AppTest.class diff --git a/solar_module_model/solar-module-editor/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/solar_module_model/solar-module-editor/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..1d2e562 --- /dev/null +++ b/solar_module_model/solar-module-editor/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +/Users/preveen/prevlabs/java/solar_module_model/solar-module-editor/src/test/java/com/example/AppTest.java diff --git a/solar_module_model/solar-module-editor/target/surefire-reports/TEST-com.example.AppTest.xml b/solar_module_model/solar-module-editor/target/surefire-reports/TEST-com.example.AppTest.xml new file mode 100644 index 0000000..14b31f3 --- /dev/null +++ b/solar_module_model/solar-module-editor/target/surefire-reports/TEST-com.example.AppTest.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/solar_module_model/solar-module-editor/target/surefire-reports/com.example.AppTest.txt b/solar_module_model/solar-module-editor/target/surefire-reports/com.example.AppTest.txt new file mode 100644 index 0000000..27b06ac --- /dev/null +++ b/solar_module_model/solar-module-editor/target/surefire-reports/com.example.AppTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: com.example.AppTest +------------------------------------------------------------------------------- +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec