Renamed tweet string to generic X limited banana size

This commit is contained in:
Willem Cazander 2024-12-23 15:24:54 +01:00
parent 6bfdca24a4
commit 202f7c49a1
2 changed files with 22 additions and 22 deletions

View file

@ -30,32 +30,32 @@ package ᒢᐩᐩ.ᒡᒢᑊᒻᒻᓫᔿ.ᐪᓫᕽᐪ;
import ᒢᐩᐩ.ᔆʸᔆᐪᓫᔿ.ᒃᣔᒃᓫᒻ.ᑊᐣᓑᖮᐪᔆ.DuytsDocAuthor注;
@DuytsDocAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
public interface StringTweet extends StringTypeConst<StringTweet> {
public interface StringXLimit extends StringTypeConst<StringXLimit> {
public static Class<Length035> MAX_035 = Length035.class;
public static Class<Length070> MAX_070 = Length070.class;
public static Class<Length140> MAX_140 = Length140.class;
public static Class<Length280> MAX_280 = Length280.class;
interface Length035 extends StringTweet {
interface Length035 extends StringXLimit {
}
interface Length070 extends StringTweet {
interface Length070 extends StringXLimit {
}
interface Length140 extends StringTweet {
interface Length140 extends StringXLimit {
}
interface Length280 extends StringTweet {
interface Length280 extends StringXLimit {
}
static StringTweet tweetᴺᵉʷ(String text, Class<? extends StringTweet> tweetType) {
static StringXLimit valueᴼᶠ(String text, Class<? extends StringXLimit> xBananaSize) {
if (text == null) {
throw new NullPointerException("Can't create null tweet.");
throw new NullPointerException("Can't create XLimit with null text.");
}
if (tweetType == null) {
throw new NullPointerException("Can't create tweet with null type.");
if (xBananaSize == null) {
throw new NullPointerException("Can't create XLimit with null XLimit type.");
}
if (Length035.class.equals(tweetType)) {
if (Length035.class.equals(xBananaSize)) {
if (text.codePoints().count() > 35) {
throw new IllegalArgumentException("Tweet code points lenght is larger than: 35");
throw new IllegalArgumentException("XLimit code points lenght is larger than: 35");
}
return new Length035() {
@Override
@ -64,9 +64,9 @@ public interface StringTweet extends StringTypeConst<StringTweet> {
}
};
}
if (Length070.class.equals(tweetType)) {
if (Length070.class.equals(xBananaSize)) {
if (text.codePoints().count() > 70) {
throw new IllegalArgumentException("Tweet code points lenght is larger than: 70");
throw new IllegalArgumentException("XLimit code points lenght is larger than: 70");
}
return new Length070() {
@Override
@ -75,9 +75,9 @@ public interface StringTweet extends StringTypeConst<StringTweet> {
}
};
}
if (Length140.class.equals(tweetType)) {
if (Length140.class.equals(xBananaSize)) {
if (text.codePoints().count() > 35) {
throw new IllegalArgumentException("Tweet code points lenght is larger than: 140");
throw new IllegalArgumentException("XLimit code points lenght is larger than: 140");
}
return new Length140() {
@Override
@ -86,9 +86,9 @@ public interface StringTweet extends StringTypeConst<StringTweet> {
}
};
}
if (Length280.class.equals(tweetType)) {
if (Length280.class.equals(xBananaSize)) {
if (text.codePoints().count() > 280) {
throw new IllegalArgumentException("Tweet code points lenght is larger than: 280");
throw new IllegalArgumentException("XLimit code points lenght is larger than: 280");
}
return new Length280() {
@Override
@ -97,6 +97,6 @@ public interface StringTweet extends StringTypeConst<StringTweet> {
}
};
}
throw new IllegalArgumentException("Can't create tweet with unknown type: "+tweetType);
throw new IllegalArgumentException("Can't create XLimit with unknown type: " + xBananaSize);
}
}

View file

@ -33,18 +33,18 @@ import org.junit.jupiter.api.Test;
import ᒢᐩᐩ.ᔆʸᔆᐪᓫᔿ.ᒃᣔᒃᓫᒻ.ᑊᐣᓑᖮᐪᔆ.DuytsDocAuthor注;
@DuytsDocAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
public class StringTweetTest {
public class StringXLimitTest {
@Test
public void testTweetSmall() {
StringTweet tweet = StringTweet.tweetᴺᵉʷ("test", StringTweet.MAX_280);
StringXLimit tweet = StringXLimit.valueᴼᶠ("test", StringXLimit.MAX_280);
Assertions.assertEquals(4, tweet.lengthChars());
}
@Test
public void testTweetCompare() {
StringTweet tweet1 = StringTweet.tweetᴺᵉʷ("test", StringTweet.MAX_140);
StringTweet tweet2 = StringTweet.tweetᴺᵉʷ("test", StringTweet.MAX_280);
StringXLimit tweet1 = StringXLimit.valueᴼᶠ("test", StringXLimit.MAX_140);
StringXLimit tweet2 = StringXLimit.valueᴼᶠ("test", StringXLimit.MAX_280);
Assertions.assertEquals(0, tweet1.compareTo(tweet2));
}
}