Friday, January 23, 2015

new favourite command

A must have for console addicted git users:
git checkout -
This jumps back and forward between two last branches. Really awesome.

Thursday, January 8, 2015

more hints regarding Optionals

Instead of
        Optional<Camera> camera = getCameraByMac(cameras, mac);        
        if (camera.isPresent()) {            
            return Optional.of( camera.get().getIp() );        
        } else {            
            return Optional.absent();        
        }

use
  
   Optional<Camera> camera = getCameraByMac(cameras, mac);
   return camera.transform(getIpFunction);

    static final Function<Camera, String> getIpFunction = new Function<Camera, String>() {
        @Nullable @Override
        public String apply(Camera camera) {
            return camera.getIP();
        }
    };

instead of
  
        List<Event> result = new LinkedList<>();
        for (Optional<Event> transformedEvent : someEvents) {
            if (transformedEvent.isPresent()) {
                result.add(transformedEvent.get());
            }
        }
        return result;

use
  
        return Optional.presentInstances(events);