-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* AVRO-3473: ServiceLoader for Conversion Automatically register Conversion classes using the Java 6 service loader upon startup. This works for any Conversion that does not need constructor parameters. * AVRO-3473: ServiceLoader for Conversion Improved variable name. * AVRO-3473: Spotless * Apply suggestions from code review Co-authored-by: Ryan Skraba <[email protected]> * AVRO-3473: Removed newline to trigger build * AVRO-3473: Add missing import No idea when that got dropped... * AVRO-3473: Removed unused import * AVRO-3473: Fix rebase errors * Fix static imports --------- Co-authored-by: Ryan Skraba <[email protected]>
- Loading branch information
1 parent
adc0b5a
commit 72beda3
Showing
10 changed files
with
238 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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 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 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
48 changes: 48 additions & 0 deletions
48
lang/java/avro/src/test/java/org/apache/avro/CustomType.java
This file contains 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,48 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF 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 | ||
* | ||
* https://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.apache.avro; | ||
|
||
import java.util.Objects; | ||
|
||
public final class CustomType { | ||
private final String name; | ||
|
||
public CustomType(CharSequence name) { | ||
this.name = name.toString(); | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(name); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
return obj instanceof CustomType && name.equals(((CustomType) obj).name); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CustomType{name='" + name + "'}"; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
lang/java/avro/src/test/java/org/apache/avro/CustomTypeConverter.java
This file contains 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,48 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF 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 | ||
* | ||
* https://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.apache.avro; | ||
|
||
public class CustomTypeConverter extends Conversion<CustomType> { | ||
private static final CustomTypeLogicalTypeFactory logicalTypeFactory = new CustomTypeLogicalTypeFactory(); | ||
|
||
@Override | ||
public Class<CustomType> getConvertedType() { | ||
return CustomType.class; | ||
} | ||
|
||
@Override | ||
public String getLogicalTypeName() { | ||
return logicalTypeFactory.getTypeName(); | ||
} | ||
|
||
@Override | ||
public Schema getRecommendedSchema() { | ||
return Schema.create(Schema.Type.STRING); | ||
} | ||
|
||
@Override | ||
public CustomType fromCharSequence(CharSequence value, Schema schema, LogicalType type) { | ||
return new CustomType(value); | ||
} | ||
|
||
@Override | ||
public CharSequence toCharSequence(CustomType value, Schema schema, LogicalType type) { | ||
return value.getName(); | ||
} | ||
} |
This file contains 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 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
Oops, something went wrong.