Thursday, June 16, 2022

In a Map, use put to update an existing value

 Existing values in a Map entry can be updated using "put":


package org.nstern.demos.app;

import java.util.HashMap;
import java.util.Map;

public class MapPutDemo {

public static void main(String[] args) {

Map<String, String> map = new HashMap<>();
map.put("Andy", "hello");
map.put("Bernie", "hi");
System.out.println(map);
map.put("Andy", "world");
System.out.println(map);
}
}
Output:
{Andy=hello, Bernie=hi}
{Andy=world, Bernie=hi}

Wednesday, May 11, 2022

GIT : push a change from a local branch to a new remote branch

1. Create a new local branch

$git checkout -b  feature/my-new-branch

2. Push the new local branch to a remote repo, creating a new remote branch

$git push -u origin feature/my-new-branch


See reference


Wednesday, April 20, 2022

Builder Implementation

 Class with Builder:

  1. public class MyClass {

  2.     public String member;

  3.     public static class Builder {
  4.         MyClass class = new MyClass();

  5.         public Builder withMember(String member) {
  6.             class.member = member;
  7.             return this;
  8.         }

  9.         public MyClass build() {
  10.             return class;
  11.         }
  12.     }
  13. }

Call

  1. package ch.mobi.vvn.baustein.dto;

  2. public class Caller {

  3.     void myMethod(){
  4.         MyClass myClass = new MyClass.Builder()
  5.           .withMember("x")
  6.           .build();
  7.     }
  8. }



Thursday, March 31, 2022

Read the content of a blob field in Oracle

 Works simply using conversion to clob:

$select to_clob(my_column) from  my_table;

Wednesday, March 16, 2022

Virtual board with sticky notes

 Found and used a good sticky notes app : https://app.mural.co/

Thursday, January 13, 2022

How to use XStream to generate xml from an object

I had to instrumentalize my code to generate tests. For that purpose, I used serialization to capture my objects state from the server while running some system tests. And I used the generated files for my tests using deserialization.

To tackle the complexity of some object graphs, I choose to use Xstream to generate xml.

Here's how to dump an object to xml:

XStream xstream = new XStream();




String xml = xstream.toXML(cs);
String filePath = "output.xml";
try{
new File(filePath).createNewFile();
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath), "utf-8"))) {
writer.write(xml);
writer.flush();
}
} catch (IOException e){
e.printStackTrace();
}

I packed it into an utility class: 

...
String fpxmlcurrentLossratioContractDTO = "currentLossratioContractDTO.xml";
XmlHelper.writeToFileAsXml(currentLossratioContractDTO,fpxmlcurrentLossratioContractDTO);
...