POSUtils { public static void assignCoarseValue(POS pos) { if (pos == null) { return; } String shortName = pos.getType().getShortName(); if (!StringUtils.equals(pos.getType().getName(), POS.class.getName())) { if (!shortName.startsWith(POS_TYPE_PREFIX)) { throw new IllegalArgumentException("The type " + shortName + "of the given POS annotation does not fulfill the convention of starting with prefix '" + POS_TYPE_PREFIX + "'"); } pos.setCoarseValue(shortName.substring(POS_TYPE_PREFIX.length()).intern()); } } private  POSUtils(); static void assignCoarseValue(POS pos); static final String POS_TYPE_PREFIX; }
@Test public void testAssignCoarseValue() throws Exception { JCas jcas = JCasFactory.createJCas(); POS posPos = new POS(jcas); POS posNoun = new POS_NOUN(jcas); POSUtils.assignCoarseValue(null); POSUtils.assignCoarseValue(posPos); POSUtils.assignCoarseValue(posNoun); Assert.assertNull(posPos.getCoarseValue()); Assert.assertEquals("NOUN", posNoun.getCoarseValue()); }