Skip to content

Commit

Permalink
add tag related helpers (addTag, hasTag, removeTag, etc)
Browse files Browse the repository at this point in the history
  • Loading branch information
ar committed Oct 1, 2015
1 parent 236079b commit efb7dd6
Showing 1 changed file with 64 additions and 3 deletions.
67 changes: 64 additions & 3 deletions modules/minigl/src/main/java/org/jpos/gl/GLEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@

package org.jpos.gl;

import java.util.Iterator;
import java.util.Date;
import java.util.Arrays;
import java.math.BigDecimal;
import java.text.ParseException;
import org.jdom.Element;
import org.jdom.Comment;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.jpos.iso.ISOUtil;


/**
Expand Down Expand Up @@ -279,12 +278,74 @@ public boolean hasLayers (short[] layers) {
}
return false;
}
public void addTag (String tag) {
if (tag != null) {
if (tags == null || tags.length() == 0)
tags = tag;
else if (!hasTag(tag)) {
String[] tt = ISOUtil.commaDecode(tags);
String[] ss = new String[tt.length+1];
System.arraycopy (tt, 0, ss, 0, tt.length);
ss[tt.length] = tag;
Arrays.sort(ss);
tags = ISOUtil.commaEncode(ss);
}
}
}

public boolean removeTag (String tag) {
int removals = 0;
if (tags != null && tag != null) {
String[] tt = ISOUtil.commaDecode(tags);
for (int i=0; i<tt.length; i++) {
if (tt[i].equalsIgnoreCase(tag)) {
tt[i] = null;
removals++;
}
}
if (removals > 0) {
String[] ss = new String[tt.length-removals];
int i = 0;
for (String s : tt) {
if (s != null)
ss[i++] = s;
}
Arrays.sort(ss);
tags = ISOUtil.commaEncode(ss);
}
}
return removals > 0;
}

public void setTags(String[] tt) {
if (tt != null) {
Arrays.sort(tt);
tags = ISOUtil.commaEncode(tt);
}
else
tags = null;
}

public String[] getTagsAsArray() {
return (tags != null) ? ISOUtil.commaDecode(tags) : new String[]{};
}

public boolean hasTag (String tag) {
if (tags != null && tag != null) {
String[] tt = ISOUtil.commaDecode(tags);
for (String s : tt)
if (tag.equalsIgnoreCase(s))
return true;
}
return false;
}

public String toString() {
return new ToStringBuilder(this)
.append("id", getId())
.append("detail", getDetail())
.append("account", getAccount())
.append("tags", getTags())
.toString();
}
private short toShort (String s) {
Expand Down

0 comments on commit efb7dd6

Please # to comment.