Tuesday, March 2, 2021

Rest Post Mock Intellij Mockoon

 Easy test your endpoints within the Ide : there is a world icon on the rest controller click on it



Here you can add your sample request and run easily


If you need to mock some requests Mockoon is a very handy tool for it




Tuesday, February 2, 2021

Does given array contains a triplet (a^2 + b^2 = c^2) ?

 





package com.company;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class TripletFounder {
public static void main(String[] args) {
Integer[] array = {3, 1, 4, 6, 5};
double pow = (int) Math.pow(2, array.length);
for (int i = 0; i < pow; i++) {
List<Integer> subsSeqWithSize3 = new ArrayList<>();
for (int j = 0; j < array.length; j++) {
if (BigInteger.valueOf(i).testBit(j)) {
System.out.print(array[j] + " ");
subsSeqWithSize3.add(array[j]);
}
}
if (subsSeqWithSize3.size() == 3) {
Collections.sort(subsSeqWithSize3);
if (Math.pow(subsSeqWithSize3.get(0), 2) + Math.pow(subsSeqWithSize3.get(1), 2) == Math.pow(subsSeqWithSize3.get(2), 2)) {
System.out.println("Found triplet = " + subsSeqWithSize3.toString());
System.exit(0);
}
}
System.out.println("");
}
}
}

Thursday, January 28, 2021

SpringBoot StringKafkaTemplate Conductor Kafka Topic Producer Consumer

Wanna produce and consume from Kafka topics with SpringBoot ?

Wanna watch your Kafka Topics via Conductor ?

Wanna send some rest request to produce data to send your Kafka topic ?

Don't wanna write code ?

Get The Code

Just checkout and sit back :) 
























Your custom java annotation and check for it on the classes with reflection

Just another copy paste run bye article !

package com.example.customannotation;
import java.lang.annotation.*;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface MyCustomAnnotation {
String name();
String surname();
}
class SomeClass {
@MyCustomAnnotation(name = "serkan", surname = "sunel")
public void someMethod(String someParameter) {
System.out.println("Hello annotation world !!" + someParameter);
}
}
class AnnotationProcessorWithReflection {
public static void main(String[] args) {
SomeClass someClass = new SomeClass();
List<Method> methodsAnnotatedWith = getMethodsAnnotatedWith(someClass.getClass(), MyCustomAnnotation.class);
methodsAnnotatedWith.stream().forEach(m -> System.out.println(" Method name " + m.getName()));
}
private static List<Method> getMethodsAnnotatedWith(final Class<?> type, final Class<? extends Annotation> annotation) {
final List<Method> methods = new ArrayList<>();
Class<?> klass = type;
while (klass != Object.class) {
for (final Method method : klass.getDeclaredMethods()) {
if (method.isAnnotationPresent(annotation)) {
Annotation annotInstance = method.getAnnotation(annotation);
System.out.println("annotInstance = " + annotInstance + " found on the class: " + type);
methods.add(method);
}
}
klass = klass.getSuperclass();
}
return methods;
}
}