// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
// 
//     private final Object instance;
//     private final T annotation;
// 
// 
//     public CheckerContext(final Object instance, final T annotation) {
//         this.instance = instance;
//         this.annotation = annotation;
//     }
// 
// 
//     public Object getInstance() {
//         return instance;
//     }
// 
//     public T getAnnotation() {
//         return annotation;
//     }
// 
// }
// 
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
// 
//     /**
//      * Checks if execution of test method should be continued or not.
//      *
//      * @param context input data for checker
//      * @return true if execution should be continued and false - otherwise
//      * @throws Exception on any error (it is the same as false in return value)
//      */
//     boolean isSatisfied(CheckerContext<T> context) throws Exception;
// 
// }
// 
// Path: src/main/java/com/github/vbauer/jconditions/util/InOutUtils.java
// public final class InOutUtils {
// 
//     private static final int BUFFER_SIZE = 1024;
//     private static final int EOF = -1;
// 
// 
//     private InOutUtils() {
//         throw new UnsupportedOperationException();
//     }
// 
// 
//     public static boolean closeQuietly(final Closeable closeable) {
//         try {
//             closeable.close();
//             return true;
//         } catch (final Exception ex) {
//             return false;
//         }
//     }
// 
//     public static void copy(final InputStream input, final OutputStream output) throws IOException {
//         final byte[] bytes = new byte[BUFFER_SIZE];
//         int read;
// 
//         while ((read = input.read(bytes)) != EOF) {
//             output.write(bytes, 0, read);
//         }
//     }
// 
// }
// 
// Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java
// public final class PropUtils {
// 
//     private static final String VAR_PREFIX = "${";
//     private static final String VAR_POSTFIX = "}";
// 
// 
//     private PropUtils() {
//         throw new UnsupportedOperationException();
//     }
// 
// 
//     public static String getSystemProperty(final String key) {
//         final Map<String, String> properties = getSystemProperties();
//         return properties.get(key);
//     }
// 
//     public static Map<String, String> getSystemProperties() {
//         final Map<String, String> result = new HashMap<>();
//         result.putAll(System.getenv());
//         result.putAll(convertPropertiesToMap(System.getProperties()));
//         return result;
//     }
// 
//     public static Map<String, String> convertPropertiesToMap(final Properties properties) {
//         final Map<String, String> result = new HashMap<>();
//         for (final String name : properties.stringPropertyNames()) {
//             result.put(name, properties.getProperty(name));
//         }
//         return result;
//     }
// 
//     public static String injectProperties(final String text) {
//         if (text != null && text.contains(VAR_PREFIX)) {
//             String result = text;
//             final Map<String, String> systemProperties = getSystemProperties();
//             for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
//                 final String key = entry.getKey();
//                 final String value = entry.getValue();
//                 result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value);
//             }
//             return result;
//         }
//         return text;
//     }
// 
//     public static boolean hasAnyWithProperties(final String value, final String... variants) {
//         for (final String operationSystem : variants) {
//             final String injected = injectProperties(operationSystem);
//             if (TextUtils.containsIgnoreCase(value, injected)) {
//                 return true;
//             }
//         }
//         return false;
//     }
// 
// }


import com.github.vbauer.jconditions.annotation.SocketIsOpened;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.util.InOutUtils;
import com.github.vbauer.jconditions.util.PropUtils;
import java.net.InetSocketAddress;
import java.net.Socket;
package com.github.vbauer.jconditions.checker;



/**
 * @author Vladislav Bauer
 */

public class SocketIsOpenedChecker implements ConditionChecker<SocketIsOpened> {

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean isSatisfied(final CheckerContext<SocketIsOpened> context) throws Exception {
        final SocketIsOpened annotation = context.getAnnotation();
        final String host = PropUtils.injectProperties(annotation.host());
        final int port = annotation.port();
        final int timeout = annotation.timeout();
        return isSocketOpened(host, port, timeout);
    }


    private boolean isSocketOpened(final String host, final int port, final int timeout) throws Exception {
        Socket socket = null;
        try {
            socket = new Socket();
            socket.bind(null);
            socket.connect(new InetSocketAddress(host, port), timeout);
            return true;
        } finally {
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
// 
//     private final Object instance;
//     private final T annotation;
// 
// 
//     public CheckerContext(final Object instance, final T annotation) {
//         this.instance = instance;
//         this.annotation = annotation;
//     }
// 
// 
//     public Object getInstance() {
//         return instance;
//     }
// 
//     public T getAnnotation() {
//         return annotation;
//     }
// 
// }
// 
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
// 
//     /**
//      * Checks if execution of test method should be continued or not.
//      *
//      * @param context input data for checker
//      * @return true if execution should be continued and false - otherwise
//      * @throws Exception on any error (it is the same as false in return value)
//      */
//     boolean isSatisfied(CheckerContext<T> context) throws Exception;
// 
// }
// 
// Path: src/main/java/com/github/vbauer/jconditions/util/InOutUtils.java
// public final class InOutUtils {
// 
//     private static final int BUFFER_SIZE = 1024;
//     private static final int EOF = -1;
// 
// 
//     private InOutUtils() {
//         throw new UnsupportedOperationException();
//     }
// 
// 
//     public static boolean closeQuietly(final Closeable closeable) {
//         try {
//             closeable.close();
//             return true;
//         } catch (final Exception ex) {
//             return false;
//         }
//     }
// 
//     public static void copy(final InputStream input, final OutputStream output) throws IOException {
//         final byte[] bytes = new byte[BUFFER_SIZE];
//         int read;
// 
//         while ((read = input.read(bytes)) != EOF) {
//             output.write(bytes, 0, read);
//         }
//     }
// 
// }
// 
// Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java
// public final class PropUtils {
// 
//     private static final String VAR_PREFIX = "${";
//     private static final String VAR_POSTFIX = "}";
// 
// 
//     private PropUtils() {
//         throw new UnsupportedOperationException();
//     }
// 
// 
//     public static String getSystemProperty(final String key) {
//         final Map<String, String> properties = getSystemProperties();
//         return properties.get(key);
//     }
// 
//     public static Map<String, String> getSystemProperties() {
//         final Map<String, String> result = new HashMap<>();
//         result.putAll(System.getenv());
//         result.putAll(convertPropertiesToMap(System.getProperties()));
//         return result;
//     }
// 
//     public static Map<String, String> convertPropertiesToMap(final Properties properties) {
//         final Map<String, String> result = new HashMap<>();
//         for (final String name : properties.stringPropertyNames()) {
//             result.put(name, properties.getProperty(name));
//         }
//         return result;
//     }
// 
//     public static String injectProperties(final String text) {
//         if (text != null && text.contains(VAR_PREFIX)) {
//             String result = text;
//             final Map<String, String> systemProperties = getSystemProperties();
//             for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
//                 final String key = entry.getKey();
//                 final String value = entry.getValue();
//                 result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value);
//             }
//             return result;
//         }
//         return text;
//     }
// 
//     public static boolean hasAnyWithProperties(final String value, final String... variants) {
//         for (final String operationSystem : variants) {
//             final String injected = injectProperties(operationSystem);
//             if (TextUtils.containsIgnoreCase(value, injected)) {
//                 return true;
//             }
//         }
//         return false;
//     }
// 
// }


// Path: src/main/java/com/github/vbauer/jconditions/checker/SocketIsOpenedChecker.java
import com.github.vbauer.jconditions.annotation.SocketIsOpened;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.util.InOutUtils;
import com.github.vbauer.jconditions.util.PropUtils;
import java.net.InetSocketAddress;
import java.net.Socket;

package com.github.vbauer.jconditions.checker;



/**
 * @author Vladislav Bauer
 */

public class SocketIsOpenedChecker implements ConditionChecker<SocketIsOpened> {

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean isSatisfied(final CheckerContext<SocketIsOpened> context) throws Exception {
        final SocketIsOpened annotation = context.getAnnotation();
        final String host = PropUtils.injectProperties(annotation.host());
        final int port = annotation.port();
        final int timeout = annotation.timeout();
        return isSocketOpened(host, port, timeout);
    }


    private boolean isSocketOpened(final String host, final int port, final int timeout) throws Exception {
        Socket socket = null;
        try {
            socket = new Socket();
            socket.bind(null);
            socket.connect(new InetSocketAddress(host, port), timeout);
            return true;
        } finally {
            InOutUtils.closeQuietly(socket);