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:net.nicoll.boot.daemon.SpringBootService.java

public void start(String[] args) throws Exception {
    if (args.length == 0) {
        throw new IllegalStateException("Spring Boot application class must be provided.");
    }//from ww  w . j  a  va  2 s . com
    Class<?> springBootApp = ClassUtils.resolveClassName(args[0], SpringBootService.class.getClassLoader());
    System.out.println("Starting Spring Boot application [" + springBootApp.getName() + "]");
    SpringApplication.run(springBootApp);
}

From source file:io.druid.query.aggregation.datasketches.theta.SketchOperations.java

public static Sketch deserialize(Object serializedSketch) {
    if (serializedSketch instanceof String) {
        return deserializeFromBase64EncodedString((String) serializedSketch);
    } else if (serializedSketch instanceof byte[]) {
        return deserializeFromByteArray((byte[]) serializedSketch);
    } else if (serializedSketch instanceof Sketch) {
        return (Sketch) serializedSketch;
    }//  w  ww  .  ja v a 2 s. c  om

    throw new IllegalStateException(
            "Object is not of a type that can deserialize to sketch: " + serializedSketch.getClass());
}

From source file:com.sap.prd.mobile.ios.mios.SCMUtil.java

public static String getConnectionString(final Properties versionInfo,
        final boolean hideConfidentialInformation) throws IOException {

    final String type = versionInfo.getProperty("type");

    final StringBuilder connectionString = new StringBuilder(128);

    if (type != null && type.equals("git")) {

        final String repo = versionInfo.getProperty("repo");

        if (StringUtils.isBlank(repo)) {
            if (!StringUtils.isBlank(versionInfo.getProperty("repo_1"))) {
                throw new IllegalStateException(
                        "Multipe git repositories provided. This use case is not supported. Provide only one git repository.");
            }/*from www  . jav a 2  s  . c om*/
            throw new IllegalStateException("No git repository provided. ");
        }

        if (hideConfidentialInformation) {
            try {
                URI uri = new URI(repo);
                int port = uri.getPort();
                if (port == -1) {
                    final String scheme = uri.getScheme();
                    if (scheme != null && gitDefaultPorts.containsKey(scheme)) {
                        port = gitDefaultPorts.get(scheme);
                    }
                }
                connectionString.append(port);

                if (uri.getHost() != null) {
                    connectionString.append(uri.getPath());
                }
            } catch (URISyntaxException e) {
                throw new IllegalStateException(String.format("Invalid repository uri: %s", repo));
            }
        } else {
            connectionString.append(PROTOCOL_PREFIX_GIT).append(repo);
        }

    } else {

        final String port = versionInfo.getProperty("port");

        if (StringUtils.isBlank(port))
            throw new IllegalStateException("No SCM port provided.");

        final String depotPath = versionInfo.getProperty("depotpath");

        if (hideConfidentialInformation) {
            try {
                URI perforceUri = new URI("perforce://" + port);

                int _port = perforceUri.getPort();
                if (_port == -1) {
                    _port = PERFORCE_DEFAULT_PORT;
                }
                connectionString.append(_port);
                connectionString.append(depotPath);
            } catch (URISyntaxException e) {
                throw new IllegalStateException(String.format("Invalid port: %s", port));
            }
        } else {

            if (StringUtils.isBlank(depotPath))
                throw new IllegalStateException("No depot path provided.");

            connectionString.append(PROTOCOL_PREFIX_PERFORCE).append(port).append(":")
                    .append(getDepotPath(depotPath));
        }
    }

    return connectionString.toString();
}

From source file:com.mongodb.hadoop.MongoInputFormat.java

@Override
public RecordReader<Object, BSONObject> createRecordReader(InputSplit split, TaskAttemptContext context) {
    if (!(split instanceof MongoInputSplit))
        throw new IllegalStateException("Creation of a new RecordReader requires a MongoInputSplit instance.");

    final MongoInputSplit mis = (MongoInputSplit) split;

    return new com.mongodb.hadoop.input.MongoRecordReader(mis);
}

From source file:net.antidot.semantic.rdf.rdb2rdf.commons.DateConverter.java

/**
 * Convert a SQL timestamp in a date format in a conform string date.
 * //  w  w w.j a  v  a  2s  .c  o  m
 * @param mySQLType
 * @param timestamp
 * @param timeZone
 */
public static String dateFormatToDate(SQLType sqlType, Long timestamp, String timeZone) {
    if (log.isDebugEnabled())
        log.debug("[DateConverter:dateFormatToDate] mySQLType : " + sqlType + " timestamp : " + timestamp);
    // Constructs a Date object using the given milliseconds time value.
    // But, timestamp in MySQL is given in seconds.
    timestamp *= 1000;
    if (!sqlType.isDateType())
        throw new IllegalStateException(
                "[DateConverter:dateFormatToDate] MySQLType forbidden : it must be in a date format.");
    Date date = timestampToDate(timestamp);
    switch (sqlType) {
    case TIME:
        return XSDDataConverter.dateToXSDTime(date, timeZone);

    case DATE:
        return XSDDataConverter.dateToXSDDate(date, timeZone);

    case TIMESTAMP:
        return XSDDataConverter.dateToISO8601(date, timeZone);

    default:
        throw new IllegalStateException("[DateConverter:dateFormatToDate] Unknown format date.");
    }
}

From source file:it.geosolutions.geoserver.jms.server.JMSAbstractProducer.java

/**
 * @return the jmsTemplate/*from w w  w .  j  a  v a  2s  .  c  om*/
 */
public final JmsTemplate getJmsTemplate() {
    final ConnectionFactory cf = jmsFactory.getConnectionFactory(config.getConfigurations());
    if (cf == null) {
        throw new IllegalStateException("Unable to load a connectionFactory");
    }
    return new JmsTemplate(cf);
}

From source file:com.addthis.hydra.job.alert.SuppressChanges.java

public boolean suppress(@Nonnull String oldMessage, @Nonnull String newMessage) {
    switch (this) {
    case TRUE://from  w  w w  . ja  v  a  2  s  .  c o  m
        return true;
    case FALSE:
        return false;
    case NEWLINE: {
        int oldLines = StringUtils.countMatches(oldMessage, "\n");
        int newLines = StringUtils.countMatches(newMessage, "\n");
        return (oldLines == newLines);
    }
    default:
        throw new IllegalStateException("unknown value " + this);
    }
}

From source file:com.sun.socialsite.business.startup.Startup.java

/**
 * Get a reference to the currently configured DatabaseProvider.
 *
 * @return DatabaseProvider The configured database provider.
 * @throws IllegalStateException If the app has not been properly prepared yet.
 *//*  www .ja  va 2 s  .  co m*/
public static DatabaseProvider getDatabaseProvider() {
    if (dbProvider == null) {
        throw new IllegalStateException("SocialSite has not been prepared yet");
    }
    return dbProvider;
}

From source file:io.sidecar.security.SecurityUtils.java

/**
 * Generates a String representation of an MD5 Checksum from a given String input.
 *
 * @param input - A non-null String./*w ww  .j ava  2  s .c o  m*/
 * @return an MD5 checksum as a Hex encoded String.
 */
public static String md5(String input) {
    checkNotNull(input);
    try {
        //Create MessageDigest object for MD5
        MessageDigest digest = MessageDigest.getInstance(MD5_ALGORITHM);

        //Update input string in message digest
        digest.update(input.getBytes(), 0, input.length());

        //Converts message digest value in base 16 (hex)
        return String.copyValueOf(Hex.encodeHex(digest.digest()));
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalStateException(e);
    }
}

From source file:com.grabtaxi.themoviedb.MyVolley.java

public static AbstractHttpClient getHttpClient() {
    if (mHttpClient != null) {
        return mHttpClient;
    } else {/*  w  ww.j a va 2  s  .  co m*/
        throw new IllegalStateException("HttpClient not initialized");
    }
}