@Override public Tags convertToEntityAttribute(String dbData) { return new Tags(dbData); } }
@Override public Object replace(Object original, Object target, Object owner) throws HibernateException { if (original != null) return new Tags(original.toString()); return null; } }
@Override public Object deepCopy(Object value) throws HibernateException { if (value == null) return null; return new Tags(value.toString()); }
/** * Retrieve an instance of the mapped class from a JDBC resultset. Implementors * should handle possibility of null values. * * @param rs a JDBC result set * @param names the column names * @param session * @param owner the containing entity @return Object * @throws HibernateException * @throws SQLException */ @Override public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { String tags = rs.getString(names[0]); if (rs.wasNull()) return null; return new Tags(tags); }
/** * @param tag to add * @return this */ public GLEntry addTag (String tag) { if (tags == null) tags = new Tags(); tags.add(tag); return this; } public boolean hasTag (String tag) {
@Override public Result<Tags> convertToModel(String value, ValueContext context) { if (value != null && !value.isEmpty()) return Result.ok(new Tags(value)); return Result.ok(null); }
@Test public void testContainsAll() { Tags ts = new Tags("abc,def,ghi"); assertTrue(ts.containsAll(new Tags("def,ghi"))); assertTrue(ts.containsAll(new Tags("abc,def"))); assertTrue(ts.containsAll(new Tags("abc,ghi,def"))); assertTrue(ts.containsAll(new Tags())); assertTrue(new Tags().containsAll(new Tags())); assertFalse(ts.containsAll(new Tags("abc,jkl"))); }
@Test public void testContainsAny() { Tags ts = new Tags("abc,def,ghi"); assertTrue(ts.containsAny(new Tags("abc,def"))); assertTrue(ts.containsAny(new Tags("abc,jkl"))); assertTrue(ts.containsAny(new Tags(""))); assertTrue(new Tags().containsAny(new Tags())); assertFalse(ts.containsAny(new Tags("jkl,mno"))); } }
@Test public void testSerialization() throws Throwable { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Tags ts1 = new Tags("xyz,abc"); new ObjectOutputStream(baos).writeObject(ts1); byte[] buf = baos.toByteArray(); ObjectInputStream is = new ObjectInputStream(new ByteArrayInputStream(buf)); Tags ts2 = (Tags) is.readObject(); assertTrue(ts1.equals(ts2)); assertTrue(ts1.hashCode() == ts2.hashCode()); assertEquals(ts1.toString(), ts2.toString()); }
/** * Parses a JDOM Element as defined in * <a href="http://jpos.org/minigl.dtd">minigl.dtd</a> */ public void fromXML (Element elem) throws ParseException { setDetail (elem.getChildTextTrim ("detail")); setTags (new Tags(elem.getChildTextTrim ("tags"))); setCredit ("credit".equals (elem.getAttributeValue("type"))); setLayer(toShort(elem.getAttributeValue("layer"))); setAmount(new BigDecimal (elem.getChild ("amount").getText())); } /**
@Test public void testEscape () { Tags ts = new Tags("d\\,ef,abc\\\\"); assertEquals("abc\\\\,d\\,ef", ts.toString()); }
@Test public void testEmpty () { Tags ts = new Tags(); assertEquals("", ts.toString()); }
@Test public void testOrder () { Tags ts = new Tags("def,abc"); assertEquals("abc,def", ts.toString()); }
/** * Parses a JDOM Element as defined in * <a href="http://jpos.org/minigl.dtd">minigl.dtd</a> */ public void fromXML (Element elem) throws ParseException { setDetail (elem.getChildTextTrim ("detail")); setTags (new Tags(elem.getChildTextTrim ("tags"))); setPostDate ( Util.parseDate (elem.getAttributeValue ("post-date")) ); setTimestamp ( Util.parseDateTime (elem.getAttributeValue ("date")) ); } /**
setType (0); setTags (new Tags(elem.getChildTextTrim ("tags"))); Account p = getParent(); if (p != null) {
@Test public void testEqualsAndHashCode () { Tags ts1 = new Tags("xyz,abc"); Tags ts2 = new Tags(ts1.toString()); Tags ts3 = new Tags("abc", "xyz"); assertTrue(ts1.equals(ts2)); assertTrue(ts1.hashCode() == ts2.hashCode()); assertTrue(ts1.equals(ts3)); assertTrue(ts1.hashCode() == ts3.hashCode()); ts2.add("xyz"); // dupe entry assertTrue(ts1.equals(ts2)); assertTrue(ts1.hashCode() == ts2.hashCode()); ts2.add("zyx"); assertFalse(ts1.equals(ts2)); assertFalse(ts1.hashCode() == ts2.hashCode()); }
/** * * Create a reverse transaction based on this one * * @param withTags entries with any tag in <code>withTags</code> are selected (can be null) * @param withoutTags entries with any tag in <code>withoutTags</code> are discarded (can be null) * * @return a reversal transaction */ public GLTransaction createReverse(Tags withTags, Tags withoutTags) { GLTransaction glt = new GLTransaction ("(" + getDetail() + ")"); glt.setJournal (getJournal()); for (GLEntry e : getEntries()) { Tags tags = e.getTags() != null ? e.getTags() : new Tags(); if ((withTags == null || tags.containsAll(withTags)) && (withoutTags == null || !tags.containsAny(withoutTags))) { glt.createGLEntry( e.getAccount(), negate(e.getAmount()), e.getDetail(), e.isCredit(), e.getLayer() ); } } return glt; }