Example usage for java.lang IllegalStateException IllegalStateException

List of usage examples for java.lang IllegalStateException IllegalStateException

Introduction

In this page you can find the example usage for java.lang IllegalStateException IllegalStateException.

Prototype

public IllegalStateException(Throwable cause) 

Source Link

Document

Constructs a new exception with the specified cause and a detail message of (cause==null ?

Usage

From source file:com.hyunnyapp.easycursor.sqlcursor.querymodels.SqlJsonModelConverter.java

public static SqlQueryModel convert(final String json) throws JSONException {
    final JSONObject payload = new JSONObject(json);

    final int modelType = payload.optInt(SqlQueryModel.FIELD_QUERY_TYPE,
            SqlQueryModel.QUERY_TYPE_UNINITIALISED);
    switch (modelType) {
    case SqlQueryModel.QUERY_TYPE_MANAGED:
        return new SelectQueryModel(new JsonWrapper(payload));
    case SqlQueryModel.QUERY_TYPE_RAW:
        return new RawQueryModel(new JsonWrapper(payload));
    default:/*from w  w  w  .  j av  a 2  s.  c  o m*/
        throw new IllegalStateException(
                "JSON cannot be converted to a valid " + SqlQueryModel.class.getSimpleName());
    }
}

From source file:Main.java

public static Point findBestPreviewSizeValue(Camera.Parameters parameters, Point screenResolution) {

    List<Camera.Size> rawSupportedSizes = parameters.getSupportedPreviewSizes();
    if (rawSupportedSizes == null) {
        //            Log.w(TAG, "Device returned no supported preview sizes; using default");
        Camera.Size defaultSize = parameters.getPreviewSize();
        if (defaultSize == null) {
            throw new IllegalStateException("Parameters contained no preview size!");
        }//w ww  .  j a  va 2 s  .c o m
        return new Point(defaultSize.width, defaultSize.height);
    }

    // Sort by size, descending
    List<Camera.Size> supportedPreviewSizes = new ArrayList<>(rawSupportedSizes);
    Collections.sort(supportedPreviewSizes, new Comparator<Camera.Size>() {
        @Override
        public int compare(Camera.Size a, Camera.Size b) {
            int aPixels = a.height * a.width;
            int bPixels = b.height * b.width;
            if (bPixels < aPixels) {
                return -1;
            }
            if (bPixels > aPixels) {
                return 1;
            }
            return 0;
        }
    });

    //        if (Log.isLoggable(TAG, Log.INFO)) {
    //            StringBuilder previewSizesString = new StringBuilder();
    //            for (Camera.Size supportedPreviewSize : supportedPreviewSizes) {
    //                previewSizesString.append(supportedPreviewSize.width).append('x')
    //                        .append(supportedPreviewSize.height).append(' ');
    //            }
    //            Log.i(TAG, "Supported preview sizes: " + previewSizesString);
    //        }

    double screenAspectRatio = (double) screenResolution.x / (double) screenResolution.y;

    // Remove sizes that are unsuitable
    Iterator<Camera.Size> it = supportedPreviewSizes.iterator();
    while (it.hasNext()) {
        Camera.Size supportedPreviewSize = it.next();
        int realWidth = supportedPreviewSize.width;
        int realHeight = supportedPreviewSize.height;
        if (realWidth * realHeight < MIN_PREVIEW_PIXELS) {
            it.remove();
            continue;
        }

        boolean isCandidatePortrait = realWidth < realHeight;
        int maybeFlippedWidth = isCandidatePortrait ? realHeight : realWidth;
        int maybeFlippedHeight = isCandidatePortrait ? realWidth : realHeight;
        double aspectRatio = (double) maybeFlippedWidth / (double) maybeFlippedHeight;
        double distortion = Math.abs(aspectRatio - screenAspectRatio);
        if (distortion > MAX_ASPECT_DISTORTION) {
            it.remove();
            continue;
        }

        if (maybeFlippedWidth == screenResolution.x && maybeFlippedHeight == screenResolution.y) {
            Point exactPoint = new Point(realWidth, realHeight);
            //                Log.i(TAG, "Found preview size exactly matching screen size: " + exactPoint);
            return exactPoint;
        }
    }

    // If no exact match, use largest preview size. This was not a great idea on older devices because
    // of the additional computation needed. We're likely to get here on newer Android 4+ devices, where
    // the CPU is much more powerful.
    if (!supportedPreviewSizes.isEmpty()) {
        Camera.Size largestPreview = supportedPreviewSizes.get(0);
        Point largestSize = new Point(largestPreview.width, largestPreview.height);
        //            Log.i(TAG, "Using largest suitable preview size: " + largestSize);
        return largestSize;
    }

    // If there is nothing at all suitable, return current preview size
    Camera.Size defaultPreview = parameters.getPreviewSize();
    if (defaultPreview == null) {
        throw new IllegalStateException("Parameters contained no preview size!");
    }
    Point defaultSize = new Point(defaultPreview.width, defaultPreview.height);
    //        Log.i(TAG, "No suitable preview sizes, using default: " + defaultSize);
    return defaultSize;
}

From source file:com.github.dozermapper.core.classmap.MappingDirection.java

public static MappingDirection valueOf(String mappingDirection) {
    if (BI_DIRECTIONAL_VALUE.equals(mappingDirection)) {
        return BI_DIRECTIONAL;
    } else if (ONE_WAY_VALUE.equals(mappingDirection)) {
        return ONE_WAY;
    } else if (StringUtils.isEmpty(mappingDirection)) {
        return null;
    }//  w w w  . j a v a 2  s.c  o  m

    throw new IllegalStateException("type should be bi-directional or one-way. " + mappingDirection);
}

From source file:Main.java

private static DocumentBuilder createDocumentBuilder() {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try {/*from w w w . ja va2s .  c o  m*/
        dbf.setNamespaceAware(false);
        return dbf.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new IllegalStateException(e);
    }
}

From source file:org.zalando.stups.tokens.FileSupplier.java

private static File getCredentialsDir() {
    String dir = System.getenv("CREDENTIALS_DIR");
    if (dir == null) {

        // this for testing
        dir = System.getProperty("CREDENTIALS_DIR");
        if (dir == null) {
            throw new IllegalStateException("environment variable CREDENTIALS_DIR not set");
        }//w  ww.j  a  v  a  2 s.c  om
    }

    return new File(dir);
}

From source file:com.soolr.core.utils.SpringContextHolder.java

private static void checkApplicationContext() {
    if (applicationContext == null) {
        throw new IllegalStateException(
                "applicaitonContext,applicationContext.xmlSpringContextUtil");
    }//from w  w w . j av a  2s  . c o m
}

From source file:jp.eisbahn.oauth2.server.utils.Util.java

/**
 * Decode the URL encoded string./*  w ww  . ja  v  a2s . c o  m*/
 * @param source The URL encoded string.
 * @return The decoded original string.
 */
public static String decodeParam(String source) {
    try {
        return URLDecoder.decode(source, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException(e);
    }
}

From source file:de.xaniox.heavyspleef.core.i18n.I18NManager.java

/**
 * Returns the global I18N instance used for
 * retrieving internal messages of HeavySpleef
 * /*  w  w w.  j  a v  a  2 s .  c  o  m*/
 * @return The global instance of I18N
 */
public static I18N getGlobal() {
    synchronized (initLock) {
        if (global == null) {
            if (globalBuilder == null) {
                throw new IllegalStateException("No global builder has been set for initializing");
            }

            global = globalBuilder.build();
        }
    }

    return global;
}

From source file:ly.stealth.punxsutawney.Marathon.java

public static void startApp(App app) throws IOException, InterruptedException {
    sendRequest("/v2/apps", "POST", app.toJson());

    for (;;) {/*from   www .  j a  v  a 2s.  com*/
        @SuppressWarnings("unchecked")
        List<JSONObject> tasks = getTasks(app.id);
        if (tasks == null)
            throw new IllegalStateException("App " + app.id + " not found");

        int started = 0;
        for (JSONObject task : tasks)
            if (task.get("startedAt") != null)
                started++;

        if (started == app.instances)
            break;
        Thread.sleep(1000);
    }
}

From source file:ThreadPool.java

synchronized public void start() {
    if (!closed) {
        throw new IllegalStateException("Pool already started.");
    }//from w w  w  . ja  v  a 2s.c  om
    closed = false;
    for (int i = 0; i < poolSize; ++i) {
        new PooledThread().start();
    }
}