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,000 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java | SignatureFinder.getSignatures | public Map<Integer, String> getSignatures() {
ensureRunning();
// Make a copy so callers get an immutable snapshot of the current state.
return Collections.unmodifiableMap(new HashMap<Integer, String>(signatures));
} | java | public Map<Integer, String> getSignatures() {
ensureRunning();
// Make a copy so callers get an immutable snapshot of the current state.
return Collections.unmodifiableMap(new HashMap<Integer, String>(signatures));
} | [
"public",
"Map",
"<",
"Integer",
",",
"String",
">",
"getSignatures",
"(",
")",
"{",
"ensureRunning",
"(",
")",
";",
"// Make a copy so callers get an immutable snapshot of the current state.",
"return",
"Collections",
".",
"unmodifiableMap",
"(",
"new",
"HashMap",
"<",
"Integer",
",",
"String",
">",
"(",
"signatures",
")",
")",
";",
"}"
] | Get the signatures that have been computed for all tracks currently loaded in any player for which we have
been able to obtain all necessary metadata.
@return the signatures that uniquely identify the tracks loaded in each player
@throws IllegalStateException if the SignatureFinder is not running | [
"Get",
"the",
"signatures",
"that",
"have",
"been",
"computed",
"for",
"all",
"tracks",
"currently",
"loaded",
"in",
"any",
"player",
"for",
"which",
"we",
"have",
"been",
"able",
"to",
"obtain",
"all",
"necessary",
"metadata",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java#L143-L147 |
164,001 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java | SignatureFinder.checkExistingTracks | private void checkExistingTracks() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (Map.Entry<DeckReference, TrackMetadata> entry : MetadataFinder.getInstance().getLoadedTracks().entrySet()) {
if (entry.getKey().hotCue == 0) { // The track is currently loaded in a main player deck
checkIfSignatureReady(entry.getKey().player);
}
}
}
});
} | java | private void checkExistingTracks() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (Map.Entry<DeckReference, TrackMetadata> entry : MetadataFinder.getInstance().getLoadedTracks().entrySet()) {
if (entry.getKey().hotCue == 0) { // The track is currently loaded in a main player deck
checkIfSignatureReady(entry.getKey().player);
}
}
}
});
} | [
"private",
"void",
"checkExistingTracks",
"(",
")",
"{",
"SwingUtilities",
".",
"invokeLater",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"for",
"(",
"Map",
".",
"Entry",
"<",
"DeckReference",
",",
"TrackMetadata",
">",
"entry",
":",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"getLoadedTracks",
"(",
")",
".",
"entrySet",
"(",
")",
")",
"{",
"if",
"(",
"entry",
".",
"getKey",
"(",
")",
".",
"hotCue",
"==",
"0",
")",
"{",
"// The track is currently loaded in a main player deck",
"checkIfSignatureReady",
"(",
"entry",
".",
"getKey",
"(",
")",
".",
"player",
")",
";",
"}",
"}",
"}",
"}",
")",
";",
"}"
] | Send ourselves "updates" about any tracks that were loaded before we started, since we missed them. | [
"Send",
"ourselves",
"updates",
"about",
"any",
"tracks",
"that",
"were",
"loaded",
"before",
"we",
"started",
"since",
"we",
"missed",
"them",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java#L267-L278 |
164,002 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java | SignatureFinder.digestInteger | private void digestInteger(MessageDigest digest, int value) {
byte[] valueBytes = new byte[4];
Util.numberToBytes(value, valueBytes, 0, 4);
digest.update(valueBytes);
} | java | private void digestInteger(MessageDigest digest, int value) {
byte[] valueBytes = new byte[4];
Util.numberToBytes(value, valueBytes, 0, 4);
digest.update(valueBytes);
} | [
"private",
"void",
"digestInteger",
"(",
"MessageDigest",
"digest",
",",
"int",
"value",
")",
"{",
"byte",
"[",
"]",
"valueBytes",
"=",
"new",
"byte",
"[",
"4",
"]",
";",
"Util",
".",
"numberToBytes",
"(",
"value",
",",
"valueBytes",
",",
"0",
",",
"4",
")",
";",
"digest",
".",
"update",
"(",
"valueBytes",
")",
";",
"}"
] | Helper method to add a Java integer value to a message digest.
@param digest the message digest being built
@param value the integer whose bytes should be included in the digest | [
"Helper",
"method",
"to",
"add",
"a",
"Java",
"integer",
"value",
"to",
"a",
"message",
"digest",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java#L286-L290 |
164,003 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java | SignatureFinder.computeTrackSignature | public String computeTrackSignature(final String title, final SearchableItem artist, final int duration,
final WaveformDetail waveformDetail, final BeatGrid beatGrid) {
final String safeTitle = (title == null)? "" : title;
final String artistName = (artist == null)? "[no artist]" : artist.label;
try {
// Compute the SHA-1 hash of our fields
MessageDigest digest = MessageDigest.getInstance("SHA1");
digest.update(safeTitle.getBytes("UTF-8"));
digest.update((byte) 0);
digest.update(artistName.getBytes("UTF-8"));
digest.update((byte) 0);
digestInteger(digest, duration);
digest.update(waveformDetail.getData());
for (int i = 1; i <= beatGrid.beatCount; i++) {
digestInteger(digest, beatGrid.getBeatWithinBar(i));
digestInteger(digest, (int)beatGrid.getTimeWithinTrack(i));
}
byte[] result = digest.digest();
// Create a hex string representation of the hash
StringBuilder hex = new StringBuilder(result.length * 2);
for (byte aResult : result) {
hex.append(Integer.toString((aResult & 0xff) + 0x100, 16).substring(1));
}
return hex.toString();
} catch (NullPointerException e) {
logger.info("Returning null track signature because an input element was null.", e);
} catch (NoSuchAlgorithmException e) {
logger.error("Unable to obtain SHA-1 MessageDigest instance for computing track signatures.", e);
} catch (UnsupportedEncodingException e) {
logger.error("Unable to work with UTF-8 string encoding for computing track signatures.", e);
}
return null; // We were unable to compute a signature
} | java | public String computeTrackSignature(final String title, final SearchableItem artist, final int duration,
final WaveformDetail waveformDetail, final BeatGrid beatGrid) {
final String safeTitle = (title == null)? "" : title;
final String artistName = (artist == null)? "[no artist]" : artist.label;
try {
// Compute the SHA-1 hash of our fields
MessageDigest digest = MessageDigest.getInstance("SHA1");
digest.update(safeTitle.getBytes("UTF-8"));
digest.update((byte) 0);
digest.update(artistName.getBytes("UTF-8"));
digest.update((byte) 0);
digestInteger(digest, duration);
digest.update(waveformDetail.getData());
for (int i = 1; i <= beatGrid.beatCount; i++) {
digestInteger(digest, beatGrid.getBeatWithinBar(i));
digestInteger(digest, (int)beatGrid.getTimeWithinTrack(i));
}
byte[] result = digest.digest();
// Create a hex string representation of the hash
StringBuilder hex = new StringBuilder(result.length * 2);
for (byte aResult : result) {
hex.append(Integer.toString((aResult & 0xff) + 0x100, 16).substring(1));
}
return hex.toString();
} catch (NullPointerException e) {
logger.info("Returning null track signature because an input element was null.", e);
} catch (NoSuchAlgorithmException e) {
logger.error("Unable to obtain SHA-1 MessageDigest instance for computing track signatures.", e);
} catch (UnsupportedEncodingException e) {
logger.error("Unable to work with UTF-8 string encoding for computing track signatures.", e);
}
return null; // We were unable to compute a signature
} | [
"public",
"String",
"computeTrackSignature",
"(",
"final",
"String",
"title",
",",
"final",
"SearchableItem",
"artist",
",",
"final",
"int",
"duration",
",",
"final",
"WaveformDetail",
"waveformDetail",
",",
"final",
"BeatGrid",
"beatGrid",
")",
"{",
"final",
"String",
"safeTitle",
"=",
"(",
"title",
"==",
"null",
")",
"?",
"\"\"",
":",
"title",
";",
"final",
"String",
"artistName",
"=",
"(",
"artist",
"==",
"null",
")",
"?",
"\"[no artist]\"",
":",
"artist",
".",
"label",
";",
"try",
"{",
"// Compute the SHA-1 hash of our fields",
"MessageDigest",
"digest",
"=",
"MessageDigest",
".",
"getInstance",
"(",
"\"SHA1\"",
")",
";",
"digest",
".",
"update",
"(",
"safeTitle",
".",
"getBytes",
"(",
"\"UTF-8\"",
")",
")",
";",
"digest",
".",
"update",
"(",
"(",
"byte",
")",
"0",
")",
";",
"digest",
".",
"update",
"(",
"artistName",
".",
"getBytes",
"(",
"\"UTF-8\"",
")",
")",
";",
"digest",
".",
"update",
"(",
"(",
"byte",
")",
"0",
")",
";",
"digestInteger",
"(",
"digest",
",",
"duration",
")",
";",
"digest",
".",
"update",
"(",
"waveformDetail",
".",
"getData",
"(",
")",
")",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<=",
"beatGrid",
".",
"beatCount",
";",
"i",
"++",
")",
"{",
"digestInteger",
"(",
"digest",
",",
"beatGrid",
".",
"getBeatWithinBar",
"(",
"i",
")",
")",
";",
"digestInteger",
"(",
"digest",
",",
"(",
"int",
")",
"beatGrid",
".",
"getTimeWithinTrack",
"(",
"i",
")",
")",
";",
"}",
"byte",
"[",
"]",
"result",
"=",
"digest",
".",
"digest",
"(",
")",
";",
"// Create a hex string representation of the hash",
"StringBuilder",
"hex",
"=",
"new",
"StringBuilder",
"(",
"result",
".",
"length",
"*",
"2",
")",
";",
"for",
"(",
"byte",
"aResult",
":",
"result",
")",
"{",
"hex",
".",
"append",
"(",
"Integer",
".",
"toString",
"(",
"(",
"aResult",
"&",
"0xff",
")",
"+",
"0x100",
",",
"16",
")",
".",
"substring",
"(",
"1",
")",
")",
";",
"}",
"return",
"hex",
".",
"toString",
"(",
")",
";",
"}",
"catch",
"(",
"NullPointerException",
"e",
")",
"{",
"logger",
".",
"info",
"(",
"\"Returning null track signature because an input element was null.\"",
",",
"e",
")",
";",
"}",
"catch",
"(",
"NoSuchAlgorithmException",
"e",
")",
"{",
"logger",
".",
"error",
"(",
"\"Unable to obtain SHA-1 MessageDigest instance for computing track signatures.\"",
",",
"e",
")",
";",
"}",
"catch",
"(",
"UnsupportedEncodingException",
"e",
")",
"{",
"logger",
".",
"error",
"(",
"\"Unable to work with UTF-8 string encoding for computing track signatures.\"",
",",
"e",
")",
";",
"}",
"return",
"null",
";",
"// We were unable to compute a signature",
"}"
] | Calculate the signature by which we can reliably recognize a loaded track.
@param title the track title
@param artist the track artist, or {@code null} if there is no artist
@param duration the duration of the track in seconds
@param waveformDetail the monochrome waveform detail of the track
@param beatGrid the beat grid of the track
@return the SHA-1 hash of all the arguments supplied, or {@code null} if any either {@code waveFormDetail} or {@code beatGrid} were {@code null} | [
"Calculate",
"the",
"signature",
"by",
"which",
"we",
"can",
"reliably",
"recognize",
"a",
"loaded",
"track",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java#L303-L338 |
164,004 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java | SignatureFinder.handleUpdate | private void handleUpdate(final int player) {
final TrackMetadata metadata = MetadataFinder.getInstance().getLatestMetadataFor(player);
final WaveformDetail waveformDetail = WaveformFinder.getInstance().getLatestDetailFor(player);
final BeatGrid beatGrid = BeatGridFinder.getInstance().getLatestBeatGridFor(player);
if (metadata != null && waveformDetail != null && beatGrid != null) {
final String signature = computeTrackSignature(metadata.getTitle(), metadata.getArtist(),
metadata.getDuration(), waveformDetail, beatGrid);
if (signature != null) {
signatures.put(player, signature);
deliverSignatureUpdate(player, signature);
}
}
} | java | private void handleUpdate(final int player) {
final TrackMetadata metadata = MetadataFinder.getInstance().getLatestMetadataFor(player);
final WaveformDetail waveformDetail = WaveformFinder.getInstance().getLatestDetailFor(player);
final BeatGrid beatGrid = BeatGridFinder.getInstance().getLatestBeatGridFor(player);
if (metadata != null && waveformDetail != null && beatGrid != null) {
final String signature = computeTrackSignature(metadata.getTitle(), metadata.getArtist(),
metadata.getDuration(), waveformDetail, beatGrid);
if (signature != null) {
signatures.put(player, signature);
deliverSignatureUpdate(player, signature);
}
}
} | [
"private",
"void",
"handleUpdate",
"(",
"final",
"int",
"player",
")",
"{",
"final",
"TrackMetadata",
"metadata",
"=",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"getLatestMetadataFor",
"(",
"player",
")",
";",
"final",
"WaveformDetail",
"waveformDetail",
"=",
"WaveformFinder",
".",
"getInstance",
"(",
")",
".",
"getLatestDetailFor",
"(",
"player",
")",
";",
"final",
"BeatGrid",
"beatGrid",
"=",
"BeatGridFinder",
".",
"getInstance",
"(",
")",
".",
"getLatestBeatGridFor",
"(",
"player",
")",
";",
"if",
"(",
"metadata",
"!=",
"null",
"&&",
"waveformDetail",
"!=",
"null",
"&&",
"beatGrid",
"!=",
"null",
")",
"{",
"final",
"String",
"signature",
"=",
"computeTrackSignature",
"(",
"metadata",
".",
"getTitle",
"(",
")",
",",
"metadata",
".",
"getArtist",
"(",
")",
",",
"metadata",
".",
"getDuration",
"(",
")",
",",
"waveformDetail",
",",
"beatGrid",
")",
";",
"if",
"(",
"signature",
"!=",
"null",
")",
"{",
"signatures",
".",
"put",
"(",
"player",
",",
"signature",
")",
";",
"deliverSignatureUpdate",
"(",
"player",
",",
"signature",
")",
";",
"}",
"}",
"}"
] | We have reason to believe we might have enough information to calculate a signature for the track loaded on a
player. Verify that, and if so, perform the computation and record and report the new signature. | [
"We",
"have",
"reason",
"to",
"believe",
"we",
"might",
"have",
"enough",
"information",
"to",
"calculate",
"a",
"signature",
"for",
"the",
"track",
"loaded",
"on",
"a",
"player",
".",
"Verify",
"that",
"and",
"if",
"so",
"perform",
"the",
"computation",
"and",
"record",
"and",
"report",
"the",
"new",
"signature",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java#L344-L356 |
164,005 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java | SignatureFinder.stop | public synchronized void stop () {
if (isRunning()) {
MetadataFinder.getInstance().removeTrackMetadataListener(metadataListener);
WaveformFinder.getInstance().removeWaveformListener(waveformListener);
BeatGridFinder.getInstance().removeBeatGridListener(beatGridListener);
running.set(false);
pendingUpdates.clear();
queueHandler.interrupt();
queueHandler = null;
// Report the loss of our signatures, on the proper thread, outside our lock
final Set<Integer> dyingSignatures = new HashSet<Integer>(signatures.keySet());
signatures.clear();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (Integer player : dyingSignatures) {
deliverSignatureUpdate(player, null);
}
}
});
}
deliverLifecycleAnnouncement(logger, false);
} | java | public synchronized void stop () {
if (isRunning()) {
MetadataFinder.getInstance().removeTrackMetadataListener(metadataListener);
WaveformFinder.getInstance().removeWaveformListener(waveformListener);
BeatGridFinder.getInstance().removeBeatGridListener(beatGridListener);
running.set(false);
pendingUpdates.clear();
queueHandler.interrupt();
queueHandler = null;
// Report the loss of our signatures, on the proper thread, outside our lock
final Set<Integer> dyingSignatures = new HashSet<Integer>(signatures.keySet());
signatures.clear();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (Integer player : dyingSignatures) {
deliverSignatureUpdate(player, null);
}
}
});
}
deliverLifecycleAnnouncement(logger, false);
} | [
"public",
"synchronized",
"void",
"stop",
"(",
")",
"{",
"if",
"(",
"isRunning",
"(",
")",
")",
"{",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"removeTrackMetadataListener",
"(",
"metadataListener",
")",
";",
"WaveformFinder",
".",
"getInstance",
"(",
")",
".",
"removeWaveformListener",
"(",
"waveformListener",
")",
";",
"BeatGridFinder",
".",
"getInstance",
"(",
")",
".",
"removeBeatGridListener",
"(",
"beatGridListener",
")",
";",
"running",
".",
"set",
"(",
"false",
")",
";",
"pendingUpdates",
".",
"clear",
"(",
")",
";",
"queueHandler",
".",
"interrupt",
"(",
")",
";",
"queueHandler",
"=",
"null",
";",
"// Report the loss of our signatures, on the proper thread, outside our lock",
"final",
"Set",
"<",
"Integer",
">",
"dyingSignatures",
"=",
"new",
"HashSet",
"<",
"Integer",
">",
"(",
"signatures",
".",
"keySet",
"(",
")",
")",
";",
"signatures",
".",
"clear",
"(",
")",
";",
"SwingUtilities",
".",
"invokeLater",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"for",
"(",
"Integer",
"player",
":",
"dyingSignatures",
")",
"{",
"deliverSignatureUpdate",
"(",
"player",
",",
"null",
")",
";",
"}",
"}",
"}",
")",
";",
"}",
"deliverLifecycleAnnouncement",
"(",
"logger",
",",
"false",
")",
";",
"}"
] | Stop finding signatures for all active players. | [
"Stop",
"finding",
"signatures",
"for",
"all",
"active",
"players",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java#L406-L429 |
164,006 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java | DeviceFinder.expireDevices | private void expireDevices() {
long now = System.currentTimeMillis();
// Make a copy so we don't have to worry about concurrent modification.
Map<InetAddress, DeviceAnnouncement> copy = new HashMap<InetAddress, DeviceAnnouncement>(devices);
for (Map.Entry<InetAddress, DeviceAnnouncement> entry : copy.entrySet()) {
if (now - entry.getValue().getTimestamp() > MAXIMUM_AGE) {
devices.remove(entry.getKey());
deliverLostAnnouncement(entry.getValue());
}
}
if (devices.isEmpty()) {
firstDeviceTime.set(0); // We have lost contact with the Pro DJ Link network, so start over with next device.
}
} | java | private void expireDevices() {
long now = System.currentTimeMillis();
// Make a copy so we don't have to worry about concurrent modification.
Map<InetAddress, DeviceAnnouncement> copy = new HashMap<InetAddress, DeviceAnnouncement>(devices);
for (Map.Entry<InetAddress, DeviceAnnouncement> entry : copy.entrySet()) {
if (now - entry.getValue().getTimestamp() > MAXIMUM_AGE) {
devices.remove(entry.getKey());
deliverLostAnnouncement(entry.getValue());
}
}
if (devices.isEmpty()) {
firstDeviceTime.set(0); // We have lost contact with the Pro DJ Link network, so start over with next device.
}
} | [
"private",
"void",
"expireDevices",
"(",
")",
"{",
"long",
"now",
"=",
"System",
".",
"currentTimeMillis",
"(",
")",
";",
"// Make a copy so we don't have to worry about concurrent modification.",
"Map",
"<",
"InetAddress",
",",
"DeviceAnnouncement",
">",
"copy",
"=",
"new",
"HashMap",
"<",
"InetAddress",
",",
"DeviceAnnouncement",
">",
"(",
"devices",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"InetAddress",
",",
"DeviceAnnouncement",
">",
"entry",
":",
"copy",
".",
"entrySet",
"(",
")",
")",
"{",
"if",
"(",
"now",
"-",
"entry",
".",
"getValue",
"(",
")",
".",
"getTimestamp",
"(",
")",
">",
"MAXIMUM_AGE",
")",
"{",
"devices",
".",
"remove",
"(",
"entry",
".",
"getKey",
"(",
")",
")",
";",
"deliverLostAnnouncement",
"(",
"entry",
".",
"getValue",
"(",
")",
")",
";",
"}",
"}",
"if",
"(",
"devices",
".",
"isEmpty",
"(",
")",
")",
"{",
"firstDeviceTime",
".",
"set",
"(",
"0",
")",
";",
"// We have lost contact with the Pro DJ Link network, so start over with next device.",
"}",
"}"
] | Remove any device announcements that are so old that the device seems to have gone away. | [
"Remove",
"any",
"device",
"announcements",
"that",
"are",
"so",
"old",
"that",
"the",
"device",
"seems",
"to",
"have",
"gone",
"away",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java#L98-L111 |
164,007 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java | DeviceFinder.updateDevices | private void updateDevices(DeviceAnnouncement announcement) {
firstDeviceTime.compareAndSet(0, System.currentTimeMillis());
devices.put(announcement.getAddress(), announcement);
} | java | private void updateDevices(DeviceAnnouncement announcement) {
firstDeviceTime.compareAndSet(0, System.currentTimeMillis());
devices.put(announcement.getAddress(), announcement);
} | [
"private",
"void",
"updateDevices",
"(",
"DeviceAnnouncement",
"announcement",
")",
"{",
"firstDeviceTime",
".",
"compareAndSet",
"(",
"0",
",",
"System",
".",
"currentTimeMillis",
"(",
")",
")",
";",
"devices",
".",
"put",
"(",
"announcement",
".",
"getAddress",
"(",
")",
",",
"announcement",
")",
";",
"}"
] | Record a device announcement in the devices map, so we know whe saw it.
@param announcement the announcement to be recorded | [
"Record",
"a",
"device",
"announcement",
"in",
"the",
"devices",
"map",
"so",
"we",
"know",
"whe",
"saw",
"it",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java#L118-L121 |
164,008 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java | DeviceFinder.start | public synchronized void start() throws SocketException {
if (!isRunning()) {
socket.set(new DatagramSocket(ANNOUNCEMENT_PORT));
startTime.set(System.currentTimeMillis());
deliverLifecycleAnnouncement(logger, true);
final byte[] buffer = new byte[512];
final DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
Thread receiver = new Thread(null, new Runnable() {
@Override
public void run() {
boolean received;
while (isRunning()) {
try {
if (getCurrentDevices().isEmpty()) {
socket.get().setSoTimeout(60000); // We have no devices to check for timeout; block for a whole minute to check for shutdown
} else {
socket.get().setSoTimeout(1000); // Check every second to see if a device has vanished
}
socket.get().receive(packet);
received = !ignoredAddresses.contains(packet.getAddress());
} catch (SocketTimeoutException ste) {
received = false;
} catch (IOException e) {
// Don't log a warning if the exception was due to the socket closing at shutdown.
if (isRunning()) {
// We did not expect to have a problem; log a warning and shut down.
logger.warn("Problem reading from DeviceAnnouncement socket, stopping", e);
stop();
}
received = false;
}
try {
if (received && (packet.getLength() == 54)) {
final Util.PacketType kind = Util.validateHeader(packet, ANNOUNCEMENT_PORT);
if (kind == Util.PacketType.DEVICE_KEEP_ALIVE) {
// Looks like the kind of packet we need
if (packet.getLength() < 54) {
logger.warn("Ignoring too-short " + kind.name + " packet; expected 54 bytes, but only got " +
packet.getLength() + ".");
} else {
if (packet.getLength() > 54) {
logger.warn("Processing too-long " + kind.name + " packet; expected 54 bytes, but got " +
packet.getLength() + ".");
}
DeviceAnnouncement announcement = new DeviceAnnouncement(packet);
final boolean foundNewDevice = isDeviceNew(announcement);
updateDevices(announcement);
if (foundNewDevice) {
deliverFoundAnnouncement(announcement);
}
}
}
}
expireDevices();
} catch (Throwable t) {
logger.warn("Problem processing DeviceAnnouncement packet", t);
}
}
}
}, "beat-link DeviceFinder receiver");
receiver.setDaemon(true);
receiver.start();
}
} | java | public synchronized void start() throws SocketException {
if (!isRunning()) {
socket.set(new DatagramSocket(ANNOUNCEMENT_PORT));
startTime.set(System.currentTimeMillis());
deliverLifecycleAnnouncement(logger, true);
final byte[] buffer = new byte[512];
final DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
Thread receiver = new Thread(null, new Runnable() {
@Override
public void run() {
boolean received;
while (isRunning()) {
try {
if (getCurrentDevices().isEmpty()) {
socket.get().setSoTimeout(60000); // We have no devices to check for timeout; block for a whole minute to check for shutdown
} else {
socket.get().setSoTimeout(1000); // Check every second to see if a device has vanished
}
socket.get().receive(packet);
received = !ignoredAddresses.contains(packet.getAddress());
} catch (SocketTimeoutException ste) {
received = false;
} catch (IOException e) {
// Don't log a warning if the exception was due to the socket closing at shutdown.
if (isRunning()) {
// We did not expect to have a problem; log a warning and shut down.
logger.warn("Problem reading from DeviceAnnouncement socket, stopping", e);
stop();
}
received = false;
}
try {
if (received && (packet.getLength() == 54)) {
final Util.PacketType kind = Util.validateHeader(packet, ANNOUNCEMENT_PORT);
if (kind == Util.PacketType.DEVICE_KEEP_ALIVE) {
// Looks like the kind of packet we need
if (packet.getLength() < 54) {
logger.warn("Ignoring too-short " + kind.name + " packet; expected 54 bytes, but only got " +
packet.getLength() + ".");
} else {
if (packet.getLength() > 54) {
logger.warn("Processing too-long " + kind.name + " packet; expected 54 bytes, but got " +
packet.getLength() + ".");
}
DeviceAnnouncement announcement = new DeviceAnnouncement(packet);
final boolean foundNewDevice = isDeviceNew(announcement);
updateDevices(announcement);
if (foundNewDevice) {
deliverFoundAnnouncement(announcement);
}
}
}
}
expireDevices();
} catch (Throwable t) {
logger.warn("Problem processing DeviceAnnouncement packet", t);
}
}
}
}, "beat-link DeviceFinder receiver");
receiver.setDaemon(true);
receiver.start();
}
} | [
"public",
"synchronized",
"void",
"start",
"(",
")",
"throws",
"SocketException",
"{",
"if",
"(",
"!",
"isRunning",
"(",
")",
")",
"{",
"socket",
".",
"set",
"(",
"new",
"DatagramSocket",
"(",
"ANNOUNCEMENT_PORT",
")",
")",
";",
"startTime",
".",
"set",
"(",
"System",
".",
"currentTimeMillis",
"(",
")",
")",
";",
"deliverLifecycleAnnouncement",
"(",
"logger",
",",
"true",
")",
";",
"final",
"byte",
"[",
"]",
"buffer",
"=",
"new",
"byte",
"[",
"512",
"]",
";",
"final",
"DatagramPacket",
"packet",
"=",
"new",
"DatagramPacket",
"(",
"buffer",
",",
"buffer",
".",
"length",
")",
";",
"Thread",
"receiver",
"=",
"new",
"Thread",
"(",
"null",
",",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"boolean",
"received",
";",
"while",
"(",
"isRunning",
"(",
")",
")",
"{",
"try",
"{",
"if",
"(",
"getCurrentDevices",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"socket",
".",
"get",
"(",
")",
".",
"setSoTimeout",
"(",
"60000",
")",
";",
"// We have no devices to check for timeout; block for a whole minute to check for shutdown",
"}",
"else",
"{",
"socket",
".",
"get",
"(",
")",
".",
"setSoTimeout",
"(",
"1000",
")",
";",
"// Check every second to see if a device has vanished",
"}",
"socket",
".",
"get",
"(",
")",
".",
"receive",
"(",
"packet",
")",
";",
"received",
"=",
"!",
"ignoredAddresses",
".",
"contains",
"(",
"packet",
".",
"getAddress",
"(",
")",
")",
";",
"}",
"catch",
"(",
"SocketTimeoutException",
"ste",
")",
"{",
"received",
"=",
"false",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"// Don't log a warning if the exception was due to the socket closing at shutdown.",
"if",
"(",
"isRunning",
"(",
")",
")",
"{",
"// We did not expect to have a problem; log a warning and shut down.",
"logger",
".",
"warn",
"(",
"\"Problem reading from DeviceAnnouncement socket, stopping\"",
",",
"e",
")",
";",
"stop",
"(",
")",
";",
"}",
"received",
"=",
"false",
";",
"}",
"try",
"{",
"if",
"(",
"received",
"&&",
"(",
"packet",
".",
"getLength",
"(",
")",
"==",
"54",
")",
")",
"{",
"final",
"Util",
".",
"PacketType",
"kind",
"=",
"Util",
".",
"validateHeader",
"(",
"packet",
",",
"ANNOUNCEMENT_PORT",
")",
";",
"if",
"(",
"kind",
"==",
"Util",
".",
"PacketType",
".",
"DEVICE_KEEP_ALIVE",
")",
"{",
"// Looks like the kind of packet we need",
"if",
"(",
"packet",
".",
"getLength",
"(",
")",
"<",
"54",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Ignoring too-short \"",
"+",
"kind",
".",
"name",
"+",
"\" packet; expected 54 bytes, but only got \"",
"+",
"packet",
".",
"getLength",
"(",
")",
"+",
"\".\"",
")",
";",
"}",
"else",
"{",
"if",
"(",
"packet",
".",
"getLength",
"(",
")",
">",
"54",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Processing too-long \"",
"+",
"kind",
".",
"name",
"+",
"\" packet; expected 54 bytes, but got \"",
"+",
"packet",
".",
"getLength",
"(",
")",
"+",
"\".\"",
")",
";",
"}",
"DeviceAnnouncement",
"announcement",
"=",
"new",
"DeviceAnnouncement",
"(",
"packet",
")",
";",
"final",
"boolean",
"foundNewDevice",
"=",
"isDeviceNew",
"(",
"announcement",
")",
";",
"updateDevices",
"(",
"announcement",
")",
";",
"if",
"(",
"foundNewDevice",
")",
"{",
"deliverFoundAnnouncement",
"(",
"announcement",
")",
";",
"}",
"}",
"}",
"}",
"expireDevices",
"(",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem processing DeviceAnnouncement packet\"",
",",
"t",
")",
";",
"}",
"}",
"}",
"}",
",",
"\"beat-link DeviceFinder receiver\"",
")",
";",
"receiver",
".",
"setDaemon",
"(",
"true",
")",
";",
"receiver",
".",
"start",
"(",
")",
";",
"}",
"}"
] | Start listening for device announcements and keeping track of the DJ Link devices visible on the network.
If already listening, has no effect.
@throws SocketException if the socket to listen on port 50000 cannot be created | [
"Start",
"listening",
"for",
"device",
"announcements",
"and",
"keeping",
"track",
"of",
"the",
"DJ",
"Link",
"devices",
"visible",
"on",
"the",
"network",
".",
"If",
"already",
"listening",
"has",
"no",
"effect",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java#L180-L245 |
164,009 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java | DeviceFinder.stop | @SuppressWarnings("WeakerAccess")
public synchronized void stop() {
if (isRunning()) {
final Set<DeviceAnnouncement> lastDevices = getCurrentDevices();
socket.get().close();
socket.set(null);
devices.clear();
firstDeviceTime.set(0);
// Report the loss of all our devices, on the proper thread, outside our lock
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (DeviceAnnouncement announcement : lastDevices) {
deliverLostAnnouncement(announcement);
}
}
});
deliverLifecycleAnnouncement(logger, false);
}
} | java | @SuppressWarnings("WeakerAccess")
public synchronized void stop() {
if (isRunning()) {
final Set<DeviceAnnouncement> lastDevices = getCurrentDevices();
socket.get().close();
socket.set(null);
devices.clear();
firstDeviceTime.set(0);
// Report the loss of all our devices, on the proper thread, outside our lock
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (DeviceAnnouncement announcement : lastDevices) {
deliverLostAnnouncement(announcement);
}
}
});
deliverLifecycleAnnouncement(logger, false);
}
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"synchronized",
"void",
"stop",
"(",
")",
"{",
"if",
"(",
"isRunning",
"(",
")",
")",
"{",
"final",
"Set",
"<",
"DeviceAnnouncement",
">",
"lastDevices",
"=",
"getCurrentDevices",
"(",
")",
";",
"socket",
".",
"get",
"(",
")",
".",
"close",
"(",
")",
";",
"socket",
".",
"set",
"(",
"null",
")",
";",
"devices",
".",
"clear",
"(",
")",
";",
"firstDeviceTime",
".",
"set",
"(",
"0",
")",
";",
"// Report the loss of all our devices, on the proper thread, outside our lock",
"SwingUtilities",
".",
"invokeLater",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"for",
"(",
"DeviceAnnouncement",
"announcement",
":",
"lastDevices",
")",
"{",
"deliverLostAnnouncement",
"(",
"announcement",
")",
";",
"}",
"}",
"}",
")",
";",
"deliverLifecycleAnnouncement",
"(",
"logger",
",",
"false",
")",
";",
"}",
"}"
] | Stop listening for device announcements. Also discard any announcements which had been received, and
notify any registered listeners that those devices have been lost. | [
"Stop",
"listening",
"for",
"device",
"announcements",
".",
"Also",
"discard",
"any",
"announcements",
"which",
"had",
"been",
"received",
"and",
"notify",
"any",
"registered",
"listeners",
"that",
"those",
"devices",
"have",
"been",
"lost",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java#L251-L270 |
164,010 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java | DeviceFinder.deliverFoundAnnouncement | private void deliverFoundAnnouncement(final DeviceAnnouncement announcement) {
for (final DeviceAnnouncementListener listener : getDeviceAnnouncementListeners()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
listener.deviceFound(announcement);
} catch (Throwable t) {
logger.warn("Problem delivering device found announcement to listener", t);
}
}
});
}
} | java | private void deliverFoundAnnouncement(final DeviceAnnouncement announcement) {
for (final DeviceAnnouncementListener listener : getDeviceAnnouncementListeners()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
listener.deviceFound(announcement);
} catch (Throwable t) {
logger.warn("Problem delivering device found announcement to listener", t);
}
}
});
}
} | [
"private",
"void",
"deliverFoundAnnouncement",
"(",
"final",
"DeviceAnnouncement",
"announcement",
")",
"{",
"for",
"(",
"final",
"DeviceAnnouncementListener",
"listener",
":",
"getDeviceAnnouncementListeners",
"(",
")",
")",
"{",
"SwingUtilities",
".",
"invokeLater",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"try",
"{",
"listener",
".",
"deviceFound",
"(",
"announcement",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem delivering device found announcement to listener\"",
",",
"t",
")",
";",
"}",
"}",
"}",
")",
";",
"}",
"}"
] | Send a device found announcement to all registered listeners.
@param announcement the message announcing the new device | [
"Send",
"a",
"device",
"found",
"announcement",
"to",
"all",
"registered",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java#L362-L375 |
164,011 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java | DeviceFinder.deliverLostAnnouncement | private void deliverLostAnnouncement(final DeviceAnnouncement announcement) {
for (final DeviceAnnouncementListener listener : getDeviceAnnouncementListeners()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
listener.deviceLost(announcement);
} catch (Throwable t) {
logger.warn("Problem delivering device lost announcement to listener", t);
}
}
});
}
} | java | private void deliverLostAnnouncement(final DeviceAnnouncement announcement) {
for (final DeviceAnnouncementListener listener : getDeviceAnnouncementListeners()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
listener.deviceLost(announcement);
} catch (Throwable t) {
logger.warn("Problem delivering device lost announcement to listener", t);
}
}
});
}
} | [
"private",
"void",
"deliverLostAnnouncement",
"(",
"final",
"DeviceAnnouncement",
"announcement",
")",
"{",
"for",
"(",
"final",
"DeviceAnnouncementListener",
"listener",
":",
"getDeviceAnnouncementListeners",
"(",
")",
")",
"{",
"SwingUtilities",
".",
"invokeLater",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"try",
"{",
"listener",
".",
"deviceLost",
"(",
"announcement",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem delivering device lost announcement to listener\"",
",",
"t",
")",
";",
"}",
"}",
"}",
")",
";",
"}",
"}"
] | Send a device lost announcement to all registered listeners.
@param announcement the last message received from the vanished device | [
"Send",
"a",
"device",
"lost",
"announcement",
"to",
"all",
"registered",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java#L382-L395 |
164,012 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java | Client.performSetupExchange | private void performSetupExchange() throws IOException {
Message setupRequest = new Message(0xfffffffeL, Message.KnownType.SETUP_REQ, new NumberField(posingAsPlayer, 4));
sendMessage(setupRequest);
Message response = Message.read(is);
if (response.knownType != Message.KnownType.MENU_AVAILABLE) {
throw new IOException("Did not receive message type 0x4000 in response to setup message, got: " + response);
}
if (response.arguments.size() != 2) {
throw new IOException("Did not receive two arguments in response to setup message, got: " + response);
}
final Field player = response.arguments.get(1);
if (!(player instanceof NumberField)) {
throw new IOException("Second argument in response to setup message was not a number: " + response);
}
if (((NumberField)player).getValue() != targetPlayer) {
throw new IOException("Expected to connect to player " + targetPlayer +
", but welcome response identified itself as player " + ((NumberField)player).getValue());
}
} | java | private void performSetupExchange() throws IOException {
Message setupRequest = new Message(0xfffffffeL, Message.KnownType.SETUP_REQ, new NumberField(posingAsPlayer, 4));
sendMessage(setupRequest);
Message response = Message.read(is);
if (response.knownType != Message.KnownType.MENU_AVAILABLE) {
throw new IOException("Did not receive message type 0x4000 in response to setup message, got: " + response);
}
if (response.arguments.size() != 2) {
throw new IOException("Did not receive two arguments in response to setup message, got: " + response);
}
final Field player = response.arguments.get(1);
if (!(player instanceof NumberField)) {
throw new IOException("Second argument in response to setup message was not a number: " + response);
}
if (((NumberField)player).getValue() != targetPlayer) {
throw new IOException("Expected to connect to player " + targetPlayer +
", but welcome response identified itself as player " + ((NumberField)player).getValue());
}
} | [
"private",
"void",
"performSetupExchange",
"(",
")",
"throws",
"IOException",
"{",
"Message",
"setupRequest",
"=",
"new",
"Message",
"(",
"0xfffffffe",
"L",
",",
"Message",
".",
"KnownType",
".",
"SETUP_REQ",
",",
"new",
"NumberField",
"(",
"posingAsPlayer",
",",
"4",
")",
")",
";",
"sendMessage",
"(",
"setupRequest",
")",
";",
"Message",
"response",
"=",
"Message",
".",
"read",
"(",
"is",
")",
";",
"if",
"(",
"response",
".",
"knownType",
"!=",
"Message",
".",
"KnownType",
".",
"MENU_AVAILABLE",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Did not receive message type 0x4000 in response to setup message, got: \"",
"+",
"response",
")",
";",
"}",
"if",
"(",
"response",
".",
"arguments",
".",
"size",
"(",
")",
"!=",
"2",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Did not receive two arguments in response to setup message, got: \"",
"+",
"response",
")",
";",
"}",
"final",
"Field",
"player",
"=",
"response",
".",
"arguments",
".",
"get",
"(",
"1",
")",
";",
"if",
"(",
"!",
"(",
"player",
"instanceof",
"NumberField",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Second argument in response to setup message was not a number: \"",
"+",
"response",
")",
";",
"}",
"if",
"(",
"(",
"(",
"NumberField",
")",
"player",
")",
".",
"getValue",
"(",
")",
"!=",
"targetPlayer",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Expected to connect to player \"",
"+",
"targetPlayer",
"+",
"\", but welcome response identified itself as player \"",
"+",
"(",
"(",
"NumberField",
")",
"player",
")",
".",
"getValue",
"(",
")",
")",
";",
"}",
"}"
] | Exchanges the initial fully-formed messages which establishes the transaction context for queries to
the dbserver.
@throws IOException if there is a problem during the exchange | [
"Exchanges",
"the",
"initial",
"fully",
"-",
"formed",
"messages",
"which",
"establishes",
"the",
"transaction",
"context",
"for",
"queries",
"to",
"the",
"dbserver",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java#L117-L135 |
164,013 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java | Client.performTeardownExchange | private void performTeardownExchange() throws IOException {
Message teardownRequest = new Message(0xfffffffeL, Message.KnownType.TEARDOWN_REQ);
sendMessage(teardownRequest);
// At this point, the server closes the connection from its end, so we can’t read any more.
} | java | private void performTeardownExchange() throws IOException {
Message teardownRequest = new Message(0xfffffffeL, Message.KnownType.TEARDOWN_REQ);
sendMessage(teardownRequest);
// At this point, the server closes the connection from its end, so we can’t read any more.
} | [
"private",
"void",
"performTeardownExchange",
"(",
")",
"throws",
"IOException",
"{",
"Message",
"teardownRequest",
"=",
"new",
"Message",
"(",
"0xfffffffe",
"L",
",",
"Message",
".",
"KnownType",
".",
"TEARDOWN_REQ",
")",
";",
"sendMessage",
"(",
"teardownRequest",
")",
";",
"// At this point, the server closes the connection from its end, so we can’t read any more.",
"}"
] | Exchanges the final messages which politely report our intention to disconnect from the dbserver. | [
"Exchanges",
"the",
"final",
"messages",
"which",
"politely",
"report",
"our",
"intention",
"to",
"disconnect",
"from",
"the",
"dbserver",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java#L140-L144 |
164,014 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java | Client.close | void close() {
try {
performTeardownExchange();
} catch (IOException e) {
logger.warn("Problem reporting our intention to close the dbserver connection", e);
}
try {
channel.close();
} catch (IOException e) {
logger.warn("Problem closing dbserver client output channel", e);
}
try {
os.close();
} catch (IOException e) {
logger.warn("Problem closing dbserver client output stream", e);
}
try {
is.close();
} catch (IOException e) {
logger.warn("Problem closing dbserver client input stream", e);
}
try {
socket.close();
} catch (IOException e) {
logger.warn("Problem closing dbserver client socket", e);
}
} | java | void close() {
try {
performTeardownExchange();
} catch (IOException e) {
logger.warn("Problem reporting our intention to close the dbserver connection", e);
}
try {
channel.close();
} catch (IOException e) {
logger.warn("Problem closing dbserver client output channel", e);
}
try {
os.close();
} catch (IOException e) {
logger.warn("Problem closing dbserver client output stream", e);
}
try {
is.close();
} catch (IOException e) {
logger.warn("Problem closing dbserver client input stream", e);
}
try {
socket.close();
} catch (IOException e) {
logger.warn("Problem closing dbserver client socket", e);
}
} | [
"void",
"close",
"(",
")",
"{",
"try",
"{",
"performTeardownExchange",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem reporting our intention to close the dbserver connection\"",
",",
"e",
")",
";",
"}",
"try",
"{",
"channel",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem closing dbserver client output channel\"",
",",
"e",
")",
";",
"}",
"try",
"{",
"os",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem closing dbserver client output stream\"",
",",
"e",
")",
";",
"}",
"try",
"{",
"is",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem closing dbserver client input stream\"",
",",
"e",
")",
";",
"}",
"try",
"{",
"socket",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem closing dbserver client socket\"",
",",
"e",
")",
";",
"}",
"}"
] | Closes the connection to the dbserver. This instance can no longer be used after this action. | [
"Closes",
"the",
"connection",
"to",
"the",
"dbserver",
".",
"This",
"instance",
"can",
"no",
"longer",
"be",
"used",
"after",
"this",
"action",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java#L160-L186 |
164,015 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java | Client.sendField | @SuppressWarnings("SameParameterValue")
private void sendField(Field field) throws IOException {
if (isConnected()) {
try {
field.write(channel);
} catch (IOException e) {
logger.warn("Problem trying to write field to dbserver, closing connection", e);
close();
throw e;
}
return;
}
throw new IOException("sendField() called after dbserver connection was closed");
} | java | @SuppressWarnings("SameParameterValue")
private void sendField(Field field) throws IOException {
if (isConnected()) {
try {
field.write(channel);
} catch (IOException e) {
logger.warn("Problem trying to write field to dbserver, closing connection", e);
close();
throw e;
}
return;
}
throw new IOException("sendField() called after dbserver connection was closed");
} | [
"@",
"SuppressWarnings",
"(",
"\"SameParameterValue\"",
")",
"private",
"void",
"sendField",
"(",
"Field",
"field",
")",
"throws",
"IOException",
"{",
"if",
"(",
"isConnected",
"(",
")",
")",
"{",
"try",
"{",
"field",
".",
"write",
"(",
"channel",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem trying to write field to dbserver, closing connection\"",
",",
"e",
")",
";",
"close",
"(",
")",
";",
"throw",
"e",
";",
"}",
"return",
";",
"}",
"throw",
"new",
"IOException",
"(",
"\"sendField() called after dbserver connection was closed\"",
")",
";",
"}"
] | Attempt to send the specified field to the dbserver.
This low-level function is available only to the package itself for use in setting up the connection. It was
previously also used for sending parts of larger-scale messages, but because that sometimes led to them being
fragmented into multiple network packets, and Windows rekordbox cannot handle that, full message sending no
longer uses this method.
@param field the field to be sent
@throws IOException if the field cannot be sent | [
"Attempt",
"to",
"send",
"the",
"specified",
"field",
"to",
"the",
"dbserver",
".",
"This",
"low",
"-",
"level",
"function",
"is",
"available",
"only",
"to",
"the",
"package",
"itself",
"for",
"use",
"in",
"setting",
"up",
"the",
"connection",
".",
"It",
"was",
"previously",
"also",
"used",
"for",
"sending",
"parts",
"of",
"larger",
"-",
"scale",
"messages",
"but",
"because",
"that",
"sometimes",
"led",
"to",
"them",
"being",
"fragmented",
"into",
"multiple",
"network",
"packets",
"and",
"Windows",
"rekordbox",
"cannot",
"handle",
"that",
"full",
"message",
"sending",
"no",
"longer",
"uses",
"this",
"method",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java#L199-L212 |
164,016 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java | Client.sendMessage | private void sendMessage(Message message) throws IOException {
logger.debug("Sending> {}", message);
int totalSize = 0;
for (Field field : message.fields) {
totalSize += field.getBytes().remaining();
}
ByteBuffer combined = ByteBuffer.allocate(totalSize);
for (Field field : message.fields) {
logger.debug("..sending> {}", field);
combined.put(field.getBytes());
}
combined.flip();
Util.writeFully(combined, channel);
} | java | private void sendMessage(Message message) throws IOException {
logger.debug("Sending> {}", message);
int totalSize = 0;
for (Field field : message.fields) {
totalSize += field.getBytes().remaining();
}
ByteBuffer combined = ByteBuffer.allocate(totalSize);
for (Field field : message.fields) {
logger.debug("..sending> {}", field);
combined.put(field.getBytes());
}
combined.flip();
Util.writeFully(combined, channel);
} | [
"private",
"void",
"sendMessage",
"(",
"Message",
"message",
")",
"throws",
"IOException",
"{",
"logger",
".",
"debug",
"(",
"\"Sending> {}\"",
",",
"message",
")",
";",
"int",
"totalSize",
"=",
"0",
";",
"for",
"(",
"Field",
"field",
":",
"message",
".",
"fields",
")",
"{",
"totalSize",
"+=",
"field",
".",
"getBytes",
"(",
")",
".",
"remaining",
"(",
")",
";",
"}",
"ByteBuffer",
"combined",
"=",
"ByteBuffer",
".",
"allocate",
"(",
"totalSize",
")",
";",
"for",
"(",
"Field",
"field",
":",
"message",
".",
"fields",
")",
"{",
"logger",
".",
"debug",
"(",
"\"..sending> {}\"",
",",
"field",
")",
";",
"combined",
".",
"put",
"(",
"field",
".",
"getBytes",
"(",
")",
")",
";",
"}",
"combined",
".",
"flip",
"(",
")",
";",
"Util",
".",
"writeFully",
"(",
"combined",
",",
"channel",
")",
";",
"}"
] | Sends a message to the dbserver, first assembling it into a single byte buffer so that it can be sent as
a single packet.
@param message the message to be sent
@throws IOException if there is a problem sending it | [
"Sends",
"a",
"message",
"to",
"the",
"dbserver",
"first",
"assembling",
"it",
"into",
"a",
"single",
"byte",
"buffer",
"so",
"that",
"it",
"can",
"be",
"sent",
"as",
"a",
"single",
"packet",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java#L231-L244 |
164,017 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java | Client.simpleRequest | public synchronized Message simpleRequest(Message.KnownType requestType, Message.KnownType responseType,
Field... arguments)
throws IOException {
final NumberField transaction = assignTransactionNumber();
final Message request = new Message(transaction, new NumberField(requestType.protocolValue, 2), arguments);
sendMessage(request);
final Message response = Message.read(is);
if (response.transaction.getValue() != transaction.getValue()) {
throw new IOException("Received response with wrong transaction ID. Expected: " + transaction.getValue() +
", got: " + response);
}
if (responseType != null && response.knownType != responseType) {
throw new IOException("Received response with wrong type. Expected: " + responseType +
", got: " + response);
}
return response;
} | java | public synchronized Message simpleRequest(Message.KnownType requestType, Message.KnownType responseType,
Field... arguments)
throws IOException {
final NumberField transaction = assignTransactionNumber();
final Message request = new Message(transaction, new NumberField(requestType.protocolValue, 2), arguments);
sendMessage(request);
final Message response = Message.read(is);
if (response.transaction.getValue() != transaction.getValue()) {
throw new IOException("Received response with wrong transaction ID. Expected: " + transaction.getValue() +
", got: " + response);
}
if (responseType != null && response.knownType != responseType) {
throw new IOException("Received response with wrong type. Expected: " + responseType +
", got: " + response);
}
return response;
} | [
"public",
"synchronized",
"Message",
"simpleRequest",
"(",
"Message",
".",
"KnownType",
"requestType",
",",
"Message",
".",
"KnownType",
"responseType",
",",
"Field",
"...",
"arguments",
")",
"throws",
"IOException",
"{",
"final",
"NumberField",
"transaction",
"=",
"assignTransactionNumber",
"(",
")",
";",
"final",
"Message",
"request",
"=",
"new",
"Message",
"(",
"transaction",
",",
"new",
"NumberField",
"(",
"requestType",
".",
"protocolValue",
",",
"2",
")",
",",
"arguments",
")",
";",
"sendMessage",
"(",
"request",
")",
";",
"final",
"Message",
"response",
"=",
"Message",
".",
"read",
"(",
"is",
")",
";",
"if",
"(",
"response",
".",
"transaction",
".",
"getValue",
"(",
")",
"!=",
"transaction",
".",
"getValue",
"(",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Received response with wrong transaction ID. Expected: \"",
"+",
"transaction",
".",
"getValue",
"(",
")",
"+",
"\", got: \"",
"+",
"response",
")",
";",
"}",
"if",
"(",
"responseType",
"!=",
"null",
"&&",
"response",
".",
"knownType",
"!=",
"responseType",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Received response with wrong type. Expected: \"",
"+",
"responseType",
"+",
"\", got: \"",
"+",
"response",
")",
";",
"}",
"return",
"response",
";",
"}"
] | Send a request that expects a single message as its response, then read and return that response.
@param requestType identifies what kind of request to send
@param responseType identifies the type of response we expect, or {@code null} if we’ll accept anything
@param arguments The argument fields to send in the request
@return the response from the player
@throws IOException if there is a communication problem, or if the response does not have the same transaction
ID as the request. | [
"Send",
"a",
"request",
"that",
"expects",
"a",
"single",
"message",
"as",
"its",
"response",
"then",
"read",
"and",
"return",
"that",
"response",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java#L345-L361 |
164,018 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java | Client.menuRequestTyped | public synchronized Message menuRequestTyped(Message.KnownType requestType, Message.MenuIdentifier targetMenu,
CdjStatus.TrackSourceSlot slot, CdjStatus.TrackType trackType, Field... arguments)
throws IOException {
if (!menuLock.isHeldByCurrentThread()) {
throw new IllegalStateException("renderMenuItems() cannot be called without first successfully calling tryLockingForMenuOperation()");
}
Field[] combinedArguments = new Field[arguments.length + 1];
combinedArguments[0] = buildRMST(targetMenu, slot, trackType);
System.arraycopy(arguments, 0, combinedArguments, 1, arguments.length);
final Message response = simpleRequest(requestType, Message.KnownType.MENU_AVAILABLE, combinedArguments);
final NumberField reportedRequestType = (NumberField)response.arguments.get(0);
if (reportedRequestType.getValue() != requestType.protocolValue) {
throw new IOException("Menu request did not return result for same type as request; sent type: " +
requestType.protocolValue + ", received type: " + reportedRequestType.getValue() +
", response: " + response);
}
return response;
} | java | public synchronized Message menuRequestTyped(Message.KnownType requestType, Message.MenuIdentifier targetMenu,
CdjStatus.TrackSourceSlot slot, CdjStatus.TrackType trackType, Field... arguments)
throws IOException {
if (!menuLock.isHeldByCurrentThread()) {
throw new IllegalStateException("renderMenuItems() cannot be called without first successfully calling tryLockingForMenuOperation()");
}
Field[] combinedArguments = new Field[arguments.length + 1];
combinedArguments[0] = buildRMST(targetMenu, slot, trackType);
System.arraycopy(arguments, 0, combinedArguments, 1, arguments.length);
final Message response = simpleRequest(requestType, Message.KnownType.MENU_AVAILABLE, combinedArguments);
final NumberField reportedRequestType = (NumberField)response.arguments.get(0);
if (reportedRequestType.getValue() != requestType.protocolValue) {
throw new IOException("Menu request did not return result for same type as request; sent type: " +
requestType.protocolValue + ", received type: " + reportedRequestType.getValue() +
", response: " + response);
}
return response;
} | [
"public",
"synchronized",
"Message",
"menuRequestTyped",
"(",
"Message",
".",
"KnownType",
"requestType",
",",
"Message",
".",
"MenuIdentifier",
"targetMenu",
",",
"CdjStatus",
".",
"TrackSourceSlot",
"slot",
",",
"CdjStatus",
".",
"TrackType",
"trackType",
",",
"Field",
"...",
"arguments",
")",
"throws",
"IOException",
"{",
"if",
"(",
"!",
"menuLock",
".",
"isHeldByCurrentThread",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"renderMenuItems() cannot be called without first successfully calling tryLockingForMenuOperation()\"",
")",
";",
"}",
"Field",
"[",
"]",
"combinedArguments",
"=",
"new",
"Field",
"[",
"arguments",
".",
"length",
"+",
"1",
"]",
";",
"combinedArguments",
"[",
"0",
"]",
"=",
"buildRMST",
"(",
"targetMenu",
",",
"slot",
",",
"trackType",
")",
";",
"System",
".",
"arraycopy",
"(",
"arguments",
",",
"0",
",",
"combinedArguments",
",",
"1",
",",
"arguments",
".",
"length",
")",
";",
"final",
"Message",
"response",
"=",
"simpleRequest",
"(",
"requestType",
",",
"Message",
".",
"KnownType",
".",
"MENU_AVAILABLE",
",",
"combinedArguments",
")",
";",
"final",
"NumberField",
"reportedRequestType",
"=",
"(",
"NumberField",
")",
"response",
".",
"arguments",
".",
"get",
"(",
"0",
")",
";",
"if",
"(",
"reportedRequestType",
".",
"getValue",
"(",
")",
"!=",
"requestType",
".",
"protocolValue",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Menu request did not return result for same type as request; sent type: \"",
"+",
"requestType",
".",
"protocolValue",
"+",
"\", received type: \"",
"+",
"reportedRequestType",
".",
"getValue",
"(",
")",
"+",
"\", response: \"",
"+",
"response",
")",
";",
"}",
"return",
"response",
";",
"}"
] | Send a request for a menu that we will retrieve items from in subsequent requests, when the request must reflect
the actual type of track being asked about.
@param requestType identifies what kind of menu request to send
@param targetMenu the destination for the response to this query
@param slot the media library of interest for this query
@param trackType the type of track for which metadata is being requested, since this affects the request format
@param arguments the additional arguments needed, if any, to complete the request
@return the {@link Message.KnownType#MENU_AVAILABLE} response reporting how many items are available in the menu
@throws IOException if there is a problem communicating, or if the requested menu is not available
@throws IllegalStateException if {@link #tryLockingForMenuOperations(long, TimeUnit)} was not called successfully
before attempting this call | [
"Send",
"a",
"request",
"for",
"a",
"menu",
"that",
"we",
"will",
"retrieve",
"items",
"from",
"in",
"subsequent",
"requests",
"when",
"the",
"request",
"must",
"reflect",
"the",
"actual",
"type",
"of",
"track",
"being",
"asked",
"about",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java#L403-L422 |
164,019 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/SlotReference.java | SlotReference.getSlotReference | @SuppressWarnings("WeakerAccess")
public static synchronized SlotReference getSlotReference(int player, CdjStatus.TrackSourceSlot slot) {
Map<CdjStatus.TrackSourceSlot, SlotReference> playerMap = instances.get(player);
if (playerMap == null) {
playerMap = new HashMap<CdjStatus.TrackSourceSlot, SlotReference>();
instances.put(player, playerMap);
}
SlotReference result = playerMap.get(slot);
if (result == null) {
result = new SlotReference(player, slot);
playerMap.put(slot, result);
}
return result;
} | java | @SuppressWarnings("WeakerAccess")
public static synchronized SlotReference getSlotReference(int player, CdjStatus.TrackSourceSlot slot) {
Map<CdjStatus.TrackSourceSlot, SlotReference> playerMap = instances.get(player);
if (playerMap == null) {
playerMap = new HashMap<CdjStatus.TrackSourceSlot, SlotReference>();
instances.put(player, playerMap);
}
SlotReference result = playerMap.get(slot);
if (result == null) {
result = new SlotReference(player, slot);
playerMap.put(slot, result);
}
return result;
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"static",
"synchronized",
"SlotReference",
"getSlotReference",
"(",
"int",
"player",
",",
"CdjStatus",
".",
"TrackSourceSlot",
"slot",
")",
"{",
"Map",
"<",
"CdjStatus",
".",
"TrackSourceSlot",
",",
"SlotReference",
">",
"playerMap",
"=",
"instances",
".",
"get",
"(",
"player",
")",
";",
"if",
"(",
"playerMap",
"==",
"null",
")",
"{",
"playerMap",
"=",
"new",
"HashMap",
"<",
"CdjStatus",
".",
"TrackSourceSlot",
",",
"SlotReference",
">",
"(",
")",
";",
"instances",
".",
"put",
"(",
"player",
",",
"playerMap",
")",
";",
"}",
"SlotReference",
"result",
"=",
"playerMap",
".",
"get",
"(",
"slot",
")",
";",
"if",
"(",
"result",
"==",
"null",
")",
"{",
"result",
"=",
"new",
"SlotReference",
"(",
"player",
",",
"slot",
")",
";",
"playerMap",
".",
"put",
"(",
"slot",
",",
"result",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Get a unique reference to a media slot on the network from which tracks can be loaded.
@param player the player in which the slot is found
@param slot the specific type of the slot
@return the instance that will always represent the specified slot
@throws NullPointerException if {@code slot} is {@code null} | [
"Get",
"a",
"unique",
"reference",
"to",
"a",
"media",
"slot",
"on",
"the",
"network",
"from",
"which",
"tracks",
"can",
"be",
"loaded",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/SlotReference.java#L56-L69 |
164,020 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/SlotReference.java | SlotReference.getSlotReference | @SuppressWarnings("WeakerAccess")
public static SlotReference getSlotReference(DataReference dataReference) {
return getSlotReference(dataReference.player, dataReference.slot);
} | java | @SuppressWarnings("WeakerAccess")
public static SlotReference getSlotReference(DataReference dataReference) {
return getSlotReference(dataReference.player, dataReference.slot);
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"static",
"SlotReference",
"getSlotReference",
"(",
"DataReference",
"dataReference",
")",
"{",
"return",
"getSlotReference",
"(",
"dataReference",
".",
"player",
",",
"dataReference",
".",
"slot",
")",
";",
"}"
] | Get a unique reference to the media slot on the network from which the specified data was loaded.
@param dataReference the data whose media slot is of interest
@return the instance that will always represent the slot associated with the specified data | [
"Get",
"a",
"unique",
"reference",
"to",
"the",
"media",
"slot",
"on",
"the",
"network",
"from",
"which",
"the",
"specified",
"data",
"was",
"loaded",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/SlotReference.java#L78-L81 |
164,021 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/Beat.java | Beat.isTempoMaster | @Override
public boolean isTempoMaster() {
DeviceUpdate master = VirtualCdj.getInstance().getTempoMaster();
return (master != null) && master.getAddress().equals(address);
} | java | @Override
public boolean isTempoMaster() {
DeviceUpdate master = VirtualCdj.getInstance().getTempoMaster();
return (master != null) && master.getAddress().equals(address);
} | [
"@",
"Override",
"public",
"boolean",
"isTempoMaster",
"(",
")",
"{",
"DeviceUpdate",
"master",
"=",
"VirtualCdj",
".",
"getInstance",
"(",
")",
".",
"getTempoMaster",
"(",
")",
";",
"return",
"(",
"master",
"!=",
"null",
")",
"&&",
"master",
".",
"getAddress",
"(",
")",
".",
"equals",
"(",
"address",
")",
";",
"}"
] | Was this beat sent by the current tempo master?
@return {@code true} if the device that sent this beat is the master
@throws IllegalStateException if the {@link VirtualCdj} is not running | [
"Was",
"this",
"beat",
"sent",
"by",
"the",
"current",
"tempo",
"master?"
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/Beat.java#L106-L110 |
164,022 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/LifecycleParticipant.java | LifecycleParticipant.deliverLifecycleAnnouncement | protected void deliverLifecycleAnnouncement(final Logger logger, final boolean starting) {
new Thread(new Runnable() {
@Override
public void run() {
for (final LifecycleListener listener : getLifecycleListeners()) {
try {
if (starting) {
listener.started(LifecycleParticipant.this);
} else {
listener.stopped(LifecycleParticipant.this);
}
} catch (Throwable t) {
logger.warn("Problem delivering lifecycle announcement to listener", t);
}
}
}
}, "Lifecycle announcement delivery").start();
} | java | protected void deliverLifecycleAnnouncement(final Logger logger, final boolean starting) {
new Thread(new Runnable() {
@Override
public void run() {
for (final LifecycleListener listener : getLifecycleListeners()) {
try {
if (starting) {
listener.started(LifecycleParticipant.this);
} else {
listener.stopped(LifecycleParticipant.this);
}
} catch (Throwable t) {
logger.warn("Problem delivering lifecycle announcement to listener", t);
}
}
}
}, "Lifecycle announcement delivery").start();
} | [
"protected",
"void",
"deliverLifecycleAnnouncement",
"(",
"final",
"Logger",
"logger",
",",
"final",
"boolean",
"starting",
")",
"{",
"new",
"Thread",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"for",
"(",
"final",
"LifecycleListener",
"listener",
":",
"getLifecycleListeners",
"(",
")",
")",
"{",
"try",
"{",
"if",
"(",
"starting",
")",
"{",
"listener",
".",
"started",
"(",
"LifecycleParticipant",
".",
"this",
")",
";",
"}",
"else",
"{",
"listener",
".",
"stopped",
"(",
"LifecycleParticipant",
".",
"this",
")",
";",
"}",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem delivering lifecycle announcement to listener\"",
",",
"t",
")",
";",
"}",
"}",
"}",
"}",
",",
"\"Lifecycle announcement delivery\"",
")",
".",
"start",
"(",
")",
";",
"}"
] | Send a lifecycle announcement to all registered listeners.
@param logger the logger to use, so the log entry shows as belonging to the proper subclass.
@param starting will be {@code true} if the DeviceFinder is starting, {@code false} if it is stopping. | [
"Send",
"a",
"lifecycle",
"announcement",
"to",
"all",
"registered",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/LifecycleParticipant.java#L69-L86 |
164,023 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/CrateDigger.java | CrateDigger.mountPath | private String mountPath(CdjStatus.TrackSourceSlot slot) {
switch (slot) {
case SD_SLOT: return "/B/";
case USB_SLOT: return "/C/";
}
throw new IllegalArgumentException("Don't know how to NFS mount filesystem for slot " + slot);
} | java | private String mountPath(CdjStatus.TrackSourceSlot slot) {
switch (slot) {
case SD_SLOT: return "/B/";
case USB_SLOT: return "/C/";
}
throw new IllegalArgumentException("Don't know how to NFS mount filesystem for slot " + slot);
} | [
"private",
"String",
"mountPath",
"(",
"CdjStatus",
".",
"TrackSourceSlot",
"slot",
")",
"{",
"switch",
"(",
"slot",
")",
"{",
"case",
"SD_SLOT",
":",
"return",
"\"/B/\"",
";",
"case",
"USB_SLOT",
":",
"return",
"\"/C/\"",
";",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Don't know how to NFS mount filesystem for slot \"",
"+",
"slot",
")",
";",
"}"
] | Return the filesystem path needed to mount the NFS filesystem associated with a particular media slot.
@param slot the slot whose filesystem is desired
@return the path to use in the NFS mount request to access the files mounted in that slot
@throws IllegalArgumentException if it is a slot that we don't know how to handle | [
"Return",
"the",
"filesystem",
"path",
"needed",
"to",
"mount",
"the",
"NFS",
"filesystem",
"associated",
"with",
"a",
"particular",
"media",
"slot",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/CrateDigger.java#L189-L195 |
164,024 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/CrateDigger.java | CrateDigger.deliverDatabaseUpdate | private void deliverDatabaseUpdate(SlotReference slot, Database database, boolean available) {
for (final DatabaseListener listener : getDatabaseListeners()) {
try {
if (available) {
listener.databaseMounted(slot, database);
} else {
listener.databaseUnmounted(slot, database);
}
} catch (Throwable t) {
logger.warn("Problem delivering rekordbox database availability update to listener", t);
}
}
} | java | private void deliverDatabaseUpdate(SlotReference slot, Database database, boolean available) {
for (final DatabaseListener listener : getDatabaseListeners()) {
try {
if (available) {
listener.databaseMounted(slot, database);
} else {
listener.databaseUnmounted(slot, database);
}
} catch (Throwable t) {
logger.warn("Problem delivering rekordbox database availability update to listener", t);
}
}
} | [
"private",
"void",
"deliverDatabaseUpdate",
"(",
"SlotReference",
"slot",
",",
"Database",
"database",
",",
"boolean",
"available",
")",
"{",
"for",
"(",
"final",
"DatabaseListener",
"listener",
":",
"getDatabaseListeners",
"(",
")",
")",
"{",
"try",
"{",
"if",
"(",
"available",
")",
"{",
"listener",
".",
"databaseMounted",
"(",
"slot",
",",
"database",
")",
";",
"}",
"else",
"{",
"listener",
".",
"databaseUnmounted",
"(",
"slot",
",",
"database",
")",
";",
"}",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem delivering rekordbox database availability update to listener\"",
",",
"t",
")",
";",
"}",
"}",
"}"
] | Send a database announcement to all registered listeners.
@param slot the media slot whose database availability has changed
@param database the database whose relevance has changed
@param available if {@code} true, the database is newly available, otherwise it is no longer relevant | [
"Send",
"a",
"database",
"announcement",
"to",
"all",
"registered",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/CrateDigger.java#L726-L738 |
164,025 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformPreviewComponent.java | WaveformPreviewComponent.delegatingRepaint | @SuppressWarnings("SameParameterValue")
private void delegatingRepaint(int x, int y, int width, int height) {
final RepaintDelegate delegate = repaintDelegate.get();
if (delegate != null) {
//logger.info("Delegating repaint: " + x + ", " + y + ", " + width + ", " + height);
delegate.repaint(x, y, width, height);
} else {
//logger.info("Normal repaint: " + x + ", " + y + ", " + width + ", " + height);
repaint(x, y, width, height);
}
} | java | @SuppressWarnings("SameParameterValue")
private void delegatingRepaint(int x, int y, int width, int height) {
final RepaintDelegate delegate = repaintDelegate.get();
if (delegate != null) {
//logger.info("Delegating repaint: " + x + ", " + y + ", " + width + ", " + height);
delegate.repaint(x, y, width, height);
} else {
//logger.info("Normal repaint: " + x + ", " + y + ", " + width + ", " + height);
repaint(x, y, width, height);
}
} | [
"@",
"SuppressWarnings",
"(",
"\"SameParameterValue\"",
")",
"private",
"void",
"delegatingRepaint",
"(",
"int",
"x",
",",
"int",
"y",
",",
"int",
"width",
",",
"int",
"height",
")",
"{",
"final",
"RepaintDelegate",
"delegate",
"=",
"repaintDelegate",
".",
"get",
"(",
")",
";",
"if",
"(",
"delegate",
"!=",
"null",
")",
"{",
"//logger.info(\"Delegating repaint: \" + x + \", \" + y + \", \" + width + \", \" + height);",
"delegate",
".",
"repaint",
"(",
"x",
",",
"y",
",",
"width",
",",
"height",
")",
";",
"}",
"else",
"{",
"//logger.info(\"Normal repaint: \" + x + \", \" + y + \", \" + width + \", \" + height);",
"repaint",
"(",
"x",
",",
"y",
",",
"width",
",",
"height",
")",
";",
"}",
"}"
] | Determine whether we should use the normal repaint process, or delegate that to another component that is
hosting us in a soft-loaded manner to save memory.
@param x the left edge of the region that we want to have redrawn
@param y the top edge of the region that we want to have redrawn
@param width the width of the region that we want to have redrawn
@param height the height of the region that we want to have redrawn | [
"Determine",
"whether",
"we",
"should",
"use",
"the",
"normal",
"repaint",
"process",
"or",
"delegate",
"that",
"to",
"another",
"component",
"that",
"is",
"hosting",
"us",
"in",
"a",
"soft",
"-",
"loaded",
"manner",
"to",
"save",
"memory",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformPreviewComponent.java#L225-L235 |
164,026 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformPreviewComponent.java | WaveformPreviewComponent.updateWaveform | private void updateWaveform(WaveformPreview preview) {
this.preview.set(preview);
if (preview == null) {
waveformImage.set(null);
} else {
BufferedImage image = new BufferedImage(preview.segmentCount, preview.maxHeight, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setColor(Color.BLACK);
g.fillRect(0, 0, preview.segmentCount, preview.maxHeight);
for (int segment = 0; segment < preview.segmentCount; segment++) {
g.setColor(preview.segmentColor(segment, false));
g.drawLine(segment, preview.maxHeight, segment, preview.maxHeight - preview.segmentHeight(segment, false));
if (preview.isColor) { // We have a front color segment to draw on top.
g.setColor(preview.segmentColor(segment, true));
g.drawLine(segment, preview.maxHeight, segment, preview.maxHeight - preview.segmentHeight(segment, true));
}
}
waveformImage.set(image);
}
} | java | private void updateWaveform(WaveformPreview preview) {
this.preview.set(preview);
if (preview == null) {
waveformImage.set(null);
} else {
BufferedImage image = new BufferedImage(preview.segmentCount, preview.maxHeight, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setColor(Color.BLACK);
g.fillRect(0, 0, preview.segmentCount, preview.maxHeight);
for (int segment = 0; segment < preview.segmentCount; segment++) {
g.setColor(preview.segmentColor(segment, false));
g.drawLine(segment, preview.maxHeight, segment, preview.maxHeight - preview.segmentHeight(segment, false));
if (preview.isColor) { // We have a front color segment to draw on top.
g.setColor(preview.segmentColor(segment, true));
g.drawLine(segment, preview.maxHeight, segment, preview.maxHeight - preview.segmentHeight(segment, true));
}
}
waveformImage.set(image);
}
} | [
"private",
"void",
"updateWaveform",
"(",
"WaveformPreview",
"preview",
")",
"{",
"this",
".",
"preview",
".",
"set",
"(",
"preview",
")",
";",
"if",
"(",
"preview",
"==",
"null",
")",
"{",
"waveformImage",
".",
"set",
"(",
"null",
")",
";",
"}",
"else",
"{",
"BufferedImage",
"image",
"=",
"new",
"BufferedImage",
"(",
"preview",
".",
"segmentCount",
",",
"preview",
".",
"maxHeight",
",",
"BufferedImage",
".",
"TYPE_INT_RGB",
")",
";",
"Graphics",
"g",
"=",
"image",
".",
"getGraphics",
"(",
")",
";",
"g",
".",
"setColor",
"(",
"Color",
".",
"BLACK",
")",
";",
"g",
".",
"fillRect",
"(",
"0",
",",
"0",
",",
"preview",
".",
"segmentCount",
",",
"preview",
".",
"maxHeight",
")",
";",
"for",
"(",
"int",
"segment",
"=",
"0",
";",
"segment",
"<",
"preview",
".",
"segmentCount",
";",
"segment",
"++",
")",
"{",
"g",
".",
"setColor",
"(",
"preview",
".",
"segmentColor",
"(",
"segment",
",",
"false",
")",
")",
";",
"g",
".",
"drawLine",
"(",
"segment",
",",
"preview",
".",
"maxHeight",
",",
"segment",
",",
"preview",
".",
"maxHeight",
"-",
"preview",
".",
"segmentHeight",
"(",
"segment",
",",
"false",
")",
")",
";",
"if",
"(",
"preview",
".",
"isColor",
")",
"{",
"// We have a front color segment to draw on top.",
"g",
".",
"setColor",
"(",
"preview",
".",
"segmentColor",
"(",
"segment",
",",
"true",
")",
")",
";",
"g",
".",
"drawLine",
"(",
"segment",
",",
"preview",
".",
"maxHeight",
",",
"segment",
",",
"preview",
".",
"maxHeight",
"-",
"preview",
".",
"segmentHeight",
"(",
"segment",
",",
"true",
")",
")",
";",
"}",
"}",
"waveformImage",
".",
"set",
"(",
"image",
")",
";",
"}",
"}"
] | Create an image of the proper size to hold a new waveform preview image and draw it. | [
"Create",
"an",
"image",
"of",
"the",
"proper",
"size",
"to",
"hold",
"a",
"new",
"waveform",
"preview",
"image",
"and",
"draw",
"it",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformPreviewComponent.java#L420-L439 |
164,027 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformPreview.java | WaveformPreview.getMaxHeight | private int getMaxHeight() {
int result = 0;
for (int i = 0; i < segmentCount; i++) {
result = Math.max(result, segmentHeight(i, false));
}
return result;
} | java | private int getMaxHeight() {
int result = 0;
for (int i = 0; i < segmentCount; i++) {
result = Math.max(result, segmentHeight(i, false));
}
return result;
} | [
"private",
"int",
"getMaxHeight",
"(",
")",
"{",
"int",
"result",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"segmentCount",
";",
"i",
"++",
")",
"{",
"result",
"=",
"Math",
".",
"max",
"(",
"result",
",",
"segmentHeight",
"(",
"i",
",",
"false",
")",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Scan the segments to find the largest height value present.
@return the largest waveform height anywhere in the preview. | [
"Scan",
"the",
"segments",
"to",
"find",
"the",
"largest",
"height",
"value",
"present",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformPreview.java#L110-L116 |
164,028 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformPreview.java | WaveformPreview.segmentHeight | @SuppressWarnings("WeakerAccess")
public int segmentHeight(final int segment, final boolean front) {
final ByteBuffer bytes = getData();
if (isColor) {
final int base = segment * 6;
final int frontHeight = Util.unsign(bytes.get(base + 5));
if (front) {
return frontHeight;
} else {
return Math.max(frontHeight, Math.max(Util.unsign(bytes.get(base + 3)), Util.unsign(bytes.get(base + 4))));
}
} else {
return getData().get(segment * 2) & 0x1f;
}
} | java | @SuppressWarnings("WeakerAccess")
public int segmentHeight(final int segment, final boolean front) {
final ByteBuffer bytes = getData();
if (isColor) {
final int base = segment * 6;
final int frontHeight = Util.unsign(bytes.get(base + 5));
if (front) {
return frontHeight;
} else {
return Math.max(frontHeight, Math.max(Util.unsign(bytes.get(base + 3)), Util.unsign(bytes.get(base + 4))));
}
} else {
return getData().get(segment * 2) & 0x1f;
}
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"int",
"segmentHeight",
"(",
"final",
"int",
"segment",
",",
"final",
"boolean",
"front",
")",
"{",
"final",
"ByteBuffer",
"bytes",
"=",
"getData",
"(",
")",
";",
"if",
"(",
"isColor",
")",
"{",
"final",
"int",
"base",
"=",
"segment",
"*",
"6",
";",
"final",
"int",
"frontHeight",
"=",
"Util",
".",
"unsign",
"(",
"bytes",
".",
"get",
"(",
"base",
"+",
"5",
")",
")",
";",
"if",
"(",
"front",
")",
"{",
"return",
"frontHeight",
";",
"}",
"else",
"{",
"return",
"Math",
".",
"max",
"(",
"frontHeight",
",",
"Math",
".",
"max",
"(",
"Util",
".",
"unsign",
"(",
"bytes",
".",
"get",
"(",
"base",
"+",
"3",
")",
")",
",",
"Util",
".",
"unsign",
"(",
"bytes",
".",
"get",
"(",
"base",
"+",
"4",
")",
")",
")",
")",
";",
"}",
"}",
"else",
"{",
"return",
"getData",
"(",
")",
".",
"get",
"(",
"segment",
"*",
"2",
")",
"&",
"0x1f",
";",
"}",
"}"
] | Determine the height of the preview given an index into it.
@param segment the index of the waveform preview segment to examine
@param front if {@code true} the height of the front (brighter) segment of a color waveform preview is returned,
otherwise the height of the back (dimmer) segment is returned. Has no effect for blue previews.
@return a value from 0 to 31 representing the height of the waveform at that segment, which may be an average
of a number of values starting there, determined by the scale | [
"Determine",
"the",
"height",
"of",
"the",
"preview",
"given",
"an",
"index",
"into",
"it",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformPreview.java#L218-L232 |
164,029 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformPreview.java | WaveformPreview.segmentColor | @SuppressWarnings("WeakerAccess")
public Color segmentColor(final int segment, final boolean front) {
final ByteBuffer bytes = getData();
if (isColor) {
final int base = segment * 6;
final int backHeight = segmentHeight(segment, false);
if (backHeight == 0) {
return Color.BLACK;
}
final int maxLevel = front? 255 : 191;
final int red = Util.unsign(bytes.get(base + 3)) * maxLevel / backHeight;
final int green = Util.unsign(bytes.get(base + 4)) * maxLevel / backHeight;
final int blue = Util.unsign(bytes.get(base + 5)) * maxLevel / backHeight;
return new Color(red, green, blue);
} else {
final int intensity = getData().get(segment * 2 + 1) & 0x07;
return (intensity >= 5) ? INTENSE_COLOR : NORMAL_COLOR;
}
} | java | @SuppressWarnings("WeakerAccess")
public Color segmentColor(final int segment, final boolean front) {
final ByteBuffer bytes = getData();
if (isColor) {
final int base = segment * 6;
final int backHeight = segmentHeight(segment, false);
if (backHeight == 0) {
return Color.BLACK;
}
final int maxLevel = front? 255 : 191;
final int red = Util.unsign(bytes.get(base + 3)) * maxLevel / backHeight;
final int green = Util.unsign(bytes.get(base + 4)) * maxLevel / backHeight;
final int blue = Util.unsign(bytes.get(base + 5)) * maxLevel / backHeight;
return new Color(red, green, blue);
} else {
final int intensity = getData().get(segment * 2 + 1) & 0x07;
return (intensity >= 5) ? INTENSE_COLOR : NORMAL_COLOR;
}
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"Color",
"segmentColor",
"(",
"final",
"int",
"segment",
",",
"final",
"boolean",
"front",
")",
"{",
"final",
"ByteBuffer",
"bytes",
"=",
"getData",
"(",
")",
";",
"if",
"(",
"isColor",
")",
"{",
"final",
"int",
"base",
"=",
"segment",
"*",
"6",
";",
"final",
"int",
"backHeight",
"=",
"segmentHeight",
"(",
"segment",
",",
"false",
")",
";",
"if",
"(",
"backHeight",
"==",
"0",
")",
"{",
"return",
"Color",
".",
"BLACK",
";",
"}",
"final",
"int",
"maxLevel",
"=",
"front",
"?",
"255",
":",
"191",
";",
"final",
"int",
"red",
"=",
"Util",
".",
"unsign",
"(",
"bytes",
".",
"get",
"(",
"base",
"+",
"3",
")",
")",
"*",
"maxLevel",
"/",
"backHeight",
";",
"final",
"int",
"green",
"=",
"Util",
".",
"unsign",
"(",
"bytes",
".",
"get",
"(",
"base",
"+",
"4",
")",
")",
"*",
"maxLevel",
"/",
"backHeight",
";",
"final",
"int",
"blue",
"=",
"Util",
".",
"unsign",
"(",
"bytes",
".",
"get",
"(",
"base",
"+",
"5",
")",
")",
"*",
"maxLevel",
"/",
"backHeight",
";",
"return",
"new",
"Color",
"(",
"red",
",",
"green",
",",
"blue",
")",
";",
"}",
"else",
"{",
"final",
"int",
"intensity",
"=",
"getData",
"(",
")",
".",
"get",
"(",
"segment",
"*",
"2",
"+",
"1",
")",
"&",
"0x07",
";",
"return",
"(",
"intensity",
">=",
"5",
")",
"?",
"INTENSE_COLOR",
":",
"NORMAL_COLOR",
";",
"}",
"}"
] | Determine the color of the waveform given an index into it.
@param segment the index of the first waveform byte to examine
@param front if {@code true} the front (brighter) segment of a color waveform preview is returned,
otherwise the back (dimmer) segment is returned. Has no effect for blue previews.
@return the color of the waveform at that segment, which may be based on an average
of a number of values starting there, determined by the scale | [
"Determine",
"the",
"color",
"of",
"the",
"waveform",
"given",
"an",
"index",
"into",
"it",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformPreview.java#L244-L262 |
164,030 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/MediaDetails.java | MediaDetails.hasChanged | public boolean hasChanged(MediaDetails originalMedia) {
if (!hashKey().equals(originalMedia.hashKey())) {
throw new IllegalArgumentException("Can't compare media details with different hashKey values");
}
return playlistCount != originalMedia.playlistCount || trackCount != originalMedia.trackCount;
} | java | public boolean hasChanged(MediaDetails originalMedia) {
if (!hashKey().equals(originalMedia.hashKey())) {
throw new IllegalArgumentException("Can't compare media details with different hashKey values");
}
return playlistCount != originalMedia.playlistCount || trackCount != originalMedia.trackCount;
} | [
"public",
"boolean",
"hasChanged",
"(",
"MediaDetails",
"originalMedia",
")",
"{",
"if",
"(",
"!",
"hashKey",
"(",
")",
".",
"equals",
"(",
"originalMedia",
".",
"hashKey",
"(",
")",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Can't compare media details with different hashKey values\"",
")",
";",
"}",
"return",
"playlistCount",
"!=",
"originalMedia",
".",
"playlistCount",
"||",
"trackCount",
"!=",
"originalMedia",
".",
"trackCount",
";",
"}"
] | Check whether the media seems to have changed since a saved version of it was used. We ignore changes in
free space because those probably just reflect history entries being added.
@param originalMedia the media details when information about it was saved
@return true if there have been detectable significant changes to the media since it was saved
@throws IllegalArgumentException if the {@link #hashKey()} values of the media detail objects differ | [
"Check",
"whether",
"the",
"media",
"seems",
"to",
"have",
"changed",
"since",
"a",
"saved",
"version",
"of",
"it",
"was",
"used",
".",
"We",
"ignore",
"changes",
"in",
"free",
"space",
"because",
"those",
"probably",
"just",
"reflect",
"history",
"entries",
"being",
"added",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/MediaDetails.java#L183-L188 |
164,031 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/BinaryField.java | BinaryField.getValueAsArray | public byte[] getValueAsArray() {
ByteBuffer buffer = getValue();
byte[] result = new byte[buffer.remaining()];
buffer.get(result);
return result;
} | java | public byte[] getValueAsArray() {
ByteBuffer buffer = getValue();
byte[] result = new byte[buffer.remaining()];
buffer.get(result);
return result;
} | [
"public",
"byte",
"[",
"]",
"getValueAsArray",
"(",
")",
"{",
"ByteBuffer",
"buffer",
"=",
"getValue",
"(",
")",
";",
"byte",
"[",
"]",
"result",
"=",
"new",
"byte",
"[",
"buffer",
".",
"remaining",
"(",
")",
"]",
";",
"buffer",
".",
"get",
"(",
"result",
")",
";",
"return",
"result",
";",
"}"
] | Get the bytes which represent the payload of this field, without the leading type tag and length header, as
a newly-allocated byte array.
@return a new byte array containing a copy of the bytes this field contains | [
"Get",
"the",
"bytes",
"which",
"represent",
"the",
"payload",
"of",
"this",
"field",
"without",
"the",
"leading",
"type",
"tag",
"and",
"length",
"header",
"as",
"a",
"newly",
"-",
"allocated",
"byte",
"array",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/BinaryField.java#L69-L74 |
164,032 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/CueList.java | CueList.getHotCueCount | public int getHotCueCount() {
if (rawMessage != null) {
return (int) ((NumberField) rawMessage.arguments.get(5)).getValue();
}
int total = 0;
for (Entry entry : entries) {
if (entry.hotCueNumber > 0) {
++total;
}
}
return total;
} | java | public int getHotCueCount() {
if (rawMessage != null) {
return (int) ((NumberField) rawMessage.arguments.get(5)).getValue();
}
int total = 0;
for (Entry entry : entries) {
if (entry.hotCueNumber > 0) {
++total;
}
}
return total;
} | [
"public",
"int",
"getHotCueCount",
"(",
")",
"{",
"if",
"(",
"rawMessage",
"!=",
"null",
")",
"{",
"return",
"(",
"int",
")",
"(",
"(",
"NumberField",
")",
"rawMessage",
".",
"arguments",
".",
"get",
"(",
"5",
")",
")",
".",
"getValue",
"(",
")",
";",
"}",
"int",
"total",
"=",
"0",
";",
"for",
"(",
"Entry",
"entry",
":",
"entries",
")",
"{",
"if",
"(",
"entry",
".",
"hotCueNumber",
">",
"0",
")",
"{",
"++",
"total",
";",
"}",
"}",
"return",
"total",
";",
"}"
] | Return the number of entries in the cue list that represent hot cues.
@return the number of cue list entries that are hot cues | [
"Return",
"the",
"number",
"of",
"entries",
"in",
"the",
"cue",
"list",
"that",
"represent",
"hot",
"cues",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/CueList.java#L42-L53 |
164,033 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/CueList.java | CueList.sortEntries | private List<Entry> sortEntries(List<Entry> loadedEntries) {
Collections.sort(loadedEntries, new Comparator<Entry>() {
@Override
public int compare(Entry entry1, Entry entry2) {
int result = (int) (entry1.cuePosition - entry2.cuePosition);
if (result == 0) {
int h1 = (entry1.hotCueNumber != 0) ? 1 : 0;
int h2 = (entry2.hotCueNumber != 0) ? 1 : 0;
result = h1 - h2;
}
return result;
}
});
return Collections.unmodifiableList(loadedEntries);
} | java | private List<Entry> sortEntries(List<Entry> loadedEntries) {
Collections.sort(loadedEntries, new Comparator<Entry>() {
@Override
public int compare(Entry entry1, Entry entry2) {
int result = (int) (entry1.cuePosition - entry2.cuePosition);
if (result == 0) {
int h1 = (entry1.hotCueNumber != 0) ? 1 : 0;
int h2 = (entry2.hotCueNumber != 0) ? 1 : 0;
result = h1 - h2;
}
return result;
}
});
return Collections.unmodifiableList(loadedEntries);
} | [
"private",
"List",
"<",
"Entry",
">",
"sortEntries",
"(",
"List",
"<",
"Entry",
">",
"loadedEntries",
")",
"{",
"Collections",
".",
"sort",
"(",
"loadedEntries",
",",
"new",
"Comparator",
"<",
"Entry",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"int",
"compare",
"(",
"Entry",
"entry1",
",",
"Entry",
"entry2",
")",
"{",
"int",
"result",
"=",
"(",
"int",
")",
"(",
"entry1",
".",
"cuePosition",
"-",
"entry2",
".",
"cuePosition",
")",
";",
"if",
"(",
"result",
"==",
"0",
")",
"{",
"int",
"h1",
"=",
"(",
"entry1",
".",
"hotCueNumber",
"!=",
"0",
")",
"?",
"1",
":",
"0",
";",
"int",
"h2",
"=",
"(",
"entry2",
".",
"hotCueNumber",
"!=",
"0",
")",
"?",
"1",
":",
"0",
";",
"result",
"=",
"h1",
"-",
"h2",
";",
"}",
"return",
"result",
";",
"}",
"}",
")",
";",
"return",
"Collections",
".",
"unmodifiableList",
"(",
"loadedEntries",
")",
";",
"}"
] | Sorts the entries into the order we want to present them in, which is by position, with hot cues coming after
ordinary memory points if both exist at the same position, which often happens.
@param loadedEntries the unsorted entries we have loaded from a dbserver message, metadata cache, or rekordbox
database export
@return an immutable list of the collections in the proper order | [
"Sorts",
"the",
"entries",
"into",
"the",
"order",
"we",
"want",
"to",
"present",
"them",
"in",
"which",
"is",
"by",
"position",
"with",
"hot",
"cues",
"coming",
"after",
"ordinary",
"memory",
"points",
"if",
"both",
"exist",
"at",
"the",
"same",
"position",
"which",
"often",
"happens",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/CueList.java#L204-L218 |
164,034 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/CueList.java | CueList.addEntriesFromTag | private void addEntriesFromTag(List<Entry> entries, RekordboxAnlz.CueTag tag) {
for (RekordboxAnlz.CueEntry cueEntry : tag.cues()) { // TODO: Need to figure out how to identify deleted entries to ignore.
if (cueEntry.type() == RekordboxAnlz.CueEntryType.LOOP) {
entries.add(new Entry((int)cueEntry.hotCue(), Util.timeToHalfFrame(cueEntry.time()),
Util.timeToHalfFrame(cueEntry.loopTime())));
} else {
entries.add(new Entry((int)cueEntry.hotCue(), Util.timeToHalfFrame(cueEntry.time())));
}
}
} | java | private void addEntriesFromTag(List<Entry> entries, RekordboxAnlz.CueTag tag) {
for (RekordboxAnlz.CueEntry cueEntry : tag.cues()) { // TODO: Need to figure out how to identify deleted entries to ignore.
if (cueEntry.type() == RekordboxAnlz.CueEntryType.LOOP) {
entries.add(new Entry((int)cueEntry.hotCue(), Util.timeToHalfFrame(cueEntry.time()),
Util.timeToHalfFrame(cueEntry.loopTime())));
} else {
entries.add(new Entry((int)cueEntry.hotCue(), Util.timeToHalfFrame(cueEntry.time())));
}
}
} | [
"private",
"void",
"addEntriesFromTag",
"(",
"List",
"<",
"Entry",
">",
"entries",
",",
"RekordboxAnlz",
".",
"CueTag",
"tag",
")",
"{",
"for",
"(",
"RekordboxAnlz",
".",
"CueEntry",
"cueEntry",
":",
"tag",
".",
"cues",
"(",
")",
")",
"{",
"// TODO: Need to figure out how to identify deleted entries to ignore.",
"if",
"(",
"cueEntry",
".",
"type",
"(",
")",
"==",
"RekordboxAnlz",
".",
"CueEntryType",
".",
"LOOP",
")",
"{",
"entries",
".",
"add",
"(",
"new",
"Entry",
"(",
"(",
"int",
")",
"cueEntry",
".",
"hotCue",
"(",
")",
",",
"Util",
".",
"timeToHalfFrame",
"(",
"cueEntry",
".",
"time",
"(",
")",
")",
",",
"Util",
".",
"timeToHalfFrame",
"(",
"cueEntry",
".",
"loopTime",
"(",
")",
")",
")",
")",
";",
"}",
"else",
"{",
"entries",
".",
"add",
"(",
"new",
"Entry",
"(",
"(",
"int",
")",
"cueEntry",
".",
"hotCue",
"(",
")",
",",
"Util",
".",
"timeToHalfFrame",
"(",
"cueEntry",
".",
"time",
"(",
")",
")",
")",
")",
";",
"}",
"}",
"}"
] | Helper method to add cue list entries from a parsed ANLZ cue tag
@param entries the list of entries being accumulated
@param tag the tag whose entries are to be added | [
"Helper",
"method",
"to",
"add",
"cue",
"list",
"entries",
"from",
"a",
"parsed",
"ANLZ",
"cue",
"tag"
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/CueList.java#L226-L235 |
164,035 | rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Processor.java | Processor.process | public final static String process(final String input, final Configuration configuration)
{
try
{
return process(new StringReader(input), configuration);
}
catch (final IOException e)
{
// This _can never_ happen
return null;
}
} | java | public final static String process(final String input, final Configuration configuration)
{
try
{
return process(new StringReader(input), configuration);
}
catch (final IOException e)
{
// This _can never_ happen
return null;
}
} | [
"public",
"final",
"static",
"String",
"process",
"(",
"final",
"String",
"input",
",",
"final",
"Configuration",
"configuration",
")",
"{",
"try",
"{",
"return",
"process",
"(",
"new",
"StringReader",
"(",
"input",
")",
",",
"configuration",
")",
";",
"}",
"catch",
"(",
"final",
"IOException",
"e",
")",
"{",
"// This _can never_ happen",
"return",
"null",
";",
"}",
"}"
] | Transforms an input String into HTML using the given Configuration.
@param input
The String to process.
@param configuration
The Configuration.
@return The processed String.
@since 0.7
@see Configuration | [
"Transforms",
"an",
"input",
"String",
"into",
"HTML",
"using",
"the",
"given",
"Configuration",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Processor.java#L97-L108 |
164,036 | rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Processor.java | Processor.process | public final static String process(final File file, final Configuration configuration) throws IOException
{
final FileInputStream input = new FileInputStream(file);
final String ret = process(input, configuration);
input.close();
return ret;
} | java | public final static String process(final File file, final Configuration configuration) throws IOException
{
final FileInputStream input = new FileInputStream(file);
final String ret = process(input, configuration);
input.close();
return ret;
} | [
"public",
"final",
"static",
"String",
"process",
"(",
"final",
"File",
"file",
",",
"final",
"Configuration",
"configuration",
")",
"throws",
"IOException",
"{",
"final",
"FileInputStream",
"input",
"=",
"new",
"FileInputStream",
"(",
"file",
")",
";",
"final",
"String",
"ret",
"=",
"process",
"(",
"input",
",",
"configuration",
")",
";",
"input",
".",
"close",
"(",
")",
";",
"return",
"ret",
";",
"}"
] | Transforms an input file into HTML using the given Configuration.
@param file
The File to process.
@param configuration
the Configuration
@return The processed String.
@throws IOException
if an IO error occurs
@since 0.7
@see Configuration | [
"Transforms",
"an",
"input",
"file",
"into",
"HTML",
"using",
"the",
"given",
"Configuration",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Processor.java#L123-L129 |
164,037 | rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Processor.java | Processor.process | public final static String process(final File file, final boolean safeMode) throws IOException
{
return process(file, Configuration.builder().setSafeMode(safeMode).build());
} | java | public final static String process(final File file, final boolean safeMode) throws IOException
{
return process(file, Configuration.builder().setSafeMode(safeMode).build());
} | [
"public",
"final",
"static",
"String",
"process",
"(",
"final",
"File",
"file",
",",
"final",
"boolean",
"safeMode",
")",
"throws",
"IOException",
"{",
"return",
"process",
"(",
"file",
",",
"Configuration",
".",
"builder",
"(",
")",
".",
"setSafeMode",
"(",
"safeMode",
")",
".",
"build",
"(",
")",
")",
";",
"}"
] | Transforms an input file into HTML.
@param file
The File to process.
@param safeMode
Set to <code>true</code> to escape unsafe HTML tags.
@return The processed String.
@throws IOException
if an IO error occurs
@see Configuration#DEFAULT | [
"Transforms",
"an",
"input",
"file",
"into",
"HTML",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Processor.java#L238-L241 |
164,038 | rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Run.java | Run.main | public static void main(final String[] args) throws IOException
{
// This is just a _hack_ ...
BufferedReader reader = null;
if (args.length == 0)
{
System.err.println("No input file specified.");
System.exit(-1);
}
if (args.length > 1)
{
reader = new BufferedReader(new InputStreamReader(new FileInputStream(args[1]), "UTF-8"));
String line = reader.readLine();
while (line != null && !line.startsWith("<!-- ###"))
{
System.out.println(line);
line = reader.readLine();
}
}
System.out.println(Processor.process(new File(args[0])));
if (args.length > 1 && reader != null)
{
String line = reader.readLine();
while (line != null)
{
System.out.println(line);
line = reader.readLine();
}
reader.close();
}
} | java | public static void main(final String[] args) throws IOException
{
// This is just a _hack_ ...
BufferedReader reader = null;
if (args.length == 0)
{
System.err.println("No input file specified.");
System.exit(-1);
}
if (args.length > 1)
{
reader = new BufferedReader(new InputStreamReader(new FileInputStream(args[1]), "UTF-8"));
String line = reader.readLine();
while (line != null && !line.startsWith("<!-- ###"))
{
System.out.println(line);
line = reader.readLine();
}
}
System.out.println(Processor.process(new File(args[0])));
if (args.length > 1 && reader != null)
{
String line = reader.readLine();
while (line != null)
{
System.out.println(line);
line = reader.readLine();
}
reader.close();
}
} | [
"public",
"static",
"void",
"main",
"(",
"final",
"String",
"[",
"]",
"args",
")",
"throws",
"IOException",
"{",
"// This is just a _hack_ ...",
"BufferedReader",
"reader",
"=",
"null",
";",
"if",
"(",
"args",
".",
"length",
"==",
"0",
")",
"{",
"System",
".",
"err",
".",
"println",
"(",
"\"No input file specified.\"",
")",
";",
"System",
".",
"exit",
"(",
"-",
"1",
")",
";",
"}",
"if",
"(",
"args",
".",
"length",
">",
"1",
")",
"{",
"reader",
"=",
"new",
"BufferedReader",
"(",
"new",
"InputStreamReader",
"(",
"new",
"FileInputStream",
"(",
"args",
"[",
"1",
"]",
")",
",",
"\"UTF-8\"",
")",
")",
";",
"String",
"line",
"=",
"reader",
".",
"readLine",
"(",
")",
";",
"while",
"(",
"line",
"!=",
"null",
"&&",
"!",
"line",
".",
"startsWith",
"(",
"\"<!-- ###\"",
")",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"line",
")",
";",
"line",
"=",
"reader",
".",
"readLine",
"(",
")",
";",
"}",
"}",
"System",
".",
"out",
".",
"println",
"(",
"Processor",
".",
"process",
"(",
"new",
"File",
"(",
"args",
"[",
"0",
"]",
")",
")",
")",
";",
"if",
"(",
"args",
".",
"length",
">",
"1",
"&&",
"reader",
"!=",
"null",
")",
"{",
"String",
"line",
"=",
"reader",
".",
"readLine",
"(",
")",
";",
"while",
"(",
"line",
"!=",
"null",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"line",
")",
";",
"line",
"=",
"reader",
".",
"readLine",
"(",
")",
";",
"}",
"reader",
".",
"close",
"(",
")",
";",
"}",
"}"
] | Static main.
@param args
Program arguments.
@throws IOException
If an IO error occurred. | [
"Static",
"main",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Run.java#L75-L105 |
164,039 | rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/cmd/CmdLineParser.java | CmdLineParser.parse | public static List<String> parse(final String[] args, final Object... objs) throws IOException
{
final List<String> ret = Colls.list();
final List<Arg> allArgs = Colls.list();
final HashMap<String, Arg> shortArgs = new HashMap<String, Arg>();
final HashMap<String, Arg> longArgs = new HashMap<String, Arg>();
parseArgs(objs, allArgs, shortArgs, longArgs);
for (int i = 0; i < args.length; i++)
{
final String s = args[i];
final Arg a;
if (s.startsWith("--"))
{
a = longArgs.get(s.substring(2));
if (a == null)
{
throw new IOException("Unknown switch: " + s);
}
}
else if (s.startsWith("-"))
{
a = shortArgs.get(s.substring(1));
if (a == null)
{
throw new IOException("Unknown switch: " + s);
}
}
else
{
a = null;
ret.add(s);
}
if (a != null)
{
if (a.isSwitch)
{
a.setField("true");
}
else
{
if (i + 1 >= args.length)
{
System.out.println("Missing parameter for: " + s);
}
if (a.isCatchAll())
{
final List<String> ca = Colls.list();
for (++i; i < args.length; ++i)
{
ca.add(args[i]);
}
a.setCatchAll(ca);
}
else
{
++i;
a.setField(args[i]);
}
}
a.setPresent();
}
}
for (final Arg a : allArgs)
{
if (!a.isOk())
{
throw new IOException("Missing mandatory argument: " + a);
}
}
return ret;
} | java | public static List<String> parse(final String[] args, final Object... objs) throws IOException
{
final List<String> ret = Colls.list();
final List<Arg> allArgs = Colls.list();
final HashMap<String, Arg> shortArgs = new HashMap<String, Arg>();
final HashMap<String, Arg> longArgs = new HashMap<String, Arg>();
parseArgs(objs, allArgs, shortArgs, longArgs);
for (int i = 0; i < args.length; i++)
{
final String s = args[i];
final Arg a;
if (s.startsWith("--"))
{
a = longArgs.get(s.substring(2));
if (a == null)
{
throw new IOException("Unknown switch: " + s);
}
}
else if (s.startsWith("-"))
{
a = shortArgs.get(s.substring(1));
if (a == null)
{
throw new IOException("Unknown switch: " + s);
}
}
else
{
a = null;
ret.add(s);
}
if (a != null)
{
if (a.isSwitch)
{
a.setField("true");
}
else
{
if (i + 1 >= args.length)
{
System.out.println("Missing parameter for: " + s);
}
if (a.isCatchAll())
{
final List<String> ca = Colls.list();
for (++i; i < args.length; ++i)
{
ca.add(args[i]);
}
a.setCatchAll(ca);
}
else
{
++i;
a.setField(args[i]);
}
}
a.setPresent();
}
}
for (final Arg a : allArgs)
{
if (!a.isOk())
{
throw new IOException("Missing mandatory argument: " + a);
}
}
return ret;
} | [
"public",
"static",
"List",
"<",
"String",
">",
"parse",
"(",
"final",
"String",
"[",
"]",
"args",
",",
"final",
"Object",
"...",
"objs",
")",
"throws",
"IOException",
"{",
"final",
"List",
"<",
"String",
">",
"ret",
"=",
"Colls",
".",
"list",
"(",
")",
";",
"final",
"List",
"<",
"Arg",
">",
"allArgs",
"=",
"Colls",
".",
"list",
"(",
")",
";",
"final",
"HashMap",
"<",
"String",
",",
"Arg",
">",
"shortArgs",
"=",
"new",
"HashMap",
"<",
"String",
",",
"Arg",
">",
"(",
")",
";",
"final",
"HashMap",
"<",
"String",
",",
"Arg",
">",
"longArgs",
"=",
"new",
"HashMap",
"<",
"String",
",",
"Arg",
">",
"(",
")",
";",
"parseArgs",
"(",
"objs",
",",
"allArgs",
",",
"shortArgs",
",",
"longArgs",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"args",
".",
"length",
";",
"i",
"++",
")",
"{",
"final",
"String",
"s",
"=",
"args",
"[",
"i",
"]",
";",
"final",
"Arg",
"a",
";",
"if",
"(",
"s",
".",
"startsWith",
"(",
"\"--\"",
")",
")",
"{",
"a",
"=",
"longArgs",
".",
"get",
"(",
"s",
".",
"substring",
"(",
"2",
")",
")",
";",
"if",
"(",
"a",
"==",
"null",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Unknown switch: \"",
"+",
"s",
")",
";",
"}",
"}",
"else",
"if",
"(",
"s",
".",
"startsWith",
"(",
"\"-\"",
")",
")",
"{",
"a",
"=",
"shortArgs",
".",
"get",
"(",
"s",
".",
"substring",
"(",
"1",
")",
")",
";",
"if",
"(",
"a",
"==",
"null",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Unknown switch: \"",
"+",
"s",
")",
";",
"}",
"}",
"else",
"{",
"a",
"=",
"null",
";",
"ret",
".",
"add",
"(",
"s",
")",
";",
"}",
"if",
"(",
"a",
"!=",
"null",
")",
"{",
"if",
"(",
"a",
".",
"isSwitch",
")",
"{",
"a",
".",
"setField",
"(",
"\"true\"",
")",
";",
"}",
"else",
"{",
"if",
"(",
"i",
"+",
"1",
">=",
"args",
".",
"length",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Missing parameter for: \"",
"+",
"s",
")",
";",
"}",
"if",
"(",
"a",
".",
"isCatchAll",
"(",
")",
")",
"{",
"final",
"List",
"<",
"String",
">",
"ca",
"=",
"Colls",
".",
"list",
"(",
")",
";",
"for",
"(",
"++",
"i",
";",
"i",
"<",
"args",
".",
"length",
";",
"++",
"i",
")",
"{",
"ca",
".",
"add",
"(",
"args",
"[",
"i",
"]",
")",
";",
"}",
"a",
".",
"setCatchAll",
"(",
"ca",
")",
";",
"}",
"else",
"{",
"++",
"i",
";",
"a",
".",
"setField",
"(",
"args",
"[",
"i",
"]",
")",
";",
"}",
"}",
"a",
".",
"setPresent",
"(",
")",
";",
"}",
"}",
"for",
"(",
"final",
"Arg",
"a",
":",
"allArgs",
")",
"{",
"if",
"(",
"!",
"a",
".",
"isOk",
"(",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Missing mandatory argument: \"",
"+",
"a",
")",
";",
"}",
"}",
"return",
"ret",
";",
"}"
] | Parses command line arguments.
@param args
Array of arguments, like the ones provided by
{@code void main(String[] args)}
@param objs
One or more objects with annotated public fields.
@return A {@code List} containing all unparsed arguments (i.e. arguments
that are no switches)
@throws IOException
if a parsing error occurred.
@see CmdArgument | [
"Parses",
"command",
"line",
"arguments",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/cmd/CmdLineParser.java#L312-L390 |
164,040 | rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Utils.java | Utils.readUntil | public final static int readUntil(final StringBuilder out, final String in, final int start, final char end)
{
int pos = start;
while (pos < in.length())
{
final char ch = in.charAt(pos);
if (ch == '\\' && pos + 1 < in.length())
{
pos = escape(out, in.charAt(pos + 1), pos);
}
else
{
if (ch == end)
{
break;
}
out.append(ch);
}
pos++;
}
return (pos == in.length()) ? -1 : pos;
} | java | public final static int readUntil(final StringBuilder out, final String in, final int start, final char end)
{
int pos = start;
while (pos < in.length())
{
final char ch = in.charAt(pos);
if (ch == '\\' && pos + 1 < in.length())
{
pos = escape(out, in.charAt(pos + 1), pos);
}
else
{
if (ch == end)
{
break;
}
out.append(ch);
}
pos++;
}
return (pos == in.length()) ? -1 : pos;
} | [
"public",
"final",
"static",
"int",
"readUntil",
"(",
"final",
"StringBuilder",
"out",
",",
"final",
"String",
"in",
",",
"final",
"int",
"start",
",",
"final",
"char",
"end",
")",
"{",
"int",
"pos",
"=",
"start",
";",
"while",
"(",
"pos",
"<",
"in",
".",
"length",
"(",
")",
")",
"{",
"final",
"char",
"ch",
"=",
"in",
".",
"charAt",
"(",
"pos",
")",
";",
"if",
"(",
"ch",
"==",
"'",
"'",
"&&",
"pos",
"+",
"1",
"<",
"in",
".",
"length",
"(",
")",
")",
"{",
"pos",
"=",
"escape",
"(",
"out",
",",
"in",
".",
"charAt",
"(",
"pos",
"+",
"1",
")",
",",
"pos",
")",
";",
"}",
"else",
"{",
"if",
"(",
"ch",
"==",
"end",
")",
"{",
"break",
";",
"}",
"out",
".",
"append",
"(",
"ch",
")",
";",
"}",
"pos",
"++",
";",
"}",
"return",
"(",
"pos",
"==",
"in",
".",
"length",
"(",
")",
")",
"?",
"-",
"1",
":",
"pos",
";",
"}"
] | Reads characters until the 'end' character is encountered.
@param out
The StringBuilder to write to.
@param in
The Input String.
@param start
Starting position.
@param end
End characters.
@return The new position or -1 if no 'end' char was found. | [
"Reads",
"characters",
"until",
"the",
"end",
"character",
"is",
"encountered",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Utils.java#L159-L181 |
164,041 | rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Utils.java | Utils.readMdLink | public final static int readMdLink(final StringBuilder out, final String in, final int start)
{
int pos = start;
int counter = 1;
while (pos < in.length())
{
final char ch = in.charAt(pos);
if (ch == '\\' && pos + 1 < in.length())
{
pos = escape(out, in.charAt(pos + 1), pos);
}
else
{
boolean endReached = false;
switch (ch)
{
case '(':
counter++;
break;
case ' ':
if (counter == 1)
{
endReached = true;
}
break;
case ')':
counter--;
if (counter == 0)
{
endReached = true;
}
break;
}
if (endReached)
{
break;
}
out.append(ch);
}
pos++;
}
return (pos == in.length()) ? -1 : pos;
} | java | public final static int readMdLink(final StringBuilder out, final String in, final int start)
{
int pos = start;
int counter = 1;
while (pos < in.length())
{
final char ch = in.charAt(pos);
if (ch == '\\' && pos + 1 < in.length())
{
pos = escape(out, in.charAt(pos + 1), pos);
}
else
{
boolean endReached = false;
switch (ch)
{
case '(':
counter++;
break;
case ' ':
if (counter == 1)
{
endReached = true;
}
break;
case ')':
counter--;
if (counter == 0)
{
endReached = true;
}
break;
}
if (endReached)
{
break;
}
out.append(ch);
}
pos++;
}
return (pos == in.length()) ? -1 : pos;
} | [
"public",
"final",
"static",
"int",
"readMdLink",
"(",
"final",
"StringBuilder",
"out",
",",
"final",
"String",
"in",
",",
"final",
"int",
"start",
")",
"{",
"int",
"pos",
"=",
"start",
";",
"int",
"counter",
"=",
"1",
";",
"while",
"(",
"pos",
"<",
"in",
".",
"length",
"(",
")",
")",
"{",
"final",
"char",
"ch",
"=",
"in",
".",
"charAt",
"(",
"pos",
")",
";",
"if",
"(",
"ch",
"==",
"'",
"'",
"&&",
"pos",
"+",
"1",
"<",
"in",
".",
"length",
"(",
")",
")",
"{",
"pos",
"=",
"escape",
"(",
"out",
",",
"in",
".",
"charAt",
"(",
"pos",
"+",
"1",
")",
",",
"pos",
")",
";",
"}",
"else",
"{",
"boolean",
"endReached",
"=",
"false",
";",
"switch",
"(",
"ch",
")",
"{",
"case",
"'",
"'",
":",
"counter",
"++",
";",
"break",
";",
"case",
"'",
"'",
":",
"if",
"(",
"counter",
"==",
"1",
")",
"{",
"endReached",
"=",
"true",
";",
"}",
"break",
";",
"case",
"'",
"'",
":",
"counter",
"--",
";",
"if",
"(",
"counter",
"==",
"0",
")",
"{",
"endReached",
"=",
"true",
";",
"}",
"break",
";",
"}",
"if",
"(",
"endReached",
")",
"{",
"break",
";",
"}",
"out",
".",
"append",
"(",
"ch",
")",
";",
"}",
"pos",
"++",
";",
"}",
"return",
"(",
"pos",
"==",
"in",
".",
"length",
"(",
")",
")",
"?",
"-",
"1",
":",
"pos",
";",
"}"
] | Reads a markdown link.
@param out
The StringBuilder to write to.
@param in
Input String.
@param start
Starting position.
@return The new position or -1 if this is no valid markdown link. | [
"Reads",
"a",
"markdown",
"link",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Utils.java#L194-L237 |
164,042 | rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Utils.java | Utils.readMdLinkId | public final static int readMdLinkId(final StringBuilder out, final String in, final int start)
{
int pos = start;
int counter = 1;
while (pos < in.length())
{
final char ch = in.charAt(pos);
boolean endReached = false;
switch (ch)
{
case '\n':
out.append(' ');
break;
case '[':
counter++;
out.append(ch);
break;
case ']':
counter--;
if (counter == 0)
{
endReached = true;
}
else
{
out.append(ch);
}
break;
default:
out.append(ch);
break;
}
if (endReached)
{
break;
}
pos++;
}
return (pos == in.length()) ? -1 : pos;
} | java | public final static int readMdLinkId(final StringBuilder out, final String in, final int start)
{
int pos = start;
int counter = 1;
while (pos < in.length())
{
final char ch = in.charAt(pos);
boolean endReached = false;
switch (ch)
{
case '\n':
out.append(' ');
break;
case '[':
counter++;
out.append(ch);
break;
case ']':
counter--;
if (counter == 0)
{
endReached = true;
}
else
{
out.append(ch);
}
break;
default:
out.append(ch);
break;
}
if (endReached)
{
break;
}
pos++;
}
return (pos == in.length()) ? -1 : pos;
} | [
"public",
"final",
"static",
"int",
"readMdLinkId",
"(",
"final",
"StringBuilder",
"out",
",",
"final",
"String",
"in",
",",
"final",
"int",
"start",
")",
"{",
"int",
"pos",
"=",
"start",
";",
"int",
"counter",
"=",
"1",
";",
"while",
"(",
"pos",
"<",
"in",
".",
"length",
"(",
")",
")",
"{",
"final",
"char",
"ch",
"=",
"in",
".",
"charAt",
"(",
"pos",
")",
";",
"boolean",
"endReached",
"=",
"false",
";",
"switch",
"(",
"ch",
")",
"{",
"case",
"'",
"'",
":",
"out",
".",
"append",
"(",
"'",
"'",
")",
";",
"break",
";",
"case",
"'",
"'",
":",
"counter",
"++",
";",
"out",
".",
"append",
"(",
"ch",
")",
";",
"break",
";",
"case",
"'",
"'",
":",
"counter",
"--",
";",
"if",
"(",
"counter",
"==",
"0",
")",
"{",
"endReached",
"=",
"true",
";",
"}",
"else",
"{",
"out",
".",
"append",
"(",
"ch",
")",
";",
"}",
"break",
";",
"default",
":",
"out",
".",
"append",
"(",
"ch",
")",
";",
"break",
";",
"}",
"if",
"(",
"endReached",
")",
"{",
"break",
";",
"}",
"pos",
"++",
";",
"}",
"return",
"(",
"pos",
"==",
"in",
".",
"length",
"(",
")",
")",
"?",
"-",
"1",
":",
"pos",
";",
"}"
] | Reads a markdown link ID.
@param out
The StringBuilder to write to.
@param in
Input String.
@param start
Starting position.
@return The new position or -1 if this is no valid markdown link ID. | [
"Reads",
"a",
"markdown",
"link",
"ID",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Utils.java#L250-L290 |
164,043 | rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Utils.java | Utils.readXMLUntil | public final static int readXMLUntil(final StringBuilder out, final String in, final int start, final char... end)
{
int pos = start;
boolean inString = false;
char stringChar = 0;
while (pos < in.length())
{
final char ch = in.charAt(pos);
if (inString)
{
if (ch == '\\')
{
out.append(ch);
pos++;
if (pos < in.length())
{
out.append(ch);
pos++;
}
continue;
}
if (ch == stringChar)
{
inString = false;
out.append(ch);
pos++;
continue;
}
}
switch (ch)
{
case '"':
case '\'':
inString = true;
stringChar = ch;
break;
}
if (!inString)
{
boolean endReached = false;
for (int n = 0; n < end.length; n++)
{
if (ch == end[n])
{
endReached = true;
break;
}
}
if (endReached)
{
break;
}
}
out.append(ch);
pos++;
}
return (pos == in.length()) ? -1 : pos;
} | java | public final static int readXMLUntil(final StringBuilder out, final String in, final int start, final char... end)
{
int pos = start;
boolean inString = false;
char stringChar = 0;
while (pos < in.length())
{
final char ch = in.charAt(pos);
if (inString)
{
if (ch == '\\')
{
out.append(ch);
pos++;
if (pos < in.length())
{
out.append(ch);
pos++;
}
continue;
}
if (ch == stringChar)
{
inString = false;
out.append(ch);
pos++;
continue;
}
}
switch (ch)
{
case '"':
case '\'':
inString = true;
stringChar = ch;
break;
}
if (!inString)
{
boolean endReached = false;
for (int n = 0; n < end.length; n++)
{
if (ch == end[n])
{
endReached = true;
break;
}
}
if (endReached)
{
break;
}
}
out.append(ch);
pos++;
}
return (pos == in.length()) ? -1 : pos;
} | [
"public",
"final",
"static",
"int",
"readXMLUntil",
"(",
"final",
"StringBuilder",
"out",
",",
"final",
"String",
"in",
",",
"final",
"int",
"start",
",",
"final",
"char",
"...",
"end",
")",
"{",
"int",
"pos",
"=",
"start",
";",
"boolean",
"inString",
"=",
"false",
";",
"char",
"stringChar",
"=",
"0",
";",
"while",
"(",
"pos",
"<",
"in",
".",
"length",
"(",
")",
")",
"{",
"final",
"char",
"ch",
"=",
"in",
".",
"charAt",
"(",
"pos",
")",
";",
"if",
"(",
"inString",
")",
"{",
"if",
"(",
"ch",
"==",
"'",
"'",
")",
"{",
"out",
".",
"append",
"(",
"ch",
")",
";",
"pos",
"++",
";",
"if",
"(",
"pos",
"<",
"in",
".",
"length",
"(",
")",
")",
"{",
"out",
".",
"append",
"(",
"ch",
")",
";",
"pos",
"++",
";",
"}",
"continue",
";",
"}",
"if",
"(",
"ch",
"==",
"stringChar",
")",
"{",
"inString",
"=",
"false",
";",
"out",
".",
"append",
"(",
"ch",
")",
";",
"pos",
"++",
";",
"continue",
";",
"}",
"}",
"switch",
"(",
"ch",
")",
"{",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"inString",
"=",
"true",
";",
"stringChar",
"=",
"ch",
";",
"break",
";",
"}",
"if",
"(",
"!",
"inString",
")",
"{",
"boolean",
"endReached",
"=",
"false",
";",
"for",
"(",
"int",
"n",
"=",
"0",
";",
"n",
"<",
"end",
".",
"length",
";",
"n",
"++",
")",
"{",
"if",
"(",
"ch",
"==",
"end",
"[",
"n",
"]",
")",
"{",
"endReached",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"endReached",
")",
"{",
"break",
";",
"}",
"}",
"out",
".",
"append",
"(",
"ch",
")",
";",
"pos",
"++",
";",
"}",
"return",
"(",
"pos",
"==",
"in",
".",
"length",
"(",
")",
")",
"?",
"-",
"1",
":",
"pos",
";",
"}"
] | Reads characters until any 'end' character is encountered, ignoring
escape sequences.
@param out
The StringBuilder to write to.
@param in
The Input String.
@param start
Starting position.
@param end
End characters.
@return The new position or -1 if no 'end' char was found. | [
"Reads",
"characters",
"until",
"any",
"end",
"character",
"is",
"encountered",
"ignoring",
"escape",
"sequences",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Utils.java#L377-L435 |
164,044 | rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Utils.java | Utils.appendCode | public final static void appendCode(final StringBuilder out, final String in, final int start, final int end)
{
for (int i = start; i < end; i++)
{
final char c;
switch (c = in.charAt(i))
{
case '&':
out.append("&");
break;
case '<':
out.append("<");
break;
case '>':
out.append(">");
break;
default:
out.append(c);
break;
}
}
} | java | public final static void appendCode(final StringBuilder out, final String in, final int start, final int end)
{
for (int i = start; i < end; i++)
{
final char c;
switch (c = in.charAt(i))
{
case '&':
out.append("&");
break;
case '<':
out.append("<");
break;
case '>':
out.append(">");
break;
default:
out.append(c);
break;
}
}
} | [
"public",
"final",
"static",
"void",
"appendCode",
"(",
"final",
"StringBuilder",
"out",
",",
"final",
"String",
"in",
",",
"final",
"int",
"start",
",",
"final",
"int",
"end",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"start",
";",
"i",
"<",
"end",
";",
"i",
"++",
")",
"{",
"final",
"char",
"c",
";",
"switch",
"(",
"c",
"=",
"in",
".",
"charAt",
"(",
"i",
")",
")",
"{",
"case",
"'",
"'",
":",
"out",
".",
"append",
"(",
"\"&\"",
")",
";",
"break",
";",
"case",
"'",
"'",
":",
"out",
".",
"append",
"(",
"\"<\"",
")",
";",
"break",
";",
"case",
"'",
"'",
":",
"out",
".",
"append",
"(",
"\">\"",
")",
";",
"break",
";",
"default",
":",
"out",
".",
"append",
"(",
"c",
")",
";",
"break",
";",
"}",
"}",
"}"
] | Appends the given string encoding special HTML characters.
@param out
The StringBuilder to write to.
@param in
Input String.
@param start
Input String starting position.
@param end
Input String end position. | [
"Appends",
"the",
"given",
"string",
"encoding",
"special",
"HTML",
"characters",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Utils.java#L449-L470 |
164,045 | rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Utils.java | Utils.appendDecEntity | public final static void appendDecEntity(final StringBuilder out, final char value)
{
out.append("&#");
out.append((int)value);
out.append(';');
} | java | public final static void appendDecEntity(final StringBuilder out, final char value)
{
out.append("&#");
out.append((int)value);
out.append(';');
} | [
"public",
"final",
"static",
"void",
"appendDecEntity",
"(",
"final",
"StringBuilder",
"out",
",",
"final",
"char",
"value",
")",
"{",
"out",
".",
"append",
"(",
"\"&#\"",
")",
";",
"out",
".",
"append",
"(",
"(",
"int",
")",
"value",
")",
";",
"out",
".",
"append",
"(",
"'",
"'",
")",
";",
"}"
] | Append the given char as a decimal HTML entity.
@param out
The StringBuilder to write to.
@param value
The character. | [
"Append",
"the",
"given",
"char",
"as",
"a",
"decimal",
"HTML",
"entity",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Utils.java#L522-L527 |
164,046 | rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Utils.java | Utils.codeEncode | public final static void codeEncode(final StringBuilder out, final String value, final int offset)
{
for (int i = offset; i < value.length(); i++)
{
final char c = value.charAt(i);
switch (c)
{
case '&':
out.append("&");
break;
case '<':
out.append("<");
break;
case '>':
out.append(">");
break;
default:
out.append(c);
}
}
} | java | public final static void codeEncode(final StringBuilder out, final String value, final int offset)
{
for (int i = offset; i < value.length(); i++)
{
final char c = value.charAt(i);
switch (c)
{
case '&':
out.append("&");
break;
case '<':
out.append("<");
break;
case '>':
out.append(">");
break;
default:
out.append(c);
}
}
} | [
"public",
"final",
"static",
"void",
"codeEncode",
"(",
"final",
"StringBuilder",
"out",
",",
"final",
"String",
"value",
",",
"final",
"int",
"offset",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"offset",
";",
"i",
"<",
"value",
".",
"length",
"(",
")",
";",
"i",
"++",
")",
"{",
"final",
"char",
"c",
"=",
"value",
".",
"charAt",
"(",
"i",
")",
";",
"switch",
"(",
"c",
")",
"{",
"case",
"'",
"'",
":",
"out",
".",
"append",
"(",
"\"&\"",
")",
";",
"break",
";",
"case",
"'",
"'",
":",
"out",
".",
"append",
"(",
"\"<\"",
")",
";",
"break",
";",
"case",
"'",
"'",
":",
"out",
".",
"append",
"(",
"\">\"",
")",
";",
"break",
";",
"default",
":",
"out",
".",
"append",
"(",
"c",
")",
";",
"}",
"}",
"}"
] | Appends the given string to the given StringBuilder, replacing '&',
'<' and '>' by their respective HTML entities.
@param out
The StringBuilder to append to.
@param value
The string to append.
@param offset
The character offset into value from where to start | [
"Appends",
"the",
"given",
"string",
"to",
"the",
"given",
"StringBuilder",
"replacing",
"&",
";",
"<",
";",
"and",
">",
";",
"by",
"their",
"respective",
"HTML",
"entities",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Utils.java#L743-L763 |
164,047 | rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Line.java | Line.countCharsStart | private int countCharsStart(final char ch, final boolean allowSpaces)
{
int count = 0;
for (int i = 0; i < this.value.length(); i++)
{
final char c = this.value.charAt(i);
if (c == ' ' && allowSpaces)
{
continue;
}
if (c == ch)
{
count++;
}
else
{
break;
}
}
return count;
} | java | private int countCharsStart(final char ch, final boolean allowSpaces)
{
int count = 0;
for (int i = 0; i < this.value.length(); i++)
{
final char c = this.value.charAt(i);
if (c == ' ' && allowSpaces)
{
continue;
}
if (c == ch)
{
count++;
}
else
{
break;
}
}
return count;
} | [
"private",
"int",
"countCharsStart",
"(",
"final",
"char",
"ch",
",",
"final",
"boolean",
"allowSpaces",
")",
"{",
"int",
"count",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"value",
".",
"length",
"(",
")",
";",
"i",
"++",
")",
"{",
"final",
"char",
"c",
"=",
"this",
".",
"value",
".",
"charAt",
"(",
"i",
")",
";",
"if",
"(",
"c",
"==",
"'",
"'",
"&&",
"allowSpaces",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"c",
"==",
"ch",
")",
"{",
"count",
"++",
";",
"}",
"else",
"{",
"break",
";",
"}",
"}",
"return",
"count",
";",
"}"
] | Counts the amount of 'ch' at the start of this line optionally ignoring
spaces.
@param ch
The char to count.
@param allowSpaces
Whether to allow spaces or not
@return Number of characters found.
@since 0.12 | [
"Counts",
"the",
"amount",
"of",
"ch",
"at",
"the",
"start",
"of",
"this",
"line",
"optionally",
"ignoring",
"spaces",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Line.java#L247-L267 |
164,048 | iwgang/SimplifySpan | library/src/main/java/cn/iwgang/simplifyspan/SimplifySpanBuild.java | SimplifySpanBuild.append | public SimplifySpanBuild append(String text) {
if (TextUtils.isEmpty(text)) return this;
mNormalSizeText.append(text);
mStringBuilder.append(text);
return this;
} | java | public SimplifySpanBuild append(String text) {
if (TextUtils.isEmpty(text)) return this;
mNormalSizeText.append(text);
mStringBuilder.append(text);
return this;
} | [
"public",
"SimplifySpanBuild",
"append",
"(",
"String",
"text",
")",
"{",
"if",
"(",
"TextUtils",
".",
"isEmpty",
"(",
"text",
")",
")",
"return",
"this",
";",
"mNormalSizeText",
".",
"append",
"(",
"text",
")",
";",
"mStringBuilder",
".",
"append",
"(",
"text",
")",
";",
"return",
"this",
";",
"}"
] | append normal text
@param text normal text
@return SimplifySpanBuild | [
"append",
"normal",
"text"
] | 34e917cd5497215c8abc07b3d8df187949967283 | https://github.com/iwgang/SimplifySpan/blob/34e917cd5497215c8abc07b3d8df187949967283/library/src/main/java/cn/iwgang/simplifyspan/SimplifySpanBuild.java#L191-L197 |
164,049 | iwgang/SimplifySpan | library/src/main/java/cn/iwgang/simplifyspan/SimplifySpanBuild.java | SimplifySpanBuild.appendMultiClickable | public SimplifySpanBuild appendMultiClickable(SpecialClickableUnit specialClickableUnit, Object... specialUnitOrStrings) {
processMultiClickableSpecialUnit(false, specialClickableUnit, specialUnitOrStrings);
return this;
} | java | public SimplifySpanBuild appendMultiClickable(SpecialClickableUnit specialClickableUnit, Object... specialUnitOrStrings) {
processMultiClickableSpecialUnit(false, specialClickableUnit, specialUnitOrStrings);
return this;
} | [
"public",
"SimplifySpanBuild",
"appendMultiClickable",
"(",
"SpecialClickableUnit",
"specialClickableUnit",
",",
"Object",
"...",
"specialUnitOrStrings",
")",
"{",
"processMultiClickableSpecialUnit",
"(",
"false",
",",
"specialClickableUnit",
",",
"specialUnitOrStrings",
")",
";",
"return",
"this",
";",
"}"
] | append multi clickable SpecialUnit or String
@param specialClickableUnit SpecialClickableUnit
@param specialUnitOrStrings Unit Or String
@return | [
"append",
"multi",
"clickable",
"SpecialUnit",
"or",
"String"
] | 34e917cd5497215c8abc07b3d8df187949967283 | https://github.com/iwgang/SimplifySpan/blob/34e917cd5497215c8abc07b3d8df187949967283/library/src/main/java/cn/iwgang/simplifyspan/SimplifySpanBuild.java#L240-L243 |
164,050 | erizet/SignalA | SignalA/src/main/java/com/zsoft/signala/Hubs/HubProxy.java | HubProxy.Invoke | @Override
public void Invoke(final String method, JSONArray args,
HubInvokeCallback callback) {
if (method == null)
{
throw new IllegalArgumentException("method");
}
if (args == null)
{
throw new IllegalArgumentException("args");
}
final String callbackId = mConnection.RegisterCallback(callback);
HubInvocation hubData = new HubInvocation(mHubName, method, args, callbackId);
String value = hubData.Serialize();
mConnection.Send(value, new SendCallback()
{
@Override
public void OnSent(CharSequence messageSent) {
Log.v(TAG, "Invoke of " + method + "sent to " + mHubName);
// callback.OnSent() ??!?!?
}
@Override
public void OnError(Exception ex) {
// TODO Cancel the callback
Log.e(TAG, "Failed to invoke " + method + "on " + mHubName);
mConnection.RemoveCallback(callbackId);
// callback.OnError() ?!?!?
}
});
} | java | @Override
public void Invoke(final String method, JSONArray args,
HubInvokeCallback callback) {
if (method == null)
{
throw new IllegalArgumentException("method");
}
if (args == null)
{
throw new IllegalArgumentException("args");
}
final String callbackId = mConnection.RegisterCallback(callback);
HubInvocation hubData = new HubInvocation(mHubName, method, args, callbackId);
String value = hubData.Serialize();
mConnection.Send(value, new SendCallback()
{
@Override
public void OnSent(CharSequence messageSent) {
Log.v(TAG, "Invoke of " + method + "sent to " + mHubName);
// callback.OnSent() ??!?!?
}
@Override
public void OnError(Exception ex) {
// TODO Cancel the callback
Log.e(TAG, "Failed to invoke " + method + "on " + mHubName);
mConnection.RemoveCallback(callbackId);
// callback.OnError() ?!?!?
}
});
} | [
"@",
"Override",
"public",
"void",
"Invoke",
"(",
"final",
"String",
"method",
",",
"JSONArray",
"args",
",",
"HubInvokeCallback",
"callback",
")",
"{",
"if",
"(",
"method",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"method\"",
")",
";",
"}",
"if",
"(",
"args",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"args\"",
")",
";",
"}",
"final",
"String",
"callbackId",
"=",
"mConnection",
".",
"RegisterCallback",
"(",
"callback",
")",
";",
"HubInvocation",
"hubData",
"=",
"new",
"HubInvocation",
"(",
"mHubName",
",",
"method",
",",
"args",
",",
"callbackId",
")",
";",
"String",
"value",
"=",
"hubData",
".",
"Serialize",
"(",
")",
";",
"mConnection",
".",
"Send",
"(",
"value",
",",
"new",
"SendCallback",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"OnSent",
"(",
"CharSequence",
"messageSent",
")",
"{",
"Log",
".",
"v",
"(",
"TAG",
",",
"\"Invoke of \"",
"+",
"method",
"+",
"\"sent to \"",
"+",
"mHubName",
")",
";",
"// callback.OnSent() ??!?!?",
"}",
"@",
"Override",
"public",
"void",
"OnError",
"(",
"Exception",
"ex",
")",
"{",
"// TODO Cancel the callback",
"Log",
".",
"e",
"(",
"TAG",
",",
"\"Failed to invoke \"",
"+",
"method",
"+",
"\"on \"",
"+",
"mHubName",
")",
";",
"mConnection",
".",
"RemoveCallback",
"(",
"callbackId",
")",
";",
"// callback.OnError() ?!?!?",
"}",
"}",
")",
";",
"}"
] | Executes a method on the server asynchronously | [
"Executes",
"a",
"method",
"on",
"the",
"server",
"asynchronously"
] | d33bf49dbcf7249f826c5dbb3411cfe4f5d97dd4 | https://github.com/erizet/SignalA/blob/d33bf49dbcf7249f826c5dbb3411cfe4f5d97dd4/SignalA/src/main/java/com/zsoft/signala/Hubs/HubProxy.java#L34-L70 |
164,051 | Doctoror/ParticlesDrawable | library/src/main/java/com/doctoror/particlesdrawable/util/LineColorResolver.java | LineColorResolver.resolveLineAlpha | @IntRange(from = 0, to = OPAQUE)
private static int resolveLineAlpha(
@IntRange(from = 0, to = OPAQUE) final int sceneAlpha,
final float maxDistance,
final float distance) {
final float alphaPercent = 1f - distance / maxDistance;
final int alpha = (int) ((float) OPAQUE * alphaPercent);
return alpha * sceneAlpha / OPAQUE;
} | java | @IntRange(from = 0, to = OPAQUE)
private static int resolveLineAlpha(
@IntRange(from = 0, to = OPAQUE) final int sceneAlpha,
final float maxDistance,
final float distance) {
final float alphaPercent = 1f - distance / maxDistance;
final int alpha = (int) ((float) OPAQUE * alphaPercent);
return alpha * sceneAlpha / OPAQUE;
} | [
"@",
"IntRange",
"(",
"from",
"=",
"0",
",",
"to",
"=",
"OPAQUE",
")",
"private",
"static",
"int",
"resolveLineAlpha",
"(",
"@",
"IntRange",
"(",
"from",
"=",
"0",
",",
"to",
"=",
"OPAQUE",
")",
"final",
"int",
"sceneAlpha",
",",
"final",
"float",
"maxDistance",
",",
"final",
"float",
"distance",
")",
"{",
"final",
"float",
"alphaPercent",
"=",
"1f",
"-",
"distance",
"/",
"maxDistance",
";",
"final",
"int",
"alpha",
"=",
"(",
"int",
")",
"(",
"(",
"float",
")",
"OPAQUE",
"*",
"alphaPercent",
")",
";",
"return",
"alpha",
"*",
"sceneAlpha",
"/",
"OPAQUE",
";",
"}"
] | Resolves line alpha based on distance comparing to max distance.
Where alpha is close to 0 for maxDistance, and close to 1 to 0 distance.
@param distance line length
@param maxDistance max line length
@return line alpha | [
"Resolves",
"line",
"alpha",
"based",
"on",
"distance",
"comparing",
"to",
"max",
"distance",
".",
"Where",
"alpha",
"is",
"close",
"to",
"0",
"for",
"maxDistance",
"and",
"close",
"to",
"1",
"to",
"0",
"distance",
"."
] | 97ab510936692b5cf47822df78dd455f5e4b7ddf | https://github.com/Doctoror/ParticlesDrawable/blob/97ab510936692b5cf47822df78dd455f5e4b7ddf/library/src/main/java/com/doctoror/particlesdrawable/util/LineColorResolver.java#L36-L44 |
164,052 | Doctoror/ParticlesDrawable | library/src/main/java/com/doctoror/particlesdrawable/engine/ParticleGenerator.java | ParticleGenerator.applyFreshParticleOnScreen | void applyFreshParticleOnScreen(
@NonNull final Scene scene,
final int position
) {
final int w = scene.getWidth();
final int h = scene.getHeight();
if (w == 0 || h == 0) {
throw new IllegalStateException(
"Cannot generate particles if scene width or height is 0");
}
final double direction = Math.toRadians(random.nextInt(360));
final float dCos = (float) Math.cos(direction);
final float dSin = (float) Math.sin(direction);
final float x = random.nextInt(w);
final float y = random.nextInt(h);
final float speedFactor = newRandomIndividualParticleSpeedFactor();
final float radius = newRandomIndividualParticleRadius(scene);
scene.setParticleData(
position,
x,
y,
dCos,
dSin,
radius,
speedFactor);
} | java | void applyFreshParticleOnScreen(
@NonNull final Scene scene,
final int position
) {
final int w = scene.getWidth();
final int h = scene.getHeight();
if (w == 0 || h == 0) {
throw new IllegalStateException(
"Cannot generate particles if scene width or height is 0");
}
final double direction = Math.toRadians(random.nextInt(360));
final float dCos = (float) Math.cos(direction);
final float dSin = (float) Math.sin(direction);
final float x = random.nextInt(w);
final float y = random.nextInt(h);
final float speedFactor = newRandomIndividualParticleSpeedFactor();
final float radius = newRandomIndividualParticleRadius(scene);
scene.setParticleData(
position,
x,
y,
dCos,
dSin,
radius,
speedFactor);
} | [
"void",
"applyFreshParticleOnScreen",
"(",
"@",
"NonNull",
"final",
"Scene",
"scene",
",",
"final",
"int",
"position",
")",
"{",
"final",
"int",
"w",
"=",
"scene",
".",
"getWidth",
"(",
")",
";",
"final",
"int",
"h",
"=",
"scene",
".",
"getHeight",
"(",
")",
";",
"if",
"(",
"w",
"==",
"0",
"||",
"h",
"==",
"0",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Cannot generate particles if scene width or height is 0\"",
")",
";",
"}",
"final",
"double",
"direction",
"=",
"Math",
".",
"toRadians",
"(",
"random",
".",
"nextInt",
"(",
"360",
")",
")",
";",
"final",
"float",
"dCos",
"=",
"(",
"float",
")",
"Math",
".",
"cos",
"(",
"direction",
")",
";",
"final",
"float",
"dSin",
"=",
"(",
"float",
")",
"Math",
".",
"sin",
"(",
"direction",
")",
";",
"final",
"float",
"x",
"=",
"random",
".",
"nextInt",
"(",
"w",
")",
";",
"final",
"float",
"y",
"=",
"random",
".",
"nextInt",
"(",
"h",
")",
";",
"final",
"float",
"speedFactor",
"=",
"newRandomIndividualParticleSpeedFactor",
"(",
")",
";",
"final",
"float",
"radius",
"=",
"newRandomIndividualParticleRadius",
"(",
"scene",
")",
";",
"scene",
".",
"setParticleData",
"(",
"position",
",",
"x",
",",
"y",
",",
"dCos",
",",
"dSin",
",",
"radius",
",",
"speedFactor",
")",
";",
"}"
] | Set new point coordinates somewhere on screen and apply new direction
@param position the point position to apply new values to | [
"Set",
"new",
"point",
"coordinates",
"somewhere",
"on",
"screen",
"and",
"apply",
"new",
"direction"
] | 97ab510936692b5cf47822df78dd455f5e4b7ddf | https://github.com/Doctoror/ParticlesDrawable/blob/97ab510936692b5cf47822df78dd455f5e4b7ddf/library/src/main/java/com/doctoror/particlesdrawable/engine/ParticleGenerator.java#L56-L83 |
164,053 | Doctoror/ParticlesDrawable | library/src/main/java/com/doctoror/particlesdrawable/engine/ParticleGenerator.java | ParticleGenerator.applyFreshParticleOffScreen | void applyFreshParticleOffScreen(
@NonNull final Scene scene,
final int position) {
final int w = scene.getWidth();
final int h = scene.getHeight();
if (w == 0 || h == 0) {
throw new IllegalStateException(
"Cannot generate particles if scene width or height is 0");
}
float x = random.nextInt(w);
float y = random.nextInt(h);
// The offset to make when creating point of out bounds
final short offset = (short) (scene.getParticleRadiusMin() + scene.getLineLength());
// Point angle range
final float startAngle;
float endAngle;
// Make random offset and calulate angles so that the direction of travel will always be
// towards our View
switch (random.nextInt(4)) {
case 0:
// offset to left
x = (short) -offset;
startAngle = angleDeg(pcc, pcc, x, y);
endAngle = angleDeg(pcc, h - pcc, x, y);
break;
case 1:
// offset to top
y = (short) -offset;
startAngle = angleDeg(w - pcc, pcc, x, y);
endAngle = angleDeg(pcc, pcc, x, y);
break;
case 2:
// offset to right
x = (short) (w + offset);
startAngle = angleDeg(w - pcc, h - pcc, x, y);
endAngle = angleDeg(w - pcc, pcc, x, y);
break;
case 3:
// offset to bottom
y = (short) (h + offset);
startAngle = angleDeg(pcc, h - pcc, x, y);
endAngle = angleDeg(w - pcc, h - pcc, x, y);
break;
default:
throw new IllegalArgumentException("Supplied value out of range");
}
if (endAngle < startAngle) {
endAngle += 360;
}
// Get random angle from angle range
final float randomAngleInRange = startAngle + (random
.nextInt((int) Math.abs(endAngle - startAngle)));
final double direction = Math.toRadians(randomAngleInRange);
final float dCos = (float) Math.cos(direction);
final float dSin = (float) Math.sin(direction);
final float speedFactor = newRandomIndividualParticleSpeedFactor();
final float radius = newRandomIndividualParticleRadius(scene);
scene.setParticleData(
position,
x,
y,
dCos,
dSin,
radius,
speedFactor);
} | java | void applyFreshParticleOffScreen(
@NonNull final Scene scene,
final int position) {
final int w = scene.getWidth();
final int h = scene.getHeight();
if (w == 0 || h == 0) {
throw new IllegalStateException(
"Cannot generate particles if scene width or height is 0");
}
float x = random.nextInt(w);
float y = random.nextInt(h);
// The offset to make when creating point of out bounds
final short offset = (short) (scene.getParticleRadiusMin() + scene.getLineLength());
// Point angle range
final float startAngle;
float endAngle;
// Make random offset and calulate angles so that the direction of travel will always be
// towards our View
switch (random.nextInt(4)) {
case 0:
// offset to left
x = (short) -offset;
startAngle = angleDeg(pcc, pcc, x, y);
endAngle = angleDeg(pcc, h - pcc, x, y);
break;
case 1:
// offset to top
y = (short) -offset;
startAngle = angleDeg(w - pcc, pcc, x, y);
endAngle = angleDeg(pcc, pcc, x, y);
break;
case 2:
// offset to right
x = (short) (w + offset);
startAngle = angleDeg(w - pcc, h - pcc, x, y);
endAngle = angleDeg(w - pcc, pcc, x, y);
break;
case 3:
// offset to bottom
y = (short) (h + offset);
startAngle = angleDeg(pcc, h - pcc, x, y);
endAngle = angleDeg(w - pcc, h - pcc, x, y);
break;
default:
throw new IllegalArgumentException("Supplied value out of range");
}
if (endAngle < startAngle) {
endAngle += 360;
}
// Get random angle from angle range
final float randomAngleInRange = startAngle + (random
.nextInt((int) Math.abs(endAngle - startAngle)));
final double direction = Math.toRadians(randomAngleInRange);
final float dCos = (float) Math.cos(direction);
final float dSin = (float) Math.sin(direction);
final float speedFactor = newRandomIndividualParticleSpeedFactor();
final float radius = newRandomIndividualParticleRadius(scene);
scene.setParticleData(
position,
x,
y,
dCos,
dSin,
radius,
speedFactor);
} | [
"void",
"applyFreshParticleOffScreen",
"(",
"@",
"NonNull",
"final",
"Scene",
"scene",
",",
"final",
"int",
"position",
")",
"{",
"final",
"int",
"w",
"=",
"scene",
".",
"getWidth",
"(",
")",
";",
"final",
"int",
"h",
"=",
"scene",
".",
"getHeight",
"(",
")",
";",
"if",
"(",
"w",
"==",
"0",
"||",
"h",
"==",
"0",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Cannot generate particles if scene width or height is 0\"",
")",
";",
"}",
"float",
"x",
"=",
"random",
".",
"nextInt",
"(",
"w",
")",
";",
"float",
"y",
"=",
"random",
".",
"nextInt",
"(",
"h",
")",
";",
"// The offset to make when creating point of out bounds",
"final",
"short",
"offset",
"=",
"(",
"short",
")",
"(",
"scene",
".",
"getParticleRadiusMin",
"(",
")",
"+",
"scene",
".",
"getLineLength",
"(",
")",
")",
";",
"// Point angle range",
"final",
"float",
"startAngle",
";",
"float",
"endAngle",
";",
"// Make random offset and calulate angles so that the direction of travel will always be",
"// towards our View",
"switch",
"(",
"random",
".",
"nextInt",
"(",
"4",
")",
")",
"{",
"case",
"0",
":",
"// offset to left",
"x",
"=",
"(",
"short",
")",
"-",
"offset",
";",
"startAngle",
"=",
"angleDeg",
"(",
"pcc",
",",
"pcc",
",",
"x",
",",
"y",
")",
";",
"endAngle",
"=",
"angleDeg",
"(",
"pcc",
",",
"h",
"-",
"pcc",
",",
"x",
",",
"y",
")",
";",
"break",
";",
"case",
"1",
":",
"// offset to top",
"y",
"=",
"(",
"short",
")",
"-",
"offset",
";",
"startAngle",
"=",
"angleDeg",
"(",
"w",
"-",
"pcc",
",",
"pcc",
",",
"x",
",",
"y",
")",
";",
"endAngle",
"=",
"angleDeg",
"(",
"pcc",
",",
"pcc",
",",
"x",
",",
"y",
")",
";",
"break",
";",
"case",
"2",
":",
"// offset to right",
"x",
"=",
"(",
"short",
")",
"(",
"w",
"+",
"offset",
")",
";",
"startAngle",
"=",
"angleDeg",
"(",
"w",
"-",
"pcc",
",",
"h",
"-",
"pcc",
",",
"x",
",",
"y",
")",
";",
"endAngle",
"=",
"angleDeg",
"(",
"w",
"-",
"pcc",
",",
"pcc",
",",
"x",
",",
"y",
")",
";",
"break",
";",
"case",
"3",
":",
"// offset to bottom",
"y",
"=",
"(",
"short",
")",
"(",
"h",
"+",
"offset",
")",
";",
"startAngle",
"=",
"angleDeg",
"(",
"pcc",
",",
"h",
"-",
"pcc",
",",
"x",
",",
"y",
")",
";",
"endAngle",
"=",
"angleDeg",
"(",
"w",
"-",
"pcc",
",",
"h",
"-",
"pcc",
",",
"x",
",",
"y",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Supplied value out of range\"",
")",
";",
"}",
"if",
"(",
"endAngle",
"<",
"startAngle",
")",
"{",
"endAngle",
"+=",
"360",
";",
"}",
"// Get random angle from angle range",
"final",
"float",
"randomAngleInRange",
"=",
"startAngle",
"+",
"(",
"random",
".",
"nextInt",
"(",
"(",
"int",
")",
"Math",
".",
"abs",
"(",
"endAngle",
"-",
"startAngle",
")",
")",
")",
";",
"final",
"double",
"direction",
"=",
"Math",
".",
"toRadians",
"(",
"randomAngleInRange",
")",
";",
"final",
"float",
"dCos",
"=",
"(",
"float",
")",
"Math",
".",
"cos",
"(",
"direction",
")",
";",
"final",
"float",
"dSin",
"=",
"(",
"float",
")",
"Math",
".",
"sin",
"(",
"direction",
")",
";",
"final",
"float",
"speedFactor",
"=",
"newRandomIndividualParticleSpeedFactor",
"(",
")",
";",
"final",
"float",
"radius",
"=",
"newRandomIndividualParticleRadius",
"(",
"scene",
")",
";",
"scene",
".",
"setParticleData",
"(",
"position",
",",
"x",
",",
"y",
",",
"dCos",
",",
"dSin",
",",
"radius",
",",
"speedFactor",
")",
";",
"}"
] | Set new particle coordinates somewhere off screen and apply new direction towards the screen
@param position the particle position to apply new values to | [
"Set",
"new",
"particle",
"coordinates",
"somewhere",
"off",
"screen",
"and",
"apply",
"new",
"direction",
"towards",
"the",
"screen"
] | 97ab510936692b5cf47822df78dd455f5e4b7ddf | https://github.com/Doctoror/ParticlesDrawable/blob/97ab510936692b5cf47822df78dd455f5e4b7ddf/library/src/main/java/com/doctoror/particlesdrawable/engine/ParticleGenerator.java#L90-L167 |
164,054 | Doctoror/ParticlesDrawable | library/src/main/java/com/doctoror/particlesdrawable/engine/ParticleGenerator.java | ParticleGenerator.angleDeg | private static float angleDeg(final float ax, final float ay,
final float bx, final float by) {
final double angleRad = Math.atan2(ay - by, ax - bx);
double angle = Math.toDegrees(angleRad);
if (angleRad < 0) {
angle += 360;
}
return (float) angle;
} | java | private static float angleDeg(final float ax, final float ay,
final float bx, final float by) {
final double angleRad = Math.atan2(ay - by, ax - bx);
double angle = Math.toDegrees(angleRad);
if (angleRad < 0) {
angle += 360;
}
return (float) angle;
} | [
"private",
"static",
"float",
"angleDeg",
"(",
"final",
"float",
"ax",
",",
"final",
"float",
"ay",
",",
"final",
"float",
"bx",
",",
"final",
"float",
"by",
")",
"{",
"final",
"double",
"angleRad",
"=",
"Math",
".",
"atan2",
"(",
"ay",
"-",
"by",
",",
"ax",
"-",
"bx",
")",
";",
"double",
"angle",
"=",
"Math",
".",
"toDegrees",
"(",
"angleRad",
")",
";",
"if",
"(",
"angleRad",
"<",
"0",
")",
"{",
"angle",
"+=",
"360",
";",
"}",
"return",
"(",
"float",
")",
"angle",
";",
"}"
] | Returns angle in degrees between two points
@param ax x of the point 1
@param ay y of the point 1
@param bx x of the point 2
@param by y of the point 2
@return angle in degrees between two points | [
"Returns",
"angle",
"in",
"degrees",
"between",
"two",
"points"
] | 97ab510936692b5cf47822df78dd455f5e4b7ddf | https://github.com/Doctoror/ParticlesDrawable/blob/97ab510936692b5cf47822df78dd455f5e4b7ddf/library/src/main/java/com/doctoror/particlesdrawable/engine/ParticleGenerator.java#L178-L186 |
164,055 | Doctoror/ParticlesDrawable | library/src/main/java/com/doctoror/particlesdrawable/engine/ParticleGenerator.java | ParticleGenerator.newRandomIndividualParticleRadius | private float newRandomIndividualParticleRadius(@NonNull final SceneConfiguration scene) {
return scene.getParticleRadiusMin() == scene.getParticleRadiusMax() ?
scene.getParticleRadiusMin() : scene.getParticleRadiusMin() + (random.nextInt(
(int) ((scene.getParticleRadiusMax() - scene.getParticleRadiusMin()) * 100f)))
/ 100f;
} | java | private float newRandomIndividualParticleRadius(@NonNull final SceneConfiguration scene) {
return scene.getParticleRadiusMin() == scene.getParticleRadiusMax() ?
scene.getParticleRadiusMin() : scene.getParticleRadiusMin() + (random.nextInt(
(int) ((scene.getParticleRadiusMax() - scene.getParticleRadiusMin()) * 100f)))
/ 100f;
} | [
"private",
"float",
"newRandomIndividualParticleRadius",
"(",
"@",
"NonNull",
"final",
"SceneConfiguration",
"scene",
")",
"{",
"return",
"scene",
".",
"getParticleRadiusMin",
"(",
")",
"==",
"scene",
".",
"getParticleRadiusMax",
"(",
")",
"?",
"scene",
".",
"getParticleRadiusMin",
"(",
")",
":",
"scene",
".",
"getParticleRadiusMin",
"(",
")",
"+",
"(",
"random",
".",
"nextInt",
"(",
"(",
"int",
")",
"(",
"(",
"scene",
".",
"getParticleRadiusMax",
"(",
")",
"-",
"scene",
".",
"getParticleRadiusMin",
"(",
")",
")",
"*",
"100f",
")",
")",
")",
"/",
"100f",
";",
"}"
] | Generates new individual particle radius based on min and max radius setting.
@return new particle radius | [
"Generates",
"new",
"individual",
"particle",
"radius",
"based",
"on",
"min",
"and",
"max",
"radius",
"setting",
"."
] | 97ab510936692b5cf47822df78dd455f5e4b7ddf | https://github.com/Doctoror/ParticlesDrawable/blob/97ab510936692b5cf47822df78dd455f5e4b7ddf/library/src/main/java/com/doctoror/particlesdrawable/engine/ParticleGenerator.java#L203-L208 |
164,056 | Doctoror/ParticlesDrawable | library/src/main/java/com/doctoror/particlesdrawable/util/DistanceResolver.java | DistanceResolver.distance | public static float distance(final float ax, final float ay,
final float bx, final float by) {
return (float) Math.sqrt(
(ax - bx) * (ax - bx) +
(ay - by) * (ay - by)
);
} | java | public static float distance(final float ax, final float ay,
final float bx, final float by) {
return (float) Math.sqrt(
(ax - bx) * (ax - bx) +
(ay - by) * (ay - by)
);
} | [
"public",
"static",
"float",
"distance",
"(",
"final",
"float",
"ax",
",",
"final",
"float",
"ay",
",",
"final",
"float",
"bx",
",",
"final",
"float",
"by",
")",
"{",
"return",
"(",
"float",
")",
"Math",
".",
"sqrt",
"(",
"(",
"ax",
"-",
"bx",
")",
"*",
"(",
"ax",
"-",
"bx",
")",
"+",
"(",
"ay",
"-",
"by",
")",
"*",
"(",
"ay",
"-",
"by",
")",
")",
";",
"}"
] | Calculates the distance between two points
@return distance between two points | [
"Calculates",
"the",
"distance",
"between",
"two",
"points"
] | 97ab510936692b5cf47822df78dd455f5e4b7ddf | https://github.com/Doctoror/ParticlesDrawable/blob/97ab510936692b5cf47822df78dd455f5e4b7ddf/library/src/main/java/com/doctoror/particlesdrawable/util/DistanceResolver.java#L28-L34 |
164,057 | ajoberstar/gradle-git | src/main/groovy/org/ajoberstar/gradle/git/auth/BasicPasswordCredentials.java | BasicPasswordCredentials.toGrgit | public Credentials toGrgit() {
if (username != null && password != null) {
return new Credentials(username, password);
} else {
return null;
}
} | java | public Credentials toGrgit() {
if (username != null && password != null) {
return new Credentials(username, password);
} else {
return null;
}
} | [
"public",
"Credentials",
"toGrgit",
"(",
")",
"{",
"if",
"(",
"username",
"!=",
"null",
"&&",
"password",
"!=",
"null",
")",
"{",
"return",
"new",
"Credentials",
"(",
"username",
",",
"password",
")",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] | Converts to credentials for use in Grgit.
@return {@code null} if both username and password are {@code null},
otherwise returns credentials in Grgit format. | [
"Converts",
"to",
"credentials",
"for",
"use",
"in",
"Grgit",
"."
] | 03b08b9f8dd2b2ff0ee9228906a6e9781b85ec79 | https://github.com/ajoberstar/gradle-git/blob/03b08b9f8dd2b2ff0ee9228906a6e9781b85ec79/src/main/groovy/org/ajoberstar/gradle/git/auth/BasicPasswordCredentials.java#L87-L93 |
164,058 | f2prateek/dart | dart-sample/app/src/main/java/com/f2prateek/dart/example/MainActivity.java | MainActivity.onSampleActivityCTAClick | @OnClick(R.id.navigateToSampleActivity)
public void onSampleActivityCTAClick() {
StringParcel parcel1 = new StringParcel("Andy");
StringParcel parcel2 = new StringParcel("Tony");
List<StringParcel> parcelList = new ArrayList<>();
parcelList.add(parcel1);
parcelList.add(parcel2);
SparseArray<StringParcel> parcelSparseArray = new SparseArray<>();
parcelSparseArray.put(0, parcel1);
parcelSparseArray.put(2, parcel2);
Intent intent = HensonNavigator.gotoSampleActivity(this)
.defaultKeyExtra("defaultKeyExtra")
.extraInt(4)
.extraListParcelable(parcelList)
.extraParcel(parcel1)
.extraParcelable(ComplexParcelable.random())
.extraSparseArrayParcelable(parcelSparseArray)
.extraString("a string")
.build();
startActivity(intent);
} | java | @OnClick(R.id.navigateToSampleActivity)
public void onSampleActivityCTAClick() {
StringParcel parcel1 = new StringParcel("Andy");
StringParcel parcel2 = new StringParcel("Tony");
List<StringParcel> parcelList = new ArrayList<>();
parcelList.add(parcel1);
parcelList.add(parcel2);
SparseArray<StringParcel> parcelSparseArray = new SparseArray<>();
parcelSparseArray.put(0, parcel1);
parcelSparseArray.put(2, parcel2);
Intent intent = HensonNavigator.gotoSampleActivity(this)
.defaultKeyExtra("defaultKeyExtra")
.extraInt(4)
.extraListParcelable(parcelList)
.extraParcel(parcel1)
.extraParcelable(ComplexParcelable.random())
.extraSparseArrayParcelable(parcelSparseArray)
.extraString("a string")
.build();
startActivity(intent);
} | [
"@",
"OnClick",
"(",
"R",
".",
"id",
".",
"navigateToSampleActivity",
")",
"public",
"void",
"onSampleActivityCTAClick",
"(",
")",
"{",
"StringParcel",
"parcel1",
"=",
"new",
"StringParcel",
"(",
"\"Andy\"",
")",
";",
"StringParcel",
"parcel2",
"=",
"new",
"StringParcel",
"(",
"\"Tony\"",
")",
";",
"List",
"<",
"StringParcel",
">",
"parcelList",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"parcelList",
".",
"add",
"(",
"parcel1",
")",
";",
"parcelList",
".",
"add",
"(",
"parcel2",
")",
";",
"SparseArray",
"<",
"StringParcel",
">",
"parcelSparseArray",
"=",
"new",
"SparseArray",
"<>",
"(",
")",
";",
"parcelSparseArray",
".",
"put",
"(",
"0",
",",
"parcel1",
")",
";",
"parcelSparseArray",
".",
"put",
"(",
"2",
",",
"parcel2",
")",
";",
"Intent",
"intent",
"=",
"HensonNavigator",
".",
"gotoSampleActivity",
"(",
"this",
")",
".",
"defaultKeyExtra",
"(",
"\"defaultKeyExtra\"",
")",
".",
"extraInt",
"(",
"4",
")",
".",
"extraListParcelable",
"(",
"parcelList",
")",
".",
"extraParcel",
"(",
"parcel1",
")",
".",
"extraParcelable",
"(",
"ComplexParcelable",
".",
"random",
"(",
")",
")",
".",
"extraSparseArrayParcelable",
"(",
"parcelSparseArray",
")",
".",
"extraString",
"(",
"\"a string\"",
")",
".",
"build",
"(",
")",
";",
"startActivity",
"(",
"intent",
")",
";",
"}"
] | Launch Sample Activity residing in the same module | [
"Launch",
"Sample",
"Activity",
"residing",
"in",
"the",
"same",
"module"
] | 7163b1b148e5141817975ae7dad99d58a8589aeb | https://github.com/f2prateek/dart/blob/7163b1b148e5141817975ae7dad99d58a8589aeb/dart-sample/app/src/main/java/com/f2prateek/dart/example/MainActivity.java#L42-L66 |
164,059 | f2prateek/dart | dart-sample/app/src/main/java/com/f2prateek/dart/example/MainActivity.java | MainActivity.onNavigationServiceCTAClick | @OnClick(R.id.navigateToModule1Service)
public void onNavigationServiceCTAClick() {
Intent intentService = HensonNavigator.gotoModule1Service(this)
.stringExtra("foo")
.build();
startService(intentService);
} | java | @OnClick(R.id.navigateToModule1Service)
public void onNavigationServiceCTAClick() {
Intent intentService = HensonNavigator.gotoModule1Service(this)
.stringExtra("foo")
.build();
startService(intentService);
} | [
"@",
"OnClick",
"(",
"R",
".",
"id",
".",
"navigateToModule1Service",
")",
"public",
"void",
"onNavigationServiceCTAClick",
"(",
")",
"{",
"Intent",
"intentService",
"=",
"HensonNavigator",
".",
"gotoModule1Service",
"(",
"this",
")",
".",
"stringExtra",
"(",
"\"foo\"",
")",
".",
"build",
"(",
")",
";",
"startService",
"(",
"intentService",
")",
";",
"}"
] | Launch Navigation Service residing in the navigation module | [
"Launch",
"Navigation",
"Service",
"residing",
"in",
"the",
"navigation",
"module"
] | 7163b1b148e5141817975ae7dad99d58a8589aeb | https://github.com/f2prateek/dart/blob/7163b1b148e5141817975ae7dad99d58a8589aeb/dart-sample/app/src/main/java/com/f2prateek/dart/example/MainActivity.java#L96-L103 |
164,060 | f2prateek/dart | dart-common/src/main/java/dart/common/util/StringUtil.java | StringUtil.isValidFqcn | public static boolean isValidFqcn(String str) {
if (isNullOrEmpty(str)) {
return false;
}
final String[] parts = str.split("\\.");
if (parts.length < 2) {
return false;
}
for (String part : parts) {
if (!isValidJavaIdentifier(part)) {
return false;
}
}
return true;
} | java | public static boolean isValidFqcn(String str) {
if (isNullOrEmpty(str)) {
return false;
}
final String[] parts = str.split("\\.");
if (parts.length < 2) {
return false;
}
for (String part : parts) {
if (!isValidJavaIdentifier(part)) {
return false;
}
}
return true;
} | [
"public",
"static",
"boolean",
"isValidFqcn",
"(",
"String",
"str",
")",
"{",
"if",
"(",
"isNullOrEmpty",
"(",
"str",
")",
")",
"{",
"return",
"false",
";",
"}",
"final",
"String",
"[",
"]",
"parts",
"=",
"str",
".",
"split",
"(",
"\"\\\\.\"",
")",
";",
"if",
"(",
"parts",
".",
"length",
"<",
"2",
")",
"{",
"return",
"false",
";",
"}",
"for",
"(",
"String",
"part",
":",
"parts",
")",
"{",
"if",
"(",
"!",
"isValidJavaIdentifier",
"(",
"part",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Returns true if the string is a valid Java full qualified class name.
@param str the string to be examined
@return true if str is a valid Java Fqcn | [
"Returns",
"true",
"if",
"the",
"string",
"is",
"a",
"valid",
"Java",
"full",
"qualified",
"class",
"name",
"."
] | 7163b1b148e5141817975ae7dad99d58a8589aeb | https://github.com/f2prateek/dart/blob/7163b1b148e5141817975ae7dad99d58a8589aeb/dart-common/src/main/java/dart/common/util/StringUtil.java#L129-L143 |
164,061 | f2prateek/dart | henson-plugin/src/main/java/dart/henson/plugin/internal/TaskManager.java | TaskManager.createHensonNavigatorGenerationTask | public TaskProvider<GenerateHensonNavigatorTask> createHensonNavigatorGenerationTask(
BaseVariant variant, String hensonNavigatorPackageName, File destinationFolder) {
TaskProvider<GenerateHensonNavigatorTask> generateHensonNavigatorTask =
project
.getTasks()
.register(
"generate" + capitalize(variant.getName()) + "HensonNavigator",
GenerateHensonNavigatorTask.class,
(Action<GenerateHensonNavigatorTask>)
generateHensonNavigatorTask1 -> {
generateHensonNavigatorTask1.hensonNavigatorPackageName =
hensonNavigatorPackageName;
generateHensonNavigatorTask1.destinationFolder = destinationFolder;
generateHensonNavigatorTask1.variant = variant;
generateHensonNavigatorTask1.logger = logger;
generateHensonNavigatorTask1.project = project;
generateHensonNavigatorTask1.hensonNavigatorGenerator =
hensonNavigatorGenerator;
});
return generateHensonNavigatorTask;
} | java | public TaskProvider<GenerateHensonNavigatorTask> createHensonNavigatorGenerationTask(
BaseVariant variant, String hensonNavigatorPackageName, File destinationFolder) {
TaskProvider<GenerateHensonNavigatorTask> generateHensonNavigatorTask =
project
.getTasks()
.register(
"generate" + capitalize(variant.getName()) + "HensonNavigator",
GenerateHensonNavigatorTask.class,
(Action<GenerateHensonNavigatorTask>)
generateHensonNavigatorTask1 -> {
generateHensonNavigatorTask1.hensonNavigatorPackageName =
hensonNavigatorPackageName;
generateHensonNavigatorTask1.destinationFolder = destinationFolder;
generateHensonNavigatorTask1.variant = variant;
generateHensonNavigatorTask1.logger = logger;
generateHensonNavigatorTask1.project = project;
generateHensonNavigatorTask1.hensonNavigatorGenerator =
hensonNavigatorGenerator;
});
return generateHensonNavigatorTask;
} | [
"public",
"TaskProvider",
"<",
"GenerateHensonNavigatorTask",
">",
"createHensonNavigatorGenerationTask",
"(",
"BaseVariant",
"variant",
",",
"String",
"hensonNavigatorPackageName",
",",
"File",
"destinationFolder",
")",
"{",
"TaskProvider",
"<",
"GenerateHensonNavigatorTask",
">",
"generateHensonNavigatorTask",
"=",
"project",
".",
"getTasks",
"(",
")",
".",
"register",
"(",
"\"generate\"",
"+",
"capitalize",
"(",
"variant",
".",
"getName",
"(",
")",
")",
"+",
"\"HensonNavigator\"",
",",
"GenerateHensonNavigatorTask",
".",
"class",
",",
"(",
"Action",
"<",
"GenerateHensonNavigatorTask",
">",
")",
"generateHensonNavigatorTask1",
"->",
"{",
"generateHensonNavigatorTask1",
".",
"hensonNavigatorPackageName",
"=",
"hensonNavigatorPackageName",
";",
"generateHensonNavigatorTask1",
".",
"destinationFolder",
"=",
"destinationFolder",
";",
"generateHensonNavigatorTask1",
".",
"variant",
"=",
"variant",
";",
"generateHensonNavigatorTask1",
".",
"logger",
"=",
"logger",
";",
"generateHensonNavigatorTask1",
".",
"project",
"=",
"project",
";",
"generateHensonNavigatorTask1",
".",
"hensonNavigatorGenerator",
"=",
"hensonNavigatorGenerator",
";",
"}",
")",
";",
"return",
"generateHensonNavigatorTask",
";",
"}"
] | A henson navigator is a class that helps a consumer to consume the navigation api that it
declares in its dependencies. The henson navigator will wrap the intent builders. Thus, a
henson navigator, is driven by consumption of intent builders, whereas the henson classes are
driven by the production of an intent builder.
<p>This task is created per android variant:
<ul>
<li>we scan the variant compile configuration for navigation api dependencies
<li>we generate a henson navigator class for this variant that wraps the intent builders
</ul>
@param variant the variant for which to create a builder.
@param hensonNavigatorPackageName the package name in which we create the class. | [
"A",
"henson",
"navigator",
"is",
"a",
"class",
"that",
"helps",
"a",
"consumer",
"to",
"consume",
"the",
"navigation",
"api",
"that",
"it",
"declares",
"in",
"its",
"dependencies",
".",
"The",
"henson",
"navigator",
"will",
"wrap",
"the",
"intent",
"builders",
".",
"Thus",
"a",
"henson",
"navigator",
"is",
"driven",
"by",
"consumption",
"of",
"intent",
"builders",
"whereas",
"the",
"henson",
"classes",
"are",
"driven",
"by",
"the",
"production",
"of",
"an",
"intent",
"builder",
"."
] | 7163b1b148e5141817975ae7dad99d58a8589aeb | https://github.com/f2prateek/dart/blob/7163b1b148e5141817975ae7dad99d58a8589aeb/henson-plugin/src/main/java/dart/henson/plugin/internal/TaskManager.java#L58-L78 |
164,062 | f2prateek/dart | henson/src/main/java/dart/henson/Bundler.java | Bundler.put | public Bundler put(String key, Bundle value) {
delegate.putBundle(key, value);
return this;
} | java | public Bundler put(String key, Bundle value) {
delegate.putBundle(key, value);
return this;
} | [
"public",
"Bundler",
"put",
"(",
"String",
"key",
",",
"Bundle",
"value",
")",
"{",
"delegate",
".",
"putBundle",
"(",
"key",
",",
"value",
")",
";",
"return",
"this",
";",
"}"
] | Inserts a Bundle value into the mapping of the underlying Bundle, replacing any existing value
for the given key. Either key or value may be null.
@param key a String, or null
@param value a Bundle object, or null
@return this bundler instance to chain method calls | [
"Inserts",
"a",
"Bundle",
"value",
"into",
"the",
"mapping",
"of",
"the",
"underlying",
"Bundle",
"replacing",
"any",
"existing",
"value",
"for",
"the",
"given",
"key",
".",
"Either",
"key",
"or",
"value",
"may",
"be",
"null",
"."
] | 7163b1b148e5141817975ae7dad99d58a8589aeb | https://github.com/f2prateek/dart/blob/7163b1b148e5141817975ae7dad99d58a8589aeb/henson/src/main/java/dart/henson/Bundler.java#L127-L130 |
164,063 | f2prateek/dart | henson/src/main/java/dart/henson/Bundler.java | Bundler.put | public Bundler put(String key, String value) {
delegate.putString(key, value);
return this;
} | java | public Bundler put(String key, String value) {
delegate.putString(key, value);
return this;
} | [
"public",
"Bundler",
"put",
"(",
"String",
"key",
",",
"String",
"value",
")",
"{",
"delegate",
".",
"putString",
"(",
"key",
",",
"value",
")",
";",
"return",
"this",
";",
"}"
] | Inserts a String value into the mapping of the underlying Bundle, replacing any existing value
for the given key. Either key or value may be null.
@param key a String, or null
@param value a String, or null
@return this bundler instance to chain method calls | [
"Inserts",
"a",
"String",
"value",
"into",
"the",
"mapping",
"of",
"the",
"underlying",
"Bundle",
"replacing",
"any",
"existing",
"value",
"for",
"the",
"given",
"key",
".",
"Either",
"key",
"or",
"value",
"may",
"be",
"null",
"."
] | 7163b1b148e5141817975ae7dad99d58a8589aeb | https://github.com/f2prateek/dart/blob/7163b1b148e5141817975ae7dad99d58a8589aeb/henson/src/main/java/dart/henson/Bundler.java#L166-L169 |
164,064 | f2prateek/dart | henson/src/main/java/dart/henson/Bundler.java | Bundler.put | public Bundler put(String key, String[] value) {
delegate.putStringArray(key, value);
return this;
} | java | public Bundler put(String key, String[] value) {
delegate.putStringArray(key, value);
return this;
} | [
"public",
"Bundler",
"put",
"(",
"String",
"key",
",",
"String",
"[",
"]",
"value",
")",
"{",
"delegate",
".",
"putStringArray",
"(",
"key",
",",
"value",
")",
";",
"return",
"this",
";",
"}"
] | Inserts a String array value into the mapping of the underlying Bundle, replacing any existing
value for the given key. Either key or value may be null.
@param key a String, or null
@param value a String array object, or null
@return this bundler instance to chain method calls | [
"Inserts",
"a",
"String",
"array",
"value",
"into",
"the",
"mapping",
"of",
"the",
"underlying",
"Bundle",
"replacing",
"any",
"existing",
"value",
"for",
"the",
"given",
"key",
".",
"Either",
"key",
"or",
"value",
"may",
"be",
"null",
"."
] | 7163b1b148e5141817975ae7dad99d58a8589aeb | https://github.com/f2prateek/dart/blob/7163b1b148e5141817975ae7dad99d58a8589aeb/henson/src/main/java/dart/henson/Bundler.java#L179-L182 |
164,065 | f2prateek/dart | henson/src/main/java/dart/henson/Bundler.java | Bundler.put | public Bundler put(String key, CharSequence value) {
delegate.putCharSequence(key, value);
return this;
} | java | public Bundler put(String key, CharSequence value) {
delegate.putCharSequence(key, value);
return this;
} | [
"public",
"Bundler",
"put",
"(",
"String",
"key",
",",
"CharSequence",
"value",
")",
"{",
"delegate",
".",
"putCharSequence",
"(",
"key",
",",
"value",
")",
";",
"return",
"this",
";",
"}"
] | Inserts a CharSequence value into the mapping of the underlying Bundle, replacing any existing
value for the given key. Either key or value may be null.
@param key a String, or null
@param value a CharSequence, or null
@return this bundler instance to chain method calls | [
"Inserts",
"a",
"CharSequence",
"value",
"into",
"the",
"mapping",
"of",
"the",
"underlying",
"Bundle",
"replacing",
"any",
"existing",
"value",
"for",
"the",
"given",
"key",
".",
"Either",
"key",
"or",
"value",
"may",
"be",
"null",
"."
] | 7163b1b148e5141817975ae7dad99d58a8589aeb | https://github.com/f2prateek/dart/blob/7163b1b148e5141817975ae7dad99d58a8589aeb/henson/src/main/java/dart/henson/Bundler.java#L283-L286 |
164,066 | f2prateek/dart | henson/src/main/java/dart/henson/Bundler.java | Bundler.put | public Bundler put(String key, CharSequence[] value) {
delegate.putCharSequenceArray(key, value);
return this;
} | java | public Bundler put(String key, CharSequence[] value) {
delegate.putCharSequenceArray(key, value);
return this;
} | [
"public",
"Bundler",
"put",
"(",
"String",
"key",
",",
"CharSequence",
"[",
"]",
"value",
")",
"{",
"delegate",
".",
"putCharSequenceArray",
"(",
"key",
",",
"value",
")",
";",
"return",
"this",
";",
"}"
] | Inserts a CharSequence array value into the mapping of the underlying Bundle, replacing any
existing value for the given key. Either key or value may be null.
@param key a String, or null
@param value a CharSequence array object, or null
@return this bundler instance to chain method calls | [
"Inserts",
"a",
"CharSequence",
"array",
"value",
"into",
"the",
"mapping",
"of",
"the",
"underlying",
"Bundle",
"replacing",
"any",
"existing",
"value",
"for",
"the",
"given",
"key",
".",
"Either",
"key",
"or",
"value",
"may",
"be",
"null",
"."
] | 7163b1b148e5141817975ae7dad99d58a8589aeb | https://github.com/f2prateek/dart/blob/7163b1b148e5141817975ae7dad99d58a8589aeb/henson/src/main/java/dart/henson/Bundler.java#L296-L299 |
164,067 | f2prateek/dart | henson/src/main/java/dart/henson/Bundler.java | Bundler.put | public Bundler put(String key, Parcelable value) {
delegate.putParcelable(key, value);
return this;
} | java | public Bundler put(String key, Parcelable value) {
delegate.putParcelable(key, value);
return this;
} | [
"public",
"Bundler",
"put",
"(",
"String",
"key",
",",
"Parcelable",
"value",
")",
"{",
"delegate",
".",
"putParcelable",
"(",
"key",
",",
"value",
")",
";",
"return",
"this",
";",
"}"
] | Inserts a Parcelable value into the mapping of the underlying Bundle, replacing any existing
value for the given key. Either key or value may be null.
@param key a String, or null
@param value a Parcelable object, or null
@return this bundler instance to chain method calls | [
"Inserts",
"a",
"Parcelable",
"value",
"into",
"the",
"mapping",
"of",
"the",
"underlying",
"Bundle",
"replacing",
"any",
"existing",
"value",
"for",
"the",
"given",
"key",
".",
"Either",
"key",
"or",
"value",
"may",
"be",
"null",
"."
] | 7163b1b148e5141817975ae7dad99d58a8589aeb | https://github.com/f2prateek/dart/blob/7163b1b148e5141817975ae7dad99d58a8589aeb/henson/src/main/java/dart/henson/Bundler.java#L348-L351 |
164,068 | f2prateek/dart | henson/src/main/java/dart/henson/Bundler.java | Bundler.put | public Bundler put(String key, Parcelable[] value) {
delegate.putParcelableArray(key, value);
return this;
} | java | public Bundler put(String key, Parcelable[] value) {
delegate.putParcelableArray(key, value);
return this;
} | [
"public",
"Bundler",
"put",
"(",
"String",
"key",
",",
"Parcelable",
"[",
"]",
"value",
")",
"{",
"delegate",
".",
"putParcelableArray",
"(",
"key",
",",
"value",
")",
";",
"return",
"this",
";",
"}"
] | Inserts an array of Parcelable values into the mapping of the underlying Bundle, replacing any
existing value for the given key. Either key or value may be null.
@param key a String, or null
@param value an array of Parcelable objects, or null
@return this bundler instance to chain method calls | [
"Inserts",
"an",
"array",
"of",
"Parcelable",
"values",
"into",
"the",
"mapping",
"of",
"the",
"underlying",
"Bundle",
"replacing",
"any",
"existing",
"value",
"for",
"the",
"given",
"key",
".",
"Either",
"key",
"or",
"value",
"may",
"be",
"null",
"."
] | 7163b1b148e5141817975ae7dad99d58a8589aeb | https://github.com/f2prateek/dart/blob/7163b1b148e5141817975ae7dad99d58a8589aeb/henson/src/main/java/dart/henson/Bundler.java#L361-L364 |
164,069 | f2prateek/dart | henson/src/main/java/dart/henson/Bundler.java | Bundler.put | public Bundler put(String key, Serializable value) {
delegate.putSerializable(key, value);
return this;
} | java | public Bundler put(String key, Serializable value) {
delegate.putSerializable(key, value);
return this;
} | [
"public",
"Bundler",
"put",
"(",
"String",
"key",
",",
"Serializable",
"value",
")",
"{",
"delegate",
".",
"putSerializable",
"(",
"key",
",",
"value",
")",
";",
"return",
"this",
";",
"}"
] | Inserts a Serializable value into the mapping of the underlying Bundle, replacing any existing
value for the given key. Either key or value may be null.
@param key a String, or null
@param value a Serializable object, or null
@return this bundler instance to chain method calls | [
"Inserts",
"a",
"Serializable",
"value",
"into",
"the",
"mapping",
"of",
"the",
"underlying",
"Bundle",
"replacing",
"any",
"existing",
"value",
"for",
"the",
"given",
"key",
".",
"Either",
"key",
"or",
"value",
"may",
"be",
"null",
"."
] | 7163b1b148e5141817975ae7dad99d58a8589aeb | https://github.com/f2prateek/dart/blob/7163b1b148e5141817975ae7dad99d58a8589aeb/henson/src/main/java/dart/henson/Bundler.java#L426-L429 |
164,070 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/HostName.java | HostName.validate | @Override
public void validate() throws HostNameException {
if(parsedHost != null) {
return;
}
if(validationException != null) {
throw validationException;
}
synchronized(this) {
if(parsedHost != null) {
return;
}
if(validationException != null) {
throw validationException;
}
try {
parsedHost = getValidator().validateHost(this);
} catch(HostNameException e) {
validationException = e;
throw e;
}
}
} | java | @Override
public void validate() throws HostNameException {
if(parsedHost != null) {
return;
}
if(validationException != null) {
throw validationException;
}
synchronized(this) {
if(parsedHost != null) {
return;
}
if(validationException != null) {
throw validationException;
}
try {
parsedHost = getValidator().validateHost(this);
} catch(HostNameException e) {
validationException = e;
throw e;
}
}
} | [
"@",
"Override",
"public",
"void",
"validate",
"(",
")",
"throws",
"HostNameException",
"{",
"if",
"(",
"parsedHost",
"!=",
"null",
")",
"{",
"return",
";",
"}",
"if",
"(",
"validationException",
"!=",
"null",
")",
"{",
"throw",
"validationException",
";",
"}",
"synchronized",
"(",
"this",
")",
"{",
"if",
"(",
"parsedHost",
"!=",
"null",
")",
"{",
"return",
";",
"}",
"if",
"(",
"validationException",
"!=",
"null",
")",
"{",
"throw",
"validationException",
";",
"}",
"try",
"{",
"parsedHost",
"=",
"getValidator",
"(",
")",
".",
"validateHost",
"(",
"this",
")",
";",
"}",
"catch",
"(",
"HostNameException",
"e",
")",
"{",
"validationException",
"=",
"e",
";",
"throw",
"e",
";",
"}",
"}",
"}"
] | Validates that this string is a valid host name or IP address, and if not, throws an exception with a descriptive message indicating why it is not.
@throws HostNameException | [
"Validates",
"that",
"this",
"string",
"is",
"a",
"valid",
"host",
"name",
"or",
"IP",
"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/HostName.java#L227-L249 |
164,071 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/HostName.java | HostName.isValid | public boolean isValid() {
if(parsedHost != null) {
return true;
}
if(validationException != null) {
return false;
}
try {
validate();
return true;
} catch(HostNameException e) {
return false;
}
} | java | public boolean isValid() {
if(parsedHost != null) {
return true;
}
if(validationException != null) {
return false;
}
try {
validate();
return true;
} catch(HostNameException e) {
return false;
}
} | [
"public",
"boolean",
"isValid",
"(",
")",
"{",
"if",
"(",
"parsedHost",
"!=",
"null",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"validationException",
"!=",
"null",
")",
"{",
"return",
"false",
";",
"}",
"try",
"{",
"validate",
"(",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"HostNameException",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
] | Returns whether this represents a valid host name or address format.
@return | [
"Returns",
"whether",
"this",
"represents",
"a",
"valid",
"host",
"name",
"or",
"address",
"format",
"."
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/HostName.java#L259-L272 |
164,072 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/HostName.java | HostName.toNormalizedString | @Override
public String toNormalizedString() {
String result = normalizedString;
if(result == null) {
normalizedString = result = toNormalizedString(false);
}
return result;
} | java | @Override
public String toNormalizedString() {
String result = normalizedString;
if(result == null) {
normalizedString = result = toNormalizedString(false);
}
return result;
} | [
"@",
"Override",
"public",
"String",
"toNormalizedString",
"(",
")",
"{",
"String",
"result",
"=",
"normalizedString",
";",
"if",
"(",
"result",
"==",
"null",
")",
"{",
"normalizedString",
"=",
"result",
"=",
"toNormalizedString",
"(",
"false",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Provides a normalized string which is lowercase for host strings, and which is a normalized string for addresses.
@return | [
"Provides",
"a",
"normalized",
"string",
"which",
"is",
"lowercase",
"for",
"host",
"strings",
"and",
"which",
"is",
"a",
"normalized",
"string",
"for",
"addresses",
"."
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/HostName.java#L328-L335 |
164,073 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/HostName.java | HostName.getNormalizedLabels | public String[] getNormalizedLabels() {
if(isValid()) {
return parsedHost.getNormalizedLabels();
}
if(host.length() == 0) {
return new String[0];
}
return new String[] {host};
} | java | public String[] getNormalizedLabels() {
if(isValid()) {
return parsedHost.getNormalizedLabels();
}
if(host.length() == 0) {
return new String[0];
}
return new String[] {host};
} | [
"public",
"String",
"[",
"]",
"getNormalizedLabels",
"(",
")",
"{",
"if",
"(",
"isValid",
"(",
")",
")",
"{",
"return",
"parsedHost",
".",
"getNormalizedLabels",
"(",
")",
";",
"}",
"if",
"(",
"host",
".",
"length",
"(",
")",
"==",
"0",
")",
"{",
"return",
"new",
"String",
"[",
"0",
"]",
";",
"}",
"return",
"new",
"String",
"[",
"]",
"{",
"host",
"}",
";",
"}"
] | Returns an array of normalized strings for this host name instance.
If this represents an IP address, the address segments are separated into the returned array.
If this represents a host name string, the domain name segments are separated into the returned array,
with the top-level domain name (right-most segment) as the last array element.
The individual segment strings are normalized in the same way as {@link #toNormalizedString()}
Ports, service name strings, prefix lengths, and masks are all omitted from the returned array.
@return | [
"Returns",
"an",
"array",
"of",
"normalized",
"strings",
"for",
"this",
"host",
"name",
"instance",
"."
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/HostName.java#L459-L467 |
164,074 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/HostName.java | HostName.matches | public boolean matches(HostName host) {
if(this == host) {
return true;
}
if(isValid()) {
if(host.isValid()) {
if(isAddressString()) {
return host.isAddressString()
&& asAddressString().equals(host.asAddressString())
&& Objects.equals(getPort(), host.getPort())
&& Objects.equals(getService(), host.getService());
}
if(host.isAddressString()) {
return false;
}
String thisHost = parsedHost.getHost();
String otherHost = host.parsedHost.getHost();
if(!thisHost.equals(otherHost)) {
return false;
}
return Objects.equals(parsedHost.getEquivalentPrefixLength(), host.parsedHost.getEquivalentPrefixLength()) &&
Objects.equals(parsedHost.getMask(), host.parsedHost.getMask()) &&
Objects.equals(parsedHost.getPort(), host.parsedHost.getPort()) &&
Objects.equals(parsedHost.getService(), host.parsedHost.getService());
}
return false;
}
return !host.isValid() && toString().equals(host.toString());
} | java | public boolean matches(HostName host) {
if(this == host) {
return true;
}
if(isValid()) {
if(host.isValid()) {
if(isAddressString()) {
return host.isAddressString()
&& asAddressString().equals(host.asAddressString())
&& Objects.equals(getPort(), host.getPort())
&& Objects.equals(getService(), host.getService());
}
if(host.isAddressString()) {
return false;
}
String thisHost = parsedHost.getHost();
String otherHost = host.parsedHost.getHost();
if(!thisHost.equals(otherHost)) {
return false;
}
return Objects.equals(parsedHost.getEquivalentPrefixLength(), host.parsedHost.getEquivalentPrefixLength()) &&
Objects.equals(parsedHost.getMask(), host.parsedHost.getMask()) &&
Objects.equals(parsedHost.getPort(), host.parsedHost.getPort()) &&
Objects.equals(parsedHost.getService(), host.parsedHost.getService());
}
return false;
}
return !host.isValid() && toString().equals(host.toString());
} | [
"public",
"boolean",
"matches",
"(",
"HostName",
"host",
")",
"{",
"if",
"(",
"this",
"==",
"host",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"isValid",
"(",
")",
")",
"{",
"if",
"(",
"host",
".",
"isValid",
"(",
")",
")",
"{",
"if",
"(",
"isAddressString",
"(",
")",
")",
"{",
"return",
"host",
".",
"isAddressString",
"(",
")",
"&&",
"asAddressString",
"(",
")",
".",
"equals",
"(",
"host",
".",
"asAddressString",
"(",
")",
")",
"&&",
"Objects",
".",
"equals",
"(",
"getPort",
"(",
")",
",",
"host",
".",
"getPort",
"(",
")",
")",
"&&",
"Objects",
".",
"equals",
"(",
"getService",
"(",
")",
",",
"host",
".",
"getService",
"(",
")",
")",
";",
"}",
"if",
"(",
"host",
".",
"isAddressString",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"String",
"thisHost",
"=",
"parsedHost",
".",
"getHost",
"(",
")",
";",
"String",
"otherHost",
"=",
"host",
".",
"parsedHost",
".",
"getHost",
"(",
")",
";",
"if",
"(",
"!",
"thisHost",
".",
"equals",
"(",
"otherHost",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"Objects",
".",
"equals",
"(",
"parsedHost",
".",
"getEquivalentPrefixLength",
"(",
")",
",",
"host",
".",
"parsedHost",
".",
"getEquivalentPrefixLength",
"(",
")",
")",
"&&",
"Objects",
".",
"equals",
"(",
"parsedHost",
".",
"getMask",
"(",
")",
",",
"host",
".",
"parsedHost",
".",
"getMask",
"(",
")",
")",
"&&",
"Objects",
".",
"equals",
"(",
"parsedHost",
".",
"getPort",
"(",
")",
",",
"host",
".",
"parsedHost",
".",
"getPort",
"(",
")",
")",
"&&",
"Objects",
".",
"equals",
"(",
"parsedHost",
".",
"getService",
"(",
")",
",",
"host",
".",
"parsedHost",
".",
"getService",
"(",
")",
")",
";",
"}",
"return",
"false",
";",
"}",
"return",
"!",
"host",
".",
"isValid",
"(",
")",
"&&",
"toString",
"(",
")",
".",
"equals",
"(",
"host",
".",
"toString",
"(",
")",
")",
";",
"}"
] | Returns whether the given host matches this one. For hosts to match, they must represent the same addresses or have the same host names.
Hosts are not resolved when matching. Also, hosts must have the same port and service. They must have the same masks if they are host names.
Even if two hosts are invalid, they match if they have the same invalid string.
@param host
@return | [
"Returns",
"whether",
"the",
"given",
"host",
"matches",
"this",
"one",
".",
"For",
"hosts",
"to",
"match",
"they",
"must",
"represent",
"the",
"same",
"addresses",
"or",
"have",
"the",
"same",
"host",
"names",
".",
"Hosts",
"are",
"not",
"resolved",
"when",
"matching",
".",
"Also",
"hosts",
"must",
"have",
"the",
"same",
"port",
"and",
"service",
".",
"They",
"must",
"have",
"the",
"same",
"masks",
"if",
"they",
"are",
"host",
"names",
".",
"Even",
"if",
"two",
"hosts",
"are",
"invalid",
"they",
"match",
"if",
"they",
"have",
"the",
"same",
"invalid",
"string",
"."
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/HostName.java#L495-L523 |
164,075 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/HostName.java | HostName.toAddress | @Override
public IPAddress toAddress() throws UnknownHostException, HostNameException {
IPAddress addr = resolvedAddress;
if(addr == null && !resolvedIsNull) {
//note that validation handles empty address resolution
validate();
synchronized(this) {
addr = resolvedAddress;
if(addr == null && !resolvedIsNull) {
if(parsedHost.isAddressString()) {
addr = parsedHost.asAddress();
resolvedIsNull = (addr == null);
//note there is no need to apply prefix or mask here, it would have been applied to the address already
} else {
String strHost = parsedHost.getHost();
if(strHost.length() == 0 && !validationOptions.emptyIsLoopback) {
addr = null;
resolvedIsNull = true;
} else {
//Note we do not set resolvedIsNull, so we will attempt to resolve again if the previous attempt threw an exception
InetAddress inetAddress = InetAddress.getByName(strHost);
byte bytes[] = inetAddress.getAddress();
Integer networkPrefixLength = parsedHost.getNetworkPrefixLength();
if(networkPrefixLength == null) {
IPAddress mask = parsedHost.getMask();
if(mask != null) {
byte maskBytes[] = mask.getBytes();
if(maskBytes.length != bytes.length) {
throw new HostNameException(host, "ipaddress.error.ipMismatch");
}
for(int i = 0; i < bytes.length; i++) {
bytes[i] &= maskBytes[i];
}
networkPrefixLength = mask.getBlockMaskPrefixLength(true);
}
}
IPAddressStringParameters addressParams = validationOptions.addressOptions;
if(bytes.length == IPv6Address.BYTE_COUNT) {
IPv6AddressCreator creator = addressParams.getIPv6Parameters().getNetwork().getAddressCreator();
addr = creator.createAddressInternal(bytes, networkPrefixLength, null, this); /* address creation */
} else {
IPv4AddressCreator creator = addressParams.getIPv4Parameters().getNetwork().getAddressCreator();
addr = creator.createAddressInternal(bytes, networkPrefixLength, this); /* address creation */
}
}
}
resolvedAddress = addr;
}
}
}
return addr;
} | java | @Override
public IPAddress toAddress() throws UnknownHostException, HostNameException {
IPAddress addr = resolvedAddress;
if(addr == null && !resolvedIsNull) {
//note that validation handles empty address resolution
validate();
synchronized(this) {
addr = resolvedAddress;
if(addr == null && !resolvedIsNull) {
if(parsedHost.isAddressString()) {
addr = parsedHost.asAddress();
resolvedIsNull = (addr == null);
//note there is no need to apply prefix or mask here, it would have been applied to the address already
} else {
String strHost = parsedHost.getHost();
if(strHost.length() == 0 && !validationOptions.emptyIsLoopback) {
addr = null;
resolvedIsNull = true;
} else {
//Note we do not set resolvedIsNull, so we will attempt to resolve again if the previous attempt threw an exception
InetAddress inetAddress = InetAddress.getByName(strHost);
byte bytes[] = inetAddress.getAddress();
Integer networkPrefixLength = parsedHost.getNetworkPrefixLength();
if(networkPrefixLength == null) {
IPAddress mask = parsedHost.getMask();
if(mask != null) {
byte maskBytes[] = mask.getBytes();
if(maskBytes.length != bytes.length) {
throw new HostNameException(host, "ipaddress.error.ipMismatch");
}
for(int i = 0; i < bytes.length; i++) {
bytes[i] &= maskBytes[i];
}
networkPrefixLength = mask.getBlockMaskPrefixLength(true);
}
}
IPAddressStringParameters addressParams = validationOptions.addressOptions;
if(bytes.length == IPv6Address.BYTE_COUNT) {
IPv6AddressCreator creator = addressParams.getIPv6Parameters().getNetwork().getAddressCreator();
addr = creator.createAddressInternal(bytes, networkPrefixLength, null, this); /* address creation */
} else {
IPv4AddressCreator creator = addressParams.getIPv4Parameters().getNetwork().getAddressCreator();
addr = creator.createAddressInternal(bytes, networkPrefixLength, this); /* address creation */
}
}
}
resolvedAddress = addr;
}
}
}
return addr;
} | [
"@",
"Override",
"public",
"IPAddress",
"toAddress",
"(",
")",
"throws",
"UnknownHostException",
",",
"HostNameException",
"{",
"IPAddress",
"addr",
"=",
"resolvedAddress",
";",
"if",
"(",
"addr",
"==",
"null",
"&&",
"!",
"resolvedIsNull",
")",
"{",
"//note that validation handles empty address resolution",
"validate",
"(",
")",
";",
"synchronized",
"(",
"this",
")",
"{",
"addr",
"=",
"resolvedAddress",
";",
"if",
"(",
"addr",
"==",
"null",
"&&",
"!",
"resolvedIsNull",
")",
"{",
"if",
"(",
"parsedHost",
".",
"isAddressString",
"(",
")",
")",
"{",
"addr",
"=",
"parsedHost",
".",
"asAddress",
"(",
")",
";",
"resolvedIsNull",
"=",
"(",
"addr",
"==",
"null",
")",
";",
"//note there is no need to apply prefix or mask here, it would have been applied to the address already",
"}",
"else",
"{",
"String",
"strHost",
"=",
"parsedHost",
".",
"getHost",
"(",
")",
";",
"if",
"(",
"strHost",
".",
"length",
"(",
")",
"==",
"0",
"&&",
"!",
"validationOptions",
".",
"emptyIsLoopback",
")",
"{",
"addr",
"=",
"null",
";",
"resolvedIsNull",
"=",
"true",
";",
"}",
"else",
"{",
"//Note we do not set resolvedIsNull, so we will attempt to resolve again if the previous attempt threw an exception",
"InetAddress",
"inetAddress",
"=",
"InetAddress",
".",
"getByName",
"(",
"strHost",
")",
";",
"byte",
"bytes",
"[",
"]",
"=",
"inetAddress",
".",
"getAddress",
"(",
")",
";",
"Integer",
"networkPrefixLength",
"=",
"parsedHost",
".",
"getNetworkPrefixLength",
"(",
")",
";",
"if",
"(",
"networkPrefixLength",
"==",
"null",
")",
"{",
"IPAddress",
"mask",
"=",
"parsedHost",
".",
"getMask",
"(",
")",
";",
"if",
"(",
"mask",
"!=",
"null",
")",
"{",
"byte",
"maskBytes",
"[",
"]",
"=",
"mask",
".",
"getBytes",
"(",
")",
";",
"if",
"(",
"maskBytes",
".",
"length",
"!=",
"bytes",
".",
"length",
")",
"{",
"throw",
"new",
"HostNameException",
"(",
"host",
",",
"\"ipaddress.error.ipMismatch\"",
")",
";",
"}",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"bytes",
".",
"length",
";",
"i",
"++",
")",
"{",
"bytes",
"[",
"i",
"]",
"&=",
"maskBytes",
"[",
"i",
"]",
";",
"}",
"networkPrefixLength",
"=",
"mask",
".",
"getBlockMaskPrefixLength",
"(",
"true",
")",
";",
"}",
"}",
"IPAddressStringParameters",
"addressParams",
"=",
"validationOptions",
".",
"addressOptions",
";",
"if",
"(",
"bytes",
".",
"length",
"==",
"IPv6Address",
".",
"BYTE_COUNT",
")",
"{",
"IPv6AddressCreator",
"creator",
"=",
"addressParams",
".",
"getIPv6Parameters",
"(",
")",
".",
"getNetwork",
"(",
")",
".",
"getAddressCreator",
"(",
")",
";",
"addr",
"=",
"creator",
".",
"createAddressInternal",
"(",
"bytes",
",",
"networkPrefixLength",
",",
"null",
",",
"this",
")",
";",
"/* address creation */",
"}",
"else",
"{",
"IPv4AddressCreator",
"creator",
"=",
"addressParams",
".",
"getIPv4Parameters",
"(",
")",
".",
"getNetwork",
"(",
")",
".",
"getAddressCreator",
"(",
")",
";",
"addr",
"=",
"creator",
".",
"createAddressInternal",
"(",
"bytes",
",",
"networkPrefixLength",
",",
"this",
")",
";",
"/* address creation */",
"}",
"}",
"}",
"resolvedAddress",
"=",
"addr",
";",
"}",
"}",
"}",
"return",
"addr",
";",
"}"
] | If this represents an ip address, returns that address.
If this represents a host, returns the resolved ip address of that host.
Otherwise, returns null, but only for strings that are considered valid address strings but cannot be converted to address objects.
This method will throw exceptions for invalid formats and failures to resolve the address. The equivalent method {@link #getAddress()} will simply return null rather than throw those exceptions.
If you wish to get the represented address and avoid DNS resolution, use {@link #asAddress()} or {@link #asAddressString()}
@return | [
"If",
"this",
"represents",
"an",
"ip",
"address",
"returns",
"that",
"address",
".",
"If",
"this",
"represents",
"a",
"host",
"returns",
"the",
"resolved",
"ip",
"address",
"of",
"that",
"host",
".",
"Otherwise",
"returns",
"null",
"but",
"only",
"for",
"strings",
"that",
"are",
"considered",
"valid",
"address",
"strings",
"but",
"cannot",
"be",
"converted",
"to",
"address",
"objects",
"."
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/HostName.java#L867-L918 |
164,076 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/mac/MACAddressSection.java | MACAddressSection.iterator | protected Iterator<MACAddress> iterator(MACAddress original) {
MACAddressCreator creator = getAddressCreator();
boolean isSingle = !isMultiple();
return iterator(
isSingle ? original : null,
creator,//using a lambda for this one results in a big performance hit
isSingle ? null : segmentsIterator(),
getNetwork().getPrefixConfiguration().allPrefixedAddressesAreSubnets() ? null : getPrefixLength());
} | java | protected Iterator<MACAddress> iterator(MACAddress original) {
MACAddressCreator creator = getAddressCreator();
boolean isSingle = !isMultiple();
return iterator(
isSingle ? original : null,
creator,//using a lambda for this one results in a big performance hit
isSingle ? null : segmentsIterator(),
getNetwork().getPrefixConfiguration().allPrefixedAddressesAreSubnets() ? null : getPrefixLength());
} | [
"protected",
"Iterator",
"<",
"MACAddress",
">",
"iterator",
"(",
"MACAddress",
"original",
")",
"{",
"MACAddressCreator",
"creator",
"=",
"getAddressCreator",
"(",
")",
";",
"boolean",
"isSingle",
"=",
"!",
"isMultiple",
"(",
")",
";",
"return",
"iterator",
"(",
"isSingle",
"?",
"original",
":",
"null",
",",
"creator",
",",
"//using a lambda for this one results in a big performance hit\r",
"isSingle",
"?",
"null",
":",
"segmentsIterator",
"(",
")",
",",
"getNetwork",
"(",
")",
".",
"getPrefixConfiguration",
"(",
")",
".",
"allPrefixedAddressesAreSubnets",
"(",
")",
"?",
"null",
":",
"getPrefixLength",
"(",
")",
")",
";",
"}"
] | these are the iterators used by MACAddress | [
"these",
"are",
"the",
"iterators",
"used",
"by",
"MACAddress"
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/mac/MACAddressSection.java#L1204-L1212 |
164,077 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/mac/MACAddressSection.java | MACAddressSection.toHexString | @Override
public String toHexString(boolean with0xPrefix) {
String result;
if(hasNoStringCache() || (result = (with0xPrefix ? stringCache.hexStringPrefixed : stringCache.hexString)) == null) {
result = toHexString(with0xPrefix, null);
if(with0xPrefix) {
stringCache.hexStringPrefixed = result;
} else {
stringCache.hexString = result;
}
}
return result;
} | java | @Override
public String toHexString(boolean with0xPrefix) {
String result;
if(hasNoStringCache() || (result = (with0xPrefix ? stringCache.hexStringPrefixed : stringCache.hexString)) == null) {
result = toHexString(with0xPrefix, null);
if(with0xPrefix) {
stringCache.hexStringPrefixed = result;
} else {
stringCache.hexString = result;
}
}
return result;
} | [
"@",
"Override",
"public",
"String",
"toHexString",
"(",
"boolean",
"with0xPrefix",
")",
"{",
"String",
"result",
";",
"if",
"(",
"hasNoStringCache",
"(",
")",
"||",
"(",
"result",
"=",
"(",
"with0xPrefix",
"?",
"stringCache",
".",
"hexStringPrefixed",
":",
"stringCache",
".",
"hexString",
")",
")",
"==",
"null",
")",
"{",
"result",
"=",
"toHexString",
"(",
"with0xPrefix",
",",
"null",
")",
";",
"if",
"(",
"with0xPrefix",
")",
"{",
"stringCache",
".",
"hexStringPrefixed",
"=",
"result",
";",
"}",
"else",
"{",
"stringCache",
".",
"hexString",
"=",
"result",
";",
"}",
"}",
"return",
"result",
";",
"}"
] | Writes this address as a single hexadecimal value with always the exact same number of characters, with or without a preceding 0x prefix. | [
"Writes",
"this",
"address",
"as",
"a",
"single",
"hexadecimal",
"value",
"with",
"always",
"the",
"exact",
"same",
"number",
"of",
"characters",
"with",
"or",
"without",
"a",
"preceding",
"0x",
"prefix",
"."
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/mac/MACAddressSection.java#L1323-L1335 |
164,078 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/mac/MACAddressSection.java | MACAddressSection.toCompressedString | @Override
public String toCompressedString() {
String result;
if(hasNoStringCache() || (result = getStringCache().compressedString) == null) {
getStringCache().compressedString = result = toNormalizedString(MACStringCache.compressedParams);
}
return result;
} | java | @Override
public String toCompressedString() {
String result;
if(hasNoStringCache() || (result = getStringCache().compressedString) == null) {
getStringCache().compressedString = result = toNormalizedString(MACStringCache.compressedParams);
}
return result;
} | [
"@",
"Override",
"public",
"String",
"toCompressedString",
"(",
")",
"{",
"String",
"result",
";",
"if",
"(",
"hasNoStringCache",
"(",
")",
"||",
"(",
"result",
"=",
"getStringCache",
"(",
")",
".",
"compressedString",
")",
"==",
"null",
")",
"{",
"getStringCache",
"(",
")",
".",
"compressedString",
"=",
"result",
"=",
"toNormalizedString",
"(",
"MACStringCache",
".",
"compressedParams",
")",
";",
"}",
"return",
"result",
";",
"}"
] | This produces a shorter string for the address that uses the canonical representation but not using leading zeroes.
Each address has a unique compressed string. | [
"This",
"produces",
"a",
"shorter",
"string",
"for",
"the",
"address",
"that",
"uses",
"the",
"canonical",
"representation",
"but",
"not",
"using",
"leading",
"zeroes",
"."
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/mac/MACAddressSection.java#L1382-L1389 |
164,079 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/mac/MACAddressSection.java | MACAddressSection.toDottedString | public String toDottedString() {
String result = null;
if(hasNoStringCache() || (result = getStringCache().dottedString) == null) {
AddressDivisionGrouping dottedGrouping = getDottedGrouping();
getStringCache().dottedString = result = toNormalizedString(MACStringCache.dottedParams, dottedGrouping);
}
return result;
} | java | public String toDottedString() {
String result = null;
if(hasNoStringCache() || (result = getStringCache().dottedString) == null) {
AddressDivisionGrouping dottedGrouping = getDottedGrouping();
getStringCache().dottedString = result = toNormalizedString(MACStringCache.dottedParams, dottedGrouping);
}
return result;
} | [
"public",
"String",
"toDottedString",
"(",
")",
"{",
"String",
"result",
"=",
"null",
";",
"if",
"(",
"hasNoStringCache",
"(",
")",
"||",
"(",
"result",
"=",
"getStringCache",
"(",
")",
".",
"dottedString",
")",
"==",
"null",
")",
"{",
"AddressDivisionGrouping",
"dottedGrouping",
"=",
"getDottedGrouping",
"(",
")",
";",
"getStringCache",
"(",
")",
".",
"dottedString",
"=",
"result",
"=",
"toNormalizedString",
"(",
"MACStringCache",
".",
"dottedParams",
",",
"dottedGrouping",
")",
";",
"}",
"return",
"result",
";",
"}"
] | This produces the dotted hexadecimal format aaaa.bbbb.cccc | [
"This",
"produces",
"the",
"dotted",
"hexadecimal",
"format",
"aaaa",
".",
"bbbb",
".",
"cccc"
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/mac/MACAddressSection.java#L1394-L1401 |
164,080 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6AddressSegment.java | IPv6AddressSegment.getSplitSegments | public <S extends AddressSegment> void getSplitSegments(S segs[], int index, AddressSegmentCreator<S> creator) {
if(!isMultiple()) {
int bitSizeSplit = IPv6Address.BITS_PER_SEGMENT >>> 1;
Integer myPrefix = getSegmentPrefixLength();
Integer highPrefixBits = getSplitSegmentPrefix(bitSizeSplit, myPrefix, 0);
Integer lowPrefixBits = getSplitSegmentPrefix(bitSizeSplit, myPrefix, 1);
if(index >= 0 && index < segs.length) {
segs[index] = creator.createSegment(highByte(), highPrefixBits);
}
if(++index >= 0 && index < segs.length) {
segs[index] = creator.createSegment(lowByte(), lowPrefixBits);
}
} else {
getSplitSegmentsMultiple(segs, index, creator);
}
} | java | public <S extends AddressSegment> void getSplitSegments(S segs[], int index, AddressSegmentCreator<S> creator) {
if(!isMultiple()) {
int bitSizeSplit = IPv6Address.BITS_PER_SEGMENT >>> 1;
Integer myPrefix = getSegmentPrefixLength();
Integer highPrefixBits = getSplitSegmentPrefix(bitSizeSplit, myPrefix, 0);
Integer lowPrefixBits = getSplitSegmentPrefix(bitSizeSplit, myPrefix, 1);
if(index >= 0 && index < segs.length) {
segs[index] = creator.createSegment(highByte(), highPrefixBits);
}
if(++index >= 0 && index < segs.length) {
segs[index] = creator.createSegment(lowByte(), lowPrefixBits);
}
} else {
getSplitSegmentsMultiple(segs, index, creator);
}
} | [
"public",
"<",
"S",
"extends",
"AddressSegment",
">",
"void",
"getSplitSegments",
"(",
"S",
"segs",
"[",
"]",
",",
"int",
"index",
",",
"AddressSegmentCreator",
"<",
"S",
">",
"creator",
")",
"{",
"if",
"(",
"!",
"isMultiple",
"(",
")",
")",
"{",
"int",
"bitSizeSplit",
"=",
"IPv6Address",
".",
"BITS_PER_SEGMENT",
">>>",
"1",
";",
"Integer",
"myPrefix",
"=",
"getSegmentPrefixLength",
"(",
")",
";",
"Integer",
"highPrefixBits",
"=",
"getSplitSegmentPrefix",
"(",
"bitSizeSplit",
",",
"myPrefix",
",",
"0",
")",
";",
"Integer",
"lowPrefixBits",
"=",
"getSplitSegmentPrefix",
"(",
"bitSizeSplit",
",",
"myPrefix",
",",
"1",
")",
";",
"if",
"(",
"index",
">=",
"0",
"&&",
"index",
"<",
"segs",
".",
"length",
")",
"{",
"segs",
"[",
"index",
"]",
"=",
"creator",
".",
"createSegment",
"(",
"highByte",
"(",
")",
",",
"highPrefixBits",
")",
";",
"}",
"if",
"(",
"++",
"index",
">=",
"0",
"&&",
"index",
"<",
"segs",
".",
"length",
")",
"{",
"segs",
"[",
"index",
"]",
"=",
"creator",
".",
"createSegment",
"(",
"lowByte",
"(",
")",
",",
"lowPrefixBits",
")",
";",
"}",
"}",
"else",
"{",
"getSplitSegmentsMultiple",
"(",
"segs",
",",
"index",
",",
"creator",
")",
";",
"}",
"}"
] | Converts this IPv6 address segment into smaller segments,
copying them into the given array starting at the given index.
If a segment does not fit into the array because the segment index in the array is out of bounds of the array,
then it is not copied.
@param segs
@param index | [
"Converts",
"this",
"IPv6",
"address",
"segment",
"into",
"smaller",
"segments",
"copying",
"them",
"into",
"the",
"given",
"array",
"starting",
"at",
"the",
"given",
"index",
"."
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6AddressSegment.java#L302-L317 |
164,081 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/format/standard/AddressDivisionGrouping.java | AddressDivisionGrouping.containsPrefixBlock | @Override
public boolean containsPrefixBlock(int prefixLength) {
checkSubnet(this, prefixLength);
int divisionCount = getDivisionCount();
int prevBitCount = 0;
for(int i = 0; i < divisionCount; i++) {
AddressDivision division = getDivision(i);
int bitCount = division.getBitCount();
int totalBitCount = bitCount + prevBitCount;
if(prefixLength < totalBitCount) {
int divPrefixLen = Math.max(0, prefixLength - prevBitCount);
if(!division.isPrefixBlock(division.getDivisionValue(), division.getUpperDivisionValue(), divPrefixLen)) {
return false;
}
for(++i; i < divisionCount; i++) {
division = getDivision(i);
if(!division.isFullRange()) {
return false;
}
}
return true;
}
prevBitCount = totalBitCount;
}
return true;
} | java | @Override
public boolean containsPrefixBlock(int prefixLength) {
checkSubnet(this, prefixLength);
int divisionCount = getDivisionCount();
int prevBitCount = 0;
for(int i = 0; i < divisionCount; i++) {
AddressDivision division = getDivision(i);
int bitCount = division.getBitCount();
int totalBitCount = bitCount + prevBitCount;
if(prefixLength < totalBitCount) {
int divPrefixLen = Math.max(0, prefixLength - prevBitCount);
if(!division.isPrefixBlock(division.getDivisionValue(), division.getUpperDivisionValue(), divPrefixLen)) {
return false;
}
for(++i; i < divisionCount; i++) {
division = getDivision(i);
if(!division.isFullRange()) {
return false;
}
}
return true;
}
prevBitCount = totalBitCount;
}
return true;
} | [
"@",
"Override",
"public",
"boolean",
"containsPrefixBlock",
"(",
"int",
"prefixLength",
")",
"{",
"checkSubnet",
"(",
"this",
",",
"prefixLength",
")",
";",
"int",
"divisionCount",
"=",
"getDivisionCount",
"(",
")",
";",
"int",
"prevBitCount",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"divisionCount",
";",
"i",
"++",
")",
"{",
"AddressDivision",
"division",
"=",
"getDivision",
"(",
"i",
")",
";",
"int",
"bitCount",
"=",
"division",
".",
"getBitCount",
"(",
")",
";",
"int",
"totalBitCount",
"=",
"bitCount",
"+",
"prevBitCount",
";",
"if",
"(",
"prefixLength",
"<",
"totalBitCount",
")",
"{",
"int",
"divPrefixLen",
"=",
"Math",
".",
"max",
"(",
"0",
",",
"prefixLength",
"-",
"prevBitCount",
")",
";",
"if",
"(",
"!",
"division",
".",
"isPrefixBlock",
"(",
"division",
".",
"getDivisionValue",
"(",
")",
",",
"division",
".",
"getUpperDivisionValue",
"(",
")",
",",
"divPrefixLen",
")",
")",
"{",
"return",
"false",
";",
"}",
"for",
"(",
"++",
"i",
";",
"i",
"<",
"divisionCount",
";",
"i",
"++",
")",
"{",
"division",
"=",
"getDivision",
"(",
"i",
")",
";",
"if",
"(",
"!",
"division",
".",
"isFullRange",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
"prevBitCount",
"=",
"totalBitCount",
";",
"}",
"return",
"true",
";",
"}"
] | Returns whether the values of this division grouping contain the prefix block for the given prefix length
@param prefixLength
@return | [
"Returns",
"whether",
"the",
"values",
"of",
"this",
"division",
"grouping",
"contain",
"the",
"prefix",
"block",
"for",
"the",
"given",
"prefix",
"length"
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/standard/AddressDivisionGrouping.java#L136-L161 |
164,082 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/format/standard/AddressDivisionGrouping.java | AddressDivisionGrouping.normalizePrefixBoundary | protected static <S extends IPAddressSegment> void normalizePrefixBoundary(
int sectionPrefixBits,
S segments[],
int segmentBitCount,
int segmentByteCount,
BiFunction<S, Integer, S> segProducer) {
//we've already verified segment prefixes in super constructor. We simply need to check the case where the prefix is at a segment boundary,
//whether the network side has the correct prefix
int networkSegmentIndex = getNetworkSegmentIndex(sectionPrefixBits, segmentByteCount, segmentBitCount);
if(networkSegmentIndex >= 0) {
S segment = segments[networkSegmentIndex];
if(!segment.isPrefixed()) {
segments[networkSegmentIndex] = segProducer.apply(segment, segmentBitCount);
}
}
} | java | protected static <S extends IPAddressSegment> void normalizePrefixBoundary(
int sectionPrefixBits,
S segments[],
int segmentBitCount,
int segmentByteCount,
BiFunction<S, Integer, S> segProducer) {
//we've already verified segment prefixes in super constructor. We simply need to check the case where the prefix is at a segment boundary,
//whether the network side has the correct prefix
int networkSegmentIndex = getNetworkSegmentIndex(sectionPrefixBits, segmentByteCount, segmentBitCount);
if(networkSegmentIndex >= 0) {
S segment = segments[networkSegmentIndex];
if(!segment.isPrefixed()) {
segments[networkSegmentIndex] = segProducer.apply(segment, segmentBitCount);
}
}
} | [
"protected",
"static",
"<",
"S",
"extends",
"IPAddressSegment",
">",
"void",
"normalizePrefixBoundary",
"(",
"int",
"sectionPrefixBits",
",",
"S",
"segments",
"[",
"]",
",",
"int",
"segmentBitCount",
",",
"int",
"segmentByteCount",
",",
"BiFunction",
"<",
"S",
",",
"Integer",
",",
"S",
">",
"segProducer",
")",
"{",
"//we've already verified segment prefixes in super constructor. We simply need to check the case where the prefix is at a segment boundary,",
"//whether the network side has the correct prefix",
"int",
"networkSegmentIndex",
"=",
"getNetworkSegmentIndex",
"(",
"sectionPrefixBits",
",",
"segmentByteCount",
",",
"segmentBitCount",
")",
";",
"if",
"(",
"networkSegmentIndex",
">=",
"0",
")",
"{",
"S",
"segment",
"=",
"segments",
"[",
"networkSegmentIndex",
"]",
";",
"if",
"(",
"!",
"segment",
".",
"isPrefixed",
"(",
")",
")",
"{",
"segments",
"[",
"networkSegmentIndex",
"]",
"=",
"segProducer",
".",
"apply",
"(",
"segment",
",",
"segmentBitCount",
")",
";",
"}",
"}",
"}"
] | In the case where the prefix sits at a segment boundary, and the prefix sequence is null - null - 0, this changes to prefix sequence of null - x - 0, where x is segment bit length.
Note: We allow both [null, null, 0] and [null, x, 0] where x is segment length. However, to avoid inconsistencies when doing segment replacements,
and when getting subsections, in the calling constructor we normalize [null, null, 0] to become [null, x, 0].
We need to support [null, x, 0] so that we can create subsections and full addresses ending with [null, x] where x is bit length.
So we defer to that when constructing addresses and sections.
Also note that in our append/appendNetowrk/insert/replace we have special handling for cases like inserting [null] into [null, 8, 0] at index 2.
The straight replace would give [null, 8, null, 0] which is wrong.
In that code we end up with [null, null, 8, 0] by doing a special trick:
We remove the end of [null, 8, 0] and do an append [null, 0] and we'd remove prefix from [null, 8] to get [null, null] and then we'd do another append to get [null, null, null, 0]
The final step is this normalization here that gives [null, null, 8, 0]
However, when users construct AddressDivisionGrouping or IPAddressDivisionGrouping, either one is allowed: [null, null, 0] and [null, x, 0].
Since those objects cannot be further subdivided with getSection/getNetworkSection/getHostSection or grown with appended/inserted/replaced,
there are no inconsistencies introduced, we are simply more user-friendly.
Also note that normalization of AddressDivisionGrouping or IPAddressDivisionGrouping is really not possible without the address creator objects we use for addresses and sections,
that allow us to recreate new segments of the correct type.
@param sectionPrefixBits
@param segments
@param segmentBitCount
@param segmentByteCount
@param segProducer | [
"In",
"the",
"case",
"where",
"the",
"prefix",
"sits",
"at",
"a",
"segment",
"boundary",
"and",
"the",
"prefix",
"sequence",
"is",
"null",
"-",
"null",
"-",
"0",
"this",
"changes",
"to",
"prefix",
"sequence",
"of",
"null",
"-",
"x",
"-",
"0",
"where",
"x",
"is",
"segment",
"bit",
"length",
"."
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/standard/AddressDivisionGrouping.java#L335-L350 |
164,083 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/format/standard/AddressDivisionGrouping.java | AddressDivisionGrouping.fastIncrement | protected static <R extends AddressSection, S extends AddressSegment> R fastIncrement(
R section,
long increment,
AddressCreator<?, R, ?, S> addrCreator,
Supplier<R> lowerProducer,
Supplier<R> upperProducer,
Integer prefixLength) {
if(increment >= 0) {
BigInteger count = section.getCount();
if(count.compareTo(LONG_MAX) <= 0) {
long longCount = count.longValue();
if(longCount > increment) {
if(longCount == increment + 1) {
return upperProducer.get();
}
return incrementRange(section, increment, addrCreator, lowerProducer, prefixLength);
}
BigInteger value = section.getValue();
BigInteger upperValue;
if(value.compareTo(LONG_MAX) <= 0 && (upperValue = section.getUpperValue()).compareTo(LONG_MAX) <= 0) {
return increment(
section,
increment,
addrCreator,
count.longValue(),
value.longValue(),
upperValue.longValue(),
lowerProducer,
upperProducer,
prefixLength);
}
}
} else {
BigInteger value = section.getValue();
if(value.compareTo(LONG_MAX) <= 0) {
return add(lowerProducer.get(), value.longValue(), increment, addrCreator, prefixLength);
}
}
return null;
} | java | protected static <R extends AddressSection, S extends AddressSegment> R fastIncrement(
R section,
long increment,
AddressCreator<?, R, ?, S> addrCreator,
Supplier<R> lowerProducer,
Supplier<R> upperProducer,
Integer prefixLength) {
if(increment >= 0) {
BigInteger count = section.getCount();
if(count.compareTo(LONG_MAX) <= 0) {
long longCount = count.longValue();
if(longCount > increment) {
if(longCount == increment + 1) {
return upperProducer.get();
}
return incrementRange(section, increment, addrCreator, lowerProducer, prefixLength);
}
BigInteger value = section.getValue();
BigInteger upperValue;
if(value.compareTo(LONG_MAX) <= 0 && (upperValue = section.getUpperValue()).compareTo(LONG_MAX) <= 0) {
return increment(
section,
increment,
addrCreator,
count.longValue(),
value.longValue(),
upperValue.longValue(),
lowerProducer,
upperProducer,
prefixLength);
}
}
} else {
BigInteger value = section.getValue();
if(value.compareTo(LONG_MAX) <= 0) {
return add(lowerProducer.get(), value.longValue(), increment, addrCreator, prefixLength);
}
}
return null;
} | [
"protected",
"static",
"<",
"R",
"extends",
"AddressSection",
",",
"S",
"extends",
"AddressSegment",
">",
"R",
"fastIncrement",
"(",
"R",
"section",
",",
"long",
"increment",
",",
"AddressCreator",
"<",
"?",
",",
"R",
",",
"?",
",",
"S",
">",
"addrCreator",
",",
"Supplier",
"<",
"R",
">",
"lowerProducer",
",",
"Supplier",
"<",
"R",
">",
"upperProducer",
",",
"Integer",
"prefixLength",
")",
"{",
"if",
"(",
"increment",
">=",
"0",
")",
"{",
"BigInteger",
"count",
"=",
"section",
".",
"getCount",
"(",
")",
";",
"if",
"(",
"count",
".",
"compareTo",
"(",
"LONG_MAX",
")",
"<=",
"0",
")",
"{",
"long",
"longCount",
"=",
"count",
".",
"longValue",
"(",
")",
";",
"if",
"(",
"longCount",
">",
"increment",
")",
"{",
"if",
"(",
"longCount",
"==",
"increment",
"+",
"1",
")",
"{",
"return",
"upperProducer",
".",
"get",
"(",
")",
";",
"}",
"return",
"incrementRange",
"(",
"section",
",",
"increment",
",",
"addrCreator",
",",
"lowerProducer",
",",
"prefixLength",
")",
";",
"}",
"BigInteger",
"value",
"=",
"section",
".",
"getValue",
"(",
")",
";",
"BigInteger",
"upperValue",
";",
"if",
"(",
"value",
".",
"compareTo",
"(",
"LONG_MAX",
")",
"<=",
"0",
"&&",
"(",
"upperValue",
"=",
"section",
".",
"getUpperValue",
"(",
")",
")",
".",
"compareTo",
"(",
"LONG_MAX",
")",
"<=",
"0",
")",
"{",
"return",
"increment",
"(",
"section",
",",
"increment",
",",
"addrCreator",
",",
"count",
".",
"longValue",
"(",
")",
",",
"value",
".",
"longValue",
"(",
")",
",",
"upperValue",
".",
"longValue",
"(",
")",
",",
"lowerProducer",
",",
"upperProducer",
",",
"prefixLength",
")",
";",
"}",
"}",
"}",
"else",
"{",
"BigInteger",
"value",
"=",
"section",
".",
"getValue",
"(",
")",
";",
"if",
"(",
"value",
".",
"compareTo",
"(",
"LONG_MAX",
")",
"<=",
"0",
")",
"{",
"return",
"add",
"(",
"lowerProducer",
".",
"get",
"(",
")",
",",
"value",
".",
"longValue",
"(",
")",
",",
"increment",
",",
"addrCreator",
",",
"prefixLength",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Handles the cases in which we can use longs rather than BigInteger
@param section
@param increment
@param addrCreator
@param lowerProducer
@param upperProducer
@param prefixLength
@return | [
"Handles",
"the",
"cases",
"in",
"which",
"we",
"can",
"use",
"longs",
"rather",
"than",
"BigInteger"
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/standard/AddressDivisionGrouping.java#L1090-L1129 |
164,084 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/format/util/sql/SQLStringMatcher.java | SQLStringMatcher.getSQLCondition | public StringBuilder getSQLCondition(StringBuilder builder, String columnName) {
String string = networkString.getString();
if(isEntireAddress) {
matchString(builder, columnName, string);
} else {
matchSubString(
builder,
columnName,
networkString.getTrailingSegmentSeparator(),
networkString.getTrailingSeparatorCount() + 1,
string);
}
return builder;
} | java | public StringBuilder getSQLCondition(StringBuilder builder, String columnName) {
String string = networkString.getString();
if(isEntireAddress) {
matchString(builder, columnName, string);
} else {
matchSubString(
builder,
columnName,
networkString.getTrailingSegmentSeparator(),
networkString.getTrailingSeparatorCount() + 1,
string);
}
return builder;
} | [
"public",
"StringBuilder",
"getSQLCondition",
"(",
"StringBuilder",
"builder",
",",
"String",
"columnName",
")",
"{",
"String",
"string",
"=",
"networkString",
".",
"getString",
"(",
")",
";",
"if",
"(",
"isEntireAddress",
")",
"{",
"matchString",
"(",
"builder",
",",
"columnName",
",",
"string",
")",
";",
"}",
"else",
"{",
"matchSubString",
"(",
"builder",
",",
"columnName",
",",
"networkString",
".",
"getTrailingSegmentSeparator",
"(",
")",
",",
"networkString",
".",
"getTrailingSeparatorCount",
"(",
")",
"+",
"1",
",",
"string",
")",
";",
"}",
"return",
"builder",
";",
"}"
] | Get an SQL condition to match this address section representation
@param builder
@param columnName
@return the condition | [
"Get",
"an",
"SQL",
"condition",
"to",
"match",
"this",
"address",
"section",
"representation"
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/util/sql/SQLStringMatcher.java#L53-L66 |
164,085 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/format/AddressDivisionBase.java | AddressDivisionBase.getRadixPower | protected static BigInteger getRadixPower(BigInteger radix, int power) {
long key = (((long) radix.intValue()) << 32) | power;
BigInteger result = radixPowerMap.get(key);
if(result == null) {
if(power == 1) {
result = radix;
} else if((power & 1) == 0) {
BigInteger halfPower = getRadixPower(radix, power >> 1);
result = halfPower.multiply(halfPower);
} else {
BigInteger halfPower = getRadixPower(radix, (power - 1) >> 1);
result = halfPower.multiply(halfPower).multiply(radix);
}
radixPowerMap.put(key, result);
}
return result;
} | java | protected static BigInteger getRadixPower(BigInteger radix, int power) {
long key = (((long) radix.intValue()) << 32) | power;
BigInteger result = radixPowerMap.get(key);
if(result == null) {
if(power == 1) {
result = radix;
} else if((power & 1) == 0) {
BigInteger halfPower = getRadixPower(radix, power >> 1);
result = halfPower.multiply(halfPower);
} else {
BigInteger halfPower = getRadixPower(radix, (power - 1) >> 1);
result = halfPower.multiply(halfPower).multiply(radix);
}
radixPowerMap.put(key, result);
}
return result;
} | [
"protected",
"static",
"BigInteger",
"getRadixPower",
"(",
"BigInteger",
"radix",
",",
"int",
"power",
")",
"{",
"long",
"key",
"=",
"(",
"(",
"(",
"long",
")",
"radix",
".",
"intValue",
"(",
")",
")",
"<<",
"32",
")",
"|",
"power",
";",
"BigInteger",
"result",
"=",
"radixPowerMap",
".",
"get",
"(",
"key",
")",
";",
"if",
"(",
"result",
"==",
"null",
")",
"{",
"if",
"(",
"power",
"==",
"1",
")",
"{",
"result",
"=",
"radix",
";",
"}",
"else",
"if",
"(",
"(",
"power",
"&",
"1",
")",
"==",
"0",
")",
"{",
"BigInteger",
"halfPower",
"=",
"getRadixPower",
"(",
"radix",
",",
"power",
">>",
"1",
")",
";",
"result",
"=",
"halfPower",
".",
"multiply",
"(",
"halfPower",
")",
";",
"}",
"else",
"{",
"BigInteger",
"halfPower",
"=",
"getRadixPower",
"(",
"radix",
",",
"(",
"power",
"-",
"1",
")",
">>",
"1",
")",
";",
"result",
"=",
"halfPower",
".",
"multiply",
"(",
"halfPower",
")",
".",
"multiply",
"(",
"radix",
")",
";",
"}",
"radixPowerMap",
".",
"put",
"(",
"key",
",",
"result",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Caches the results of radix to the given power.
@param radix
@param power
@return | [
"Caches",
"the",
"results",
"of",
"radix",
"to",
"the",
"given",
"power",
"."
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/AddressDivisionBase.java#L351-L367 |
164,086 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/format/AddressDivisionGroupingBase.java | AddressDivisionGroupingBase.getBytesInternal | protected byte[] getBytesInternal() {
byte cached[];
if(hasNoValueCache() || (cached = valueCache.lowerBytes) == null) {
valueCache.lowerBytes = cached = getBytesImpl(true);
}
return cached;
} | java | protected byte[] getBytesInternal() {
byte cached[];
if(hasNoValueCache() || (cached = valueCache.lowerBytes) == null) {
valueCache.lowerBytes = cached = getBytesImpl(true);
}
return cached;
} | [
"protected",
"byte",
"[",
"]",
"getBytesInternal",
"(",
")",
"{",
"byte",
"cached",
"[",
"]",
";",
"if",
"(",
"hasNoValueCache",
"(",
")",
"||",
"(",
"cached",
"=",
"valueCache",
".",
"lowerBytes",
")",
"==",
"null",
")",
"{",
"valueCache",
".",
"lowerBytes",
"=",
"cached",
"=",
"getBytesImpl",
"(",
"true",
")",
";",
"}",
"return",
"cached",
";",
"}"
] | gets the bytes, sharing the cached array and does not clone it | [
"gets",
"the",
"bytes",
"sharing",
"the",
"cached",
"array",
"and",
"does",
"not",
"clone",
"it"
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/AddressDivisionGroupingBase.java#L136-L142 |
164,087 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/format/AddressDivisionGroupingBase.java | AddressDivisionGroupingBase.getUpperBytesInternal | protected byte[] getUpperBytesInternal() {
byte cached[];
if(hasNoValueCache()) {
ValueCache cache = valueCache;
cache.upperBytes = cached = getBytesImpl(false);
if(!isMultiple()) {
cache.lowerBytes = cached;
}
} else {
ValueCache cache = valueCache;
if((cached = cache.upperBytes) == null) {
if(!isMultiple()) {
if((cached = cache.lowerBytes) != null) {
cache.upperBytes = cached;
} else {
cache.lowerBytes = cache.upperBytes = cached = getBytesImpl(false);
}
} else {
cache.upperBytes = cached = getBytesImpl(false);
}
}
}
return cached;
} | java | protected byte[] getUpperBytesInternal() {
byte cached[];
if(hasNoValueCache()) {
ValueCache cache = valueCache;
cache.upperBytes = cached = getBytesImpl(false);
if(!isMultiple()) {
cache.lowerBytes = cached;
}
} else {
ValueCache cache = valueCache;
if((cached = cache.upperBytes) == null) {
if(!isMultiple()) {
if((cached = cache.lowerBytes) != null) {
cache.upperBytes = cached;
} else {
cache.lowerBytes = cache.upperBytes = cached = getBytesImpl(false);
}
} else {
cache.upperBytes = cached = getBytesImpl(false);
}
}
}
return cached;
} | [
"protected",
"byte",
"[",
"]",
"getUpperBytesInternal",
"(",
")",
"{",
"byte",
"cached",
"[",
"]",
";",
"if",
"(",
"hasNoValueCache",
"(",
")",
")",
"{",
"ValueCache",
"cache",
"=",
"valueCache",
";",
"cache",
".",
"upperBytes",
"=",
"cached",
"=",
"getBytesImpl",
"(",
"false",
")",
";",
"if",
"(",
"!",
"isMultiple",
"(",
")",
")",
"{",
"cache",
".",
"lowerBytes",
"=",
"cached",
";",
"}",
"}",
"else",
"{",
"ValueCache",
"cache",
"=",
"valueCache",
";",
"if",
"(",
"(",
"cached",
"=",
"cache",
".",
"upperBytes",
")",
"==",
"null",
")",
"{",
"if",
"(",
"!",
"isMultiple",
"(",
")",
")",
"{",
"if",
"(",
"(",
"cached",
"=",
"cache",
".",
"lowerBytes",
")",
"!=",
"null",
")",
"{",
"cache",
".",
"upperBytes",
"=",
"cached",
";",
"}",
"else",
"{",
"cache",
".",
"lowerBytes",
"=",
"cache",
".",
"upperBytes",
"=",
"cached",
"=",
"getBytesImpl",
"(",
"false",
")",
";",
"}",
"}",
"else",
"{",
"cache",
".",
"upperBytes",
"=",
"cached",
"=",
"getBytesImpl",
"(",
"false",
")",
";",
"}",
"}",
"}",
"return",
"cached",
";",
"}"
] | Gets the bytes for the highest address in the range represented by this address.
@return | [
"Gets",
"the",
"bytes",
"for",
"the",
"highest",
"address",
"in",
"the",
"range",
"represented",
"by",
"this",
"address",
"."
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/AddressDivisionGroupingBase.java#L203-L226 |
164,088 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/format/AddressDivisionGroupingBase.java | AddressDivisionGroupingBase.getMinPrefixLengthForBlock | @Override
public int getMinPrefixLengthForBlock() {
int count = getDivisionCount();
int totalPrefix = getBitCount();
for(int i = count - 1; i >= 0 ; i--) {
AddressDivisionBase div = getDivision(i);
int segBitCount = div.getBitCount();
int segPrefix = div.getMinPrefixLengthForBlock();
if(segPrefix == segBitCount) {
break;
} else {
totalPrefix -= segBitCount;
if(segPrefix != 0) {
totalPrefix += segPrefix;
break;
}
}
}
return totalPrefix;
} | java | @Override
public int getMinPrefixLengthForBlock() {
int count = getDivisionCount();
int totalPrefix = getBitCount();
for(int i = count - 1; i >= 0 ; i--) {
AddressDivisionBase div = getDivision(i);
int segBitCount = div.getBitCount();
int segPrefix = div.getMinPrefixLengthForBlock();
if(segPrefix == segBitCount) {
break;
} else {
totalPrefix -= segBitCount;
if(segPrefix != 0) {
totalPrefix += segPrefix;
break;
}
}
}
return totalPrefix;
} | [
"@",
"Override",
"public",
"int",
"getMinPrefixLengthForBlock",
"(",
")",
"{",
"int",
"count",
"=",
"getDivisionCount",
"(",
")",
";",
"int",
"totalPrefix",
"=",
"getBitCount",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"count",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"AddressDivisionBase",
"div",
"=",
"getDivision",
"(",
"i",
")",
";",
"int",
"segBitCount",
"=",
"div",
".",
"getBitCount",
"(",
")",
";",
"int",
"segPrefix",
"=",
"div",
".",
"getMinPrefixLengthForBlock",
"(",
")",
";",
"if",
"(",
"segPrefix",
"==",
"segBitCount",
")",
"{",
"break",
";",
"}",
"else",
"{",
"totalPrefix",
"-=",
"segBitCount",
";",
"if",
"(",
"segPrefix",
"!=",
"0",
")",
"{",
"totalPrefix",
"+=",
"segPrefix",
";",
"break",
";",
"}",
"}",
"}",
"return",
"totalPrefix",
";",
"}"
] | Returns the smallest prefix length possible such that this address division grouping includes the block of addresses for that prefix.
@return the prefix length | [
"Returns",
"the",
"smallest",
"prefix",
"length",
"possible",
"such",
"that",
"this",
"address",
"division",
"grouping",
"includes",
"the",
"block",
"of",
"addresses",
"for",
"that",
"prefix",
"."
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/AddressDivisionGroupingBase.java#L347-L366 |
164,089 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/format/AddressDivisionGroupingBase.java | AddressDivisionGroupingBase.getPrefixLengthForSingleBlock | @Override
public Integer getPrefixLengthForSingleBlock() {
int count = getDivisionCount();
int totalPrefix = 0;
for(int i = 0; i < count; i++) {
AddressDivisionBase div = getDivision(i);
Integer divPrefix = div.getPrefixLengthForSingleBlock();
if(divPrefix == null) {
return null;
}
totalPrefix += divPrefix;
if(divPrefix < div.getBitCount()) {
//remaining segments must be full range or we return null
for(i++; i < count; i++) {
AddressDivisionBase laterDiv = getDivision(i);
if(!laterDiv.isFullRange()) {
return null;
}
}
}
}
return cacheBits(totalPrefix);
} | java | @Override
public Integer getPrefixLengthForSingleBlock() {
int count = getDivisionCount();
int totalPrefix = 0;
for(int i = 0; i < count; i++) {
AddressDivisionBase div = getDivision(i);
Integer divPrefix = div.getPrefixLengthForSingleBlock();
if(divPrefix == null) {
return null;
}
totalPrefix += divPrefix;
if(divPrefix < div.getBitCount()) {
//remaining segments must be full range or we return null
for(i++; i < count; i++) {
AddressDivisionBase laterDiv = getDivision(i);
if(!laterDiv.isFullRange()) {
return null;
}
}
}
}
return cacheBits(totalPrefix);
} | [
"@",
"Override",
"public",
"Integer",
"getPrefixLengthForSingleBlock",
"(",
")",
"{",
"int",
"count",
"=",
"getDivisionCount",
"(",
")",
";",
"int",
"totalPrefix",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"{",
"AddressDivisionBase",
"div",
"=",
"getDivision",
"(",
"i",
")",
";",
"Integer",
"divPrefix",
"=",
"div",
".",
"getPrefixLengthForSingleBlock",
"(",
")",
";",
"if",
"(",
"divPrefix",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"totalPrefix",
"+=",
"divPrefix",
";",
"if",
"(",
"divPrefix",
"<",
"div",
".",
"getBitCount",
"(",
")",
")",
"{",
"//remaining segments must be full range or we return null",
"for",
"(",
"i",
"++",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"{",
"AddressDivisionBase",
"laterDiv",
"=",
"getDivision",
"(",
"i",
")",
";",
"if",
"(",
"!",
"laterDiv",
".",
"isFullRange",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"}",
"}",
"}",
"return",
"cacheBits",
"(",
"totalPrefix",
")",
";",
"}"
] | Returns a prefix length for which the range of this segment grouping matches the the block of addresses for that prefix.
If no such prefix exists, returns null
If this segment grouping represents a single value, returns the bit length
@return the prefix length or null | [
"Returns",
"a",
"prefix",
"length",
"for",
"which",
"the",
"range",
"of",
"this",
"segment",
"grouping",
"matches",
"the",
"the",
"block",
"of",
"addresses",
"for",
"that",
"prefix",
"."
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/AddressDivisionGroupingBase.java#L377-L399 |
164,090 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/format/AddressDivisionGroupingBase.java | AddressDivisionGroupingBase.getCount | @Override
public BigInteger getCount() {
BigInteger cached = cachedCount;
if(cached == null) {
cachedCount = cached = getCountImpl();
}
return cached;
} | java | @Override
public BigInteger getCount() {
BigInteger cached = cachedCount;
if(cached == null) {
cachedCount = cached = getCountImpl();
}
return cached;
} | [
"@",
"Override",
"public",
"BigInteger",
"getCount",
"(",
")",
"{",
"BigInteger",
"cached",
"=",
"cachedCount",
";",
"if",
"(",
"cached",
"==",
"null",
")",
"{",
"cachedCount",
"=",
"cached",
"=",
"getCountImpl",
"(",
")",
";",
"}",
"return",
"cached",
";",
"}"
] | gets the count of addresses that this address division grouping may represent
If this address division grouping is not a subnet block of multiple addresses or has no range of values, then there is only one such address.
@return | [
"gets",
"the",
"count",
"of",
"addresses",
"that",
"this",
"address",
"division",
"grouping",
"may",
"represent"
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/AddressDivisionGroupingBase.java#L442-L449 |
164,091 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/format/validate/Validator.java | Validator.validateZone | public static int validateZone(CharSequence zone) {
for(int i = 0; i < zone.length(); i++) {
char c = zone.charAt(i);
if (c == IPAddress.PREFIX_LEN_SEPARATOR) {
return i;
}
if (c == IPv6Address.SEGMENT_SEPARATOR) {
return i;
}
}
return -1;
} | java | public static int validateZone(CharSequence zone) {
for(int i = 0; i < zone.length(); i++) {
char c = zone.charAt(i);
if (c == IPAddress.PREFIX_LEN_SEPARATOR) {
return i;
}
if (c == IPv6Address.SEGMENT_SEPARATOR) {
return i;
}
}
return -1;
} | [
"public",
"static",
"int",
"validateZone",
"(",
"CharSequence",
"zone",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"zone",
".",
"length",
"(",
")",
";",
"i",
"++",
")",
"{",
"char",
"c",
"=",
"zone",
".",
"charAt",
"(",
"i",
")",
";",
"if",
"(",
"c",
"==",
"IPAddress",
".",
"PREFIX_LEN_SEPARATOR",
")",
"{",
"return",
"i",
";",
"}",
"if",
"(",
"c",
"==",
"IPv6Address",
".",
"SEGMENT_SEPARATOR",
")",
"{",
"return",
"i",
";",
"}",
"}",
"return",
"-",
"1",
";",
"}"
] | Returns the index of the first invalid character of the zone, or -1 if the zone is valid
@param sequence
@return | [
"Returns",
"the",
"index",
"of",
"the",
"first",
"invalid",
"character",
"of",
"the",
"zone",
"or",
"-",
"1",
"if",
"the",
"zone",
"is",
"valid"
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/validate/Validator.java#L1988-L1999 |
164,092 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/format/validate/Validator.java | Validator.switchValue8 | private static long switchValue8(long currentHexValue, int digitCount) {
long result = 0x7 & currentHexValue;
int shift = 0;
while(--digitCount > 0) {
shift += 3;
currentHexValue >>>= 4;
result |= (0x7 & currentHexValue) << shift;
}
return result;
} | java | private static long switchValue8(long currentHexValue, int digitCount) {
long result = 0x7 & currentHexValue;
int shift = 0;
while(--digitCount > 0) {
shift += 3;
currentHexValue >>>= 4;
result |= (0x7 & currentHexValue) << shift;
}
return result;
} | [
"private",
"static",
"long",
"switchValue8",
"(",
"long",
"currentHexValue",
",",
"int",
"digitCount",
")",
"{",
"long",
"result",
"=",
"0x7",
"&",
"currentHexValue",
";",
"int",
"shift",
"=",
"0",
";",
"while",
"(",
"--",
"digitCount",
">",
"0",
")",
"{",
"shift",
"+=",
"3",
";",
"currentHexValue",
">>>=",
"4",
";",
"result",
"|=",
"(",
"0x7",
"&",
"currentHexValue",
")",
"<<",
"shift",
";",
"}",
"return",
"result",
";",
"}"
] | The digits were stored as a hex value, thix switches them to an octal value.
@param currentHexValue
@param digitCount
@return | [
"The",
"digits",
"were",
"stored",
"as",
"a",
"hex",
"value",
"thix",
"switches",
"them",
"to",
"an",
"octal",
"value",
"."
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/validate/Validator.java#L2312-L2321 |
164,093 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/format/validate/Validator.java | Validator.validateHostImpl | static ParsedHost validateHostImpl(HostName fromHost) throws HostNameException {
final String str = fromHost.toString();
HostNameParameters validationOptions = fromHost.getValidationOptions();
return validateHost(fromHost, str, validationOptions);
} | java | static ParsedHost validateHostImpl(HostName fromHost) throws HostNameException {
final String str = fromHost.toString();
HostNameParameters validationOptions = fromHost.getValidationOptions();
return validateHost(fromHost, str, validationOptions);
} | [
"static",
"ParsedHost",
"validateHostImpl",
"(",
"HostName",
"fromHost",
")",
"throws",
"HostNameException",
"{",
"final",
"String",
"str",
"=",
"fromHost",
".",
"toString",
"(",
")",
";",
"HostNameParameters",
"validationOptions",
"=",
"fromHost",
".",
"getValidationOptions",
"(",
")",
";",
"return",
"validateHost",
"(",
"fromHost",
",",
"str",
",",
"validationOptions",
")",
";",
"}"
] | So we will follow rfc 1035 and in addition allow the underscore. | [
"So",
"we",
"will",
"follow",
"rfc",
"1035",
"and",
"in",
"addition",
"allow",
"the",
"underscore",
"."
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/validate/Validator.java#L2426-L2430 |
164,094 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/format/validate/Validator.java | Validator.convertReverseDNSIPv4 | private static CharSequence convertReverseDNSIPv4(String str, int suffixStartIndex) throws AddressStringException {
StringBuilder builder = new StringBuilder(suffixStartIndex);
int segCount = 0;
int j = suffixStartIndex;
for(int i = suffixStartIndex - 1; i > 0; i--) {
char c1 = str.charAt(i);
if(c1 == IPv4Address.SEGMENT_SEPARATOR) {
if(j - i <= 1) {
throw new AddressStringException(str, i);
}
for(int k = i + 1; k < j; k++) {
builder.append(str.charAt(k));
}
builder.append(c1);
j = i;
segCount++;
}
}
for(int k = 0; k < j; k++) {
builder.append(str.charAt(k));
}
if(segCount + 1 != IPv4Address.SEGMENT_COUNT) {
throw new AddressStringException(str, 0);
}
return builder;
} | java | private static CharSequence convertReverseDNSIPv4(String str, int suffixStartIndex) throws AddressStringException {
StringBuilder builder = new StringBuilder(suffixStartIndex);
int segCount = 0;
int j = suffixStartIndex;
for(int i = suffixStartIndex - 1; i > 0; i--) {
char c1 = str.charAt(i);
if(c1 == IPv4Address.SEGMENT_SEPARATOR) {
if(j - i <= 1) {
throw new AddressStringException(str, i);
}
for(int k = i + 1; k < j; k++) {
builder.append(str.charAt(k));
}
builder.append(c1);
j = i;
segCount++;
}
}
for(int k = 0; k < j; k++) {
builder.append(str.charAt(k));
}
if(segCount + 1 != IPv4Address.SEGMENT_COUNT) {
throw new AddressStringException(str, 0);
}
return builder;
} | [
"private",
"static",
"CharSequence",
"convertReverseDNSIPv4",
"(",
"String",
"str",
",",
"int",
"suffixStartIndex",
")",
"throws",
"AddressStringException",
"{",
"StringBuilder",
"builder",
"=",
"new",
"StringBuilder",
"(",
"suffixStartIndex",
")",
";",
"int",
"segCount",
"=",
"0",
";",
"int",
"j",
"=",
"suffixStartIndex",
";",
"for",
"(",
"int",
"i",
"=",
"suffixStartIndex",
"-",
"1",
";",
"i",
">",
"0",
";",
"i",
"--",
")",
"{",
"char",
"c1",
"=",
"str",
".",
"charAt",
"(",
"i",
")",
";",
"if",
"(",
"c1",
"==",
"IPv4Address",
".",
"SEGMENT_SEPARATOR",
")",
"{",
"if",
"(",
"j",
"-",
"i",
"<=",
"1",
")",
"{",
"throw",
"new",
"AddressStringException",
"(",
"str",
",",
"i",
")",
";",
"}",
"for",
"(",
"int",
"k",
"=",
"i",
"+",
"1",
";",
"k",
"<",
"j",
";",
"k",
"++",
")",
"{",
"builder",
".",
"append",
"(",
"str",
".",
"charAt",
"(",
"k",
")",
")",
";",
"}",
"builder",
".",
"append",
"(",
"c1",
")",
";",
"j",
"=",
"i",
";",
"segCount",
"++",
";",
"}",
"}",
"for",
"(",
"int",
"k",
"=",
"0",
";",
"k",
"<",
"j",
";",
"k",
"++",
")",
"{",
"builder",
".",
"append",
"(",
"str",
".",
"charAt",
"(",
"k",
")",
")",
";",
"}",
"if",
"(",
"segCount",
"+",
"1",
"!=",
"IPv4Address",
".",
"SEGMENT_COUNT",
")",
"{",
"throw",
"new",
"AddressStringException",
"(",
"str",
",",
"0",
")",
";",
"}",
"return",
"builder",
";",
"}"
] | 123.2.3.4 is 4.3.2.123.in-addr.arpa. | [
"123",
".",
"2",
".",
"3",
".",
"4",
"is",
"4",
".",
"3",
".",
"2",
".",
"123",
".",
"in",
"-",
"addr",
".",
"arpa",
"."
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/validate/Validator.java#L3062-L3087 |
164,095 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/format/standard/AddressDivision.java | AddressDivision.isPrefixBlock | protected boolean isPrefixBlock(long divisionValue, long upperValue, int divisionPrefixLen) {
if(divisionPrefixLen == 0) {
return divisionValue == 0 && upperValue == getMaxValue();
}
long ones = ~0L;
long divisionBitMask = ~(ones << getBitCount());
long divisionPrefixMask = ones << (getBitCount() - divisionPrefixLen);
long divisionNonPrefixMask = ~divisionPrefixMask;
return testRange(divisionValue,
upperValue,
upperValue,
divisionPrefixMask & divisionBitMask,
divisionNonPrefixMask);
} | java | protected boolean isPrefixBlock(long divisionValue, long upperValue, int divisionPrefixLen) {
if(divisionPrefixLen == 0) {
return divisionValue == 0 && upperValue == getMaxValue();
}
long ones = ~0L;
long divisionBitMask = ~(ones << getBitCount());
long divisionPrefixMask = ones << (getBitCount() - divisionPrefixLen);
long divisionNonPrefixMask = ~divisionPrefixMask;
return testRange(divisionValue,
upperValue,
upperValue,
divisionPrefixMask & divisionBitMask,
divisionNonPrefixMask);
} | [
"protected",
"boolean",
"isPrefixBlock",
"(",
"long",
"divisionValue",
",",
"long",
"upperValue",
",",
"int",
"divisionPrefixLen",
")",
"{",
"if",
"(",
"divisionPrefixLen",
"==",
"0",
")",
"{",
"return",
"divisionValue",
"==",
"0",
"&&",
"upperValue",
"==",
"getMaxValue",
"(",
")",
";",
"}",
"long",
"ones",
"=",
"~",
"0L",
";",
"long",
"divisionBitMask",
"=",
"~",
"(",
"ones",
"<<",
"getBitCount",
"(",
")",
")",
";",
"long",
"divisionPrefixMask",
"=",
"ones",
"<<",
"(",
"getBitCount",
"(",
")",
"-",
"divisionPrefixLen",
")",
";",
"long",
"divisionNonPrefixMask",
"=",
"~",
"divisionPrefixMask",
";",
"return",
"testRange",
"(",
"divisionValue",
",",
"upperValue",
",",
"upperValue",
",",
"divisionPrefixMask",
"&",
"divisionBitMask",
",",
"divisionNonPrefixMask",
")",
";",
"}"
] | Returns whether the division range includes the block of values for its prefix length | [
"Returns",
"whether",
"the",
"division",
"range",
"includes",
"the",
"block",
"of",
"values",
"for",
"its",
"prefix",
"length"
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/standard/AddressDivision.java#L196-L209 |
164,096 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/format/standard/AddressDivision.java | AddressDivision.matchesWithMask | public boolean matchesWithMask(long lowerValue, long upperValue, long mask) {
if(lowerValue == upperValue) {
return matchesWithMask(lowerValue, mask);
}
if(!isMultiple()) {
//we know lowerValue and upperValue are not the same, so impossible to match those two values with a single value
return false;
}
long thisValue = getDivisionValue();
long thisUpperValue = getUpperDivisionValue();
if(!isMaskCompatibleWithRange(thisValue, thisUpperValue, mask, getMaxValue())) {
return false;
}
return lowerValue == (thisValue & mask) && upperValue == (thisUpperValue & mask);
} | java | public boolean matchesWithMask(long lowerValue, long upperValue, long mask) {
if(lowerValue == upperValue) {
return matchesWithMask(lowerValue, mask);
}
if(!isMultiple()) {
//we know lowerValue and upperValue are not the same, so impossible to match those two values with a single value
return false;
}
long thisValue = getDivisionValue();
long thisUpperValue = getUpperDivisionValue();
if(!isMaskCompatibleWithRange(thisValue, thisUpperValue, mask, getMaxValue())) {
return false;
}
return lowerValue == (thisValue & mask) && upperValue == (thisUpperValue & mask);
} | [
"public",
"boolean",
"matchesWithMask",
"(",
"long",
"lowerValue",
",",
"long",
"upperValue",
",",
"long",
"mask",
")",
"{",
"if",
"(",
"lowerValue",
"==",
"upperValue",
")",
"{",
"return",
"matchesWithMask",
"(",
"lowerValue",
",",
"mask",
")",
";",
"}",
"if",
"(",
"!",
"isMultiple",
"(",
")",
")",
"{",
"//we know lowerValue and upperValue are not the same, so impossible to match those two values with a single value",
"return",
"false",
";",
"}",
"long",
"thisValue",
"=",
"getDivisionValue",
"(",
")",
";",
"long",
"thisUpperValue",
"=",
"getUpperDivisionValue",
"(",
")",
";",
"if",
"(",
"!",
"isMaskCompatibleWithRange",
"(",
"thisValue",
",",
"thisUpperValue",
",",
"mask",
",",
"getMaxValue",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"lowerValue",
"==",
"(",
"thisValue",
"&",
"mask",
")",
"&&",
"upperValue",
"==",
"(",
"thisUpperValue",
"&",
"mask",
")",
";",
"}"
] | returns whether masking with the given mask results in a valid contiguous range for this segment,
and if it does, if it matches the range obtained when masking the given values with the same mask.
@param lowerValue
@param upperValue
@param mask
@return | [
"returns",
"whether",
"masking",
"with",
"the",
"given",
"mask",
"results",
"in",
"a",
"valid",
"contiguous",
"range",
"for",
"this",
"segment",
"and",
"if",
"it",
"does",
"if",
"it",
"matches",
"the",
"range",
"obtained",
"when",
"masking",
"the",
"given",
"values",
"with",
"the",
"same",
"mask",
"."
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/standard/AddressDivision.java#L266-L280 |
164,097 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/format/standard/AddressDivision.java | AddressDivision.isMaskCompatibleWithRange | protected static boolean isMaskCompatibleWithRange(long value, long upperValue, long maskValue, long maxValue) {
if(value == upperValue || maskValue == maxValue || maskValue == 0) {
return true;
}
//algorithm:
//here we find the highest bit that is part of the range, highestDifferingBitInRange (ie changes from lower to upper)
//then we find the highest bit in the mask that is 1 that is the same or below highestDifferingBitInRange (if such a bit exists)
//this gives us the highest bit that is part of the masked range (ie changes from lower to upper after applying the mask)
//if this latter bit exists, then any bit below it in the mask must be 1 to include the entire range.
long differing = value ^ upperValue;
boolean foundDiffering = (differing != 0);
boolean differingIsLowestBit = (differing == 1);
if(foundDiffering && !differingIsLowestBit) {
int highestDifferingBitInRange = Long.numberOfLeadingZeros(differing);
long maskMask = ~0L >>> highestDifferingBitInRange;
long differingMasked = maskValue & maskMask;
foundDiffering = (differingMasked != 0);
differingIsLowestBit = (differingMasked == 1);
if(foundDiffering && !differingIsLowestBit) {
//anything below highestDifferingBitMasked in the mask must be ones
//Also, if we have masked out any 1 bit in the original, then anything that we do not mask out that follows must be all 1s
int highestDifferingBitMasked = Long.numberOfLeadingZeros(differingMasked);
long hostMask = ~0L >>> (highestDifferingBitMasked + 1);//for the first mask bit that is 1, all bits that follow must also be 1
if((maskValue & hostMask) != hostMask) { //check if all ones below
return false;
}
if(highestDifferingBitMasked > highestDifferingBitInRange) {
//We have masked out a 1 bit, so we need to check that all bits in upper value that we do not mask out are also 1 bits, otherwise we end up missing values in the masked range
//This check is unnecessary for prefix-length subnets, only non-standard ranges might fail this check.
//For instance, if we have range 0000 to 1010
//and we mask upper and lower with 0111
//we get 0000 to 0010, but 0111 was in original range, and the mask of that value retains that value
//so that value needs to be in final range, and it's not.
//What went wrong is that we masked out the top bit, and any other bit that is not masked out must be 1.
//To work, our original range needed to be 0000 to 1111, with the three 1s following the first masked-out 1
long hostMaskUpper = ~0L >>> highestDifferingBitMasked;
if((upperValue & hostMaskUpper) != hostMaskUpper) {
return false;
}
}
}
}
return true;
} | java | protected static boolean isMaskCompatibleWithRange(long value, long upperValue, long maskValue, long maxValue) {
if(value == upperValue || maskValue == maxValue || maskValue == 0) {
return true;
}
//algorithm:
//here we find the highest bit that is part of the range, highestDifferingBitInRange (ie changes from lower to upper)
//then we find the highest bit in the mask that is 1 that is the same or below highestDifferingBitInRange (if such a bit exists)
//this gives us the highest bit that is part of the masked range (ie changes from lower to upper after applying the mask)
//if this latter bit exists, then any bit below it in the mask must be 1 to include the entire range.
long differing = value ^ upperValue;
boolean foundDiffering = (differing != 0);
boolean differingIsLowestBit = (differing == 1);
if(foundDiffering && !differingIsLowestBit) {
int highestDifferingBitInRange = Long.numberOfLeadingZeros(differing);
long maskMask = ~0L >>> highestDifferingBitInRange;
long differingMasked = maskValue & maskMask;
foundDiffering = (differingMasked != 0);
differingIsLowestBit = (differingMasked == 1);
if(foundDiffering && !differingIsLowestBit) {
//anything below highestDifferingBitMasked in the mask must be ones
//Also, if we have masked out any 1 bit in the original, then anything that we do not mask out that follows must be all 1s
int highestDifferingBitMasked = Long.numberOfLeadingZeros(differingMasked);
long hostMask = ~0L >>> (highestDifferingBitMasked + 1);//for the first mask bit that is 1, all bits that follow must also be 1
if((maskValue & hostMask) != hostMask) { //check if all ones below
return false;
}
if(highestDifferingBitMasked > highestDifferingBitInRange) {
//We have masked out a 1 bit, so we need to check that all bits in upper value that we do not mask out are also 1 bits, otherwise we end up missing values in the masked range
//This check is unnecessary for prefix-length subnets, only non-standard ranges might fail this check.
//For instance, if we have range 0000 to 1010
//and we mask upper and lower with 0111
//we get 0000 to 0010, but 0111 was in original range, and the mask of that value retains that value
//so that value needs to be in final range, and it's not.
//What went wrong is that we masked out the top bit, and any other bit that is not masked out must be 1.
//To work, our original range needed to be 0000 to 1111, with the three 1s following the first masked-out 1
long hostMaskUpper = ~0L >>> highestDifferingBitMasked;
if((upperValue & hostMaskUpper) != hostMaskUpper) {
return false;
}
}
}
}
return true;
} | [
"protected",
"static",
"boolean",
"isMaskCompatibleWithRange",
"(",
"long",
"value",
",",
"long",
"upperValue",
",",
"long",
"maskValue",
",",
"long",
"maxValue",
")",
"{",
"if",
"(",
"value",
"==",
"upperValue",
"||",
"maskValue",
"==",
"maxValue",
"||",
"maskValue",
"==",
"0",
")",
"{",
"return",
"true",
";",
"}",
"//algorithm:",
"//here we find the highest bit that is part of the range, highestDifferingBitInRange (ie changes from lower to upper)",
"//then we find the highest bit in the mask that is 1 that is the same or below highestDifferingBitInRange (if such a bit exists)",
"//this gives us the highest bit that is part of the masked range (ie changes from lower to upper after applying the mask)",
"//if this latter bit exists, then any bit below it in the mask must be 1 to include the entire range.",
"long",
"differing",
"=",
"value",
"^",
"upperValue",
";",
"boolean",
"foundDiffering",
"=",
"(",
"differing",
"!=",
"0",
")",
";",
"boolean",
"differingIsLowestBit",
"=",
"(",
"differing",
"==",
"1",
")",
";",
"if",
"(",
"foundDiffering",
"&&",
"!",
"differingIsLowestBit",
")",
"{",
"int",
"highestDifferingBitInRange",
"=",
"Long",
".",
"numberOfLeadingZeros",
"(",
"differing",
")",
";",
"long",
"maskMask",
"=",
"~",
"0L",
">>>",
"highestDifferingBitInRange",
";",
"long",
"differingMasked",
"=",
"maskValue",
"&",
"maskMask",
";",
"foundDiffering",
"=",
"(",
"differingMasked",
"!=",
"0",
")",
";",
"differingIsLowestBit",
"=",
"(",
"differingMasked",
"==",
"1",
")",
";",
"if",
"(",
"foundDiffering",
"&&",
"!",
"differingIsLowestBit",
")",
"{",
"//anything below highestDifferingBitMasked in the mask must be ones",
"//Also, if we have masked out any 1 bit in the original, then anything that we do not mask out that follows must be all 1s",
"int",
"highestDifferingBitMasked",
"=",
"Long",
".",
"numberOfLeadingZeros",
"(",
"differingMasked",
")",
";",
"long",
"hostMask",
"=",
"~",
"0L",
">>>",
"(",
"highestDifferingBitMasked",
"+",
"1",
")",
";",
"//for the first mask bit that is 1, all bits that follow must also be 1",
"if",
"(",
"(",
"maskValue",
"&",
"hostMask",
")",
"!=",
"hostMask",
")",
"{",
"//check if all ones below",
"return",
"false",
";",
"}",
"if",
"(",
"highestDifferingBitMasked",
">",
"highestDifferingBitInRange",
")",
"{",
"//We have masked out a 1 bit, so we need to check that all bits in upper value that we do not mask out are also 1 bits, otherwise we end up missing values in the masked range",
"//This check is unnecessary for prefix-length subnets, only non-standard ranges might fail this check.",
"//For instance, if we have range 0000 to 1010",
"//and we mask upper and lower with 0111",
"//we get 0000 to 0010, but 0111 was in original range, and the mask of that value retains that value",
"//so that value needs to be in final range, and it's not.",
"//What went wrong is that we masked out the top bit, and any other bit that is not masked out must be 1.",
"//To work, our original range needed to be 0000 to 1111, with the three 1s following the first masked-out 1",
"long",
"hostMaskUpper",
"=",
"~",
"0L",
">>>",
"highestDifferingBitMasked",
";",
"if",
"(",
"(",
"upperValue",
"&",
"hostMaskUpper",
")",
"!=",
"hostMaskUpper",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] | when divisionPrefixLen is null, isAutoSubnets has no effect | [
"when",
"divisionPrefixLen",
"is",
"null",
"isAutoSubnets",
"has",
"no",
"effect"
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/format/standard/AddressDivision.java#L309-L355 |
164,098 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6AddressSection.java | IPv6AddressSection.isEUI64 | public boolean isEUI64(boolean partial) {
int segmentCount = getSegmentCount();
int endIndex = addressSegmentIndex + segmentCount;
if(addressSegmentIndex <= 5) {
if(endIndex > 6) {
int index3 = 5 - addressSegmentIndex;
IPv6AddressSegment seg3 = getSegment(index3);
IPv6AddressSegment seg4 = getSegment(index3 + 1);
return seg4.matchesWithMask(0xfe00, 0xff00) && seg3.matchesWithMask(0xff, 0xff);
} else if(partial && endIndex == 6) {
IPv6AddressSegment seg3 = getSegment(5 - addressSegmentIndex);
return seg3.matchesWithMask(0xff, 0xff);
}
} else if(partial && addressSegmentIndex == 6 && endIndex > 6) {
IPv6AddressSegment seg4 = getSegment(6 - addressSegmentIndex);
return seg4.matchesWithMask(0xfe00, 0xff00);
}
return partial;
} | java | public boolean isEUI64(boolean partial) {
int segmentCount = getSegmentCount();
int endIndex = addressSegmentIndex + segmentCount;
if(addressSegmentIndex <= 5) {
if(endIndex > 6) {
int index3 = 5 - addressSegmentIndex;
IPv6AddressSegment seg3 = getSegment(index3);
IPv6AddressSegment seg4 = getSegment(index3 + 1);
return seg4.matchesWithMask(0xfe00, 0xff00) && seg3.matchesWithMask(0xff, 0xff);
} else if(partial && endIndex == 6) {
IPv6AddressSegment seg3 = getSegment(5 - addressSegmentIndex);
return seg3.matchesWithMask(0xff, 0xff);
}
} else if(partial && addressSegmentIndex == 6 && endIndex > 6) {
IPv6AddressSegment seg4 = getSegment(6 - addressSegmentIndex);
return seg4.matchesWithMask(0xfe00, 0xff00);
}
return partial;
} | [
"public",
"boolean",
"isEUI64",
"(",
"boolean",
"partial",
")",
"{",
"int",
"segmentCount",
"=",
"getSegmentCount",
"(",
")",
";",
"int",
"endIndex",
"=",
"addressSegmentIndex",
"+",
"segmentCount",
";",
"if",
"(",
"addressSegmentIndex",
"<=",
"5",
")",
"{",
"if",
"(",
"endIndex",
">",
"6",
")",
"{",
"int",
"index3",
"=",
"5",
"-",
"addressSegmentIndex",
";",
"IPv6AddressSegment",
"seg3",
"=",
"getSegment",
"(",
"index3",
")",
";",
"IPv6AddressSegment",
"seg4",
"=",
"getSegment",
"(",
"index3",
"+",
"1",
")",
";",
"return",
"seg4",
".",
"matchesWithMask",
"(",
"0xfe00",
",",
"0xff00",
")",
"&&",
"seg3",
".",
"matchesWithMask",
"(",
"0xff",
",",
"0xff",
")",
";",
"}",
"else",
"if",
"(",
"partial",
"&&",
"endIndex",
"==",
"6",
")",
"{",
"IPv6AddressSegment",
"seg3",
"=",
"getSegment",
"(",
"5",
"-",
"addressSegmentIndex",
")",
";",
"return",
"seg3",
".",
"matchesWithMask",
"(",
"0xff",
",",
"0xff",
")",
";",
"}",
"}",
"else",
"if",
"(",
"partial",
"&&",
"addressSegmentIndex",
"==",
"6",
"&&",
"endIndex",
">",
"6",
")",
"{",
"IPv6AddressSegment",
"seg4",
"=",
"getSegment",
"(",
"6",
"-",
"addressSegmentIndex",
")",
";",
"return",
"seg4",
".",
"matchesWithMask",
"(",
"0xfe00",
",",
"0xff00",
")",
";",
"}",
"return",
"partial",
";",
"}"
] | Whether this section is consistent with an EUI64 section,
which means it came from an extended 8 byte address,
and the corresponding segments in the middle match 0xff and 0xfe
@param partial whether missing segments are considered a match
@return | [
"Whether",
"this",
"section",
"is",
"consistent",
"with",
"an",
"EUI64",
"section",
"which",
"means",
"it",
"came",
"from",
"an",
"extended",
"8",
"byte",
"address",
"and",
"the",
"corresponding",
"segments",
"in",
"the",
"middle",
"match",
"0xff",
"and",
"0xfe"
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6AddressSection.java#L1133-L1151 |
164,099 | seancfoley/IPAddress | IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6AddressSection.java | IPv6AddressSection.toEUI | public MACAddressSection toEUI(boolean extended) {
MACAddressSegment[] segs = toEUISegments(extended);
if(segs == null) {
return null;
}
MACAddressCreator creator = getMACNetwork().getAddressCreator();
return createSectionInternal(creator, segs, Math.max(0, addressSegmentIndex - 4) << 1, extended);
} | java | public MACAddressSection toEUI(boolean extended) {
MACAddressSegment[] segs = toEUISegments(extended);
if(segs == null) {
return null;
}
MACAddressCreator creator = getMACNetwork().getAddressCreator();
return createSectionInternal(creator, segs, Math.max(0, addressSegmentIndex - 4) << 1, extended);
} | [
"public",
"MACAddressSection",
"toEUI",
"(",
"boolean",
"extended",
")",
"{",
"MACAddressSegment",
"[",
"]",
"segs",
"=",
"toEUISegments",
"(",
"extended",
")",
";",
"if",
"(",
"segs",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"MACAddressCreator",
"creator",
"=",
"getMACNetwork",
"(",
")",
".",
"getAddressCreator",
"(",
")",
";",
"return",
"createSectionInternal",
"(",
"creator",
",",
"segs",
",",
"Math",
".",
"max",
"(",
"0",
",",
"addressSegmentIndex",
"-",
"4",
")",
"<<",
"1",
",",
"extended",
")",
";",
"}"
] | Returns the corresponding mac section, or null if this address section does not correspond to a mac section.
If this address section has a prefix length it is ignored.
@param extended
@return | [
"Returns",
"the",
"corresponding",
"mac",
"section",
"or",
"null",
"if",
"this",
"address",
"section",
"does",
"not",
"correspond",
"to",
"a",
"mac",
"section",
".",
"If",
"this",
"address",
"section",
"has",
"a",
"prefix",
"length",
"it",
"is",
"ignored",
"."
] | 90493d0673511d673100c36d020dd93dd870111a | https://github.com/seancfoley/IPAddress/blob/90493d0673511d673100c36d020dd93dd870111a/IPAddress/src/inet.ipaddr/inet/ipaddr/ipv6/IPv6AddressSection.java#L1160-L1167 |
Subsets and Splits