/** * Find key position in the map. * * @param key * Key to look for * @return Key position or -1 if not found */ @CheckForSigned private int _getReadIndex (final int key) { int idx = MapHelper.phiMix (key) & m_nMask; if (m_aKeys[idx] == key) { // we check FREE prior to this call return idx; } if (m_aKeys[idx] == FREE_KEY) { // end of chain already return -1; } final int startIdx = idx; while ((idx = _getNextIndex (idx)) != startIdx) { if (m_aKeys[idx] == FREE_KEY) return -1; if (m_aKeys[idx] == key) return idx; } return -1; }
/** * Find an index of a cell which should be updated by 'put' operation. It can * be: 1) a cell with a given key 2) first free cell in the chain * * @param key * Key to look for * @return Index of a cell to be updated by a 'put' operation */ @CheckForSigned private int _getPutIndex (final int key) { final int readIdx = _getReadIndex (key); if (readIdx >= 0) return readIdx; // key not found, find insertion point final int startIdx = MapHelper.phiMix (key) & m_nMask; if (m_aKeys[startIdx] == FREE_KEY) return startIdx; int idx = startIdx; while (m_aKeys[idx] != FREE_KEY) { idx = _getNextIndex (idx); if (idx == startIdx) return -1; } return idx; }
@CheckForSigned public static int getIndex (@Nonnull final int [] aCodepointSet, final int nValue) { int nStart = 0; int nEnd = aCodepointSet.length; while (nEnd - nStart > 8) { final int i = (nEnd + nStart) >>> 1; nStart = aCodepointSet[i] <= nValue ? i : nStart; nEnd = aCodepointSet[i] > nValue ? i : nEnd; } while (nStart < nEnd) { if (nValue < aCodepointSet[nStart]) break; nStart++; } return nStart == nEnd ? -1 : nStart - 1; }
/** * Reads characters into a portion of an array. * * @param aBuf * Destination buffer * @param nOfs * Offset at which to start writing characters * @param nLen * Maximum number of characters to read * @return The number of characters read, or -1 if the end of the stream has * been reached * @exception IOException * If an I/O error occurs */ @Override @CheckForSigned public int read (@Nonnull final char [] aBuf, @Nonnegative final int nOfs, @Nonnegative final int nLen) throws IOException { _ensureOpen (); ValueEnforcer.isArrayOfsLen (aBuf, nOfs, nLen); if (nLen == 0) return 0; if (m_nNext >= m_nLength) return -1; final int nChars = Math.min (m_nLength - m_nNext, nLen); System.arraycopy (m_aChars, m_nNext, aBuf, nOfs, nChars); m_nNext += nChars; return nChars; }
@CheckForSigned public int getIndex (final String uri, final String localName) { for (int n = m_nLength; n-- > 0;) if (localName.equals (m_aLocalNames[n]) && uri.equals (m_aUris[n])) return n; return -1; }
@CheckForSigned public int getIndex (final String qName) { for (int n = m_nLength; n-- > 0;) { if (qName.equals (m_aQNames[n])) return n; } return -1; }
@Override protected void _fromWire(@Nonnull ByteBuf in, @CheckForSigned int length) throws MessageValidationException { super._fromWire(in, length); setConnectionId(in.readLong()); int actionId = in.readInt(); if (actionId != getActionId()) throw new MessageValidationException("Packet contained bad ActionId: " + this); setTransactionId(in.readInt()); }
@Override protected void _fromWire(@Nonnull ByteBuf in, @CheckForSigned int length) throws MessageValidationException { super._fromWire(in, length); int actionId = in.readInt(); if (actionId != getActionId()) throw new MessageValidationException("Packet contained bad ActionId: " + this); setTransactionId(in.readInt()); }
@CheckForSigned public int getPort() { SocketAddress sa = getAddress(); if (!(sa instanceof InetSocketAddress)) return -1; InetSocketAddress isa = (InetSocketAddress) sa; return isa.getPort(); }
@CheckForSigned private int readCharStart() throws IOException { for (;;) { int c = reader.read(); if (Character.isWhitespace(c)) continue; return c; } }
@CheckForSigned private int readCharNext() throws IOException { for (;;) { int c = reader.read(); if (Character.isWhitespace(c)) return -1; if (c == '(' || c == ')' || c == '.') { reader.unread(c); return -1; } return c; } }
@CheckForSigned public final long getAverage () { return m_aRWLock.readLocked ( () -> { if (m_nInvocationCount == 0) return CGlobal.ILLEGAL_ULONG; return m_aSum.divide (BigInteger.valueOf (m_nInvocationCount)).longValue (); }); }
@CheckForSigned public final int getInvocationCount (@Nullable final String sKey) { return m_aRWLock.readLocked ( () -> { final Value aValue = m_aMap.get (sKey); return aValue == null ? CGlobal.ILLEGAL_UINT : aValue.getInvocationCount (); }); }
@CheckForSigned public final long getMin (@Nullable final String sKey) { return m_aRWLock.readLocked ( () -> { final Value aValue = m_aMap.get (sKey); return aValue == null ? CGlobal.ILLEGAL_ULONG : aValue.getMin (); }); }
@CheckForSigned public final long getAverage (@Nullable final String sKey) { return m_aRWLock.readLocked ( () -> { final Value aValue = m_aMap.get (sKey); return aValue == null ? CGlobal.ILLEGAL_ULONG : aValue.getAverage (); }); }
@CheckForSigned public long getMax (@Nullable final String sKey) { return m_aRWLock.readLocked ( () -> { final Value aValue = m_aMap.get (sKey); return aValue == null ? CGlobal.ILLEGAL_ULONG : aValue.getMax (); }); }
@CheckForSigned public long getCount (@Nullable final String sKey) { return m_aRWLock.readLocked ( () -> { final Value aCount = m_aMap.get (sKey); return aCount == null ? CGlobal.ILLEGAL_ULONG : aCount.getCount (); }); }
@CheckForSigned public int getInvocationCount (@Nullable final String sKey) { return m_aRWLock.readLocked ( () -> { final Value aCount = m_aMap.get (sKey); return aCount == null ? CGlobal.ILLEGAL_UINT : aCount.getInvocationCount (); }); }
/** * Reads a single character. * * @return The character read, or -1 if the end of the stream has been reached * @exception IOException * If an I/O error occurs */ @Override @CheckForSigned public int read () throws IOException { _ensureOpen (); if (m_nNext >= m_nLength) return -1; return m_aChars[m_nNext++]; }
@Nullable public InputStream getInputStream (@CheckForSigned final int nConnectTimeoutMS, @CheckForSigned final int nReadTimeoutMS) { return getInputStream (nConnectTimeoutMS, nReadTimeoutMS, (Consumer <? super URLConnection>) null, (IMutableWrapper <IOException>) null); }
@Nullable public InputStream getInputStream (@CheckForSigned final int nConnectTimeoutMS, @CheckForSigned final int nReadTimeoutMS, @Nullable final IMutableWrapper <IOException> aExceptionHolder) { return getInputStream (nConnectTimeoutMS, nReadTimeoutMS, (Consumer <? super URLConnection>) null, aExceptionHolder); }
@Nullable public InputStream getInputStream (@CheckForSigned final int nConnectTimeoutMS, @CheckForSigned final int nReadTimeoutMS, @Nullable final Consumer <? super URLConnection> aConnectionModifier, @Nullable final IMutableWrapper <IOException> aExceptionHolder) { return URLHelper.getInputStream (m_aURL, nConnectTimeoutMS, nReadTimeoutMS, aConnectionModifier, aExceptionHolder); }
@CheckForSigned public static long getFileSize (@Nullable final FileChannel aChannel) { if (aChannel != null) try { return aChannel.size (); } catch (final IOException ex) { // fall-through } return -1; }
@CheckForSigned private static int _fr_check (final char c) { if (_isNum (c)) return _toInt (c); final int idx = "ABCDEFGHJKLMNPQRSTUVWXYZ".indexOf (c); if (idx < 0) return -1; return 10 + idx; }
@Nonnegative protected static long getLeaseTime(@Nonnull LeaseTimeRange leaseTimeSecs, @CheckForSigned long requestedLeaseTimeSecs) { if (requestedLeaseTimeSecs < 0) return leaseTimeSecs.defaultLeaseTime; if (requestedLeaseTimeSecs <= leaseTimeSecs.minLeaseTime) return leaseTimeSecs.minLeaseTime; if (requestedLeaseTimeSecs >= leaseTimeSecs.maxLeaseTime) return leaseTimeSecs.maxLeaseTime; return requestedLeaseTimeSecs; }
/** Utility: Constructs a new ACK reply. */ @Nonnull protected static DhcpMessage newReplyAck( @Nonnull DhcpMessage request, @Nonnull MessageType type, @CheckForNull InetAddress assignedClientAddress, @CheckForSigned long leaseTimeSecs) { DhcpMessage reply = newReply(request, type); if (leaseTimeSecs > 0) reply.getOptions().setIntOption(IpAddressLeaseTime.class, leaseTimeSecs); if (assignedClientAddress != null) reply.setAssignedClientAddress(assignedClientAddress); return reply; }
private void _addAndReturnColumn (@CheckForSigned final int nIndex, @Nonnull final PLHBoxColumn aColumn) { internalCheckNotPrepared (); if (nIndex < 0 || nIndex >= m_aColumns.size ()) m_aColumns.add (aColumn); else m_aColumns.add (nIndex, aColumn); }
@Nonnull public PLHBoxColumn addAndReturnColumn (@CheckForSigned final int nIndex, @Nonnull final IPLRenderableObject <?> aElement, @Nonnull final WidthSpec aWidth) { final PLHBoxColumn aColumn = new PLHBoxColumn (aElement, aWidth); _addAndReturnColumn (nIndex, aColumn); return aColumn; }
@Nonnull public IMPLTYPE addColumn (@CheckForSigned final int nIndex, @Nonnull final IPLRenderableObject <?> aElement, @Nonnull final WidthSpec aWidth) { addAndReturnColumn (nIndex, aElement, aWidth); return thisAsT (); }
@Nonnull private PLVBoxRow _addAndReturnRow (@CheckForSigned final int nIndex, @Nonnull final IPLRenderableObject <?> aElement, @Nonnull final HeightSpec aHeight) { final PLVBoxRow aItem = new PLVBoxRow (aElement, aHeight); if (nIndex < 0 || nIndex >= m_aRows.size ()) m_aRows.add (aItem); else m_aRows.add (nIndex, aItem); return aItem; }
@CheckForSigned public int getEffectivePModeLegNumber () { return getAsInt (KEY_EFFECTIVE_PMODE_LEG_NUMBER, -1); }
/** * @return The line number where the token begins (incl.). May be -1 if not * such token is available. */ @CheckForSigned public int getTokenBeginLineNumber () { return m_nBeginLineNumber; }