/*
 * Copyright 2016 Palantir Technologies, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.palantir.docker.compose.execution;

import java.io.File;
import java.util.List;
import java.util.Optional;

import static java.util.Arrays.asList;

public class DockerComposeLocations {
    private final List<String> paths;

    public DockerComposeLocations(String... paths) {
        this.paths = asList(paths);
    }

    public Optional<String> preferredLocation() {
        return paths.stream()
                .filter(path -> path != null)
                .filter(path -> new File(path).exists())
                .findFirst();
    }
}

@@ -743,16 +743,53 @@
 ptional;
+%0Aimport java.util.function.Predicate;
 %0A%0Aimport
@@ -876,28 +876,210 @@
 ate 
-final List%3CString%3E p
+static final Predicate%3CString%3E IS_NOT_NULL = path -%3E path != null;%0A    private static final Predicate%3CString%3E FILE_EXISTS = path -%3E new File(path).exists();%0A    %0A    private final List%3CString%3E possibleP
 aths
@@ -1126,16 +1126,24 @@
 ing... p
+ossibleP
 aths) %7B%0A
@@ -1156,16 +1156,24 @@
   this.p
+ossibleP
 aths = a
@@ -1179,16 +1179,24 @@
 asList(p
+ossibleP
 aths);%0A 
@@ -1247,24 +1247,25 @@
 ocation() %7B%0A
+%0A
         retu
@@ -1268,16 +1268,24 @@
 return p
+ossibleP
 aths.str
@@ -1314,36 +1314,27 @@
 .filter(
-path -%3E path != null
+IS_NOT_NULL
 )%0A      
@@ -1355,39 +1355,19 @@
 ter(
-path -%3E new File(path).exists()
+FILE_EXISTS
 )%0A  

Clean up implementation