BundleFilter { public static BundleFilter fromString(String text) { final String[] parameters = text.split(String.valueOf(PARAMETER_SEPARATOR)); final BundleFilter filter = new BundleFilter(); for (String parameter : parameters) { if (parameter.startsWith(PROVIDER_TAG)) { final String[] providers = parameter.substring(PROVIDER_TAG.length()).split(String.valueOf(VALUE_SEPARATOR)); for (String provider : providers) { filter.withProvider(provider); } } else if (parameter.startsWith(BUNDLE_TAG)) { final String[] bundleInfos = parameter.substring(BUNDLE_TAG.length()).split(String.valueOf(VALUE_SEPARATOR)); filter.withTheBundle(bundleInfos[0], bundleInfos[1]); } else if (parameter.startsWith(PROCESSOR_TAG)) { final String[] processorInfos = parameter.substring(PROCESSOR_TAG.length()).split(String.valueOf(VALUE_SEPARATOR)); filter.withTheProcessor(processorInfos[0], processorInfos[1]); } else if (parameter.startsWith(USER_TAG)) { filter.withTheUser(parameter.substring(USER_TAG.length())); } else { throw new IllegalArgumentException("Tag provider=, bundle= or processor= not found in '" + text + "'"); } } return filter; } BundleFilter(); boolean isProviderSupported(String provider); int getNumSupportedProvider(); String getBundleName(); String getBundleVersion(); String getProcessorName(); String getProcessorVersion(); String getUserName(); BundleFilter withProvider(String provider); BundleFilter withTheUser(String userName); BundleFilter withTheBundle(String bundleName, String bundleVersion); BundleFilter withTheProcessor(String processorName, String processorVersion); @Override String toString(); static BundleFilter fromString(String text); static final String PROVIDER_SYSTEM; static final String PROVIDER_USER; static final String PROVIDER_ALL_USERS; static final String DUMMY_PROCESSOR_NAME; }
@Test public void testFromString() throws Exception { final BundleFilter filter = BundleFilter.fromString("provider=SYSTEM,USER;bundle=coastcolour,1.6;processor=idepix,1.8-cc;user=Hugo"); assertTrue(filter.isProviderSupported(BundleFilter.PROVIDER_SYSTEM)); assertTrue(filter.isProviderSupported(BundleFilter.PROVIDER_USER)); assertFalse(filter.isProviderSupported(BundleFilter.PROVIDER_ALL_USERS)); assertEquals("coastcolour", filter.getBundleName()); assertEquals("1.6", filter.getBundleVersion()); assertEquals("idepix", filter.getProcessorName()); assertEquals("1.8-cc", filter.getProcessorVersion()); assertEquals("Hugo", filter.getUserName()); }