Repository navigation
Expand file tree
/
Copy pathIPAddressSegment.java
More file actions
654 lines (569 loc) · 23.3 KB
/
Copy pathIPAddressSegment.java
File metadata and controls
654 lines (569 loc) · 23.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
/*
* Copyright 2017 Sean C Foley
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* or at
* https://github.com/seancfoley/IPAddress/blob/master/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inet.ipaddr;
import java.util.Iterator;
import inet.ipaddr.AddressNetwork.AddressSegmentCreator;
import inet.ipaddr.IPAddress.IPVersion;
import inet.ipaddr.IPAddressSection.IPStringCache;
import inet.ipaddr.IPAddressSection.IPStringOptions;
import inet.ipaddr.format.AddressDivision;
import inet.ipaddr.format.IPAddressDivision;
import inet.ipaddr.format.IPAddressStringDivisionSeries;
import inet.ipaddr.format.util.IPAddressStringWriter;
import inet.ipaddr.ipv4.IPv4Address;
import inet.ipaddr.ipv6.IPv6Address;
/**
* This represents a single segment of an IP address. For IPv4, segments are 1 byte. For IPv6, they are two bytes.
*
* IPAddressSegment objects are immutable and thus also thread-safe.
*
* @author sfoley
*
*/
public abstract class IPAddressSegment extends IPAddressDivision implements AddressSegment {
private static final long serialVersionUID = 4L;
// These two values define the uniqueness of a segment with respect to equality and comparison, while the prefix is ignored as these values encapsulate the range of addresses created by the prefix.
private final int value; // the lower value of the segment
private final int upperValue; // the upper value of a CIDR or other type of range, if not a range it is the same as value
/**
* Constructs a segment of an IPv4 or IPv6 address with the given value.
*
* @param value the value of the segment
*/
protected IPAddressSegment(int value) {
if(value < 0) {
throw new AddressValueException(value);
}
this.value = this.upperValue = value;
}
/**
* Constructs a segment of an IPv4 or IPv6 address.
*
* @param value the value of the segment.
* If the segmentPrefixLength is non-null, the network prefix of the value is used, and the segment represents all segment values with the same network prefix (all network or subnet segments, in other words).
* @param segmentPrefixLength the segment prefix bits, which can be null
*/
protected IPAddressSegment(int value, Integer segmentPrefixLength) {
this(value, value, segmentPrefixLength);
}
/**
* Constructs a segment of an IPv4 or IPv6 address that represents a range of values.
*
* @param segmentPrefixLength the segment prefix bits, which can be null. If segmentPrefixLength is non-null, this segment represents a range of segment values with the given network prefix length.
* @param lower the lower value of the range of values represented by the segment. If segmentPrefixLength is non-null, the lower value becomes the smallest value with the same network prefix.
* @param upper the upper value of the range of values represented by the segment. If segmentPrefixLength is non-null, the upper value becomes the largest value with the same network prefix.
*/
protected IPAddressSegment(int lower, int upper, Integer segmentPrefixLength) {
super(segmentPrefixLength);
if(lower < 0 || upper < 0) {
throw new AddressValueException(lower < 0 ? lower : upper);
}
if(lower > upper) {
int tmp = lower;
lower = upper;
upper = tmp;
}
segmentPrefixLength = getSegmentPrefixLength();
if(segmentPrefixLength == null || segmentPrefixLength >= getBitCount() || !getNetwork().getPrefixConfiguration().allPrefixedAddressesAreSubnets()) {
this.value = lower;
this.upperValue = upper;
} else {
int mask = getSegmentNetworkMask(segmentPrefixLength);
this.value = lower & mask;
this.upperValue = upper | getSegmentHostMask(segmentPrefixLength);
}
}
@Override
public abstract IPAddressNetwork<?, ?, ?, ?, ?> getNetwork();
public boolean isIPv4() {
return false;
}
public boolean isIPv6() {
return false;
}
public abstract IPVersion getIPVersion();
protected static Integer getSplitSegmentPrefix(int bitsPerSegment, Integer networkPrefixLength, int segmentIndex) {
return IPAddressSection.getSegmentPrefixLength(bitsPerSegment, networkPrefixLength, segmentIndex);
}
@Override
protected long getDivisionNetworkMask(int bits) {
return getSegmentNetworkMask(bits);
}
@Override
protected long getDivisionHostMask(int bits) {
return getSegmentHostMask(bits);
}
protected abstract int getSegmentNetworkMask(int bits);
protected abstract int getSegmentHostMask(int bits);
@Override
public int getMinPrefixLengthForBlock() {
if(getNetwork().getPrefixConfiguration().allPrefixedAddressesAreSubnets() && isPrefixed() && getSegmentPrefixLength() == 0) {
return 0;
}
return super.getMinPrefixLengthForBlock();
}
public static int getMaxSegmentValue(IPVersion version) {
return version.isIPv4() ? IPv4Address.MAX_VALUE_PER_SEGMENT : IPv6Address.MAX_VALUE_PER_SEGMENT;
}
protected boolean isChangedByPrefix(Integer bits, boolean smallerOnly) {
boolean hasBits = (bits != null);
if(hasBits && (bits < 0 || bits > getBitCount())) {
throw new PrefixLenException(this, bits);
}
if(smallerOnly) {
if(isPrefixed()) {
return hasBits && bits < getSegmentPrefixLength();
}
} else {
if(isPrefixed()) {
return !hasBits || bits != getSegmentPrefixLength().intValue();
}
}
return hasBits;
}
protected <S extends IPAddressSegment> S toPrefixedSegment(Integer segmentPrefixLength, AddressSegmentCreator<S> creator) {
int lower = getLowerSegmentValue();
int upper = getUpperSegmentValue();
boolean hasBits = (segmentPrefixLength != null);
if(lower != upper) {
//note that the case where our segmentPrefix is less than the requested prefix bits has already been accounted for in isNetworkChangedByPrefix
//so we are not handling that here
if(!hasBits) {
return creator.createSegment(lower, upper, null);
}
return creator.createSegment(lower, upper, segmentPrefixLength);
}
return hasBits ? creator.createSegment(lower, segmentPrefixLength) : creator.createSegment(lower);
}
@Override
public boolean isPrefixBlock() {
return (isPrefixed() && getNetwork().getPrefixConfiguration().allPrefixedAddressesAreSubnets()) || super.isPrefixBlock();
}
protected boolean isNetworkChangedByPrefix(Integer bits, boolean withPrefixLength) {
boolean hasBits = (bits != null);
if(hasBits && (bits < 0 || bits > getBitCount())) {
throw new PrefixLenException(this, bits);
}
withPrefixLength &= hasBits;
boolean thisHasPrefix = isPrefixed();
if(withPrefixLength != thisHasPrefix) {
return true;
}
if(hasBits && bits != getDivisionPrefixLength()) {
return true;
}
return
//this call differs from the host side. On the host side, we check that the network portion is 0
//on the network side, we check that the host side is the full range, not 0.
//This means that any resulting network section is the same regardless of whether a prefix is used: we don't need a prefix.
!hasBits || !isPrefixBlock(bits);
}
/**
* used by constructors of IPAddressSection, see {@link IPAddress#getNetworkSection(int, boolean)}
*/
public IPAddressSegment toNetworkSegment(Integer segmentPrefixLength) {
return toNetworkSegment(segmentPrefixLength, true);
}
/**
* used by getNetworkSection and by constructors of IPAddressSection, see {@link IPAddress#getNetworkSection(int, boolean)}
*/
public abstract IPAddressSegment toNetworkSegment(Integer segmentPrefixLength, boolean withPrefixLength);
protected <S extends IPAddressSegment> S toNetworkSegment(Integer segmentPrefixLength, boolean withPrefixLength, AddressSegmentCreator<S> creator) {
int newLower = getLowerSegmentValue();
int newUpper = getUpperSegmentValue();
if(segmentPrefixLength != null) {
int mask = getSegmentNetworkMask(segmentPrefixLength);
newLower &= mask;
newUpper |= getSegmentHostMask(segmentPrefixLength);
}
boolean hasBits = (segmentPrefixLength != null);
withPrefixLength &= hasBits;
if(newLower != newUpper) {
//note that the case where our segmentPrefix is less than the requested prefix bits has already been accounted for in isNetworkChangedByPrefix
//so we are not handling that here
if(!withPrefixLength) {
return creator.createSegment(newLower, newUpper, null);
}
return creator.createSegment(newLower, newUpper, segmentPrefixLength);
}
return withPrefixLength ? creator.createSegment(newLower, segmentPrefixLength) : creator.createSegment(newLower);
}
/**
* used by getHostSection, see {@link IPAddress#getHostSection(int)}
*/
public abstract IPAddressSegment toHostSegment(Integer segmentPrefixLength);
protected <S extends IPAddressSegment> S toHostSegment(Integer segmentPrefixLength, AddressSegmentCreator<S> creator) {
int mask = (segmentPrefixLength == null) ? 0 : getSegmentHostMask(segmentPrefixLength);
int newLower = getLowerSegmentValue() & mask;
int newUpper = getUpperSegmentValue() & mask;
if(newLower != newUpper) {
return creator.createSegment(newLower, newUpper, null);
}
return creator.createSegment(newLower);
}
protected boolean isHostChangedByPrefix(Integer bits) {
boolean hasBits = (bits != null);
if(hasBits && (bits < 0 || bits > getBitCount())) {
throw new PrefixLenException(this, bits);
}
//a host segment has no prefix, so if this remains unchanged it must have no prefix length
if(isPrefixed()) {
return true;
}
int mask = !hasBits ? 0 : getSegmentHostMask(bits);
//additionally, the value must match the value for the given network prefix length
int value = getLowerSegmentValue();
int upperValue = getUpperSegmentValue();
return value != (value & mask) || upperValue != (upperValue & mask);
}
/**
* 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.
*
*/
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 = getLowerSegmentValue();
int upperValue = getUpperSegmentValue();
return value != (value & maskValue) ||
upperValue != (upperValue & maskValue) ||
(isPrefixed() ? !getSegmentPrefixLength().equals(segmentPrefixLength) : hasBits);
}
protected boolean isChangedByOr(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 = getLowerSegmentValue();
int upperValue = getUpperSegmentValue();
return value != (value | maskValue) ||
upperValue != (upperValue | maskValue) ||
(isPrefixed() ? !getSegmentPrefixLength().equals(segmentPrefixLength) : hasBits);
}
/**
* 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
*/
public boolean isMaskCompatibleWithRange(int maskValue, Integer segmentPrefixLength) throws PrefixLenException {
if(!isMultiple()) {
return true;
}
return super.isMaskCompatibleWithRange(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
*/
public boolean isBitwiseOrCompatibleWithRange(int maskValue, Integer segmentPrefixLength) throws PrefixLenException {
return super.isBitwiseOrCompatibleWithRange(maskValue, segmentPrefixLength, getNetwork().getPrefixConfiguration().allPrefixedAddressesAreSubnets());
}
/**
* If this segment represents a range of values, returns a segment representing just the lowest value in the range, otherwise returns this.
* @return
*/
@Override
public abstract IPAddressSegment getLower();
/**
* If this segment represents a range of values, returns a segment representing just the highest value in the range, otherwise returns this.
* @return
*/
@Override
public abstract IPAddressSegment getUpper();
protected static <S extends IPAddressSegment> S getLowestOrHighest(S original, AddressSegmentCreator<S> segmentCreator, boolean lowest) {
if(!original.isMultiple() && !original.isPrefixed()) {//like with the iterator, we do not return segments with prefix, even if it is the full bit length
return original;
}
return segmentCreator.createSegment(lowest ? original.getLowerSegmentValue() : original.getUpperSegmentValue(),
original.getNetwork().getPrefixConfiguration().allPrefixedAddressesAreSubnets() ? null : original.getSegmentPrefixLength());
}
@Override
public abstract Iterable<? extends IPAddressSegment> getIterable();
@Override
public abstract Iterator<? extends IPAddressSegment> iterator();
/**
* Iterates through the individual prefix blocks.
*
* If the series has no prefix length, then this is equivalent to {@link #iterator()}
*/
public abstract Iterator<? extends IPAddressSegment> prefixBlockIterator();
public static int getBitCount(IPVersion version) {
return version.isIPv4() ? IPv4Address.BITS_PER_SEGMENT : IPv6Address.BITS_PER_SEGMENT;
}
public static int getByteCount(IPVersion version) {
return version.isIPv4() ? IPv4Address.BYTES_PER_SEGMENT : IPv6Address.BYTES_PER_SEGMENT;
}
public static int getDefaultTextualRadix(IPVersion version) {
return version.isIPv4() ? IPv4Address.DEFAULT_TEXTUAL_RADIX : IPv6Address.DEFAULT_TEXTUAL_RADIX;
}
@Override
public boolean matches(int value) {
return super.matches(value);
}
public boolean matchesWithPrefixMask(int value, Integer segmentPrefixLength) {
return super.matchesWithPrefixMask(value, segmentPrefixLength);
}
@Override
public boolean matchesWithMask(int value, int mask) {
return super.matchesWithMask(value, mask);
}
@Override
public boolean matchesWithMask(int lowerValue, int upperValue, int mask) {
return super.matchesWithMask(lowerValue, upperValue, mask);
}
@Override
public int getValueCount() {
return getUpperSegmentValue() - getLowerSegmentValue() + 1;
}
/**
* Counts the number of prefixes in this address segment.
* <p>
* If this segment has no prefix length, this is equivalent to {@link #getValueCount()}
*
* @return
*/
public int getPrefixValueCount() {
Integer prefixLength = getSegmentPrefixLength();
if(prefixLength == null) {
return getValueCount();
}
int shiftAdjustment = getBitCount() - prefixLength;
return (getUpperSegmentValue() >>> shiftAdjustment) - (getLowerSegmentValue() >>> shiftAdjustment) + 1;
}
@Override
public long getDivisionValueCount() {
return getValueCount();
}
protected int highByte() {
return highByte(getLowerSegmentValue());
}
protected int lowByte() {
return lowByte(getLowerSegmentValue());
}
protected static int highByte(int value) {
return value >> 8;
}
protected static int lowByte(int value) {
return value & 0xff;
}
@Override
public long getMaxValue() {
return getMaxSegmentValue();
}
@Override
public boolean isMultiple() {
return getLowerSegmentValue() != getUpperSegmentValue();
}
/**
* returns the lower value
*/
@Override
public int getLowerSegmentValue() {
return value;
}
/**
* returns the upper value
*/
@Override
public int getUpperSegmentValue() {
return upperValue;
}
/**
* returns the lower value as a long, although for individual segments {@link #getLowerSegmentValue()} provides the same value as an int
*/
@Override
public long getLowerValue() {
return getLowerSegmentValue();
}
/**
* returns the lower upper value as a long, although for individual segments {@link #getUpperSegmentValue()} provides the same value as an int
*/
@Override
public long getUpperValue() {
return getUpperSegmentValue();
}
@Override
public abstract IPAddressSegment reverseBits(boolean perByte);
@Override
public abstract IPAddressSegment reverseBytes();
public abstract IPAddressSegment removePrefixLength();
public abstract IPAddressSegment removePrefixLength(boolean zeroed);
protected static <S extends IPAddressSegment> S removePrefix(S original, boolean zeroed, AddressSegmentCreator<S> creator) {
if(original.isPrefixed()) {
int lower = original.getLowerSegmentValue();
int upper = original.getUpperSegmentValue();
if(zeroed) {
int maskBits = original.getSegmentNetworkMask(original.getSegmentPrefixLength());
if(!original.isMaskCompatibleWithRange(maskBits, null)) {
throw new IncompatibleAddressException(original, maskBits, "ipaddress.error.maskMismatch");
}
return creator.createSegment(lower & maskBits, upper & maskBits, null);
}
return creator.createSegment(lower, upper, null);
}
return original;
}
@Override
public boolean isBoundedBy(int value) {
return getUpperSegmentValue() < value;
}
public Integer getSegmentPrefixLength() {
return getDivisionPrefixLength();
}
@Override
protected boolean isSameValues(AddressDivision other) {
if(other instanceof IPAddressSegment) {
return isSameValues((IPAddressSegment) other);
}
return false;
}
protected boolean isSameValues(IPAddressSegment otherSegment) {
//note that it is the range of values that matters, the prefix bits do not
return getLowerSegmentValue() == otherSegment.getLowerSegmentValue() && getUpperSegmentValue() == otherSegment.getUpperSegmentValue();
}
@Override
public int hashCode() {
return hash(getLowerSegmentValue(), getUpperSegmentValue(), getBitCount());
}
static int hash(int lower, int upper, int bitCount) {
return lower | (upper << bitCount);
}
/**
*
* @param other
* @return whether this subnet segment contains the given address segment
*/
protected boolean containsSeg(AddressSegment other) {
return other.getLowerSegmentValue() >= getLowerSegmentValue() && other.getUpperSegmentValue() <= getUpperSegmentValue();
}
@Override
public boolean includesZero() {
return getLowerSegmentValue() == 0;
}
@Override
public boolean includesMax() {
return getUpperSegmentValue() == getMaxSegmentValue();
}
@Override
public String toHexString(boolean with0xPrefix) {
return toNormalizedString(with0xPrefix ? IPStringCache.hexPrefixedParams : IPStringCache.hexParams);
}
@Override
public String toNormalizedString() {
return toNormalizedString(IPStringCache.canonicalSegmentParams);
}
public String toNormalizedString(IPStringOptions options) {
IPAddressStringWriter<IPAddressStringDivisionSeries> params = IPAddressSection.toIPParams(options);
StringBuilder builder = new StringBuilder(params.getDivisionStringLength(this));
return params.appendDivision(builder, this).toString();
}
protected static int toUnsignedStringLength(int value, int radix) {
return AddressDivision.toUnsignedStringLength(value, radix);
}
protected static StringBuilder toUnsignedString(int value, int radix, StringBuilder appendable) {
return toUnsignedString(value, radix, 0, false, DIGITS, appendable);
}
void setStandardString(
CharSequence addressStr,
boolean isStandardString,
int lowerStringStartIndex,
int lowerStringEndIndex,
int originalLowerValue) {
if(cachedString == null && isStandardString && originalLowerValue == getLowerValue()) {
cachedString = addressStr.subSequence(lowerStringStartIndex, lowerStringEndIndex).toString();
}
}
void setWildcardString(
CharSequence addressStr,
boolean isStandardString,
int lowerStringStartIndex,
int lowerStringEndIndex,
int lowerValue) {
if(cachedWildcardString == null && isStandardString && lowerValue == getLowerValue() && lowerValue == getUpperValue()) {
cachedWildcardString = addressStr.subSequence(lowerStringStartIndex, lowerStringEndIndex).toString();
}
}
void setStandardString(
CharSequence addressStr,
boolean isStandardString,
boolean isStandardRangeString,
int lowerStringStartIndex,
int lowerStringEndIndex,
int upperStringEndIndex,
int rangeLower,
int rangeUpper) {
if(cachedString == null) {
if(isSinglePrefixBlock()) {
if(isStandardString && rangeLower == getLowerValue()) {
cachedString = addressStr.subSequence(lowerStringStartIndex, lowerStringEndIndex).toString();
}
} else if(isFullRange()) {
cachedString = IPAddress.SEGMENT_WILDCARD_STR;
} else if(isStandardRangeString && rangeLower == getLowerValue()) {
long upper = getUpperValue();
if(isPrefixed()) {
upper &= getDivisionNetworkMask(getDivisionPrefixLength());
}
if(rangeUpper == upper) {
cachedString = addressStr.subSequence(lowerStringStartIndex, upperStringEndIndex).toString();
}
}
}
}
void setWildcardString(
CharSequence addressStr,
boolean isStandardRangeString,
int lowerStringStartIndex,
int upperStringEndIndex,
int rangeLower,
int rangeUpper) {
if(cachedWildcardString == null) {
if(isFullRange()) {
cachedWildcardString = IPAddress.SEGMENT_WILDCARD_STR;
} else if(isStandardRangeString && rangeLower == getLowerValue() && rangeUpper == getUpperValue()) {
cachedWildcardString = addressStr.subSequence(lowerStringStartIndex, upperStringEndIndex).toString();
}
}
}
}