Skip to content

Instantly share code, notes, and snippets.

codinko codinko

View GitHub Profile
View bootstrap-carousel-multiple-items.html
@codinko
codinko / JsonNodeReadingExample1.java
Last active Jan 20, 2020
Read elements from the Json Tree - say responseData.json
View JsonNodeReadingExample1.java
String jsonString = Util.readFileFromClassPathAndConvert2String(fileNameInCP);
JsonNode root = objectMapper.readTree(jsonString);
---------------------
APPROACH-1
---------------------
JsonNode nodes = root.get("companies");
// imp note that you are going to iterate over the node values, not the keys ...
Iterator<JsonNode> itr = nodes.iterator();
@codinko
codinko / readFileFromClassPathAndConvert2String.java
Created Jan 19, 2020
readFileFromClassPathAndConvert2String , Convert InputStream to String
View readFileFromClassPathAndConvert2String.java
package com.codinko.json.util;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
public class Util {
public static String readFileFromClassPathAndConvert2String(String filenameInCP) {
@codinko
codinko / pom.xml
Created Nov 22, 2019
mavenprofilepom1
View pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.codinko</groupId>
<artifactId>mavenprofilesample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<profiles>
View MainCachingGet.java
package com.codinko.caching;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Main {
public static void main(String[] args) {
@codinko
codinko / EmployeeDAOCaching.java
Created Nov 21, 2019
EmployeeDAOCachingGetEmployee
View EmployeeDAOCaching.java
package com.codinko.caching;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
@codinko
codinko / Employee.java
Created Nov 21, 2019
EmployeeClassWithIdNameDesig
View Employee.java
package com.codinko.caching;
public class Employee {
private int id;
private String name;
private String designation;
public Employee(int id, String name, String designation) {
super();
this.id = id;
@codinko
codinko / java.util.Optional.map.codesnippet1.java
Last active Nov 19, 2018
java.util.Optional.map code snippet-1
View java.util.Optional.map.codesnippet1.java
// Get all notes by userId
java.util.Optional;
java.util.Optional.map()
java.util.Optional class
// A container object which may or may not contain a non-null value.
// If a value is present, {@code isPresent()} will return {@code true} and
// {@code get()} will return the value.
// Approach-1
View NoteUserJavaStreamUsageWithMapReduce.java
// How to get a Note from noteId and userId
private Note findNote(int noteId, List<Note> notes) {
return notes.stream()
.filter(note -> note.getNoteId() == noteId)
.findAny()
.orElse(null);
}
// Approach-1
@codinko
codinko / deleteNoteUsageOfJavaStream.java
Last active Nov 18, 2018
delete a note using java stream
View deleteNoteUsageOfJavaStream.java
public boolean deleteNote(String userId, int noteId) {
NoteUser dbUser = this.noteRepository.findById(userId).orElse(null);
Note dbNote = null;
if(dbUser != null) {
dbNote = this.findNote(noteId, dbUser.getNotes());
if(dbNote != null) {
dbUser.getNotes().remove(dbNote);
dbUser = this.noteRepository.save(dbUser);
}
You can’t perform that action at this time.