diff --git a/src/com/p2/client/CassandraClient.java b/src/com/p2/client/CassandraClient.java new file mode 100644 index 0000000..a3cd715 --- /dev/null +++ b/src/com/p2/client/CassandraClient.java @@ -0,0 +1,48 @@ +package com.p2.client; + +public class CassandraClient { + + public static void main(String[] args) { + + } + +} + +class CassandraConnector { + + private Cluster cluster; + + private Session session; + + public static void connect(String node, Integer port) { + Builder b = Cluster.builder().addContactPoint(node); + if (port != null) { + b.withPort(port); + } + cluster = b.build(); + + session = cluster.connect(); + } + + public static Session getSession() { + return this.session; + } + + public static void close() { + session.close(); + cluster.close(); + } + + public void createKeyspace(String keyspaceName, String replicationStrategy, + int replicationFactor) { + StringBuilder sb = new StringBuilder("CREATE KEYSPACE IF NOT EXISTS ") + .append(keyspaceName).append(" WITH replication = {") + .append("'class':'").append(replicationStrategy) + .append("','replication_factor':").append(replicationFactor) + .append("};"); + + String query = sb.toString(); + session.execute(query); + } + +} \ No newline at end of file diff --git a/src/com/p2/client/NetClientGet.java b/src/com/p2/client/NetClientGet.java new file mode 100644 index 0000000..bec6902 --- /dev/null +++ b/src/com/p2/client/NetClientGet.java @@ -0,0 +1,53 @@ +package com.p2.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; + +public class NetClientGet { + + public static void main(String[] args) { + String url = "http://localhost:8080/RESTfulExample/json/product/get"; + // How to convert json payload into JavaObject + } + +} + +class JavaRestClient { + + public static void httpGet(String url, String method) { + + try { + + URL finalUrl = new URL(url); + HttpURLConnection conn = (HttpURLConnection) finalUrl + .openConnection(); + conn.setRequestMethod("GET"); + conn.setRequestProperty("Accept", "application/json"); + + if (conn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + + conn.getResponseCode()); + } + + BufferedReader br = new BufferedReader(new InputStreamReader( + (conn.getInputStream()))); + + String output; + System.out.println("Output from Server .... \n"); + while ((output = br.readLine()) != null) { + System.out.println(output); + } + + conn.disconnect(); + + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/com/p2/client/package-info.java b/src/com/p2/client/package-info.java new file mode 100644 index 0000000..01fa0ed --- /dev/null +++ b/src/com/p2/client/package-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * @author pradeep_patel + * + */ +package com.p2.client; \ No newline at end of file diff --git a/src/com/p2/io/CurrentDirectoryAndPath.java b/src/com/p2/io/CurrentDirectoryAndPath.java new file mode 100644 index 0000000..d17e677 --- /dev/null +++ b/src/com/p2/io/CurrentDirectoryAndPath.java @@ -0,0 +1,30 @@ +package com.p2.io; + +import java.io.File; +import java.io.IOException; +import java.util.Enumeration; +import java.util.Properties; + +public class CurrentDirectoryAndPath { + + public static void main(String[] args) throws IOException { + File currentDirFile = new File("."); + String path = currentDirFile.getAbsolutePath(); + + System.out.println(path); + + Properties properties = System.getProperties(); + System.out.println(properties.get("user.dir")); + File f = new File(properties.get("user.dir")+"\\map1.json" ); + System.out.println(f.getAbsolutePath()); + + /*properties.get("user.dir"); + Enumeration enumeration = properties.keys(); + for (int i = 0; i < properties.size(); i++) { + Object obj = enumeration.nextElement(); + System.out.println("Key: " + obj + "\tOutPut= " + + System.getProperty(obj.toString())); + }*/ + + } +} diff --git a/src/com/p2/json/JsonParserExample.java b/src/com/p2/json/JsonParserExample.java new file mode 100644 index 0000000..1a3d8f0 --- /dev/null +++ b/src/com/p2/json/JsonParserExample.java @@ -0,0 +1,105 @@ +package com.p2.json; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import org.json.JSONObject; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class JsonParserExample { + + public static void main(String[] args) throws JsonParseException,JsonMappingException, IOException { + String file01 = "d:\\temp\\" + "map1.json"; + String file02 = "d:\\temp\\" + "map2.json"; + String[] pathList = { file01, file02 }; + List> list = ReadFile.readJSON(Arrays + .asList(pathList)); + List> nestedKeys = new ArrayList>(); + ReadFile.printAllKeys(list,nestedKeys); + + System.out.println(nestedKeys.toString()); + //ReadFile.mergeMaps(list); + + } +} + +class ReadFile { + + static List> readJSON(List pathList) { + ObjectMapper mapper = new ObjectMapper(); + Map map; + List> jsonFileList = new ArrayList>(); + + for (String path : pathList) { + try { + map = mapper.readValue(new File(path), + new TypeReference>() { + }); + + jsonFileList.add(map); + } catch (JsonParseException e) { + e.printStackTrace(); + } catch (JsonMappingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + return jsonFileList; + } + + static void printAllKeys(List> listOfJsonFiles,List> list) { + int i = 0; + for (Map json : listOfJsonFiles) { + System.out.println(i + + " Map :----------------------------------------->"); + printKeys(json,list); + } + } + + static Map mergeMaps(List> listOfJsonFiles) { + System.out.println("Inside merge maps"); + for (Map json : listOfJsonFiles) { + Set keys = json.keySet(); + for (String string : keys) { + System.out.println("Printing Key :" + string); + json.get(string); + if (json.get(string) instanceof Map) { + } else { + } + } + } + return null; + } + + static void printKeys(Object value,List> list) { + + List innerList = new ArrayList(); + if (value instanceof Map) { + Set keys = ((Map) value).keySet(); + + for (String string : keys) { + System.out.println("Printing Key :" + string); + innerList.add(string); + printKeys(((Map) value).get(string),list); + } + list.add(innerList); + } else { + + //System.out.println("Printing Values :" + value); + } + } +} diff --git a/src/com/p2/json/package-info.java b/src/com/p2/json/package-info.java new file mode 100644 index 0000000..b351242 --- /dev/null +++ b/src/com/p2/json/package-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * @author pradeep_patel + * + */ +package com.p2.json; \ No newline at end of file diff --git a/src/com/p2/marshalling/package-info.java b/src/com/p2/marshalling/package-info.java new file mode 100644 index 0000000..835d897 --- /dev/null +++ b/src/com/p2/marshalling/package-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * @author pradeep_patel + *http://www.javarticles.com/2016/09/jaxb-binding-and-unmarshalling-example.html + */ +package com.p2.marshalling; \ No newline at end of file diff --git a/src/com/p2/regex/PatternExample.java b/src/com/p2/regex/PatternExample.java new file mode 100644 index 0000000..6c3ed6d --- /dev/null +++ b/src/com/p2/regex/PatternExample.java @@ -0,0 +1,29 @@ +package com.p2.regex; + +import java.util.regex.Pattern; + +public class PatternExample { + + public static void main(String[] args) { + + //Regular Expression Character classes Example + String [] lsit = {"[abc]","[^abc]","[a-zA-Z]","[a-d[m-p]]","[a-z&&[def]]","[a-z&&[^bc]]","[a-z&&[^m-p]]"}; + + Regex.checkMatch("....s.", "Mahesh"); + // + Regex.checkMatch(lsit[2], "adfewtwetryre"); + + + + } +} + +class Regex { + + static void checkMatch(String matcher, String matches) { + boolean b = Pattern.matches(matcher, matches); + System.out.println(b); + + } + +} \ No newline at end of file diff --git a/src/com/p2/regex/RegexExample.java b/src/com/p2/regex/RegexExample.java new file mode 100644 index 0000000..e3e0efb --- /dev/null +++ b/src/com/p2/regex/RegexExample.java @@ -0,0 +1,27 @@ +package com.p2.regex; + +import java.util.regex.Pattern; +import java.util.Scanner; +import java.util.regex.Matcher; + +public class RegexExample { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + while (true) { + System.out.println("Enter regex pattern:"); + Pattern pattern = Pattern.compile(sc.nextLine()); + System.out.println("Enter text:"); + Matcher matcher = pattern.matcher(sc.nextLine()); + boolean found = false; + while (matcher.find()) { + System.out.println("I found the text " + matcher.group() + + " starting at index " + matcher.start() + + " and ending at index " + matcher.end()); + found = true; + } + if (!found) { + System.out.println("No match found."); + } + } + } +} \ No newline at end of file diff --git a/src/com/p2/regex/package-info.java b/src/com/p2/regex/package-info.java new file mode 100644 index 0000000..8db9483 --- /dev/null +++ b/src/com/p2/regex/package-info.java @@ -0,0 +1,39 @@ +/** + * + */ +/** + * @author pradeep_patel + * + */ +package com.p2.regex; + +/** + +java.util.regex package + +It provides following classes and interface for regular expressions. The Matcher and Pattern classes are +widely used in java regular expression. + + MatchResult interface + Matcher class + Pattern class + PatternSyntaxException class + + +*/ + + +/** +No. Method Description +1 boolean matches() test whether the regular expression matches the pattern. +2 boolean find() finds the next expression that matches the pattern. +3 boolean find(int start) finds the next expression that matches the pattern from the given start number. +4 String group() returns the matched subsequence. +5 int start() returns the starting index of the matched subsequence. +6 int end() returns the ending index of the matched subsequence. +7 int groupCount() returns the total number of the matched subsequence. + +*/ + + +