Skip to content

Commit

Permalink
objectionary#3542 simplify implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Suban05 committed Feb 21, 2025
1 parent 9f70b01 commit 380790c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 59 deletions.
24 changes: 0 additions & 24 deletions .github/typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,3 @@ extend-ignore-identifiers-re = [
"scrpt", # valid variable name
"fle" # valid variable name
]
# The MIT License (MIT)
#
# Copyright (c) 2016-2025 Objectionary.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

[default.extend-words]
nd = "nd"
37 changes: 3 additions & 34 deletions eo-runtime/src/main/java/org/eolang/PhDefault.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,11 @@ public boolean hasRho() {
@Override
public void put(final int pos, final Phi object) {
final String name = this.attr(pos);
final AtWithRho attribute = (AtWithRho) this.attrs.get(name);
if (!(attribute.getOrigin() instanceof AtVoid)) {
if (!(((AtWithRho) this.attrs.get(name)).getOrigin() instanceof AtVoid)) {
throw new ExReadOnly(
String.format(
"There are no void attributes left, can't set the %s one",
PhDefault.ordinal(pos)
"Can't put attribute with position %d because it's not void one",
pos
)
);
}
Expand Down Expand Up @@ -346,34 +345,4 @@ private static void debug(final String msg) {
private static String padding() {
return String.join("", Collections.nCopies(PhDefault.NESTING.get(), "·"));
}

/**
* Returns the ordinal representation of a number (e.g., "1st", "2nd", "3rd", "4th").
* @param number The number to format
* @return The number with its ordinal suffix
*/
private static String ordinal(final int number) {
final int lasts = number % 100;
final int last = number % 10;
final String suffix;
if (lasts >= 11 && lasts <= 13) {
suffix = "th";
} else {
switch (last) {
case 1:
suffix = "st";
break;
case 2:
suffix = "nd";
break;
case 3:
suffix = "rd";
break;
default:
suffix = "th";
break;
}
}
return number + suffix;
}
}
2 changes: 1 addition & 1 deletion eo-runtime/src/test/java/org/eolang/PhDefaultTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ void failsCorrectlyWhenTooManyAttributesPut() {
() -> new EOnumber().put(1, new Data.ToPhi(1)),
"fails when trying to set attribute with too big position"
).getMessage(),
Matchers.equalTo("There are no void attributes left, can't set the 1st one")
Matchers.equalTo("Can't put attribute with position 1 because it's not void one")
);
}

Expand Down

0 comments on commit 380790c

Please sign in to comment.