_id
stringlengths
2
7
title
stringlengths
3
140
partition
stringclasses
3 values
text
stringlengths
73
34.1k
language
stringclasses
1 value
meta_information
dict
q7600
Bundler.put
train
public Bundler put(String key, CharSequence[] value) { delegate.putCharSequenceArray(key, value); return this; }
java
{ "resource": "" }
q7601
Bundler.put
train
public Bundler put(String key, Parcelable value) { delegate.putParcelable(key, value); return this; }
java
{ "resource": "" }
q7602
Bundler.put
train
public Bundler put(String key, Parcelable[] value) { delegate.putParcelableArray(key, value); return this; }
java
{ "resource": "" }
q7603
Bundler.put
train
public Bundler put(String key, Serializable value) { delegate.putSerializable(key, value); return this; }
java
{ "resource": "" }
q7604
HostName.validate
train
@Override public void validate() throws HostNameException { if(parsedHost != null) { return; } if(validationException != null) { throw validationException; } synchronized(this) { if(parsedHost != null) { return; } if(validationException != null) { throw validationException; } try { parsedHost = getValidator().validateHost(this); } catch(HostNameException e) { validationException = e; throw e; } } }
java
{ "resource": "" }
q7605
HostName.isValid
train
public boolean isValid() { if(parsedHost != null) { return true; } if(validationException != null) { return false; } try { validate(); return true; } catch(HostNameException e) { return false; } }
java
{ "resource": "" }
q7606
HostName.toNormalizedString
train
@Override public String toNormalizedString() { String result = normalizedString; if(result == null) { normalizedString = result = toNormalizedString(false); } return result; }
java
{ "resource": "" }
q7607
HostName.getNormalizedLabels
train
public String[] getNormalizedLabels() { if(isValid()) { return parsedHost.getNormalizedLabels(); } if(host.length() == 0) { return new String[0]; } return new String[] {host}; }
java
{ "resource": "" }
q7608
HostName.matches
train
public boolean matches(HostName host) { if(this == host) { return true; } if(isValid()) { if(host.isValid()) { if(isAddressString()) { return host.isAddressString() && asAddressString().equals(host.asAddressString()) && Objects.equals(getPort(), host.getPort()) && Objects.equals(getService(), host.getService()); } if(host.isAddressString()) { return false; } String thisHost = parsedHost.getHost(); String otherHost = host.parsedHost.getHost(); if(!thisHost.equals(otherHost)) { return false; } return Objects.equals(parsedHost.getEquivalentPrefixLength(), host.parsedHost.getEquivalentPrefixLength()) && Objects.equals(parsedHost.getMask(), host.parsedHost.getMask()) && Objects.equals(parsedHost.getPort(), host.parsedHost.getPort()) && Objects.equals(parsedHost.getService(), host.parsedHost.getService()); } return false; } return !host.isValid() && toString().equals(host.toString()); }
java
{ "resource": "" }
q7609
HostName.toAddress
train
@Override public IPAddress toAddress() throws UnknownHostException, HostNameException { IPAddress addr = resolvedAddress; if(addr == null && !resolvedIsNull) { //note that validation handles empty address resolution validate(); synchronized(this) { addr = resolvedAddress; if(addr == null && !resolvedIsNull) { if(parsedHost.isAddressString()) { addr = parsedHost.asAddress(); resolvedIsNull = (addr == null); //note there is no need to apply prefix or mask here, it would have been applied to the address already } else { String strHost = parsedHost.getHost(); if(strHost.length() == 0 && !validationOptions.emptyIsLoopback) { addr = null; resolvedIsNull = true; } else { //Note we do not set resolvedIsNull, so we will attempt to resolve again if the previous attempt threw an exception InetAddress inetAddress = InetAddress.getByName(strHost); byte bytes[] = inetAddress.getAddress(); Integer networkPrefixLength = parsedHost.getNetworkPrefixLength(); if(networkPrefixLength == null) { IPAddress mask = parsedHost.getMask(); if(mask != null) { byte maskBytes[] = mask.getBytes(); if(maskBytes.length != bytes.length) { throw new HostNameException(host, "ipaddress.error.ipMismatch"); } for(int i = 0; i < bytes.length; i++) { bytes[i] &= maskBytes[i]; } networkPrefixLength = mask.getBlockMaskPrefixLength(true); } } IPAddressStringParameters addressParams = validationOptions.addressOptions; if(bytes.length == IPv6Address.BYTE_COUNT) { IPv6AddressCreator creator = addressParams.getIPv6Parameters().getNetwork().getAddressCreator(); addr = creator.createAddressInternal(bytes, networkPrefixLength, null, this); /* address creation */ } else { IPv4AddressCreator creator = addressParams.getIPv4Parameters().getNetwork().getAddressCreator(); addr = creator.createAddressInternal(bytes, networkPrefixLength, this); /* address creation */ } } } resolvedAddress = addr; } } } return addr; }
java
{ "resource": "" }
q7610
MACAddressSection.iterator
train
protected Iterator<MACAddress> iterator(MACAddress original) { MACAddressCreator creator = getAddressCreator(); boolean isSingle = !isMultiple(); return iterator( isSingle ? original : null, creator,//using a lambda for this one results in a big performance hit isSingle ? null : segmentsIterator(), getNetwork().getPrefixConfiguration().allPrefixedAddressesAreSubnets() ? null : getPrefixLength()); }
java
{ "resource": "" }
q7611
MACAddressSection.toHexString
train
@Override public String toHexString(boolean with0xPrefix) { String result; if(hasNoStringCache() || (result = (with0xPrefix ? stringCache.hexStringPrefixed : stringCache.hexString)) == null) { result = toHexString(with0xPrefix, null); if(with0xPrefix) { stringCache.hexStringPrefixed = result; } else { stringCache.hexString = result; } } return result; }
java
{ "resource": "" }
q7612
MACAddressSection.toCompressedString
train
@Override public String toCompressedString() { String result; if(hasNoStringCache() || (result = getStringCache().compressedString) == null) { getStringCache().compressedString = result = toNormalizedString(MACStringCache.compressedParams); } return result; }
java
{ "resource": "" }
q7613
MACAddressSection.toDottedString
train
public String toDottedString() { String result = null; if(hasNoStringCache() || (result = getStringCache().dottedString) == null) { AddressDivisionGrouping dottedGrouping = getDottedGrouping(); getStringCache().dottedString = result = toNormalizedString(MACStringCache.dottedParams, dottedGrouping); } return result; }
java
{ "resource": "" }
q7614
IPv6AddressSegment.getSplitSegments
train
public <S extends AddressSegment> void getSplitSegments(S segs[], int index, AddressSegmentCreator<S> creator) { if(!isMultiple()) { int bitSizeSplit = IPv6Address.BITS_PER_SEGMENT >>> 1; Integer myPrefix = getSegmentPrefixLength(); Integer highPrefixBits = getSplitSegmentPrefix(bitSizeSplit, myPrefix, 0); Integer lowPrefixBits = getSplitSegmentPrefix(bitSizeSplit, myPrefix, 1); if(index >= 0 && index < segs.length) { segs[index] = creator.createSegment(highByte(), highPrefixBits); } if(++index >= 0 && index < segs.length) { segs[index] = creator.createSegment(lowByte(), lowPrefixBits); } } else { getSplitSegmentsMultiple(segs, index, creator); } }
java
{ "resource": "" }
q7615
AddressDivisionGrouping.containsPrefixBlock
train
@Override public boolean containsPrefixBlock(int prefixLength) { checkSubnet(this, prefixLength); int divisionCount = getDivisionCount(); int prevBitCount = 0; for(int i = 0; i < divisionCount; i++) { AddressDivision division = getDivision(i); int bitCount = division.getBitCount(); int totalBitCount = bitCount + prevBitCount; if(prefixLength < totalBitCount) { int divPrefixLen = Math.max(0, prefixLength - prevBitCount); if(!division.isPrefixBlock(division.getDivisionValue(), division.getUpperDivisionValue(), divPrefixLen)) { return false; } for(++i; i < divisionCount; i++) { division = getDivision(i); if(!division.isFullRange()) { return false; } } return true; } prevBitCount = totalBitCount; } return true; }
java
{ "resource": "" }
q7616
AddressDivisionGrouping.normalizePrefixBoundary
train
protected static <S extends IPAddressSegment> void normalizePrefixBoundary( int sectionPrefixBits, S segments[], int segmentBitCount, int segmentByteCount, BiFunction<S, Integer, S> segProducer) { //we've already verified segment prefixes in super constructor. We simply need to check the case where the prefix is at a segment boundary, //whether the network side has the correct prefix int networkSegmentIndex = getNetworkSegmentIndex(sectionPrefixBits, segmentByteCount, segmentBitCount); if(networkSegmentIndex >= 0) { S segment = segments[networkSegmentIndex]; if(!segment.isPrefixed()) { segments[networkSegmentIndex] = segProducer.apply(segment, segmentBitCount); } } }
java
{ "resource": "" }
q7617
AddressDivisionGrouping.fastIncrement
train
protected static <R extends AddressSection, S extends AddressSegment> R fastIncrement( R section, long increment, AddressCreator<?, R, ?, S> addrCreator, Supplier<R> lowerProducer, Supplier<R> upperProducer, Integer prefixLength) { if(increment >= 0) { BigInteger count = section.getCount(); if(count.compareTo(LONG_MAX) <= 0) { long longCount = count.longValue(); if(longCount > increment) { if(longCount == increment + 1) { return upperProducer.get(); } return incrementRange(section, increment, addrCreator, lowerProducer, prefixLength); } BigInteger value = section.getValue(); BigInteger upperValue; if(value.compareTo(LONG_MAX) <= 0 && (upperValue = section.getUpperValue()).compareTo(LONG_MAX) <= 0) { return increment( section, increment, addrCreator, count.longValue(), value.longValue(), upperValue.longValue(), lowerProducer, upperProducer, prefixLength); } } } else { BigInteger value = section.getValue(); if(value.compareTo(LONG_MAX) <= 0) { return add(lowerProducer.get(), value.longValue(), increment, addrCreator, prefixLength); } } return null; }
java
{ "resource": "" }
q7618
SQLStringMatcher.getSQLCondition
train
public StringBuilder getSQLCondition(StringBuilder builder, String columnName) { String string = networkString.getString(); if(isEntireAddress) { matchString(builder, columnName, string); } else { matchSubString( builder, columnName, networkString.getTrailingSegmentSeparator(), networkString.getTrailingSeparatorCount() + 1, string); } return builder; }
java
{ "resource": "" }
q7619
AddressDivisionBase.getRadixPower
train
protected static BigInteger getRadixPower(BigInteger radix, int power) { long key = (((long) radix.intValue()) << 32) | power; BigInteger result = radixPowerMap.get(key); if(result == null) { if(power == 1) { result = radix; } else if((power & 1) == 0) { BigInteger halfPower = getRadixPower(radix, power >> 1); result = halfPower.multiply(halfPower); } else { BigInteger halfPower = getRadixPower(radix, (power - 1) >> 1); result = halfPower.multiply(halfPower).multiply(radix); } radixPowerMap.put(key, result); } return result; }
java
{ "resource": "" }
q7620
AddressDivisionGroupingBase.getBytesInternal
train
protected byte[] getBytesInternal() { byte cached[]; if(hasNoValueCache() || (cached = valueCache.lowerBytes) == null) { valueCache.lowerBytes = cached = getBytesImpl(true); } return cached; }
java
{ "resource": "" }
q7621
AddressDivisionGroupingBase.getUpperBytesInternal
train
protected byte[] getUpperBytesInternal() { byte cached[]; if(hasNoValueCache()) { ValueCache cache = valueCache; cache.upperBytes = cached = getBytesImpl(false); if(!isMultiple()) { cache.lowerBytes = cached; } } else { ValueCache cache = valueCache; if((cached = cache.upperBytes) == null) { if(!isMultiple()) { if((cached = cache.lowerBytes) != null) { cache.upperBytes = cached; } else { cache.lowerBytes = cache.upperBytes = cached = getBytesImpl(false); } } else { cache.upperBytes = cached = getBytesImpl(false); } } } return cached; }
java
{ "resource": "" }
q7622
AddressDivisionGroupingBase.getMinPrefixLengthForBlock
train
@Override public int getMinPrefixLengthForBlock() { int count = getDivisionCount(); int totalPrefix = getBitCount(); for(int i = count - 1; i >= 0 ; i--) { AddressDivisionBase div = getDivision(i); int segBitCount = div.getBitCount(); int segPrefix = div.getMinPrefixLengthForBlock(); if(segPrefix == segBitCount) { break; } else { totalPrefix -= segBitCount; if(segPrefix != 0) { totalPrefix += segPrefix; break; } } } return totalPrefix; }
java
{ "resource": "" }
q7623
AddressDivisionGroupingBase.getPrefixLengthForSingleBlock
train
@Override public Integer getPrefixLengthForSingleBlock() { int count = getDivisionCount(); int totalPrefix = 0; for(int i = 0; i < count; i++) { AddressDivisionBase div = getDivision(i); Integer divPrefix = div.getPrefixLengthForSingleBlock(); if(divPrefix == null) { return null; } totalPrefix += divPrefix; if(divPrefix < div.getBitCount()) { //remaining segments must be full range or we return null for(i++; i < count; i++) { AddressDivisionBase laterDiv = getDivision(i); if(!laterDiv.isFullRange()) { return null; } } } } return cacheBits(totalPrefix); }
java
{ "resource": "" }
q7624
AddressDivisionGroupingBase.getCount
train
@Override public BigInteger getCount() { BigInteger cached = cachedCount; if(cached == null) { cachedCount = cached = getCountImpl(); } return cached; }
java
{ "resource": "" }
q7625
Validator.validateZone
train
public static int validateZone(CharSequence zone) { for(int i = 0; i < zone.length(); i++) { char c = zone.charAt(i); if (c == IPAddress.PREFIX_LEN_SEPARATOR) { return i; } if (c == IPv6Address.SEGMENT_SEPARATOR) { return i; } } return -1; }
java
{ "resource": "" }
q7626
Validator.switchValue8
train
private static long switchValue8(long currentHexValue, int digitCount) { long result = 0x7 & currentHexValue; int shift = 0; while(--digitCount > 0) { shift += 3; currentHexValue >>>= 4; result |= (0x7 & currentHexValue) << shift; } return result; }
java
{ "resource": "" }
q7627
Validator.validateHostImpl
train
static ParsedHost validateHostImpl(HostName fromHost) throws HostNameException { final String str = fromHost.toString(); HostNameParameters validationOptions = fromHost.getValidationOptions(); return validateHost(fromHost, str, validationOptions); }
java
{ "resource": "" }
q7628
Validator.convertReverseDNSIPv4
train
private static CharSequence convertReverseDNSIPv4(String str, int suffixStartIndex) throws AddressStringException { StringBuilder builder = new StringBuilder(suffixStartIndex); int segCount = 0; int j = suffixStartIndex; for(int i = suffixStartIndex - 1; i > 0; i--) { char c1 = str.charAt(i); if(c1 == IPv4Address.SEGMENT_SEPARATOR) { if(j - i <= 1) { throw new AddressStringException(str, i); } for(int k = i + 1; k < j; k++) { builder.append(str.charAt(k)); } builder.append(c1); j = i; segCount++; } } for(int k = 0; k < j; k++) { builder.append(str.charAt(k)); } if(segCount + 1 != IPv4Address.SEGMENT_COUNT) { throw new AddressStringException(str, 0); } return builder; }
java
{ "resource": "" }
q7629
AddressDivision.isPrefixBlock
train
protected boolean isPrefixBlock(long divisionValue, long upperValue, int divisionPrefixLen) { if(divisionPrefixLen == 0) { return divisionValue == 0 && upperValue == getMaxValue(); } long ones = ~0L; long divisionBitMask = ~(ones << getBitCount()); long divisionPrefixMask = ones << (getBitCount() - divisionPrefixLen); long divisionNonPrefixMask = ~divisionPrefixMask; return testRange(divisionValue, upperValue, upperValue, divisionPrefixMask & divisionBitMask, divisionNonPrefixMask); }
java
{ "resource": "" }
q7630
AddressDivision.matchesWithMask
train
public boolean matchesWithMask(long lowerValue, long upperValue, long mask) { if(lowerValue == upperValue) { return matchesWithMask(lowerValue, mask); } if(!isMultiple()) { //we know lowerValue and upperValue are not the same, so impossible to match those two values with a single value return false; } long thisValue = getDivisionValue(); long thisUpperValue = getUpperDivisionValue(); if(!isMaskCompatibleWithRange(thisValue, thisUpperValue, mask, getMaxValue())) { return false; } return lowerValue == (thisValue & mask) && upperValue == (thisUpperValue & mask); }
java
{ "resource": "" }
q7631
AddressDivision.isMaskCompatibleWithRange
train
protected static boolean isMaskCompatibleWithRange(long value, long upperValue, long maskValue, long maxValue) { if(value == upperValue || maskValue == maxValue || maskValue == 0) { return true; } //algorithm: //here we find the highest bit that is part of the range, highestDifferingBitInRange (ie changes from lower to upper) //then we find the highest bit in the mask that is 1 that is the same or below highestDifferingBitInRange (if such a bit exists) //this gives us the highest bit that is part of the masked range (ie changes from lower to upper after applying the mask) //if this latter bit exists, then any bit below it in the mask must be 1 to include the entire range. long differing = value ^ upperValue; boolean foundDiffering = (differing != 0); boolean differingIsLowestBit = (differing == 1); if(foundDiffering && !differingIsLowestBit) { int highestDifferingBitInRange = Long.numberOfLeadingZeros(differing); long maskMask = ~0L >>> highestDifferingBitInRange; long differingMasked = maskValue & maskMask; foundDiffering = (differingMasked != 0); differingIsLowestBit = (differingMasked == 1); if(foundDiffering && !differingIsLowestBit) { //anything below highestDifferingBitMasked in the mask must be ones //Also, if we have masked out any 1 bit in the original, then anything that we do not mask out that follows must be all 1s int highestDifferingBitMasked = Long.numberOfLeadingZeros(differingMasked); long hostMask = ~0L >>> (highestDifferingBitMasked + 1);//for the first mask bit that is 1, all bits that follow must also be 1 if((maskValue & hostMask) != hostMask) { //check if all ones below return false; } if(highestDifferingBitMasked > highestDifferingBitInRange) { //We have masked out a 1 bit, so we need to check that all bits in upper value that we do not mask out are also 1 bits, otherwise we end up missing values in the masked range //This check is unnecessary for prefix-length subnets, only non-standard ranges might fail this check. //For instance, if we have range 0000 to 1010 //and we mask upper and lower with 0111 //we get 0000 to 0010, but 0111 was in original range, and the mask of that value retains that value //so that value needs to be in final range, and it's not. //What went wrong is that we masked out the top bit, and any other bit that is not masked out must be 1. //To work, our original range needed to be 0000 to 1111, with the three 1s following the first masked-out 1 long hostMaskUpper = ~0L >>> highestDifferingBitMasked; if((upperValue & hostMaskUpper) != hostMaskUpper) { return false; } } } } return true; }
java
{ "resource": "" }
q7632
IPv6AddressSection.isEUI64
train
public boolean isEUI64(boolean partial) { int segmentCount = getSegmentCount(); int endIndex = addressSegmentIndex + segmentCount; if(addressSegmentIndex <= 5) { if(endIndex > 6) { int index3 = 5 - addressSegmentIndex; IPv6AddressSegment seg3 = getSegment(index3); IPv6AddressSegment seg4 = getSegment(index3 + 1); return seg4.matchesWithMask(0xfe00, 0xff00) && seg3.matchesWithMask(0xff, 0xff); } else if(partial && endIndex == 6) { IPv6AddressSegment seg3 = getSegment(5 - addressSegmentIndex); return seg3.matchesWithMask(0xff, 0xff); } } else if(partial && addressSegmentIndex == 6 && endIndex > 6) { IPv6AddressSegment seg4 = getSegment(6 - addressSegmentIndex); return seg4.matchesWithMask(0xfe00, 0xff00); } return partial; }
java
{ "resource": "" }
q7633
IPv6AddressSection.toEUI
train
public MACAddressSection toEUI(boolean extended) { MACAddressSegment[] segs = toEUISegments(extended); if(segs == null) { return null; } MACAddressCreator creator = getMACNetwork().getAddressCreator(); return createSectionInternal(creator, segs, Math.max(0, addressSegmentIndex - 4) << 1, extended); }
java
{ "resource": "" }
q7634
IPv6AddressSection.toEUISegments
train
MACAddressSegment[] toEUISegments(boolean extended) { IPv6AddressSegment seg0, seg1, seg2, seg3; int start = addressSegmentIndex; int segmentCount = getSegmentCount(); int segmentIndex; if(start < 4) { start = 0; segmentIndex = 4 - start; } else { start -= 4; segmentIndex = 0; } int originalSegmentIndex = segmentIndex; seg0 = (start == 0 && segmentIndex < segmentCount) ? getSegment(segmentIndex++) : null; seg1 = (start <= 1 && segmentIndex < segmentCount) ? getSegment(segmentIndex++) : null; seg2 = (start <= 2 && segmentIndex < segmentCount) ? getSegment(segmentIndex++) : null; seg3 = (start <= 3 && segmentIndex < segmentCount) ? getSegment(segmentIndex++) : null; int macSegCount = (segmentIndex - originalSegmentIndex) << 1; if(!extended) { macSegCount -= 2; } if((seg1 != null && !seg1.matchesWithMask(0xff, 0xff)) || (seg2 != null && !seg2.matchesWithMask(0xfe00, 0xff00)) || macSegCount == 0) { return null; } MACAddressCreator creator = getMACNetwork().getAddressCreator(); MACAddressSegment ZERO_SEGMENT = creator.createSegment(0); MACAddressSegment newSegs[] = creator.createSegmentArray(macSegCount); int macStartIndex = 0; if(seg0 != null) { seg0.getSplitSegments(newSegs, macStartIndex, creator); //toggle the u/l bit MACAddressSegment macSegment0 = newSegs[0]; int lower0 = macSegment0.getSegmentValue(); int upper0 = macSegment0.getUpperSegmentValue(); int mask2ndBit = 0x2; if(!macSegment0.matchesWithMask(mask2ndBit & lower0, mask2ndBit)) { return null; } //you can use matches with mask lower0 ^= mask2ndBit;//flip the universal/local bit upper0 ^= mask2ndBit; newSegs[0] = creator.createSegment(lower0, upper0, null); macStartIndex += 2; } if(seg1 != null) { seg1.getSplitSegments(newSegs, macStartIndex, creator); //a ff fe b if(!extended) { newSegs[macStartIndex + 1] = ZERO_SEGMENT; } macStartIndex += 2; } if(seg2 != null) { if(!extended) { if(seg1 != null) { macStartIndex -= 2; MACAddressSegment first = newSegs[macStartIndex]; seg2.getSplitSegments(newSegs, macStartIndex, creator); newSegs[macStartIndex] = first; } else { seg2.getSplitSegments(newSegs, macStartIndex, creator); newSegs[macStartIndex] = ZERO_SEGMENT; } } else { seg2.getSplitSegments(newSegs, macStartIndex, creator); } macStartIndex += 2; } if(seg3 != null) { seg3.getSplitSegments(newSegs, macStartIndex, creator); } return newSegs; }
java
{ "resource": "" }
q7635
IPv6AddressSection.getEmbeddedIPv4AddressSection
train
public IPv4AddressSection getEmbeddedIPv4AddressSection(int startIndex, int endIndex) { if(startIndex == ((IPv6Address.MIXED_ORIGINAL_SEGMENT_COUNT - this.addressSegmentIndex) << 1) && endIndex == (getSegmentCount() << 1)) { return getEmbeddedIPv4AddressSection(); } IPv4AddressCreator creator = getIPv4Network().getAddressCreator(); IPv4AddressSegment[] segments = creator.createSegmentArray((endIndex - startIndex) >> 1); int i = startIndex, j = 0; if(i % IPv6Address.BYTES_PER_SEGMENT == 1) { IPv6AddressSegment ipv6Segment = getSegment(i >> 1); i++; ipv6Segment.getSplitSegments(segments, j - 1, creator); j++; } for(; i < endIndex; i <<= 1, j <<= 1) { IPv6AddressSegment ipv6Segment = getSegment(i >> 1); ipv6Segment.getSplitSegments(segments, j, creator); } return createEmbeddedSection(creator, segments, this); }
java
{ "resource": "" }
q7636
IPv6AddressSection.hasUppercaseVariations
train
public boolean hasUppercaseVariations(int base, boolean lowerOnly) { if(base > 10) { int count = getSegmentCount(); for(int i = 0; i < count; i++) { IPv6AddressSegment seg = getSegment(i); if(seg.hasUppercaseVariations(base, lowerOnly)) { return true; } } } return false; }
java
{ "resource": "" }
q7637
IPv6AddressSection.mergeToSequentialBlocks
train
public IPv6AddressSection[] mergeToSequentialBlocks(IPv6AddressSection ...sections) throws SizeMismatchException { List<IPAddressSegmentSeries> blocks = getMergedSequentialBlocks(this, sections, true, createSeriesCreator(getAddressCreator(), getMaxSegmentValue())); return blocks.toArray(new IPv6AddressSection[blocks.size()]); }
java
{ "resource": "" }
q7638
IPv6AddressSection.toCanonicalString
train
@Override public String toCanonicalString() { String result; if(hasNoStringCache() || (result = stringCache.canonicalString) == null) { stringCache.canonicalString = result = toNormalizedString(IPv6StringCache.canonicalParams); } return result; }
java
{ "resource": "" }
q7639
IPv6AddressSection.toFullString
train
@Override public String toFullString() { String result; if(hasNoStringCache() || (result = getStringCache().fullString) == null) { getStringCache().fullString = result = toNormalizedString(IPv6StringCache.fullParams); } return result; }
java
{ "resource": "" }
q7640
IPv6AddressSection.toNormalizedString
train
@Override public String toNormalizedString() { String result; if(hasNoStringCache() || (result = getStringCache().normalizedString) == null) { getStringCache().normalizedString = result = toNormalizedString(IPv6StringCache.normalizedParams); } return result; }
java
{ "resource": "" }
q7641
IPv6AddressSection.getCompressIndexAndCount
train
private int[] getCompressIndexAndCount(CompressOptions options, boolean createMixed) { if(options != null) { CompressionChoiceOptions rangeSelection = options.rangeSelection; RangeList compressibleSegs = rangeSelection.compressHost() ? getZeroRangeSegments() : getZeroSegments(); int maxIndex = -1, maxCount = 0; int segmentCount = getSegmentCount(); boolean compressMixed = createMixed && options.compressMixedOptions.compressMixed(this); boolean preferHost = (rangeSelection == CompressOptions.CompressionChoiceOptions.HOST_PREFERRED); boolean preferMixed = createMixed && (rangeSelection == CompressOptions.CompressionChoiceOptions.MIXED_PREFERRED); for(int i = compressibleSegs.size() - 1; i >= 0 ; i--) { Range range = compressibleSegs.getRange(i); int index = range.index; int count = range.length; if(createMixed) { //so here we shorten the range to exclude the mixed part if necessary int mixedIndex = IPv6Address.MIXED_ORIGINAL_SEGMENT_COUNT - addressSegmentIndex; if(!compressMixed || index > mixedIndex || index + count < segmentCount) { //range does not include entire mixed part. We never compress only part of a mixed part. //the compressible range must stop at the mixed part count = Math.min(count, mixedIndex - index); } } //select this range if is the longest if(count > 0 && count >= maxCount && (options.compressSingle || count > 1)) { maxIndex = index; maxCount = count; } if(preferHost && isPrefixed() && ((index + count) * IPv6Address.BITS_PER_SEGMENT) > getNetworkPrefixLength()) { //this range contains the host //Since we are going backwards, this means we select as the maximum any zero segment that includes the host break; } if(preferMixed && index + count >= segmentCount) { //this range contains the mixed section //Since we are going backwards, this means we select to compress the mixed segment break; } } if(maxIndex >= 0) { return new int[] {maxIndex, maxCount}; } } return null; }
java
{ "resource": "" }
q7642
ParsedAddressGrouping.getHostSegmentIndex
train
public static int getHostSegmentIndex(int networkPrefixLength, int bytesPerSegment, int bitsPerSegment) { if(bytesPerSegment > 1) { if(bytesPerSegment == 2) { return networkPrefixLength >> 4; } return networkPrefixLength / bitsPerSegment; } return networkPrefixLength >> 3; }
java
{ "resource": "" }
q7643
MACAddressString.validate
train
@Override public void validate() throws AddressStringException { if(isValidated()) { return; } synchronized(this) { if(isValidated()) { return; } //we know nothing about this address. See what it is. try { parsedAddress = getValidator().validateAddress(this); isValid = true; } catch(AddressStringException e) { cachedException = e; isValid = false; throw e; } } }
java
{ "resource": "" }
q7644
IPAddressSegment.isChangedByMask
train
protected boolean isChangedByMask(int maskValue, Integer segmentPrefixLength) throws IncompatibleAddressException { boolean hasBits = (segmentPrefixLength != null); if(hasBits && (segmentPrefixLength < 0 || segmentPrefixLength > getBitCount())) { throw new PrefixLenException(this, segmentPrefixLength); } //note that the mask can represent a range (for example a CIDR mask), //but we use the lowest value (maskSegment.value) in the range when masking (ie we discard the range) int value = getSegmentValue(); int upperValue = getUpperSegmentValue(); return value != (value & maskValue) || upperValue != (upperValue & maskValue) || (isPrefixed() ? !getSegmentPrefixLength().equals(segmentPrefixLength) : hasBits); }
java
{ "resource": "" }
q7645
IPAddressSegment.isMaskCompatibleWithRange
train
public boolean isMaskCompatibleWithRange(int maskValue, Integer segmentPrefixLength) throws PrefixLenException { if(!isMultiple()) { return true; } return super.isMaskCompatibleWithRange(maskValue, segmentPrefixLength, getNetwork().getPrefixConfiguration().allPrefixedAddressesAreSubnets()); }
java
{ "resource": "" }
q7646
IPAddressSegment.isBitwiseOrCompatibleWithRange
train
public boolean isBitwiseOrCompatibleWithRange(int maskValue, Integer segmentPrefixLength) throws PrefixLenException { return super.isBitwiseOrCompatibleWithRange(maskValue, segmentPrefixLength, getNetwork().getPrefixConfiguration().allPrefixedAddressesAreSubnets()); }
java
{ "resource": "" }
q7647
IPv4AddressSegment.join
train
public IPv6AddressSegment join(IPv6AddressCreator creator, IPv4AddressSegment low) throws IncompatibleAddressException { int shift = IPv4Address.BITS_PER_SEGMENT; Integer prefix = getJoinedSegmentPrefixLength(shift, getSegmentPrefixLength(), low.getSegmentPrefixLength()); if(isMultiple()) { //if the high segment has a range, the low segment must match the full range, //otherwise it is not possible to create an equivalent range when joining if(!low.isFullRange()) { throw new IncompatibleAddressException(this, low, "ipaddress.error.invalidMixedRange"); } } return creator.createSegment( (getSegmentValue() << shift) | low.getSegmentValue(), (getUpperSegmentValue() << shift) | low.getUpperSegmentValue(), prefix); }
java
{ "resource": "" }
q7648
IPAddress.toHostName
train
public HostName toHostName() { HostName host = fromHost; if(host == null) { fromHost = host = toCanonicalHostName(); } return host; }
java
{ "resource": "" }
q7649
IPAddress.matchesWithMask
train
public boolean matchesWithMask(IPAddress other, IPAddress mask) { return getSection().matchesWithMask(other.getSection(), mask.getSection()); }
java
{ "resource": "" }
q7650
MACAddress.toLinkLocalIPv6
train
public IPv6Address toLinkLocalIPv6() { IPv6AddressNetwork network = getIPv6Network(); IPv6AddressSection linkLocalPrefix = network.getLinkLocalPrefix(); IPv6AddressCreator creator = network.getAddressCreator(); return creator.createAddress(linkLocalPrefix.append(toEUI64IPv6())); }
java
{ "resource": "" }
q7651
MACAddress.toEUI64
train
public MACAddress toEUI64(boolean asMAC) { if(!isExtended()) {//getSegmentCount() == EXTENDED_UNIQUE_IDENTIFIER_48_SEGMENT_COUNT MACAddressCreator creator = getAddressCreator(); MACAddressSegment segs[] = creator.createSegmentArray(EXTENDED_UNIQUE_IDENTIFIER_64_SEGMENT_COUNT); MACAddressSection section = getSection(); section.getSegments(0, 3, segs, 0); MACAddressSegment ffSegment = creator.createSegment(0xff); segs[3] = ffSegment; segs[4] = asMAC ? ffSegment : creator.createSegment(0xfe); section.getSegments(3, 6, segs, 5); Integer prefLength = getPrefixLength(); if(prefLength != null) { MACAddressSection resultSection = creator.createSectionInternal(segs, true); if(prefLength >= 24) { prefLength += MACAddress.BITS_PER_SEGMENT << 1; //two segments } resultSection.assignPrefixLength(prefLength); } return creator.createAddressInternal(segs); } else { MACAddressSection section = getSection(); MACAddressSegment seg3 = section.getSegment(3); MACAddressSegment seg4 = section.getSegment(4); if(seg3.matches(0xff) && seg4.matches(asMAC ? 0xff : 0xfe)) { return this; } } throw new IncompatibleAddressException(this, "ipaddress.mac.error.not.eui.convertible"); }
java
{ "resource": "" }
q7652
IPAddressSeqRange.prefixIterator
train
@Override public Iterator<? extends IPAddressSeqRange> prefixIterator(int prefixLength) { if(!isMultiple()) { return new Iterator<IPAddressSeqRange>() { IPAddressSeqRange orig = IPAddressSeqRange.this; @Override public boolean hasNext() { return orig != null; } @Override public IPAddressSeqRange next() { if(orig == null) { throw new NoSuchElementException(); } IPAddressSeqRange result = orig; orig = null; return result; } @Override public void remove() { throw new UnsupportedOperationException(); } }; } return new Iterator<IPAddressSeqRange>() { Iterator<? extends IPAddress> prefixBlockIterator = prefixBlockIterator(prefixLength); private boolean first = true; @Override public boolean hasNext() { return prefixBlockIterator.hasNext(); } @Override public IPAddressSeqRange next() { IPAddress next = prefixBlockIterator.next(); if(first) { first = false; // next is a prefix block IPAddress lower = getLower(); if(hasNext()) { if(!lower.includesZeroHost(prefixLength)) { return create(lower, next.getUpper()); } } else { IPAddress upper = getUpper(); if(!lower.includesZeroHost(prefixLength) || !upper.includesMaxHost(prefixLength)) { return create(lower, upper); } } } else if(!hasNext()) { IPAddress upper = getUpper(); if(!upper.includesMaxHost(prefixLength)) { return create(next.getLower(), upper); } } return next.toSequentialRange(); } @Override public void remove() { throw new UnsupportedOperationException(); } }; }
java
{ "resource": "" }
q7653
IPAddressSeqRange.join
train
public static IPAddressSeqRange[] join(IPAddressSeqRange... ranges) { int joinedCount = 0; Arrays.sort(ranges, Address.ADDRESS_LOW_VALUE_COMPARATOR); for(int i = 0; i < ranges.length; i++) { IPAddressSeqRange range = ranges[i]; if(range == null) { continue; } for(int j = i + 1; j < ranges.length; j++) { IPAddressSeqRange range2 = ranges[j]; if(range2 == null) { continue; } IPAddress upper = range.getUpper(); IPAddress lower = range2.getLower(); if(compareLowValues(upper, lower) >= 0 || upper.increment(1).equals(lower)) { //join them ranges[i] = range = range.create(range.getLower(), range2.getUpper()); ranges[j] = null; joinedCount++; } else break; } } if(joinedCount == 0) { return ranges; } IPAddressSeqRange joined[] = new IPAddressSeqRange[ranges.length - joinedCount]; for(int i = 0, j = 0; i < ranges.length; i++) { IPAddressSeqRange range = ranges[i]; if(range == null) { continue; } joined[j++] = range; if(j >= joined.length) { break; } } return joined; }
java
{ "resource": "" }
q7654
IPAddressSeqRange.intersect
train
public IPAddressSeqRange intersect(IPAddressSeqRange other) { IPAddress otherLower = other.getLower(); IPAddress otherUpper = other.getUpper(); IPAddress lower = this.getLower(); IPAddress upper = this.getUpper(); if(compareLowValues(lower, otherLower) <= 0) { if(compareLowValues(upper, otherUpper) >= 0) { return other; } else if(compareLowValues(upper, otherLower) < 0) { return null; } return create(otherLower, upper); } else if(compareLowValues(otherUpper, upper) >= 0) { return this; } else if(compareLowValues(otherUpper, lower) < 0) { return null; } return create(lower, otherUpper); }
java
{ "resource": "" }
q7655
IPAddressSeqRange.subtract
train
public IPAddressSeqRange[] subtract(IPAddressSeqRange other) { IPAddress otherLower = other.getLower(); IPAddress otherUpper = other.getUpper(); IPAddress lower = this.getLower(); IPAddress upper = this.getUpper(); if(compareLowValues(lower, otherLower) < 0) { if(compareLowValues(upper, otherUpper) > 0) { // l ol ou u return createPair(lower, otherLower.increment(-1), otherUpper.increment(1), upper); } else { int comp = compareLowValues(upper, otherLower); if(comp < 0) { // l u ol ou return createSingle(); } else if(comp == 0) { // l u == ol ou return createSingle(lower, upper.increment(-1)); } return createSingle(lower, otherLower.increment(-1)); // l ol u ou } } else if(compareLowValues(otherUpper, upper) >= 0) { // ol l u ou return createEmpty(); } else { int comp = compareLowValues(otherUpper, lower); if(comp < 0) { return createSingle(); // ol ou l u } else if(comp == 0) { return createSingle(lower.increment(1), upper); //ol ou == l u } return createSingle(otherUpper.increment(1), upper); // ol l ou u } }
java
{ "resource": "" }
q7656
IPAddressSection.isNetworkSection
train
protected boolean isNetworkSection(int networkPrefixLength, boolean withPrefixLength) { int segmentCount = getSegmentCount(); if(segmentCount == 0) { return true; } int bitsPerSegment = getBitsPerSegment(); int prefixedSegmentIndex = getNetworkSegmentIndex(networkPrefixLength, getBytesPerSegment(), bitsPerSegment); if(prefixedSegmentIndex + 1 < segmentCount) { return false; //not the right number of segments } //the segment count matches, now compare the prefixed segment int segPrefLength = getPrefixedSegmentPrefixLength(bitsPerSegment, networkPrefixLength, prefixedSegmentIndex); return !getSegment(segmentCount - 1).isNetworkChangedByPrefix(segPrefLength, withPrefixLength); }
java
{ "resource": "" }
q7657
IPAddressSection.getBlockMaskPrefixLength
train
public Integer getBlockMaskPrefixLength(boolean network) { Integer prefixLen; if(network) { if(hasNoPrefixCache() || (prefixLen = prefixCache.networkMaskPrefixLen) == null) { prefixLen = setNetworkMaskPrefix(checkForPrefixMask(network)); } } else { if(hasNoPrefixCache() || (prefixLen = prefixCache.hostMaskPrefixLen) == null) { prefixLen = setHostMaskPrefix(checkForPrefixMask(network)); } } if(prefixLen < 0) { return null; } return prefixLen; }
java
{ "resource": "" }
q7658
IPAddressSection.containsNonZeroHosts
train
public boolean containsNonZeroHosts(IPAddressSection other) { if(!other.isPrefixed()) { return contains(other); } int otherPrefixLength = other.getNetworkPrefixLength(); if(otherPrefixLength == other.getBitCount()) { return contains(other); } return containsNonZeroHostsImpl(other, otherPrefixLength); }
java
{ "resource": "" }
q7659
IPAddressSection.matchesWithMask
train
public boolean matchesWithMask(IPAddressSection other, IPAddressSection mask) { checkMaskSectionCount(mask); checkSectionCount(other); int divCount = getSegmentCount(); for(int i = 0; i < divCount; i++) { IPAddressSegment div = getSegment(i); IPAddressSegment maskSegment = mask.getSegment(i); IPAddressSegment otherSegment = other.getSegment(i); if(!div.matchesWithMask( otherSegment.getSegmentValue(), otherSegment.getUpperSegmentValue(), maskSegment.getSegmentValue())) { return false; } } return true; }
java
{ "resource": "" }
q7660
IPAddressSection.toHexString
train
protected String toHexString(boolean with0xPrefix, CharSequence zone) { if(isDualString()) { return toNormalizedStringRange(toIPParams(with0xPrefix ? IPStringCache.hexPrefixedParams : IPStringCache.hexParams), getLower(), getUpper(), zone); } return toIPParams(with0xPrefix ? IPStringCache.hexPrefixedParams : IPStringCache.hexParams).toString(this, zone); }
java
{ "resource": "" }
q7661
IPv6Address.getEmbeddedIPv4Address
train
public IPv4Address getEmbeddedIPv4Address(int byteIndex) { if(byteIndex == IPv6Address.MIXED_ORIGINAL_SEGMENT_COUNT * IPv6Address.BYTES_PER_SEGMENT) { return getEmbeddedIPv4Address(); } IPv4AddressCreator creator = getIPv4Network().getAddressCreator(); return creator.createAddress(getSection().getEmbeddedIPv4AddressSection(byteIndex, byteIndex + IPv4Address.BYTE_COUNT)); /* address creation */ }
java
{ "resource": "" }
q7662
IPv6Address.isIPv4Mapped
train
public boolean isIPv4Mapped() { //::ffff:x:x/96 indicates IPv6 address mapped to IPv4 if(getSegment(5).matches(IPv6Address.MAX_VALUE_PER_SEGMENT)) { for(int i = 0; i < 5; i++) { if(!getSegment(i).isZero()) { return false; } } return true; } return false; }
java
{ "resource": "" }
q7663
IPv6Address.isIPv4Compatible
train
public boolean isIPv4Compatible() { return getSegment(0).isZero() && getSegment(1).isZero() && getSegment(2).isZero() && getSegment(3).isZero() && getSegment(4).isZero() && getSegment(5).isZero(); }
java
{ "resource": "" }
q7664
IPv6Address.isWellKnownIPv4Translatable
train
public boolean isWellKnownIPv4Translatable() { //rfc 6052 rfc 6144 //64:ff9b::/96 prefix for auto ipv4/ipv6 translation if(getSegment(0).matches(0x64) && getSegment(1).matches(0xff9b)) { for(int i=2; i<=5; i++) { if(!getSegment(i).isZero()) { return false; } } return true; } return false; }
java
{ "resource": "" }
q7665
IPv6Address.toInetAddress
train
@Override public Inet6Address toInetAddress() { if(hasZone()) { Inet6Address result; if(hasNoValueCache() || (result = valueCache.inetAddress) == null) { valueCache.inetAddress = result = (Inet6Address) toInetAddressImpl(getBytes()); } return result; } return (Inet6Address) super.toInetAddress(); }
java
{ "resource": "" }
q7666
IPv6Address.toMixedString
train
public String toMixedString() { String result; if(hasNoStringCache() || (result = stringCache.mixedString) == null) { if(hasZone()) { stringCache.mixedString = result = toNormalizedString(IPv6StringCache.mixedParams); } else { result = getSection().toMixedString();//the cache is shared so no need to update it here } } return result; }
java
{ "resource": "" }
q7667
IPv6Address.toNormalizedString
train
@Override public String toNormalizedString() { String result; if(hasNoStringCache() || (result = stringCache.normalizedString) == null) { if(hasZone()) { stringCache.normalizedString = result = toNormalizedString(IPv6StringCache.normalizedParams); } else { result = getSection().toNormalizedString();//the cache is shared so no need to update it here } } return result; }
java
{ "resource": "" }
q7668
IPv6Address.toNormalizedWildcardString
train
@Override public String toNormalizedWildcardString() { String result; if(hasNoStringCache() || (result = stringCache.normalizedWildcardString) == null) { if(hasZone()) { stringCache.normalizedWildcardString = result = toNormalizedString(IPv6StringCache.wildcardNormalizedParams); } else { result = getSection().toNormalizedWildcardString();//the cache is shared so no need to update it here } } return result; }
java
{ "resource": "" }
q7669
IPv6Address.toNormalizedString
train
public String toNormalizedString(boolean keepMixed, IPv6StringOptions params) { if(keepMixed && fromString != null && getAddressfromString().isMixedIPv6() && !params.makeMixed()) { params = new IPv6StringOptions( params.base, params.expandSegments, params.wildcardOption, params.wildcards, params.segmentStrPrefix, true, params.ipv4Opts, params.compressOptions, params.separator, params.zoneSeparator, params.addrLabel, params.addrSuffix, params.reverse, params.splitDigits, params.uppercase); } return toNormalizedString(params); }
java
{ "resource": "" }
q7670
IPv4AddressSection.mask
train
public IPv4AddressSection mask(IPv4AddressSection mask, boolean retainPrefix) throws IncompatibleAddressException, PrefixLenException, SizeMismatchException { checkMaskSectionCount(mask); return getSubnetSegments( this, retainPrefix ? getPrefixLength() : null, getAddressCreator(), true, this::getSegment, i -> mask.getSegment(i).getSegmentValue(), false); }
java
{ "resource": "" }
q7671
IPv4AddressSection.toFullString
train
@Override public String toFullString() { String result; if(hasNoStringCache() || (result = stringCache.fullString) == null) { stringCache.fullString = result = toNormalizedString(IPv4StringCache.fullParams); } return result; }
java
{ "resource": "" }
q7672
IPAddressPartConfiguredString.getNetworkStringMatcher
train
@SuppressWarnings("unchecked") public <S extends IPAddressPartConfiguredString<T, P>> SQLStringMatcher<T, P, S> getNetworkStringMatcher(boolean isEntireAddress, IPAddressSQLTranslator translator) { return new SQLStringMatcher<T, P, S>((S) this, isEntireAddress, translator); }
java
{ "resource": "" }
q7673
IPAddressString.isValid
train
public boolean isValid() { if(addressProvider.isUninitialized()) { try { validate(); return true; } catch(AddressStringException e) { return false; } } return !addressProvider.isInvalid(); }
java
{ "resource": "" }
q7674
IPAddressString.compareTo
train
@Override public int compareTo(IPAddressString other) { if(this == other) { return 0; } boolean isValid = isValid(); boolean otherIsValid = other.isValid(); if(!isValid && !otherIsValid) { return toString().compareTo(other.toString()); } return addressProvider.providerCompare(other.addressProvider); }
java
{ "resource": "" }
q7675
IPAddressString.convertToPrefixLength
train
public String convertToPrefixLength() throws AddressStringException { IPAddress address = toAddress(); Integer prefix; if(address == null) { if(isPrefixOnly()) { prefix = getNetworkPrefixLength(); } else { return null; } } else { prefix = address.getBlockMaskPrefixLength(true); if(prefix == null) { return null; } } return IPAddressSegment.toUnsignedString(prefix, 10, new StringBuilder(IPAddressSegment.toUnsignedStringLength(prefix, 10) + 1).append(IPAddress.PREFIX_LEN_SEPARATOR)).toString(); }
java
{ "resource": "" }
q7676
IPAddressDivisionGrouping.getTrailingBitCount
train
public int getTrailingBitCount(boolean network) { int count = getDivisionCount(); if(count == 0) { return 0; } long back = network ? 0 : getDivision(0).getMaxValue(); int bitLen = 0; for(int i = count - 1; i >= 0; i--) { IPAddressDivision seg = getDivision(i); long value = seg.getDivisionValue(); if(value != back) { return bitLen + seg.getTrailingBitCount(network); } bitLen += seg.getBitCount(); } return bitLen; }
java
{ "resource": "" }
q7677
IPAddressDivisionGrouping.getLeadingBitCount
train
public int getLeadingBitCount(boolean network) { int count = getDivisionCount(); if(count == 0) { return 0; } long front = network ? getDivision(0).getMaxValue() : 0; int prefixLen = 0; for(int i = 0; i < count; i++) { IPAddressDivision seg = getDivision(i); long value = seg.getDivisionValue(); if(value != front) { return prefixLen + seg.getLeadingBitCount(network); } prefixLen += seg.getBitCount(); } return prefixLen; }
java
{ "resource": "" }
q7678
IPAddressDivisionGrouping.isPrefixBlock
train
@Override public boolean isPrefixBlock() { Integer networkPrefixLength = getNetworkPrefixLength(); if(networkPrefixLength == null) { return false; } if(getNetwork().getPrefixConfiguration().allPrefixedAddressesAreSubnets()) { return true; } return containsPrefixBlock(networkPrefixLength); }
java
{ "resource": "" }
q7679
IPAddressDivisionGrouping.isSinglePrefixBlock
train
@Override public boolean isSinglePrefixBlock() { Integer networkPrefixLength = getNetworkPrefixLength(); if(networkPrefixLength == null) { return false; } return containsSinglePrefixBlock(networkPrefixLength); }
java
{ "resource": "" }
q7680
IPv4Address.getIPv6Address
train
public IPv6Address getIPv6Address(IPv6AddressSegment segs[]) { IPv6AddressCreator creator = getIPv6Network().getAddressCreator(); return creator.createAddress(IPv6AddressSection.createSection(creator, segs, this)); /* address creation */ }
java
{ "resource": "" }
q7681
IPv4Address.isPrivate
train
public boolean isPrivate() { // refer to RFC 1918 // 10/8 prefix // 172.16/12 prefix (172.16.0.0 – 172.31.255.255) // 192.168/16 prefix IPv4AddressSegment seg0 = getSegment(0); IPv4AddressSegment seg1 = getSegment(1); return seg0.matches(10) || seg0.matches(172) && seg1.matchesWithPrefixMask(16, 4) || seg0.matches(192) && seg1.matches(168); }
java
{ "resource": "" }
q7682
JacksonJsonLogger.unableToParseValue
train
public SpinJsonDataFormatException unableToParseValue(String expectedType, JsonNodeType type) { return new SpinJsonDataFormatException(exceptionMessage("002", "Expected '{}', got '{}'", expectedType, type.toString())); }
java
{ "resource": "" }
q7683
DomXmlElement.adoptElement
train
protected void adoptElement(DomXmlElement elementToAdopt) { Document document = this.domElement.getOwnerDocument(); Element element = elementToAdopt.domElement; if (!document.equals(element.getOwnerDocument())) { Node node = document.adoptNode(element); if (node == null) { throw LOG.unableToAdoptElement(elementToAdopt); } } }
java
{ "resource": "" }
q7684
DomXmlEnsure.ensureChildElement
train
public static void ensureChildElement(DomXmlElement parentElement, DomXmlElement childElement) { Node parent = childElement.unwrap().getParentNode(); if (parent == null || !parentElement.unwrap().isEqualNode(parent)) { throw LOG.elementIsNotChildOfThisElement(childElement, parentElement); } }
java
{ "resource": "" }
q7685
DomXmlEnsure.ensureXPathNotNull
train
public static void ensureXPathNotNull(Node node, String expression) { if (node == null) { throw LOG.unableToFindXPathExpression(expression); } }
java
{ "resource": "" }
q7686
DomXmlEnsure.ensureXPathNotEmpty
train
public static void ensureXPathNotEmpty(NodeList nodeList, String expression) { if (nodeList == null || nodeList.getLength() == 0) { throw LOG.unableToFindXPathExpression(expression); } }
java
{ "resource": "" }
q7687
JacksonJsonDataFormat.getCanonicalTypeName
train
public String getCanonicalTypeName(Object object) { ensureNotNull("object", object); for (TypeDetector typeDetector : typeDetectors) { if (typeDetector.canHandle(object)) { return typeDetector.detectType(object); } } throw LOG.unableToDetectCanonicalType(object); }
java
{ "resource": "" }
q7688
DomXmlDataFormatWriter.getTransformer
train
protected Transformer getTransformer() { TransformerFactory transformerFactory = domXmlDataFormat.getTransformerFactory(); try { Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); return transformer; } catch (TransformerConfigurationException e) { throw LOG.unableToCreateTransformer(e); } }
java
{ "resource": "" }
q7689
SpinReflectUtil.loadClass
train
public static Class<?> loadClass(String classname, DataFormat<?> dataFormat) { // first try context classoader ClassLoader cl = Thread.currentThread().getContextClassLoader(); if(cl != null) { LOG.tryLoadingClass(classname, cl); try { return cl.loadClass(classname); } catch(Exception e) { // ignore } } // else try the classloader which loaded the dataformat cl = dataFormat.getClass().getClassLoader(); try { LOG.tryLoadingClass(classname, cl); return cl.loadClass(classname); } catch (ClassNotFoundException e) { throw LOG.classNotFound(classname, e); } }
java
{ "resource": "" }
q7690
SpinScriptEnv.getExtension
train
public static String getExtension(String language) { language = language.toLowerCase(); if("ecmascript".equals(language)) { language = "javascript"; } return extensions.get(language); }
java
{ "resource": "" }
q7691
SpinScriptEnv.get
train
public static String get(String language) { language = language.toLowerCase(); if("ecmascript".equals(language)) { language = "javascript"; } String extension = extensions.get(language); if(extension == null) { return null; } else { return loadScriptEnv(language, extension); } }
java
{ "resource": "" }
q7692
JacksonJsonNode.getCorrectIndex
train
protected Integer getCorrectIndex(Integer index) { Integer size = jsonNode.size(); Integer newIndex = index; // reverse walking through the array if(index < 0) { newIndex = size + index; } // the negative index would be greater than the size a second time! if(newIndex < 0) { throw LOG.indexOutOfBounds(index, size); } // the index is greater as the actual size if(index > size) { throw LOG.indexOutOfBounds(index, size); } return newIndex; }
java
{ "resource": "" }
q7693
DomXPathNamespaceResolver.setNamespace
train
public void setNamespace(String prefix, String namespaceURI) { ensureNotNull("Prefix", prefix); ensureNotNull("Namespace URI", namespaceURI); namespaces.put(prefix, namespaceURI); }
java
{ "resource": "" }
q7694
Spin.S
train
public static <T extends Spin<?>> T S(Object input, DataFormat<T> format) { return SpinFactory.INSTANCE.createSpin(input, format); }
java
{ "resource": "" }
q7695
Spin.XML
train
public static SpinXmlElement XML(Object input) { return SpinFactory.INSTANCE.createSpin(input, DataFormats.xml()); }
java
{ "resource": "" }
q7696
Spin.JSON
train
public static SpinJsonNode JSON(Object input) { return SpinFactory.INSTANCE.createSpin(input, DataFormats.json()); }
java
{ "resource": "" }
q7697
DatastoreEmulator.stop
train
public synchronized void stop() throws DatastoreEmulatorException { // We intentionally don't check the internal state. If people want to try and stop the server // multiple times that's fine. stopEmulatorInternal(); if (state != State.STOPPED) { state = State.STOPPED; if (projectDirectory != null) { try { Process process = new ProcessBuilder("rm", "-r", projectDirectory.getAbsolutePath()).start(); if (process.waitFor() != 0) { throw new IOException( "Temporary project directory deletion exited with " + process.exitValue()); } } catch (IOException e) { throw new IllegalStateException("Could not delete temporary project directory", e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IllegalStateException("Could not delete temporary project directory", e); } } } }
java
{ "resource": "" }
q7698
DatastoreEmulator.sendEmptyRequest
train
private void sendEmptyRequest(String path, String method) throws DatastoreEmulatorException { HttpURLConnection connection = null; try { URL url = new URL(this.host + path); connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setRequestMethod(method); connection.getOutputStream().close(); if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { throw new DatastoreEmulatorException( String.format( "%s request to %s returned HTTP status %s", method, path, connection.getResponseCode())); } } catch (IOException e) { throw new DatastoreEmulatorException( String.format("Exception connecting to emulator on %s request to %s", method, path), e); } finally { if (connection != null) { connection.disconnect(); } } }
java
{ "resource": "" }
q7699
RemoteRpc.call
train
public InputStream call(String methodName, MessageLite request) throws DatastoreException { logger.fine("remote datastore call " + methodName); long startTime = System.currentTimeMillis(); try { HttpResponse httpResponse; try { rpcCount.incrementAndGet(); ProtoHttpContent payload = new ProtoHttpContent(request); HttpRequest httpRequest = client.buildPostRequest(resolveURL(methodName), payload); httpRequest.getHeaders().put(API_FORMAT_VERSION_HEADER, API_FORMAT_VERSION); // Don't throw an HTTPResponseException on error. It converts the response to a String and // throws away the original, whereas we need the raw bytes to parse it as a proto. httpRequest.setThrowExceptionOnExecuteError(false); // Datastore requests typically time out after 60s; set the read timeout to slightly longer // than that by default (can be overridden via the HttpRequestInitializer). httpRequest.setReadTimeout(65 * 1000); if (initializer != null) { initializer.initialize(httpRequest); } httpResponse = httpRequest.execute(); if (!httpResponse.isSuccessStatusCode()) { try (InputStream content = GzipFixingInputStream.maybeWrap(httpResponse.getContent())) { throw makeException(url, methodName, content, httpResponse.getContentType(), httpResponse.getContentCharset(), null, httpResponse.getStatusCode()); } } return GzipFixingInputStream.maybeWrap(httpResponse.getContent()); } catch (SocketTimeoutException e) { throw makeException(url, methodName, Code.DEADLINE_EXCEEDED, "Deadline exceeded", e); } catch (IOException e) { throw makeException(url, methodName, Code.UNAVAILABLE, "I/O error", e); } } finally { long elapsedTime = System.currentTimeMillis() - startTime; logger.fine("remote datastore call " + methodName + " took " + elapsedTime + " ms"); } }
java
{ "resource": "" }