Data retrieval service with exponential backoff

Posted on Leave a commentPosted in java

Here we will create Data retrieval service with exponential backoff that we covered in the previous post. Implementation   package com.rms.blueprint.data;   import java.util.Date; import java.util.Objects; import java.util.concurrent.TimeUnit; import java.util.function.Function; import java.util.function.ObjLongConsumer; import java.util.function.Supplier;   import org.slf4j.Logger; import org.slf4j.LoggerFactory;   public class DataRetrievalWithBackoff implements Runnable { public final Logger LOGGER = LoggerFactory.getLogger(DataRetrievalWithBackoff.class);   private final […]

Generate ID from UUID

Posted on 2 CommentsPosted in java

This is a method to generate a long id in the positive space. There are few issues to consider with this method – UUID is 16 bytes / 128 bits – Long is 8 bytes / 64 bits This means that we will loose some information, if we don’t want to lose that we could […]

Calculate centroid of 2D non crossing polygon

Posted on Leave a commentPosted in java

Calculate centroid of 2D non crossing polygon, To accommodate that points are correct using Gift wrapping algorithm(Finding Convex Hull) Test case   import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull;   import java.awt.Point; import java.util.ArrayList; import java.util.Arrays; import java.util.List;   import org.junit.Test;   public class MathUtilTest {   @Test public void computeCentroidWithHull() { Point p1 = new […]

Find Convex hull of given points using Gift wrapping algorithm

Posted on 3 CommentsPosted in java

Find Convex hull of given points using Gift wrapping algorithm This is implementation of Grift wrapping algorithm for finding convex hull.   private static final Integer ZERO = new Integer(0);     /** * Find Convex hull of given points * * @ref http://en.wikipedia.org/wiki/Gift_wrapping_algorithm * @param vertices * @return */ private static List<Point> findConvexHull(final List<Point> […]

Convert Leptonica PIX data to Java BufferedImage

Posted on Leave a commentPosted in java

This snippet allows us to convert Leptonica PIX data into Java BufferedImage, in my case the pix->data could be compressed using zlib so I am decompressing before recreating image. We are assuming here that this is bi-tonal image(1 bpp) Sample Usage BufferedImage image = LeptonicaUtil.convert(zlibData, width, height, 1); ImageIO.write(image, "png", new File("C:/temp/test.png")); BufferedImage image = […]