-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Move Port and PortRange Ruby settings to Java #17964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
andsel
merged 15 commits into
elastic:main
from
andsel:feature/portrange_setting_to_java
Sep 17, 2025
Merged
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5d43c26
Moved PositiveInteger Ruby class to Java SettingPositiveInteger
andsel a5e61cd
Code clean, removed debug logs
andsel 50f5a6c
Minor, reinserted dropped line
andsel c0286fd
[WIP] First implementation of Port and PortRange classes
andsel f36a55e
Fixed SettingPortRange.coerce when Long value is provided. Added meth…
andsel 8ba2530
Updated SettingsPortRange to work on generic Object so that the const…
andsel 3e6dfee
Minor, added license header to new files
andsel 80e252b
[Test] Covered Java Range class with tests
andsel c72b6bb
[Test] Covered Java class SettingPortRange with JUnit test copied fro…
andsel fbd6ca2
Updated coerce to trim whitespaces when coercing from String and adde…
andsel 194ad7d
[Test] Given that SettingPortRange cna handle also JRuby RubyRange av…
andsel d241192
Removed aliasing of PortRange (Ruby class) with SettingPortRange (Jav…
andsel 52a6da2
Renamed SettingPortRange to PortRangeSetting
andsel 47c5d6b
Renamed SettingPort to PortSetting
andsel d9f442b
Fix spacing
andsel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
logstash-core/src/main/java/org/logstash/settings/Range.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.logstash.settings; | ||
|
||
import java.util.Objects; | ||
import java.util.function.BiConsumer; | ||
|
||
public class Range<T extends Integer> { | ||
|
||
private final T first; | ||
private final T last; | ||
|
||
public Range(T first, T last) { | ||
this.first = Objects.requireNonNull(first); | ||
this.last =Objects.requireNonNull(last); | ||
if (first.compareTo(last) > 0) { | ||
throw new IllegalArgumentException("First must be less than or equal to last"); | ||
} | ||
} | ||
|
||
public boolean contains(Range<T> other) { | ||
return first.compareTo(other.first) <= 0 && last.compareTo(other.last) >= 0; | ||
} | ||
|
||
public T getFirst() { | ||
return first; | ||
} | ||
|
||
public T getLast() { | ||
return last; | ||
} | ||
|
||
public void eachWithIndex(BiConsumer<Integer, Integer> consumer) { | ||
// In case of a single value range, we should still yield once | ||
if (first.intValue() == last.intValue()) { | ||
consumer.accept(first.intValue(), 0); | ||
return; | ||
} | ||
int index = 0; | ||
for (int value = first.intValue(); value < last.intValue(); value++) { | ||
consumer.accept(value, index++); | ||
} | ||
} | ||
|
||
public int count() { | ||
return last.intValue() - first.intValue() + 1; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.getClass().getName() + | ||
"{first=" + first + | ||
", last=" + last + | ||
'}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Range<?> range = (Range<?>) o; | ||
return Objects.equals(first, range.first) && Objects.equals(last, range.last); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(first, last); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
logstash-core/src/main/java/org/logstash/settings/SettingPort.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.logstash.settings; | ||
|
||
import java.util.function.Predicate; | ||
|
||
public final class SettingPort extends SettingInteger { | ||
|
||
public static final Predicate<Integer> VALID_PORT_RANGE = new Predicate<>() { | ||
@Override | ||
public boolean test(Integer integer) { | ||
return isValid(integer); | ||
} | ||
}; | ||
|
||
public SettingPort(String name, Integer defaultValue) { | ||
super(name, defaultValue); | ||
} | ||
|
||
public SettingPort(String name, Integer defaultValue, boolean strict) { | ||
this(name, defaultValue, strict, VALID_PORT_RANGE); | ||
} | ||
|
||
protected SettingPort(String name, Integer defaultValue, boolean strict, Predicate<Integer> validator) { | ||
super(name, defaultValue, strict, validator); | ||
} | ||
|
||
public static boolean isValid(int port) { | ||
return 1 <= port && port <= 65535; | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.