Skip to content

Commit

Permalink
PolyString support for lang
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Mar 20, 2019
1 parent c1c2846 commit ba377e1
Show file tree
Hide file tree
Showing 20 changed files with 588 additions and 30 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2018 Evolveum
* Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,6 +30,7 @@
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

import java.io.Serializable;
import java.util.Map;
import java.util.regex.Pattern;

import javax.xml.namespace.QName;
Expand All @@ -53,10 +54,12 @@ public class PolyString implements Matchable<PolyString>, Recomputable, Structur
public static final ItemName F_ORIG = new ItemName(PrismConstants.NS_TYPES, "orig");
public static final ItemName F_NORM = new ItemName(PrismConstants.NS_TYPES, "norm");
public static final ItemName F_TRANSLATION = new ItemName(PrismConstants.NS_TYPES, "translation");
public static final ItemName F_LANG = new ItemName(PrismConstants.NS_TYPES, "lang");

private final String orig;
private String norm = null;
private PolyStringTranslationType translation;
private Map<String,String> lang;

public PolyString(String orig) {
super();
Expand All @@ -75,10 +78,24 @@ public PolyString(String orig, String norm) {
this.norm = norm;
}

// TODO: we may need a builder for this ... hopefully I do not expect that there will be
// any more properties in a near future

public PolyString(String orig, String norm, PolyStringTranslationType translation) {
this(orig, norm);
this.translation = translation;
}

public PolyString(String orig, String norm, Map<String,String> lang) {
this(orig, norm);
this.lang = lang;
}

public PolyString(String orig, String norm, PolyStringTranslationType translation, Map<String,String> lang) {
this(orig, norm);
this.translation = translation;
this.lang = lang;
}

public String getOrig() {
return orig;
Expand All @@ -92,6 +109,10 @@ public PolyStringTranslationType getTranslation() {
return translation;
}

public Map<String, String> getLang() {
return lang;
}

/**
* Do NOT rely on this method too much. It may disappear later, e.g. when we align PolyString and PolyString type and
* make PolyString really immutable.
Expand All @@ -100,6 +121,15 @@ public PolyStringTranslationType getTranslation() {
public void setTranslation(PolyStringTranslationType translation) {
this.translation = translation;
}

/**
* Do NOT rely on this method too much. It may disappear later, e.g. when we align PolyString and PolyString type and
* make PolyString really immutable.
*/
@Experimental
public void setLang(Map<String, String> lang) {
this.lang = lang;
}

public boolean isEmpty() {
if (orig == null) {
Expand Down Expand Up @@ -135,6 +165,8 @@ public Object resolve(ItemPath subpath) {
return norm;
} else if (QNameUtil.match(F_TRANSLATION, itemName)) {
return translation;
} else if (QNameUtil.match(F_LANG, itemName)) {
return lang;
} else {
throw new IllegalArgumentException("Unknown path segment "+itemName);
}
Expand Down Expand Up @@ -206,6 +238,7 @@ public boolean endsWith(String value) {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((lang == null) ? 0 : lang.hashCode());
result = prime * result + ((norm == null) ? 0 : norm.hashCode());
result = prime * result + ((orig == null) ? 0 : orig.hashCode());
result = prime * result + ((translation == null) ? 0 : translation.hashCode());
Expand All @@ -214,28 +247,44 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
PolyString other = (PolyString) obj;
if (lang == null) {
if (other.lang != null) {
return false;
}
} else if (!lang.equals(other.lang)) {
return false;
}
if (norm == null) {
if (other.norm != null)
if (other.norm != null) {
return false;
} else if (!norm.equals(other.norm))
}
} else if (!norm.equals(other.norm)) {
return false;
}
if (orig == null) {
if (other.orig != null)
if (other.orig != null) {
return false;
} else if (!orig.equals(other.orig))
}
} else if (!orig.equals(other.orig)) {
return false;
}
if (translation == null) {
if (other.translation != null)
if (other.translation != null) {
return false;
} else if (!translation.equals(other.translation))
}
} else if (!translation.equals(other.translation)) {
return false;
}
return true;
}

Expand Down Expand Up @@ -275,6 +324,10 @@ public String debugDump(int indent) {
sb.append(";translation=");
sb.append(translation.getKey());
}
if (lang != null) {
sb.append(";lang=");
sb.append(lang);
}
sb.append(")");
return sb.toString();
}
Expand Down

0 comments on commit ba377e1

Please sign in to comment.