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:com.tc.object.ApplicatorDNAEncodingTest.java

private char[] makeCharArray() {
    final char[] rv = new char[this.rnd.nextInt(10)];
    for (int i = 0; i < rv.length; i++) {
        rv[i] = new Character((char) this.rnd.nextInt(Character.MAX_VALUE)).charValue();
    }//from   w w  w .  j  av  a2 s.  co m
    return rv;
}

From source file:org.dspace.browse.BrowseDAOPostgres.java

public int doOffsetQuery(String column, String value, boolean isAscending) throws BrowseException {
    TableRowIterator tri = null;/* w w w .  ja v a2s  .c o  m*/

    if (column == null || value == null) {
        return 0;
    }

    try {
        List<Serializable> paramsList = new ArrayList<Serializable>();
        StringBuffer queryBuf = new StringBuffer();

        queryBuf.append("COUNT(").append(column).append(") AS offset ");

        buildSelectStatement(queryBuf, paramsList);
        if (isAscending) {
            queryBuf.append(" WHERE ").append(column).append("<?");
            paramsList.add(value);
        } else {
            queryBuf.append(" WHERE ").append(column).append(">?");
            paramsList.add(value + Character.MAX_VALUE);
        }

        if (containerTable != null
                || (value != null && valueField != null && tableDis != null && tableMap != null)) {
            queryBuf.append(" AND ").append("mappings.item_id=");
            queryBuf.append(table).append(".item_id");
        }

        tri = DatabaseManager.query(context, queryBuf.toString(), paramsList.toArray());

        TableRow row;
        if (tri.hasNext()) {
            row = tri.next();
            return (int) row.getLongColumn("offset");
        } else {
            return 0;
        }
    } catch (SQLException e) {
        throw new BrowseException(e);
    } finally {
        if (tri != null) {
            tri.close();
        }
    }
}

From source file:xbird.xquery.misc.BasicStringChunk.java

private int allocateCharChunk(final char[] src, final int start, final int length) {
    assert (length < CHUNKED_THRESHOLD) : length;
    final int reqlen = length + 1; // actual length is store in first char. 
    final long lpage;
    if (((_cpointer & BLOCK_MASK) + reqlen) > BLOCK_SIZE) {
        // spanning pages is not allowed, allocate in next chunk.
        lpage = (_cpointer >> BLOCK_SHIFT) + 1;
        if (lpage > Integer.MAX_VALUE) {
            throw new IllegalStateException("Assained page exceeds system's limit: " + lpage);
        }//  w  w w  .j av a  2  s .  co  m
        this._cpointer = lpage * BLOCK_SIZE;
    } else {
        lpage = _cpointer >> BLOCK_SHIFT;
    }
    final int page = (int) lpage;
    if (page >= _cchunks.length) {
        enlarge((int) (_cchunks.length * ENLARGE_PAGES_FACTOR));
    }
    if (_cchunks[page] == null) {
        _cchunks[page] = new char[BLOCK_SIZE];
    }
    final long lblock = _cpointer & BLOCK_MASK;
    if (lblock > Integer.MAX_VALUE) {
        throw new IllegalStateException("Assained block exceeds system's limit: " + lblock);
    }
    final int block = (int) lblock;
    assert (length < Character.MAX_VALUE) : length;
    _cchunks[page][block] = (char) length;
    System.arraycopy(src, start, _cchunks[page], block + 1, length);
    final long index = _cpointer;
    _cpointer += reqlen; // move ahead pointer
    return chunkKey(index);
}

From source file:org.dspace.browse.BrowseDAOOracle.java

public int doDistinctOffsetQuery(String column, String value, boolean isAscending) throws BrowseException {
    TableRowIterator tri = null;//  www  . j  a v  a2  s  .  c o  m

    try {
        List<Serializable> paramsList = new ArrayList<Serializable>();
        StringBuffer queryBuf = new StringBuffer();

        queryBuf.append("COUNT(").append(column).append(") AS offset ");

        buildSelectStatementDistinct(queryBuf, paramsList);
        if (isAscending) {
            queryBuf.append(" WHERE ").append(column).append("<?");
            paramsList.add(value);
        } else {
            queryBuf.append(" WHERE ").append(column).append(">?");
            paramsList.add(value + Character.MAX_VALUE);
        }

        if (containerTable != null && tableMap != null) {
            queryBuf.append(" AND ").append("mappings.distinct_id=");
            queryBuf.append(table).append(".id");
        }

        tri = DatabaseManager.query(context, queryBuf.toString(), paramsList.toArray());

        TableRow row;
        if (tri.hasNext()) {
            row = tri.next();
            return row.getIntColumn("offset");
        } else {
            return 0;
        }
    } catch (SQLException e) {
        throw new BrowseException(e);
    } finally {
        if (tri != null) {
            tri.close();
        }
    }
}

From source file:org.dspace.browse.BrowseDAOPostgres.java

public int doDistinctOffsetQuery(String column, String value, boolean isAscending) throws BrowseException {
    TableRowIterator tri = null;/*w  w  w  .jav a 2  s.c om*/

    try {
        List<Serializable> paramsList = new ArrayList<Serializable>();
        StringBuffer queryBuf = new StringBuffer();

        queryBuf.append("COUNT(").append(column).append(") AS offset ");

        buildSelectStatementDistinct(queryBuf, paramsList);
        if (isAscending) {
            queryBuf.append(" WHERE ").append(column).append("<?");
            paramsList.add(value);
        } else {
            queryBuf.append(" WHERE ").append(column).append(">?");
            paramsList.add(value + Character.MAX_VALUE);
        }

        if (containerTable != null && tableMap != null) {
            queryBuf.append(" AND ").append("mappings.distinct_id=");
            queryBuf.append(table).append(".id");
        }

        tri = DatabaseManager.query(context, queryBuf.toString(), paramsList.toArray());

        TableRow row;
        if (tri.hasNext()) {
            row = tri.next();
            return (int) row.getLongColumn("offset");
        } else {
            return 0;
        }
    } catch (SQLException e) {
        throw new BrowseException(e);
    } finally {
        if (tri != null) {
            tri.close();
        }
    }
}

From source file:net.dv8tion.jda.audio.AudioConnection.java

private void setupSendThread() {
    if (sendThread == null && udpSocket != null && sendHandler != null) {
        sendThread = new Thread("AudioConnection SendThread Guild: " + channel.getGuild().getId()) {
            @Override/*from w ww. ja  v  a  2  s  .c om*/
            public void run() {
                char seq = 0; //Sequence of audio packets. Used to determine the order of the packets.
                int timestamp = 0; //Used to sync up our packets within the same timeframe of other people talking.
                long lastFrameSent = System.currentTimeMillis();
                boolean sentSilenceOnConnect = false;
                while (!udpSocket.isClosed() && !this.isInterrupted()) {
                    try {
                        //WE NEED TO CONSIDER BUFFERING STUFF BECAUSE REASONS.
                        //Consider storing 40-60ms of encoded audio as a buffer.
                        if (sentSilenceOnConnect && sendHandler != null && sendHandler.canProvide()) {
                            silenceCounter = -1;
                            byte[] rawAudio = sendHandler.provide20MsAudio();
                            if (rawAudio == null || rawAudio.length == 0) {
                                if (speaking && (System.currentTimeMillis()
                                        - lastFrameSent) > OPUS_FRAME_TIME_AMOUNT)
                                    setSpeaking(false);
                            } else {
                                if (!sendHandler.isOpus()) {
                                    rawAudio = encodeToOpus(rawAudio);
                                }
                                AudioPacket packet = new AudioPacket(seq, timestamp, webSocket.getSSRC(),
                                        rawAudio);
                                if (!speaking)
                                    setSpeaking(true);
                                udpSocket.send(packet.asEncryptedUdpPacket(webSocket.getAddress(),
                                        webSocket.getSecretKey()));

                                if (seq + 1 > Character.MAX_VALUE)
                                    seq = 0;
                                else
                                    seq++;
                            }
                        } else if (silenceCounter > -1) {
                            AudioPacket packet = new AudioPacket(seq, timestamp, webSocket.getSSRC(),
                                    silenceBytes);
                            udpSocket.send(packet.asEncryptedUdpPacket(webSocket.getAddress(),
                                    webSocket.getSecretKey()));

                            if (seq + 1 > Character.MAX_VALUE)
                                seq = 0;
                            else
                                seq++;

                            if (++silenceCounter > 10) {
                                silenceCounter = -1;
                                sentSilenceOnConnect = true;
                            }
                        } else if (speaking
                                && (System.currentTimeMillis() - lastFrameSent) > OPUS_FRAME_TIME_AMOUNT)
                            setSpeaking(false);
                    } catch (NoRouteToHostException e) {
                        LOG.warn("Closing AudioConnection due to inability to send audio packets.");
                        LOG.warn("Cannot send audio packet because JDA cannot navigate the route to Discord.\n"
                                + "Are you sure you have internet connection? It is likely that you've lost connection.");
                        webSocket.close(true, -1);
                    } catch (SocketException e) {
                        //Most likely the socket has been closed due to the audio connection be closed. Next iteration will kill loop.
                    } catch (Exception e) {
                        LOG.log(e);
                    } finally {
                        timestamp += OPUS_FRAME_SIZE;
                        long sleepTime = (OPUS_FRAME_TIME_AMOUNT)
                                - (System.currentTimeMillis() - lastFrameSent);
                        if (sleepTime > 0) {
                            try {
                                Thread.sleep(sleepTime);
                            } catch (InterruptedException e) {
                                //We've been asked to stop. The next iteration will kill the loop. 
                            }
                        }
                        if (System.currentTimeMillis() < lastFrameSent + 60) // If the sending didn't took longer than 60ms (3 times the time frame)
                        {
                            lastFrameSent += OPUS_FRAME_TIME_AMOUNT; // incrase lastFrameSent
                        } else {
                            lastFrameSent = System.currentTimeMillis(); // else reset lastFrameSent to current time
                        }
                    }
                }
            }
        };
        sendThread.setPriority((Thread.NORM_PRIORITY + Thread.MAX_PRIORITY) / 2);
        sendThread.setDaemon(true);
        sendThread.start();
    }
}

From source file:it.unimi.dsi.util.ImmutableExternalPrefixMap.java

/** map external map.
 * //  w  w w  .ja  v a  2  s.  c om
 * <P>This constructor does not assume that strings returned by <code>terms.iterator()</code>
 * will be distinct. Thus, it can be safely used with {@link FileLinesCollection}.
 * 
 * @param terms an iterable whose iterator will enumerate in lexicographical order the terms for the map.
 * @param blockSizeInBytes the block size (in bytes).
 * @param dumpStreamFilename the name of the dump stream, or <code>null</code> for a map
 * with an automatic dump stream.
 */

public ImmutableExternalPrefixMap(final Iterable<? extends CharSequence> terms, final int blockSizeInBytes,
        final CharSequence dumpStreamFilename) throws IOException {
    this.blockSize = blockSizeInBytes * 8;
    this.selfContained = dumpStreamFilename == null;
    // First of all, we gather frequencies for all Unicode characters
    int[] frequency = new int[Character.MAX_VALUE + 1];
    int maxWordLength = 0;
    CharSequence s;
    int count = 0;

    final MutableString prevTerm = new MutableString();

    for (Iterator<? extends CharSequence> i = terms.iterator(); i.hasNext();) {
        s = i.next();
        maxWordLength = Math.max(s.length(), maxWordLength);
        for (int j = s.length(); j-- != 0;)
            frequency[s.charAt(j)]++;
        if (count > 0 && prevTerm.compareTo(s) >= 0)
            throw new IllegalArgumentException(
                    "The provided term collection is not sorted, or contains duplicates [" + prevTerm + ", " + s
                            + "]");
        count++;
        prevTerm.replace(s);
    }

    size = count;

    // Then, we compute the number of actually used characters
    count = 0;
    for (int i = frequency.length; i-- != 0;)
        if (frequency[i] != 0)
            count++;

    /* Now we remap used characters in f, building at the same time maps from 
     * symbol to characters and from characters to symbols. */

    int[] packedFrequency = new int[count];
    symbol2char = new char[count];
    char2symbol = new Char2IntOpenHashMap(count);
    char2symbol.defaultReturnValue(-1);

    for (int i = frequency.length, k = count; i-- != 0;) {
        if (frequency[i] != 0) {
            packedFrequency[--k] = frequency[i];
            symbol2char[k] = (char) i;
            char2symbol.put((char) i, k);
        }
    }

    char2symbol.trim();

    // We now build the coder used to code the strings

    final PrefixCoder prefixCoder;
    final PrefixCodec codec;
    final BitVector[] codeWord;

    if (packedFrequency.length != 0) {
        codec = new HuTuckerCodec(packedFrequency);
        prefixCoder = codec.coder();
        decoder = codec.decoder();
        codeWord = prefixCoder.codeWords();
    } else {
        // This handles the case of a collection without words
        codec = null;
        prefixCoder = null;
        decoder = null;
        codeWord = null;
    }

    packedFrequency = frequency = null;

    // We now compress all strings using the given codec mixed with front coding
    final OutputBitStream output;
    if (selfContained) {
        final File temp = File.createTempFile(this.getClass().getName(), ".dump");
        temp.deleteOnExit();
        tempDumpStreamFilename = temp.toString();
        output = new OutputBitStream(temp, blockSizeInBytes);
    } else
        output = new OutputBitStream(tempDumpStreamFilename = dumpStreamFilename.toString(), blockSizeInBytes);

    // This array will contain the delimiting words (the ones at the start of each block)
    boolean isDelimiter;

    int length, prevTermLength = 0, bits;
    int prefixLength = 0, termCount = 0;
    int currBuffer = 0;

    final IntArrayList blockStarts = new IntArrayList();
    final IntArrayList blockOffsets = new IntArrayList();
    final ObjectArrayList<MutableString> delimiters = new ObjectArrayList<MutableString>();
    prevTerm.length(0);

    for (Iterator<?> i = terms.iterator(); i.hasNext();) {
        s = (CharSequence) i.next();
        length = s.length();

        isDelimiter = false;

        // We compute the common prefix and the number of bits that are necessary to code the next term.
        bits = 0;
        for (prefixLength = 0; prefixLength < length && prefixLength < prevTermLength
                && prevTerm.charAt(prefixLength) == s.charAt(prefixLength); prefixLength++)
            ;
        for (int j = prefixLength; j < length; j++)
            bits += codeWord[char2symbol.get(s.charAt(j))].size();

        //if ( bits + length + 1 > blockSize ) throw new IllegalArgumentException( "The string \"" + s + "\" is too long to be encoded with block size " + blockSizeInBytes );

        // If the next term would overflow the block, and we are not at the start of a block, we align.
        if (output.writtenBits() % blockSize != 0 && output.writtenBits() / blockSize != (output.writtenBits()
                + (length - prefixLength + 1) + (prefixLength + 1) + bits - 1) / blockSize) {
            // We align by writing 0es.
            if (DEBUG)
                System.err.println(
                        "Aligning away " + (blockSize - output.writtenBits() % blockSize) + " bits...");
            for (int j = (int) (blockSize - output.writtenBits() % blockSize); j-- != 0;)
                output.writeBit(0);
            if (ASSERTS)
                assert output.writtenBits() % blockSize == 0;
        }

        if (output.writtenBits() % blockSize == 0) {
            isDelimiter = true;
            prefixLength = 0;
            blockOffsets.add((int) (output.writtenBits() / blockSize));
        }

        // Note that delimiters do not get the prefix length, as it's 0.
        if (!isDelimiter)
            output.writeUnary(prefixLength);
        output.writeUnary(length - prefixLength);

        // Write the next coded suffix on output.
        for (int j = prefixLength; j < length; j++) {
            BitVector c = codeWord[char2symbol.get(s.charAt(j))];
            for (int k = 0; k < c.size(); k++)
                output.writeBit(c.getBoolean(k));
        }

        if (isDelimiter) {
            if (DEBUG)
                System.err.println(
                        "First string of block " + blockStarts.size() + ": " + termCount + " (" + s + ")");
            // The current word starts a new block
            blockStarts.add(termCount);
            // We do not want to rely on s being immutable.
            delimiters.add(new MutableString(s));
        }

        currBuffer = 1 - currBuffer;
        prevTerm.replace(s);
        prevTermLength = length;
        termCount++;
    }

    output.align();
    dumpStreamLength = output.writtenBits() / 8;
    output.close();

    intervalApproximator = prefixCoder == null ? null
            : new ImmutableBinaryTrie<CharSequence>(delimiters,
                    new PrefixCoderTransformationStrategy(prefixCoder, char2symbol, false));

    blockStarts.add(size);
    blockStart = blockStarts.toIntArray();
    blockOffset = blockOffsets.toIntArray();

    // We use a buffer of the same size of a block, hoping in fast I/O. */
    dumpStream = new InputBitStream(tempDumpStreamFilename, blockSizeInBytes);
}

From source file:org.apache.drill.exec.store.parquet2.DrillParquetReader.java

@Override
public void allocate(Map<Key, ValueVector> vectorMap) throws OutOfMemoryException {
    try {/*from  w w w.j  a v  a  2 s . c  om*/
        for (ValueVector v : vectorMap.values()) {
            AllocationHelper.allocate(v, Character.MAX_VALUE, 50, 10);
        }
    } catch (NullPointerException e) {
        throw new OutOfMemoryException();
    }
}

From source file:org.dataconservancy.packaging.tool.impl.generator.DomainObjectResourceBuilder.java

private static void remap(String oldBaseURI, String newBaseURI, TreeMap<String, Resource> resources,
        Map<String, String> renameMap) {

    Map<String, Resource> toReplace = new HashMap<>();

    /* Consider the the URI plus any hash fragments */
    toReplace.putAll(resources.subMap(oldBaseURI, true, oldBaseURI, true));
    toReplace.putAll(resources.subMap(oldBaseURI + "#", oldBaseURI + "#" + Character.MAX_VALUE));

    /* Swap out the base URI for each matching resource */
    toReplace.entrySet().forEach(res -> {
        String newURI = res.getKey().replaceFirst(oldBaseURI, Matcher.quoteReplacement(newBaseURI));
        renameMap.put(res.getValue().toString(), newURI);
        ResourceUtils.renameResource(res.getValue(), newURI);
    });/*from  w w w  . j av a  2 s .  com*/
}

From source file:org.objectweb.proactive.core.body.ft.protocols.cic.managers.FTManagerCIC.java

@Override
public synchronized int onSendReplyBefore(Reply reply) {
    if (multiactiveLogger.isDebugEnabled()) {
        multiactiveLogger.debug("#onSendReplyBefore " + reply.getMethodName());
    }//from   w ww  . ja v a  2  s. co m
    // set message info values
    this.forSentReply.checkpointIndex = (char) this.checkpointIndex;
    this.forSentReply.historyIndex = (char) this.historyIndex;
    this.forSentReply.incarnation = (char) this.incarnation;
    this.forSentReply.lastRecovery = (char) this.lastRecovery;
    this.forSentReply.isOrphanFor = Character.MAX_VALUE;
    this.forSentReply.fromHalfBody = false;
    this.forSentReply.vectorClock = null;
    reply.setMessageInfo(this.forSentReply);

    // output commit
    if (FTManagerCIC.isOCEnable && this.isOutputCommit(reply)) {
        try {
            if (logger.isDebugEnabled()) {
                logger.debug(this.ownerID + " is output commiting for reply " + reply);
            }
            this.storage.outputCommit(this.forSentReply);
        } catch (RemoteException e) {
            logger.error("**ERROR** Cannot perform output commit");
            e.printStackTrace();
        }
    }

    return 0;
}