Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolamand-db committed Apr 23, 2024
1 parent ae2ff0a commit 7317811
Showing 1 changed file with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,17 @@ protected enum CaseConversion {
protected static final int localeOffset = 0;
protected static final int localeLen = 16;

protected final ImplementationProvider implementationProvider;
protected final CaseSensitivity caseSensitivity;
protected final AccentSensitivity accentSensitivity;
protected final CaseConversion caseConversion;
protected final String locale;
protected final int collationId;

protected CollationSpec(
ImplementationProvider implementationProvider,
String locale,
CaseSensitivity caseSensitivity,
AccentSensitivity accentSensitivity,
CaseConversion caseConversion) {
this.implementationProvider = implementationProvider;
this.locale = locale;
this.caseSensitivity = caseSensitivity;
this.accentSensitivity = accentSensitivity;
Expand Down Expand Up @@ -244,9 +241,8 @@ protected static int parseSpecifiers(String specString) throws SparkException {
return specifiers;
}

public abstract int getCollationId();
public abstract Collation buildCollation();
protected abstract String collationName();
protected abstract int getCollationId();
protected abstract Collation buildCollation();
}

public static class CollationSpecUTF8Binary extends CollationSpec {
Expand All @@ -257,8 +253,7 @@ public static class CollationSpecUTF8Binary extends CollationSpec {
new CollationSpecUTF8Binary(CaseConversion.LCASE).getCollationId();

private CollationSpecUTF8Binary(CaseConversion caseConversion) {
super(ImplementationProvider.UTF8_BINARY, null,
CaseSensitivity.CS, AccentSensitivity.AS, caseConversion);
super(null, CaseSensitivity.CS, AccentSensitivity.AS, caseConversion);
}

public static int collationNameToId(String collationName) throws SparkException {
Expand All @@ -270,9 +265,8 @@ public static int collationNameToId(String collationName) throws SparkException
}

@Override
public int getCollationId() {
protected int getCollationId() {
int collationId = 0;
collationId |= implementationProvider.ordinal() << implementationProviderOffset;
collationId |= caseConversion.ordinal() << caseConversionOffset;
return collationId;
}
Expand All @@ -283,7 +277,8 @@ public static CollationSpecUTF8Binary fromCollationId(int collationId) {
return new CollationSpecUTF8Binary(caseConversion);
}

public Collation buildCollation() {
@Override
protected Collation buildCollation() {
Comparator<UTF8String> comparator;
if (collationId == UTF8_BINARY_COLLATION_ID) {
comparator = UTF8String::binaryCompare;
Expand Down Expand Up @@ -318,8 +313,7 @@ private UTF8String caseConversion(UTF8String s) {
}
}

@Override
protected String collationName() {
private String collationName() {
StringBuilder builder = new StringBuilder();
builder.append("UTF8_BINARY");
if (caseConversion != CaseConversion.UNSPECIFIED) {
Expand Down Expand Up @@ -382,8 +376,7 @@ public static class CollationSpecICU extends CollationSpec {

private CollationSpecICU(String locale, CaseSensitivity caseSensitivity,
AccentSensitivity accentSensitivity, CaseConversion caseConversion) {
super(ImplementationProvider.ICU, locale, caseSensitivity,
accentSensitivity, caseConversion);
super(locale, caseSensitivity, accentSensitivity, caseConversion);
}

public static int collationNameToId(String collationName) throws SparkException {
Expand Down Expand Up @@ -419,17 +412,18 @@ public static CollationSpecICU fromCollationId(int collationId) {
}

@Override
public int getCollationId() {
protected int getCollationId() {
int collationId = 0;
collationId |= implementationProvider.ordinal() << implementationProviderOffset;
collationId |= ImplementationProvider.ICU.ordinal() << implementationProviderOffset;
collationId |= caseSensitivity.ordinal() << caseSensitivityOffset;
collationId |= accentSensitivity.ordinal() << accentSensitivityOffset;
collationId |= caseConversion.ordinal() << caseConversionOffset;
collationId |= ICULocaleToId.get(locale);
return collationId;
}

public Collation buildCollation() {
@Override
protected Collation buildCollation() {
ULocale.Builder builder = new ULocale.Builder();
builder.setLocale(ICULocaleMap.get(locale));
if (caseSensitivity == CaseSensitivity.CS &&
Expand Down Expand Up @@ -473,8 +467,7 @@ private String caseConversion(ULocale locale, UTF8String s) {
}
}

@Override
protected String collationName() {
private String collationName() {
StringBuilder builder = new StringBuilder();
if (locale.equals("UNICODE")) {
builder.append("UNICODE");
Expand Down

0 comments on commit 7317811

Please sign in to comment.