id
int32
0
165k
repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
sequence
docstring
stringlengths
3
16k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
105
339
164,100
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6AddressSection.java
IPv6AddressSection.toEUISegments
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
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; }
[ "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", ";", "}" ]
prefix length in this section is ignored when converting to MAC
[ "prefix", "length", "in", "this", "section", "is", "ignored", "when", "converting", "to", "MAC" ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6AddressSection.java#L1174-L1245
164,101
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6AddressSection.java
IPv6AddressSection.getEmbeddedIPv4AddressSection
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
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); }
[ "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", ")", ";", "}" ]
Produces an IPv4 address section from any sequence of bytes in this IPv6 address section @param startIndex the byte index in this section to start from @param endIndex the byte index in this section to end at @throws IndexOutOfBoundsException @return @see #getEmbeddedIPv4AddressSection() @see #getMixedAddressSection()
[ "Produces", "an", "IPv4", "address", "section", "from", "any", "sequence", "of", "bytes", "in", "this", "IPv6", "address", "section" ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6AddressSection.java#L1258-L1276
164,102
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6AddressSection.java
IPv6AddressSection.hasUppercaseVariations
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
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; }
[ "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", ";", "}" ]
Returns whether this subnet or address has alphabetic digits when printed. Note that this method does not indicate whether any address contained within this subnet has alphabetic digits, only whether the subnet itself when printed has alphabetic digits. @return whether the section has alphabetic digits when printed.
[ "Returns", "whether", "this", "subnet", "or", "address", "has", "alphabetic", "digits", "when", "printed", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6AddressSection.java#L1410-L1421
164,103
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6AddressSection.java
IPv6AddressSection.mergeToSequentialBlocks
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
public IPv6AddressSection[] mergeToSequentialBlocks(IPv6AddressSection ...sections) throws SizeMismatchException { List<IPAddressSegmentSeries> blocks = getMergedSequentialBlocks(this, sections, true, createSeriesCreator(getAddressCreator(), getMaxSegmentValue())); return blocks.toArray(new IPv6AddressSection[blocks.size()]); }
[ "public", "IPv6AddressSection", "[", "]", "mergeToSequentialBlocks", "(", "IPv6AddressSection", "...", "sections", ")", "throws", "SizeMismatchException", "{", "List", "<", "IPAddressSegmentSeries", ">", "blocks", "=", "getMergedSequentialBlocks", "(", "this", ",", "sections", ",", "true", ",", "createSeriesCreator", "(", "getAddressCreator", "(", ")", ",", "getMaxSegmentValue", "(", ")", ")", ")", ";", "return", "blocks", ".", "toArray", "(", "new", "IPv6AddressSection", "[", "blocks", ".", "size", "(", ")", "]", ")", ";", "}" ]
Merges this with the list of sections to produce the smallest array of sequential block subnets, going from smallest to largest @param sections the sections to merge with this @return
[ "Merges", "this", "with", "the", "list", "of", "sections", "to", "produce", "the", "smallest", "array", "of", "sequential", "block", "subnets", "going", "from", "smallest", "to", "largest" ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6AddressSection.java#L2067-L2070
164,104
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6AddressSection.java
IPv6AddressSection.toCanonicalString
@Override public String toCanonicalString() { String result; if(hasNoStringCache() || (result = stringCache.canonicalString) == null) { stringCache.canonicalString = result = toNormalizedString(IPv6StringCache.canonicalParams); } return result; }
java
@Override public String toCanonicalString() { String result; if(hasNoStringCache() || (result = stringCache.canonicalString) == null) { stringCache.canonicalString = result = toNormalizedString(IPv6StringCache.canonicalParams); } return result; }
[ "@", "Override", "public", "String", "toCanonicalString", "(", ")", "{", "String", "result", ";", "if", "(", "hasNoStringCache", "(", ")", "||", "(", "result", "=", "stringCache", ".", "canonicalString", ")", "==", "null", ")", "{", "stringCache", ".", "canonicalString", "=", "result", "=", "toNormalizedString", "(", "IPv6StringCache", ".", "canonicalParams", ")", ";", "}", "return", "result", ";", "}" ]
This produces a canonical string. RFC 5952 describes canonical representations. http://en.wikipedia.org/wiki/IPv6_address#Recommended_representation_as_text http://tools.ietf.org/html/rfc5952
[ "This", "produces", "a", "canonical", "string", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6AddressSection.java#L2111-L2118
164,105
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6AddressSection.java
IPv6AddressSection.toFullString
@Override public String toFullString() { String result; if(hasNoStringCache() || (result = getStringCache().fullString) == null) { getStringCache().fullString = result = toNormalizedString(IPv6StringCache.fullParams); } return result; }
java
@Override public String toFullString() { String result; if(hasNoStringCache() || (result = getStringCache().fullString) == null) { getStringCache().fullString = result = toNormalizedString(IPv6StringCache.fullParams); } return result; }
[ "@", "Override", "public", "String", "toFullString", "(", ")", "{", "String", "result", ";", "if", "(", "hasNoStringCache", "(", ")", "||", "(", "result", "=", "getStringCache", "(", ")", ".", "fullString", ")", "==", "null", ")", "{", "getStringCache", "(", ")", ".", "fullString", "=", "result", "=", "toNormalizedString", "(", "IPv6StringCache", ".", "fullParams", ")", ";", "}", "return", "result", ";", "}" ]
This produces a string with no compressed segments and all segments of full length, which is 4 characters for IPv6 segments and 3 characters for IPv4 segments.
[ "This", "produces", "a", "string", "with", "no", "compressed", "segments", "and", "all", "segments", "of", "full", "length", "which", "is", "4", "characters", "for", "IPv6", "segments", "and", "3", "characters", "for", "IPv4", "segments", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6AddressSection.java#L2135-L2142
164,106
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6AddressSection.java
IPv6AddressSection.toNormalizedString
@Override public String toNormalizedString() { String result; if(hasNoStringCache() || (result = getStringCache().normalizedString) == null) { getStringCache().normalizedString = result = toNormalizedString(IPv6StringCache.normalizedParams); } return result; }
java
@Override public String toNormalizedString() { String result; if(hasNoStringCache() || (result = getStringCache().normalizedString) == null) { getStringCache().normalizedString = result = toNormalizedString(IPv6StringCache.normalizedParams); } return result; }
[ "@", "Override", "public", "String", "toNormalizedString", "(", ")", "{", "String", "result", ";", "if", "(", "hasNoStringCache", "(", ")", "||", "(", "result", "=", "getStringCache", "(", ")", ".", "normalizedString", ")", "==", "null", ")", "{", "getStringCache", "(", ")", ".", "normalizedString", "=", "result", "=", "toNormalizedString", "(", "IPv6StringCache", ".", "normalizedParams", ")", ";", "}", "return", "result", ";", "}" ]
The normalized string returned by this method is consistent with java.net.Inet6address. IPs are not compressed nor mixed in this representation.
[ "The", "normalized", "string", "returned", "by", "this", "method", "is", "consistent", "with", "java", ".", "net", ".", "Inet6address", ".", "IPs", "are", "not", "compressed", "nor", "mixed", "in", "this", "representation", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6AddressSection.java#L2198-L2205
164,107
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6AddressSection.java
IPv6AddressSection.getCompressIndexAndCount
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
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; }
[ "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", ";", "}" ]
Chooses a single segment to be compressed, or null if no segment could be chosen. @param options @param createMixed @return
[ "Chooses", "a", "single", "segment", "to", "be", "compressed", "or", "null", "if", "no", "segment", "could", "be", "chosen", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6AddressSection.java#L2731-L2774
164,108
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/format/validate/ParsedAddressGrouping.java
ParsedAddressGrouping.getHostSegmentIndex
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
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; }
[ "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", ";", "}" ]
Returns the index of the segment containing the first byte outside the network prefix. When networkPrefixLength is null, or it matches or exceeds the bit length, returns the segment count. @param networkPrefixLength @param byteLength @return
[ "Returns", "the", "index", "of", "the", "segment", "containing", "the", "first", "byte", "outside", "the", "network", "prefix", ".", "When", "networkPrefixLength", "is", "null", "or", "it", "matches", "or", "exceeds", "the", "bit", "length", "returns", "the", "segment", "count", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/validate/ParsedAddressGrouping.java#L52-L60
164,109
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/MACAddressString.java
MACAddressString.validate
@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
@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; } } }
[ "@", "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", ";", "}", "}", "}" ]
Validates this string is a valid address, and if not, throws an exception with a descriptive message indicating why it is not. @throws AddressStringException
[ "Validates", "this", "string", "is", "a", "valid", "address", "and", "if", "not", "throws", "an", "exception", "with", "a", "descriptive", "message", "indicating", "why", "it", "is", "not", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/MACAddressString.java#L243-L262
164,110
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSegment.java
IPAddressSegment.isChangedByMask
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
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); }
[ "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), \r", "//but we use the lowest value (maskSegment.value) in the range when masking (ie we discard the range)\r", "int", "value", "=", "getSegmentValue", "(", ")", ";", "int", "upperValue", "=", "getUpperSegmentValue", "(", ")", ";", "return", "value", "!=", "(", "value", "&", "maskValue", ")", "||", "upperValue", "!=", "(", "upperValue", "&", "maskValue", ")", "||", "(", "isPrefixed", "(", ")", "?", "!", "getSegmentPrefixLength", "(", ")", ".", "equals", "(", "segmentPrefixLength", ")", ":", "hasBits", ")", ";", "}" ]
returns a new segment masked by the given mask This method applies the mask first to every address in the range, and it does not preserve any existing prefix. The given prefix will be applied to the range of addresses after the mask. If the combination of the two does not result in a contiguous range, then {@link IncompatibleAddressException} is thrown.
[ "returns", "a", "new", "segment", "masked", "by", "the", "given", "mask" ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSegment.java#L273-L286
164,111
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSegment.java
IPAddressSegment.isMaskCompatibleWithRange
public boolean isMaskCompatibleWithRange(int maskValue, Integer segmentPrefixLength) throws PrefixLenException { if(!isMultiple()) { return true; } return super.isMaskCompatibleWithRange(maskValue, segmentPrefixLength, getNetwork().getPrefixConfiguration().allPrefixedAddressesAreSubnets()); }
java
public boolean isMaskCompatibleWithRange(int maskValue, Integer segmentPrefixLength) throws PrefixLenException { if(!isMultiple()) { return true; } return super.isMaskCompatibleWithRange(maskValue, segmentPrefixLength, getNetwork().getPrefixConfiguration().allPrefixedAddressesAreSubnets()); }
[ "public", "boolean", "isMaskCompatibleWithRange", "(", "int", "maskValue", ",", "Integer", "segmentPrefixLength", ")", "throws", "PrefixLenException", "{", "if", "(", "!", "isMultiple", "(", ")", ")", "{", "return", "true", ";", "}", "return", "super", ".", "isMaskCompatibleWithRange", "(", "maskValue", ",", "segmentPrefixLength", ",", "getNetwork", "(", ")", ".", "getPrefixConfiguration", "(", ")", ".", "allPrefixedAddressesAreSubnets", "(", ")", ")", ";", "}" ]
Check that the range resulting from the mask is contiguous, otherwise we cannot represent it. For instance, for the range 0 to 3 (bits are 00 to 11), if we mask all 4 numbers from 0 to 3 with 2 (ie bits are 10), then we are left with 1 and 3. 2 is not included. So we cannot represent 1 and 3 as a contiguous range. The underlying rule is that mask bits that are 0 must be above the resulting range in each segment. Any bit in the mask that is 0 must not fall below any bit in the masked segment range that is different between low and high. Any network mask must eliminate the entire segment range. Any host mask is fine. @param maskValue @param segmentPrefixLength @return @throws PrefixLenException
[ "Check", "that", "the", "range", "resulting", "from", "the", "mask", "is", "contiguous", "otherwise", "we", "cannot", "represent", "it", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSegment.java#L320-L325
164,112
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSegment.java
IPAddressSegment.isBitwiseOrCompatibleWithRange
public boolean isBitwiseOrCompatibleWithRange(int maskValue, Integer segmentPrefixLength) throws PrefixLenException { return super.isBitwiseOrCompatibleWithRange(maskValue, segmentPrefixLength, getNetwork().getPrefixConfiguration().allPrefixedAddressesAreSubnets()); }
java
public boolean isBitwiseOrCompatibleWithRange(int maskValue, Integer segmentPrefixLength) throws PrefixLenException { return super.isBitwiseOrCompatibleWithRange(maskValue, segmentPrefixLength, getNetwork().getPrefixConfiguration().allPrefixedAddressesAreSubnets()); }
[ "public", "boolean", "isBitwiseOrCompatibleWithRange", "(", "int", "maskValue", ",", "Integer", "segmentPrefixLength", ")", "throws", "PrefixLenException", "{", "return", "super", ".", "isBitwiseOrCompatibleWithRange", "(", "maskValue", ",", "segmentPrefixLength", ",", "getNetwork", "(", ")", ".", "getPrefixConfiguration", "(", ")", ".", "allPrefixedAddressesAreSubnets", "(", ")", ")", ";", "}" ]
Similar to masking, checks that the range resulting from the bitwise or is contiguous. @param maskValue @param segmentPrefixLength @return @throws PrefixLenException
[ "Similar", "to", "masking", "checks", "that", "the", "range", "resulting", "from", "the", "bitwise", "or", "is", "contiguous", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSegment.java#L335-L337
164,113
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/ipv4/IPv4AddressSegment.java
IPv4AddressSegment.join
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
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); }
[ "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, \r", "//otherwise it is not possible to create an equivalent range when joining\r", "if", "(", "!", "low", ".", "isFullRange", "(", ")", ")", "{", "throw", "new", "IncompatibleAddressException", "(", "this", ",", "low", ",", "\"ipaddress.error.invalidMixedRange\"", ")", ";", "}", "}", "return", "creator", ".", "createSegment", "(", "(", "getSegmentValue", "(", ")", "<<", "shift", ")", "|", "low", ".", "getSegmentValue", "(", ")", ",", "(", "getUpperSegmentValue", "(", ")", "<<", "shift", ")", "|", "low", ".", "getUpperSegmentValue", "(", ")", ",", "prefix", ")", ";", "}" ]
Joins with another IPv4 segment to produce a IPv6 segment. @param creator @param low @return
[ "Joins", "with", "another", "IPv4", "segment", "to", "produce", "a", "IPv6", "segment", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv4/IPv4AddressSegment.java#L306-L320
164,114
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddress.java
IPAddress.toHostName
public HostName toHostName() { HostName host = fromHost; if(host == null) { fromHost = host = toCanonicalHostName(); } return host; }
java
public HostName toHostName() { HostName host = fromHost; if(host == null) { fromHost = host = toCanonicalHostName(); } return host; }
[ "public", "HostName", "toHostName", "(", ")", "{", "HostName", "host", "=", "fromHost", ";", "if", "(", "host", "==", "null", ")", "{", "fromHost", "=", "host", "=", "toCanonicalHostName", "(", ")", ";", "}", "return", "host", ";", "}" ]
If this address was resolved from a host, returns that host. Otherwise, does a reverse name lookup.
[ "If", "this", "address", "was", "resolved", "from", "a", "host", "returns", "that", "host", ".", "Otherwise", "does", "a", "reverse", "name", "lookup", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddress.java#L164-L170
164,115
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddress.java
IPAddress.matchesWithMask
public boolean matchesWithMask(IPAddress other, IPAddress mask) { return getSection().matchesWithMask(other.getSection(), mask.getSection()); }
java
public boolean matchesWithMask(IPAddress other, IPAddress mask) { return getSection().matchesWithMask(other.getSection(), mask.getSection()); }
[ "public", "boolean", "matchesWithMask", "(", "IPAddress", "other", ",", "IPAddress", "mask", ")", "{", "return", "getSection", "(", ")", ".", "matchesWithMask", "(", "other", ".", "getSection", "(", ")", ",", "mask", ".", "getSection", "(", ")", ")", ";", "}" ]
Applies the mask to this address and then compares values with the given address @param mask @param other @return
[ "Applies", "the", "mask", "to", "this", "address", "and", "then", "compares", "values", "with", "the", "given", "address" ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddress.java#L592-L594
164,116
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/mac/MACAddress.java
MACAddress.toLinkLocalIPv6
public IPv6Address toLinkLocalIPv6() { IPv6AddressNetwork network = getIPv6Network(); IPv6AddressSection linkLocalPrefix = network.getLinkLocalPrefix(); IPv6AddressCreator creator = network.getAddressCreator(); return creator.createAddress(linkLocalPrefix.append(toEUI64IPv6())); }
java
public IPv6Address toLinkLocalIPv6() { IPv6AddressNetwork network = getIPv6Network(); IPv6AddressSection linkLocalPrefix = network.getLinkLocalPrefix(); IPv6AddressCreator creator = network.getAddressCreator(); return creator.createAddress(linkLocalPrefix.append(toEUI64IPv6())); }
[ "public", "IPv6Address", "toLinkLocalIPv6", "(", ")", "{", "IPv6AddressNetwork", "network", "=", "getIPv6Network", "(", ")", ";", "IPv6AddressSection", "linkLocalPrefix", "=", "network", ".", "getLinkLocalPrefix", "(", ")", ";", "IPv6AddressCreator", "creator", "=", "network", ".", "getAddressCreator", "(", ")", ";", "return", "creator", ".", "createAddress", "(", "linkLocalPrefix", ".", "append", "(", "toEUI64IPv6", "(", ")", ")", ")", ";", "}" ]
Converts to a link-local Ipv6 address. Any MAC prefix length is ignored. Other elements of this address section are incorporated into the conversion. This will provide the latter 4 segments of an IPv6 address, to be paired with the link-local IPv6 prefix of 4 segments. @return
[ "Converts", "to", "a", "link", "-", "local", "Ipv6", "address", ".", "Any", "MAC", "prefix", "length", "is", "ignored", ".", "Other", "elements", "of", "this", "address", "section", "are", "incorporated", "into", "the", "conversion", ".", "This", "will", "provide", "the", "latter", "4", "segments", "of", "an", "IPv6", "address", "to", "be", "paired", "with", "the", "link", "-", "local", "IPv6", "prefix", "of", "4", "segments", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/mac/MACAddress.java#L467-L472
164,117
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/mac/MACAddress.java
MACAddress.toEUI64
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
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"); }
[ "public", "MACAddress", "toEUI64", "(", "boolean", "asMAC", ")", "{", "if", "(", "!", "isExtended", "(", ")", ")", "{", "//getSegmentCount() == EXTENDED_UNIQUE_IDENTIFIER_48_SEGMENT_COUNT\r", "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\r", "}", "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\"", ")", ";", "}" ]
Convert to IPv6 EUI-64 section http://standards.ieee.org/develop/regauth/tut/eui64.pdf @param asMAC if true, this address is considered MAC and the EUI-64 is extended using ff-ff, otherwise this address is considered EUI-48 and extended using ff-fe Note that IPv6 treats MAC as EUI-48 and extends MAC to IPv6 addresses using ff-fe @return
[ "Convert", "to", "IPv6", "EUI", "-", "64", "section" ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/mac/MACAddress.java#L511-L539
164,118
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSeqRange.java
IPAddressSeqRange.prefixIterator
@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
@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(); } }; }
[ "@", "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", "(", ")", ";", "}", "}", ";", "}" ]
Iterates through the range of prefixes in this range instance using the given prefix length. @param prefixLength @return
[ "Iterates", "through", "the", "range", "of", "prefixes", "in", "this", "range", "instance", "using", "the", "given", "prefix", "length", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSeqRange.java#L152-L219
164,119
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSeqRange.java
IPAddressSeqRange.join
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
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; }
[ "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", ";", "}" ]
Joins the given ranges into the fewest number of ranges. If no joining can take place, the original array is returned. @param ranges @return
[ "Joins", "the", "given", "ranges", "into", "the", "fewest", "number", "of", "ranges", ".", "If", "no", "joining", "can", "take", "place", "the", "original", "array", "is", "returned", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSeqRange.java#L450-L489
164,120
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSeqRange.java
IPAddressSeqRange.intersect
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
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); }
[ "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", ")", ";", "}" ]
Returns the intersection of this range with the given range, a range which includes those addresses in both this and the given rqnge. @param other @return
[ "Returns", "the", "intersection", "of", "this", "range", "with", "the", "given", "range", "a", "range", "which", "includes", "those", "addresses", "in", "both", "this", "and", "the", "given", "rqnge", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSeqRange.java#L533-L551
164,121
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSeqRange.java
IPAddressSeqRange.subtract
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
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 } }
[ "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 ", "}", "}" ]
Subtracts the given range from this range, to produce either zero, one, or two address ranges that contain the addresses in this range and not in the given range. If the result has length 2, the two ranges are in increasing order. @param other @return
[ "Subtracts", "the", "given", "range", "from", "this", "range", "to", "produce", "either", "zero", "one", "or", "two", "address", "ranges", "that", "contain", "the", "addresses", "in", "this", "range", "and", "not", "in", "the", "given", "range", ".", "If", "the", "result", "has", "length", "2", "the", "two", "ranges", "are", "in", "increasing", "order", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSeqRange.java#L602-L630
164,122
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSection.java
IPAddressSection.isNetworkSection
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
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); }
[ "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", ")", ";", "}" ]
this method is basically checking whether we can return "this" for getNetworkSection
[ "this", "method", "is", "basically", "checking", "whether", "we", "can", "return", "this", "for", "getNetworkSection" ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSection.java#L258-L271
164,123
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSection.java
IPAddressSection.getBlockMaskPrefixLength
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
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; }
[ "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", ";", "}" ]
If this address section is equivalent to the mask for a CIDR prefix block, it returns that prefix length. Otherwise, it returns null. A CIDR network mask is an address with all 1s in the network section and then all 0s in the host section. A CIDR host mask is an address with all 0s in the network section and then all 1s in the host section. The prefix length is the length of the network section. Also, keep in mind that the prefix length returned by this method is not equivalent to the prefix length used to construct this object. The prefix length used to construct indicates the network and host section of this address. The prefix length returned here indicates the whether the value of this address can be used as a mask for the network and host section of any other address. Therefore the two values can be different values, or one can be null while the other is not. This method applies only to the lower value of the range if this section represents multiple values. @param network whether to check for a network mask or a host mask @return the prefix length corresponding to this mask, or null if there is no such prefix length
[ "If", "this", "address", "section", "is", "equivalent", "to", "the", "mask", "for", "a", "CIDR", "prefix", "block", "it", "returns", "that", "prefix", "length", ".", "Otherwise", "it", "returns", "null", ".", "A", "CIDR", "network", "mask", "is", "an", "address", "with", "all", "1s", "in", "the", "network", "section", "and", "then", "all", "0s", "in", "the", "host", "section", ".", "A", "CIDR", "host", "mask", "is", "an", "address", "with", "all", "0s", "in", "the", "network", "section", "and", "then", "all", "1s", "in", "the", "host", "section", ".", "The", "prefix", "length", "is", "the", "length", "of", "the", "network", "section", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSection.java#L347-L362
164,124
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSection.java
IPAddressSection.containsNonZeroHosts
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
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); }
[ "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", ")", ";", "}" ]
Returns whether this address contains the non-zero host addresses in other. @param other @return
[ "Returns", "whether", "this", "address", "contains", "the", "non", "-", "zero", "host", "addresses", "in", "other", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSection.java#L803-L812
164,125
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSection.java
IPAddressSection.matchesWithMask
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
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; }
[ "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", ";", "}" ]
Applies the mask to this address section and then compares values with the given address section @param mask @param other @return
[ "Applies", "the", "mask", "to", "this", "address", "section", "and", "then", "compares", "values", "with", "the", "given", "address", "section" ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSection.java#L1824-L1840
164,126
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSection.java
IPAddressSection.toHexString
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
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); }
[ "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", ")", ";", "}" ]
overridden in ipv6 to handle zone
[ "overridden", "in", "ipv6", "to", "handle", "zone" ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressSection.java#L2331-L2336
164,127
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6Address.java
IPv6Address.getEmbeddedIPv4Address
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
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 */ }
[ "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 */", "}" ]
Produces an IPv4 address from any sequence of 4 bytes in this IPv6 address. @param byteIndex the byte index to start @throws IndexOutOfBoundsException if the index is less than zero or bigger than 7 @return
[ "Produces", "an", "IPv4", "address", "from", "any", "sequence", "of", "4", "bytes", "in", "this", "IPv6", "address", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6Address.java#L1043-L1049
164,128
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6Address.java
IPv6Address.isIPv4Mapped
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
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; }
[ "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", ";", "}" ]
Whether the address is IPv4-mapped ::ffff:x:x/96 indicates IPv6 address mapped to IPv4
[ "Whether", "the", "address", "is", "IPv4", "-", "mapped" ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6Address.java#L1117-L1128
164,129
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6Address.java
IPv6Address.isIPv4Compatible
public boolean isIPv4Compatible() { return getSegment(0).isZero() && getSegment(1).isZero() && getSegment(2).isZero() && getSegment(3).isZero() && getSegment(4).isZero() && getSegment(5).isZero(); }
java
public boolean isIPv4Compatible() { return getSegment(0).isZero() && getSegment(1).isZero() && getSegment(2).isZero() && getSegment(3).isZero() && getSegment(4).isZero() && getSegment(5).isZero(); }
[ "public", "boolean", "isIPv4Compatible", "(", ")", "{", "return", "getSegment", "(", "0", ")", ".", "isZero", "(", ")", "&&", "getSegment", "(", "1", ")", ".", "isZero", "(", ")", "&&", "getSegment", "(", "2", ")", ".", "isZero", "(", ")", "&&", "getSegment", "(", "3", ")", ".", "isZero", "(", ")", "&&", "getSegment", "(", "4", ")", ".", "isZero", "(", ")", "&&", "getSegment", "(", "5", ")", ".", "isZero", "(", ")", ";", "}" ]
Whether the address is IPv4-compatible @see java.net.Inet6Address#isIPv4CompatibleAddress()
[ "Whether", "the", "address", "is", "IPv4", "-", "compatible" ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6Address.java#L1135-L1138
164,130
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6Address.java
IPv6Address.isWellKnownIPv4Translatable
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
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; }
[ "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", ";", "}" ]
Whether the address has the well-known prefix for IPv4 translatable addresses as in rfc 6052 and 6144 @return
[ "Whether", "the", "address", "has", "the", "well", "-", "known", "prefix", "for", "IPv4", "translatable", "addresses", "as", "in", "rfc", "6052", "and", "6144" ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6Address.java#L1192-L1203
164,131
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6Address.java
IPv6Address.toInetAddress
@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
@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(); }
[ "@", "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", "(", ")", ";", "}" ]
we need to cache the address in here and not in the address section if there is a zone
[ "we", "need", "to", "cache", "the", "address", "in", "here", "and", "not", "in", "the", "address", "section", "if", "there", "is", "a", "zone" ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6Address.java#L1570-L1580
164,132
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6Address.java
IPv6Address.toMixedString
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
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; }
[ "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", ";", "}" ]
Produces a string in which the lower 4 bytes are expressed as an IPv4 address and the remaining upper bytes are expressed in IPv6 format. This the mixed IPv6/IPv4 format described in RFC 1884 https://tools.ietf.org/html/rfc1884 @return
[ "Produces", "a", "string", "in", "which", "the", "lower", "4", "bytes", "are", "expressed", "as", "an", "IPv4", "address", "and", "the", "remaining", "upper", "bytes", "are", "expressed", "in", "IPv6", "format", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6Address.java#L1707-L1717
164,133
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6Address.java
IPv6Address.toNormalizedString
@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
@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; }
[ "@", "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", ";", "}" ]
The normalized string returned by this method is consistent with java.net.Inet6address. IPs are not compressed nor mixed in this representation. If this has a prefix length, that will be included in the string.
[ "The", "normalized", "string", "returned", "by", "this", "method", "is", "consistent", "with", "java", ".", "net", ".", "Inet6address", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6Address.java#L1773-L1784
164,134
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6Address.java
IPv6Address.toNormalizedWildcardString
@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
@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; }
[ "@", "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", ";", "}" ]
note this string is used by hashCode
[ "note", "this", "string", "is", "used", "by", "hashCode" ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6Address.java#L1808-L1819
164,135
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6Address.java
IPv6Address.toNormalizedString
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
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); }
[ "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", ")", ";", "}" ]
Constructs a string representing this address according to the given parameters @param keepMixed if this address was constructed from a string with mixed representation (a:b:c:d:e:f:1.2.3.4), whether to keep it that way (ignored if makeMixed is true in the params argument) @param params the parameters for the address string
[ "Constructs", "a", "string", "representing", "this", "address", "according", "to", "the", "given", "parameters" ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6Address.java#L1968-L1988
164,136
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/ipv4/IPv4AddressSection.java
IPv4AddressSection.mask
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
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); }
[ "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", ")", ";", "}" ]
Does the bitwise conjunction with this address. Useful when subnetting. @param mask @param retainPrefix whether to drop the prefix @return @throws IncompatibleAddressException
[ "Does", "the", "bitwise", "conjunction", "with", "this", "address", ".", "Useful", "when", "subnetting", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv4/IPv4AddressSection.java#L1261-L1271
164,137
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/ipv4/IPv4AddressSection.java
IPv4AddressSection.toFullString
@Override public String toFullString() { String result; if(hasNoStringCache() || (result = stringCache.fullString) == null) { stringCache.fullString = result = toNormalizedString(IPv4StringCache.fullParams); } return result; }
java
@Override public String toFullString() { String result; if(hasNoStringCache() || (result = stringCache.fullString) == null) { stringCache.fullString = result = toNormalizedString(IPv4StringCache.fullParams); } return result; }
[ "@", "Override", "public", "String", "toFullString", "(", ")", "{", "String", "result", ";", "if", "(", "hasNoStringCache", "(", ")", "||", "(", "result", "=", "stringCache", ".", "fullString", ")", "==", "null", ")", "{", "stringCache", ".", "fullString", "=", "result", "=", "toNormalizedString", "(", "IPv4StringCache", ".", "fullParams", ")", ";", "}", "return", "result", ";", "}" ]
This produces a string with no compressed segments and all segments of full length, which is 3 characters for IPv4 segments.
[ "This", "produces", "a", "string", "with", "no", "compressed", "segments", "and", "all", "segments", "of", "full", "length", "which", "is", "3", "characters", "for", "IPv4", "segments", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv4/IPv4AddressSection.java#L1554-L1561
164,138
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/format/util/IPAddressPartConfiguredString.java
IPAddressPartConfiguredString.getNetworkStringMatcher
@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
@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); }
[ "@", "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", ")", ";", "}" ]
Provides an object that can build SQL clauses to match this string representation. This method can be overridden for other IP address types to match in their own ways. @param isEntireAddress @param translator @return
[ "Provides", "an", "object", "that", "can", "build", "SQL", "clauses", "to", "match", "this", "string", "representation", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/util/IPAddressPartConfiguredString.java#L61-L64
164,139
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressString.java
IPAddressString.isValid
public boolean isValid() { if(addressProvider.isUninitialized()) { try { validate(); return true; } catch(AddressStringException e) { return false; } } return !addressProvider.isInvalid(); }
java
public boolean isValid() { if(addressProvider.isUninitialized()) { try { validate(); return true; } catch(AddressStringException e) { return false; } } return !addressProvider.isInvalid(); }
[ "public", "boolean", "isValid", "(", ")", "{", "if", "(", "addressProvider", ".", "isUninitialized", "(", ")", ")", "{", "try", "{", "validate", "(", ")", ";", "return", "true", ";", "}", "catch", "(", "AddressStringException", "e", ")", "{", "return", "false", ";", "}", "}", "return", "!", "addressProvider", ".", "isInvalid", "(", ")", ";", "}" ]
Returns whether this is a valid address string format. The accepted IP address formats are: an IPv4 address, an IPv6 address, a network prefix alone, the address representing all addresses of all types, or an empty string. If this method returns false, and you want more details, call validate() and examine the thrown exception. @return whether this is a valid address string format
[ "Returns", "whether", "this", "is", "a", "valid", "address", "string", "format", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressString.java#L382-L392
164,140
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressString.java
IPAddressString.compareTo
@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
@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); }
[ "@", "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", ")", ";", "}" ]
All address strings are comparable. If two address strings are invalid, their strings are compared. Otherwise, address strings are compared according to which type or version of string, and then within each type or version they are compared using the comparison rules for addresses. @param other @return
[ "All", "address", "strings", "are", "comparable", ".", "If", "two", "address", "strings", "are", "invalid", "their", "strings", "are", "compared", ".", "Otherwise", "address", "strings", "are", "compared", "according", "to", "which", "type", "or", "version", "of", "string", "and", "then", "within", "each", "type", "or", "version", "they", "are", "compared", "using", "the", "comparison", "rules", "for", "addresses", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressString.java#L517-L528
164,141
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressString.java
IPAddressString.convertToPrefixLength
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
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(); }
[ "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", "(", ")", ";", "}" ]
Converts this address to a prefix length @return the prefix of the indicated IP type represented by this address or null if this address is valid but cannot be represented by a network prefix length @throws AddressStringException if the address is invalid
[ "Converts", "this", "address", "to", "a", "prefix", "length" ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/IPAddressString.java#L1044-L1061
164,142
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/format/standard/IPAddressDivisionGrouping.java
IPAddressDivisionGrouping.getTrailingBitCount
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
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; }
[ "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", ";", "}" ]
Returns the number of consecutive trailing one or zero bits. If network is true, returns the number of consecutive trailing zero bits. Otherwise, returns the number of consecutive trailing one bits. @param network @return
[ "Returns", "the", "number", "of", "consecutive", "trailing", "one", "or", "zero", "bits", ".", "If", "network", "is", "true", "returns", "the", "number", "of", "consecutive", "trailing", "zero", "bits", ".", "Otherwise", "returns", "the", "number", "of", "consecutive", "trailing", "one", "bits", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/standard/IPAddressDivisionGrouping.java#L177-L193
164,143
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/format/standard/IPAddressDivisionGrouping.java
IPAddressDivisionGrouping.getLeadingBitCount
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
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; }
[ "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", ";", "}" ]
Returns the number of consecutive leading one or zero bits. If network is true, returns the number of consecutive leading one bits. Otherwise, returns the number of consecutive leading zero bits. @param network @return
[ "Returns", "the", "number", "of", "consecutive", "leading", "one", "or", "zero", "bits", ".", "If", "network", "is", "true", "returns", "the", "number", "of", "consecutive", "leading", "one", "bits", ".", "Otherwise", "returns", "the", "number", "of", "consecutive", "leading", "zero", "bits", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/standard/IPAddressDivisionGrouping.java#L203-L219
164,144
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/format/standard/IPAddressDivisionGrouping.java
IPAddressDivisionGrouping.isPrefixBlock
@Override public boolean isPrefixBlock() { Integer networkPrefixLength = getNetworkPrefixLength(); if(networkPrefixLength == null) { return false; } if(getNetwork().getPrefixConfiguration().allPrefixedAddressesAreSubnets()) { return true; } return containsPrefixBlock(networkPrefixLength); }
java
@Override public boolean isPrefixBlock() { Integer networkPrefixLength = getNetworkPrefixLength(); if(networkPrefixLength == null) { return false; } if(getNetwork().getPrefixConfiguration().allPrefixedAddressesAreSubnets()) { return true; } return containsPrefixBlock(networkPrefixLength); }
[ "@", "Override", "public", "boolean", "isPrefixBlock", "(", ")", "{", "Integer", "networkPrefixLength", "=", "getNetworkPrefixLength", "(", ")", ";", "if", "(", "networkPrefixLength", "==", "null", ")", "{", "return", "false", ";", "}", "if", "(", "getNetwork", "(", ")", ".", "getPrefixConfiguration", "(", ")", ".", "allPrefixedAddressesAreSubnets", "(", ")", ")", "{", "return", "true", ";", "}", "return", "containsPrefixBlock", "(", "networkPrefixLength", ")", ";", "}" ]
Returns whether this address section represents a subnet block of addresses associated its prefix length. Returns false if it has no prefix length, if it is a single address with a prefix length (ie not a subnet), or if it is a range of addresses that does not include the entire subnet block for its prefix length. If {@link AddressNetwork#getPrefixConfiguration} is set to consider all prefixes as subnets, this returns true for any grouping with prefix length. @return
[ "Returns", "whether", "this", "address", "section", "represents", "a", "subnet", "block", "of", "addresses", "associated", "its", "prefix", "length", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/standard/IPAddressDivisionGrouping.java#L231-L241
164,145
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/format/standard/IPAddressDivisionGrouping.java
IPAddressDivisionGrouping.isSinglePrefixBlock
@Override public boolean isSinglePrefixBlock() { Integer networkPrefixLength = getNetworkPrefixLength(); if(networkPrefixLength == null) { return false; } return containsSinglePrefixBlock(networkPrefixLength); }
java
@Override public boolean isSinglePrefixBlock() { Integer networkPrefixLength = getNetworkPrefixLength(); if(networkPrefixLength == null) { return false; } return containsSinglePrefixBlock(networkPrefixLength); }
[ "@", "Override", "public", "boolean", "isSinglePrefixBlock", "(", ")", "{", "Integer", "networkPrefixLength", "=", "getNetworkPrefixLength", "(", ")", ";", "if", "(", "networkPrefixLength", "==", "null", ")", "{", "return", "false", ";", "}", "return", "containsSinglePrefixBlock", "(", "networkPrefixLength", ")", ";", "}" ]
Returns whether the division grouping range matches the block of values for its prefix length. In other words, returns true if and only if it has a prefix length and it has just a single prefix.
[ "Returns", "whether", "the", "division", "grouping", "range", "matches", "the", "block", "of", "values", "for", "its", "prefix", "length", ".", "In", "other", "words", "returns", "true", "if", "and", "only", "if", "it", "has", "a", "prefix", "length", "and", "it", "has", "just", "a", "single", "prefix", "." ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/standard/IPAddressDivisionGrouping.java#L257-L264
164,146
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/ipv4/IPv4Address.java
IPv4Address.getIPv6Address
public IPv6Address getIPv6Address(IPv6AddressSegment segs[]) { IPv6AddressCreator creator = getIPv6Network().getAddressCreator(); return creator.createAddress(IPv6AddressSection.createSection(creator, segs, this)); /* address creation */ }
java
public IPv6Address getIPv6Address(IPv6AddressSegment segs[]) { IPv6AddressCreator creator = getIPv6Network().getAddressCreator(); return creator.createAddress(IPv6AddressSection.createSection(creator, segs, this)); /* address creation */ }
[ "public", "IPv6Address", "getIPv6Address", "(", "IPv6AddressSegment", "segs", "[", "]", ")", "{", "IPv6AddressCreator", "creator", "=", "getIPv6Network", "(", ")", ".", "getAddressCreator", "(", ")", ";", "return", "creator", ".", "createAddress", "(", "IPv6AddressSection", ".", "createSection", "(", "creator", ",", "segs", ",", "this", ")", ")", ";", "/* address creation */", "}" ]
Create an IPv6 mixed address using the given ipv6 segments and using this address for the embedded IPv4 segments @param segs @return
[ "Create", "an", "IPv6", "mixed", "address", "using", "the", "given", "ipv6", "segments", "and", "using", "this", "address", "for", "the", "embedded", "IPv4", "segments" ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv4/IPv4Address.java#L341-L344
164,147
seancfoley/IPAddress
IPAddress/src/inet.ipaddr/inet/ipaddr/ipv4/IPv4Address.java
IPv4Address.isPrivate
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
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); }
[ "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", ")", ";", "}" ]
Unicast addresses allocated for private use @see java.net.InetAddress#isSiteLocalAddress()
[ "Unicast", "addresses", "allocated", "for", "private", "use" ]
90493d0673511d673100c36d020dd93dd870111a
https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv4/IPv4Address.java#L919-L929
164,148
camunda/camunda-spin
dataformat-json-jackson/src/main/java/org/camunda/spin/impl/json/jackson/JacksonJsonLogger.java
JacksonJsonLogger.unableToParseValue
public SpinJsonDataFormatException unableToParseValue(String expectedType, JsonNodeType type) { return new SpinJsonDataFormatException(exceptionMessage("002", "Expected '{}', got '{}'", expectedType, type.toString())); }
java
public SpinJsonDataFormatException unableToParseValue(String expectedType, JsonNodeType type) { return new SpinJsonDataFormatException(exceptionMessage("002", "Expected '{}', got '{}'", expectedType, type.toString())); }
[ "public", "SpinJsonDataFormatException", "unableToParseValue", "(", "String", "expectedType", ",", "JsonNodeType", "type", ")", "{", "return", "new", "SpinJsonDataFormatException", "(", "exceptionMessage", "(", "\"002\"", ",", "\"Expected '{}', got '{}'\"", ",", "expectedType", ",", "type", ".", "toString", "(", ")", ")", ")", ";", "}" ]
Exception handler if we are unable to parse a json value into a java representation @param expectedType Name of the expected Type @param type Type of the json node @return SpinJsonDataFormatException
[ "Exception", "handler", "if", "we", "are", "unable", "to", "parse", "a", "json", "value", "into", "a", "java", "representation" ]
cfe65161eb97fd5023a945cb97c47fbfe69e9fdd
https://github.com/camunda/camunda-spin/blob/cfe65161eb97fd5023a945cb97c47fbfe69e9fdd/dataformat-json-jackson/src/main/java/org/camunda/spin/impl/json/jackson/JacksonJsonLogger.java#L52-L54
164,149
camunda/camunda-spin
dataformat-xml-dom/src/main/java/org/camunda/spin/impl/xml/dom/DomXmlElement.java
DomXmlElement.adoptElement
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
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); } } }
[ "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", ")", ";", "}", "}", "}" ]
Adopts an xml dom element to the owner document of this element if necessary. @param elementToAdopt the element to adopt
[ "Adopts", "an", "xml", "dom", "element", "to", "the", "owner", "document", "of", "this", "element", "if", "necessary", "." ]
cfe65161eb97fd5023a945cb97c47fbfe69e9fdd
https://github.com/camunda/camunda-spin/blob/cfe65161eb97fd5023a945cb97c47fbfe69e9fdd/dataformat-xml-dom/src/main/java/org/camunda/spin/impl/xml/dom/DomXmlElement.java#L357-L367
164,150
camunda/camunda-spin
dataformat-xml-dom/src/main/java/org/camunda/spin/impl/xml/dom/util/DomXmlEnsure.java
DomXmlEnsure.ensureChildElement
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
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); } }
[ "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", ")", ";", "}", "}" ]
Ensures that the element is child element of the parent element. @param parentElement the parent xml dom element @param childElement the child element @throws SpinXmlElementException if the element is not child of the parent element
[ "Ensures", "that", "the", "element", "is", "child", "element", "of", "the", "parent", "element", "." ]
cfe65161eb97fd5023a945cb97c47fbfe69e9fdd
https://github.com/camunda/camunda-spin/blob/cfe65161eb97fd5023a945cb97c47fbfe69e9fdd/dataformat-xml-dom/src/main/java/org/camunda/spin/impl/xml/dom/util/DomXmlEnsure.java#L46-L51
164,151
camunda/camunda-spin
dataformat-xml-dom/src/main/java/org/camunda/spin/impl/xml/dom/util/DomXmlEnsure.java
DomXmlEnsure.ensureXPathNotNull
public static void ensureXPathNotNull(Node node, String expression) { if (node == null) { throw LOG.unableToFindXPathExpression(expression); } }
java
public static void ensureXPathNotNull(Node node, String expression) { if (node == null) { throw LOG.unableToFindXPathExpression(expression); } }
[ "public", "static", "void", "ensureXPathNotNull", "(", "Node", "node", ",", "String", "expression", ")", "{", "if", "(", "node", "==", "null", ")", "{", "throw", "LOG", ".", "unableToFindXPathExpression", "(", "expression", ")", ";", "}", "}" ]
Ensure that the node is not null. @param node the node to ensure to be not null @param expression the expression was used to find the node @throws SpinXPathException if the node is null
[ "Ensure", "that", "the", "node", "is", "not", "null", "." ]
cfe65161eb97fd5023a945cb97c47fbfe69e9fdd
https://github.com/camunda/camunda-spin/blob/cfe65161eb97fd5023a945cb97c47fbfe69e9fdd/dataformat-xml-dom/src/main/java/org/camunda/spin/impl/xml/dom/util/DomXmlEnsure.java#L72-L76
164,152
camunda/camunda-spin
dataformat-xml-dom/src/main/java/org/camunda/spin/impl/xml/dom/util/DomXmlEnsure.java
DomXmlEnsure.ensureXPathNotEmpty
public static void ensureXPathNotEmpty(NodeList nodeList, String expression) { if (nodeList == null || nodeList.getLength() == 0) { throw LOG.unableToFindXPathExpression(expression); } }
java
public static void ensureXPathNotEmpty(NodeList nodeList, String expression) { if (nodeList == null || nodeList.getLength() == 0) { throw LOG.unableToFindXPathExpression(expression); } }
[ "public", "static", "void", "ensureXPathNotEmpty", "(", "NodeList", "nodeList", ",", "String", "expression", ")", "{", "if", "(", "nodeList", "==", "null", "||", "nodeList", ".", "getLength", "(", ")", "==", "0", ")", "{", "throw", "LOG", ".", "unableToFindXPathExpression", "(", "expression", ")", ";", "}", "}" ]
Ensure that the nodeList is either null or empty. @param nodeList the nodeList to ensure to be either null or empty @param expression the expression was used to fine the nodeList @throws SpinXPathException if the nodeList is either null or empty
[ "Ensure", "that", "the", "nodeList", "is", "either", "null", "or", "empty", "." ]
cfe65161eb97fd5023a945cb97c47fbfe69e9fdd
https://github.com/camunda/camunda-spin/blob/cfe65161eb97fd5023a945cb97c47fbfe69e9fdd/dataformat-xml-dom/src/main/java/org/camunda/spin/impl/xml/dom/util/DomXmlEnsure.java#L85-L89
164,153
camunda/camunda-spin
dataformat-json-jackson/src/main/java/org/camunda/spin/impl/json/jackson/format/JacksonJsonDataFormat.java
JacksonJsonDataFormat.getCanonicalTypeName
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
public String getCanonicalTypeName(Object object) { ensureNotNull("object", object); for (TypeDetector typeDetector : typeDetectors) { if (typeDetector.canHandle(object)) { return typeDetector.detectType(object); } } throw LOG.unableToDetectCanonicalType(object); }
[ "public", "String", "getCanonicalTypeName", "(", "Object", "object", ")", "{", "ensureNotNull", "(", "\"object\"", ",", "object", ")", ";", "for", "(", "TypeDetector", "typeDetector", ":", "typeDetectors", ")", "{", "if", "(", "typeDetector", ".", "canHandle", "(", "object", ")", ")", "{", "return", "typeDetector", ".", "detectType", "(", "object", ")", ";", "}", "}", "throw", "LOG", ".", "unableToDetectCanonicalType", "(", "object", ")", ";", "}" ]
Identifies the canonical type of an object heuristically. @return the canonical type identifier of the object's class according to Jackson's type format (see {@link TypeFactory#constructFromCanonical(String)})
[ "Identifies", "the", "canonical", "type", "of", "an", "object", "heuristically", "." ]
cfe65161eb97fd5023a945cb97c47fbfe69e9fdd
https://github.com/camunda/camunda-spin/blob/cfe65161eb97fd5023a945cb97c47fbfe69e9fdd/dataformat-json-jackson/src/main/java/org/camunda/spin/impl/json/jackson/format/JacksonJsonDataFormat.java#L143-L153
164,154
camunda/camunda-spin
dataformat-xml-dom/src/main/java/org/camunda/spin/impl/xml/dom/format/DomXmlDataFormatWriter.java
DomXmlDataFormatWriter.getTransformer
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
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); } }
[ "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", ")", ";", "}", "}" ]
Returns a configured transformer to write XML. @return the XML configured transformer @throws SpinXmlElementException if no new transformer can be created
[ "Returns", "a", "configured", "transformer", "to", "write", "XML", "." ]
cfe65161eb97fd5023a945cb97c47fbfe69e9fdd
https://github.com/camunda/camunda-spin/blob/cfe65161eb97fd5023a945cb97c47fbfe69e9fdd/dataformat-xml-dom/src/main/java/org/camunda/spin/impl/xml/dom/format/DomXmlDataFormatWriter.java#L70-L82
164,155
camunda/camunda-spin
core/src/main/java/org/camunda/spin/impl/util/SpinReflectUtil.java
SpinReflectUtil.loadClass
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
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); } }
[ "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", ")", ";", "}", "}" ]
Used by dataformats if they need to load a class @param classname the name of the @param dataFormat @return
[ "Used", "by", "dataformats", "if", "they", "need", "to", "load", "a", "class" ]
cfe65161eb97fd5023a945cb97c47fbfe69e9fdd
https://github.com/camunda/camunda-spin/blob/cfe65161eb97fd5023a945cb97c47fbfe69e9fdd/core/src/main/java/org/camunda/spin/impl/util/SpinReflectUtil.java#L37-L61
164,156
camunda/camunda-spin
core/src/main/java/org/camunda/spin/scripting/SpinScriptEnv.java
SpinScriptEnv.getExtension
public static String getExtension(String language) { language = language.toLowerCase(); if("ecmascript".equals(language)) { language = "javascript"; } return extensions.get(language); }
java
public static String getExtension(String language) { language = language.toLowerCase(); if("ecmascript".equals(language)) { language = "javascript"; } return extensions.get(language); }
[ "public", "static", "String", "getExtension", "(", "String", "language", ")", "{", "language", "=", "language", ".", "toLowerCase", "(", ")", ";", "if", "(", "\"ecmascript\"", ".", "equals", "(", "language", ")", ")", "{", "language", "=", "\"javascript\"", ";", "}", "return", "extensions", ".", "get", "(", "language", ")", ";", "}" ]
Get file extension for script language. @param language the language name @return the file extension as string or null if the language is not in the set of languages supported by spin
[ "Get", "file", "extension", "for", "script", "language", "." ]
cfe65161eb97fd5023a945cb97c47fbfe69e9fdd
https://github.com/camunda/camunda-spin/blob/cfe65161eb97fd5023a945cb97c47fbfe69e9fdd/core/src/main/java/org/camunda/spin/scripting/SpinScriptEnv.java#L62-L68
164,157
camunda/camunda-spin
core/src/main/java/org/camunda/spin/scripting/SpinScriptEnv.java
SpinScriptEnv.get
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
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); } }
[ "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", ")", ";", "}", "}" ]
Get the spin scripting environment @param language the language name @return the environment script as string or null if the language is not in the set of languages supported by spin.
[ "Get", "the", "spin", "scripting", "environment" ]
cfe65161eb97fd5023a945cb97c47fbfe69e9fdd
https://github.com/camunda/camunda-spin/blob/cfe65161eb97fd5023a945cb97c47fbfe69e9fdd/core/src/main/java/org/camunda/spin/scripting/SpinScriptEnv.java#L77-L91
164,158
camunda/camunda-spin
dataformat-json-jackson/src/main/java/org/camunda/spin/impl/json/jackson/JacksonJsonNode.java
JacksonJsonNode.getCorrectIndex
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
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; }
[ "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", ";", "}" ]
fetch correct array index if index is less than 0 ArrayNode will convert all negative integers into 0... @param index wanted index @return {@link Integer} new index
[ "fetch", "correct", "array", "index", "if", "index", "is", "less", "than", "0" ]
cfe65161eb97fd5023a945cb97c47fbfe69e9fdd
https://github.com/camunda/camunda-spin/blob/cfe65161eb97fd5023a945cb97c47fbfe69e9fdd/dataformat-json-jackson/src/main/java/org/camunda/spin/impl/json/jackson/JacksonJsonNode.java#L92-L112
164,159
camunda/camunda-spin
dataformat-xml-dom/src/main/java/org/camunda/spin/impl/xml/dom/query/DomXPathNamespaceResolver.java
DomXPathNamespaceResolver.setNamespace
public void setNamespace(String prefix, String namespaceURI) { ensureNotNull("Prefix", prefix); ensureNotNull("Namespace URI", namespaceURI); namespaces.put(prefix, namespaceURI); }
java
public void setNamespace(String prefix, String namespaceURI) { ensureNotNull("Prefix", prefix); ensureNotNull("Namespace URI", namespaceURI); namespaces.put(prefix, namespaceURI); }
[ "public", "void", "setNamespace", "(", "String", "prefix", ",", "String", "namespaceURI", ")", "{", "ensureNotNull", "(", "\"Prefix\"", ",", "prefix", ")", ";", "ensureNotNull", "(", "\"Namespace URI\"", ",", "namespaceURI", ")", ";", "namespaces", ".", "put", "(", "prefix", ",", "namespaceURI", ")", ";", "}" ]
Maps a single prefix, uri pair as namespace. @param prefix the prefix to use @param namespaceURI the URI to use @throws IllegalArgumentException if prefix or namespaceURI is null
[ "Maps", "a", "single", "prefix", "uri", "pair", "as", "namespace", "." ]
cfe65161eb97fd5023a945cb97c47fbfe69e9fdd
https://github.com/camunda/camunda-spin/blob/cfe65161eb97fd5023a945cb97c47fbfe69e9fdd/dataformat-xml-dom/src/main/java/org/camunda/spin/impl/xml/dom/query/DomXPathNamespaceResolver.java#L144-L149
164,160
camunda/camunda-spin
core/src/main/java/org/camunda/spin/Spin.java
Spin.S
public static <T extends Spin<?>> T S(Object input, DataFormat<T> format) { return SpinFactory.INSTANCE.createSpin(input, format); }
java
public static <T extends Spin<?>> T S(Object input, DataFormat<T> format) { return SpinFactory.INSTANCE.createSpin(input, format); }
[ "public", "static", "<", "T", "extends", "Spin", "<", "?", ">", ">", "T", "S", "(", "Object", "input", ",", "DataFormat", "<", "T", ">", "format", ")", "{", "return", "SpinFactory", ".", "INSTANCE", ".", "createSpin", "(", "input", ",", "format", ")", ";", "}" ]
Creates a spin wrapper for a data input of a given data format. @param input the input to wrap @param format the data format of the input @return the spin wrapper for the input @throws IllegalArgumentException in case an argument of illegal type is provided (such as 'null')
[ "Creates", "a", "spin", "wrapper", "for", "a", "data", "input", "of", "a", "given", "data", "format", "." ]
cfe65161eb97fd5023a945cb97c47fbfe69e9fdd
https://github.com/camunda/camunda-spin/blob/cfe65161eb97fd5023a945cb97c47fbfe69e9fdd/core/src/main/java/org/camunda/spin/Spin.java#L41-L43
164,161
camunda/camunda-spin
core/src/main/java/org/camunda/spin/Spin.java
Spin.XML
public static SpinXmlElement XML(Object input) { return SpinFactory.INSTANCE.createSpin(input, DataFormats.xml()); }
java
public static SpinXmlElement XML(Object input) { return SpinFactory.INSTANCE.createSpin(input, DataFormats.xml()); }
[ "public", "static", "SpinXmlElement", "XML", "(", "Object", "input", ")", "{", "return", "SpinFactory", ".", "INSTANCE", ".", "createSpin", "(", "input", ",", "DataFormats", ".", "xml", "(", ")", ")", ";", "}" ]
Creates a spin wrapper for a data input. The data format of the input is assumed to be XML. @param input the input to wrap @return the spin wrapper for the input @throws IllegalArgumentException in case an argument of illegal type is provided (such as 'null')
[ "Creates", "a", "spin", "wrapper", "for", "a", "data", "input", ".", "The", "data", "format", "of", "the", "input", "is", "assumed", "to", "be", "XML", "." ]
cfe65161eb97fd5023a945cb97c47fbfe69e9fdd
https://github.com/camunda/camunda-spin/blob/cfe65161eb97fd5023a945cb97c47fbfe69e9fdd/core/src/main/java/org/camunda/spin/Spin.java#L80-L82
164,162
camunda/camunda-spin
core/src/main/java/org/camunda/spin/Spin.java
Spin.JSON
public static SpinJsonNode JSON(Object input) { return SpinFactory.INSTANCE.createSpin(input, DataFormats.json()); }
java
public static SpinJsonNode JSON(Object input) { return SpinFactory.INSTANCE.createSpin(input, DataFormats.json()); }
[ "public", "static", "SpinJsonNode", "JSON", "(", "Object", "input", ")", "{", "return", "SpinFactory", ".", "INSTANCE", ".", "createSpin", "(", "input", ",", "DataFormats", ".", "json", "(", ")", ")", ";", "}" ]
Creates a spin wrapper for a data input. The data format of the input is assumed to be JSON. @param input the input to wrap @return the spin wrapper for the input @throws IllegalArgumentException in case an argument of illegal type is provided (such as 'null')
[ "Creates", "a", "spin", "wrapper", "for", "a", "data", "input", ".", "The", "data", "format", "of", "the", "input", "is", "assumed", "to", "be", "JSON", "." ]
cfe65161eb97fd5023a945cb97c47fbfe69e9fdd
https://github.com/camunda/camunda-spin/blob/cfe65161eb97fd5023a945cb97c47fbfe69e9fdd/core/src/main/java/org/camunda/spin/Spin.java#L93-L95
164,163
GoogleCloudPlatform/google-cloud-datastore
java/datastore/src/main/java/com/google/datastore/v1/client/DatastoreEmulator.java
DatastoreEmulator.stop
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
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); } } } }
[ "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", ")", ";", "}", "}", "}", "}" ]
Stops the emulator. Multiple calls are allowed. @throws DatastoreEmulatorException if the emulator cannot be stopped
[ "Stops", "the", "emulator", ".", "Multiple", "calls", "are", "allowed", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/java/datastore/src/main/java/com/google/datastore/v1/client/DatastoreEmulator.java#L221-L243
164,164
GoogleCloudPlatform/google-cloud-datastore
java/datastore/src/main/java/com/google/datastore/v1/client/DatastoreEmulator.java
DatastoreEmulator.sendEmptyRequest
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
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(); } } }
[ "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", "(", ")", ";", "}", "}", "}" ]
Send an empty request using a standard HTTP connection.
[ "Send", "an", "empty", "request", "using", "a", "standard", "HTTP", "connection", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/java/datastore/src/main/java/com/google/datastore/v1/client/DatastoreEmulator.java#L308-L330
164,165
GoogleCloudPlatform/google-cloud-datastore
java/datastore/src/main/java/com/google/datastore/v1/client/RemoteRpc.java
RemoteRpc.call
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
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"); } }
[ "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\"", ")", ";", "}", "}" ]
Makes an RPC call using the client. Logs how long it took and any exceptions. NOTE: The request could be an InputStream too, but the http client will need to find its length, which will require buffering it anyways. @throws DatastoreException if the RPC fails.
[ "Makes", "an", "RPC", "call", "using", "the", "client", ".", "Logs", "how", "long", "it", "took", "and", "any", "exceptions", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/java/datastore/src/main/java/com/google/datastore/v1/client/RemoteRpc.java#L163-L201
164,166
GoogleCloudPlatform/google-cloud-datastore
java/demos/src/main/java/com/google/datastore/v1/demos/guestbook/Guestbook.java
Guestbook.addGreeting
private void addGreeting(String guestbookName, String user, String message) throws DatastoreException { Entity.Builder greeting = Entity.newBuilder(); greeting.setKey(makeKey(GUESTBOOK_KIND, guestbookName, GREETING_KIND)); greeting.getMutableProperties().put(USER_PROPERTY, makeValue(user).build()); greeting.getMutableProperties().put(MESSAGE_PROPERTY, makeValue(message).build()); greeting.getMutableProperties().put(DATE_PROPERTY, makeValue(new Date()).build()); Key greetingKey = insert(greeting.build()); System.out.println("greeting key is: " + greetingKey); }
java
private void addGreeting(String guestbookName, String user, String message) throws DatastoreException { Entity.Builder greeting = Entity.newBuilder(); greeting.setKey(makeKey(GUESTBOOK_KIND, guestbookName, GREETING_KIND)); greeting.getMutableProperties().put(USER_PROPERTY, makeValue(user).build()); greeting.getMutableProperties().put(MESSAGE_PROPERTY, makeValue(message).build()); greeting.getMutableProperties().put(DATE_PROPERTY, makeValue(new Date()).build()); Key greetingKey = insert(greeting.build()); System.out.println("greeting key is: " + greetingKey); }
[ "private", "void", "addGreeting", "(", "String", "guestbookName", ",", "String", "user", ",", "String", "message", ")", "throws", "DatastoreException", "{", "Entity", ".", "Builder", "greeting", "=", "Entity", ".", "newBuilder", "(", ")", ";", "greeting", ".", "setKey", "(", "makeKey", "(", "GUESTBOOK_KIND", ",", "guestbookName", ",", "GREETING_KIND", ")", ")", ";", "greeting", ".", "getMutableProperties", "(", ")", ".", "put", "(", "USER_PROPERTY", ",", "makeValue", "(", "user", ")", ".", "build", "(", ")", ")", ";", "greeting", ".", "getMutableProperties", "(", ")", ".", "put", "(", "MESSAGE_PROPERTY", ",", "makeValue", "(", "message", ")", ".", "build", "(", ")", ")", ";", "greeting", ".", "getMutableProperties", "(", ")", ".", "put", "(", "DATE_PROPERTY", ",", "makeValue", "(", "new", "Date", "(", ")", ")", ".", "build", "(", ")", ")", ";", "Key", "greetingKey", "=", "insert", "(", "greeting", ".", "build", "(", ")", ")", ";", "System", ".", "out", ".", "println", "(", "\"greeting key is: \"", "+", "greetingKey", ")", ";", "}" ]
Add a greeting to the specified guestbook.
[ "Add", "a", "greeting", "to", "the", "specified", "guestbook", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/java/demos/src/main/java/com/google/datastore/v1/demos/guestbook/Guestbook.java#L112-L121
164,167
GoogleCloudPlatform/google-cloud-datastore
java/demos/src/main/java/com/google/datastore/v1/demos/guestbook/Guestbook.java
Guestbook.listGreetings
private void listGreetings(String guestbookName) throws DatastoreException { Query.Builder query = Query.newBuilder(); query.addKindBuilder().setName(GREETING_KIND); query.setFilter(makeFilter(KEY_PROPERTY, PropertyFilter.Operator.HAS_ANCESTOR, makeValue(makeKey(GUESTBOOK_KIND, guestbookName)))); query.addOrder(makeOrder(DATE_PROPERTY, PropertyOrder.Direction.DESCENDING)); List<Entity> greetings = runQuery(query.build()); if (greetings.size() == 0) { System.out.println("no greetings in " + guestbookName); } for (Entity greeting : greetings) { Map<String, Value> propertyMap = greeting.getProperties(); System.out.println( DatastoreHelper.toDate(propertyMap.get(DATE_PROPERTY)) + ": " + DatastoreHelper.getString(propertyMap.get(USER_PROPERTY)) + " says " + DatastoreHelper.getString(propertyMap.get(MESSAGE_PROPERTY))); } }
java
private void listGreetings(String guestbookName) throws DatastoreException { Query.Builder query = Query.newBuilder(); query.addKindBuilder().setName(GREETING_KIND); query.setFilter(makeFilter(KEY_PROPERTY, PropertyFilter.Operator.HAS_ANCESTOR, makeValue(makeKey(GUESTBOOK_KIND, guestbookName)))); query.addOrder(makeOrder(DATE_PROPERTY, PropertyOrder.Direction.DESCENDING)); List<Entity> greetings = runQuery(query.build()); if (greetings.size() == 0) { System.out.println("no greetings in " + guestbookName); } for (Entity greeting : greetings) { Map<String, Value> propertyMap = greeting.getProperties(); System.out.println( DatastoreHelper.toDate(propertyMap.get(DATE_PROPERTY)) + ": " + DatastoreHelper.getString(propertyMap.get(USER_PROPERTY)) + " says " + DatastoreHelper.getString(propertyMap.get(MESSAGE_PROPERTY))); } }
[ "private", "void", "listGreetings", "(", "String", "guestbookName", ")", "throws", "DatastoreException", "{", "Query", ".", "Builder", "query", "=", "Query", ".", "newBuilder", "(", ")", ";", "query", ".", "addKindBuilder", "(", ")", ".", "setName", "(", "GREETING_KIND", ")", ";", "query", ".", "setFilter", "(", "makeFilter", "(", "KEY_PROPERTY", ",", "PropertyFilter", ".", "Operator", ".", "HAS_ANCESTOR", ",", "makeValue", "(", "makeKey", "(", "GUESTBOOK_KIND", ",", "guestbookName", ")", ")", ")", ")", ";", "query", ".", "addOrder", "(", "makeOrder", "(", "DATE_PROPERTY", ",", "PropertyOrder", ".", "Direction", ".", "DESCENDING", ")", ")", ";", "List", "<", "Entity", ">", "greetings", "=", "runQuery", "(", "query", ".", "build", "(", ")", ")", ";", "if", "(", "greetings", ".", "size", "(", ")", "==", "0", ")", "{", "System", ".", "out", ".", "println", "(", "\"no greetings in \"", "+", "guestbookName", ")", ";", "}", "for", "(", "Entity", "greeting", ":", "greetings", ")", "{", "Map", "<", "String", ",", "Value", ">", "propertyMap", "=", "greeting", ".", "getProperties", "(", ")", ";", "System", ".", "out", ".", "println", "(", "DatastoreHelper", ".", "toDate", "(", "propertyMap", ".", "get", "(", "DATE_PROPERTY", ")", ")", "+", "\": \"", "+", "DatastoreHelper", ".", "getString", "(", "propertyMap", ".", "get", "(", "USER_PROPERTY", ")", ")", "+", "\" says \"", "+", "DatastoreHelper", ".", "getString", "(", "propertyMap", ".", "get", "(", "MESSAGE_PROPERTY", ")", ")", ")", ";", "}", "}" ]
List the greetings in the specified guestbook.
[ "List", "the", "greetings", "in", "the", "specified", "guestbook", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/java/demos/src/main/java/com/google/datastore/v1/demos/guestbook/Guestbook.java#L126-L144
164,168
GoogleCloudPlatform/google-cloud-datastore
java/demos/src/main/java/com/google/datastore/v1/demos/guestbook/Guestbook.java
Guestbook.insert
private Key insert(Entity entity) throws DatastoreException { CommitRequest req = CommitRequest.newBuilder() .addMutations(Mutation.newBuilder() .setInsert(entity)) .setMode(CommitRequest.Mode.NON_TRANSACTIONAL) .build(); return datastore.commit(req).getMutationResults(0).getKey(); }
java
private Key insert(Entity entity) throws DatastoreException { CommitRequest req = CommitRequest.newBuilder() .addMutations(Mutation.newBuilder() .setInsert(entity)) .setMode(CommitRequest.Mode.NON_TRANSACTIONAL) .build(); return datastore.commit(req).getMutationResults(0).getKey(); }
[ "private", "Key", "insert", "(", "Entity", "entity", ")", "throws", "DatastoreException", "{", "CommitRequest", "req", "=", "CommitRequest", ".", "newBuilder", "(", ")", ".", "addMutations", "(", "Mutation", ".", "newBuilder", "(", ")", ".", "setInsert", "(", "entity", ")", ")", ".", "setMode", "(", "CommitRequest", ".", "Mode", ".", "NON_TRANSACTIONAL", ")", ".", "build", "(", ")", ";", "return", "datastore", ".", "commit", "(", "req", ")", ".", "getMutationResults", "(", "0", ")", ".", "getKey", "(", ")", ";", "}" ]
Insert an entity into the datastore. The entity must have no ids. @return The key for the inserted entity. @throws DatastoreException on error
[ "Insert", "an", "entity", "into", "the", "datastore", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/java/demos/src/main/java/com/google/datastore/v1/demos/guestbook/Guestbook.java#L154-L161
164,169
GoogleCloudPlatform/google-cloud-datastore
java/demos/src/main/java/com/google/datastore/v1/demos/guestbook/Guestbook.java
Guestbook.runQuery
private List<Entity> runQuery(Query query) throws DatastoreException { RunQueryRequest.Builder request = RunQueryRequest.newBuilder(); request.setQuery(query); RunQueryResponse response = datastore.runQuery(request.build()); if (response.getBatch().getMoreResults() == QueryResultBatch.MoreResultsType.NOT_FINISHED) { System.err.println("WARNING: partial results\n"); } List<EntityResult> results = response.getBatch().getEntityResultsList(); List<Entity> entities = new ArrayList<Entity>(results.size()); for (EntityResult result : results) { entities.add(result.getEntity()); } return entities; }
java
private List<Entity> runQuery(Query query) throws DatastoreException { RunQueryRequest.Builder request = RunQueryRequest.newBuilder(); request.setQuery(query); RunQueryResponse response = datastore.runQuery(request.build()); if (response.getBatch().getMoreResults() == QueryResultBatch.MoreResultsType.NOT_FINISHED) { System.err.println("WARNING: partial results\n"); } List<EntityResult> results = response.getBatch().getEntityResultsList(); List<Entity> entities = new ArrayList<Entity>(results.size()); for (EntityResult result : results) { entities.add(result.getEntity()); } return entities; }
[ "private", "List", "<", "Entity", ">", "runQuery", "(", "Query", "query", ")", "throws", "DatastoreException", "{", "RunQueryRequest", ".", "Builder", "request", "=", "RunQueryRequest", ".", "newBuilder", "(", ")", ";", "request", ".", "setQuery", "(", "query", ")", ";", "RunQueryResponse", "response", "=", "datastore", ".", "runQuery", "(", "request", ".", "build", "(", ")", ")", ";", "if", "(", "response", ".", "getBatch", "(", ")", ".", "getMoreResults", "(", ")", "==", "QueryResultBatch", ".", "MoreResultsType", ".", "NOT_FINISHED", ")", "{", "System", ".", "err", ".", "println", "(", "\"WARNING: partial results\\n\"", ")", ";", "}", "List", "<", "EntityResult", ">", "results", "=", "response", ".", "getBatch", "(", ")", ".", "getEntityResultsList", "(", ")", ";", "List", "<", "Entity", ">", "entities", "=", "new", "ArrayList", "<", "Entity", ">", "(", "results", ".", "size", "(", ")", ")", ";", "for", "(", "EntityResult", "result", ":", "results", ")", "{", "entities", ".", "add", "(", "result", ".", "getEntity", "(", ")", ")", ";", "}", "return", "entities", ";", "}" ]
Run a query on the datastore. @return The entities returned by the query. @throws DatastoreException on error
[ "Run", "a", "query", "on", "the", "datastore", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/java/demos/src/main/java/com/google/datastore/v1/demos/guestbook/Guestbook.java#L169-L183
164,170
GoogleCloudPlatform/google-cloud-datastore
java/datastore/src/main/java/com/google/datastore/v1/client/QuerySplitterImpl.java
QuerySplitterImpl.validateFilter
private void validateFilter(Filter filter) throws IllegalArgumentException { switch (filter.getFilterTypeCase()) { case COMPOSITE_FILTER: for (Filter subFilter : filter.getCompositeFilter().getFiltersList()) { validateFilter(subFilter); } break; case PROPERTY_FILTER: if (UNSUPPORTED_OPERATORS.contains(filter.getPropertyFilter().getOp())) { throw new IllegalArgumentException("Query cannot have any inequality filters."); } break; default: throw new IllegalArgumentException( "Unsupported filter type: " + filter.getFilterTypeCase()); } }
java
private void validateFilter(Filter filter) throws IllegalArgumentException { switch (filter.getFilterTypeCase()) { case COMPOSITE_FILTER: for (Filter subFilter : filter.getCompositeFilter().getFiltersList()) { validateFilter(subFilter); } break; case PROPERTY_FILTER: if (UNSUPPORTED_OPERATORS.contains(filter.getPropertyFilter().getOp())) { throw new IllegalArgumentException("Query cannot have any inequality filters."); } break; default: throw new IllegalArgumentException( "Unsupported filter type: " + filter.getFilterTypeCase()); } }
[ "private", "void", "validateFilter", "(", "Filter", "filter", ")", "throws", "IllegalArgumentException", "{", "switch", "(", "filter", ".", "getFilterTypeCase", "(", ")", ")", "{", "case", "COMPOSITE_FILTER", ":", "for", "(", "Filter", "subFilter", ":", "filter", ".", "getCompositeFilter", "(", ")", ".", "getFiltersList", "(", ")", ")", "{", "validateFilter", "(", "subFilter", ")", ";", "}", "break", ";", "case", "PROPERTY_FILTER", ":", "if", "(", "UNSUPPORTED_OPERATORS", ".", "contains", "(", "filter", ".", "getPropertyFilter", "(", ")", ".", "getOp", "(", ")", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Query cannot have any inequality filters.\"", ")", ";", "}", "break", ";", "default", ":", "throw", "new", "IllegalArgumentException", "(", "\"Unsupported filter type: \"", "+", "filter", ".", "getFilterTypeCase", "(", ")", ")", ";", "}", "}" ]
Validates that we only have allowable filters. <p>Note that equality and ancestor filters are allowed, however they may result in inefficient sharding.
[ "Validates", "that", "we", "only", "have", "allowable", "filters", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/java/datastore/src/main/java/com/google/datastore/v1/client/QuerySplitterImpl.java#L99-L115
164,171
GoogleCloudPlatform/google-cloud-datastore
java/datastore/src/main/java/com/google/datastore/v1/client/QuerySplitterImpl.java
QuerySplitterImpl.validateQuery
private void validateQuery(Query query) throws IllegalArgumentException { if (query.getKindCount() != 1) { throw new IllegalArgumentException("Query must have exactly one kind."); } if (query.getOrderCount() != 0) { throw new IllegalArgumentException("Query cannot have any sort orders."); } if (query.hasFilter()) { validateFilter(query.getFilter()); } }
java
private void validateQuery(Query query) throws IllegalArgumentException { if (query.getKindCount() != 1) { throw new IllegalArgumentException("Query must have exactly one kind."); } if (query.getOrderCount() != 0) { throw new IllegalArgumentException("Query cannot have any sort orders."); } if (query.hasFilter()) { validateFilter(query.getFilter()); } }
[ "private", "void", "validateQuery", "(", "Query", "query", ")", "throws", "IllegalArgumentException", "{", "if", "(", "query", ".", "getKindCount", "(", ")", "!=", "1", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Query must have exactly one kind.\"", ")", ";", "}", "if", "(", "query", ".", "getOrderCount", "(", ")", "!=", "0", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Query cannot have any sort orders.\"", ")", ";", "}", "if", "(", "query", ".", "hasFilter", "(", ")", ")", "{", "validateFilter", "(", "query", ".", "getFilter", "(", ")", ")", ";", "}", "}" ]
Verifies that the given query can be properly scattered. @param query the query to verify @throws IllegalArgumentException if the query is invalid.
[ "Verifies", "that", "the", "given", "query", "can", "be", "properly", "scattered", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/java/datastore/src/main/java/com/google/datastore/v1/client/QuerySplitterImpl.java#L123-L133
164,172
GoogleCloudPlatform/google-cloud-datastore
java/datastore/src/main/java/com/google/datastore/v1/client/QuerySplitterImpl.java
QuerySplitterImpl.getScatterKeys
private List<Key> getScatterKeys( int numSplits, Query query, PartitionId partition, Datastore datastore) throws DatastoreException { Query.Builder scatterPointQuery = createScatterQuery(query, numSplits); List<Key> keySplits = new ArrayList<Key>(); QueryResultBatch batch; do { RunQueryRequest scatterRequest = RunQueryRequest.newBuilder() .setPartitionId(partition) .setQuery(scatterPointQuery) .build(); batch = datastore.runQuery(scatterRequest).getBatch(); for (EntityResult result : batch.getEntityResultsList()) { keySplits.add(result.getEntity().getKey()); } scatterPointQuery.setStartCursor(batch.getEndCursor()); scatterPointQuery.getLimitBuilder().setValue( scatterPointQuery.getLimit().getValue() - batch.getEntityResultsCount()); } while (batch.getMoreResults() == MoreResultsType.NOT_FINISHED); Collections.sort(keySplits, DatastoreHelper.getKeyComparator()); return keySplits; }
java
private List<Key> getScatterKeys( int numSplits, Query query, PartitionId partition, Datastore datastore) throws DatastoreException { Query.Builder scatterPointQuery = createScatterQuery(query, numSplits); List<Key> keySplits = new ArrayList<Key>(); QueryResultBatch batch; do { RunQueryRequest scatterRequest = RunQueryRequest.newBuilder() .setPartitionId(partition) .setQuery(scatterPointQuery) .build(); batch = datastore.runQuery(scatterRequest).getBatch(); for (EntityResult result : batch.getEntityResultsList()) { keySplits.add(result.getEntity().getKey()); } scatterPointQuery.setStartCursor(batch.getEndCursor()); scatterPointQuery.getLimitBuilder().setValue( scatterPointQuery.getLimit().getValue() - batch.getEntityResultsCount()); } while (batch.getMoreResults() == MoreResultsType.NOT_FINISHED); Collections.sort(keySplits, DatastoreHelper.getKeyComparator()); return keySplits; }
[ "private", "List", "<", "Key", ">", "getScatterKeys", "(", "int", "numSplits", ",", "Query", "query", ",", "PartitionId", "partition", ",", "Datastore", "datastore", ")", "throws", "DatastoreException", "{", "Query", ".", "Builder", "scatterPointQuery", "=", "createScatterQuery", "(", "query", ",", "numSplits", ")", ";", "List", "<", "Key", ">", "keySplits", "=", "new", "ArrayList", "<", "Key", ">", "(", ")", ";", "QueryResultBatch", "batch", ";", "do", "{", "RunQueryRequest", "scatterRequest", "=", "RunQueryRequest", ".", "newBuilder", "(", ")", ".", "setPartitionId", "(", "partition", ")", ".", "setQuery", "(", "scatterPointQuery", ")", ".", "build", "(", ")", ";", "batch", "=", "datastore", ".", "runQuery", "(", "scatterRequest", ")", ".", "getBatch", "(", ")", ";", "for", "(", "EntityResult", "result", ":", "batch", ".", "getEntityResultsList", "(", ")", ")", "{", "keySplits", ".", "add", "(", "result", ".", "getEntity", "(", ")", ".", "getKey", "(", ")", ")", ";", "}", "scatterPointQuery", ".", "setStartCursor", "(", "batch", ".", "getEndCursor", "(", ")", ")", ";", "scatterPointQuery", ".", "getLimitBuilder", "(", ")", ".", "setValue", "(", "scatterPointQuery", ".", "getLimit", "(", ")", ".", "getValue", "(", ")", "-", "batch", ".", "getEntityResultsCount", "(", ")", ")", ";", "}", "while", "(", "batch", ".", "getMoreResults", "(", ")", "==", "MoreResultsType", ".", "NOT_FINISHED", ")", ";", "Collections", ".", "sort", "(", "keySplits", ",", "DatastoreHelper", ".", "getKeyComparator", "(", ")", ")", ";", "return", "keySplits", ";", "}" ]
Gets a list of split keys given a desired number of splits. <p>This list will contain multiple split keys for each split. Only a single split key will be chosen as the split point, however providing multiple keys allows for more uniform sharding. @param numSplits the number of desired splits. @param query the user query. @param partition the partition to run the query in. @param datastore the datastore containing the data. @throws DatastoreException if there was an error when executing the datastore query.
[ "Gets", "a", "list", "of", "split", "keys", "given", "a", "desired", "number", "of", "splits", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/java/datastore/src/main/java/com/google/datastore/v1/client/QuerySplitterImpl.java#L178-L202
164,173
GoogleCloudPlatform/google-cloud-datastore
java/datastore/src/main/java/com/google/datastore/v1/client/QuerySplitterImpl.java
QuerySplitterImpl.createScatterQuery
private Query.Builder createScatterQuery(Query query, int numSplits) { // TODO(pcostello): We can potentially support better splits with equality filters in our query // if there exists a composite index on property, __scatter__, __key__. Until an API for // metadata exists, this isn't possible. Note that ancestor and inequality queries fall into // the same category. Query.Builder scatterPointQuery = Query.newBuilder(); scatterPointQuery.addAllKind(query.getKindList()); scatterPointQuery.addOrder(DatastoreHelper.makeOrder( DatastoreHelper.SCATTER_PROPERTY_NAME, Direction.ASCENDING)); // There is a split containing entities before and after each scatter entity: // ||---*------*------*------*------*------*------*---|| = scatter entity // If we represent each split as a region before a scatter entity, there is an extra region // following the last scatter point. Thus, we do not need the scatter entities for the last // region. scatterPointQuery.getLimitBuilder().setValue((numSplits - 1) * KEYS_PER_SPLIT); scatterPointQuery.addProjection(Projection.newBuilder().setProperty( PropertyReference.newBuilder().setName("__key__"))); return scatterPointQuery; }
java
private Query.Builder createScatterQuery(Query query, int numSplits) { // TODO(pcostello): We can potentially support better splits with equality filters in our query // if there exists a composite index on property, __scatter__, __key__. Until an API for // metadata exists, this isn't possible. Note that ancestor and inequality queries fall into // the same category. Query.Builder scatterPointQuery = Query.newBuilder(); scatterPointQuery.addAllKind(query.getKindList()); scatterPointQuery.addOrder(DatastoreHelper.makeOrder( DatastoreHelper.SCATTER_PROPERTY_NAME, Direction.ASCENDING)); // There is a split containing entities before and after each scatter entity: // ||---*------*------*------*------*------*------*---|| = scatter entity // If we represent each split as a region before a scatter entity, there is an extra region // following the last scatter point. Thus, we do not need the scatter entities for the last // region. scatterPointQuery.getLimitBuilder().setValue((numSplits - 1) * KEYS_PER_SPLIT); scatterPointQuery.addProjection(Projection.newBuilder().setProperty( PropertyReference.newBuilder().setName("__key__"))); return scatterPointQuery; }
[ "private", "Query", ".", "Builder", "createScatterQuery", "(", "Query", "query", ",", "int", "numSplits", ")", "{", "// TODO(pcostello): We can potentially support better splits with equality filters in our query", "// if there exists a composite index on property, __scatter__, __key__. Until an API for", "// metadata exists, this isn't possible. Note that ancestor and inequality queries fall into", "// the same category.", "Query", ".", "Builder", "scatterPointQuery", "=", "Query", ".", "newBuilder", "(", ")", ";", "scatterPointQuery", ".", "addAllKind", "(", "query", ".", "getKindList", "(", ")", ")", ";", "scatterPointQuery", ".", "addOrder", "(", "DatastoreHelper", ".", "makeOrder", "(", "DatastoreHelper", ".", "SCATTER_PROPERTY_NAME", ",", "Direction", ".", "ASCENDING", ")", ")", ";", "// There is a split containing entities before and after each scatter entity:", "// ||---*------*------*------*------*------*------*---|| = scatter entity", "// If we represent each split as a region before a scatter entity, there is an extra region", "// following the last scatter point. Thus, we do not need the scatter entities for the last", "// region.", "scatterPointQuery", ".", "getLimitBuilder", "(", ")", ".", "setValue", "(", "(", "numSplits", "-", "1", ")", "*", "KEYS_PER_SPLIT", ")", ";", "scatterPointQuery", ".", "addProjection", "(", "Projection", ".", "newBuilder", "(", ")", ".", "setProperty", "(", "PropertyReference", ".", "newBuilder", "(", ")", ".", "setName", "(", "\"__key__\"", ")", ")", ")", ";", "return", "scatterPointQuery", ";", "}" ]
Creates a scatter query from the given user query @param query the user's query. @param numSplits the number of splits to create.
[ "Creates", "a", "scatter", "query", "from", "the", "given", "user", "query" ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/java/datastore/src/main/java/com/google/datastore/v1/client/QuerySplitterImpl.java#L210-L228
164,174
GoogleCloudPlatform/google-cloud-datastore
java/datastore/src/main/java/com/google/datastore/v1/client/QuerySplitterImpl.java
QuerySplitterImpl.getSplitKey
private Iterable<Key> getSplitKey(List<Key> keys, int numSplits) { // If the number of keys is less than the number of splits, we are limited in the number of // splits we can make. if (keys.size() < numSplits - 1) { return keys; } // Calculate the number of keys per split. This should be KEYS_PER_SPLIT, but may // be less if there are not KEYS_PER_SPLIT * (numSplits - 1) scatter entities. // // Consider the following dataset, where - represents an entity and * represents an entity // that is returned as a scatter entity: // ||---*-----*----*-----*-----*------*----*----|| // If we want 4 splits in this data, the optimal split would look like: // ||---*-----*----*-----*-----*------*----*----|| // | | | // The scatter keys in the last region are not useful to us, so we never request them: // ||---*-----*----*-----*-----*------*---------|| // | | | // With 6 scatter keys we want to set scatter points at indexes: 1, 3, 5. // // We keep this as a double so that any "fractional" keys per split get distributed throughout // the splits and don't make the last split significantly larger than the rest. double numKeysPerSplit = Math.max(1.0, ((double) keys.size()) / (numSplits - 1)); List<Key> keysList = new ArrayList<Key>(numSplits - 1); // Grab the last sample for each split, otherwise the first split will be too small. for (int i = 1; i < numSplits; i++) { int splitIndex = (int) Math.round(i * numKeysPerSplit) - 1; keysList.add(keys.get(splitIndex)); } return keysList; }
java
private Iterable<Key> getSplitKey(List<Key> keys, int numSplits) { // If the number of keys is less than the number of splits, we are limited in the number of // splits we can make. if (keys.size() < numSplits - 1) { return keys; } // Calculate the number of keys per split. This should be KEYS_PER_SPLIT, but may // be less if there are not KEYS_PER_SPLIT * (numSplits - 1) scatter entities. // // Consider the following dataset, where - represents an entity and * represents an entity // that is returned as a scatter entity: // ||---*-----*----*-----*-----*------*----*----|| // If we want 4 splits in this data, the optimal split would look like: // ||---*-----*----*-----*-----*------*----*----|| // | | | // The scatter keys in the last region are not useful to us, so we never request them: // ||---*-----*----*-----*-----*------*---------|| // | | | // With 6 scatter keys we want to set scatter points at indexes: 1, 3, 5. // // We keep this as a double so that any "fractional" keys per split get distributed throughout // the splits and don't make the last split significantly larger than the rest. double numKeysPerSplit = Math.max(1.0, ((double) keys.size()) / (numSplits - 1)); List<Key> keysList = new ArrayList<Key>(numSplits - 1); // Grab the last sample for each split, otherwise the first split will be too small. for (int i = 1; i < numSplits; i++) { int splitIndex = (int) Math.round(i * numKeysPerSplit) - 1; keysList.add(keys.get(splitIndex)); } return keysList; }
[ "private", "Iterable", "<", "Key", ">", "getSplitKey", "(", "List", "<", "Key", ">", "keys", ",", "int", "numSplits", ")", "{", "// If the number of keys is less than the number of splits, we are limited in the number of", "// splits we can make.", "if", "(", "keys", ".", "size", "(", ")", "<", "numSplits", "-", "1", ")", "{", "return", "keys", ";", "}", "// Calculate the number of keys per split. This should be KEYS_PER_SPLIT, but may", "// be less if there are not KEYS_PER_SPLIT * (numSplits - 1) scatter entities.", "//", "// Consider the following dataset, where - represents an entity and * represents an entity", "// that is returned as a scatter entity:", "// ||---*-----*----*-----*-----*------*----*----||", "// If we want 4 splits in this data, the optimal split would look like:", "// ||---*-----*----*-----*-----*------*----*----||", "// | | |", "// The scatter keys in the last region are not useful to us, so we never request them:", "// ||---*-----*----*-----*-----*------*---------||", "// | | |", "// With 6 scatter keys we want to set scatter points at indexes: 1, 3, 5.", "//", "// We keep this as a double so that any \"fractional\" keys per split get distributed throughout", "// the splits and don't make the last split significantly larger than the rest.", "double", "numKeysPerSplit", "=", "Math", ".", "max", "(", "1.0", ",", "(", "(", "double", ")", "keys", ".", "size", "(", ")", ")", "/", "(", "numSplits", "-", "1", ")", ")", ";", "List", "<", "Key", ">", "keysList", "=", "new", "ArrayList", "<", "Key", ">", "(", "numSplits", "-", "1", ")", ";", "// Grab the last sample for each split, otherwise the first split will be too small.", "for", "(", "int", "i", "=", "1", ";", "i", "<", "numSplits", ";", "i", "++", ")", "{", "int", "splitIndex", "=", "(", "int", ")", "Math", ".", "round", "(", "i", "*", "numKeysPerSplit", ")", "-", "1", ";", "keysList", ".", "add", "(", "keys", ".", "get", "(", "splitIndex", ")", ")", ";", "}", "return", "keysList", ";", "}" ]
Given a list of keys and a number of splits find the keys to split on. @param keys the list of keys. @param numSplits the number of splits.
[ "Given", "a", "list", "of", "keys", "and", "a", "number", "of", "splits", "find", "the", "keys", "to", "split", "on", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/java/datastore/src/main/java/com/google/datastore/v1/client/QuerySplitterImpl.java#L236-L269
164,175
GoogleCloudPlatform/google-cloud-datastore
java/datastore/src/main/java/com/google/datastore/v1/client/DatastoreFactory.java
DatastoreFactory.makeClient
public HttpRequestFactory makeClient(DatastoreOptions options) { Credential credential = options.getCredential(); HttpTransport transport = options.getTransport(); if (transport == null) { transport = credential == null ? new NetHttpTransport() : credential.getTransport(); transport = transport == null ? new NetHttpTransport() : transport; } return transport.createRequestFactory(credential); }
java
public HttpRequestFactory makeClient(DatastoreOptions options) { Credential credential = options.getCredential(); HttpTransport transport = options.getTransport(); if (transport == null) { transport = credential == null ? new NetHttpTransport() : credential.getTransport(); transport = transport == null ? new NetHttpTransport() : transport; } return transport.createRequestFactory(credential); }
[ "public", "HttpRequestFactory", "makeClient", "(", "DatastoreOptions", "options", ")", "{", "Credential", "credential", "=", "options", ".", "getCredential", "(", ")", ";", "HttpTransport", "transport", "=", "options", ".", "getTransport", "(", ")", ";", "if", "(", "transport", "==", "null", ")", "{", "transport", "=", "credential", "==", "null", "?", "new", "NetHttpTransport", "(", ")", ":", "credential", ".", "getTransport", "(", ")", ";", "transport", "=", "transport", "==", "null", "?", "new", "NetHttpTransport", "(", ")", ":", "transport", ";", "}", "return", "transport", ".", "createRequestFactory", "(", "credential", ")", ";", "}" ]
Constructs a Google APIs HTTP client with the associated credentials.
[ "Constructs", "a", "Google", "APIs", "HTTP", "client", "with", "the", "associated", "credentials", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/java/datastore/src/main/java/com/google/datastore/v1/client/DatastoreFactory.java#L71-L79
164,176
GoogleCloudPlatform/google-cloud-datastore
java/datastore/src/main/java/com/google/datastore/v1/client/DatastoreFactory.java
DatastoreFactory.buildProjectEndpoint
String buildProjectEndpoint(DatastoreOptions options) { if (options.getProjectEndpoint() != null) { return options.getProjectEndpoint(); } // DatastoreOptions ensures either project endpoint or project ID is set. String projectId = checkNotNull(options.getProjectId()); if (options.getHost() != null) { return validateUrl(String.format("https://%s/%s/projects/%s", options.getHost(), VERSION, projectId)); } else if (options.getLocalHost() != null) { return validateUrl(String.format("http://%s/%s/projects/%s", options.getLocalHost(), VERSION, projectId)); } return validateUrl(String.format("%s/%s/projects/%s", DEFAULT_HOST, VERSION, projectId)); }
java
String buildProjectEndpoint(DatastoreOptions options) { if (options.getProjectEndpoint() != null) { return options.getProjectEndpoint(); } // DatastoreOptions ensures either project endpoint or project ID is set. String projectId = checkNotNull(options.getProjectId()); if (options.getHost() != null) { return validateUrl(String.format("https://%s/%s/projects/%s", options.getHost(), VERSION, projectId)); } else if (options.getLocalHost() != null) { return validateUrl(String.format("http://%s/%s/projects/%s", options.getLocalHost(), VERSION, projectId)); } return validateUrl(String.format("%s/%s/projects/%s", DEFAULT_HOST, VERSION, projectId)); }
[ "String", "buildProjectEndpoint", "(", "DatastoreOptions", "options", ")", "{", "if", "(", "options", ".", "getProjectEndpoint", "(", ")", "!=", "null", ")", "{", "return", "options", ".", "getProjectEndpoint", "(", ")", ";", "}", "// DatastoreOptions ensures either project endpoint or project ID is set.", "String", "projectId", "=", "checkNotNull", "(", "options", ".", "getProjectId", "(", ")", ")", ";", "if", "(", "options", ".", "getHost", "(", ")", "!=", "null", ")", "{", "return", "validateUrl", "(", "String", ".", "format", "(", "\"https://%s/%s/projects/%s\"", ",", "options", ".", "getHost", "(", ")", ",", "VERSION", ",", "projectId", ")", ")", ";", "}", "else", "if", "(", "options", ".", "getLocalHost", "(", ")", "!=", "null", ")", "{", "return", "validateUrl", "(", "String", ".", "format", "(", "\"http://%s/%s/projects/%s\"", ",", "options", ".", "getLocalHost", "(", ")", ",", "VERSION", ",", "projectId", ")", ")", ";", "}", "return", "validateUrl", "(", "String", ".", "format", "(", "\"%s/%s/projects/%s\"", ",", "DEFAULT_HOST", ",", "VERSION", ",", "projectId", ")", ")", ";", "}" ]
Build a valid datastore URL.
[ "Build", "a", "valid", "datastore", "URL", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/java/datastore/src/main/java/com/google/datastore/v1/client/DatastoreFactory.java#L95-L110
164,177
GoogleCloudPlatform/google-cloud-datastore
java/datastore/src/main/java/com/google/datastore/v1/client/DatastoreFactory.java
DatastoreFactory.getStreamHandler
private static synchronized StreamHandler getStreamHandler() { if (methodHandler == null) { methodHandler = new ConsoleHandler(); methodHandler.setFormatter(new Formatter() { @Override public String format(LogRecord record) { return record.getMessage() + "\n"; } }); methodHandler.setLevel(Level.FINE); } return methodHandler; }
java
private static synchronized StreamHandler getStreamHandler() { if (methodHandler == null) { methodHandler = new ConsoleHandler(); methodHandler.setFormatter(new Formatter() { @Override public String format(LogRecord record) { return record.getMessage() + "\n"; } }); methodHandler.setLevel(Level.FINE); } return methodHandler; }
[ "private", "static", "synchronized", "StreamHandler", "getStreamHandler", "(", ")", "{", "if", "(", "methodHandler", "==", "null", ")", "{", "methodHandler", "=", "new", "ConsoleHandler", "(", ")", ";", "methodHandler", ".", "setFormatter", "(", "new", "Formatter", "(", ")", "{", "@", "Override", "public", "String", "format", "(", "LogRecord", "record", ")", "{", "return", "record", ".", "getMessage", "(", ")", "+", "\"\\n\"", ";", "}", "}", ")", ";", "methodHandler", ".", "setLevel", "(", "Level", ".", "FINE", ")", ";", "}", "return", "methodHandler", ";", "}" ]
running in App Engine
[ "running", "in", "App", "Engine" ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/java/datastore/src/main/java/com/google/datastore/v1/client/DatastoreFactory.java#L128-L140
164,178
GoogleCloudPlatform/google-cloud-datastore
java/datastore/src/main/java/com/google/datastore/v1/client/DatastoreHelper.java
DatastoreHelper.getServiceAccountCredential
public static Credential getServiceAccountCredential(String serviceAccountId, String privateKeyFile, Collection<String> serviceAccountScopes) throws GeneralSecurityException, IOException { return getCredentialBuilderWithoutPrivateKey(serviceAccountId, serviceAccountScopes) .setServiceAccountPrivateKeyFromP12File(new File(privateKeyFile)) .build(); }
java
public static Credential getServiceAccountCredential(String serviceAccountId, String privateKeyFile, Collection<String> serviceAccountScopes) throws GeneralSecurityException, IOException { return getCredentialBuilderWithoutPrivateKey(serviceAccountId, serviceAccountScopes) .setServiceAccountPrivateKeyFromP12File(new File(privateKeyFile)) .build(); }
[ "public", "static", "Credential", "getServiceAccountCredential", "(", "String", "serviceAccountId", ",", "String", "privateKeyFile", ",", "Collection", "<", "String", ">", "serviceAccountScopes", ")", "throws", "GeneralSecurityException", ",", "IOException", "{", "return", "getCredentialBuilderWithoutPrivateKey", "(", "serviceAccountId", ",", "serviceAccountScopes", ")", ".", "setServiceAccountPrivateKeyFromP12File", "(", "new", "File", "(", "privateKeyFile", ")", ")", ".", "build", "(", ")", ";", "}" ]
Constructs credentials for the given account and key file. @param serviceAccountId service account ID (typically an e-mail address). @param privateKeyFile the file name from which to get the private key. @param serviceAccountScopes Collection of OAuth scopes to use with the the service account flow or {@code null} if not. @return valid credentials or {@code null}
[ "Constructs", "credentials", "for", "the", "given", "account", "and", "key", "file", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/java/datastore/src/main/java/com/google/datastore/v1/client/DatastoreHelper.java#L177-L183
164,179
GoogleCloudPlatform/google-cloud-datastore
java/datastore/src/main/java/com/google/datastore/v1/client/DatastoreHelper.java
DatastoreHelper.makeOrder
public static PropertyOrder.Builder makeOrder(String property, PropertyOrder.Direction direction) { return PropertyOrder.newBuilder() .setProperty(makePropertyReference(property)) .setDirection(direction); }
java
public static PropertyOrder.Builder makeOrder(String property, PropertyOrder.Direction direction) { return PropertyOrder.newBuilder() .setProperty(makePropertyReference(property)) .setDirection(direction); }
[ "public", "static", "PropertyOrder", ".", "Builder", "makeOrder", "(", "String", "property", ",", "PropertyOrder", ".", "Direction", "direction", ")", "{", "return", "PropertyOrder", ".", "newBuilder", "(", ")", ".", "setProperty", "(", "makePropertyReference", "(", "property", ")", ")", ".", "setDirection", "(", "direction", ")", ";", "}" ]
Make a sort order for use in a query.
[ "Make", "a", "sort", "order", "for", "use", "in", "a", "query", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/java/datastore/src/main/java/com/google/datastore/v1/client/DatastoreHelper.java#L366-L371
164,180
GoogleCloudPlatform/google-cloud-datastore
java/datastore/src/main/java/com/google/datastore/v1/client/DatastoreHelper.java
DatastoreHelper.makeAncestorFilter
public static Filter.Builder makeAncestorFilter(Key ancestor) { return makeFilter( DatastoreHelper.KEY_PROPERTY_NAME, PropertyFilter.Operator.HAS_ANCESTOR, makeValue(ancestor)); }
java
public static Filter.Builder makeAncestorFilter(Key ancestor) { return makeFilter( DatastoreHelper.KEY_PROPERTY_NAME, PropertyFilter.Operator.HAS_ANCESTOR, makeValue(ancestor)); }
[ "public", "static", "Filter", ".", "Builder", "makeAncestorFilter", "(", "Key", "ancestor", ")", "{", "return", "makeFilter", "(", "DatastoreHelper", ".", "KEY_PROPERTY_NAME", ",", "PropertyFilter", ".", "Operator", ".", "HAS_ANCESTOR", ",", "makeValue", "(", "ancestor", ")", ")", ";", "}" ]
Makes an ancestor filter.
[ "Makes", "an", "ancestor", "filter", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/java/datastore/src/main/java/com/google/datastore/v1/client/DatastoreHelper.java#L376-L380
164,181
GoogleCloudPlatform/google-cloud-datastore
java/datastore/src/main/java/com/google/datastore/v1/client/DatastoreHelper.java
DatastoreHelper.makeAndFilter
public static Filter.Builder makeAndFilter(Iterable<Filter> subfilters) { return Filter.newBuilder() .setCompositeFilter(CompositeFilter.newBuilder() .addAllFilters(subfilters) .setOp(CompositeFilter.Operator.AND)); }
java
public static Filter.Builder makeAndFilter(Iterable<Filter> subfilters) { return Filter.newBuilder() .setCompositeFilter(CompositeFilter.newBuilder() .addAllFilters(subfilters) .setOp(CompositeFilter.Operator.AND)); }
[ "public", "static", "Filter", ".", "Builder", "makeAndFilter", "(", "Iterable", "<", "Filter", ">", "subfilters", ")", "{", "return", "Filter", ".", "newBuilder", "(", ")", ".", "setCompositeFilter", "(", "CompositeFilter", ".", "newBuilder", "(", ")", ".", "addAllFilters", "(", "subfilters", ")", ".", "setOp", "(", "CompositeFilter", ".", "Operator", ".", "AND", ")", ")", ";", "}" ]
Make a composite filter from the given sub-filters using AND to combine filters.
[ "Make", "a", "composite", "filter", "from", "the", "given", "sub", "-", "filters", "using", "AND", "to", "combine", "filters", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/java/datastore/src/main/java/com/google/datastore/v1/client/DatastoreHelper.java#L412-L417
164,182
GoogleCloudPlatform/google-cloud-datastore
java/datastore/src/main/java/com/google/datastore/v1/client/DatastoreHelper.java
DatastoreHelper.makeValue
public static Value.Builder makeValue(Value value1, Value value2, Value... rest) { ArrayValue.Builder arrayValue = ArrayValue.newBuilder(); arrayValue.addValues(value1); arrayValue.addValues(value2); arrayValue.addAllValues(Arrays.asList(rest)); return Value.newBuilder().setArrayValue(arrayValue); }
java
public static Value.Builder makeValue(Value value1, Value value2, Value... rest) { ArrayValue.Builder arrayValue = ArrayValue.newBuilder(); arrayValue.addValues(value1); arrayValue.addValues(value2); arrayValue.addAllValues(Arrays.asList(rest)); return Value.newBuilder().setArrayValue(arrayValue); }
[ "public", "static", "Value", ".", "Builder", "makeValue", "(", "Value", "value1", ",", "Value", "value2", ",", "Value", "...", "rest", ")", "{", "ArrayValue", ".", "Builder", "arrayValue", "=", "ArrayValue", ".", "newBuilder", "(", ")", ";", "arrayValue", ".", "addValues", "(", "value1", ")", ";", "arrayValue", ".", "addValues", "(", "value2", ")", ";", "arrayValue", ".", "addAllValues", "(", "Arrays", ".", "asList", "(", "rest", ")", ")", ";", "return", "Value", ".", "newBuilder", "(", ")", ".", "setArrayValue", "(", "arrayValue", ")", ";", "}" ]
Make a list value containing the specified values.
[ "Make", "a", "list", "value", "containing", "the", "specified", "values", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/java/datastore/src/main/java/com/google/datastore/v1/client/DatastoreHelper.java#L436-L442
164,183
GoogleCloudPlatform/google-cloud-datastore
java/datastore/src/main/java/com/google/datastore/v1/client/DatastoreHelper.java
DatastoreHelper.makeValue
public static Value.Builder makeValue(Date date) { return Value.newBuilder().setTimestampValue(toTimestamp(date.getTime() * 1000L)); }
java
public static Value.Builder makeValue(Date date) { return Value.newBuilder().setTimestampValue(toTimestamp(date.getTime() * 1000L)); }
[ "public", "static", "Value", ".", "Builder", "makeValue", "(", "Date", "date", ")", "{", "return", "Value", ".", "newBuilder", "(", ")", ".", "setTimestampValue", "(", "toTimestamp", "(", "date", ".", "getTime", "(", ")", "*", "1000L", ")", ")", ";", "}" ]
Make a timestamp value given a date.
[ "Make", "a", "timestamp", "value", "given", "a", "date", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/java/datastore/src/main/java/com/google/datastore/v1/client/DatastoreHelper.java#L524-L526
164,184
eclipse/xtext-lib
org.eclipse.xtext.xbase.lib/src/org/eclipse/xtext/xbase/lib/ListExtensions.java
ListExtensions.sortInplace
public static <T extends Comparable<? super T>> List<T> sortInplace(List<T> list) { Collections.sort(list); return list; }
java
public static <T extends Comparable<? super T>> List<T> sortInplace(List<T> list) { Collections.sort(list); return list; }
[ "public", "static", "<", "T", "extends", "Comparable", "<", "?", "super", "T", ">", ">", "List", "<", "T", ">", "sortInplace", "(", "List", "<", "T", ">", "list", ")", "{", "Collections", ".", "sort", "(", "list", ")", ";", "return", "list", ";", "}" ]
Sorts the specified list itself into ascending order, according to the natural ordering of its elements. @param list the list to be sorted. May not be <code>null</code>. @return the sorted list itself. @see Collections#sort(List)
[ "Sorts", "the", "specified", "list", "itself", "into", "ascending", "order", "according", "to", "the", "natural", "ordering", "of", "its", "elements", "." ]
7063572e1f1bd713a3aa53bdf3a8dc60e25c169a
https://github.com/eclipse/xtext-lib/blob/7063572e1f1bd713a3aa53bdf3a8dc60e25c169a/org.eclipse.xtext.xbase.lib/src/org/eclipse/xtext/xbase/lib/ListExtensions.java#L44-L47
164,185
eclipse/xtext-lib
org.eclipse.xtext.xbase.lib/src/org/eclipse/xtext/xbase/lib/ListExtensions.java
ListExtensions.sortInplaceBy
public static <T, C extends Comparable<? super C>> List<T> sortInplaceBy(List<T> list, final Functions.Function1<? super T, C> key) { if (key == null) throw new NullPointerException("key"); Collections.sort(list, new KeyComparator<T, C>(key)); return list; }
java
public static <T, C extends Comparable<? super C>> List<T> sortInplaceBy(List<T> list, final Functions.Function1<? super T, C> key) { if (key == null) throw new NullPointerException("key"); Collections.sort(list, new KeyComparator<T, C>(key)); return list; }
[ "public", "static", "<", "T", ",", "C", "extends", "Comparable", "<", "?", "super", "C", ">", ">", "List", "<", "T", ">", "sortInplaceBy", "(", "List", "<", "T", ">", "list", ",", "final", "Functions", ".", "Function1", "<", "?", "super", "T", ",", "C", ">", "key", ")", "{", "if", "(", "key", "==", "null", ")", "throw", "new", "NullPointerException", "(", "\"key\"", ")", ";", "Collections", ".", "sort", "(", "list", ",", "new", "KeyComparator", "<", "T", ",", "C", ">", "(", "key", ")", ")", ";", "return", "list", ";", "}" ]
Sorts the specified list itself according to the order induced by applying a key function to each element which yields a comparable criteria. @param list the list to be sorted. May not be <code>null</code>. @param key the key function to-be-used. May not be <code>null</code>. @return the sorted list itself. @see Collections#sort(List)
[ "Sorts", "the", "specified", "list", "itself", "according", "to", "the", "order", "induced", "by", "applying", "a", "key", "function", "to", "each", "element", "which", "yields", "a", "comparable", "criteria", "." ]
7063572e1f1bd713a3aa53bdf3a8dc60e25c169a
https://github.com/eclipse/xtext-lib/blob/7063572e1f1bd713a3aa53bdf3a8dc60e25c169a/org.eclipse.xtext.xbase.lib/src/org/eclipse/xtext/xbase/lib/ListExtensions.java#L78-L84
164,186
eclipse/xtext-lib
org.eclipse.xtext.xbase.lib/src/org/eclipse/xtext/xbase/lib/ListExtensions.java
ListExtensions.reverseView
@Pure public static <T> List<T> reverseView(List<T> list) { return Lists.reverse(list); }
java
@Pure public static <T> List<T> reverseView(List<T> list) { return Lists.reverse(list); }
[ "@", "Pure", "public", "static", "<", "T", ">", "List", "<", "T", ">", "reverseView", "(", "List", "<", "T", ">", "list", ")", "{", "return", "Lists", ".", "reverse", "(", "list", ")", ";", "}" ]
Provides a reverse view on the given list which is especially useful to traverse a list backwards in a for-each loop. The list itself is not modified by calling this method. @param list the list whose elements should be traversed in reverse. May not be <code>null</code>. @return a list with the same elements as the given list, in reverse
[ "Provides", "a", "reverse", "view", "on", "the", "given", "list", "which", "is", "especially", "useful", "to", "traverse", "a", "list", "backwards", "in", "a", "for", "-", "each", "loop", ".", "The", "list", "itself", "is", "not", "modified", "by", "calling", "this", "method", "." ]
7063572e1f1bd713a3aa53bdf3a8dc60e25c169a
https://github.com/eclipse/xtext-lib/blob/7063572e1f1bd713a3aa53bdf3a8dc60e25c169a/org.eclipse.xtext.xbase.lib/src/org/eclipse/xtext/xbase/lib/ListExtensions.java#L94-L97
164,187
eclipse/xtext-lib
org.eclipse.xtext.xbase.lib/src/org/eclipse/xtext/xbase/lib/util/ReflectExtensions.java
ReflectExtensions.set
public void set(Object receiver, String fieldName, /* @Nullable */ Object value) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { Preconditions.checkNotNull(receiver,"receiver"); Preconditions.checkNotNull(fieldName,"fieldName"); Class<? extends Object> clazz = receiver.getClass(); Field f = getDeclaredField(clazz, fieldName); if (!f.isAccessible()) f.setAccessible(true); f.set(receiver, value); }
java
public void set(Object receiver, String fieldName, /* @Nullable */ Object value) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { Preconditions.checkNotNull(receiver,"receiver"); Preconditions.checkNotNull(fieldName,"fieldName"); Class<? extends Object> clazz = receiver.getClass(); Field f = getDeclaredField(clazz, fieldName); if (!f.isAccessible()) f.setAccessible(true); f.set(receiver, value); }
[ "public", "void", "set", "(", "Object", "receiver", ",", "String", "fieldName", ",", "/* @Nullable */", "Object", "value", ")", "throws", "SecurityException", ",", "NoSuchFieldException", ",", "IllegalArgumentException", ",", "IllegalAccessException", "{", "Preconditions", ".", "checkNotNull", "(", "receiver", ",", "\"receiver\"", ")", ";", "Preconditions", ".", "checkNotNull", "(", "fieldName", ",", "\"fieldName\"", ")", ";", "Class", "<", "?", "extends", "Object", ">", "clazz", "=", "receiver", ".", "getClass", "(", ")", ";", "Field", "f", "=", "getDeclaredField", "(", "clazz", ",", "fieldName", ")", ";", "if", "(", "!", "f", ".", "isAccessible", "(", ")", ")", "f", ".", "setAccessible", "(", "true", ")", ";", "f", ".", "set", "(", "receiver", ",", "value", ")", ";", "}" ]
Sets the given value on an the receivers's accessible field with the given name. @param receiver the receiver, never <code>null</code> @param fieldName the field's name, never <code>null</code> @param value the value to set @throws NoSuchFieldException see {@link Class#getField(String)} @throws SecurityException see {@link Class#getField(String)} @throws IllegalAccessException see {@link Field#set(Object, Object)} @throws IllegalArgumentException see {@link Field#set(Object, Object)}
[ "Sets", "the", "given", "value", "on", "an", "the", "receivers", "s", "accessible", "field", "with", "the", "given", "name", "." ]
7063572e1f1bd713a3aa53bdf3a8dc60e25c169a
https://github.com/eclipse/xtext-lib/blob/7063572e1f1bd713a3aa53bdf3a8dc60e25c169a/org.eclipse.xtext.xbase.lib/src/org/eclipse/xtext/xbase/lib/util/ReflectExtensions.java#L38-L46
164,188
eclipse/xtext-lib
org.eclipse.xtext.xbase.lib/src/org/eclipse/xtext/xbase/lib/util/ReflectExtensions.java
ReflectExtensions.get
@SuppressWarnings("unchecked") /* @Nullable */ public <T> T get(Object receiver, String fieldName) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { Preconditions.checkNotNull(receiver,"receiver"); Preconditions.checkNotNull(fieldName,"fieldName"); Class<? extends Object> clazz = receiver.getClass(); Field f = getDeclaredField(clazz, fieldName); if (!f.isAccessible()) f.setAccessible(true); return (T) f.get(receiver); }
java
@SuppressWarnings("unchecked") /* @Nullable */ public <T> T get(Object receiver, String fieldName) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { Preconditions.checkNotNull(receiver,"receiver"); Preconditions.checkNotNull(fieldName,"fieldName"); Class<? extends Object> clazz = receiver.getClass(); Field f = getDeclaredField(clazz, fieldName); if (!f.isAccessible()) f.setAccessible(true); return (T) f.get(receiver); }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "/* @Nullable */", "public", "<", "T", ">", "T", "get", "(", "Object", "receiver", ",", "String", "fieldName", ")", "throws", "SecurityException", ",", "NoSuchFieldException", ",", "IllegalArgumentException", ",", "IllegalAccessException", "{", "Preconditions", ".", "checkNotNull", "(", "receiver", ",", "\"receiver\"", ")", ";", "Preconditions", ".", "checkNotNull", "(", "fieldName", ",", "\"fieldName\"", ")", ";", "Class", "<", "?", "extends", "Object", ">", "clazz", "=", "receiver", ".", "getClass", "(", ")", ";", "Field", "f", "=", "getDeclaredField", "(", "clazz", ",", "fieldName", ")", ";", "if", "(", "!", "f", ".", "isAccessible", "(", ")", ")", "f", ".", "setAccessible", "(", "true", ")", ";", "return", "(", "T", ")", "f", ".", "get", "(", "receiver", ")", ";", "}" ]
Retrieves the value of the given accessible field of the given receiver. @param receiver the container of the field, not <code>null</code> @param fieldName the field's name, not <code>null</code> @return the value of the field @throws NoSuchFieldException see {@link Class#getField(String)} @throws SecurityException see {@link Class#getField(String)} @throws IllegalAccessException see {@link Field#get(Object)} @throws IllegalArgumentException see {@link Field#get(Object)}
[ "Retrieves", "the", "value", "of", "the", "given", "accessible", "field", "of", "the", "given", "receiver", "." ]
7063572e1f1bd713a3aa53bdf3a8dc60e25c169a
https://github.com/eclipse/xtext-lib/blob/7063572e1f1bd713a3aa53bdf3a8dc60e25c169a/org.eclipse.xtext.xbase.lib/src/org/eclipse/xtext/xbase/lib/util/ReflectExtensions.java#L60-L71
164,189
eclipse/xtext-lib
org.eclipse.xtext.xbase.lib/src/org/eclipse/xtend2/lib/StringConcatenation.java
StringConcatenation.append
public void append(Object object, String indentation) { append(object, indentation, segments.size()); }
java
public void append(Object object, String indentation) { append(object, indentation, segments.size()); }
[ "public", "void", "append", "(", "Object", "object", ",", "String", "indentation", ")", "{", "append", "(", "object", ",", "indentation", ",", "segments", ".", "size", "(", ")", ")", ";", "}" ]
Add the string representation of the given object to this sequence. The given indentation will be prepended to each line except the first one if the object has a multi-line string representation. @param object the appended object. @param indentation the indentation string that should be prepended. May not be <code>null</code>.
[ "Add", "the", "string", "representation", "of", "the", "given", "object", "to", "this", "sequence", ".", "The", "given", "indentation", "will", "be", "prepended", "to", "each", "line", "except", "the", "first", "one", "if", "the", "object", "has", "a", "multi", "-", "line", "string", "representation", "." ]
7063572e1f1bd713a3aa53bdf3a8dc60e25c169a
https://github.com/eclipse/xtext-lib/blob/7063572e1f1bd713a3aa53bdf3a8dc60e25c169a/org.eclipse.xtext.xbase.lib/src/org/eclipse/xtend2/lib/StringConcatenation.java#L225-L227
164,190
eclipse/xtext-lib
org.eclipse.xtext.xbase.lib/src/org/eclipse/xtend2/lib/StringConcatenation.java
StringConcatenation.append
public void append(String str, String indentation) { if (indentation.isEmpty()) { append(str); } else if (str != null) append(indentation, str, segments.size()); }
java
public void append(String str, String indentation) { if (indentation.isEmpty()) { append(str); } else if (str != null) append(indentation, str, segments.size()); }
[ "public", "void", "append", "(", "String", "str", ",", "String", "indentation", ")", "{", "if", "(", "indentation", ".", "isEmpty", "(", ")", ")", "{", "append", "(", "str", ")", ";", "}", "else", "if", "(", "str", "!=", "null", ")", "append", "(", "indentation", ",", "str", ",", "segments", ".", "size", "(", ")", ")", ";", "}" ]
Add the given string to this sequence. The given indentation will be prepended to each line except the first one if the object has a multi-line string representation. @param str the appended string. @param indentation the indentation string that should be prepended. May not be <code>null</code>. @since 2.11
[ "Add", "the", "given", "string", "to", "this", "sequence", ".", "The", "given", "indentation", "will", "be", "prepended", "to", "each", "line", "except", "the", "first", "one", "if", "the", "object", "has", "a", "multi", "-", "line", "string", "representation", "." ]
7063572e1f1bd713a3aa53bdf3a8dc60e25c169a
https://github.com/eclipse/xtext-lib/blob/7063572e1f1bd713a3aa53bdf3a8dc60e25c169a/org.eclipse.xtext.xbase.lib/src/org/eclipse/xtend2/lib/StringConcatenation.java#L239-L244
164,191
eclipse/xtext-lib
org.eclipse.xtext.xbase.lib/src/org/eclipse/xtend2/lib/StringConcatenation.java
StringConcatenation.append
protected void append(Object object, String indentation, int index) { if (indentation.length() == 0) { append(object, index); return; } if (object == null) return; if (object instanceof String) { append(indentation, (String)object, index); } else if (object instanceof StringConcatenation) { StringConcatenation other = (StringConcatenation) object; List<String> otherSegments = other.getSignificantContent(); appendSegments(indentation, index, otherSegments, other.lineDelimiter); } else if (object instanceof StringConcatenationClient) { StringConcatenationClient other = (StringConcatenationClient) object; other.appendTo(new IndentedTarget(this, indentation, index)); } else { final String text = getStringRepresentation(object); if (text != null) { append(indentation, text, index); } } }
java
protected void append(Object object, String indentation, int index) { if (indentation.length() == 0) { append(object, index); return; } if (object == null) return; if (object instanceof String) { append(indentation, (String)object, index); } else if (object instanceof StringConcatenation) { StringConcatenation other = (StringConcatenation) object; List<String> otherSegments = other.getSignificantContent(); appendSegments(indentation, index, otherSegments, other.lineDelimiter); } else if (object instanceof StringConcatenationClient) { StringConcatenationClient other = (StringConcatenationClient) object; other.appendTo(new IndentedTarget(this, indentation, index)); } else { final String text = getStringRepresentation(object); if (text != null) { append(indentation, text, index); } } }
[ "protected", "void", "append", "(", "Object", "object", ",", "String", "indentation", ",", "int", "index", ")", "{", "if", "(", "indentation", ".", "length", "(", ")", "==", "0", ")", "{", "append", "(", "object", ",", "index", ")", ";", "return", ";", "}", "if", "(", "object", "==", "null", ")", "return", ";", "if", "(", "object", "instanceof", "String", ")", "{", "append", "(", "indentation", ",", "(", "String", ")", "object", ",", "index", ")", ";", "}", "else", "if", "(", "object", "instanceof", "StringConcatenation", ")", "{", "StringConcatenation", "other", "=", "(", "StringConcatenation", ")", "object", ";", "List", "<", "String", ">", "otherSegments", "=", "other", ".", "getSignificantContent", "(", ")", ";", "appendSegments", "(", "indentation", ",", "index", ",", "otherSegments", ",", "other", ".", "lineDelimiter", ")", ";", "}", "else", "if", "(", "object", "instanceof", "StringConcatenationClient", ")", "{", "StringConcatenationClient", "other", "=", "(", "StringConcatenationClient", ")", "object", ";", "other", ".", "appendTo", "(", "new", "IndentedTarget", "(", "this", ",", "indentation", ",", "index", ")", ")", ";", "}", "else", "{", "final", "String", "text", "=", "getStringRepresentation", "(", "object", ")", ";", "if", "(", "text", "!=", "null", ")", "{", "append", "(", "indentation", ",", "text", ",", "index", ")", ";", "}", "}", "}" ]
Add the string representation of the given object to this sequence at the given index. The given indentation will be prepended to each line except the first one if the object has a multi-line string representation. @param object the to-be-appended object. @param indentation the indentation string that should be prepended. May not be <code>null</code>. @param index the index in the list of segments.
[ "Add", "the", "string", "representation", "of", "the", "given", "object", "to", "this", "sequence", "at", "the", "given", "index", ".", "The", "given", "indentation", "will", "be", "prepended", "to", "each", "line", "except", "the", "first", "one", "if", "the", "object", "has", "a", "multi", "-", "line", "string", "representation", "." ]
7063572e1f1bd713a3aa53bdf3a8dc60e25c169a
https://github.com/eclipse/xtext-lib/blob/7063572e1f1bd713a3aa53bdf3a8dc60e25c169a/org.eclipse.xtext.xbase.lib/src/org/eclipse/xtend2/lib/StringConcatenation.java#L293-L315
164,192
eclipse/xtext-lib
org.eclipse.xtext.xbase.lib/src/org/eclipse/xtend2/lib/StringConcatenation.java
StringConcatenation.appendImmediate
public void appendImmediate(Object object, String indentation) { for (int i = segments.size() - 1; i >= 0; i--) { String segment = segments.get(i); for (int j = 0; j < segment.length(); j++) { if (!WhitespaceMatcher.isWhitespace(segment.charAt(j))) { append(object, indentation, i + 1); return; } } } append(object, indentation, 0); }
java
public void appendImmediate(Object object, String indentation) { for (int i = segments.size() - 1; i >= 0; i--) { String segment = segments.get(i); for (int j = 0; j < segment.length(); j++) { if (!WhitespaceMatcher.isWhitespace(segment.charAt(j))) { append(object, indentation, i + 1); return; } } } append(object, indentation, 0); }
[ "public", "void", "appendImmediate", "(", "Object", "object", ",", "String", "indentation", ")", "{", "for", "(", "int", "i", "=", "segments", ".", "size", "(", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", ")", "{", "String", "segment", "=", "segments", ".", "get", "(", "i", ")", ";", "for", "(", "int", "j", "=", "0", ";", "j", "<", "segment", ".", "length", "(", ")", ";", "j", "++", ")", "{", "if", "(", "!", "WhitespaceMatcher", ".", "isWhitespace", "(", "segment", ".", "charAt", "(", "j", ")", ")", ")", "{", "append", "(", "object", ",", "indentation", ",", "i", "+", "1", ")", ";", "return", ";", "}", "}", "}", "append", "(", "object", ",", "indentation", ",", "0", ")", ";", "}" ]
Add the string representation of the given object to this sequence immediately. That is, all the trailing whitespace of this sequence will be ignored and the string is appended directly after the last segment that contains something besides whitespace. The given indentation will be prepended to each line except the first one if the object has a multi-line string representation. @param object the to-be-appended object. @param indentation the indentation string that should be prepended. May not be <code>null</code>.
[ "Add", "the", "string", "representation", "of", "the", "given", "object", "to", "this", "sequence", "immediately", ".", "That", "is", "all", "the", "trailing", "whitespace", "of", "this", "sequence", "will", "be", "ignored", "and", "the", "string", "is", "appended", "directly", "after", "the", "last", "segment", "that", "contains", "something", "besides", "whitespace", ".", "The", "given", "indentation", "will", "be", "prepended", "to", "each", "line", "except", "the", "first", "one", "if", "the", "object", "has", "a", "multi", "-", "line", "string", "representation", "." ]
7063572e1f1bd713a3aa53bdf3a8dc60e25c169a
https://github.com/eclipse/xtext-lib/blob/7063572e1f1bd713a3aa53bdf3a8dc60e25c169a/org.eclipse.xtext.xbase.lib/src/org/eclipse/xtend2/lib/StringConcatenation.java#L350-L361
164,193
eclipse/xtext-lib
org.eclipse.xtext.xbase.lib/src/org/eclipse/xtend2/lib/StringConcatenation.java
StringConcatenation.newLineIfNotEmpty
public void newLineIfNotEmpty() { for (int i = segments.size() - 1; i >= 0; i--) { String segment = segments.get(i); if (lineDelimiter.equals(segment)) { segments.subList(i + 1, segments.size()).clear(); cachedToString = null; return; } for (int j = 0; j < segment.length(); j++) { if (!WhitespaceMatcher.isWhitespace(segment.charAt(j))) { newLine(); return; } } } segments.clear(); cachedToString = null; }
java
public void newLineIfNotEmpty() { for (int i = segments.size() - 1; i >= 0; i--) { String segment = segments.get(i); if (lineDelimiter.equals(segment)) { segments.subList(i + 1, segments.size()).clear(); cachedToString = null; return; } for (int j = 0; j < segment.length(); j++) { if (!WhitespaceMatcher.isWhitespace(segment.charAt(j))) { newLine(); return; } } } segments.clear(); cachedToString = null; }
[ "public", "void", "newLineIfNotEmpty", "(", ")", "{", "for", "(", "int", "i", "=", "segments", ".", "size", "(", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", ")", "{", "String", "segment", "=", "segments", ".", "get", "(", "i", ")", ";", "if", "(", "lineDelimiter", ".", "equals", "(", "segment", ")", ")", "{", "segments", ".", "subList", "(", "i", "+", "1", ",", "segments", ".", "size", "(", ")", ")", ".", "clear", "(", ")", ";", "cachedToString", "=", "null", ";", "return", ";", "}", "for", "(", "int", "j", "=", "0", ";", "j", "<", "segment", ".", "length", "(", ")", ";", "j", "++", ")", "{", "if", "(", "!", "WhitespaceMatcher", ".", "isWhitespace", "(", "segment", ".", "charAt", "(", "j", ")", ")", ")", "{", "newLine", "(", ")", ";", "return", ";", "}", "}", "}", "segments", ".", "clear", "(", ")", ";", "cachedToString", "=", "null", ";", "}" ]
Add a newline to this sequence according to the configured lineDelimiter if the last line contains something besides whitespace.
[ "Add", "a", "newline", "to", "this", "sequence", "according", "to", "the", "configured", "lineDelimiter", "if", "the", "last", "line", "contains", "something", "besides", "whitespace", "." ]
7063572e1f1bd713a3aa53bdf3a8dc60e25c169a
https://github.com/eclipse/xtext-lib/blob/7063572e1f1bd713a3aa53bdf3a8dc60e25c169a/org.eclipse.xtext.xbase.lib/src/org/eclipse/xtend2/lib/StringConcatenation.java#L461-L478
164,194
eclipse/xtext-lib
org.eclipse.xtext.xbase.lib/src/org/eclipse/xtend2/lib/StringConcatenation.java
StringConcatenation.splitLinesAndNewLines
protected List<String> splitLinesAndNewLines(String text) { if (text == null) return Collections.emptyList(); int idx = initialSegmentSize(text); if (idx == text.length()) { return Collections.singletonList(text); } return continueSplitting(text, idx); }
java
protected List<String> splitLinesAndNewLines(String text) { if (text == null) return Collections.emptyList(); int idx = initialSegmentSize(text); if (idx == text.length()) { return Collections.singletonList(text); } return continueSplitting(text, idx); }
[ "protected", "List", "<", "String", ">", "splitLinesAndNewLines", "(", "String", "text", ")", "{", "if", "(", "text", "==", "null", ")", "return", "Collections", ".", "emptyList", "(", ")", ";", "int", "idx", "=", "initialSegmentSize", "(", "text", ")", ";", "if", "(", "idx", "==", "text", ".", "length", "(", ")", ")", "{", "return", "Collections", ".", "singletonList", "(", "text", ")", ";", "}", "return", "continueSplitting", "(", "text", ",", "idx", ")", ";", "}" ]
Return a list of segments where each segment is either the content of a line in the given text or a line-break according to the configured delimiter. Existing line-breaks in the text will be replaced by this's instances delimiter. @param text the to-be-splitted text. May be <code>null</code>. @return a list of segments. Is never <code>null</code>.
[ "Return", "a", "list", "of", "segments", "where", "each", "segment", "is", "either", "the", "content", "of", "a", "line", "in", "the", "given", "text", "or", "a", "line", "-", "break", "according", "to", "the", "configured", "delimiter", ".", "Existing", "line", "-", "breaks", "in", "the", "text", "will", "be", "replaced", "by", "this", "s", "instances", "delimiter", "." ]
7063572e1f1bd713a3aa53bdf3a8dc60e25c169a
https://github.com/eclipse/xtext-lib/blob/7063572e1f1bd713a3aa53bdf3a8dc60e25c169a/org.eclipse.xtext.xbase.lib/src/org/eclipse/xtend2/lib/StringConcatenation.java#L582-L591
164,195
eclipse/xtext-lib
org.eclipse.xtext.xbase.lib/src/org/eclipse/xtext/xbase/lib/Pair.java
Pair.of
@Pure public static <K, V> Pair<K, V> of(K k, V v) { return new Pair<K, V>(k, v); }
java
@Pure public static <K, V> Pair<K, V> of(K k, V v) { return new Pair<K, V>(k, v); }
[ "@", "Pure", "public", "static", "<", "K", ",", "V", ">", "Pair", "<", "K", ",", "V", ">", "of", "(", "K", "k", ",", "V", "v", ")", "{", "return", "new", "Pair", "<", "K", ",", "V", ">", "(", "k", ",", "v", ")", ";", "}" ]
Creates a new instance with the given key and value. May be used instead of the constructor for convenience reasons. @param k the key. May be <code>null</code>. @param v the value. May be <code>null</code>. @return a newly created pair. Never <code>null</code>. @since 2.3
[ "Creates", "a", "new", "instance", "with", "the", "given", "key", "and", "value", ".", "May", "be", "used", "instead", "of", "the", "constructor", "for", "convenience", "reasons", "." ]
7063572e1f1bd713a3aa53bdf3a8dc60e25c169a
https://github.com/eclipse/xtext-lib/blob/7063572e1f1bd713a3aa53bdf3a8dc60e25c169a/org.eclipse.xtext.xbase.lib/src/org/eclipse/xtext/xbase/lib/Pair.java#L42-L45
164,196
eclipse/xtext-lib
org.eclipse.xtext.xbase.lib/src/org/eclipse/xtext/xbase/lib/ProcedureExtensions.java
ProcedureExtensions.curry
@Pure public static <P1> Procedure0 curry(final Procedure1<? super P1> procedure, final P1 argument) { if (procedure == null) throw new NullPointerException("procedure"); return new Procedure0() { @Override public void apply() { procedure.apply(argument); } }; }
java
@Pure public static <P1> Procedure0 curry(final Procedure1<? super P1> procedure, final P1 argument) { if (procedure == null) throw new NullPointerException("procedure"); return new Procedure0() { @Override public void apply() { procedure.apply(argument); } }; }
[ "@", "Pure", "public", "static", "<", "P1", ">", "Procedure0", "curry", "(", "final", "Procedure1", "<", "?", "super", "P1", ">", "procedure", ",", "final", "P1", "argument", ")", "{", "if", "(", "procedure", "==", "null", ")", "throw", "new", "NullPointerException", "(", "\"procedure\"", ")", ";", "return", "new", "Procedure0", "(", ")", "{", "@", "Override", "public", "void", "apply", "(", ")", "{", "procedure", ".", "apply", "(", "argument", ")", ";", "}", "}", ";", "}" ]
Curries a procedure that takes one argument. @param procedure the original procedure. May not be <code>null</code>. @param argument the fixed argument. @return a procedure that takes no arguments. Never <code>null</code>.
[ "Curries", "a", "procedure", "that", "takes", "one", "argument", "." ]
7063572e1f1bd713a3aa53bdf3a8dc60e25c169a
https://github.com/eclipse/xtext-lib/blob/7063572e1f1bd713a3aa53bdf3a8dc60e25c169a/org.eclipse.xtext.xbase.lib/src/org/eclipse/xtext/xbase/lib/ProcedureExtensions.java#L37-L47
164,197
eclipse/xtext-lib
org.eclipse.xtext.xbase.lib/src/org/eclipse/xtext/xbase/lib/ProcedureExtensions.java
ProcedureExtensions.curry
@Pure public static <P1, P2> Procedure1<P2> curry(final Procedure2<? super P1, ? super P2> procedure, final P1 argument) { if (procedure == null) throw new NullPointerException("procedure"); return new Procedure1<P2>() { @Override public void apply(P2 p) { procedure.apply(argument, p); } }; }
java
@Pure public static <P1, P2> Procedure1<P2> curry(final Procedure2<? super P1, ? super P2> procedure, final P1 argument) { if (procedure == null) throw new NullPointerException("procedure"); return new Procedure1<P2>() { @Override public void apply(P2 p) { procedure.apply(argument, p); } }; }
[ "@", "Pure", "public", "static", "<", "P1", ",", "P2", ">", "Procedure1", "<", "P2", ">", "curry", "(", "final", "Procedure2", "<", "?", "super", "P1", ",", "?", "super", "P2", ">", "procedure", ",", "final", "P1", "argument", ")", "{", "if", "(", "procedure", "==", "null", ")", "throw", "new", "NullPointerException", "(", "\"procedure\"", ")", ";", "return", "new", "Procedure1", "<", "P2", ">", "(", ")", "{", "@", "Override", "public", "void", "apply", "(", "P2", "p", ")", "{", "procedure", ".", "apply", "(", "argument", ",", "p", ")", ";", "}", "}", ";", "}" ]
Curries a procedure that takes two arguments. @param procedure the original procedure. May not be <code>null</code>. @param argument the fixed first argument of {@code procedure}. @return a procedure that takes one argument. Never <code>null</code>.
[ "Curries", "a", "procedure", "that", "takes", "two", "arguments", "." ]
7063572e1f1bd713a3aa53bdf3a8dc60e25c169a
https://github.com/eclipse/xtext-lib/blob/7063572e1f1bd713a3aa53bdf3a8dc60e25c169a/org.eclipse.xtext.xbase.lib/src/org/eclipse/xtext/xbase/lib/ProcedureExtensions.java#L58-L68
164,198
eclipse/xtext-lib
org.eclipse.xtext.xbase.lib/src/org/eclipse/xtext/xbase/lib/ProcedureExtensions.java
ProcedureExtensions.curry
@Pure public static <P1, P2, P3> Procedure2<P2, P3> curry(final Procedure3<? super P1, ? super P2, ? super P3> procedure, final P1 argument) { if (procedure == null) throw new NullPointerException("procedure"); return new Procedure2<P2, P3>() { @Override public void apply(P2 p2, P3 p3) { procedure.apply(argument, p2, p3); } }; }
java
@Pure public static <P1, P2, P3> Procedure2<P2, P3> curry(final Procedure3<? super P1, ? super P2, ? super P3> procedure, final P1 argument) { if (procedure == null) throw new NullPointerException("procedure"); return new Procedure2<P2, P3>() { @Override public void apply(P2 p2, P3 p3) { procedure.apply(argument, p2, p3); } }; }
[ "@", "Pure", "public", "static", "<", "P1", ",", "P2", ",", "P3", ">", "Procedure2", "<", "P2", ",", "P3", ">", "curry", "(", "final", "Procedure3", "<", "?", "super", "P1", ",", "?", "super", "P2", ",", "?", "super", "P3", ">", "procedure", ",", "final", "P1", "argument", ")", "{", "if", "(", "procedure", "==", "null", ")", "throw", "new", "NullPointerException", "(", "\"procedure\"", ")", ";", "return", "new", "Procedure2", "<", "P2", ",", "P3", ">", "(", ")", "{", "@", "Override", "public", "void", "apply", "(", "P2", "p2", ",", "P3", "p3", ")", "{", "procedure", ".", "apply", "(", "argument", ",", "p2", ",", "p3", ")", ";", "}", "}", ";", "}" ]
Curries a procedure that takes three arguments. @param procedure the original procedure. May not be <code>null</code>. @param argument the fixed first argument of {@code procedure}. @return a procedure that takes two arguments. Never <code>null</code>.
[ "Curries", "a", "procedure", "that", "takes", "three", "arguments", "." ]
7063572e1f1bd713a3aa53bdf3a8dc60e25c169a
https://github.com/eclipse/xtext-lib/blob/7063572e1f1bd713a3aa53bdf3a8dc60e25c169a/org.eclipse.xtext.xbase.lib/src/org/eclipse/xtext/xbase/lib/ProcedureExtensions.java#L79-L89
164,199
eclipse/xtext-lib
org.eclipse.xtext.xbase.lib/src/org/eclipse/xtext/xbase/lib/ProcedureExtensions.java
ProcedureExtensions.curry
@Pure public static <P1, P2, P3, P4, P5> Procedure4<P2, P3, P4, P5> curry(final Procedure5<? super P1, ? super P2, ? super P3, ? super P4, ? super P5> procedure, final P1 argument) { if (procedure == null) throw new NullPointerException("procedure"); return new Procedure4<P2, P3, P4, P5>() { @Override public void apply(P2 p2, P3 p3, P4 p4, P5 p5) { procedure.apply(argument, p2, p3, p4, p5); } }; }
java
@Pure public static <P1, P2, P3, P4, P5> Procedure4<P2, P3, P4, P5> curry(final Procedure5<? super P1, ? super P2, ? super P3, ? super P4, ? super P5> procedure, final P1 argument) { if (procedure == null) throw new NullPointerException("procedure"); return new Procedure4<P2, P3, P4, P5>() { @Override public void apply(P2 p2, P3 p3, P4 p4, P5 p5) { procedure.apply(argument, p2, p3, p4, p5); } }; }
[ "@", "Pure", "public", "static", "<", "P1", ",", "P2", ",", "P3", ",", "P4", ",", "P5", ">", "Procedure4", "<", "P2", ",", "P3", ",", "P4", ",", "P5", ">", "curry", "(", "final", "Procedure5", "<", "?", "super", "P1", ",", "?", "super", "P2", ",", "?", "super", "P3", ",", "?", "super", "P4", ",", "?", "super", "P5", ">", "procedure", ",", "final", "P1", "argument", ")", "{", "if", "(", "procedure", "==", "null", ")", "throw", "new", "NullPointerException", "(", "\"procedure\"", ")", ";", "return", "new", "Procedure4", "<", "P2", ",", "P3", ",", "P4", ",", "P5", ">", "(", ")", "{", "@", "Override", "public", "void", "apply", "(", "P2", "p2", ",", "P3", "p3", ",", "P4", "p4", ",", "P5", "p5", ")", "{", "procedure", ".", "apply", "(", "argument", ",", "p2", ",", "p3", ",", "p4", ",", "p5", ")", ";", "}", "}", ";", "}" ]
Curries a procedure that takes five arguments. @param procedure the original procedure. May not be <code>null</code>. @param argument the fixed first argument of {@code procedure}. @return a procedure that takes four arguments. Never <code>null</code>.
[ "Curries", "a", "procedure", "that", "takes", "five", "arguments", "." ]
7063572e1f1bd713a3aa53bdf3a8dc60e25c169a
https://github.com/eclipse/xtext-lib/blob/7063572e1f1bd713a3aa53bdf3a8dc60e25c169a/org.eclipse.xtext.xbase.lib/src/org/eclipse/xtext/xbase/lib/ProcedureExtensions.java#L122-L133