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:JvmVersionUtil.java

/**
 * Gets the version of the JVM./*ww w  .  ja  va 2 s . c o  m*/
 * 
 * @return The integer that corresponds with the version of the JVM. This
 *         can be VERSION_3_OR_LESS,VERSION_4_or_5, VERSION_6_OR_MORE.
 * @throws IllegalStateException
 *             If the system property <code>java.version</code> does not
 *             start with a x.x. x should be a number.
 */
public static int getVersion() {

    // Get the system property java.vm.version.
    String jVersion = System.getProperty("java.version");

    // Get the version number.
    int pointPosition = jVersion.indexOf(".");
    if (pointPosition > 0) {
        if (jVersion.length() >= pointPosition + 2) {
            String version = jVersion.substring(0, pointPosition + 2);

            try {
                float versionNumber = Float.parseFloat(version);
                if (versionNumber < VERSION_4) {
                    return VERSION_3_OR_LESS;
                }
                if (versionNumber < VERSION_6) {
                    return VERSION_4_or_5;
                } else {
                    return VERSION_6_OR_MORE;
                }
            } catch (NumberFormatException exception) {
                throw new IllegalStateException("Unknown java version [" + jVersion + "].");
            }
        }
    }

    throw new IllegalStateException("Unknown java version [" + jVersion + "].");

}

From source file:com.adito.tunnels.TunnelDatabaseFactory.java

/**
 * @param tunnelDatabaseImpl the class of the system database
 * @param lock weather to lock the policy database after setting it.
 * @throws IllegalStateException/*from  ww w. j  ava2  s . c  om*/
 */
public static void setFactoryImpl(Class<TunnelDatabase> tunnelDatabaseImpl, boolean lock)
        throws IllegalStateException {
    if (locked) {
        throw new IllegalStateException("System database factory has been locked by another plugin.");
    }
    TunnelDatabaseFactory.tunnelDatabaseImpl = tunnelDatabaseImpl;
    locked = lock;
}

From source file:com.dsh105.commodus.Affirm.java

public static void checkInstanceOf(Class<?> type, Object instance, boolean allowNull) {
    Affirm.notNull(type);/*from w w  w .  j  ava2 s  . c  o  m*/
    if (!allowNull) {
        Affirm.notNull(instance);
    }
    if (!type.isAssignableFrom(instance.getClass())) {
        throwException(new IllegalStateException(
                instance.getClass().getCanonicalName() + " must be a subclass of " + type.getCanonicalName()));
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase.java

protected String getDefaultNamespace(ServletContext ctx) {
    String dns = ConfigurationProperties.getBean(ctx).getProperty(VITRO_DEFAULT_NAMESPACE);
    if ((dns != null) && (!dns.isEmpty())) {
        return dns;
    } else {/*  w  ww.  j  ava 2  s  .c  o  m*/
        throw new IllegalStateException(
                "runtime.properties does not " + "contain a value for '" + VITRO_DEFAULT_NAMESPACE + "'");
    }
}

From source file:Main.java

public static void writeSettings(String file, Object... objs) throws IOException {
    DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file), 1024));
    try {/*  w  w  w .j a  v a 2  s . co  m*/
        out.writeInt(objs.length);
        for (Object obj : objs) {
            char cl;
            if (obj instanceof Byte) {
                cl = 'Y';
            } else {
                cl = obj.getClass().getSimpleName().charAt(0);
            }

            out.writeChar(cl);
            if (obj instanceof String) {
                out.writeUTF((String) obj);
            } else if (obj instanceof Float) {
                out.writeFloat((Float) obj);
            } else if (obj instanceof Double) {
                out.writeDouble((Double) obj);
            } else if (obj instanceof Integer) {
                out.writeInt((Integer) obj);
            } else if (obj instanceof Long) {
                out.writeLong((Long) obj);
            } else if (obj instanceof Boolean) {
                out.writeBoolean((Boolean) obj);
            } else {
                throw new IllegalStateException("Unsupported type");
            }
        }
    } finally {
        out.close();
    }
}

From source file:com.anhth12.lambda.common.text.TextUtils.java

private static String[] doParseDelimited(String delimited, CSVFormat format) {
    Iterator<CSVRecord> records;
    try {/*from   w  ww . ja v  a2 s.c o  m*/
        records = CSVParser.parse(delimited, format).iterator();
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }

    if (records.hasNext()) {
        return Iterators.toArray(records.next().iterator(), String.class);
    } else {
        return EMPTY_STRING;
    }
}

From source file:com.qcadoo.mes.costNormsForMaterials.constants.ProductsCostFields.java

public static ProductsCostFields forMode(final String mode) {
    for (ProductsCostFields productsCostFields : values()) {
        if (StringUtils.equalsIgnoreCase(mode, productsCostFields.getMode())) {
            return productsCostFields;
        }//from www. j a  v a 2s  .c o  m
    }
    throw new IllegalStateException("Unsupported calculateMaterialCostsMode: " + mode);
}

From source file:com.jaxio.celerio.aspects.ForbiddenWhenBuildingAspect.java

public void checkNotForbidden() {
    if (isBuilding) {
        IllegalStateException ise = new IllegalStateException(
                "Called a " + ForbiddenWhenBuilding.class.getSimpleName() + " method while building");
        ise.printStackTrace();//from www  .  java  2  s.c o m
        throw ise;
    }
}

From source file:hivemall.math.random.RandomNumberGeneratorFactory.java

@Nonnull
public static PRNG createPRNG(@Nonnull PRNGType type) {
    final PRNG rng;
    switch (type) {
    case java:/*ww w  .j  ava 2s  .  c o m*/
        rng = new JavaRandom();
        break;
    case secure:
        rng = new JavaRandom(new SecureRandom());
        break;
    case smile:
        rng = new SmileRandom();
        break;
    case smileMT:
        rng = new SmileRandom(new smile.math.random.MersenneTwister());
        break;
    case smileMT64:
        rng = new SmileRandom(new smile.math.random.MersenneTwister64());
        break;
    case commonsMath3MT:
        rng = new CommonsMathRandom(new org.apache.commons.math3.random.MersenneTwister());
        break;
    default:
        throw new IllegalStateException("Unexpected type: " + type);
    }
    return rng;
}

From source file:de.kaiserpfalzEdv.iam.role.PermissionQueryBuilder.java

@Override
public PermissionQuery build() {
    if (query.isValid())
        return query;

    throw new IllegalStateException("The permission object can not be built!");
}