Example usage for java.lang Character MAX_VALUE

List of usage examples for java.lang Character MAX_VALUE

Introduction

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

Prototype

char MAX_VALUE

To view the source code for java.lang Character MAX_VALUE.

Click Source Link

Document

The constant value of this field is the largest value of type char , '\u005CuFFFF' .

Usage

From source file:org.richfaces.request.FileUploadValueParamTest.java

@Test
public void testLongParam() throws Exception {
    StringBuilder sb = new StringBuilder();
    CharsetEncoder charsetEncoder = Charset.forName("UTF-8").newEncoder();

    for (int i = 0; i < 256; i++) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        int count = new Random().nextInt(128) + 128;
        while (count != 0) {
            char c = (char) new Random().nextInt(Character.MAX_VALUE);

            if (charsetEncoder.canEncode(c)) {
                baos.write(charsetEncoder.encode(CharBuffer.wrap(new char[] { c })).array());
                count--;/*from www  . j a v a2 s  .c o m*/
            }
        }

        byte[] bs = baos.toByteArray();
        param.handle(bs, bs.length);
        sb.append(new String(bs, "UTF-8"));
    }

    param.complete();
    assertEquals(sb.toString(), param.getValue());
}

From source file:com.datasayer.meerkat.TestMeerkatMain.java

private String randomString(final int length) {
    Random r = new Random();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < length; i++) {
        char c = (char) (r.nextInt((int) (Character.MAX_VALUE)));
        sb.append(c);/* w  w w. ja va 2 s. c om*/
    }
    sb.append(System.lineSeparator());
    return sb.toString();
}

From source file:com.qwazr.externalizor.SimplePrimitive.java

public SimplePrimitive() {

    intValue = RandomUtils.nextInt();/*from  w  w w .  j  av a2  s .  c  o m*/
    intArray = new int[] { RandomUtils.nextInt(), RandomUtils.nextInt(), RandomUtils.nextInt() };

    shortValue = (short) RandomUtils.nextInt(0, Short.MAX_VALUE);
    shortArray = new short[] { (short) RandomUtils.nextInt(0, Short.MAX_VALUE),
            (short) RandomUtils.nextInt(0, Short.MAX_VALUE), (short) RandomUtils.nextInt(0, Short.MAX_VALUE) };

    longValue = RandomUtils.nextLong();
    longArray = new long[] { RandomUtils.nextLong(), RandomUtils.nextLong(), RandomUtils.nextLong() };

    floatValue = RandomUtils.nextFloat();
    floatArray = new float[] { RandomUtils.nextFloat(), RandomUtils.nextFloat(), RandomUtils.nextFloat() };

    doubleValue = RandomUtils.nextDouble();
    doubleArray = new double[] { RandomUtils.nextDouble(), RandomUtils.nextDouble(), RandomUtils.nextDouble() };
    emptyDoubleArray = new double[0];

    booleanValue = RandomUtils.nextInt(0, 2) == 0;
    booleanArray = new boolean[RandomUtils.nextInt(0, 5)];
    for (int i = 0; i < booleanArray.length; i++)
        booleanArray[i] = RandomUtils.nextInt(0, 2) == 1;

    byteValue = (byte) RandomUtils.nextInt(0, Byte.MAX_VALUE);
    byteArray = new byte[] { (byte) RandomUtils.nextInt(0, Byte.MAX_VALUE),
            (byte) RandomUtils.nextInt(0, Byte.MAX_VALUE), (byte) RandomUtils.nextInt(0, Byte.MAX_VALUE) };

    charValue = (char) RandomUtils.nextInt(0, Character.MAX_VALUE);
    charArray = new char[] { (char) RandomUtils.nextInt(0, Character.MAX_VALUE),
            (char) RandomUtils.nextInt(0, Character.MAX_VALUE),
            (char) RandomUtils.nextInt(0, Character.MAX_VALUE) };

}

From source file:management.limbr.test.util.PojoTester.java

private Object getTestValueFor(Class<?> type) {
    if (type.equals(boolean.class) || type.equals(Boolean.class)) {
        return random.nextBoolean();
    } else if (type.equals(byte.class) || type.equals(Byte.class)) {
        return (byte) random.nextInt(Byte.MAX_VALUE);
    } else if (type.equals(short.class) || type.equals(Short.class)) {
        return (short) random.nextInt(Short.MAX_VALUE);
    } else if (type.equals(int.class) || type.equals(Integer.class)) {
        return random.nextInt();
    } else if (type.equals(long.class) || type.equals(Long.class)) {
        return random.nextLong();
    } else if (type.equals(char.class) || type.equals(Character.class)) {
        return (char) random.nextInt(Character.MAX_VALUE);
    } else if (type.equals(float.class) || type.equals(Float.class)) {
        return random.nextFloat();
    } else if (type.equals(double.class) || type.equals(Double.class)) {
        return random.nextDouble();
    } else if (type.equals(String.class)) {
        return Long.toString(random.nextLong());
    } else {/*from  w ww  .  j av a 2s.  c  o  m*/
        return createRichObject(type);
    }
}

From source file:org.janusgraph.graphdb.serializer.SerializerTest.java

License:asdf

@Test
public void comparableStringSerialization() {
    //Characters/*from  w  ww  . j  av a  2s.  c o  m*/
    DataOutput out = serialize.getDataOutput(((int) Character.MAX_VALUE) * 2 + 8);
    for (char c = Character.MIN_VALUE; c < Character.MAX_VALUE; c++) {
        out.writeObjectNotNull(c);
    }
    ReadBuffer b = out.getStaticBuffer().asReadBuffer();
    for (char c = Character.MIN_VALUE; c < Character.MAX_VALUE; c++) {
        assertEquals(c, serialize.readObjectNotNull(b, Character.class).charValue());
    }

    //String
    for (int t = 0; t < 10000; t++) {
        DataOutput out1 = serialize.getDataOutput(32 + 5);
        DataOutput out2 = serialize.getDataOutput(32 + 5);
        String s1 = RandomGenerator.randomString(1, 32);
        String s2 = RandomGenerator.randomString(1, 32);
        out1.writeObjectByteOrder(s1, String.class);
        out2.writeObjectByteOrder(s2, String.class);
        StaticBuffer b1 = out1.getStaticBuffer();
        StaticBuffer b2 = out2.getStaticBuffer();
        assertEquals(s1, serialize.readObjectByteOrder(b1.asReadBuffer(), String.class));
        assertEquals(s2, serialize.readObjectByteOrder(b2.asReadBuffer(), String.class));
        assertEquals(s1 + " vs " + s2, Integer.signum(s1.compareTo(s2)), Integer.signum(b1.compareTo(b2)));
    }
}

From source file:fr.pasteque.client.models.Catalog.java

public List<Product> getProductLikeBarcode(String barcode) {
    SortedMap<String, Product> sm = ((TreeMap<String, Product>) this.barcodeDb).subMap(barcode,
            barcode + Character.MAX_VALUE);
    return new ArrayList<Product>(sm.values());
}

From source file:org.owasp.jbrofuzz.update.StartUpdateChecker.java

/**
 * <p>/*  w w  w.  j a v a2 s. c  o  m*/
 * Static method for getting the current online version of JBroFuzz.
 * </p>
 * 
 * <p>
 * This method makes a connection to the OWASP web site, checking for the
 * latest version number.
 * </p>
 * 
 * @return double of the version or 0.0 in case of an error
 * 
 * @author subere@uncon.org
 * @version 2.5
 * @since 1.3
 */
private static double getWebsiteVersion() {

    String response = "";
    BufferedReader instream = null;

    try {

        final URL url = new URL(JBroFuzzFormat.URL_WEBSITE);
        final URLConnection urlc;

        final boolean proxyEnabled = JBroFuzz.PREFS.getBoolean(JBroFuzzPrefs.UPDATE[0].getId(), false);
        if (proxyEnabled) {

            final String proxy = JBroFuzz.PREFS.get(JBroFuzzPrefs.UPDATE[1].getId(), "");
            final int port = JBroFuzz.PREFS.getInt(JBroFuzzPrefs.UPDATE[2].getId(), -1);
            // A note here, proxy has no http:// or https://
            Proxy myProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxy, port));
            urlc = url.openConnection(myProxy);
            // Username:Password, yawn

            final boolean proxyReqAuth = JBroFuzz.PREFS.getBoolean(JBroFuzzPrefs.UPDATE[3].getId(), false);
            if (proxyReqAuth) {

                final String user = JBroFuzz.PREFS.get(JBroFuzzPrefs.UPDATE[5].getId(), "");
                final String pass = JBroFuzz.PREFS.get(JBroFuzzPrefs.UPDATE[6].getId(), "");
                final String encodedPassword = EncoderHashCore.encode(user + ":" + pass, "Base64");
                urlc.setRequestProperty("Proxy-Authorization", "Basic " + encodedPassword);
            }

        } else {

            urlc = url.openConnection();

        }
        urlc.setRequestProperty("User-Agent", "JBroFuzz/" + JBroFuzzFormat.VERSION);

        final int statusCode = ((HttpURLConnection) urlc).getResponseCode();

        if (statusCode == HttpURLConnection.HTTP_OK) {

            instream = new BufferedReader(new InputStreamReader(urlc.getInputStream()));

            // Typically returns -1
            final long contentLength = urlc.getContentLength();

            if (contentLength > Integer.MAX_VALUE) {
                return ZERO_VERSION;
            }

            int count;
            int limit = 0;
            final StringBuffer body = new StringBuffer(Character.MAX_VALUE);
            // 
            while (((count = instream.read()) != -1) && (limit < Character.MAX_VALUE)) {
                body.append((char) count);
                limit++;
            }
            instream.close();

            response = body.toString();

        } else {
            return ZERO_VERSION;
        } // else statement for a 200 response

    } catch (final IOException e) {
        return ZERO_VERSION;
    } finally {
        IOUtils.closeQuietly(instream);
    }

    if (!response.equalsIgnoreCase("")) {

        final Pattern pattern1 = Pattern.compile("Current version is (\\d.\\d)");
        final Matcher match1 = pattern1.matcher(response);
        if (match1.find()) {
            final String webVersion = match1.group().substring(19, 22);

            try {
                // Return the value, if found
                return Double.parseDouble(webVersion);

            } catch (final NumberFormatException e) {
                // Return 0.0 if an error occurs
                return ZERO_VERSION;

            }

        } else {
            return ZERO_VERSION;
        }
    }
    return ZERO_VERSION;
}

From source file:de.knightsoftnet.validators.shared.util.RegExUtil.java

/**
 * get all allowed characters which can be part of a String which matches a given regular
 * expression. TODO: this is a first feature incomplete implementation, has to be improved.
 *
 * @param pregEx string contains a regular expression pattern
 * @return string with all characters that can be part of a string that matches the regex
 *//*w  w  w .  j ava  2  s.  co  m*/
public static String getAllowedCharactersForRegEx(final String pregEx) {
    if (StringUtils.isEmpty(pregEx)) {
        return null;
    }
    final StringBuilder regExCheck = new StringBuilder();
    final StringBuilder regExCheckOut = new StringBuilder();
    boolean inSequence = false;
    boolean isNegativeSequence = false;
    boolean inSize = false;
    boolean isMasked = false;

    regExCheck.append("([");
    for (final char character : pregEx.toCharArray()) {
        switch (character) {
        case '\\':
            if (isMasked || inSequence) {
                regExCheck.append(character);
            }
            if (!inSequence) {
                isMasked = !isMasked;
            }
            break;
        case '^':
            if (inSequence) {
                if (isMasked) {
                    regExCheck.append(character);
                } else {
                    isNegativeSequence = true;
                }
            }
            isMasked = false;
            break;
        case '$':
        case '*':
        case '+':
        case '?':
        case '|':
            if (isMasked || inSequence) {
                regExCheck.append(character);
            }
            isMasked = false;
            break;
        case '[':
            if (isMasked || inSequence) {
                regExCheck.append(character);
            } else {
                inSequence = true;
                isNegativeSequence = false;
            }
            isMasked = false;
            break;
        case ']':
            if (isMasked) {
                regExCheck.append(character);
            } else {
                inSequence = false;
                isNegativeSequence = false;
            }
            isMasked = false;
            break;
        case '{':
            if (isMasked || inSequence) {
                regExCheck.append(character);
            } else {
                inSize = true;
            }
            isMasked = false;
            break;
        case '}':
            if (isMasked || inSequence) {
                regExCheck.append(character);
            } else {
                inSize = false;
            }
            isMasked = false;
            break;
        case '(':
            if (isMasked || inSequence) {
                regExCheck.append(character);
            }
            isMasked = false;
            break;
        case ')':
            if (isMasked || inSequence) {
                regExCheck.append(character);
            }
            isMasked = false;
            break;
        default:
            if (inSize) {
                if (character != ',' && (character < '0' || character > '9')) {
                    regExCheck.append(character);
                }
            } else if (!isNegativeSequence) {
                if (isMasked) {
                    if (regExCheckOut.length() > 1) {
                        regExCheckOut.append('|');
                    }
                    regExCheckOut.append('\\');
                    regExCheckOut.append(character);
                } else {
                    regExCheck.append(character);
                }
            }
            isMasked = false;
            break;
        }
    }
    if (regExCheck.length() < 3) {
        regExCheck.delete(1, regExCheck.length());
    } else {
        regExCheck.append(']');
        if (regExCheckOut.length() > 0) {
            regExCheck.append('|');
        }
    }
    regExCheck.append(regExCheckOut);
    regExCheck.append(')');
    final RegExp regEx = RegExp.compile(regExCheck.toString());
    final StringBuilder result = new StringBuilder();
    for (int count = Character.MIN_VALUE; count < Character.MAX_VALUE; count++) {
        if (regEx.exec(String.valueOf((char) count)) != null) {
            result.append((char) count);
        }
    }
    return result.toString();
}

From source file:savant.data.sources.DataSource.java

@Override
public List<BookmarkAdapter> lookup(String key) {
    if (dictionary != null) {
        if (key.endsWith("*")) {
            // Looking for a prefix-match.  Get the submap from k0 (inclusive) to k1 (exclusive);
            String k0 = key.substring(0, key.length() - 1);
            String k1 = k0 + Character.MAX_VALUE;
            Map<String, List<BookmarkAdapter>> subDict = dictionary.subMap(k0, k1);
            List<BookmarkAdapter> result = new ArrayList<BookmarkAdapter>();
            for (List<BookmarkAdapter> bms : subDict.values()) {
                result.addAll(bms);// w  ww.j  a v  a 2s .  c  o  m
            }
            return result;
        } else {
            // Looking for an exact match.
            return dictionary.get(key);
        }
    }
    return null;
}

From source file:org.apache.hadoop.hdfs.server.datanode.web.webhdfs.ParameterParser.java

/**
 * The following function behaves exactly the same as netty's
 * <code>QueryStringDecoder#decodeComponent</code> except that it
 * does not decode the '+' character as space. WebHDFS takes this scheme
 * to maintain the backward-compatibility for pre-2.7 releases.
 *//*from  w  w w.j a v a  2s .c om*/
private static String decodeComponent(final String s, final Charset charset) {
    if (s == null) {
        return "";
    }
    final int size = s.length();
    boolean modified = false;
    for (int i = 0; i < size; i++) {
        final char c = s.charAt(i);
        if (c == '%' || c == '+') {
            modified = true;
            break;
        }
    }
    if (!modified) {
        return s;
    }
    final byte[] buf = new byte[size];
    int pos = 0; // position in `buf'.
    for (int i = 0; i < size; i++) {
        char c = s.charAt(i);
        if (c == '%') {
            if (i == size - 1) {
                throw new IllegalArgumentException("unterminated escape sequence at" + " end of string: " + s);
            }
            c = s.charAt(++i);
            if (c == '%') {
                buf[pos++] = '%'; // "%%" -> "%"
                break;
            }
            if (i == size - 1) {
                throw new IllegalArgumentException("partial escape sequence at end " + "of string: " + s);
            }
            c = decodeHexNibble(c);
            final char c2 = decodeHexNibble(s.charAt(++i));
            if (c == Character.MAX_VALUE || c2 == Character.MAX_VALUE) {
                throw new IllegalArgumentException("invalid escape sequence `%" + s.charAt(i - 1) + s.charAt(i)
                        + "' at index " + (i - 2) + " of: " + s);
            }
            c = (char) (c * 16 + c2);
            // Fall through.
        }
        buf[pos++] = (byte) c;
    }
    return new String(buf, 0, pos, charset);
}