SpecialAgentUtil { static Event[] digestEventsProperty(final String eventsProperty) { if (eventsProperty == null) return DEFAULT_EVENTS; final String[] parts = eventsProperty.split(","); Arrays.sort(parts); final Event[] events = Event.values(); for (int i = 0, j = 0; i < events.length;) { final int comparison = j < parts.length ? events[i].name().compareTo(parts[j]) : -1; if (comparison < 0) { events[i] = null; ++i; } else if (comparison > 0) { ++j; } else { ++i; ++j; } } return events; } private  SpecialAgentUtil(); static Enumeration<T> enumeration(final T[] a);  }
@Test public void testDigestEventsProperty() { Event[] events = SpecialAgentUtil.digestEventsProperty(null); for (int i = 0; i < events.length; ++i) assertNull(events[i]); events = SpecialAgentUtil.digestEventsProperty("DISCOVERY,TRANSFORMATION,IGNORED,ERROR,COMPLETE"); for (final Event event : events) assertNotNull(event); events = SpecialAgentUtil.digestEventsProperty(""); for (final Event event : events) assertNull(event); events = SpecialAgentUtil.digestEventsProperty("DISCOVERY"); assertNotNull(events[Event.DISCOVERY.ordinal()]); assertNull(events[Event.COMPLETE.ordinal()]); assertNull(events[Event.TRANSFORMATION.ordinal()]); assertNull(events[Event.ERROR.ordinal()]); assertNull(events[Event.IGNORED.ordinal()]); events = SpecialAgentUtil.digestEventsProperty("TRANSFORMATION,COMPLETE"); assertNotNull(events[Event.TRANSFORMATION.ordinal()]); assertNotNull(events[Event.COMPLETE.ordinal()]); assertNull(events[Event.DISCOVERY.ordinal()]); assertNull(events[Event.ERROR.ordinal()]); assertNull(events[Event.IGNORED.ordinal()]); }