Building REST API with Swagger
Swagger is one of the most popular specifications for developing APIs on the market right now. There are different ways how to work with it. I’ll describe my practical experience. Code generation By this...
making ideas into a digitized reality
Swagger is one of the most popular specifications for developing APIs on the market right now. There are different ways how to work with it. I’ll describe my practical experience. Code generation By this...
This short comment intends to explain the usage of HSQLDB as a shared data source for Apache camel using camel-blueprint. As a result, any possible camel routes can be linked to the created shared data source....
There are a lot of examples how to read a file content in Java 8. The most common one is
1 2 3 4 5 6 7 |
import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public static void main(String[] args) throws IOException { String content = new String(Files.readAllBytes(Paths.get("duke.java"))); } |
Use always a charset with String to Byte array transformations and vice versa...
1 2 3 4 5 6 7 8 9 10 11 12 |
distance = new long[points.size()][points.size()]; for (int i = -1; ++i < points.size();) { int x1 = points.get(i).getX(); int y1 = points.get(i).getY(); distance[i][i] = 0; for (int j = -1; ++j < i;) { int x2 = points.get(j).getX(); int y2 = points.get(j).getY(); distance[i][j] = Math.max(Math.abs(x1 - x2) * costX, Math.abs(y1 - y2) * costY); distance[j][i] = distance[i][j]; } } |
CostX and CostY – are the axle weight. E.g .: maximum axis velocity of the robot. An edge is calculated by the TSPAction class. The recursive function returns no results , so TSPAction...
Short snippet how to leave 100 newest text files in directory and delete others with help of Java 8 lambda.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
String pattern = "**.txt"; int fileCapacity = 100; Path path = Paths.get("your/directory/"); PathMatcher ldfMatcher = FileSystems.getDefault().getPathMatcher("glob:" + pattern); try (DirectoryStream files = Files.newDirectoryStream(path)) { StreamSupport.stream(files.spliterator(), false) // sequential stream .filter(file -> Files.isRegularFile(file) && ldfMatcher.matches(file)) .sorted((Path o1, Path o2) -> { try { return Files.getLastModifiedTime(o2).compareTo(Files.getLastModifiedTime(o1)); } catch (IOException ex) { // exception handling... } }) .skip(fileCapacity) .forEach(file -> { try { Files.delete(file); } catch (IOException ex) { // exception handling... } }); } catch (IOException ex) { // exception handling... } |