Java Code Examples for java.awt.image.BufferedImage.getPropertyNames()

The following are Jave code examples for showing how to use getPropertyNames() of the java.awt.image.BufferedImage class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jdk8u-jdk   File: GetPropertyNames.java   View Source Code Vote up 5 votes
private static void validate(final BufferedImage bi, final int expected) {
    final String[] names = bi.getPropertyNames();
    if (names.length != expected) {
        throw new RuntimeException("Wrong number of names");
    }
    for (final String name : names) {
        final Object property = bi.getProperty(name);
        if (property == Image.UndefinedProperty || property == null) {
            throw new RuntimeException("Unexpected property");
        }
    }
}
 
Example 2
Project: openjdk-jdk10   File: GetPropertyNames.java   View Source Code Vote up 5 votes
private static void validate(final BufferedImage bi, final int expected) {
    final String[] names = bi.getPropertyNames();
    if (names.length != expected) {
        throw new RuntimeException("Wrong number of names");
    }
    for (final String name : names) {
        final Object property = bi.getProperty(name);
        if (property == Image.UndefinedProperty || property == null) {
            throw new RuntimeException("Unexpected property");
        }
    }
}
 
Example 3
Project: jdk8u-jdk   File: GetPropertyNames.java   View Source Code Vote up 4 votes
public static void main(final String[] args) {
    // default result is null
    if (defaultProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for null properties result is null
    final BufferedImage emptyProps = getBufferedImage(null);
    if (emptyProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for empty properties result is null
    final BufferedImage nullProps = getBufferedImage(new Properties());
    if (nullProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for non-string keys result is null
    final Properties properties = new Properties();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    final BufferedImage nonStringProps = getBufferedImage(properties);
    if (nonStringProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for string keys result is not null
    properties.clear();
    properties.setProperty("1", "1");
    properties.setProperty("2", "2");
    validate(getBufferedImage(properties), 2);
    // for the mix of strings and objects result is not null
    properties.clear();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    properties.setProperty("key1", "value1");
    properties.setProperty("key2", "value2");
    final BufferedImage mixProps = getBufferedImage(properties);
    validate(mixProps, 2);
    if (!"value1".equals(mixProps.getProperty("key1"))
        || !"value2".equals(mixProps.getProperty("key2"))) {
        throw new RuntimeException("Wrong key-value pair");
    }
}
 
Example 4
Project: openjdk-jdk10   File: GetPropertyNames.java   View Source Code Vote up 4 votes
public static void main(final String[] args) {
    // default result is null
    if (defaultProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for null properties result is null
    final BufferedImage emptyProps = getBufferedImage(null);
    if (emptyProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for empty properties result is null
    final BufferedImage nullProps = getBufferedImage(new Properties());
    if (nullProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for non-string keys result is null
    final Properties properties = new Properties();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    final BufferedImage nonStringProps = getBufferedImage(properties);
    if (nonStringProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for string keys result is not null
    properties.clear();
    properties.setProperty("1", "1");
    properties.setProperty("2", "2");
    validate(getBufferedImage(properties), 2);
    // for the mix of strings and objects result is not null
    properties.clear();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    properties.setProperty("key1", "value1");
    properties.setProperty("key2", "value2");
    final BufferedImage mixProps = getBufferedImage(properties);
    validate(mixProps, 2);
    if (!"value1".equals(mixProps.getProperty("key1"))
        || !"value2".equals(mixProps.getProperty("key2"))) {
        throw new RuntimeException("Wrong key-value pair");
    }
}