Java Thread Callable resolveCompositeKey(final String key, final Map props)

Here you can find the source of resolveCompositeKey(final String key, final Map props)

Description

resolve Composite Key

License

Apache License

Declaration

private static String resolveCompositeKey(final String key, final Map<String, Object> props) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Map;
import java.util.Properties;

import java.util.concurrent.Callable;

public class Main {
    private static String resolveCompositeKey(final String key, final Properties props) {
        String value = null;// w w  w. ja  v a  2  s .c om

        // Look for the comma
        final int comma = key.indexOf(',');
        if (comma > -1) {
            // If we have a first part, try resolve it
            if (comma > 0) {
                // Check the first part
                final String key1 = key.substring(0, comma);
                if (props != null) {
                    value = props.getProperty(key1);
                } else {
                    value = System.getProperty(key1);
                }
            }
            // Check the second part, if there is one and first lookup failed
            if (value == null && comma < key.length() - 1) {
                final String key2 = key.substring(comma + 1);
                if (props != null) {
                    value = props.getProperty(key2);
                } else {
                    value = System.getProperty(key2);
                }
            }
        }
        // Return whatever we've found or null
        return value;
    }

    private static String resolveCompositeKey(final String key, final Map<String, Object> props) {
        String value = null;

        // Look for the comma
        final int comma = key.indexOf(',');
        if (comma > -1) {
            // If we have a first part, try resolve it
            if (comma > 0) {
                // Check the first part
                final String key1 = key.substring(0, comma);
                if (props != null) {
                    Object o = props.get(key1);
                    if (o instanceof Callable) {
                        try {
                            o = ((Callable) o).call();
                        } catch (final Exception e) {
                            ;
                        }
                    }
                    if (o != null) {
                        value = String.valueOf(o);
                    }
                } else {
                    value = System.getProperty(key1);
                }
            }
            // Check the second part, if there is one and first lookup failed
            if (value == null && comma < key.length() - 1) {
                final String key2 = key.substring(comma + 1);
                if (props != null) {
                    Object o = props.get(key2);
                    if (o instanceof Callable) {
                        try {
                            o = ((Callable) o).call();
                        } catch (final Exception e) {
                            ;
                        }
                    }
                    if (o != null) {
                        value = String.valueOf(o);
                    }
                } else {
                    value = System.getProperty(key2);
                }
            }
        }
        // Return whatever we've found or null
        return value;
    }
}

Related

  1. invokeBulkActions(Collection> tasks)
  2. max(final double[] a, final double[] b)
  3. minScalar(final double[] a, final double scalar)
  4. powerTo(final double base, final double[] exponents)
  5. repeatedlyTry(Callable task, int maxRounds, long backoff)
  6. resolveSingle(Object object)
  7. runAndRethrowRuntimeExceptionOnFailure(final Callable operation, final String exceptionMessage)
  8. runConcurrently(final Callable task)
  9. runConcurrently(final Callable task)