Skip to content

Commit

Permalink
match type changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sania-16 committed Dec 8, 2024
1 parent b3b297a commit aba0c96
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class FieldDefinition implements Named,

@JsonDeserialize(using = MatchTypeDeserializer.class)
@JsonSerialize(using = MatchTypeSerializer.class)
public List<MatchType> matchType;
public List<? extends IMatchType> matchType;

//@JsonSerialize(using = DataTypeSerializer.class)
public String dataType;
Expand All @@ -61,7 +61,7 @@ public FieldDefinition() {
*
* @return the type
*/
public List<MatchType> getMatchType() {
public List<? extends IMatchType> getMatchType() {
return matchType;
}

Expand Down Expand Up @@ -185,17 +185,17 @@ public void serialize(DataType dType, JsonGenerator jsonGenerator,
}
}*/

public static class MatchTypeSerializer extends StdSerializer<List<MatchType>> {
public static class MatchTypeSerializer extends StdSerializer<List<? extends IMatchType>> {
public MatchTypeSerializer() {
this(null);
}

public MatchTypeSerializer(Class<List<MatchType>> t) {
public MatchTypeSerializer(Class<List<? extends IMatchType>> t) {
super(t);
}

@Override
public void serialize(List<MatchType> matchType, JsonGenerator jsonGen, SerializerProvider provider)
public void serialize(List<? extends IMatchType> matchType, JsonGenerator jsonGen, SerializerProvider provider)
throws IOException, JsonProcessingException {
try {
jsonGen.writeObject(getStringFromMatchType(matchType));
Expand All @@ -205,14 +205,14 @@ public void serialize(List<MatchType> matchType, JsonGenerator jsonGen, Serializ
}
}

public static String getStringFromMatchType(List<MatchType> matchType) throws ZinggClientException {
public static String getStringFromMatchType(List<? extends IMatchType> matchType) throws ZinggClientException {
return String.join(",", matchType.stream()
.map(p -> p.value())
.collect(Collectors.toList()));
}
}

public static class MatchTypeDeserializer extends StdDeserializer<List<MatchType>> {
public static class MatchTypeDeserializer extends StdDeserializer<List<? extends IMatchType>> {
private static final long serialVersionUID = 1L;

public MatchTypeDeserializer() {
Expand All @@ -222,7 +222,7 @@ public MatchTypeDeserializer(Class<String> t) {
super(t);
}
@Override
public List<MatchType> deserialize(JsonParser parser, DeserializationContext context)
public List<? extends IMatchType> deserialize(JsonParser parser, DeserializationContext context)
throws IOException, JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
try{
Expand All @@ -235,7 +235,7 @@ public List<MatchType> deserialize(JsonParser parser, DeserializationContext con
}
}

public static List<MatchType> getMatchTypeFromString(String m) throws ZinggClientException{
public static List<? extends IMatchType> getMatchTypeFromString(String m) throws ZinggClientException{
List<MatchType> matchTypes = new ArrayList<MatchType>();
String[] matchTypeFromConfig = m.split(",");
for (String s: matchTypeFromConfig) {
Expand Down
10 changes: 10 additions & 0 deletions common/client/src/main/java/zingg/common/client/IMatchType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package zingg.common.client;

public interface IMatchType extends Named {

public String getValue();

Check warning

Code scanning / PMD

Unnecessary modifier 'private' on constructor 'LabelMatchType(Double, String)': enum constructors are implicitly private Warning

Unnecessary modifier 'public' on method 'getValue': the method is declared in an interface type

public void setValue(String value);

Check warning

Code scanning / PMD

Unnecessary modifier 'private' on constructor 'LabelMatchType(Double, String)': enum constructors are implicitly private Warning

Unnecessary modifier 'public' on method 'setValue': the method is declared in an interface type

}

83 changes: 24 additions & 59 deletions common/client/src/main/java/zingg/common/client/MatchType.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,75 +12,40 @@
* definitions and the user guide for more details
*/

public enum MatchType implements Serializable {
/**
* Short words like first names and organizations with focus on first
* characters matching
*/
FUZZY("FUZZY"),
public enum MatchType implements IMatchType {

/**
* Fields needing exact matches
*/
EXACT("EXACT"),


/**
* Many times pin code is xxxxx-xxxx and has to be matched with xxxxx.
*/
PINCODE("PINCODE"),

/**
* an email type which is supposed to look at only the first part of the email and ignore the domain.
*/
EMAIL("EMAIL"),

/**
* Long descriptive text, usually more than a couple of words for example
* product descriptions
*/
TEXT("TEXT"),
private String value;
private String name;

/**
* Strings containing numbers which need to be same. Example in addresses,
* we dont want 4th street to match 5th street
* Matching numbers with deviations
*/
NUMERIC("NUMERIC"),
/*eg P301d, P00231*/
NUMERIC_WITH_UNITS("NUMBER_WITH_UNITS"),
NULL_OR_BLANK("NULL_OR_BLANK"),
ONLY_ALPHABETS_EXACT("ONLY_ALPHABETS_EXACT"),
ONLY_ALPHABETS_FUZZY("ONLY_ALPHABETS_FUZZY"),
DONT_USE("DONT_USE");
MatchType(String n){
this.name = n;
this.value = n;
}

private String value;
private static Map<String, MatchType> types;
MatchType(String n, String v){
this.name = n;
this.value = v;
}

MatchType(String type) {
this.value = type;
@Override
public String getName() {
return this.name;
}

private static void init() {
types = new HashMap<String, MatchType>();
for (MatchType f : MatchType.values()) {
types.put(f.value, f);
}
@Override
public void setName(String name) {
this.name = name;
}

@JsonCreator
public static MatchType getMatchType(String t) throws ZinggClientException{
if (types == null) {
init();
}
MatchType type = types.get(t.trim().toUpperCase());
if (type == null) throw new ZinggClientException("Unsupported Match Type: " + t);
return type;
@Override
public String getValue() {
return this.value;
}

@JsonValue
public String value() {
return value;
@Override
public void setValue(String value) {
this.value = value;
}


}
54 changes: 54 additions & 0 deletions common/client/src/main/java/zingg/common/client/MatchTypes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package zingg.common.client;

import java.util.HashMap;
import java.util.Map;

public class MatchTypes {

Check warning

Code scanning / PMD

This utility class has a non-private constructor Warning

This utility class has a non-private constructor

public final static IMatchType FUZZY = new MatchType("FUZZY");
public final static IMatchType EXACT = new MatchType("EXACT");
public final static IMatchType PINCODE = new MatchType("PINCODE");
public final static IMatchType EMAIL = new MatchType("EMAIL");
public final static IMatchType TEXT = new MatchType("TEXT");
public final static IMatchType NUMERIC = new MatchType("NUMERIC");
public final static IMatchType NUMERIC_WITH_UNITS = new MatchType("NUMERIC_WITH_UNITS");
public final static IMatchType NULL_OR_BLANK = new MatchType("NULL_OR_BLANK");
public final static IMatchType ONLY_ALPHABETS_EXACT = new MatchType("ONLY_ALPHABETS_EXACT");
public final static IMatchType ONLY_ALPHABETS_FUZZY = new MatchType("ONLY_ALPHABETS_FUZZY");
public final static IMatchType DONT_USE = new MatchType("DONT_USE");

public static Map<String, IMatchType> allMatchTypes;// = new HashMap<String, IMatchType>();

protected MatchTypes(){

Check warning

Code scanning / PMD

Document empty constructor Warning

Document empty constructor

}

public static final void put(IMatchType o) {

if (allMatchTypes == null) {
allMatchTypes = new HashMap<String, IMatchType>();
}

Check warning

Code scanning / PMD

Singleton is not thread safe Warning

Singleton is not thread safe

allMatchTypes.put(o.getName(), o);
}

public static String[] getAllMatchTypes() {
IMatchType[] zo = allMatchTypes.values().toArray(new IMatchType[allMatchTypes.size()]);

Check warning

Code scanning / PMD

This call to Collection.toArray() may be optimizable Warning

This call to Collection.toArray() may be optimizable
int i = 0;
String[] s = new String[zo.length];
for (IMatchType z: zo) {
s[i++] = z.getName();
}
return s;
}

public static final IMatchType getByValue(String value){

for (IMatchType zo: MatchTypes.allMatchTypes.values()) {

Check warning

Code scanning / PMD

Unnecessary qualifier 'LabelMatchType': 'values' is already in scope Warning

Unnecessary qualifier 'MatchTypes': 'allMatchTypes' is already in scope because it is declared in an enclosing type
if (zo.getName().equals(value))
return zo;

Check warning

Code scanning / PMD

This statement should have braces Warning

This statement should have braces
}
return null;
}

}

0 comments on commit aba0c96

Please sign in to comment.