/*
 * Copyright 2016 the original author or authors.
 *
 * 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 org.gradle.internal.metaobject;

public abstract class DynamicInvokeResult {

    public static DynamicInvokeResult found(Object value) {
        return value == null ? found() : new Found(value);
    }

    public static DynamicInvokeResult found() {
        return Found.NULL;
    }

    public static DynamicInvokeResult notFound() {
        return NotFound.INSTANCE;
    }

    private DynamicInvokeResult() {
    }

    public abstract Object getValue();

    public abstract boolean isFound();

    private static class NotFound extends DynamicInvokeResult {
        private static final NotFound INSTANCE = new NotFound();

        @Override
        public Object getValue() {
            throw new IllegalStateException("Not found");
        }

        @Override
        public boolean isFound() {
            return false;
        }
    }

    private static class Found extends DynamicInvokeResult {
        private static final Found NULL = new Found(null);

        private final Object value;

        private Found(Object value) {
            this.value = value;
        }

        @Override
        public Object getValue() {
            return value;
        }

        @Override
        public boolean isFound() {
            return true;
        }
    }
}

@@ -658,25 +658,16 @@
 %0Apublic 
-abstract 
 class Dy
@@ -685,16 +685,249 @@
 Result %7B
+%0A%0A    private static final Object NO_VALUE = new Object();%0A    private static final DynamicInvokeResult NOT_FOUND = new DynamicInvokeResult(NO_VALUE);%0A    private static final DynamicInvokeResult NULL = new DynamicInvokeResult(null);
 %0A%0A    pu
@@ -1025,21 +1025,35 @@
 ) : new 
-Found
+DynamicInvokeResult
 (value);
@@ -1123,21 +1123,35 @@
  return 
-Found
+DynamicInvokeResult
 .NULL;%0A 
@@ -1226,46 +1226,8 @@
 urn 
-NotFound.INSTANCE;%0A    %7D%0A%0A    private 
 Dyna
@@ -1241,20 +1241,27 @@
 keResult
-() %7B
+.NOT_FOUND;
 %0A    %7D%0A%0A
@@ -1269,235 +1269,119 @@
    p
-ublic abstract Object getValue();%0A%0A    public abstract boolean isFound();%0A%0A    private static class NotFound extends DynamicInvokeResult %7B%0A        private static final NotFound INSTANCE = new NotFound();%0A%0A        @Override%0A    
+rivate final Object value;%0A%0A    private DynamicInvokeResult(Object value) %7B%0A        this.value = value;%0A    %7D%0A%0A
     
@@ -1419,110 +1419,12 @@
     
-    throw new IllegalStateException(%22Not found%22);%0A        %7D%0A%0A        @Override%0A        public boolean 
+if (
 isFo
@@ -1420,32 +1420,33 @@
    if (isFound()
+)
  %7B%0A            r
@@ -1455,12 +1455,12 @@
 urn 
-fals
+valu
 e;%0A 
@@ -1471,242 +1471,72 @@
    %7D
-%0A    %7D%0A%0A    private static class Found extends DynamicInvokeResult %7B%0A        private static final Found NULL = new Found(null);%0A%0A        private final Object value;%0A%0A        private Found(Object value) %7B%0A            this.value = value
+ else %7B%0A            throw new IllegalStateException(%22Not found%22)
 ;%0A  
@@ -1547,121 +1547,15 @@
   %7D%0A
-%0A
     
-    @Override%0A        public Object getValue() %7B%0A            return value;%0A        %7D%0A%0A        @Override%0A    
+%7D%0A%0A
     
@@ -1593,34 +1593,33 @@
     
-    
 return 
-true;%0A        %7D
+value != NO_VALUE;
 %0A   

Make DynamicInvokeResult more inline-friendly