Example usage for java.util MissingFormatArgumentException MissingFormatArgumentException

List of usage examples for java.util MissingFormatArgumentException MissingFormatArgumentException

Introduction

In this page you can find the example usage for java.util MissingFormatArgumentException MissingFormatArgumentException.

Prototype

public MissingFormatArgumentException(String s) 

Source Link

Document

Constructs an instance of this class with the unmatched format specifier.

Usage

From source file:com.googlecode.hive.serde.FixedLengthAndDelimitedSerde.java

protected Map<Integer, String> getColumnValues(String inputRecordString) {
    String[] columnFormats = inputFormatString.split(inputFormatColumnSeperator);
    if (columnFormats.length != numColumns) {
        throw new MissingFormatArgumentException("Mismatch columnFormats.length : " + columnFormats.length
                + " between numColumns : " + numColumns);
    }//from   w w  w .j a v  a2s  . c  o m

    int index = 0;
    int cIndex = 0;
    Integer totalRowLenght = inputRecordString.length();
    Map<Integer, String> columnValues = new HashMap<Integer, String>();
    try {
        for (String columnFormat : columnFormats) {
            String columnSerdeType = columnFormat.substring(0, 2);
            String columnValue = null;
            if (columnSerdeType.equalsIgnoreCase("FL")) {
                Integer length = Integer.parseInt(columnFormat.substring(2));
                Integer columnLastIndexValue = cIndex + length;
                if (columnLastIndexValue <= totalRowLenght) {
                    columnValue = inputRecordString.substring(cIndex, columnLastIndexValue);
                } else {
                    fillWithNull(columnValues, index);
                    return columnValues;
                }
                cIndex += length;
            } else if (columnSerdeType.equalsIgnoreCase("DM")) {
                String delimit = columnFormat.substring(2);
                if (delimit.equalsIgnoreCase("\n")) {
                    columnValue = inputRecordString.substring(cIndex);
                    columnValues.put(index, handleNullFormat(columnValue));
                    return columnValues;
                } else {
                    int indexOf = inputRecordString.substring(cIndex).indexOf(delimit);
                    if (indexOf != -1) {
                        columnValue = inputRecordString.substring(cIndex, indexOf + cIndex);
                        cIndex = indexOf + cIndex + delimit.length();
                    } else {
                        fillWithNull(columnValues, index);
                        return columnValues;
                    }
                }
            } else {
                throw new MissingFormatArgumentException(
                        "Invalid " + INPUT_FORMAT_STRING + " : " + inputFormatString);
            }
            columnValues.put(index, handleNullFormat(columnValue));
            index++;
        }
    } catch (Exception e) {
        LOG.error("error processing row [" + inputRecordString + "]", e);
    }
    return columnValues;
}

From source file:com.googlecode.hive.serde.FixedLengthAndDelimitedSerde.java

protected String getRowString(Object[] outputFields) {

    StringBuilder rowString = new StringBuilder();

    String[] columnFormats = inputFormatString.split(inputFormatColumnSeperator);
    int index = 0;
    for (String columnFormat : columnFormats) {
        String columnSerdeType = columnFormat.substring(0, 2);
        String columnValue = null;
        if (columnSerdeType.equalsIgnoreCase("FL")) {
            Integer length = Integer.parseInt(columnFormat.substring(2));
            columnValue = String.format("%1$" + length + "s", outputFields[index]);
        } else if (columnSerdeType.equalsIgnoreCase("DM")) {
            String delimit = columnFormat.substring(2);
            columnValue = outputFields[index] + delimit;
        } else {/*from  ww w . j av a  2 s. c o  m*/
            throw new MissingFormatArgumentException(
                    "Invalid \"" + INPUT_FORMAT_STRING + "\" : " + inputFormatString);
        }
        rowString.append(columnValue);
        index++;
    }

    return rowString.toString();
}

From source file:com.radthorne.fancychat.JChat.java

/**
 * tooltipsWithValues extended method to create a tooltip which allows color codes and substitute values to be passed.
 * <p>Color codes or styles many be passed in here using the '&amp;' followed by a valid format code. They can be added in any order you like.
 * </p>/*from   w ww.  j  a  va 2s  . co  m*/
 * <p>The message can contain as many place holders as you like place holders in the messages must be '%s' and you must
 * are required to have the same number of values to match the number of placeholders. Failure to do so will and it will
 * throw an MissingFormatArgumentException
 * </p>
 * <p>Values should be passed as the 2nd argument as a list of strings. The order you add them will be the order they are used to replace
 * placeholders.
 * </p>
 * <p>Like standard tooltips the onHover event will be applied to the text part that immediately proceeds it. While this function allow you
 * to input an entire line of text and styles all at once, it is still splitting them up to message parts, this is not a design fault, it is
 * the way the JSON message format requires.
 * </p>
 * <p>If you do not need to use placeholders then do not use this method use the standard tooltips. Failure to do this will
 * cause MissingFormatArgumentException to be thrown as the method is expecting it. See below for an example usage of this method.
 * </p>
 * <p>
 * <strong>player</strong> is an instance of {@link Player}. You are not required to use a player object to send the message,
 * you can use the players name, the players UUID or if left blank it will send to all players. Please note you will need to roughly follow the
 * example below, especially on the instance creation do not pass in any arguments. As mentioned above the following onHover event is applied to
 * the last text part. In this case the "server" word. if you wish to have the effect applied to a different part of the message you will need to
 * split up the .tooltipsWithValues the second example demonstrates this. This will add the effect to the first .then chat part.</p>
 * <pre>
 * {@code
 *     JChat jChat = new JChat();
 *     jChat.then("&a&oHi %s hope you like the &6&o%s &a&oserver", player.getName(), "Factions")
 *     .tooltipsWithValues("&aHi %s hope you like &b%s server", player.getName(), "Factions"))
 *     .send(player);
 *     }
 * </pre>
 * <pre>
 * {@code
 *     JChat jChat = new JChat();
 *     jChat.then("&a&oHi %s hope you like the ", player.getName())
 *     .tooltipsWithValues("&aHi %s hope you like &b%s server", player.getName(), "Factions"))
 *     .then("&6&o%s &a&oserver","Factions")
 *     .send(player);
 *     }
 * </pre>
 * <p>
 * <tt>NOTE CURRENTLY ONLY SINGLE LINE TOOLTIPSWITHVALUES IN THIS FORMAT ARE SUPPORTED AT THIS TIME, MULTI LINE WILL BE ADDED SOON</tt>
 * </p>
 * <p>Currently it has a limitation of only being able to pass 2 ChatColor objects in a row. They can be one color and style OR 2 styles OR just one of either.
 * this would be valid in the message part. "&amp;a&amp;oHello" This would display green and italic text. This is what I mean when you can only pass to ChatColor objects
 * in a row. This is invalid <strong>"&amp;a&amp;o&amp;lHello"</strong> The total message can have as many Chatcolors as you like provided they are not added more than 2 in a row.
 * I will soon be changing this to remove this limitation but it was hard enough with just the 2 options, allowing the developer complete freedom to the order they are
 * added. These to are equal <strong>"&amp;a&amp;oHello"</strong> OR <strong>"&amp;o&amp;aHello"</strong> both result in identical formatting without the developer indicating in any way
 * what order they are adding them.
 * </p>
 *
 * @param text the text that will be used for the tooltip message. Placeholders MUST be <strong>%s</strong>
 * @param subs the subs the values that are used to replace placeholders in the message. You must pass the exact number of values as you have placeholders.
 * @return the {@link JChat} instance of itself to allow chaining of methods
 * @throws MissingFormatArgumentException the missing format argument exception
 */
public JChat tooltipsWithValues(String text, String... subs) throws MissingFormatArgumentException {
    Validate.notNull(text, "The message can not be null");
    Matcher matcher = _pattern.matcher(text);
    int count = 0;
    while (matcher.find()) {
        count++;
    }

    if (count == 0 || count != subs.length) {
        throw new MissingFormatArgumentException(
                "Error: The number of values do not match the number of placeholders");
    }

    onHover("show_text", ChatColor.translateAlternateColorCodes('&', String.format(text, subs)));
    return this;
}

From source file:com.radthorne.fancychat.JChat.java

/**
 * Tooltip displayed with the onHover event, allowing color and style codes and placeholders to be used.
 * <p>For full usage instructions see {@link JChat#tooltipsWithValues(String, String...)} as the functionality
 * is almost identical. Except this is for adding the message text body not a tooltip !
 *
 * @param message the text that will be used for the tooltip message. Placeholders MUST be <strong>%s</strong>
 * @param subs    the subs the values that are used to replace placeholders in the message. You must pass the exact number of values as you have placeholders.
 * @return the {@link JChat} instance of itself to allow chaining of methods
 * @throws IllegalArgumentException the illegal argument exception
 *//*  w  w w. j a v a 2s  .  c o m*/
public JChat then(String message, String... subs) throws IllegalArgumentException {
    Validate.notNull(message, "The message can not be null");
    Matcher matcher = _pattern.matcher(message);
    int count = 0;
    while (matcher.find()) {
        count++;
    }

    if (count == 0 || count != subs.length) {
        throw new MissingFormatArgumentException(
                "Error: The number of values do not match the number of placeholders");
    }

    message = String.format(message, subs);
    //  System.out.println("Message length is currently " + message.length());
    //  System.out.println(message);
    splitPartsOnColor(message);

    return this;
}

From source file:com.ibm.watson.developer_cloud.concept_insights.v2.ConceptInsights.java

/**
 * Searches for graph concepts by using partial matches.
 *
 * @param parameters The parameters to be used in the service call, account_id,
 * graph are required./*from w  w w .j a v a2 s  .com*/
 * <ul>
 * <li> String account_id - The account identifier.<br>
 * <li> String graph - The graph name.<br>
 * <li> List&lt;String&gt; concepts - Array of concept IDs, each identifying a concept.<br>
 * <li> String concept - the concept name.<br>
 * <li> Integer level - A number in the range 0 - 3 that represents the level of popularity of related concepts.<br>
 * <li> Integer limit - The maximum number of concepts to be returned.<br>
 * </ul>
 * @return {@link Concepts}
 */
public Concepts getGraphsRelatedConcepts(Map<String, Object> parameters) {
    //TODO: we may need to divide this into 2 methods
    Validate.notNull(parameters.get(ACCOUNT_ID), "account_id can't be null");
    Validate.notNull(parameters.get(GRAPH), "graph can't be null");
    if (parameters.get(CONCEPTS) == null && parameters.get(CONCEPT) == null)
        throw new MissingFormatArgumentException("concept or concepts should be identified");

    String graphId = createGraphIdPath((String) parameters.get(ACCOUNT_ID), (String) parameters.get(GRAPH));
    Map<String, Object> queryParameters = new HashMap<String, Object>();
    String[] queryParms = new String[] { LEVEL, LIMIT };
    for (String param : queryParms) {
        if (parameters.containsKey(param))
            queryParameters.put(param, parameters.get(param));
    }
    if (parameters.get(CONCEPT_FIELDS) != null) {
        RequestedFields fields = (RequestedFields) parameters.get(CONCEPT_FIELDS);
        if (fields != null && fields.getFields() != null && !fields.getFields().isEmpty())
            queryParameters.put(CONCEPT_FIELDS, fields.toString());
    }
    if (parameters.get(CONCEPTS) != null) {
        JsonObject contentJson = new JsonObject();
        JsonArray conceptsJson = new JsonArray();
        @SuppressWarnings("unchecked")
        List<String> concepts = (List<String>) parameters.get(CONCEPTS);
        for (String value : concepts) {
            conceptsJson.add(new JsonPrimitive(value));
        }
        contentJson.add(CONCEPTS, conceptsJson);
        queryParameters.put(CONCEPTS, conceptsJson.toString());
        return executeRequest(graphId + RELATED_CONCEPTS_PATH, queryParameters, Concepts.class);
    } else {
        String conceptId = createConceptIdPath((String) parameters.get(ACCOUNT_ID),
                (String) parameters.get(GRAPH), (String) parameters.get(CONCEPT));
        return executeRequest(conceptId + RELATED_CONCEPTS_PATH, queryParameters, Concepts.class);
    }
}

From source file:org.codemine.jchatter.JChat.java

/**
 * Text that forms part of the message, allowing color and style codes and placeholders to be used.
 * <p>For full usage instructions see {@link org.codemine.jchatter.JChat#tooltipsWithValues(String, String...)} as the functionality
 * is almost identical. Except this is for adding the message text body not a tooltip !
 *
 * @param message the text that will be used for the text message. Placeholders MUST be <strong>%s</strong>
 * @param subs    the subs the values that are used to replace placeholders in the message. You must pass the exact number of values as you have placeholders.
 * @return the {@link org.codemine.jchatter.JChat} instance of itself to allow chaining of methods
 * @throws java.util.MissingFormatArgumentException if the number of placeholders and subs don't match
 */// w w w . j av a  2 s  .c  o  m
public JChat text(String message, String... subs) throws MissingFormatArgumentException {

    Validate.notNull(message, "The message can not be null");
    Matcher matcher = _pattern.matcher(message);
    int count = 0;
    while (matcher.find())
        count++;

    if (count == 0 || count != subs.length)
        throw new MissingFormatArgumentException(
                "Error: The number of values do not match the number of placeholders");

    message = String.format(message, subs);

    return coloredText(message);

}

From source file:org.codemine.jchatter.JChat.java

/**
 * tooltipsWithValues extended method to create a tooltip which allows color codes and substitute values to be passed.
 * <p>Color codes or styles many be passed in here using the '&amp;' followed by a valid format code. They can be added in any order you like.
 * <p>The message can contain as many place holders as you like place holders in the messages must be '%s' and you must
 * are required to have the same number of values to match the number of placeholders. Failure to do so will and it will
 * throw an MissingFormatArgumentException
 * <p>Values should be passed as the 2nd argument as a list of strings. The order you add them will be the order they are used to replace
 * placeholders./* w w  w.  j  a v a  2 s .c o  m*/
 * <p>Like standard tooltips the onHover event will be applied to the text part that immediately proceeds it. While this function allow you
 * to input an entire line of text and styles all at once, it is still splitting them up to message parts, this is not a design fault, it is
 * the way the JSON message format requires.
 * <p>If you do not need to use placeholders then do not use this method use the standard tooltips. Failure to do this will
 * cause MissingFormatArgumentException to be thrown as the method is expecting it. See below for an example usage of this method.
 * <p><strong>player</strong> is an instance of {@link org.bukkit.entity.Player}. You are not required to use a player object to send the message,
 * you can use the players name, the players UUID or if left blank it will send to all players. Please note you will need to roughly follow the
 * example below, especially on the instance creation do not pass in any arguments. As mentioned above the following onHover event is applied to
 * the last text part. In this case the "server" word. if you wish to have the effect applied to a different part of the message you will need to
 * split up the .tooltipsWithValues the second example demonstrates this. This will add the effect to the first .then chat part.
 * <p>
 * <pre>
 * {@code
 *     JChat jChat = new JChat();
 *     jChat.then("&a&oHi %s hope you like the &6&o%s &a&oserver", player.getName(), "Factions")
 *     .tooltipsWithValues("&aHi %s hope you like &b%s server", player.getName(), "Factions"))
 *     .send(player);
 *     }
 * </pre>
 * <p>
 * <pre>
 * {@code
 *     JChat jChat = new JChat();
 *     jChat.then("&a&oHi %s hope you like the ", player.getName())
 *     .tooltipsWithValues("&aHi %s hope you like &b%s server", player.getName(), "Factions"))
 *     .then("&6&o%s &a&oserver","Factions")
 *     .send(player);
 *     }
 * </pre>
 * <tt>NOTE CURRENTLY ONLY SINGLE LINE TOOLTIPSWITHVALUES IN THIS FORMAT ARE SUPPORTED AT THIS TIME, MULTI LINE WILL BE ADDED SOON</tt>
 * <p>Currently it has a limitation of only being able to pass 2 ChatColor objects in a row. They can be one color and style OR 2 styles OR just one of either.
 * this would be valid in the message part. "&amp;a&amp;oHello" This would display green and italic text. This is what I mean when you can only pass to ChatColor objects
 * in a row. This is invalid <strong>"&amp;a&amp;o&amp;lHello"</strong> The total message can have as many Chatcolors as you like provided they are not added more than 2 in a row.
 * I will soon be changing this to remove this limitation but it was hard enough with just the 2 options, allowing the developer complete freedom to the order they are
 * added. These to are equal <strong>"&amp;a&amp;oHello"</strong> OR <strong>"&amp;o&amp;aHello"</strong> both result in identical formatting without the developer indicating in any way
 * what order they are adding them.
 * </p>
 *
 * @param text the text that will be used for the tooltip message. Placeholders MUST be <strong>%s</strong>
 * @param subs the subs the values that are used to replace placeholders in the message. You must pass the exact number of values as you have placeholders.
 * @return the {@link org.codemine.jchatter.JChat} instance of itself to allow chaining of methods
 * @throws MissingFormatArgumentException the missing format argument exception
 */
public JChat tooltipsWithValues(String text, String... subs) throws MissingFormatArgumentException {
    Validate.notNull(text, "The message can not be null");
    Matcher matcher = _pattern.matcher(text);
    int count = 0;
    while (matcher.find())
        count++;

    if (count == 0 || count != subs.length)
        throw new MissingFormatArgumentException(
                "Error: The number of values do not match the number of placeholders");

    onHover("show_text", ChatColor.translateAlternateColorCodes('&', String.format(text, subs)));
    return this;

}

From source file:org.codemine.jchatter.JChat.java

/**
 * Tooltip displayed with the onHover event, allowing color and style codes and placeholders to be used.
 * <p>For full usage instructions see {@link org.codemine.jchatter.JChat#tooltipsWithValues(String, String...)} as the functionality
 * is almost identical. Except this is for adding the message text body not a tooltip !
 *
 * @param message the text that will be used for the tooltip message. Placeholders MUST be <strong>%s</strong>
 * @param subs    the subs the values that are used to replace placeholders in the message. You must pass the exact number of values as you have placeholders.
 * @return the {@link org.codemine.jchatter.JChat} instance of itself to allow chaining of methods
 * @throws IllegalArgumentException the illegal argument exception
 *//*from   ww  w .  j  av  a 2  s  .  c o  m*/
public JChat then(String message, String... subs) throws IllegalArgumentException {
    Validate.notNull(message, "The message can not be null");
    Matcher matcher = _pattern.matcher(message);
    int count = 0;
    while (matcher.find())
        count++;

    if (count == 0 || count != subs.length)
        throw new MissingFormatArgumentException(
                "Error: The number of values do not match the number of placeholders");

    message = String.format(message, subs);
    //  System.out.println("Message length is currently " + message.length());
    //  System.out.println(message);
    splitPartsOnColor(message);

    return this;
}

From source file:org.deegree.tools.rendering.manager.DataManager.java

private static void startManager(CommandLine line)
        throws FileNotFoundException, IOException, UnsupportedOperationException, DatasourceException {

    ModelBackend<?> backend = getModelBackend(line);

    Action action = null;/*from  w w w  .j  a  v a  2  s  .  c om*/
    try {
        action = Action.valueOf(line.getOptionValue(ACTION).toUpperCase().trim());
    } catch (Exception e) {
        throw new IllegalArgumentException(ACTION + " may only be " + Arrays.toString(Action.values()), e);
    }
    Type type = null;
    try {
        type = Type.valueOf(line.getOptionValue(TYPE).toUpperCase().trim());
    } catch (Exception e) {
        throw new IllegalArgumentException(TYPE + " may only be one of " + Arrays.toString(Type.values()), e);
    }

    int qualityLevel = -1;
    try {
        qualityLevel = Integer.parseInt(line.getOptionValue(QL));
    } catch (NumberFormatException e) {
        // nothing
    }
    double[] translationVector = createTranslationVector(line.getOptionValue(OPT_WPVS_TRANSLATION_TO));

    backend.setWPVSTranslationVector(translationVector);

    String textureDir = line.getOptionValue(OPT_TEXTURE_DIR);
    String buildingID = line.getOptionValue(OPT_UUID);

    ModelManager<?> manager;
    switch (type) {
    case TREE:
        manager = new TreeManager(backend, textureDir, translationVector);
        break;
    case STAGE:
        manager = new StageManager(backend, 6, qualityLevel, translationVector);
        break;
    case PROTOTYPE:
        manager = new PrototypeManager(backend, textureDir, buildingID, translationVector);
        break;
    default:
        if (Action.IMPORT == action && (qualityLevel < 1) || (qualityLevel > 5)) {
            throw new IllegalArgumentException(QL + " may only be an integer in the range of 1-5.");
        }
        manager = new BuildingManager(backend, textureDir, 6, qualityLevel, buildingID,
                line.hasOption(OPT_CREATE_LOWEST_LEVELS), translationVector);
    }
    if (action == Action.IMPORT) {
        if (textureDir == null) {
            System.out.println("You supplied no texture dir, using user home/textures directory instead.");
            textureDir = System.getProperty("user.home") + "/textures";
        }
        String file = line.getOptionValue(OPT_FILE);
        if (file == null) {
            throw new IllegalArgumentException(
                    "Missing parameter: " + OPT_FILE + " it is required for importing.");
        }
        File f = new File(file);
        if (!f.exists()) {
            throw new IllegalArgumentException(OPT_FILE + ": " + f.getAbsolutePath()
                    + ", did not denote an existing file, nothing to import.");
        }

        long begin = System.currentTimeMillis();

        BackendResult inserted = manager.importFromFile(f, line);

        System.out
                .println("Result " + inserted + "\ntook:  " + (System.currentTimeMillis() - begin) + " millis");

    } else {
        String sqlWhere = line.getOptionValue(OPT_DELETE_SQL);
        if (sqlWhere == null || "".equals(sqlWhere)) {
            throw new MissingFormatArgumentException("The sql where clause of the delete action is mandatory.");
        }
        System.out
                .println("Deleted: " + manager.delete(buildingID, type, qualityLevel, sqlWhere) + " objects.");
    }

}

From source file:vault.queryrouter.common.Constant.java

public static String getKeyConfigValue(String key) {
    String value = configs.getString(key);
    if (value == null)
        throw new MissingFormatArgumentException(
                "'" + key + "'" + " is not specific in the configuration file");
    return value;
}