Skip to content

Commit

Permalink
JSONLookupValue.concat
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Dec 3, 2017
1 parent 98dea5a commit bebf944
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Joiner;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;

Expand Down Expand Up @@ -138,6 +139,23 @@ public static JSONLookupValue unknown(final int id)
return of(id, "<" + id + ">");
}

public static final JSONLookupValue concat(final JSONLookupValue lookupValue1, final JSONLookupValue lookupValue2)
{
if (lookupValue1 == null)
{
return lookupValue2;
}
if (lookupValue2 == null)
{
return lookupValue1;
}

final String key = Joiner.on("_").skipNulls().join(lookupValue1.getKey(), lookupValue2.getKey());
final String caption = Joiner.on(" ").skipNulls().join(lookupValue1.getCaption(), lookupValue2.getCaption());
return JSONLookupValue.of(key, caption);

}

// IMPORTANT: when changing this property name, pls also check/change de.metas.handlingunits.attribute.impl.AbstractAttributeValue.extractKey(Map<String, String>, I_M_Attribute)
private static final String PROPERTY_Key = "key";
@JsonProperty(PROPERTY_Key)
Expand Down

0 comments on commit bebf944

Please sign in to comment.