javax.annotation.CheckForSigned Java Examples
The following examples show how to use
javax.annotation.CheckForSigned.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NonBlockingStringReader.java From ph-commons with Apache License 2.0 | 6 votes |
/** * 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; }
Example #2
Source File: IntDoubleMap.java From ph-commons with Apache License 2.0 | 6 votes |
/** * 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; }
Example #3
Source File: IntFloatMap.java From ph-commons with Apache License 2.0 | 6 votes |
/** * 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; }
Example #4
Source File: IntObjectMap.java From ph-commons with Apache License 2.0 | 6 votes |
/** * 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; }
Example #5
Source File: IntObjectMap.java From ph-commons with Apache License 2.0 | 6 votes |
/** * 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; }
Example #6
Source File: IntDoubleMap.java From ph-commons with Apache License 2.0 | 6 votes |
/** * 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; }
Example #7
Source File: IntFloatMap.java From ph-commons with Apache License 2.0 | 6 votes |
/** * 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; }
Example #8
Source File: IntIntMap.java From ph-commons with Apache License 2.0 | 6 votes |
/** * 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; }
Example #9
Source File: IntIntMap.java From ph-commons with Apache License 2.0 | 6 votes |
/** * 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; }
Example #10
Source File: CodepointHelper.java From ph-commons with Apache License 2.0 | 6 votes |
@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; }
Example #11
Source File: PDTDisplayHelper.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @Nonempty @Override public String getDays (@CheckForSigned final int nDays) { return MathHelper.abs (nDays) == 1 ? nDays + " Tag" : nDays + " Tage"; }
Example #12
Source File: PDTDisplayHelper.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @Nonempty @Override public String getHours (@CheckForSigned final long nHours) { return MathHelper.abs (nHours) == 1 ? nHours + " Stunde" : nHours + " Stunden"; }
Example #13
Source File: PDTDisplayHelper.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @Nonempty @Override public String getMinutes (@CheckForSigned final long nMinutes) { return MathHelper.abs (nMinutes) == 1 ? nMinutes + " Minute" : nMinutes + " Minuten"; }
Example #14
Source File: PDTDisplayHelper.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @Nonempty @Override public String getSeconds (@CheckForSigned final long nSeconds) { return MathHelper.abs (nSeconds) == 1 ? nSeconds + " Sekunde" : nSeconds + " Sekunden"; }
Example #15
Source File: PDTDisplayHelper.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @Nonempty default String getYears (@CheckForSigned final int nYears) { // Use "abs" to ensure it is "1 year" and "-1 year" return MathHelper.abs (nYears) == 1 ? nYears + " year" : nYears + " years"; }
Example #16
Source File: PDTDisplayHelper.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @Nonempty @Override public String getYears (@CheckForSigned final int nYears) { // Use "abs" to ensure it is "1 year" and "-1 year" return MathHelper.abs (nYears) == 1 ? nYears + " Jahr" : nYears + " Jahre"; }
Example #17
Source File: AbstractCodepointIterator.java From ph-commons with Apache License 2.0 | 5 votes |
@CheckForSigned public int lastPosition () { final int nPos = position (); if (nPos < 0) return -1; return nPos >= limit () ? nPos : nPos - 1; }
Example #18
Source File: PDTDisplayHelper.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @Nonempty @Override public String getMonths (@CheckForSigned final int nMonths) { return MathHelper.abs (nMonths) == 1 ? nMonths + " Monat" : nMonths + " Monate"; }
Example #19
Source File: AbstractDhcpReplyFactory.java From dhcp4j with Apache License 2.0 | 5 votes |
/** 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; }
Example #20
Source File: AbstractDhcpReplyFactory.java From dhcp4j with Apache License 2.0 | 5 votes |
@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; }
Example #21
Source File: FileChannelHelper.java From ph-commons with Apache License 2.0 | 5 votes |
@CheckForSigned public static long getFileSize (@Nullable final FileChannel aChannel) { if (aChannel != null) try { return aChannel.size (); } catch (final IOException ex) { // fall-through } return -1; }
Example #22
Source File: AbstractStatisticsHandlerKeyedNumeric.java From ph-commons with Apache License 2.0 | 5 votes |
@CheckForSigned public final int getInvocationCount (@Nullable final String sKey) { return m_aRWLock.readLockedInt ( () -> { final Value aValue = m_aMap.get (sKey); return aValue == null ? CGlobal.ILLEGAL_UINT : aValue.getInvocationCount (); }); }
Example #23
Source File: AbstractStatisticsHandlerKeyedNumeric.java From ph-commons with Apache License 2.0 | 5 votes |
@CheckForSigned public final long getMin (@Nullable final String sKey) { return m_aRWLock.readLockedLong ( () -> { final Value aValue = m_aMap.get (sKey); return aValue == null ? CGlobal.ILLEGAL_ULONG : aValue.getMin (); }); }
Example #24
Source File: AbstractDhcpReplyFactory.java From dhcp4j with Apache License 2.0 | 5 votes |
/** 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; }
Example #25
Source File: URLResource.java From ph-commons with Apache License 2.0 | 5 votes |
@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); }
Example #26
Source File: StatisticsHandlerKeyedCounter.java From ph-commons with Apache License 2.0 | 5 votes |
@CheckForSigned public long getCount (@Nullable final String sKey) { return m_aRWLock.readLockedLong ( () -> { final Value aCount = m_aMap.get (sKey); return aCount == null ? CGlobal.ILLEGAL_ULONG : aCount.getCount (); }); }
Example #27
Source File: StatisticsHandlerKeyedCounter.java From ph-commons with Apache License 2.0 | 5 votes |
@CheckForSigned public int getInvocationCount (@Nullable final String sKey) { return m_aRWLock.readLockedInt ( () -> { final Value aCount = m_aMap.get (sKey); return aCount == null ? CGlobal.ILLEGAL_UINT : aCount.getInvocationCount (); }); }
Example #28
Source File: NonBlockingStringReader.java From ph-commons with Apache License 2.0 | 5 votes |
/** * 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++]; }
Example #29
Source File: URLResource.java From ph-commons with Apache License 2.0 | 5 votes |
@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); }
Example #30
Source File: URLResource.java From ph-commons with Apache License 2.0 | 5 votes |
@Nullable public InputStream getInputStream (@CheckForSigned final int nConnectTimeoutMS, @CheckForSigned final int nReadTimeoutMS) { return getInputStream (nConnectTimeoutMS, nReadTimeoutMS, (Consumer <? super URLConnection>) null, (IMutableWrapper <IOException>) null); }