Challenges are what make life interesting
Overcoming them is what makes life meaningful I am enjoying Challenges
Friday 4 October 2019
Wednesday 2 October 2019
Java 8 predicate test method example
for this
https://stackoverflow.com/questions/1128723/how-do-i-determine-whether-an-array-contains-a-particular-value-in-java/1128728#1128728
I have a String[] with values like so:
https://stackoverflow.com/questions/1128723/how-do-i-determine-whether-an-array-contains-a-particular-value-in-java/1128728#1128728
I have a String[] with values like so:
public static final String[] VALUES = new String[] {"AB","BC","CD","AE"};
Given
String s
, is there a good way of testing whether VALUES
contains s
?
ANS:
Java 8 predicate test method is best for it.
test(T t) : Evaluates this predicate on the given argument.boolean test(T t)
test(T t)
Parameters:
t - the input argument
Returns:
true if the input argument matches the predicate, otherwise false
Here is a full example of it.
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
public class Test {
public static final List<String> VALUES = Arrays.asList("AA", "AB", "BC", "CD", "AE");
public static void main(String args[]) {
Predicate<String> containsLetterA = VALUES -> VALUES.contains("AB");
for (String i : VALUES) {
System.out.println(containsLetterA.test(i));
}
}
}
Wednesday 4 September 2019
docker commands
Here is a list of docker commands.
Child commands
Child commands
Command | Description |
docker attach | Attach local standard input, output, and error streams to a running container |
docker build | Build an image from a Dockerfile |
docker builder | Manage builds |
docker checkpoint | Manage checkpoints |
docker commit | Create a new image from a container’s changes |
docker config | Manage Docker configs |
docker container | Manage containers |
docker context | Manage contexts |
docker cp | Copy files/folders between a container and the local filesystem |
docker create | Create a new container |
docker deploy | Deploy a new stack or update an existing stack |
docker diff | Inspect changes to files or directories on a container’s filesystem |
docker engine | Manage the docker engine |
docker events | Get real time events from the server |
docker exec | Run a command in a running container |
docker export | Export a container’s filesystem as a tar archive |
docker history | Show the history of an image |
docker image | Manage images |
docker images | List images |
docker import | Import the contents from a tarball to create a filesystem image |
docker info | Display system-wide information |
docker inspect | Return low-level information on Docker objects |
docker kill | Kill one or more running containers |
docker load | Load an image from a tar archive or STDIN |
docker login | Log in to a Docker registry |
docker logout | Log out from a Docker registry |
docker logs | Fetch the logs of a container |
docker manifest | Manage Docker image manifests and manifest lists |
docker network | Manage networks |
docker node | Manage Swarm nodes |
docker pause | Pause all processes within one or more containers |
docker plugin | Manage plugins |
docker port | List port mappings or a specific mapping for the container |
docker ps | List containers |
docker pull | Pull an image or a repository from a registry |
docker push | Push an image or a repository to a registry |
docker rename | Rename a container |
docker restart | Restart one or more containers |
docker rm | Remove one or more containers |
docker rmi | Remove one or more images |
docker run | Run a command in a new container |
docker save | Save one or more images to a tar archive (streamed to STDOUT by default) |
docker search | Search the Docker Hub for images |
docker secret | Manage Docker secrets |
docker service | Manage services |
docker stack | Manage Docker stacks |
docker start | Start one or more stopped containers |
docker stats | Display a live stream of container(s) resource usage statistics |
docker stop | Stop one or more running containers |
docker swarm | Manage Swarm |
docker system | Manage Docker |
docker tag | Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE |
docker top | Display the running processes of a container |
docker trust | Manage trust on Docker images |
docker unpause | Unpause all processes within one or more containers |
docker update | Update configuration of one or more containers |
docker version | Show the Docker version information |
docker volume | Manage volumes |
docker wait | Block until one or more containers stop, then print their exit codes |
Saturday 1 September 2018
Sunday 26 August 2018
return list of json spring boot rest controller
Let Say we have list of CarDetails Pojo and we want to return them back
@RestController
public class CarDetailController {
@GetMapping("/viewAllCarDetailList")
public List<CarDetail> retrieveAllCarDetails() {
List<CarDetail> contacts = new ArrayList<CarDetail>();
CarDetail objt = new CarDetail();
objt.setCarModel("hyundai");
objt.setSubModel("I10");
CarDetail objt2 = new CarDetail();
objt2.setCarModel("hyundai");
objt2.setSubModel("I20");
contacts.add(objt);
contacts.add(objt2);
return contacts;
}
}
public class CarDetails {
private String carModel;
private String subModel;
// Will haave Setter getter and hash code equls method
//and constructor
}
This JSON will be output:-
[
{
"carModel": "hyundai",
"subModel": "I10"
},
{
"carModel": "hyundai",
"subModel": "I20"
}
]
https://stackoverflow.com/questions/41719142/how-to-return-a-set-of-objects-with-spring-boot
Subscribe to:
Posts (Atom)