target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test public void urlAsMavenUrl() { assertThat( "Scan features url", new FeaturesScannerProvisionOption( maven().groupId( "bar" ).artifactId( "foo" ).classifier( "features" ).type( "xml" ), "f1", "f2/1.0.0" ).getURL(), is( equalTo( "scan-features:mvn:bar/foo ); }
|
public String getURL() { final StringBuilder url = new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( SEPARATOR_FILTER ); boolean first = true; for( String feature : m_features ) { if( !first ) { url.append( FEATURE_SEPARATOR ); } first = false; url.append( feature ); } url.append( getOptions( this ) ); return url.toString(); }
|
FeaturesScannerProvisionOption extends AbstractUrlProvisionOption<FeaturesScannerProvisionOption> implements Scanner { public String getURL() { final StringBuilder url = new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( SEPARATOR_FILTER ); boolean first = true; for( String feature : m_features ) { if( !first ) { url.append( FEATURE_SEPARATOR ); } first = false; url.append( feature ); } url.append( getOptions( this ) ); return url.toString(); } }
|
FeaturesScannerProvisionOption extends AbstractUrlProvisionOption<FeaturesScannerProvisionOption> implements Scanner { public String getURL() { final StringBuilder url = new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( SEPARATOR_FILTER ); boolean first = true; for( String feature : m_features ) { if( !first ) { url.append( FEATURE_SEPARATOR ); } first = false; url.append( feature ); } url.append( getOptions( this ) ); return url.toString(); } FeaturesScannerProvisionOption( final String repositoryUrl,
final String... features ); FeaturesScannerProvisionOption( final UrlReference repositoryUrl,
final String... features ); }
|
FeaturesScannerProvisionOption extends AbstractUrlProvisionOption<FeaturesScannerProvisionOption> implements Scanner { public String getURL() { final StringBuilder url = new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( SEPARATOR_FILTER ); boolean first = true; for( String feature : m_features ) { if( !first ) { url.append( FEATURE_SEPARATOR ); } first = false; url.append( feature ); } url.append( getOptions( this ) ); return url.toString(); } FeaturesScannerProvisionOption( final String repositoryUrl,
final String... features ); FeaturesScannerProvisionOption( final UrlReference repositoryUrl,
final String... features ); String getURL(); }
|
FeaturesScannerProvisionOption extends AbstractUrlProvisionOption<FeaturesScannerProvisionOption> implements Scanner { public String getURL() { final StringBuilder url = new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( SEPARATOR_FILTER ); boolean first = true; for( String feature : m_features ) { if( !first ) { url.append( FEATURE_SEPARATOR ); } first = false; url.append( feature ); } url.append( getOptions( this ) ); return url.toString(); } FeaturesScannerProvisionOption( final String repositoryUrl,
final String... features ); FeaturesScannerProvisionOption( final UrlReference repositoryUrl,
final String... features ); String getURL(); }
|
@Test public void urlAsMavenUrlViaFactoryMethod() { assertThat( "Scan features url", scanFeatures( maven().groupId( "bar" ).artifactId( "foo" ).classifier( "features" ).type( "xml" ), "f1", "f2/1.0.0" ).getURL(), is( equalTo( "scan-features:mvn:bar/foo ); }
|
public String getURL() { final StringBuilder url = new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( SEPARATOR_FILTER ); boolean first = true; for( String feature : m_features ) { if( !first ) { url.append( FEATURE_SEPARATOR ); } first = false; url.append( feature ); } url.append( getOptions( this ) ); return url.toString(); }
|
FeaturesScannerProvisionOption extends AbstractUrlProvisionOption<FeaturesScannerProvisionOption> implements Scanner { public String getURL() { final StringBuilder url = new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( SEPARATOR_FILTER ); boolean first = true; for( String feature : m_features ) { if( !first ) { url.append( FEATURE_SEPARATOR ); } first = false; url.append( feature ); } url.append( getOptions( this ) ); return url.toString(); } }
|
FeaturesScannerProvisionOption extends AbstractUrlProvisionOption<FeaturesScannerProvisionOption> implements Scanner { public String getURL() { final StringBuilder url = new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( SEPARATOR_FILTER ); boolean first = true; for( String feature : m_features ) { if( !first ) { url.append( FEATURE_SEPARATOR ); } first = false; url.append( feature ); } url.append( getOptions( this ) ); return url.toString(); } FeaturesScannerProvisionOption( final String repositoryUrl,
final String... features ); FeaturesScannerProvisionOption( final UrlReference repositoryUrl,
final String... features ); }
|
FeaturesScannerProvisionOption extends AbstractUrlProvisionOption<FeaturesScannerProvisionOption> implements Scanner { public String getURL() { final StringBuilder url = new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( SEPARATOR_FILTER ); boolean first = true; for( String feature : m_features ) { if( !first ) { url.append( FEATURE_SEPARATOR ); } first = false; url.append( feature ); } url.append( getOptions( this ) ); return url.toString(); } FeaturesScannerProvisionOption( final String repositoryUrl,
final String... features ); FeaturesScannerProvisionOption( final UrlReference repositoryUrl,
final String... features ); String getURL(); }
|
FeaturesScannerProvisionOption extends AbstractUrlProvisionOption<FeaturesScannerProvisionOption> implements Scanner { public String getURL() { final StringBuilder url = new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( SEPARATOR_FILTER ); boolean first = true; for( String feature : m_features ) { if( !first ) { url.append( FEATURE_SEPARATOR ); } first = false; url.append( feature ); } url.append( getOptions( this ) ); return url.toString(); } FeaturesScannerProvisionOption( final String repositoryUrl,
final String... features ); FeaturesScannerProvisionOption( final UrlReference repositoryUrl,
final String... features ); String getURL(); }
|
@Test public void urlAsString() { assertThat( "Scan composite url", new CompositeScannerProvisionOption( "file:foo.composite" ).getURL(), is( equalTo( "scan-composite:file:foo.composite@update" ) ) ); }
|
public String getURL() { return new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( getOptions( this ) ) .toString(); }
|
CompositeScannerProvisionOption extends AbstractUrlProvisionOption<CompositeScannerProvisionOption> implements Scanner { public String getURL() { return new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( getOptions( this ) ) .toString(); } }
|
CompositeScannerProvisionOption extends AbstractUrlProvisionOption<CompositeScannerProvisionOption> implements Scanner { public String getURL() { return new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( getOptions( this ) ) .toString(); } CompositeScannerProvisionOption( final String url ); CompositeScannerProvisionOption( final UrlReference url ); }
|
CompositeScannerProvisionOption extends AbstractUrlProvisionOption<CompositeScannerProvisionOption> implements Scanner { public String getURL() { return new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( getOptions( this ) ) .toString(); } CompositeScannerProvisionOption( final String url ); CompositeScannerProvisionOption( final UrlReference url ); String getURL(); }
|
CompositeScannerProvisionOption extends AbstractUrlProvisionOption<CompositeScannerProvisionOption> implements Scanner { public String getURL() { return new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( getOptions( this ) ) .toString(); } CompositeScannerProvisionOption( final String url ); CompositeScannerProvisionOption( final UrlReference url ); String getURL(); }
|
@Test public void urlAsStringViaFactoryMethod() { assertThat( "Scan composite url", scanComposite( "file:foo.composite" ).getURL(), is( equalTo( "scan-composite:file:foo.composite@update" ) ) ); }
|
public String getURL() { return new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( getOptions( this ) ) .toString(); }
|
CompositeScannerProvisionOption extends AbstractUrlProvisionOption<CompositeScannerProvisionOption> implements Scanner { public String getURL() { return new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( getOptions( this ) ) .toString(); } }
|
CompositeScannerProvisionOption extends AbstractUrlProvisionOption<CompositeScannerProvisionOption> implements Scanner { public String getURL() { return new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( getOptions( this ) ) .toString(); } CompositeScannerProvisionOption( final String url ); CompositeScannerProvisionOption( final UrlReference url ); }
|
CompositeScannerProvisionOption extends AbstractUrlProvisionOption<CompositeScannerProvisionOption> implements Scanner { public String getURL() { return new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( getOptions( this ) ) .toString(); } CompositeScannerProvisionOption( final String url ); CompositeScannerProvisionOption( final UrlReference url ); String getURL(); }
|
CompositeScannerProvisionOption extends AbstractUrlProvisionOption<CompositeScannerProvisionOption> implements Scanner { public String getURL() { return new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( getOptions( this ) ) .toString(); } CompositeScannerProvisionOption( final String url ); CompositeScannerProvisionOption( final UrlReference url ); String getURL(); }
|
@Test public void urlAsReference() { assertThat( "Scan composite url", new CompositeScannerProvisionOption( url( "file:foo.composite" ) ).getURL(), is( equalTo( "scan-composite:file:foo.composite@update" ) ) ); }
|
public String getURL() { return new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( getOptions( this ) ) .toString(); }
|
CompositeScannerProvisionOption extends AbstractUrlProvisionOption<CompositeScannerProvisionOption> implements Scanner { public String getURL() { return new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( getOptions( this ) ) .toString(); } }
|
CompositeScannerProvisionOption extends AbstractUrlProvisionOption<CompositeScannerProvisionOption> implements Scanner { public String getURL() { return new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( getOptions( this ) ) .toString(); } CompositeScannerProvisionOption( final String url ); CompositeScannerProvisionOption( final UrlReference url ); }
|
CompositeScannerProvisionOption extends AbstractUrlProvisionOption<CompositeScannerProvisionOption> implements Scanner { public String getURL() { return new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( getOptions( this ) ) .toString(); } CompositeScannerProvisionOption( final String url ); CompositeScannerProvisionOption( final UrlReference url ); String getURL(); }
|
CompositeScannerProvisionOption extends AbstractUrlProvisionOption<CompositeScannerProvisionOption> implements Scanner { public String getURL() { return new StringBuilder() .append( SCHEMA ) .append( SEPARATOR_SCHEME ) .append( super.getURL() ) .append( getOptions( this ) ) .toString(); } CompositeScannerProvisionOption( final String url ); CompositeScannerProvisionOption( final UrlReference url ); String getURL(); }
|
@Test public void testGetDefaultAppPro(){ ConfigurationManager.setEnableDefaultload(true); System.out.println(ConfigurationManager.class.getProtectionDomain().getCodeSource().getLocation().toString()); URL url = getClass().getProtectionDomain().getCodeSource().getLocation(); try { InputStream in = ConfigurationManager.class.getClassLoader().getResourceAsStream("jar:"+url.toURI().toString()+"!/META-INF/MANIFEST.MF"); System.out.println(url.toURI().toString()); System.out.println(in); ZipInputStream zip = new ZipInputStream(url.openStream()); ZipEntry ze; while ((ze = zip.getNextEntry())!=null){ if(ze.getName().equals("META-INF/MANIFEST.MF")){ System.out.println(ze.getName()); break; } } System.out.println(IOUtils.readAll(zip)); } catch (URISyntaxException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } ConfigurationManager.setEnableDefaultload(false); }
|
static void setEnableDefaultload(boolean enabled){ enableDefaultload =enabled; }
|
ConfigurationManager { static void setEnableDefaultload(boolean enabled){ enableDefaultload =enabled; } }
|
ConfigurationManager { static void setEnableDefaultload(boolean enabled){ enableDefaultload =enabled; } }
|
ConfigurationManager { static void setEnableDefaultload(boolean enabled){ enableDefaultload =enabled; } static Map<String,Map<String,String>> getAllProperties(); static Map<String,String> getPropertiesByConfigName(String configName); static Set<String> getConfigKeys(String configName); static synchronized boolean isConfigurationInstalled(); static Configuration getConfigInstance(); static Configuration getConfigFromPropertiesFile(URL startingUrl); static Properties getPropertiesFromFile(URL startingUrl); static void installReadonlyProperties(Properties pros); }
|
ConfigurationManager { static void setEnableDefaultload(boolean enabled){ enableDefaultload =enabled; } static Map<String,Map<String,String>> getAllProperties(); static Map<String,String> getPropertiesByConfigName(String configName); static Set<String> getConfigKeys(String configName); static synchronized boolean isConfigurationInstalled(); static Configuration getConfigInstance(); static Configuration getConfigFromPropertiesFile(URL startingUrl); static Properties getPropertiesFromFile(URL startingUrl); static void installReadonlyProperties(Properties pros); }
|
@Test public void testLoadProperties() throws Exception { ConfigurationManager.loadPropertiesFromResources("test.properties"); assertEquals("9", ConfigurationManager.getConfigInstance().getProperty("com.ctrip.config.samples.needCount")); assertEquals("9", ConfigurationManager.getConfigInstance().getString("com.ctrip.config.samples.needCount")); assertEquals("100", ConfigurationManager.getConfigInstance().getString("no.exist","100")); }
|
static void loadProperties(Properties properties) throws InitConfigurationException { if (instance == null) { instance = getConfigInstance(); } ConfigurationUtils.loadProperties(properties, instance); }
|
ConfigurationManager { static void loadProperties(Properties properties) throws InitConfigurationException { if (instance == null) { instance = getConfigInstance(); } ConfigurationUtils.loadProperties(properties, instance); } }
|
ConfigurationManager { static void loadProperties(Properties properties) throws InitConfigurationException { if (instance == null) { instance = getConfigInstance(); } ConfigurationUtils.loadProperties(properties, instance); } }
|
ConfigurationManager { static void loadProperties(Properties properties) throws InitConfigurationException { if (instance == null) { instance = getConfigInstance(); } ConfigurationUtils.loadProperties(properties, instance); } static Map<String,Map<String,String>> getAllProperties(); static Map<String,String> getPropertiesByConfigName(String configName); static Set<String> getConfigKeys(String configName); static synchronized boolean isConfigurationInstalled(); static Configuration getConfigInstance(); static Configuration getConfigFromPropertiesFile(URL startingUrl); static Properties getPropertiesFromFile(URL startingUrl); static void installReadonlyProperties(Properties pros); }
|
ConfigurationManager { static void loadProperties(Properties properties) throws InitConfigurationException { if (instance == null) { instance = getConfigInstance(); } ConfigurationUtils.loadProperties(properties, instance); } static Map<String,Map<String,String>> getAllProperties(); static Map<String,String> getPropertiesByConfigName(String configName); static Set<String> getConfigKeys(String configName); static synchronized boolean isConfigurationInstalled(); static Configuration getConfigInstance(); static Configuration getConfigFromPropertiesFile(URL startingUrl); static Properties getPropertiesFromFile(URL startingUrl); static void installReadonlyProperties(Properties pros); }
|
@Test public void testNumberProperties() throws Exception { Configuration config = ConfigurationManager.getConfigInstance(); double val = 12.3; config.setProperty("test-double",val); assertTrue(val == config.getDouble("test-double")); config.setProperty("test-int",10); assertTrue(10 == config.getDouble("test-int")); assertTrue(0 == config.getDouble("test-int-emp")); assertTrue(20 == config.getInt("test-int-emp",20)); assertTrue(new Integer(23) == config.getInt("test-int-emp",new Integer(23))); assertEquals(false,config.getBoolean("test-boolean")); }
|
public static Configuration getConfigInstance() throws InitConfigurationException { if (instance == null) { synchronized (ConfigurationManager.class) { if (instance == null) { instance = createDefaultConfigInstance(); try { customProperties = Tools.loadPropertiesFromFile(TEMPFILENAME); } catch (Throwable e) { logger.error("load temp custom properties failed!", e); } if(customProperties!=null) { Iterator<String> keys = customProperties.getKeys(); while (keys.hasNext()) { String key = keys.next(); if (instance.containsKey(key)) { instance.setProperty(key, customProperties.getString(key)); } } } } } } return instance; }
|
ConfigurationManager { public static Configuration getConfigInstance() throws InitConfigurationException { if (instance == null) { synchronized (ConfigurationManager.class) { if (instance == null) { instance = createDefaultConfigInstance(); try { customProperties = Tools.loadPropertiesFromFile(TEMPFILENAME); } catch (Throwable e) { logger.error("load temp custom properties failed!", e); } if(customProperties!=null) { Iterator<String> keys = customProperties.getKeys(); while (keys.hasNext()) { String key = keys.next(); if (instance.containsKey(key)) { instance.setProperty(key, customProperties.getString(key)); } } } } } } return instance; } }
|
ConfigurationManager { public static Configuration getConfigInstance() throws InitConfigurationException { if (instance == null) { synchronized (ConfigurationManager.class) { if (instance == null) { instance = createDefaultConfigInstance(); try { customProperties = Tools.loadPropertiesFromFile(TEMPFILENAME); } catch (Throwable e) { logger.error("load temp custom properties failed!", e); } if(customProperties!=null) { Iterator<String> keys = customProperties.getKeys(); while (keys.hasNext()) { String key = keys.next(); if (instance.containsKey(key)) { instance.setProperty(key, customProperties.getString(key)); } } } } } } return instance; } }
|
ConfigurationManager { public static Configuration getConfigInstance() throws InitConfigurationException { if (instance == null) { synchronized (ConfigurationManager.class) { if (instance == null) { instance = createDefaultConfigInstance(); try { customProperties = Tools.loadPropertiesFromFile(TEMPFILENAME); } catch (Throwable e) { logger.error("load temp custom properties failed!", e); } if(customProperties!=null) { Iterator<String> keys = customProperties.getKeys(); while (keys.hasNext()) { String key = keys.next(); if (instance.containsKey(key)) { instance.setProperty(key, customProperties.getString(key)); } } } } } } return instance; } static Map<String,Map<String,String>> getAllProperties(); static Map<String,String> getPropertiesByConfigName(String configName); static Set<String> getConfigKeys(String configName); static synchronized boolean isConfigurationInstalled(); static Configuration getConfigInstance(); static Configuration getConfigFromPropertiesFile(URL startingUrl); static Properties getPropertiesFromFile(URL startingUrl); static void installReadonlyProperties(Properties pros); }
|
ConfigurationManager { public static Configuration getConfigInstance() throws InitConfigurationException { if (instance == null) { synchronized (ConfigurationManager.class) { if (instance == null) { instance = createDefaultConfigInstance(); try { customProperties = Tools.loadPropertiesFromFile(TEMPFILENAME); } catch (Throwable e) { logger.error("load temp custom properties failed!", e); } if(customProperties!=null) { Iterator<String> keys = customProperties.getKeys(); while (keys.hasNext()) { String key = keys.next(); if (instance.containsKey(key)) { instance.setProperty(key, customProperties.getString(key)); } } } } } } return instance; } static Map<String,Map<String,String>> getAllProperties(); static Map<String,String> getPropertiesByConfigName(String configName); static Set<String> getConfigKeys(String configName); static synchronized boolean isConfigurationInstalled(); static Configuration getConfigInstance(); static Configuration getConfigFromPropertiesFile(URL startingUrl); static Properties getPropertiesFromFile(URL startingUrl); static void installReadonlyProperties(Properties pros); }
|
@Test public void testLoadCascadedProperties() throws Exception { ConfigurationManager.loadCascadedPropertiesFromResources("config/test"); assertEquals("7", ConfigurationManager.getConfigInstance().getProperty("com.ctrip.config.samples.needCount")); assertEquals("1", ConfigurationManager.getConfigInstance().getProperty("cascaded.property")); }
|
private static Properties loadCascadedProperties(String configName) throws IOException { String defaultConfigFileName = configName + ".properties"; ClassLoader loader = Thread.currentThread().getContextClassLoader(); URL url = loader.getResource(defaultConfigFileName); if (url == null) { throw new IOException("Cannot locate " + defaultConfigFileName + " as a classpath resource."); } Properties props = getPropertiesFromFile(url); String environment = EnFactory.getEnBase().getEnvType(); if(environment!=null) { environment = environment.toLowerCase(); } if (environment != null && environment.length() > 0) { String envConfigFileName = configName + "-" + environment + ".properties"; url = loader.getResource(envConfigFileName); if(url==null){ url = loader.getResource(configName.replace("config/",environment+"-config/") +".properties"); } if (url != null) { Properties envProps = getPropertiesFromFile(url); if (envProps != null) { props.putAll(envProps); } } } return props; }
|
ConfigurationManager { private static Properties loadCascadedProperties(String configName) throws IOException { String defaultConfigFileName = configName + ".properties"; ClassLoader loader = Thread.currentThread().getContextClassLoader(); URL url = loader.getResource(defaultConfigFileName); if (url == null) { throw new IOException("Cannot locate " + defaultConfigFileName + " as a classpath resource."); } Properties props = getPropertiesFromFile(url); String environment = EnFactory.getEnBase().getEnvType(); if(environment!=null) { environment = environment.toLowerCase(); } if (environment != null && environment.length() > 0) { String envConfigFileName = configName + "-" + environment + ".properties"; url = loader.getResource(envConfigFileName); if(url==null){ url = loader.getResource(configName.replace("config/",environment+"-config/") +".properties"); } if (url != null) { Properties envProps = getPropertiesFromFile(url); if (envProps != null) { props.putAll(envProps); } } } return props; } }
|
ConfigurationManager { private static Properties loadCascadedProperties(String configName) throws IOException { String defaultConfigFileName = configName + ".properties"; ClassLoader loader = Thread.currentThread().getContextClassLoader(); URL url = loader.getResource(defaultConfigFileName); if (url == null) { throw new IOException("Cannot locate " + defaultConfigFileName + " as a classpath resource."); } Properties props = getPropertiesFromFile(url); String environment = EnFactory.getEnBase().getEnvType(); if(environment!=null) { environment = environment.toLowerCase(); } if (environment != null && environment.length() > 0) { String envConfigFileName = configName + "-" + environment + ".properties"; url = loader.getResource(envConfigFileName); if(url==null){ url = loader.getResource(configName.replace("config/",environment+"-config/") +".properties"); } if (url != null) { Properties envProps = getPropertiesFromFile(url); if (envProps != null) { props.putAll(envProps); } } } return props; } }
|
ConfigurationManager { private static Properties loadCascadedProperties(String configName) throws IOException { String defaultConfigFileName = configName + ".properties"; ClassLoader loader = Thread.currentThread().getContextClassLoader(); URL url = loader.getResource(defaultConfigFileName); if (url == null) { throw new IOException("Cannot locate " + defaultConfigFileName + " as a classpath resource."); } Properties props = getPropertiesFromFile(url); String environment = EnFactory.getEnBase().getEnvType(); if(environment!=null) { environment = environment.toLowerCase(); } if (environment != null && environment.length() > 0) { String envConfigFileName = configName + "-" + environment + ".properties"; url = loader.getResource(envConfigFileName); if(url==null){ url = loader.getResource(configName.replace("config/",environment+"-config/") +".properties"); } if (url != null) { Properties envProps = getPropertiesFromFile(url); if (envProps != null) { props.putAll(envProps); } } } return props; } static Map<String,Map<String,String>> getAllProperties(); static Map<String,String> getPropertiesByConfigName(String configName); static Set<String> getConfigKeys(String configName); static synchronized boolean isConfigurationInstalled(); static Configuration getConfigInstance(); static Configuration getConfigFromPropertiesFile(URL startingUrl); static Properties getPropertiesFromFile(URL startingUrl); static void installReadonlyProperties(Properties pros); }
|
ConfigurationManager { private static Properties loadCascadedProperties(String configName) throws IOException { String defaultConfigFileName = configName + ".properties"; ClassLoader loader = Thread.currentThread().getContextClassLoader(); URL url = loader.getResource(defaultConfigFileName); if (url == null) { throw new IOException("Cannot locate " + defaultConfigFileName + " as a classpath resource."); } Properties props = getPropertiesFromFile(url); String environment = EnFactory.getEnBase().getEnvType(); if(environment!=null) { environment = environment.toLowerCase(); } if (environment != null && environment.length() > 0) { String envConfigFileName = configName + "-" + environment + ".properties"; url = loader.getResource(envConfigFileName); if(url==null){ url = loader.getResource(configName.replace("config/",environment+"-config/") +".properties"); } if (url != null) { Properties envProps = getPropertiesFromFile(url); if (envProps != null) { props.putAll(envProps); } } } return props; } static Map<String,Map<String,String>> getAllProperties(); static Map<String,String> getPropertiesByConfigName(String configName); static Set<String> getConfigKeys(String configName); static synchronized boolean isConfigurationInstalled(); static Configuration getConfigInstance(); static Configuration getConfigFromPropertiesFile(URL startingUrl); static Properties getPropertiesFromFile(URL startingUrl); static void installReadonlyProperties(Properties pros); }
|
@Test public void testConfig(){ String path = "/config/all"; VIApiHandler.ExeResult rtn = handler.executeService(path, user, null); Map<String,Object> data = (Map<String, Object>) rtn.getData(); assertTrue(data.size()>0); assertTrue(data.containsKey("test")); }
|
public ExeResult executeService(String path,String user,Map<String,Object> params){ long startTime = System.nanoTime(); Object rtn=null; int responseCode = SC_OK; int permission = Permission.ALL.getValue(); EventLogger eventLogger = EventLoggerFactory.getTransLogger(getClass()); if(path == null){ return new ExeResult("NO PATH ERROR",0,SC_NOTFOUND); } path = path.toLowerCase(); boolean isHandled =false; try { eventLogger.fireEvent(EventLogger.TRANSSTART,path); switch (path) { case "/ip": rtn = params.get("req_ip"); isHandled = true; break; case "/status": case "/health": AppInfo appInfo = ComponentManager.getStatus(AppInfo.class); switch (appInfo.getStatus()) { case Uninitiated: responseCode = AppInfo.UNINITIATED; break; case Initiating: responseCode = AppInfo.INITIATING; break; case Initiated: responseCode = AppInfo.INITIATED; break; case InitiatedFailed: responseCode = AppInfo.INITIATEDFAILED; break; case MarkDown: responseCode = AppInfo.MARKDOWN; break; } rtn = appInfo.getStatus(); if(appInfo.getStatus() == AppStatus.MarkDown){ rtn = "markdown by "+appInfo.getMarkDownReason(); } isHandled = true; break; case "/status/detail": case "/health/detail": appInfo = ComponentManager.getStatus(AppInfo.class); Map<String,Object> statusDetail = new LinkedHashMap<>(); statusDetail.put("appStatus",appInfo.getStatus()); if(appInfo.getStatus()==AppStatus.MarkDown){ statusDetail.put("markDownReason",appInfo.getMarkDownReason()); } statusDetail.put("igniteDetail",ComponentManager.getStatus(IgniteStatus.class)); rtn = statusDetail; isHandled = true; break; default: for (String startPath : handlersMap.keySet()) { if (path.startsWith(startPath)) { isHandled = true; ViFunctionHandler functionHandler = handlersMap.get(startPath); permission = functionHandler.getPermission(user).getValue(); rtn = functionHandler.execute(path, user, permission, logger, params); break; } } break; } eventLogger.fireEvent(EventLogger.TRANSEND); }catch (Throwable e){ logger.warn("execute service error",e); e.printStackTrace(); eventLogger.fireEvent(EventLogger.TRANSEND,e); Throwable rootCause; if(e.getCause()!=null){ rootCause = e.getCause(); }else{ rootCause = e; } rtn = TextUtils.makeJSErrorMsg(rootCause.getMessage(),e.getClass().getName()); if(e instanceof NoPermissionException){ responseCode = SC_METHODNOTALLOWED; } }finally { eventLogger.fireEvent(EventLogger.TRANSFINALLY); } if(!isHandled){ rtn = path + " not found"; } long cost = (System.nanoTime()-startTime)/1000L; try { MetricsCollector.getCollector().record(Metrics.VIAPI, cost); }catch (Throwable e){ logger.error("metrics collect failed!",e); } return new ExeResult(rtn,permission,responseCode); }
|
VIApiHandler { public ExeResult executeService(String path,String user,Map<String,Object> params){ long startTime = System.nanoTime(); Object rtn=null; int responseCode = SC_OK; int permission = Permission.ALL.getValue(); EventLogger eventLogger = EventLoggerFactory.getTransLogger(getClass()); if(path == null){ return new ExeResult("NO PATH ERROR",0,SC_NOTFOUND); } path = path.toLowerCase(); boolean isHandled =false; try { eventLogger.fireEvent(EventLogger.TRANSSTART,path); switch (path) { case "/ip": rtn = params.get("req_ip"); isHandled = true; break; case "/status": case "/health": AppInfo appInfo = ComponentManager.getStatus(AppInfo.class); switch (appInfo.getStatus()) { case Uninitiated: responseCode = AppInfo.UNINITIATED; break; case Initiating: responseCode = AppInfo.INITIATING; break; case Initiated: responseCode = AppInfo.INITIATED; break; case InitiatedFailed: responseCode = AppInfo.INITIATEDFAILED; break; case MarkDown: responseCode = AppInfo.MARKDOWN; break; } rtn = appInfo.getStatus(); if(appInfo.getStatus() == AppStatus.MarkDown){ rtn = "markdown by "+appInfo.getMarkDownReason(); } isHandled = true; break; case "/status/detail": case "/health/detail": appInfo = ComponentManager.getStatus(AppInfo.class); Map<String,Object> statusDetail = new LinkedHashMap<>(); statusDetail.put("appStatus",appInfo.getStatus()); if(appInfo.getStatus()==AppStatus.MarkDown){ statusDetail.put("markDownReason",appInfo.getMarkDownReason()); } statusDetail.put("igniteDetail",ComponentManager.getStatus(IgniteStatus.class)); rtn = statusDetail; isHandled = true; break; default: for (String startPath : handlersMap.keySet()) { if (path.startsWith(startPath)) { isHandled = true; ViFunctionHandler functionHandler = handlersMap.get(startPath); permission = functionHandler.getPermission(user).getValue(); rtn = functionHandler.execute(path, user, permission, logger, params); break; } } break; } eventLogger.fireEvent(EventLogger.TRANSEND); }catch (Throwable e){ logger.warn("execute service error",e); e.printStackTrace(); eventLogger.fireEvent(EventLogger.TRANSEND,e); Throwable rootCause; if(e.getCause()!=null){ rootCause = e.getCause(); }else{ rootCause = e; } rtn = TextUtils.makeJSErrorMsg(rootCause.getMessage(),e.getClass().getName()); if(e instanceof NoPermissionException){ responseCode = SC_METHODNOTALLOWED; } }finally { eventLogger.fireEvent(EventLogger.TRANSFINALLY); } if(!isHandled){ rtn = path + " not found"; } long cost = (System.nanoTime()-startTime)/1000L; try { MetricsCollector.getCollector().record(Metrics.VIAPI, cost); }catch (Throwable e){ logger.error("metrics collect failed!",e); } return new ExeResult(rtn,permission,responseCode); } }
|
VIApiHandler { public ExeResult executeService(String path,String user,Map<String,Object> params){ long startTime = System.nanoTime(); Object rtn=null; int responseCode = SC_OK; int permission = Permission.ALL.getValue(); EventLogger eventLogger = EventLoggerFactory.getTransLogger(getClass()); if(path == null){ return new ExeResult("NO PATH ERROR",0,SC_NOTFOUND); } path = path.toLowerCase(); boolean isHandled =false; try { eventLogger.fireEvent(EventLogger.TRANSSTART,path); switch (path) { case "/ip": rtn = params.get("req_ip"); isHandled = true; break; case "/status": case "/health": AppInfo appInfo = ComponentManager.getStatus(AppInfo.class); switch (appInfo.getStatus()) { case Uninitiated: responseCode = AppInfo.UNINITIATED; break; case Initiating: responseCode = AppInfo.INITIATING; break; case Initiated: responseCode = AppInfo.INITIATED; break; case InitiatedFailed: responseCode = AppInfo.INITIATEDFAILED; break; case MarkDown: responseCode = AppInfo.MARKDOWN; break; } rtn = appInfo.getStatus(); if(appInfo.getStatus() == AppStatus.MarkDown){ rtn = "markdown by "+appInfo.getMarkDownReason(); } isHandled = true; break; case "/status/detail": case "/health/detail": appInfo = ComponentManager.getStatus(AppInfo.class); Map<String,Object> statusDetail = new LinkedHashMap<>(); statusDetail.put("appStatus",appInfo.getStatus()); if(appInfo.getStatus()==AppStatus.MarkDown){ statusDetail.put("markDownReason",appInfo.getMarkDownReason()); } statusDetail.put("igniteDetail",ComponentManager.getStatus(IgniteStatus.class)); rtn = statusDetail; isHandled = true; break; default: for (String startPath : handlersMap.keySet()) { if (path.startsWith(startPath)) { isHandled = true; ViFunctionHandler functionHandler = handlersMap.get(startPath); permission = functionHandler.getPermission(user).getValue(); rtn = functionHandler.execute(path, user, permission, logger, params); break; } } break; } eventLogger.fireEvent(EventLogger.TRANSEND); }catch (Throwable e){ logger.warn("execute service error",e); e.printStackTrace(); eventLogger.fireEvent(EventLogger.TRANSEND,e); Throwable rootCause; if(e.getCause()!=null){ rootCause = e.getCause(); }else{ rootCause = e; } rtn = TextUtils.makeJSErrorMsg(rootCause.getMessage(),e.getClass().getName()); if(e instanceof NoPermissionException){ responseCode = SC_METHODNOTALLOWED; } }finally { eventLogger.fireEvent(EventLogger.TRANSFINALLY); } if(!isHandled){ rtn = path + " not found"; } long cost = (System.nanoTime()-startTime)/1000L; try { MetricsCollector.getCollector().record(Metrics.VIAPI, cost); }catch (Throwable e){ logger.error("metrics collect failed!",e); } return new ExeResult(rtn,permission,responseCode); } VIApiHandler(); }
|
VIApiHandler { public ExeResult executeService(String path,String user,Map<String,Object> params){ long startTime = System.nanoTime(); Object rtn=null; int responseCode = SC_OK; int permission = Permission.ALL.getValue(); EventLogger eventLogger = EventLoggerFactory.getTransLogger(getClass()); if(path == null){ return new ExeResult("NO PATH ERROR",0,SC_NOTFOUND); } path = path.toLowerCase(); boolean isHandled =false; try { eventLogger.fireEvent(EventLogger.TRANSSTART,path); switch (path) { case "/ip": rtn = params.get("req_ip"); isHandled = true; break; case "/status": case "/health": AppInfo appInfo = ComponentManager.getStatus(AppInfo.class); switch (appInfo.getStatus()) { case Uninitiated: responseCode = AppInfo.UNINITIATED; break; case Initiating: responseCode = AppInfo.INITIATING; break; case Initiated: responseCode = AppInfo.INITIATED; break; case InitiatedFailed: responseCode = AppInfo.INITIATEDFAILED; break; case MarkDown: responseCode = AppInfo.MARKDOWN; break; } rtn = appInfo.getStatus(); if(appInfo.getStatus() == AppStatus.MarkDown){ rtn = "markdown by "+appInfo.getMarkDownReason(); } isHandled = true; break; case "/status/detail": case "/health/detail": appInfo = ComponentManager.getStatus(AppInfo.class); Map<String,Object> statusDetail = new LinkedHashMap<>(); statusDetail.put("appStatus",appInfo.getStatus()); if(appInfo.getStatus()==AppStatus.MarkDown){ statusDetail.put("markDownReason",appInfo.getMarkDownReason()); } statusDetail.put("igniteDetail",ComponentManager.getStatus(IgniteStatus.class)); rtn = statusDetail; isHandled = true; break; default: for (String startPath : handlersMap.keySet()) { if (path.startsWith(startPath)) { isHandled = true; ViFunctionHandler functionHandler = handlersMap.get(startPath); permission = functionHandler.getPermission(user).getValue(); rtn = functionHandler.execute(path, user, permission, logger, params); break; } } break; } eventLogger.fireEvent(EventLogger.TRANSEND); }catch (Throwable e){ logger.warn("execute service error",e); e.printStackTrace(); eventLogger.fireEvent(EventLogger.TRANSEND,e); Throwable rootCause; if(e.getCause()!=null){ rootCause = e.getCause(); }else{ rootCause = e; } rtn = TextUtils.makeJSErrorMsg(rootCause.getMessage(),e.getClass().getName()); if(e instanceof NoPermissionException){ responseCode = SC_METHODNOTALLOWED; } }finally { eventLogger.fireEvent(EventLogger.TRANSFINALLY); } if(!isHandled){ rtn = path + " not found"; } long cost = (System.nanoTime()-startTime)/1000L; try { MetricsCollector.getCollector().record(Metrics.VIAPI, cost); }catch (Throwable e){ logger.error("metrics collect failed!",e); } return new ExeResult(rtn,permission,responseCode); } VIApiHandler(); static synchronized VIApiHandler getInstance(); boolean register(ViFunctionHandler apiHandler); ExeResult executeService(String path,String user,Map<String,Object> params); }
|
VIApiHandler { public ExeResult executeService(String path,String user,Map<String,Object> params){ long startTime = System.nanoTime(); Object rtn=null; int responseCode = SC_OK; int permission = Permission.ALL.getValue(); EventLogger eventLogger = EventLoggerFactory.getTransLogger(getClass()); if(path == null){ return new ExeResult("NO PATH ERROR",0,SC_NOTFOUND); } path = path.toLowerCase(); boolean isHandled =false; try { eventLogger.fireEvent(EventLogger.TRANSSTART,path); switch (path) { case "/ip": rtn = params.get("req_ip"); isHandled = true; break; case "/status": case "/health": AppInfo appInfo = ComponentManager.getStatus(AppInfo.class); switch (appInfo.getStatus()) { case Uninitiated: responseCode = AppInfo.UNINITIATED; break; case Initiating: responseCode = AppInfo.INITIATING; break; case Initiated: responseCode = AppInfo.INITIATED; break; case InitiatedFailed: responseCode = AppInfo.INITIATEDFAILED; break; case MarkDown: responseCode = AppInfo.MARKDOWN; break; } rtn = appInfo.getStatus(); if(appInfo.getStatus() == AppStatus.MarkDown){ rtn = "markdown by "+appInfo.getMarkDownReason(); } isHandled = true; break; case "/status/detail": case "/health/detail": appInfo = ComponentManager.getStatus(AppInfo.class); Map<String,Object> statusDetail = new LinkedHashMap<>(); statusDetail.put("appStatus",appInfo.getStatus()); if(appInfo.getStatus()==AppStatus.MarkDown){ statusDetail.put("markDownReason",appInfo.getMarkDownReason()); } statusDetail.put("igniteDetail",ComponentManager.getStatus(IgniteStatus.class)); rtn = statusDetail; isHandled = true; break; default: for (String startPath : handlersMap.keySet()) { if (path.startsWith(startPath)) { isHandled = true; ViFunctionHandler functionHandler = handlersMap.get(startPath); permission = functionHandler.getPermission(user).getValue(); rtn = functionHandler.execute(path, user, permission, logger, params); break; } } break; } eventLogger.fireEvent(EventLogger.TRANSEND); }catch (Throwable e){ logger.warn("execute service error",e); e.printStackTrace(); eventLogger.fireEvent(EventLogger.TRANSEND,e); Throwable rootCause; if(e.getCause()!=null){ rootCause = e.getCause(); }else{ rootCause = e; } rtn = TextUtils.makeJSErrorMsg(rootCause.getMessage(),e.getClass().getName()); if(e instanceof NoPermissionException){ responseCode = SC_METHODNOTALLOWED; } }finally { eventLogger.fireEvent(EventLogger.TRANSFINALLY); } if(!isHandled){ rtn = path + " not found"; } long cost = (System.nanoTime()-startTime)/1000L; try { MetricsCollector.getCollector().record(Metrics.VIAPI, cost); }catch (Throwable e){ logger.error("metrics collect failed!",e); } return new ExeResult(rtn,permission,responseCode); } VIApiHandler(); static synchronized VIApiHandler getInstance(); boolean register(ViFunctionHandler apiHandler); ExeResult executeService(String path,String user,Map<String,Object> params); }
|
@Test public void testThreading(){ String path = "/threading/all"; VIApiHandler.ExeResult rtn = handler.executeService(path, user, null); List<ThreadingManager.TInfo> data = (List<ThreadingManager.TInfo>) rtn.getData(); assertTrue(data.size()>0); }
|
public ExeResult executeService(String path,String user,Map<String,Object> params){ long startTime = System.nanoTime(); Object rtn=null; int responseCode = SC_OK; int permission = Permission.ALL.getValue(); EventLogger eventLogger = EventLoggerFactory.getTransLogger(getClass()); if(path == null){ return new ExeResult("NO PATH ERROR",0,SC_NOTFOUND); } path = path.toLowerCase(); boolean isHandled =false; try { eventLogger.fireEvent(EventLogger.TRANSSTART,path); switch (path) { case "/ip": rtn = params.get("req_ip"); isHandled = true; break; case "/status": case "/health": AppInfo appInfo = ComponentManager.getStatus(AppInfo.class); switch (appInfo.getStatus()) { case Uninitiated: responseCode = AppInfo.UNINITIATED; break; case Initiating: responseCode = AppInfo.INITIATING; break; case Initiated: responseCode = AppInfo.INITIATED; break; case InitiatedFailed: responseCode = AppInfo.INITIATEDFAILED; break; case MarkDown: responseCode = AppInfo.MARKDOWN; break; } rtn = appInfo.getStatus(); if(appInfo.getStatus() == AppStatus.MarkDown){ rtn = "markdown by "+appInfo.getMarkDownReason(); } isHandled = true; break; case "/status/detail": case "/health/detail": appInfo = ComponentManager.getStatus(AppInfo.class); Map<String,Object> statusDetail = new LinkedHashMap<>(); statusDetail.put("appStatus",appInfo.getStatus()); if(appInfo.getStatus()==AppStatus.MarkDown){ statusDetail.put("markDownReason",appInfo.getMarkDownReason()); } statusDetail.put("igniteDetail",ComponentManager.getStatus(IgniteStatus.class)); rtn = statusDetail; isHandled = true; break; default: for (String startPath : handlersMap.keySet()) { if (path.startsWith(startPath)) { isHandled = true; ViFunctionHandler functionHandler = handlersMap.get(startPath); permission = functionHandler.getPermission(user).getValue(); rtn = functionHandler.execute(path, user, permission, logger, params); break; } } break; } eventLogger.fireEvent(EventLogger.TRANSEND); }catch (Throwable e){ logger.warn("execute service error",e); e.printStackTrace(); eventLogger.fireEvent(EventLogger.TRANSEND,e); Throwable rootCause; if(e.getCause()!=null){ rootCause = e.getCause(); }else{ rootCause = e; } rtn = TextUtils.makeJSErrorMsg(rootCause.getMessage(),e.getClass().getName()); if(e instanceof NoPermissionException){ responseCode = SC_METHODNOTALLOWED; } }finally { eventLogger.fireEvent(EventLogger.TRANSFINALLY); } if(!isHandled){ rtn = path + " not found"; } long cost = (System.nanoTime()-startTime)/1000L; try { MetricsCollector.getCollector().record(Metrics.VIAPI, cost); }catch (Throwable e){ logger.error("metrics collect failed!",e); } return new ExeResult(rtn,permission,responseCode); }
|
VIApiHandler { public ExeResult executeService(String path,String user,Map<String,Object> params){ long startTime = System.nanoTime(); Object rtn=null; int responseCode = SC_OK; int permission = Permission.ALL.getValue(); EventLogger eventLogger = EventLoggerFactory.getTransLogger(getClass()); if(path == null){ return new ExeResult("NO PATH ERROR",0,SC_NOTFOUND); } path = path.toLowerCase(); boolean isHandled =false; try { eventLogger.fireEvent(EventLogger.TRANSSTART,path); switch (path) { case "/ip": rtn = params.get("req_ip"); isHandled = true; break; case "/status": case "/health": AppInfo appInfo = ComponentManager.getStatus(AppInfo.class); switch (appInfo.getStatus()) { case Uninitiated: responseCode = AppInfo.UNINITIATED; break; case Initiating: responseCode = AppInfo.INITIATING; break; case Initiated: responseCode = AppInfo.INITIATED; break; case InitiatedFailed: responseCode = AppInfo.INITIATEDFAILED; break; case MarkDown: responseCode = AppInfo.MARKDOWN; break; } rtn = appInfo.getStatus(); if(appInfo.getStatus() == AppStatus.MarkDown){ rtn = "markdown by "+appInfo.getMarkDownReason(); } isHandled = true; break; case "/status/detail": case "/health/detail": appInfo = ComponentManager.getStatus(AppInfo.class); Map<String,Object> statusDetail = new LinkedHashMap<>(); statusDetail.put("appStatus",appInfo.getStatus()); if(appInfo.getStatus()==AppStatus.MarkDown){ statusDetail.put("markDownReason",appInfo.getMarkDownReason()); } statusDetail.put("igniteDetail",ComponentManager.getStatus(IgniteStatus.class)); rtn = statusDetail; isHandled = true; break; default: for (String startPath : handlersMap.keySet()) { if (path.startsWith(startPath)) { isHandled = true; ViFunctionHandler functionHandler = handlersMap.get(startPath); permission = functionHandler.getPermission(user).getValue(); rtn = functionHandler.execute(path, user, permission, logger, params); break; } } break; } eventLogger.fireEvent(EventLogger.TRANSEND); }catch (Throwable e){ logger.warn("execute service error",e); e.printStackTrace(); eventLogger.fireEvent(EventLogger.TRANSEND,e); Throwable rootCause; if(e.getCause()!=null){ rootCause = e.getCause(); }else{ rootCause = e; } rtn = TextUtils.makeJSErrorMsg(rootCause.getMessage(),e.getClass().getName()); if(e instanceof NoPermissionException){ responseCode = SC_METHODNOTALLOWED; } }finally { eventLogger.fireEvent(EventLogger.TRANSFINALLY); } if(!isHandled){ rtn = path + " not found"; } long cost = (System.nanoTime()-startTime)/1000L; try { MetricsCollector.getCollector().record(Metrics.VIAPI, cost); }catch (Throwable e){ logger.error("metrics collect failed!",e); } return new ExeResult(rtn,permission,responseCode); } }
|
VIApiHandler { public ExeResult executeService(String path,String user,Map<String,Object> params){ long startTime = System.nanoTime(); Object rtn=null; int responseCode = SC_OK; int permission = Permission.ALL.getValue(); EventLogger eventLogger = EventLoggerFactory.getTransLogger(getClass()); if(path == null){ return new ExeResult("NO PATH ERROR",0,SC_NOTFOUND); } path = path.toLowerCase(); boolean isHandled =false; try { eventLogger.fireEvent(EventLogger.TRANSSTART,path); switch (path) { case "/ip": rtn = params.get("req_ip"); isHandled = true; break; case "/status": case "/health": AppInfo appInfo = ComponentManager.getStatus(AppInfo.class); switch (appInfo.getStatus()) { case Uninitiated: responseCode = AppInfo.UNINITIATED; break; case Initiating: responseCode = AppInfo.INITIATING; break; case Initiated: responseCode = AppInfo.INITIATED; break; case InitiatedFailed: responseCode = AppInfo.INITIATEDFAILED; break; case MarkDown: responseCode = AppInfo.MARKDOWN; break; } rtn = appInfo.getStatus(); if(appInfo.getStatus() == AppStatus.MarkDown){ rtn = "markdown by "+appInfo.getMarkDownReason(); } isHandled = true; break; case "/status/detail": case "/health/detail": appInfo = ComponentManager.getStatus(AppInfo.class); Map<String,Object> statusDetail = new LinkedHashMap<>(); statusDetail.put("appStatus",appInfo.getStatus()); if(appInfo.getStatus()==AppStatus.MarkDown){ statusDetail.put("markDownReason",appInfo.getMarkDownReason()); } statusDetail.put("igniteDetail",ComponentManager.getStatus(IgniteStatus.class)); rtn = statusDetail; isHandled = true; break; default: for (String startPath : handlersMap.keySet()) { if (path.startsWith(startPath)) { isHandled = true; ViFunctionHandler functionHandler = handlersMap.get(startPath); permission = functionHandler.getPermission(user).getValue(); rtn = functionHandler.execute(path, user, permission, logger, params); break; } } break; } eventLogger.fireEvent(EventLogger.TRANSEND); }catch (Throwable e){ logger.warn("execute service error",e); e.printStackTrace(); eventLogger.fireEvent(EventLogger.TRANSEND,e); Throwable rootCause; if(e.getCause()!=null){ rootCause = e.getCause(); }else{ rootCause = e; } rtn = TextUtils.makeJSErrorMsg(rootCause.getMessage(),e.getClass().getName()); if(e instanceof NoPermissionException){ responseCode = SC_METHODNOTALLOWED; } }finally { eventLogger.fireEvent(EventLogger.TRANSFINALLY); } if(!isHandled){ rtn = path + " not found"; } long cost = (System.nanoTime()-startTime)/1000L; try { MetricsCollector.getCollector().record(Metrics.VIAPI, cost); }catch (Throwable e){ logger.error("metrics collect failed!",e); } return new ExeResult(rtn,permission,responseCode); } VIApiHandler(); }
|
VIApiHandler { public ExeResult executeService(String path,String user,Map<String,Object> params){ long startTime = System.nanoTime(); Object rtn=null; int responseCode = SC_OK; int permission = Permission.ALL.getValue(); EventLogger eventLogger = EventLoggerFactory.getTransLogger(getClass()); if(path == null){ return new ExeResult("NO PATH ERROR",0,SC_NOTFOUND); } path = path.toLowerCase(); boolean isHandled =false; try { eventLogger.fireEvent(EventLogger.TRANSSTART,path); switch (path) { case "/ip": rtn = params.get("req_ip"); isHandled = true; break; case "/status": case "/health": AppInfo appInfo = ComponentManager.getStatus(AppInfo.class); switch (appInfo.getStatus()) { case Uninitiated: responseCode = AppInfo.UNINITIATED; break; case Initiating: responseCode = AppInfo.INITIATING; break; case Initiated: responseCode = AppInfo.INITIATED; break; case InitiatedFailed: responseCode = AppInfo.INITIATEDFAILED; break; case MarkDown: responseCode = AppInfo.MARKDOWN; break; } rtn = appInfo.getStatus(); if(appInfo.getStatus() == AppStatus.MarkDown){ rtn = "markdown by "+appInfo.getMarkDownReason(); } isHandled = true; break; case "/status/detail": case "/health/detail": appInfo = ComponentManager.getStatus(AppInfo.class); Map<String,Object> statusDetail = new LinkedHashMap<>(); statusDetail.put("appStatus",appInfo.getStatus()); if(appInfo.getStatus()==AppStatus.MarkDown){ statusDetail.put("markDownReason",appInfo.getMarkDownReason()); } statusDetail.put("igniteDetail",ComponentManager.getStatus(IgniteStatus.class)); rtn = statusDetail; isHandled = true; break; default: for (String startPath : handlersMap.keySet()) { if (path.startsWith(startPath)) { isHandled = true; ViFunctionHandler functionHandler = handlersMap.get(startPath); permission = functionHandler.getPermission(user).getValue(); rtn = functionHandler.execute(path, user, permission, logger, params); break; } } break; } eventLogger.fireEvent(EventLogger.TRANSEND); }catch (Throwable e){ logger.warn("execute service error",e); e.printStackTrace(); eventLogger.fireEvent(EventLogger.TRANSEND,e); Throwable rootCause; if(e.getCause()!=null){ rootCause = e.getCause(); }else{ rootCause = e; } rtn = TextUtils.makeJSErrorMsg(rootCause.getMessage(),e.getClass().getName()); if(e instanceof NoPermissionException){ responseCode = SC_METHODNOTALLOWED; } }finally { eventLogger.fireEvent(EventLogger.TRANSFINALLY); } if(!isHandled){ rtn = path + " not found"; } long cost = (System.nanoTime()-startTime)/1000L; try { MetricsCollector.getCollector().record(Metrics.VIAPI, cost); }catch (Throwable e){ logger.error("metrics collect failed!",e); } return new ExeResult(rtn,permission,responseCode); } VIApiHandler(); static synchronized VIApiHandler getInstance(); boolean register(ViFunctionHandler apiHandler); ExeResult executeService(String path,String user,Map<String,Object> params); }
|
VIApiHandler { public ExeResult executeService(String path,String user,Map<String,Object> params){ long startTime = System.nanoTime(); Object rtn=null; int responseCode = SC_OK; int permission = Permission.ALL.getValue(); EventLogger eventLogger = EventLoggerFactory.getTransLogger(getClass()); if(path == null){ return new ExeResult("NO PATH ERROR",0,SC_NOTFOUND); } path = path.toLowerCase(); boolean isHandled =false; try { eventLogger.fireEvent(EventLogger.TRANSSTART,path); switch (path) { case "/ip": rtn = params.get("req_ip"); isHandled = true; break; case "/status": case "/health": AppInfo appInfo = ComponentManager.getStatus(AppInfo.class); switch (appInfo.getStatus()) { case Uninitiated: responseCode = AppInfo.UNINITIATED; break; case Initiating: responseCode = AppInfo.INITIATING; break; case Initiated: responseCode = AppInfo.INITIATED; break; case InitiatedFailed: responseCode = AppInfo.INITIATEDFAILED; break; case MarkDown: responseCode = AppInfo.MARKDOWN; break; } rtn = appInfo.getStatus(); if(appInfo.getStatus() == AppStatus.MarkDown){ rtn = "markdown by "+appInfo.getMarkDownReason(); } isHandled = true; break; case "/status/detail": case "/health/detail": appInfo = ComponentManager.getStatus(AppInfo.class); Map<String,Object> statusDetail = new LinkedHashMap<>(); statusDetail.put("appStatus",appInfo.getStatus()); if(appInfo.getStatus()==AppStatus.MarkDown){ statusDetail.put("markDownReason",appInfo.getMarkDownReason()); } statusDetail.put("igniteDetail",ComponentManager.getStatus(IgniteStatus.class)); rtn = statusDetail; isHandled = true; break; default: for (String startPath : handlersMap.keySet()) { if (path.startsWith(startPath)) { isHandled = true; ViFunctionHandler functionHandler = handlersMap.get(startPath); permission = functionHandler.getPermission(user).getValue(); rtn = functionHandler.execute(path, user, permission, logger, params); break; } } break; } eventLogger.fireEvent(EventLogger.TRANSEND); }catch (Throwable e){ logger.warn("execute service error",e); e.printStackTrace(); eventLogger.fireEvent(EventLogger.TRANSEND,e); Throwable rootCause; if(e.getCause()!=null){ rootCause = e.getCause(); }else{ rootCause = e; } rtn = TextUtils.makeJSErrorMsg(rootCause.getMessage(),e.getClass().getName()); if(e instanceof NoPermissionException){ responseCode = SC_METHODNOTALLOWED; } }finally { eventLogger.fireEvent(EventLogger.TRANSFINALLY); } if(!isHandled){ rtn = path + " not found"; } long cost = (System.nanoTime()-startTime)/1000L; try { MetricsCollector.getCollector().record(Metrics.VIAPI, cost); }catch (Throwable e){ logger.error("metrics collect failed!",e); } return new ExeResult(rtn,permission,responseCode); } VIApiHandler(); static synchronized VIApiHandler getInstance(); boolean register(ViFunctionHandler apiHandler); ExeResult executeService(String path,String user,Map<String,Object> params); }
|
@Test public void testGetThreadInfo(){ long threadId = 1; String path = "/threading/detail/"+threadId; VIApiHandler.ExeResult rtn = handler.executeService(path, user, null); ThreadInfo info = (ThreadInfo) rtn.getData(); assertEquals(threadId, info.getThreadId()); assertEquals("main", info.getThreadName()); final int maxDepth = 2; rtn = handler.executeService(path, user, new HashMap<String, Object>(){ { put("maxdepth",maxDepth+""); } }); info = (ThreadInfo) rtn.getData(); assertEquals(maxDepth,info.getStackTrace().length); rtn = handler.executeService(path, user, new HashMap<String, Object>(){ { put("maxdepth","abc"); } }); info = (ThreadInfo) rtn.getData(); assertEquals(3,info.getStackTrace().length); }
|
public ExeResult executeService(String path,String user,Map<String,Object> params){ long startTime = System.nanoTime(); Object rtn=null; int responseCode = SC_OK; int permission = Permission.ALL.getValue(); EventLogger eventLogger = EventLoggerFactory.getTransLogger(getClass()); if(path == null){ return new ExeResult("NO PATH ERROR",0,SC_NOTFOUND); } path = path.toLowerCase(); boolean isHandled =false; try { eventLogger.fireEvent(EventLogger.TRANSSTART,path); switch (path) { case "/ip": rtn = params.get("req_ip"); isHandled = true; break; case "/status": case "/health": AppInfo appInfo = ComponentManager.getStatus(AppInfo.class); switch (appInfo.getStatus()) { case Uninitiated: responseCode = AppInfo.UNINITIATED; break; case Initiating: responseCode = AppInfo.INITIATING; break; case Initiated: responseCode = AppInfo.INITIATED; break; case InitiatedFailed: responseCode = AppInfo.INITIATEDFAILED; break; case MarkDown: responseCode = AppInfo.MARKDOWN; break; } rtn = appInfo.getStatus(); if(appInfo.getStatus() == AppStatus.MarkDown){ rtn = "markdown by "+appInfo.getMarkDownReason(); } isHandled = true; break; case "/status/detail": case "/health/detail": appInfo = ComponentManager.getStatus(AppInfo.class); Map<String,Object> statusDetail = new LinkedHashMap<>(); statusDetail.put("appStatus",appInfo.getStatus()); if(appInfo.getStatus()==AppStatus.MarkDown){ statusDetail.put("markDownReason",appInfo.getMarkDownReason()); } statusDetail.put("igniteDetail",ComponentManager.getStatus(IgniteStatus.class)); rtn = statusDetail; isHandled = true; break; default: for (String startPath : handlersMap.keySet()) { if (path.startsWith(startPath)) { isHandled = true; ViFunctionHandler functionHandler = handlersMap.get(startPath); permission = functionHandler.getPermission(user).getValue(); rtn = functionHandler.execute(path, user, permission, logger, params); break; } } break; } eventLogger.fireEvent(EventLogger.TRANSEND); }catch (Throwable e){ logger.warn("execute service error",e); e.printStackTrace(); eventLogger.fireEvent(EventLogger.TRANSEND,e); Throwable rootCause; if(e.getCause()!=null){ rootCause = e.getCause(); }else{ rootCause = e; } rtn = TextUtils.makeJSErrorMsg(rootCause.getMessage(),e.getClass().getName()); if(e instanceof NoPermissionException){ responseCode = SC_METHODNOTALLOWED; } }finally { eventLogger.fireEvent(EventLogger.TRANSFINALLY); } if(!isHandled){ rtn = path + " not found"; } long cost = (System.nanoTime()-startTime)/1000L; try { MetricsCollector.getCollector().record(Metrics.VIAPI, cost); }catch (Throwable e){ logger.error("metrics collect failed!",e); } return new ExeResult(rtn,permission,responseCode); }
|
VIApiHandler { public ExeResult executeService(String path,String user,Map<String,Object> params){ long startTime = System.nanoTime(); Object rtn=null; int responseCode = SC_OK; int permission = Permission.ALL.getValue(); EventLogger eventLogger = EventLoggerFactory.getTransLogger(getClass()); if(path == null){ return new ExeResult("NO PATH ERROR",0,SC_NOTFOUND); } path = path.toLowerCase(); boolean isHandled =false; try { eventLogger.fireEvent(EventLogger.TRANSSTART,path); switch (path) { case "/ip": rtn = params.get("req_ip"); isHandled = true; break; case "/status": case "/health": AppInfo appInfo = ComponentManager.getStatus(AppInfo.class); switch (appInfo.getStatus()) { case Uninitiated: responseCode = AppInfo.UNINITIATED; break; case Initiating: responseCode = AppInfo.INITIATING; break; case Initiated: responseCode = AppInfo.INITIATED; break; case InitiatedFailed: responseCode = AppInfo.INITIATEDFAILED; break; case MarkDown: responseCode = AppInfo.MARKDOWN; break; } rtn = appInfo.getStatus(); if(appInfo.getStatus() == AppStatus.MarkDown){ rtn = "markdown by "+appInfo.getMarkDownReason(); } isHandled = true; break; case "/status/detail": case "/health/detail": appInfo = ComponentManager.getStatus(AppInfo.class); Map<String,Object> statusDetail = new LinkedHashMap<>(); statusDetail.put("appStatus",appInfo.getStatus()); if(appInfo.getStatus()==AppStatus.MarkDown){ statusDetail.put("markDownReason",appInfo.getMarkDownReason()); } statusDetail.put("igniteDetail",ComponentManager.getStatus(IgniteStatus.class)); rtn = statusDetail; isHandled = true; break; default: for (String startPath : handlersMap.keySet()) { if (path.startsWith(startPath)) { isHandled = true; ViFunctionHandler functionHandler = handlersMap.get(startPath); permission = functionHandler.getPermission(user).getValue(); rtn = functionHandler.execute(path, user, permission, logger, params); break; } } break; } eventLogger.fireEvent(EventLogger.TRANSEND); }catch (Throwable e){ logger.warn("execute service error",e); e.printStackTrace(); eventLogger.fireEvent(EventLogger.TRANSEND,e); Throwable rootCause; if(e.getCause()!=null){ rootCause = e.getCause(); }else{ rootCause = e; } rtn = TextUtils.makeJSErrorMsg(rootCause.getMessage(),e.getClass().getName()); if(e instanceof NoPermissionException){ responseCode = SC_METHODNOTALLOWED; } }finally { eventLogger.fireEvent(EventLogger.TRANSFINALLY); } if(!isHandled){ rtn = path + " not found"; } long cost = (System.nanoTime()-startTime)/1000L; try { MetricsCollector.getCollector().record(Metrics.VIAPI, cost); }catch (Throwable e){ logger.error("metrics collect failed!",e); } return new ExeResult(rtn,permission,responseCode); } }
|
VIApiHandler { public ExeResult executeService(String path,String user,Map<String,Object> params){ long startTime = System.nanoTime(); Object rtn=null; int responseCode = SC_OK; int permission = Permission.ALL.getValue(); EventLogger eventLogger = EventLoggerFactory.getTransLogger(getClass()); if(path == null){ return new ExeResult("NO PATH ERROR",0,SC_NOTFOUND); } path = path.toLowerCase(); boolean isHandled =false; try { eventLogger.fireEvent(EventLogger.TRANSSTART,path); switch (path) { case "/ip": rtn = params.get("req_ip"); isHandled = true; break; case "/status": case "/health": AppInfo appInfo = ComponentManager.getStatus(AppInfo.class); switch (appInfo.getStatus()) { case Uninitiated: responseCode = AppInfo.UNINITIATED; break; case Initiating: responseCode = AppInfo.INITIATING; break; case Initiated: responseCode = AppInfo.INITIATED; break; case InitiatedFailed: responseCode = AppInfo.INITIATEDFAILED; break; case MarkDown: responseCode = AppInfo.MARKDOWN; break; } rtn = appInfo.getStatus(); if(appInfo.getStatus() == AppStatus.MarkDown){ rtn = "markdown by "+appInfo.getMarkDownReason(); } isHandled = true; break; case "/status/detail": case "/health/detail": appInfo = ComponentManager.getStatus(AppInfo.class); Map<String,Object> statusDetail = new LinkedHashMap<>(); statusDetail.put("appStatus",appInfo.getStatus()); if(appInfo.getStatus()==AppStatus.MarkDown){ statusDetail.put("markDownReason",appInfo.getMarkDownReason()); } statusDetail.put("igniteDetail",ComponentManager.getStatus(IgniteStatus.class)); rtn = statusDetail; isHandled = true; break; default: for (String startPath : handlersMap.keySet()) { if (path.startsWith(startPath)) { isHandled = true; ViFunctionHandler functionHandler = handlersMap.get(startPath); permission = functionHandler.getPermission(user).getValue(); rtn = functionHandler.execute(path, user, permission, logger, params); break; } } break; } eventLogger.fireEvent(EventLogger.TRANSEND); }catch (Throwable e){ logger.warn("execute service error",e); e.printStackTrace(); eventLogger.fireEvent(EventLogger.TRANSEND,e); Throwable rootCause; if(e.getCause()!=null){ rootCause = e.getCause(); }else{ rootCause = e; } rtn = TextUtils.makeJSErrorMsg(rootCause.getMessage(),e.getClass().getName()); if(e instanceof NoPermissionException){ responseCode = SC_METHODNOTALLOWED; } }finally { eventLogger.fireEvent(EventLogger.TRANSFINALLY); } if(!isHandled){ rtn = path + " not found"; } long cost = (System.nanoTime()-startTime)/1000L; try { MetricsCollector.getCollector().record(Metrics.VIAPI, cost); }catch (Throwable e){ logger.error("metrics collect failed!",e); } return new ExeResult(rtn,permission,responseCode); } VIApiHandler(); }
|
VIApiHandler { public ExeResult executeService(String path,String user,Map<String,Object> params){ long startTime = System.nanoTime(); Object rtn=null; int responseCode = SC_OK; int permission = Permission.ALL.getValue(); EventLogger eventLogger = EventLoggerFactory.getTransLogger(getClass()); if(path == null){ return new ExeResult("NO PATH ERROR",0,SC_NOTFOUND); } path = path.toLowerCase(); boolean isHandled =false; try { eventLogger.fireEvent(EventLogger.TRANSSTART,path); switch (path) { case "/ip": rtn = params.get("req_ip"); isHandled = true; break; case "/status": case "/health": AppInfo appInfo = ComponentManager.getStatus(AppInfo.class); switch (appInfo.getStatus()) { case Uninitiated: responseCode = AppInfo.UNINITIATED; break; case Initiating: responseCode = AppInfo.INITIATING; break; case Initiated: responseCode = AppInfo.INITIATED; break; case InitiatedFailed: responseCode = AppInfo.INITIATEDFAILED; break; case MarkDown: responseCode = AppInfo.MARKDOWN; break; } rtn = appInfo.getStatus(); if(appInfo.getStatus() == AppStatus.MarkDown){ rtn = "markdown by "+appInfo.getMarkDownReason(); } isHandled = true; break; case "/status/detail": case "/health/detail": appInfo = ComponentManager.getStatus(AppInfo.class); Map<String,Object> statusDetail = new LinkedHashMap<>(); statusDetail.put("appStatus",appInfo.getStatus()); if(appInfo.getStatus()==AppStatus.MarkDown){ statusDetail.put("markDownReason",appInfo.getMarkDownReason()); } statusDetail.put("igniteDetail",ComponentManager.getStatus(IgniteStatus.class)); rtn = statusDetail; isHandled = true; break; default: for (String startPath : handlersMap.keySet()) { if (path.startsWith(startPath)) { isHandled = true; ViFunctionHandler functionHandler = handlersMap.get(startPath); permission = functionHandler.getPermission(user).getValue(); rtn = functionHandler.execute(path, user, permission, logger, params); break; } } break; } eventLogger.fireEvent(EventLogger.TRANSEND); }catch (Throwable e){ logger.warn("execute service error",e); e.printStackTrace(); eventLogger.fireEvent(EventLogger.TRANSEND,e); Throwable rootCause; if(e.getCause()!=null){ rootCause = e.getCause(); }else{ rootCause = e; } rtn = TextUtils.makeJSErrorMsg(rootCause.getMessage(),e.getClass().getName()); if(e instanceof NoPermissionException){ responseCode = SC_METHODNOTALLOWED; } }finally { eventLogger.fireEvent(EventLogger.TRANSFINALLY); } if(!isHandled){ rtn = path + " not found"; } long cost = (System.nanoTime()-startTime)/1000L; try { MetricsCollector.getCollector().record(Metrics.VIAPI, cost); }catch (Throwable e){ logger.error("metrics collect failed!",e); } return new ExeResult(rtn,permission,responseCode); } VIApiHandler(); static synchronized VIApiHandler getInstance(); boolean register(ViFunctionHandler apiHandler); ExeResult executeService(String path,String user,Map<String,Object> params); }
|
VIApiHandler { public ExeResult executeService(String path,String user,Map<String,Object> params){ long startTime = System.nanoTime(); Object rtn=null; int responseCode = SC_OK; int permission = Permission.ALL.getValue(); EventLogger eventLogger = EventLoggerFactory.getTransLogger(getClass()); if(path == null){ return new ExeResult("NO PATH ERROR",0,SC_NOTFOUND); } path = path.toLowerCase(); boolean isHandled =false; try { eventLogger.fireEvent(EventLogger.TRANSSTART,path); switch (path) { case "/ip": rtn = params.get("req_ip"); isHandled = true; break; case "/status": case "/health": AppInfo appInfo = ComponentManager.getStatus(AppInfo.class); switch (appInfo.getStatus()) { case Uninitiated: responseCode = AppInfo.UNINITIATED; break; case Initiating: responseCode = AppInfo.INITIATING; break; case Initiated: responseCode = AppInfo.INITIATED; break; case InitiatedFailed: responseCode = AppInfo.INITIATEDFAILED; break; case MarkDown: responseCode = AppInfo.MARKDOWN; break; } rtn = appInfo.getStatus(); if(appInfo.getStatus() == AppStatus.MarkDown){ rtn = "markdown by "+appInfo.getMarkDownReason(); } isHandled = true; break; case "/status/detail": case "/health/detail": appInfo = ComponentManager.getStatus(AppInfo.class); Map<String,Object> statusDetail = new LinkedHashMap<>(); statusDetail.put("appStatus",appInfo.getStatus()); if(appInfo.getStatus()==AppStatus.MarkDown){ statusDetail.put("markDownReason",appInfo.getMarkDownReason()); } statusDetail.put("igniteDetail",ComponentManager.getStatus(IgniteStatus.class)); rtn = statusDetail; isHandled = true; break; default: for (String startPath : handlersMap.keySet()) { if (path.startsWith(startPath)) { isHandled = true; ViFunctionHandler functionHandler = handlersMap.get(startPath); permission = functionHandler.getPermission(user).getValue(); rtn = functionHandler.execute(path, user, permission, logger, params); break; } } break; } eventLogger.fireEvent(EventLogger.TRANSEND); }catch (Throwable e){ logger.warn("execute service error",e); e.printStackTrace(); eventLogger.fireEvent(EventLogger.TRANSEND,e); Throwable rootCause; if(e.getCause()!=null){ rootCause = e.getCause(); }else{ rootCause = e; } rtn = TextUtils.makeJSErrorMsg(rootCause.getMessage(),e.getClass().getName()); if(e instanceof NoPermissionException){ responseCode = SC_METHODNOTALLOWED; } }finally { eventLogger.fireEvent(EventLogger.TRANSFINALLY); } if(!isHandled){ rtn = path + " not found"; } long cost = (System.nanoTime()-startTime)/1000L; try { MetricsCollector.getCollector().record(Metrics.VIAPI, cost); }catch (Throwable e){ logger.error("metrics collect failed!",e); } return new ExeResult(rtn,permission,responseCode); } VIApiHandler(); static synchronized VIApiHandler getInstance(); boolean register(ViFunctionHandler apiHandler); ExeResult executeService(String path,String user,Map<String,Object> params); }
|
@Test public void testThreadStats(){ String path = "/threading/stats"; VIApiHandler.ExeResult rtn = handler.executeService(path, user, null); Map<String,Number> info = (Map<String, Number>) rtn.getData(); assertTrue(info.containsKey("currentThreadCount")); assertTrue(info.get("currentThreadCount").intValue()>0); assertTrue(info.containsKey("daemonThreadCount")); assertTrue(info.get("daemonThreadCount").intValue()>0); assertTrue(info.containsKey("totalStartedThreadCount")); assertTrue(info.get("totalStartedThreadCount").longValue() > 0); assertTrue(info.containsKey("peakThreadCount")); assertTrue(info.get("peakThreadCount").intValue()>0); }
|
public ExeResult executeService(String path,String user,Map<String,Object> params){ long startTime = System.nanoTime(); Object rtn=null; int responseCode = SC_OK; int permission = Permission.ALL.getValue(); EventLogger eventLogger = EventLoggerFactory.getTransLogger(getClass()); if(path == null){ return new ExeResult("NO PATH ERROR",0,SC_NOTFOUND); } path = path.toLowerCase(); boolean isHandled =false; try { eventLogger.fireEvent(EventLogger.TRANSSTART,path); switch (path) { case "/ip": rtn = params.get("req_ip"); isHandled = true; break; case "/status": case "/health": AppInfo appInfo = ComponentManager.getStatus(AppInfo.class); switch (appInfo.getStatus()) { case Uninitiated: responseCode = AppInfo.UNINITIATED; break; case Initiating: responseCode = AppInfo.INITIATING; break; case Initiated: responseCode = AppInfo.INITIATED; break; case InitiatedFailed: responseCode = AppInfo.INITIATEDFAILED; break; case MarkDown: responseCode = AppInfo.MARKDOWN; break; } rtn = appInfo.getStatus(); if(appInfo.getStatus() == AppStatus.MarkDown){ rtn = "markdown by "+appInfo.getMarkDownReason(); } isHandled = true; break; case "/status/detail": case "/health/detail": appInfo = ComponentManager.getStatus(AppInfo.class); Map<String,Object> statusDetail = new LinkedHashMap<>(); statusDetail.put("appStatus",appInfo.getStatus()); if(appInfo.getStatus()==AppStatus.MarkDown){ statusDetail.put("markDownReason",appInfo.getMarkDownReason()); } statusDetail.put("igniteDetail",ComponentManager.getStatus(IgniteStatus.class)); rtn = statusDetail; isHandled = true; break; default: for (String startPath : handlersMap.keySet()) { if (path.startsWith(startPath)) { isHandled = true; ViFunctionHandler functionHandler = handlersMap.get(startPath); permission = functionHandler.getPermission(user).getValue(); rtn = functionHandler.execute(path, user, permission, logger, params); break; } } break; } eventLogger.fireEvent(EventLogger.TRANSEND); }catch (Throwable e){ logger.warn("execute service error",e); e.printStackTrace(); eventLogger.fireEvent(EventLogger.TRANSEND,e); Throwable rootCause; if(e.getCause()!=null){ rootCause = e.getCause(); }else{ rootCause = e; } rtn = TextUtils.makeJSErrorMsg(rootCause.getMessage(),e.getClass().getName()); if(e instanceof NoPermissionException){ responseCode = SC_METHODNOTALLOWED; } }finally { eventLogger.fireEvent(EventLogger.TRANSFINALLY); } if(!isHandled){ rtn = path + " not found"; } long cost = (System.nanoTime()-startTime)/1000L; try { MetricsCollector.getCollector().record(Metrics.VIAPI, cost); }catch (Throwable e){ logger.error("metrics collect failed!",e); } return new ExeResult(rtn,permission,responseCode); }
|
VIApiHandler { public ExeResult executeService(String path,String user,Map<String,Object> params){ long startTime = System.nanoTime(); Object rtn=null; int responseCode = SC_OK; int permission = Permission.ALL.getValue(); EventLogger eventLogger = EventLoggerFactory.getTransLogger(getClass()); if(path == null){ return new ExeResult("NO PATH ERROR",0,SC_NOTFOUND); } path = path.toLowerCase(); boolean isHandled =false; try { eventLogger.fireEvent(EventLogger.TRANSSTART,path); switch (path) { case "/ip": rtn = params.get("req_ip"); isHandled = true; break; case "/status": case "/health": AppInfo appInfo = ComponentManager.getStatus(AppInfo.class); switch (appInfo.getStatus()) { case Uninitiated: responseCode = AppInfo.UNINITIATED; break; case Initiating: responseCode = AppInfo.INITIATING; break; case Initiated: responseCode = AppInfo.INITIATED; break; case InitiatedFailed: responseCode = AppInfo.INITIATEDFAILED; break; case MarkDown: responseCode = AppInfo.MARKDOWN; break; } rtn = appInfo.getStatus(); if(appInfo.getStatus() == AppStatus.MarkDown){ rtn = "markdown by "+appInfo.getMarkDownReason(); } isHandled = true; break; case "/status/detail": case "/health/detail": appInfo = ComponentManager.getStatus(AppInfo.class); Map<String,Object> statusDetail = new LinkedHashMap<>(); statusDetail.put("appStatus",appInfo.getStatus()); if(appInfo.getStatus()==AppStatus.MarkDown){ statusDetail.put("markDownReason",appInfo.getMarkDownReason()); } statusDetail.put("igniteDetail",ComponentManager.getStatus(IgniteStatus.class)); rtn = statusDetail; isHandled = true; break; default: for (String startPath : handlersMap.keySet()) { if (path.startsWith(startPath)) { isHandled = true; ViFunctionHandler functionHandler = handlersMap.get(startPath); permission = functionHandler.getPermission(user).getValue(); rtn = functionHandler.execute(path, user, permission, logger, params); break; } } break; } eventLogger.fireEvent(EventLogger.TRANSEND); }catch (Throwable e){ logger.warn("execute service error",e); e.printStackTrace(); eventLogger.fireEvent(EventLogger.TRANSEND,e); Throwable rootCause; if(e.getCause()!=null){ rootCause = e.getCause(); }else{ rootCause = e; } rtn = TextUtils.makeJSErrorMsg(rootCause.getMessage(),e.getClass().getName()); if(e instanceof NoPermissionException){ responseCode = SC_METHODNOTALLOWED; } }finally { eventLogger.fireEvent(EventLogger.TRANSFINALLY); } if(!isHandled){ rtn = path + " not found"; } long cost = (System.nanoTime()-startTime)/1000L; try { MetricsCollector.getCollector().record(Metrics.VIAPI, cost); }catch (Throwable e){ logger.error("metrics collect failed!",e); } return new ExeResult(rtn,permission,responseCode); } }
|
VIApiHandler { public ExeResult executeService(String path,String user,Map<String,Object> params){ long startTime = System.nanoTime(); Object rtn=null; int responseCode = SC_OK; int permission = Permission.ALL.getValue(); EventLogger eventLogger = EventLoggerFactory.getTransLogger(getClass()); if(path == null){ return new ExeResult("NO PATH ERROR",0,SC_NOTFOUND); } path = path.toLowerCase(); boolean isHandled =false; try { eventLogger.fireEvent(EventLogger.TRANSSTART,path); switch (path) { case "/ip": rtn = params.get("req_ip"); isHandled = true; break; case "/status": case "/health": AppInfo appInfo = ComponentManager.getStatus(AppInfo.class); switch (appInfo.getStatus()) { case Uninitiated: responseCode = AppInfo.UNINITIATED; break; case Initiating: responseCode = AppInfo.INITIATING; break; case Initiated: responseCode = AppInfo.INITIATED; break; case InitiatedFailed: responseCode = AppInfo.INITIATEDFAILED; break; case MarkDown: responseCode = AppInfo.MARKDOWN; break; } rtn = appInfo.getStatus(); if(appInfo.getStatus() == AppStatus.MarkDown){ rtn = "markdown by "+appInfo.getMarkDownReason(); } isHandled = true; break; case "/status/detail": case "/health/detail": appInfo = ComponentManager.getStatus(AppInfo.class); Map<String,Object> statusDetail = new LinkedHashMap<>(); statusDetail.put("appStatus",appInfo.getStatus()); if(appInfo.getStatus()==AppStatus.MarkDown){ statusDetail.put("markDownReason",appInfo.getMarkDownReason()); } statusDetail.put("igniteDetail",ComponentManager.getStatus(IgniteStatus.class)); rtn = statusDetail; isHandled = true; break; default: for (String startPath : handlersMap.keySet()) { if (path.startsWith(startPath)) { isHandled = true; ViFunctionHandler functionHandler = handlersMap.get(startPath); permission = functionHandler.getPermission(user).getValue(); rtn = functionHandler.execute(path, user, permission, logger, params); break; } } break; } eventLogger.fireEvent(EventLogger.TRANSEND); }catch (Throwable e){ logger.warn("execute service error",e); e.printStackTrace(); eventLogger.fireEvent(EventLogger.TRANSEND,e); Throwable rootCause; if(e.getCause()!=null){ rootCause = e.getCause(); }else{ rootCause = e; } rtn = TextUtils.makeJSErrorMsg(rootCause.getMessage(),e.getClass().getName()); if(e instanceof NoPermissionException){ responseCode = SC_METHODNOTALLOWED; } }finally { eventLogger.fireEvent(EventLogger.TRANSFINALLY); } if(!isHandled){ rtn = path + " not found"; } long cost = (System.nanoTime()-startTime)/1000L; try { MetricsCollector.getCollector().record(Metrics.VIAPI, cost); }catch (Throwable e){ logger.error("metrics collect failed!",e); } return new ExeResult(rtn,permission,responseCode); } VIApiHandler(); }
|
VIApiHandler { public ExeResult executeService(String path,String user,Map<String,Object> params){ long startTime = System.nanoTime(); Object rtn=null; int responseCode = SC_OK; int permission = Permission.ALL.getValue(); EventLogger eventLogger = EventLoggerFactory.getTransLogger(getClass()); if(path == null){ return new ExeResult("NO PATH ERROR",0,SC_NOTFOUND); } path = path.toLowerCase(); boolean isHandled =false; try { eventLogger.fireEvent(EventLogger.TRANSSTART,path); switch (path) { case "/ip": rtn = params.get("req_ip"); isHandled = true; break; case "/status": case "/health": AppInfo appInfo = ComponentManager.getStatus(AppInfo.class); switch (appInfo.getStatus()) { case Uninitiated: responseCode = AppInfo.UNINITIATED; break; case Initiating: responseCode = AppInfo.INITIATING; break; case Initiated: responseCode = AppInfo.INITIATED; break; case InitiatedFailed: responseCode = AppInfo.INITIATEDFAILED; break; case MarkDown: responseCode = AppInfo.MARKDOWN; break; } rtn = appInfo.getStatus(); if(appInfo.getStatus() == AppStatus.MarkDown){ rtn = "markdown by "+appInfo.getMarkDownReason(); } isHandled = true; break; case "/status/detail": case "/health/detail": appInfo = ComponentManager.getStatus(AppInfo.class); Map<String,Object> statusDetail = new LinkedHashMap<>(); statusDetail.put("appStatus",appInfo.getStatus()); if(appInfo.getStatus()==AppStatus.MarkDown){ statusDetail.put("markDownReason",appInfo.getMarkDownReason()); } statusDetail.put("igniteDetail",ComponentManager.getStatus(IgniteStatus.class)); rtn = statusDetail; isHandled = true; break; default: for (String startPath : handlersMap.keySet()) { if (path.startsWith(startPath)) { isHandled = true; ViFunctionHandler functionHandler = handlersMap.get(startPath); permission = functionHandler.getPermission(user).getValue(); rtn = functionHandler.execute(path, user, permission, logger, params); break; } } break; } eventLogger.fireEvent(EventLogger.TRANSEND); }catch (Throwable e){ logger.warn("execute service error",e); e.printStackTrace(); eventLogger.fireEvent(EventLogger.TRANSEND,e); Throwable rootCause; if(e.getCause()!=null){ rootCause = e.getCause(); }else{ rootCause = e; } rtn = TextUtils.makeJSErrorMsg(rootCause.getMessage(),e.getClass().getName()); if(e instanceof NoPermissionException){ responseCode = SC_METHODNOTALLOWED; } }finally { eventLogger.fireEvent(EventLogger.TRANSFINALLY); } if(!isHandled){ rtn = path + " not found"; } long cost = (System.nanoTime()-startTime)/1000L; try { MetricsCollector.getCollector().record(Metrics.VIAPI, cost); }catch (Throwable e){ logger.error("metrics collect failed!",e); } return new ExeResult(rtn,permission,responseCode); } VIApiHandler(); static synchronized VIApiHandler getInstance(); boolean register(ViFunctionHandler apiHandler); ExeResult executeService(String path,String user,Map<String,Object> params); }
|
VIApiHandler { public ExeResult executeService(String path,String user,Map<String,Object> params){ long startTime = System.nanoTime(); Object rtn=null; int responseCode = SC_OK; int permission = Permission.ALL.getValue(); EventLogger eventLogger = EventLoggerFactory.getTransLogger(getClass()); if(path == null){ return new ExeResult("NO PATH ERROR",0,SC_NOTFOUND); } path = path.toLowerCase(); boolean isHandled =false; try { eventLogger.fireEvent(EventLogger.TRANSSTART,path); switch (path) { case "/ip": rtn = params.get("req_ip"); isHandled = true; break; case "/status": case "/health": AppInfo appInfo = ComponentManager.getStatus(AppInfo.class); switch (appInfo.getStatus()) { case Uninitiated: responseCode = AppInfo.UNINITIATED; break; case Initiating: responseCode = AppInfo.INITIATING; break; case Initiated: responseCode = AppInfo.INITIATED; break; case InitiatedFailed: responseCode = AppInfo.INITIATEDFAILED; break; case MarkDown: responseCode = AppInfo.MARKDOWN; break; } rtn = appInfo.getStatus(); if(appInfo.getStatus() == AppStatus.MarkDown){ rtn = "markdown by "+appInfo.getMarkDownReason(); } isHandled = true; break; case "/status/detail": case "/health/detail": appInfo = ComponentManager.getStatus(AppInfo.class); Map<String,Object> statusDetail = new LinkedHashMap<>(); statusDetail.put("appStatus",appInfo.getStatus()); if(appInfo.getStatus()==AppStatus.MarkDown){ statusDetail.put("markDownReason",appInfo.getMarkDownReason()); } statusDetail.put("igniteDetail",ComponentManager.getStatus(IgniteStatus.class)); rtn = statusDetail; isHandled = true; break; default: for (String startPath : handlersMap.keySet()) { if (path.startsWith(startPath)) { isHandled = true; ViFunctionHandler functionHandler = handlersMap.get(startPath); permission = functionHandler.getPermission(user).getValue(); rtn = functionHandler.execute(path, user, permission, logger, params); break; } } break; } eventLogger.fireEvent(EventLogger.TRANSEND); }catch (Throwable e){ logger.warn("execute service error",e); e.printStackTrace(); eventLogger.fireEvent(EventLogger.TRANSEND,e); Throwable rootCause; if(e.getCause()!=null){ rootCause = e.getCause(); }else{ rootCause = e; } rtn = TextUtils.makeJSErrorMsg(rootCause.getMessage(),e.getClass().getName()); if(e instanceof NoPermissionException){ responseCode = SC_METHODNOTALLOWED; } }finally { eventLogger.fireEvent(EventLogger.TRANSFINALLY); } if(!isHandled){ rtn = path + " not found"; } long cost = (System.nanoTime()-startTime)/1000L; try { MetricsCollector.getCollector().record(Metrics.VIAPI, cost); }catch (Throwable e){ logger.error("metrics collect failed!",e); } return new ExeResult(rtn,permission,responseCode); } VIApiHandler(); static synchronized VIApiHandler getInstance(); boolean register(ViFunctionHandler apiHandler); ExeResult executeService(String path,String user,Map<String,Object> params); }
|
@Test public void testVIServer() throws Exception { int port = 1998; VIServer server = new VIServer(port); server.start(); URL url = new URL("http: Gson gson = new Gson(); List<CInfo> infos= new ArrayList<>(); String content = IOUtils.readAll((InputStream)url.getContent()); System.out.println(IgniteManager.getStatus().getMessages()); infos =gson.fromJson(content, infos.getClass()); Assert.assertTrue(infos.size()>=3); server.stop(); try{ infos =gson.fromJson(IOUtils.readAll((InputStream)url.getContent()), infos.getClass()); Assert.fail("can't reach there"); }catch (Exception e){ Assert.assertTrue(e instanceof ConnectException); } }
|
public VIServer(int listenPort,boolean useVIAuthentication) throws Exception { server = new Server(listenPort); handler = bind(server, String.valueOf(listenPort),useVIAuthentication); }
|
VIServer { public VIServer(int listenPort,boolean useVIAuthentication) throws Exception { server = new Server(listenPort); handler = bind(server, String.valueOf(listenPort),useVIAuthentication); } }
|
VIServer { public VIServer(int listenPort,boolean useVIAuthentication) throws Exception { server = new Server(listenPort); handler = bind(server, String.valueOf(listenPort),useVIAuthentication); } VIServer(int listenPort,boolean useVIAuthentication); VIServer(int listenPort); }
|
VIServer { public VIServer(int listenPort,boolean useVIAuthentication) throws Exception { server = new Server(listenPort); handler = bind(server, String.valueOf(listenPort),useVIAuthentication); } VIServer(int listenPort,boolean useVIAuthentication); VIServer(int listenPort); static ServletHandler bind(Server server,String id); static ServletHandler bind(Server server,String id,boolean useVIAuthentication); Server getInnerServer(); ServletHandler getHandler(); synchronized void start(); synchronized void stop(); }
|
VIServer { public VIServer(int listenPort,boolean useVIAuthentication) throws Exception { server = new Server(listenPort); handler = bind(server, String.valueOf(listenPort),useVIAuthentication); } VIServer(int listenPort,boolean useVIAuthentication); VIServer(int listenPort); static ServletHandler bind(Server server,String id); static ServletHandler bind(Server server,String id,boolean useVIAuthentication); Server getInnerServer(); ServletHandler getHandler(); synchronized void start(); synchronized void stop(); }
|
@Test public void testDispatch_withArgumentAndExistingMethod_willSuccess() { testEventBus.testEventWithArgument(THE_ARG); replay(testEventBus); eventBusDispatcher.dispatch("testEventWithArgument", THE_ARG); verify(testEventBus); }
|
@Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); }
|
EventBusDispatcher implements IEventDispatcher { @Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); } }
|
EventBusDispatcher implements IEventDispatcher { @Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); } EventBusDispatcher(EventBusManager ebManager, EventBus eb); }
|
EventBusDispatcher implements IEventDispatcher { @Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); } EventBusDispatcher(EventBusManager ebManager, EventBus eb); @Override void dispatch(String name, Object event); @Override void dispatch(String name, Object... args); }
|
EventBusDispatcher implements IEventDispatcher { @Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); } EventBusDispatcher(EventBusManager ebManager, EventBus eb); @Override void dispatch(String name, Object event); @Override void dispatch(String name, Object... args); }
|
@Test public void testBindUiFields() throws Exception { UiBinderView view = instance.bind(UiBinderView.class, new Locale("en"), null); assertNotNull("button ui field not bound", view.save); assertNotNull("label ui field not bound", view.labelOne); assertNotNull("label ui field not bound", view.labelTwo); }
|
public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); void setUiMessageSource(IUiMessageSource messageSource); boolean isBindable(Class<?> viewClass); boolean isBindable(String viewName); T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder); Component bind(String viewName, Locale locale, IEventBinder eventBinder); }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); void setUiMessageSource(IUiMessageSource messageSource); boolean isBindable(Class<?> viewClass); boolean isBindable(String viewName); T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder); Component bind(String viewName, Locale locale, IEventBinder eventBinder); }
|
@Test public void testBindTranslations() throws Exception { UiBinderView view = instance.bind(UiBinderView.class, new Locale("en"), null); Label l = view.title; String caption = l.getCaption(); assertNotNull("caption is null", caption); assertEquals("wrong caption", "This is the view title", caption); assertEquals("de only message wrong", "Dieser Text steht nur in deutsch", view.labelTwo.getCaption()); }
|
public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); void setUiMessageSource(IUiMessageSource messageSource); boolean isBindable(Class<?> viewClass); boolean isBindable(String viewName); T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder); Component bind(String viewName, Locale locale, IEventBinder eventBinder); }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); void setUiMessageSource(IUiMessageSource messageSource); boolean isBindable(Class<?> viewClass); boolean isBindable(String viewName); T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder); Component bind(String viewName, Locale locale, IEventBinder eventBinder); }
|
@Test public void testBindSimpleComponentsInitialized() throws UiBinderException { UiBinderViewInit root = instance.bind(UiBinderViewInit.class, new Locale("en"), null); assertNotNull("component is null", root); assertTrue("component is not initialzed", root.initialized); }
|
public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); void setUiMessageSource(IUiMessageSource messageSource); boolean isBindable(Class<?> viewClass); boolean isBindable(String viewName); T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder); Component bind(String viewName, Locale locale, IEventBinder eventBinder); }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); void setUiMessageSource(IUiMessageSource messageSource); boolean isBindable(Class<?> viewClass); boolean isBindable(String viewName); T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder); Component bind(String viewName, Locale locale, IEventBinder eventBinder); }
|
@Test public void testGetMessageStringLocale() { String message = instance.getMessage("message.key", new Locale("de")); assertNotNull(message); assertEquals("Hier ein kleiner Text um die Sache zu erläutern.", message); }
|
@Override public String getMessage(String key, Locale locale) { ResourceBundle bundle = getBundle(locale); if (bundle.containsKey(key)) { return bundle.getString(key); } return "{{ message missing: " + key + "}}"; }
|
ResourceBundleUiMessageSource implements IUiMessageSource { @Override public String getMessage(String key, Locale locale) { ResourceBundle bundle = getBundle(locale); if (bundle.containsKey(key)) { return bundle.getString(key); } return "{{ message missing: " + key + "}}"; } }
|
ResourceBundleUiMessageSource implements IUiMessageSource { @Override public String getMessage(String key, Locale locale) { ResourceBundle bundle = getBundle(locale); if (bundle.containsKey(key)) { return bundle.getString(key); } return "{{ message missing: " + key + "}}"; } ResourceBundleUiMessageSource(String baseName); }
|
ResourceBundleUiMessageSource implements IUiMessageSource { @Override public String getMessage(String key, Locale locale) { ResourceBundle bundle = getBundle(locale); if (bundle.containsKey(key)) { return bundle.getString(key); } return "{{ message missing: " + key + "}}"; } ResourceBundleUiMessageSource(String baseName); @Override String getMessage(String key, Locale locale); @Override String getMessage(String key, Object[] args, Locale locale); }
|
ResourceBundleUiMessageSource implements IUiMessageSource { @Override public String getMessage(String key, Locale locale) { ResourceBundle bundle = getBundle(locale); if (bundle.containsKey(key)) { return bundle.getString(key); } return "{{ message missing: " + key + "}}"; } ResourceBundleUiMessageSource(String baseName); @Override String getMessage(String key, Locale locale); @Override String getMessage(String key, Object[] args, Locale locale); }
|
@Test public void testGetMessageStringLocaleDefault() { String message = instance.getMessage("message.default", new Locale("en")); assertNotNull(message); assertEquals("Dieser Text steht nur in deutsch", message); }
|
@Override public String getMessage(String key, Locale locale) { ResourceBundle bundle = getBundle(locale); if (bundle.containsKey(key)) { return bundle.getString(key); } return "{{ message missing: " + key + "}}"; }
|
ResourceBundleUiMessageSource implements IUiMessageSource { @Override public String getMessage(String key, Locale locale) { ResourceBundle bundle = getBundle(locale); if (bundle.containsKey(key)) { return bundle.getString(key); } return "{{ message missing: " + key + "}}"; } }
|
ResourceBundleUiMessageSource implements IUiMessageSource { @Override public String getMessage(String key, Locale locale) { ResourceBundle bundle = getBundle(locale); if (bundle.containsKey(key)) { return bundle.getString(key); } return "{{ message missing: " + key + "}}"; } ResourceBundleUiMessageSource(String baseName); }
|
ResourceBundleUiMessageSource implements IUiMessageSource { @Override public String getMessage(String key, Locale locale) { ResourceBundle bundle = getBundle(locale); if (bundle.containsKey(key)) { return bundle.getString(key); } return "{{ message missing: " + key + "}}"; } ResourceBundleUiMessageSource(String baseName); @Override String getMessage(String key, Locale locale); @Override String getMessage(String key, Object[] args, Locale locale); }
|
ResourceBundleUiMessageSource implements IUiMessageSource { @Override public String getMessage(String key, Locale locale) { ResourceBundle bundle = getBundle(locale); if (bundle.containsKey(key)) { return bundle.getString(key); } return "{{ message missing: " + key + "}}"; } ResourceBundleUiMessageSource(String baseName); @Override String getMessage(String key, Locale locale); @Override String getMessage(String key, Object[] args, Locale locale); }
|
@Test public void testGetMessageStringObjectArrayLocale() { String message = instance.getMessage("message.args", new Object[] {"PARAM"}, new Locale("de")); assertNotNull(message); assertEquals("Hier eine Nachricht mit Parametern... PARAM wurde eingegeben.", message); }
|
@Override public String getMessage(String key, Locale locale) { ResourceBundle bundle = getBundle(locale); if (bundle.containsKey(key)) { return bundle.getString(key); } return "{{ message missing: " + key + "}}"; }
|
ResourceBundleUiMessageSource implements IUiMessageSource { @Override public String getMessage(String key, Locale locale) { ResourceBundle bundle = getBundle(locale); if (bundle.containsKey(key)) { return bundle.getString(key); } return "{{ message missing: " + key + "}}"; } }
|
ResourceBundleUiMessageSource implements IUiMessageSource { @Override public String getMessage(String key, Locale locale) { ResourceBundle bundle = getBundle(locale); if (bundle.containsKey(key)) { return bundle.getString(key); } return "{{ message missing: " + key + "}}"; } ResourceBundleUiMessageSource(String baseName); }
|
ResourceBundleUiMessageSource implements IUiMessageSource { @Override public String getMessage(String key, Locale locale) { ResourceBundle bundle = getBundle(locale); if (bundle.containsKey(key)) { return bundle.getString(key); } return "{{ message missing: " + key + "}}"; } ResourceBundleUiMessageSource(String baseName); @Override String getMessage(String key, Locale locale); @Override String getMessage(String key, Object[] args, Locale locale); }
|
ResourceBundleUiMessageSource implements IUiMessageSource { @Override public String getMessage(String key, Locale locale) { ResourceBundle bundle = getBundle(locale); if (bundle.containsKey(key)) { return bundle.getString(key); } return "{{ message missing: " + key + "}}"; } ResourceBundleUiMessageSource(String baseName); @Override String getMessage(String key, Locale locale); @Override String getMessage(String key, Object[] args, Locale locale); }
|
@Test public void getTargetNamespace() { assertEquals("urn:org.vaadin.mvp.uibinder.method", instance.getTargetNamespace()); }
|
@Override public String getTargetNamespace() { return "urn:org.vaadin.mvp.uibinder.method"; }
|
MethodHandler implements TargetHandler { @Override public String getTargetNamespace() { return "urn:org.vaadin.mvp.uibinder.method"; } }
|
MethodHandler implements TargetHandler { @Override public String getTargetNamespace() { return "urn:org.vaadin.mvp.uibinder.method"; } MethodHandler(ComponentHandler ch); }
|
MethodHandler implements TargetHandler { @Override public String getTargetNamespace() { return "urn:org.vaadin.mvp.uibinder.method"; } MethodHandler(ComponentHandler ch); @Override String getTargetNamespace(); @Override void handleElementOpen(String uri, String name); @Override void handleElementClose(); @Override void handleAttribute(String name, Object value); }
|
MethodHandler implements TargetHandler { @Override public String getTargetNamespace() { return "urn:org.vaadin.mvp.uibinder.method"; } MethodHandler(ComponentHandler ch); @Override String getTargetNamespace(); @Override void handleElementOpen(String uri, String name); @Override void handleElementClose(); @Override void handleAttribute(String name, Object value); }
|
@Test public void handleElementOpen() { instance.handleElementOpen("", "addComponent"); Method m = ch.getCurrentMethod(); assertNotNull(m); assertEquals("addComponent", m.getName()); assertEquals(1, m.getParameterTypes().length); }
|
@Override public void handleElementOpen(String uri, String name) { method = findMethod(ch.getCurrent().getClass(), name); if (method == null) { throw new IllegalArgumentException("The method " + name + " is missing in " + ch.getCurrent().getClass()); } ch.setCurrentMethod(method); }
|
MethodHandler implements TargetHandler { @Override public void handleElementOpen(String uri, String name) { method = findMethod(ch.getCurrent().getClass(), name); if (method == null) { throw new IllegalArgumentException("The method " + name + " is missing in " + ch.getCurrent().getClass()); } ch.setCurrentMethod(method); } }
|
MethodHandler implements TargetHandler { @Override public void handleElementOpen(String uri, String name) { method = findMethod(ch.getCurrent().getClass(), name); if (method == null) { throw new IllegalArgumentException("The method " + name + " is missing in " + ch.getCurrent().getClass()); } ch.setCurrentMethod(method); } MethodHandler(ComponentHandler ch); }
|
MethodHandler implements TargetHandler { @Override public void handleElementOpen(String uri, String name) { method = findMethod(ch.getCurrent().getClass(), name); if (method == null) { throw new IllegalArgumentException("The method " + name + " is missing in " + ch.getCurrent().getClass()); } ch.setCurrentMethod(method); } MethodHandler(ComponentHandler ch); @Override String getTargetNamespace(); @Override void handleElementOpen(String uri, String name); @Override void handleElementClose(); @Override void handleAttribute(String name, Object value); }
|
MethodHandler implements TargetHandler { @Override public void handleElementOpen(String uri, String name) { method = findMethod(ch.getCurrent().getClass(), name); if (method == null) { throw new IllegalArgumentException("The method " + name + " is missing in " + ch.getCurrent().getClass()); } ch.setCurrentMethod(method); } MethodHandler(ComponentHandler ch); @Override String getTargetNamespace(); @Override void handleElementOpen(String uri, String name); @Override void handleElementClose(); @Override void handleAttribute(String name, Object value); }
|
@Test (expected = IllegalArgumentException.class) public void handleElementOpenFail() { instance.handleElementOpen("", "nirvanaMethod"); }
|
@Override public void handleElementOpen(String uri, String name) { method = findMethod(ch.getCurrent().getClass(), name); if (method == null) { throw new IllegalArgumentException("The method " + name + " is missing in " + ch.getCurrent().getClass()); } ch.setCurrentMethod(method); }
|
MethodHandler implements TargetHandler { @Override public void handleElementOpen(String uri, String name) { method = findMethod(ch.getCurrent().getClass(), name); if (method == null) { throw new IllegalArgumentException("The method " + name + " is missing in " + ch.getCurrent().getClass()); } ch.setCurrentMethod(method); } }
|
MethodHandler implements TargetHandler { @Override public void handleElementOpen(String uri, String name) { method = findMethod(ch.getCurrent().getClass(), name); if (method == null) { throw new IllegalArgumentException("The method " + name + " is missing in " + ch.getCurrent().getClass()); } ch.setCurrentMethod(method); } MethodHandler(ComponentHandler ch); }
|
MethodHandler implements TargetHandler { @Override public void handleElementOpen(String uri, String name) { method = findMethod(ch.getCurrent().getClass(), name); if (method == null) { throw new IllegalArgumentException("The method " + name + " is missing in " + ch.getCurrent().getClass()); } ch.setCurrentMethod(method); } MethodHandler(ComponentHandler ch); @Override String getTargetNamespace(); @Override void handleElementOpen(String uri, String name); @Override void handleElementClose(); @Override void handleAttribute(String name, Object value); }
|
MethodHandler implements TargetHandler { @Override public void handleElementOpen(String uri, String name) { method = findMethod(ch.getCurrent().getClass(), name); if (method == null) { throw new IllegalArgumentException("The method " + name + " is missing in " + ch.getCurrent().getClass()); } ch.setCurrentMethod(method); } MethodHandler(ComponentHandler ch); @Override String getTargetNamespace(); @Override void handleElementOpen(String uri, String name); @Override void handleElementClose(); @Override void handleAttribute(String name, Object value); }
|
@Test public void findMethod() throws SecurityException, NoSuchMethodException { Method m = instance.findMethod(VerticalLayout.class, "addComponent"); assertNotNull(m); assertEquals("addComponent", m.getName()); assertEquals(1, m.getParameterTypes().length); }
|
protected Method findMethod(Class<?> clazz, String name) { Class<?> searchType = clazz; while (searchType != null) { Method[] methods = (searchType.isInterface() ? searchType.getMethods() : searchType.getDeclaredMethods()); for (Method method : methods) { if (name.equals(method.getName()) && method.getParameterTypes().length == 1 && Component.class.isAssignableFrom(method.getParameterTypes()[0])) { return method; } } searchType = searchType.getSuperclass(); } return null; }
|
MethodHandler implements TargetHandler { protected Method findMethod(Class<?> clazz, String name) { Class<?> searchType = clazz; while (searchType != null) { Method[] methods = (searchType.isInterface() ? searchType.getMethods() : searchType.getDeclaredMethods()); for (Method method : methods) { if (name.equals(method.getName()) && method.getParameterTypes().length == 1 && Component.class.isAssignableFrom(method.getParameterTypes()[0])) { return method; } } searchType = searchType.getSuperclass(); } return null; } }
|
MethodHandler implements TargetHandler { protected Method findMethod(Class<?> clazz, String name) { Class<?> searchType = clazz; while (searchType != null) { Method[] methods = (searchType.isInterface() ? searchType.getMethods() : searchType.getDeclaredMethods()); for (Method method : methods) { if (name.equals(method.getName()) && method.getParameterTypes().length == 1 && Component.class.isAssignableFrom(method.getParameterTypes()[0])) { return method; } } searchType = searchType.getSuperclass(); } return null; } MethodHandler(ComponentHandler ch); }
|
MethodHandler implements TargetHandler { protected Method findMethod(Class<?> clazz, String name) { Class<?> searchType = clazz; while (searchType != null) { Method[] methods = (searchType.isInterface() ? searchType.getMethods() : searchType.getDeclaredMethods()); for (Method method : methods) { if (name.equals(method.getName()) && method.getParameterTypes().length == 1 && Component.class.isAssignableFrom(method.getParameterTypes()[0])) { return method; } } searchType = searchType.getSuperclass(); } return null; } MethodHandler(ComponentHandler ch); @Override String getTargetNamespace(); @Override void handleElementOpen(String uri, String name); @Override void handleElementClose(); @Override void handleAttribute(String name, Object value); }
|
MethodHandler implements TargetHandler { protected Method findMethod(Class<?> clazz, String name) { Class<?> searchType = clazz; while (searchType != null) { Method[] methods = (searchType.isInterface() ? searchType.getMethods() : searchType.getDeclaredMethods()); for (Method method : methods) { if (name.equals(method.getName()) && method.getParameterTypes().length == 1 && Component.class.isAssignableFrom(method.getParameterTypes()[0])) { return method; } } searchType = searchType.getSuperclass(); } return null; } MethodHandler(ComponentHandler ch); @Override String getTargetNamespace(); @Override void handleElementOpen(String uri, String name); @Override void handleElementClose(); @Override void handleAttribute(String name, Object value); }
|
@Test public void testDispatch_withoutArgumentAndExistingMethod_willSuccess() { testEventBus.testEventWithoutArgument(); replay(testEventBus); eventBusDispatcher.dispatch("testEventWithoutArgument"); verify(testEventBus); }
|
@Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); }
|
EventBusDispatcher implements IEventDispatcher { @Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); } }
|
EventBusDispatcher implements IEventDispatcher { @Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); } EventBusDispatcher(EventBusManager ebManager, EventBus eb); }
|
EventBusDispatcher implements IEventDispatcher { @Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); } EventBusDispatcher(EventBusManager ebManager, EventBus eb); @Override void dispatch(String name, Object event); @Override void dispatch(String name, Object... args); }
|
EventBusDispatcher implements IEventDispatcher { @Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); } EventBusDispatcher(EventBusManager ebManager, EventBus eb); @Override void dispatch(String name, Object event); @Override void dispatch(String name, Object... args); }
|
@Test public void findMethodNotFound() throws SecurityException, NoSuchMethodException { Method m = instance.findMethod(VerticalLayout.class, "nirvanaMethod"); assertNull(m); }
|
protected Method findMethod(Class<?> clazz, String name) { Class<?> searchType = clazz; while (searchType != null) { Method[] methods = (searchType.isInterface() ? searchType.getMethods() : searchType.getDeclaredMethods()); for (Method method : methods) { if (name.equals(method.getName()) && method.getParameterTypes().length == 1 && Component.class.isAssignableFrom(method.getParameterTypes()[0])) { return method; } } searchType = searchType.getSuperclass(); } return null; }
|
MethodHandler implements TargetHandler { protected Method findMethod(Class<?> clazz, String name) { Class<?> searchType = clazz; while (searchType != null) { Method[] methods = (searchType.isInterface() ? searchType.getMethods() : searchType.getDeclaredMethods()); for (Method method : methods) { if (name.equals(method.getName()) && method.getParameterTypes().length == 1 && Component.class.isAssignableFrom(method.getParameterTypes()[0])) { return method; } } searchType = searchType.getSuperclass(); } return null; } }
|
MethodHandler implements TargetHandler { protected Method findMethod(Class<?> clazz, String name) { Class<?> searchType = clazz; while (searchType != null) { Method[] methods = (searchType.isInterface() ? searchType.getMethods() : searchType.getDeclaredMethods()); for (Method method : methods) { if (name.equals(method.getName()) && method.getParameterTypes().length == 1 && Component.class.isAssignableFrom(method.getParameterTypes()[0])) { return method; } } searchType = searchType.getSuperclass(); } return null; } MethodHandler(ComponentHandler ch); }
|
MethodHandler implements TargetHandler { protected Method findMethod(Class<?> clazz, String name) { Class<?> searchType = clazz; while (searchType != null) { Method[] methods = (searchType.isInterface() ? searchType.getMethods() : searchType.getDeclaredMethods()); for (Method method : methods) { if (name.equals(method.getName()) && method.getParameterTypes().length == 1 && Component.class.isAssignableFrom(method.getParameterTypes()[0])) { return method; } } searchType = searchType.getSuperclass(); } return null; } MethodHandler(ComponentHandler ch); @Override String getTargetNamespace(); @Override void handleElementOpen(String uri, String name); @Override void handleElementClose(); @Override void handleAttribute(String name, Object value); }
|
MethodHandler implements TargetHandler { protected Method findMethod(Class<?> clazz, String name) { Class<?> searchType = clazz; while (searchType != null) { Method[] methods = (searchType.isInterface() ? searchType.getMethods() : searchType.getDeclaredMethods()); for (Method method : methods) { if (name.equals(method.getName()) && method.getParameterTypes().length == 1 && Component.class.isAssignableFrom(method.getParameterTypes()[0])) { return method; } } searchType = searchType.getSuperclass(); } return null; } MethodHandler(ComponentHandler ch); @Override String getTargetNamespace(); @Override void handleElementOpen(String uri, String name); @Override void handleElementClose(); @Override void handleAttribute(String name, Object value); }
|
@Test public void testFindApplicableSetterMethodStringArg() throws SecurityException, NoSuchMethodException { Method m = instance.findApplicableSetterMethod(bean, "height", "67%"); assertEquals("wrong setter selected", VerticalLayout.class.getMethod("setHeight", String.class), m); }
|
protected Method findApplicableSetterMethod(Object target, String propertyName, Object value) { String methodName = "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); Method[] methods = target.getClass().getMethods(); if (value.getClass().isArray()) { } else { Method method = MethodUtils.getAccessibleMethod(target.getClass(), methodName, value.getClass()); if (method != null) { return method; } for (Method m : methods) { if (!m.getName().equals(methodName)) { continue; } Class<?>[] parameterTypes = m.getParameterTypes(); if (parameterTypes.length != 1) { continue; } Class<?> mpt = parameterTypes[0]; if (mpt.isAssignableFrom(value.getClass())) { return m; } Converter converter = ConvertUtils.lookup(mpt); if (converter != null) { return m; } } } if (value == null || value.toString().length() == 0) { for (Method m : methods) { if (m.getName().equals(methodName) && m.getParameterTypes().length == 0) { return m; } } } return null; }
|
ComponentHandler implements TargetHandler { protected Method findApplicableSetterMethod(Object target, String propertyName, Object value) { String methodName = "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); Method[] methods = target.getClass().getMethods(); if (value.getClass().isArray()) { } else { Method method = MethodUtils.getAccessibleMethod(target.getClass(), methodName, value.getClass()); if (method != null) { return method; } for (Method m : methods) { if (!m.getName().equals(methodName)) { continue; } Class<?>[] parameterTypes = m.getParameterTypes(); if (parameterTypes.length != 1) { continue; } Class<?> mpt = parameterTypes[0]; if (mpt.isAssignableFrom(value.getClass())) { return m; } Converter converter = ConvertUtils.lookup(mpt); if (converter != null) { return m; } } } if (value == null || value.toString().length() == 0) { for (Method m : methods) { if (m.getName().equals(methodName) && m.getParameterTypes().length == 0) { return m; } } } return null; } }
|
ComponentHandler implements TargetHandler { protected Method findApplicableSetterMethod(Object target, String propertyName, Object value) { String methodName = "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); Method[] methods = target.getClass().getMethods(); if (value.getClass().isArray()) { } else { Method method = MethodUtils.getAccessibleMethod(target.getClass(), methodName, value.getClass()); if (method != null) { return method; } for (Method m : methods) { if (!m.getName().equals(methodName)) { continue; } Class<?>[] parameterTypes = m.getParameterTypes(); if (parameterTypes.length != 1) { continue; } Class<?> mpt = parameterTypes[0]; if (mpt.isAssignableFrom(value.getClass())) { return m; } Converter converter = ConvertUtils.lookup(mpt); if (converter != null) { return m; } } } if (value == null || value.toString().length() == 0) { for (Method m : methods) { if (m.getName().equals(methodName) && m.getParameterTypes().length == 0) { return m; } } } return null; } ComponentHandler(UiBinder uiBinder, Component view, Locale locale); }
|
ComponentHandler implements TargetHandler { protected Method findApplicableSetterMethod(Object target, String propertyName, Object value) { String methodName = "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); Method[] methods = target.getClass().getMethods(); if (value.getClass().isArray()) { } else { Method method = MethodUtils.getAccessibleMethod(target.getClass(), methodName, value.getClass()); if (method != null) { return method; } for (Method m : methods) { if (!m.getName().equals(methodName)) { continue; } Class<?>[] parameterTypes = m.getParameterTypes(); if (parameterTypes.length != 1) { continue; } Class<?> mpt = parameterTypes[0]; if (mpt.isAssignableFrom(value.getClass())) { return m; } Converter converter = ConvertUtils.lookup(mpt); if (converter != null) { return m; } } } if (value == null || value.toString().length() == 0) { for (Method m : methods) { if (m.getName().equals(methodName) && m.getParameterTypes().length == 0) { return m; } } } return null; } ComponentHandler(UiBinder uiBinder, Component view, Locale locale); IEventBinder getEventBinder(); void setEventBinder(IEventBinder eventBinder); @Override String getTargetNamespace(); Component getRootComponent(); @Override void handleElementOpen(String uri, String name); @Override void handleElementClose(); @Override void handleAttribute(String name, Object value); Component getCurrent(); void setCurrentMethod(Method currentMethod); }
|
ComponentHandler implements TargetHandler { protected Method findApplicableSetterMethod(Object target, String propertyName, Object value) { String methodName = "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); Method[] methods = target.getClass().getMethods(); if (value.getClass().isArray()) { } else { Method method = MethodUtils.getAccessibleMethod(target.getClass(), methodName, value.getClass()); if (method != null) { return method; } for (Method m : methods) { if (!m.getName().equals(methodName)) { continue; } Class<?>[] parameterTypes = m.getParameterTypes(); if (parameterTypes.length != 1) { continue; } Class<?> mpt = parameterTypes[0]; if (mpt.isAssignableFrom(value.getClass())) { return m; } Converter converter = ConvertUtils.lookup(mpt); if (converter != null) { return m; } } } if (value == null || value.toString().length() == 0) { for (Method m : methods) { if (m.getName().equals(methodName) && m.getParameterTypes().length == 0) { return m; } } } return null; } ComponentHandler(UiBinder uiBinder, Component view, Locale locale); IEventBinder getEventBinder(); void setEventBinder(IEventBinder eventBinder); @Override String getTargetNamespace(); Component getRootComponent(); @Override void handleElementOpen(String uri, String name); @Override void handleElementClose(); @Override void handleAttribute(String name, Object value); Component getCurrent(); void setCurrentMethod(Method currentMethod); }
|
@Ignore("Currently not supported, introduce expressions, e.g. MVEL to support this.") @Test public void testFindApplicableSetterMethodFloatIntArg() throws SecurityException, NoSuchMethodException { Method m = instance.findApplicableSetterMethod(bean, "height", "67, #UNITS_PERCENTAGE"); assertEquals("wrong setter selected", VerticalLayout.class.getMethod("setHeight", float.class, int.class), m); }
|
protected Method findApplicableSetterMethod(Object target, String propertyName, Object value) { String methodName = "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); Method[] methods = target.getClass().getMethods(); if (value.getClass().isArray()) { } else { Method method = MethodUtils.getAccessibleMethod(target.getClass(), methodName, value.getClass()); if (method != null) { return method; } for (Method m : methods) { if (!m.getName().equals(methodName)) { continue; } Class<?>[] parameterTypes = m.getParameterTypes(); if (parameterTypes.length != 1) { continue; } Class<?> mpt = parameterTypes[0]; if (mpt.isAssignableFrom(value.getClass())) { return m; } Converter converter = ConvertUtils.lookup(mpt); if (converter != null) { return m; } } } if (value == null || value.toString().length() == 0) { for (Method m : methods) { if (m.getName().equals(methodName) && m.getParameterTypes().length == 0) { return m; } } } return null; }
|
ComponentHandler implements TargetHandler { protected Method findApplicableSetterMethod(Object target, String propertyName, Object value) { String methodName = "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); Method[] methods = target.getClass().getMethods(); if (value.getClass().isArray()) { } else { Method method = MethodUtils.getAccessibleMethod(target.getClass(), methodName, value.getClass()); if (method != null) { return method; } for (Method m : methods) { if (!m.getName().equals(methodName)) { continue; } Class<?>[] parameterTypes = m.getParameterTypes(); if (parameterTypes.length != 1) { continue; } Class<?> mpt = parameterTypes[0]; if (mpt.isAssignableFrom(value.getClass())) { return m; } Converter converter = ConvertUtils.lookup(mpt); if (converter != null) { return m; } } } if (value == null || value.toString().length() == 0) { for (Method m : methods) { if (m.getName().equals(methodName) && m.getParameterTypes().length == 0) { return m; } } } return null; } }
|
ComponentHandler implements TargetHandler { protected Method findApplicableSetterMethod(Object target, String propertyName, Object value) { String methodName = "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); Method[] methods = target.getClass().getMethods(); if (value.getClass().isArray()) { } else { Method method = MethodUtils.getAccessibleMethod(target.getClass(), methodName, value.getClass()); if (method != null) { return method; } for (Method m : methods) { if (!m.getName().equals(methodName)) { continue; } Class<?>[] parameterTypes = m.getParameterTypes(); if (parameterTypes.length != 1) { continue; } Class<?> mpt = parameterTypes[0]; if (mpt.isAssignableFrom(value.getClass())) { return m; } Converter converter = ConvertUtils.lookup(mpt); if (converter != null) { return m; } } } if (value == null || value.toString().length() == 0) { for (Method m : methods) { if (m.getName().equals(methodName) && m.getParameterTypes().length == 0) { return m; } } } return null; } ComponentHandler(UiBinder uiBinder, Component view, Locale locale); }
|
ComponentHandler implements TargetHandler { protected Method findApplicableSetterMethod(Object target, String propertyName, Object value) { String methodName = "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); Method[] methods = target.getClass().getMethods(); if (value.getClass().isArray()) { } else { Method method = MethodUtils.getAccessibleMethod(target.getClass(), methodName, value.getClass()); if (method != null) { return method; } for (Method m : methods) { if (!m.getName().equals(methodName)) { continue; } Class<?>[] parameterTypes = m.getParameterTypes(); if (parameterTypes.length != 1) { continue; } Class<?> mpt = parameterTypes[0]; if (mpt.isAssignableFrom(value.getClass())) { return m; } Converter converter = ConvertUtils.lookup(mpt); if (converter != null) { return m; } } } if (value == null || value.toString().length() == 0) { for (Method m : methods) { if (m.getName().equals(methodName) && m.getParameterTypes().length == 0) { return m; } } } return null; } ComponentHandler(UiBinder uiBinder, Component view, Locale locale); IEventBinder getEventBinder(); void setEventBinder(IEventBinder eventBinder); @Override String getTargetNamespace(); Component getRootComponent(); @Override void handleElementOpen(String uri, String name); @Override void handleElementClose(); @Override void handleAttribute(String name, Object value); Component getCurrent(); void setCurrentMethod(Method currentMethod); }
|
ComponentHandler implements TargetHandler { protected Method findApplicableSetterMethod(Object target, String propertyName, Object value) { String methodName = "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); Method[] methods = target.getClass().getMethods(); if (value.getClass().isArray()) { } else { Method method = MethodUtils.getAccessibleMethod(target.getClass(), methodName, value.getClass()); if (method != null) { return method; } for (Method m : methods) { if (!m.getName().equals(methodName)) { continue; } Class<?>[] parameterTypes = m.getParameterTypes(); if (parameterTypes.length != 1) { continue; } Class<?> mpt = parameterTypes[0]; if (mpt.isAssignableFrom(value.getClass())) { return m; } Converter converter = ConvertUtils.lookup(mpt); if (converter != null) { return m; } } } if (value == null || value.toString().length() == 0) { for (Method m : methods) { if (m.getName().equals(methodName) && m.getParameterTypes().length == 0) { return m; } } } return null; } ComponentHandler(UiBinder uiBinder, Component view, Locale locale); IEventBinder getEventBinder(); void setEventBinder(IEventBinder eventBinder); @Override String getTargetNamespace(); Component getRootComponent(); @Override void handleElementOpen(String uri, String name); @Override void handleElementClose(); @Override void handleAttribute(String name, Object value); Component getCurrent(); void setCurrentMethod(Method currentMethod); }
|
@Test public void testFindApplicableSetterMethodNoArg() throws SecurityException, NoSuchMethodException { Method m = instance.findApplicableSetterMethod(bean, "sizeFull", ""); assertEquals("wrong setter selected", VerticalLayout.class.getMethod("setSizeFull"), m); }
|
protected Method findApplicableSetterMethod(Object target, String propertyName, Object value) { String methodName = "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); Method[] methods = target.getClass().getMethods(); if (value.getClass().isArray()) { } else { Method method = MethodUtils.getAccessibleMethod(target.getClass(), methodName, value.getClass()); if (method != null) { return method; } for (Method m : methods) { if (!m.getName().equals(methodName)) { continue; } Class<?>[] parameterTypes = m.getParameterTypes(); if (parameterTypes.length != 1) { continue; } Class<?> mpt = parameterTypes[0]; if (mpt.isAssignableFrom(value.getClass())) { return m; } Converter converter = ConvertUtils.lookup(mpt); if (converter != null) { return m; } } } if (value == null || value.toString().length() == 0) { for (Method m : methods) { if (m.getName().equals(methodName) && m.getParameterTypes().length == 0) { return m; } } } return null; }
|
ComponentHandler implements TargetHandler { protected Method findApplicableSetterMethod(Object target, String propertyName, Object value) { String methodName = "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); Method[] methods = target.getClass().getMethods(); if (value.getClass().isArray()) { } else { Method method = MethodUtils.getAccessibleMethod(target.getClass(), methodName, value.getClass()); if (method != null) { return method; } for (Method m : methods) { if (!m.getName().equals(methodName)) { continue; } Class<?>[] parameterTypes = m.getParameterTypes(); if (parameterTypes.length != 1) { continue; } Class<?> mpt = parameterTypes[0]; if (mpt.isAssignableFrom(value.getClass())) { return m; } Converter converter = ConvertUtils.lookup(mpt); if (converter != null) { return m; } } } if (value == null || value.toString().length() == 0) { for (Method m : methods) { if (m.getName().equals(methodName) && m.getParameterTypes().length == 0) { return m; } } } return null; } }
|
ComponentHandler implements TargetHandler { protected Method findApplicableSetterMethod(Object target, String propertyName, Object value) { String methodName = "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); Method[] methods = target.getClass().getMethods(); if (value.getClass().isArray()) { } else { Method method = MethodUtils.getAccessibleMethod(target.getClass(), methodName, value.getClass()); if (method != null) { return method; } for (Method m : methods) { if (!m.getName().equals(methodName)) { continue; } Class<?>[] parameterTypes = m.getParameterTypes(); if (parameterTypes.length != 1) { continue; } Class<?> mpt = parameterTypes[0]; if (mpt.isAssignableFrom(value.getClass())) { return m; } Converter converter = ConvertUtils.lookup(mpt); if (converter != null) { return m; } } } if (value == null || value.toString().length() == 0) { for (Method m : methods) { if (m.getName().equals(methodName) && m.getParameterTypes().length == 0) { return m; } } } return null; } ComponentHandler(UiBinder uiBinder, Component view, Locale locale); }
|
ComponentHandler implements TargetHandler { protected Method findApplicableSetterMethod(Object target, String propertyName, Object value) { String methodName = "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); Method[] methods = target.getClass().getMethods(); if (value.getClass().isArray()) { } else { Method method = MethodUtils.getAccessibleMethod(target.getClass(), methodName, value.getClass()); if (method != null) { return method; } for (Method m : methods) { if (!m.getName().equals(methodName)) { continue; } Class<?>[] parameterTypes = m.getParameterTypes(); if (parameterTypes.length != 1) { continue; } Class<?> mpt = parameterTypes[0]; if (mpt.isAssignableFrom(value.getClass())) { return m; } Converter converter = ConvertUtils.lookup(mpt); if (converter != null) { return m; } } } if (value == null || value.toString().length() == 0) { for (Method m : methods) { if (m.getName().equals(methodName) && m.getParameterTypes().length == 0) { return m; } } } return null; } ComponentHandler(UiBinder uiBinder, Component view, Locale locale); IEventBinder getEventBinder(); void setEventBinder(IEventBinder eventBinder); @Override String getTargetNamespace(); Component getRootComponent(); @Override void handleElementOpen(String uri, String name); @Override void handleElementClose(); @Override void handleAttribute(String name, Object value); Component getCurrent(); void setCurrentMethod(Method currentMethod); }
|
ComponentHandler implements TargetHandler { protected Method findApplicableSetterMethod(Object target, String propertyName, Object value) { String methodName = "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); Method[] methods = target.getClass().getMethods(); if (value.getClass().isArray()) { } else { Method method = MethodUtils.getAccessibleMethod(target.getClass(), methodName, value.getClass()); if (method != null) { return method; } for (Method m : methods) { if (!m.getName().equals(methodName)) { continue; } Class<?>[] parameterTypes = m.getParameterTypes(); if (parameterTypes.length != 1) { continue; } Class<?> mpt = parameterTypes[0]; if (mpt.isAssignableFrom(value.getClass())) { return m; } Converter converter = ConvertUtils.lookup(mpt); if (converter != null) { return m; } } } if (value == null || value.toString().length() == 0) { for (Method m : methods) { if (m.getName().equals(methodName) && m.getParameterTypes().length == 0) { return m; } } } return null; } ComponentHandler(UiBinder uiBinder, Component view, Locale locale); IEventBinder getEventBinder(); void setEventBinder(IEventBinder eventBinder); @Override String getTargetNamespace(); Component getRootComponent(); @Override void handleElementOpen(String uri, String name); @Override void handleElementClose(); @Override void handleAttribute(String name, Object value); Component getCurrent(); void setCurrentMethod(Method currentMethod); }
|
@Test public void testNamespaceUriToPackageName() throws UiConstraintException { String pkg = instance.namespaceUriToPackageName("urn:import:org.vaadin.test"); assertEquals("invalid conversion of namespace to package", "org.vaadin.test", pkg); }
|
protected String namespaceUriToPackageName(String uri) throws UiConstraintException { if (packages.containsKey(uri)) { return packages.get(uri); } try { URI nsUri = new URI(uri); String pkg = null; String scheme = nsUri.getScheme(); if ("urn".equals(scheme)) { pkg = nsUri.getSchemeSpecificPart(); } else if ("http".equals(scheme)) { String[] hostParts = nsUri.getHost().split("\\."); String[] pathParts = nsUri.getPath().substring(1).split("/"); StringBuilder sb = new StringBuilder(); List<String> list = new ArrayList<String>(Arrays.asList(hostParts)); Collections.reverse(list); list.addAll(Arrays.asList(pathParts)); if (list.size() > 0) { sb.append(list.get(0)); for (int i = 1; i < list.size(); i++) { sb.append(".").append(list.get(i)); } } pkg = sb.toString(); } else { throw new UiConstraintException("Unsupported namespace URI scheme: " + scheme + " (URI = " + uri + ")"); } if (pkg.startsWith("import:")) { pkg = pkg.substring("import:".length()); } packages.put(uri, pkg); return pkg; } catch (URISyntaxException e) { throw new UiConstraintException("Invalid namespace URI", e); } }
|
ComponentHandler implements TargetHandler { protected String namespaceUriToPackageName(String uri) throws UiConstraintException { if (packages.containsKey(uri)) { return packages.get(uri); } try { URI nsUri = new URI(uri); String pkg = null; String scheme = nsUri.getScheme(); if ("urn".equals(scheme)) { pkg = nsUri.getSchemeSpecificPart(); } else if ("http".equals(scheme)) { String[] hostParts = nsUri.getHost().split("\\."); String[] pathParts = nsUri.getPath().substring(1).split("/"); StringBuilder sb = new StringBuilder(); List<String> list = new ArrayList<String>(Arrays.asList(hostParts)); Collections.reverse(list); list.addAll(Arrays.asList(pathParts)); if (list.size() > 0) { sb.append(list.get(0)); for (int i = 1; i < list.size(); i++) { sb.append(".").append(list.get(i)); } } pkg = sb.toString(); } else { throw new UiConstraintException("Unsupported namespace URI scheme: " + scheme + " (URI = " + uri + ")"); } if (pkg.startsWith("import:")) { pkg = pkg.substring("import:".length()); } packages.put(uri, pkg); return pkg; } catch (URISyntaxException e) { throw new UiConstraintException("Invalid namespace URI", e); } } }
|
ComponentHandler implements TargetHandler { protected String namespaceUriToPackageName(String uri) throws UiConstraintException { if (packages.containsKey(uri)) { return packages.get(uri); } try { URI nsUri = new URI(uri); String pkg = null; String scheme = nsUri.getScheme(); if ("urn".equals(scheme)) { pkg = nsUri.getSchemeSpecificPart(); } else if ("http".equals(scheme)) { String[] hostParts = nsUri.getHost().split("\\."); String[] pathParts = nsUri.getPath().substring(1).split("/"); StringBuilder sb = new StringBuilder(); List<String> list = new ArrayList<String>(Arrays.asList(hostParts)); Collections.reverse(list); list.addAll(Arrays.asList(pathParts)); if (list.size() > 0) { sb.append(list.get(0)); for (int i = 1; i < list.size(); i++) { sb.append(".").append(list.get(i)); } } pkg = sb.toString(); } else { throw new UiConstraintException("Unsupported namespace URI scheme: " + scheme + " (URI = " + uri + ")"); } if (pkg.startsWith("import:")) { pkg = pkg.substring("import:".length()); } packages.put(uri, pkg); return pkg; } catch (URISyntaxException e) { throw new UiConstraintException("Invalid namespace URI", e); } } ComponentHandler(UiBinder uiBinder, Component view, Locale locale); }
|
ComponentHandler implements TargetHandler { protected String namespaceUriToPackageName(String uri) throws UiConstraintException { if (packages.containsKey(uri)) { return packages.get(uri); } try { URI nsUri = new URI(uri); String pkg = null; String scheme = nsUri.getScheme(); if ("urn".equals(scheme)) { pkg = nsUri.getSchemeSpecificPart(); } else if ("http".equals(scheme)) { String[] hostParts = nsUri.getHost().split("\\."); String[] pathParts = nsUri.getPath().substring(1).split("/"); StringBuilder sb = new StringBuilder(); List<String> list = new ArrayList<String>(Arrays.asList(hostParts)); Collections.reverse(list); list.addAll(Arrays.asList(pathParts)); if (list.size() > 0) { sb.append(list.get(0)); for (int i = 1; i < list.size(); i++) { sb.append(".").append(list.get(i)); } } pkg = sb.toString(); } else { throw new UiConstraintException("Unsupported namespace URI scheme: " + scheme + " (URI = " + uri + ")"); } if (pkg.startsWith("import:")) { pkg = pkg.substring("import:".length()); } packages.put(uri, pkg); return pkg; } catch (URISyntaxException e) { throw new UiConstraintException("Invalid namespace URI", e); } } ComponentHandler(UiBinder uiBinder, Component view, Locale locale); IEventBinder getEventBinder(); void setEventBinder(IEventBinder eventBinder); @Override String getTargetNamespace(); Component getRootComponent(); @Override void handleElementOpen(String uri, String name); @Override void handleElementClose(); @Override void handleAttribute(String name, Object value); Component getCurrent(); void setCurrentMethod(Method currentMethod); }
|
ComponentHandler implements TargetHandler { protected String namespaceUriToPackageName(String uri) throws UiConstraintException { if (packages.containsKey(uri)) { return packages.get(uri); } try { URI nsUri = new URI(uri); String pkg = null; String scheme = nsUri.getScheme(); if ("urn".equals(scheme)) { pkg = nsUri.getSchemeSpecificPart(); } else if ("http".equals(scheme)) { String[] hostParts = nsUri.getHost().split("\\."); String[] pathParts = nsUri.getPath().substring(1).split("/"); StringBuilder sb = new StringBuilder(); List<String> list = new ArrayList<String>(Arrays.asList(hostParts)); Collections.reverse(list); list.addAll(Arrays.asList(pathParts)); if (list.size() > 0) { sb.append(list.get(0)); for (int i = 1; i < list.size(); i++) { sb.append(".").append(list.get(i)); } } pkg = sb.toString(); } else { throw new UiConstraintException("Unsupported namespace URI scheme: " + scheme + " (URI = " + uri + ")"); } if (pkg.startsWith("import:")) { pkg = pkg.substring("import:".length()); } packages.put(uri, pkg); return pkg; } catch (URISyntaxException e) { throw new UiConstraintException("Invalid namespace URI", e); } } ComponentHandler(UiBinder uiBinder, Component view, Locale locale); IEventBinder getEventBinder(); void setEventBinder(IEventBinder eventBinder); @Override String getTargetNamespace(); Component getRootComponent(); @Override void handleElementOpen(String uri, String name); @Override void handleElementClose(); @Override void handleAttribute(String name, Object value); Component getCurrent(); void setCurrentMethod(Method currentMethod); }
|
@Test public void testNamespaceUriToPackageNameHttp() throws UiConstraintException { String pkg = instance.namespaceUriToPackageName("http: assertEquals("invalid conversion of namespace to package", "org.vaadin.test.some.pkg", pkg); }
|
protected String namespaceUriToPackageName(String uri) throws UiConstraintException { if (packages.containsKey(uri)) { return packages.get(uri); } try { URI nsUri = new URI(uri); String pkg = null; String scheme = nsUri.getScheme(); if ("urn".equals(scheme)) { pkg = nsUri.getSchemeSpecificPart(); } else if ("http".equals(scheme)) { String[] hostParts = nsUri.getHost().split("\\."); String[] pathParts = nsUri.getPath().substring(1).split("/"); StringBuilder sb = new StringBuilder(); List<String> list = new ArrayList<String>(Arrays.asList(hostParts)); Collections.reverse(list); list.addAll(Arrays.asList(pathParts)); if (list.size() > 0) { sb.append(list.get(0)); for (int i = 1; i < list.size(); i++) { sb.append(".").append(list.get(i)); } } pkg = sb.toString(); } else { throw new UiConstraintException("Unsupported namespace URI scheme: " + scheme + " (URI = " + uri + ")"); } if (pkg.startsWith("import:")) { pkg = pkg.substring("import:".length()); } packages.put(uri, pkg); return pkg; } catch (URISyntaxException e) { throw new UiConstraintException("Invalid namespace URI", e); } }
|
ComponentHandler implements TargetHandler { protected String namespaceUriToPackageName(String uri) throws UiConstraintException { if (packages.containsKey(uri)) { return packages.get(uri); } try { URI nsUri = new URI(uri); String pkg = null; String scheme = nsUri.getScheme(); if ("urn".equals(scheme)) { pkg = nsUri.getSchemeSpecificPart(); } else if ("http".equals(scheme)) { String[] hostParts = nsUri.getHost().split("\\."); String[] pathParts = nsUri.getPath().substring(1).split("/"); StringBuilder sb = new StringBuilder(); List<String> list = new ArrayList<String>(Arrays.asList(hostParts)); Collections.reverse(list); list.addAll(Arrays.asList(pathParts)); if (list.size() > 0) { sb.append(list.get(0)); for (int i = 1; i < list.size(); i++) { sb.append(".").append(list.get(i)); } } pkg = sb.toString(); } else { throw new UiConstraintException("Unsupported namespace URI scheme: " + scheme + " (URI = " + uri + ")"); } if (pkg.startsWith("import:")) { pkg = pkg.substring("import:".length()); } packages.put(uri, pkg); return pkg; } catch (URISyntaxException e) { throw new UiConstraintException("Invalid namespace URI", e); } } }
|
ComponentHandler implements TargetHandler { protected String namespaceUriToPackageName(String uri) throws UiConstraintException { if (packages.containsKey(uri)) { return packages.get(uri); } try { URI nsUri = new URI(uri); String pkg = null; String scheme = nsUri.getScheme(); if ("urn".equals(scheme)) { pkg = nsUri.getSchemeSpecificPart(); } else if ("http".equals(scheme)) { String[] hostParts = nsUri.getHost().split("\\."); String[] pathParts = nsUri.getPath().substring(1).split("/"); StringBuilder sb = new StringBuilder(); List<String> list = new ArrayList<String>(Arrays.asList(hostParts)); Collections.reverse(list); list.addAll(Arrays.asList(pathParts)); if (list.size() > 0) { sb.append(list.get(0)); for (int i = 1; i < list.size(); i++) { sb.append(".").append(list.get(i)); } } pkg = sb.toString(); } else { throw new UiConstraintException("Unsupported namespace URI scheme: " + scheme + " (URI = " + uri + ")"); } if (pkg.startsWith("import:")) { pkg = pkg.substring("import:".length()); } packages.put(uri, pkg); return pkg; } catch (URISyntaxException e) { throw new UiConstraintException("Invalid namespace URI", e); } } ComponentHandler(UiBinder uiBinder, Component view, Locale locale); }
|
ComponentHandler implements TargetHandler { protected String namespaceUriToPackageName(String uri) throws UiConstraintException { if (packages.containsKey(uri)) { return packages.get(uri); } try { URI nsUri = new URI(uri); String pkg = null; String scheme = nsUri.getScheme(); if ("urn".equals(scheme)) { pkg = nsUri.getSchemeSpecificPart(); } else if ("http".equals(scheme)) { String[] hostParts = nsUri.getHost().split("\\."); String[] pathParts = nsUri.getPath().substring(1).split("/"); StringBuilder sb = new StringBuilder(); List<String> list = new ArrayList<String>(Arrays.asList(hostParts)); Collections.reverse(list); list.addAll(Arrays.asList(pathParts)); if (list.size() > 0) { sb.append(list.get(0)); for (int i = 1; i < list.size(); i++) { sb.append(".").append(list.get(i)); } } pkg = sb.toString(); } else { throw new UiConstraintException("Unsupported namespace URI scheme: " + scheme + " (URI = " + uri + ")"); } if (pkg.startsWith("import:")) { pkg = pkg.substring("import:".length()); } packages.put(uri, pkg); return pkg; } catch (URISyntaxException e) { throw new UiConstraintException("Invalid namespace URI", e); } } ComponentHandler(UiBinder uiBinder, Component view, Locale locale); IEventBinder getEventBinder(); void setEventBinder(IEventBinder eventBinder); @Override String getTargetNamespace(); Component getRootComponent(); @Override void handleElementOpen(String uri, String name); @Override void handleElementClose(); @Override void handleAttribute(String name, Object value); Component getCurrent(); void setCurrentMethod(Method currentMethod); }
|
ComponentHandler implements TargetHandler { protected String namespaceUriToPackageName(String uri) throws UiConstraintException { if (packages.containsKey(uri)) { return packages.get(uri); } try { URI nsUri = new URI(uri); String pkg = null; String scheme = nsUri.getScheme(); if ("urn".equals(scheme)) { pkg = nsUri.getSchemeSpecificPart(); } else if ("http".equals(scheme)) { String[] hostParts = nsUri.getHost().split("\\."); String[] pathParts = nsUri.getPath().substring(1).split("/"); StringBuilder sb = new StringBuilder(); List<String> list = new ArrayList<String>(Arrays.asList(hostParts)); Collections.reverse(list); list.addAll(Arrays.asList(pathParts)); if (list.size() > 0) { sb.append(list.get(0)); for (int i = 1; i < list.size(); i++) { sb.append(".").append(list.get(i)); } } pkg = sb.toString(); } else { throw new UiConstraintException("Unsupported namespace URI scheme: " + scheme + " (URI = " + uri + ")"); } if (pkg.startsWith("import:")) { pkg = pkg.substring("import:".length()); } packages.put(uri, pkg); return pkg; } catch (URISyntaxException e) { throw new UiConstraintException("Invalid namespace URI", e); } } ComponentHandler(UiBinder uiBinder, Component view, Locale locale); IEventBinder getEventBinder(); void setEventBinder(IEventBinder eventBinder); @Override String getTargetNamespace(); Component getRootComponent(); @Override void handleElementOpen(String uri, String name); @Override void handleElementClose(); @Override void handleAttribute(String name, Object value); Component getCurrent(); void setCurrentMethod(Method currentMethod); }
|
@Test(expected = IllegalArgumentException.class) public void testGetEventBus_privateEventBus_NotSupported() { eventBusManager.getEventBus(StubPrivateEventBus.class); }
|
public <T extends EventBus> T getEventBus(Class<T> busType) { if (isPrivateEventBus(busType)) { throw new IllegalArgumentException("The bus " + busType + " is marked as private and it can be retrieved only from his presenter"); } assertEventBus(busType); EventBus eventBus = eventBusses.get(busType); return busType.cast(eventBus); }
|
EventBusManager { public <T extends EventBus> T getEventBus(Class<T> busType) { if (isPrivateEventBus(busType)) { throw new IllegalArgumentException("The bus " + busType + " is marked as private and it can be retrieved only from his presenter"); } assertEventBus(busType); EventBus eventBus = eventBusses.get(busType); return busType.cast(eventBus); } }
|
EventBusManager { public <T extends EventBus> T getEventBus(Class<T> busType) { if (isPrivateEventBus(busType)) { throw new IllegalArgumentException("The bus " + busType + " is marked as private and it can be retrieved only from his presenter"); } assertEventBus(busType); EventBus eventBus = eventBusses.get(busType); return busType.cast(eventBus); } EventBusManager(); }
|
EventBusManager { public <T extends EventBus> T getEventBus(Class<T> busType) { if (isPrivateEventBus(busType)) { throw new IllegalArgumentException("The bus " + busType + " is marked as private and it can be retrieved only from his presenter"); } assertEventBus(busType); EventBus eventBus = eventBusses.get(busType); return busType.cast(eventBus); } EventBusManager(); T register(Class<T> busType, Object subscriber); T register(Class<T> busType, Object subscriber,EventBus parentEventBus); void addSubscriber(Object subscriber); T getEventBus(Class<T> busType); }
|
EventBusManager { public <T extends EventBus> T getEventBus(Class<T> busType) { if (isPrivateEventBus(busType)) { throw new IllegalArgumentException("The bus " + busType + " is marked as private and it can be retrieved only from his presenter"); } assertEventBus(busType); EventBus eventBus = eventBusses.get(busType); return busType.cast(eventBus); } EventBusManager(); T register(Class<T> busType, Object subscriber); T register(Class<T> busType, Object subscriber,EventBus parentEventBus); void addSubscriber(Object subscriber); T getEventBus(Class<T> busType); }
|
@Test public void testGetEventBus_NonPrivateEventBus_Supported() { eventBusManager.getEventBus(StubEventBus.class); }
|
public <T extends EventBus> T getEventBus(Class<T> busType) { if (isPrivateEventBus(busType)) { throw new IllegalArgumentException("The bus " + busType + " is marked as private and it can be retrieved only from his presenter"); } assertEventBus(busType); EventBus eventBus = eventBusses.get(busType); return busType.cast(eventBus); }
|
EventBusManager { public <T extends EventBus> T getEventBus(Class<T> busType) { if (isPrivateEventBus(busType)) { throw new IllegalArgumentException("The bus " + busType + " is marked as private and it can be retrieved only from his presenter"); } assertEventBus(busType); EventBus eventBus = eventBusses.get(busType); return busType.cast(eventBus); } }
|
EventBusManager { public <T extends EventBus> T getEventBus(Class<T> busType) { if (isPrivateEventBus(busType)) { throw new IllegalArgumentException("The bus " + busType + " is marked as private and it can be retrieved only from his presenter"); } assertEventBus(busType); EventBus eventBus = eventBusses.get(busType); return busType.cast(eventBus); } EventBusManager(); }
|
EventBusManager { public <T extends EventBus> T getEventBus(Class<T> busType) { if (isPrivateEventBus(busType)) { throw new IllegalArgumentException("The bus " + busType + " is marked as private and it can be retrieved only from his presenter"); } assertEventBus(busType); EventBus eventBus = eventBusses.get(busType); return busType.cast(eventBus); } EventBusManager(); T register(Class<T> busType, Object subscriber); T register(Class<T> busType, Object subscriber,EventBus parentEventBus); void addSubscriber(Object subscriber); T getEventBus(Class<T> busType); }
|
EventBusManager { public <T extends EventBus> T getEventBus(Class<T> busType) { if (isPrivateEventBus(busType)) { throw new IllegalArgumentException("The bus " + busType + " is marked as private and it can be retrieved only from his presenter"); } assertEventBus(busType); EventBus eventBus = eventBusses.get(busType); return busType.cast(eventBus); } EventBusManager(); T register(Class<T> busType, Object subscriber); T register(Class<T> busType, Object subscriber,EventBus parentEventBus); void addSubscriber(Object subscriber); T getEventBus(Class<T> busType); }
|
@Test public void testRegister_NonPrivateEventBus_mustReturnSameBus() { EventBus eventBus = eventBusManager.register(StubEventBus.class,new Object()); EventBus eventBus2 = eventBusManager.register(StubEventBus.class,new Object()); Assert.assertSame("Different event bus instances",eventBus,eventBus2); }
|
public <T extends EventBus> T register(Class<T> busType, Object subscriber) { return this.register(busType,subscriber,null); }
|
EventBusManager { public <T extends EventBus> T register(Class<T> busType, Object subscriber) { return this.register(busType,subscriber,null); } }
|
EventBusManager { public <T extends EventBus> T register(Class<T> busType, Object subscriber) { return this.register(busType,subscriber,null); } EventBusManager(); }
|
EventBusManager { public <T extends EventBus> T register(Class<T> busType, Object subscriber) { return this.register(busType,subscriber,null); } EventBusManager(); T register(Class<T> busType, Object subscriber); T register(Class<T> busType, Object subscriber,EventBus parentEventBus); void addSubscriber(Object subscriber); T getEventBus(Class<T> busType); }
|
EventBusManager { public <T extends EventBus> T register(Class<T> busType, Object subscriber) { return this.register(busType,subscriber,null); } EventBusManager(); T register(Class<T> busType, Object subscriber); T register(Class<T> busType, Object subscriber,EventBus parentEventBus); void addSubscriber(Object subscriber); T getEventBus(Class<T> busType); }
|
@Test public void testRegister_NonPrivateEventBus_mustReturnDifferentBus() { EventBus eventBus = eventBusManager.register(StubPrivateEventBus.class,new Object()); EventBus eventBus2 = eventBusManager.register(StubPrivateEventBus.class,new Object()); Assert.assertNotSame("Same event bus instances",eventBus,eventBus2); }
|
public <T extends EventBus> T register(Class<T> busType, Object subscriber) { return this.register(busType,subscriber,null); }
|
EventBusManager { public <T extends EventBus> T register(Class<T> busType, Object subscriber) { return this.register(busType,subscriber,null); } }
|
EventBusManager { public <T extends EventBus> T register(Class<T> busType, Object subscriber) { return this.register(busType,subscriber,null); } EventBusManager(); }
|
EventBusManager { public <T extends EventBus> T register(Class<T> busType, Object subscriber) { return this.register(busType,subscriber,null); } EventBusManager(); T register(Class<T> busType, Object subscriber); T register(Class<T> busType, Object subscriber,EventBus parentEventBus); void addSubscriber(Object subscriber); T getEventBus(Class<T> busType); }
|
EventBusManager { public <T extends EventBus> T register(Class<T> busType, Object subscriber) { return this.register(busType,subscriber,null); } EventBusManager(); T register(Class<T> busType, Object subscriber); T register(Class<T> busType, Object subscriber,EventBus parentEventBus); void addSubscriber(Object subscriber); T getEventBus(Class<T> busType); }
|
@Test(expected = Exception.class) public void testDispatch_withoutArgument_exceptionOccurred_willBeRaised() { testEventBus.testEventWithoutArgument(); expectLastCall().andThrow(new RuntimeException("Faking an exception")); replay(testEventBus); eventBusDispatcher.dispatch("testEventWithoutArgument"); verify(testEventBus); }
|
@Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); }
|
EventBusDispatcher implements IEventDispatcher { @Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); } }
|
EventBusDispatcher implements IEventDispatcher { @Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); } EventBusDispatcher(EventBusManager ebManager, EventBus eb); }
|
EventBusDispatcher implements IEventDispatcher { @Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); } EventBusDispatcher(EventBusManager ebManager, EventBus eb); @Override void dispatch(String name, Object event); @Override void dispatch(String name, Object... args); }
|
EventBusDispatcher implements IEventDispatcher { @Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); } EventBusDispatcher(EventBusManager ebManager, EventBus eb); @Override void dispatch(String name, Object event); @Override void dispatch(String name, Object... args); }
|
@Test public void testParentFallbackEventsDelivery_notExistingEventOnChildWillBeForwarded() throws Exception{ StubPrivateEventBus parentEventBus = createNiceMock(StubPrivateEventBus.class); parentEventBus.niceEvent(); replay(mainEventReceiverRegistry, parentEventBus); StubEventBus eventBus = EventBusHandlerProxyFactory.createEventBusHandler(StubEventBus.class, mainEventReceiverRegistry,parentEventBus); Class<? extends EventBus> eventBusType = eventBus.getClass(); Method method = eventBusType.getMethod("niceEvent"); method.invoke(eventBus); verify(mainEventReceiverRegistry,parentEventBus); }
|
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ("toString".equals(method.getName())) { return "EventBus<" + busName + ">"; } logger.info("Event received: {}", method.getName()); Event eventDef = method.getAnnotation(Event.class); logger.info("Event annotation: {}", eventDef); boolean localHandlerMethodFound = false; final boolean fallbackOnParent = parent != null; String eventName = method.getName(); String eventHandlerName = buildExpectedEventHandlerMethodName(eventName); Class<?>[] handlerTypes = eventDef.handlers(); for (Class<?> handlerType : handlerTypes) { Object handler = handlerRegistry.lookupReceiver(handlerType); if (handler == null) { logger.info("Handler {} not registered", handlerType.getName()); continue; } Method handlerMethod = lookupHandlerMethod(method, eventName, eventHandlerName, handler); if (handlerMethod == null) { continue; } try { localHandlerMethodFound = true; handlerMethod.invoke(handler, args); } catch (Exception e) { logger.debug("Failed to propagate event {} to handler {}", eventName, handlerType.getName()); throw new RuntimeException("During the invocations of the handler method an exception has occurred",e); } } if (!localHandlerMethodFound && fallbackOnParent) { delegateToParent(method.getName(),method.getParameterTypes(), args); } return null; }
|
EventBusHandler implements InvocationHandler { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ("toString".equals(method.getName())) { return "EventBus<" + busName + ">"; } logger.info("Event received: {}", method.getName()); Event eventDef = method.getAnnotation(Event.class); logger.info("Event annotation: {}", eventDef); boolean localHandlerMethodFound = false; final boolean fallbackOnParent = parent != null; String eventName = method.getName(); String eventHandlerName = buildExpectedEventHandlerMethodName(eventName); Class<?>[] handlerTypes = eventDef.handlers(); for (Class<?> handlerType : handlerTypes) { Object handler = handlerRegistry.lookupReceiver(handlerType); if (handler == null) { logger.info("Handler {} not registered", handlerType.getName()); continue; } Method handlerMethod = lookupHandlerMethod(method, eventName, eventHandlerName, handler); if (handlerMethod == null) { continue; } try { localHandlerMethodFound = true; handlerMethod.invoke(handler, args); } catch (Exception e) { logger.debug("Failed to propagate event {} to handler {}", eventName, handlerType.getName()); throw new RuntimeException("During the invocations of the handler method an exception has occurred",e); } } if (!localHandlerMethodFound && fallbackOnParent) { delegateToParent(method.getName(),method.getParameterTypes(), args); } return null; } }
|
EventBusHandler implements InvocationHandler { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ("toString".equals(method.getName())) { return "EventBus<" + busName + ">"; } logger.info("Event received: {}", method.getName()); Event eventDef = method.getAnnotation(Event.class); logger.info("Event annotation: {}", eventDef); boolean localHandlerMethodFound = false; final boolean fallbackOnParent = parent != null; String eventName = method.getName(); String eventHandlerName = buildExpectedEventHandlerMethodName(eventName); Class<?>[] handlerTypes = eventDef.handlers(); for (Class<?> handlerType : handlerTypes) { Object handler = handlerRegistry.lookupReceiver(handlerType); if (handler == null) { logger.info("Handler {} not registered", handlerType.getName()); continue; } Method handlerMethod = lookupHandlerMethod(method, eventName, eventHandlerName, handler); if (handlerMethod == null) { continue; } try { localHandlerMethodFound = true; handlerMethod.invoke(handler, args); } catch (Exception e) { logger.debug("Failed to propagate event {} to handler {}", eventName, handlerType.getName()); throw new RuntimeException("During the invocations of the handler method an exception has occurred",e); } } if (!localHandlerMethodFound && fallbackOnParent) { delegateToParent(method.getName(),method.getParameterTypes(), args); } return null; } EventBusHandler(IEventReceiverRegistry hr, String name); EventBusHandler(IEventReceiverRegistry hr, String name, EventBus parent); }
|
EventBusHandler implements InvocationHandler { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ("toString".equals(method.getName())) { return "EventBus<" + busName + ">"; } logger.info("Event received: {}", method.getName()); Event eventDef = method.getAnnotation(Event.class); logger.info("Event annotation: {}", eventDef); boolean localHandlerMethodFound = false; final boolean fallbackOnParent = parent != null; String eventName = method.getName(); String eventHandlerName = buildExpectedEventHandlerMethodName(eventName); Class<?>[] handlerTypes = eventDef.handlers(); for (Class<?> handlerType : handlerTypes) { Object handler = handlerRegistry.lookupReceiver(handlerType); if (handler == null) { logger.info("Handler {} not registered", handlerType.getName()); continue; } Method handlerMethod = lookupHandlerMethod(method, eventName, eventHandlerName, handler); if (handlerMethod == null) { continue; } try { localHandlerMethodFound = true; handlerMethod.invoke(handler, args); } catch (Exception e) { logger.debug("Failed to propagate event {} to handler {}", eventName, handlerType.getName()); throw new RuntimeException("During the invocations of the handler method an exception has occurred",e); } } if (!localHandlerMethodFound && fallbackOnParent) { delegateToParent(method.getName(),method.getParameterTypes(), args); } return null; } EventBusHandler(IEventReceiverRegistry hr, String name); EventBusHandler(IEventReceiverRegistry hr, String name, EventBus parent); @Override Object invoke(Object proxy, Method method, Object[] args); }
|
EventBusHandler implements InvocationHandler { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ("toString".equals(method.getName())) { return "EventBus<" + busName + ">"; } logger.info("Event received: {}", method.getName()); Event eventDef = method.getAnnotation(Event.class); logger.info("Event annotation: {}", eventDef); boolean localHandlerMethodFound = false; final boolean fallbackOnParent = parent != null; String eventName = method.getName(); String eventHandlerName = buildExpectedEventHandlerMethodName(eventName); Class<?>[] handlerTypes = eventDef.handlers(); for (Class<?> handlerType : handlerTypes) { Object handler = handlerRegistry.lookupReceiver(handlerType); if (handler == null) { logger.info("Handler {} not registered", handlerType.getName()); continue; } Method handlerMethod = lookupHandlerMethod(method, eventName, eventHandlerName, handler); if (handlerMethod == null) { continue; } try { localHandlerMethodFound = true; handlerMethod.invoke(handler, args); } catch (Exception e) { logger.debug("Failed to propagate event {} to handler {}", eventName, handlerType.getName()); throw new RuntimeException("During the invocations of the handler method an exception has occurred",e); } } if (!localHandlerMethodFound && fallbackOnParent) { delegateToParent(method.getName(),method.getParameterTypes(), args); } return null; } EventBusHandler(IEventReceiverRegistry hr, String name); EventBusHandler(IEventReceiverRegistry hr, String name, EventBus parent); @Override Object invoke(Object proxy, Method method, Object[] args); }
|
@Test(expected = Exception.class) public void testParentFallbackEventsDelivery_notExistingEventOnChildWillBeForwarded_exceptionIsThrown() throws Exception{ StubPrivateEventBus parentEventBus = createNiceMock(StubPrivateEventBus.class); parentEventBus.niceEvent(); expectLastCall().andThrow(new RuntimeException()); replay(mainEventReceiverRegistry, parentEventBus); StubEventBus eventBus = EventBusHandlerProxyFactory.createEventBusHandler(StubEventBus.class, mainEventReceiverRegistry,parentEventBus); Class<? extends EventBus> eventBusType = eventBus.getClass(); Method method = eventBusType.getMethod("niceEvent"); method.invoke(eventBus); verify(mainEventReceiverRegistry,parentEventBus); }
|
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ("toString".equals(method.getName())) { return "EventBus<" + busName + ">"; } logger.info("Event received: {}", method.getName()); Event eventDef = method.getAnnotation(Event.class); logger.info("Event annotation: {}", eventDef); boolean localHandlerMethodFound = false; final boolean fallbackOnParent = parent != null; String eventName = method.getName(); String eventHandlerName = buildExpectedEventHandlerMethodName(eventName); Class<?>[] handlerTypes = eventDef.handlers(); for (Class<?> handlerType : handlerTypes) { Object handler = handlerRegistry.lookupReceiver(handlerType); if (handler == null) { logger.info("Handler {} not registered", handlerType.getName()); continue; } Method handlerMethod = lookupHandlerMethod(method, eventName, eventHandlerName, handler); if (handlerMethod == null) { continue; } try { localHandlerMethodFound = true; handlerMethod.invoke(handler, args); } catch (Exception e) { logger.debug("Failed to propagate event {} to handler {}", eventName, handlerType.getName()); throw new RuntimeException("During the invocations of the handler method an exception has occurred",e); } } if (!localHandlerMethodFound && fallbackOnParent) { delegateToParent(method.getName(),method.getParameterTypes(), args); } return null; }
|
EventBusHandler implements InvocationHandler { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ("toString".equals(method.getName())) { return "EventBus<" + busName + ">"; } logger.info("Event received: {}", method.getName()); Event eventDef = method.getAnnotation(Event.class); logger.info("Event annotation: {}", eventDef); boolean localHandlerMethodFound = false; final boolean fallbackOnParent = parent != null; String eventName = method.getName(); String eventHandlerName = buildExpectedEventHandlerMethodName(eventName); Class<?>[] handlerTypes = eventDef.handlers(); for (Class<?> handlerType : handlerTypes) { Object handler = handlerRegistry.lookupReceiver(handlerType); if (handler == null) { logger.info("Handler {} not registered", handlerType.getName()); continue; } Method handlerMethod = lookupHandlerMethod(method, eventName, eventHandlerName, handler); if (handlerMethod == null) { continue; } try { localHandlerMethodFound = true; handlerMethod.invoke(handler, args); } catch (Exception e) { logger.debug("Failed to propagate event {} to handler {}", eventName, handlerType.getName()); throw new RuntimeException("During the invocations of the handler method an exception has occurred",e); } } if (!localHandlerMethodFound && fallbackOnParent) { delegateToParent(method.getName(),method.getParameterTypes(), args); } return null; } }
|
EventBusHandler implements InvocationHandler { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ("toString".equals(method.getName())) { return "EventBus<" + busName + ">"; } logger.info("Event received: {}", method.getName()); Event eventDef = method.getAnnotation(Event.class); logger.info("Event annotation: {}", eventDef); boolean localHandlerMethodFound = false; final boolean fallbackOnParent = parent != null; String eventName = method.getName(); String eventHandlerName = buildExpectedEventHandlerMethodName(eventName); Class<?>[] handlerTypes = eventDef.handlers(); for (Class<?> handlerType : handlerTypes) { Object handler = handlerRegistry.lookupReceiver(handlerType); if (handler == null) { logger.info("Handler {} not registered", handlerType.getName()); continue; } Method handlerMethod = lookupHandlerMethod(method, eventName, eventHandlerName, handler); if (handlerMethod == null) { continue; } try { localHandlerMethodFound = true; handlerMethod.invoke(handler, args); } catch (Exception e) { logger.debug("Failed to propagate event {} to handler {}", eventName, handlerType.getName()); throw new RuntimeException("During the invocations of the handler method an exception has occurred",e); } } if (!localHandlerMethodFound && fallbackOnParent) { delegateToParent(method.getName(),method.getParameterTypes(), args); } return null; } EventBusHandler(IEventReceiverRegistry hr, String name); EventBusHandler(IEventReceiverRegistry hr, String name, EventBus parent); }
|
EventBusHandler implements InvocationHandler { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ("toString".equals(method.getName())) { return "EventBus<" + busName + ">"; } logger.info("Event received: {}", method.getName()); Event eventDef = method.getAnnotation(Event.class); logger.info("Event annotation: {}", eventDef); boolean localHandlerMethodFound = false; final boolean fallbackOnParent = parent != null; String eventName = method.getName(); String eventHandlerName = buildExpectedEventHandlerMethodName(eventName); Class<?>[] handlerTypes = eventDef.handlers(); for (Class<?> handlerType : handlerTypes) { Object handler = handlerRegistry.lookupReceiver(handlerType); if (handler == null) { logger.info("Handler {} not registered", handlerType.getName()); continue; } Method handlerMethod = lookupHandlerMethod(method, eventName, eventHandlerName, handler); if (handlerMethod == null) { continue; } try { localHandlerMethodFound = true; handlerMethod.invoke(handler, args); } catch (Exception e) { logger.debug("Failed to propagate event {} to handler {}", eventName, handlerType.getName()); throw new RuntimeException("During the invocations of the handler method an exception has occurred",e); } } if (!localHandlerMethodFound && fallbackOnParent) { delegateToParent(method.getName(),method.getParameterTypes(), args); } return null; } EventBusHandler(IEventReceiverRegistry hr, String name); EventBusHandler(IEventReceiverRegistry hr, String name, EventBus parent); @Override Object invoke(Object proxy, Method method, Object[] args); }
|
EventBusHandler implements InvocationHandler { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ("toString".equals(method.getName())) { return "EventBus<" + busName + ">"; } logger.info("Event received: {}", method.getName()); Event eventDef = method.getAnnotation(Event.class); logger.info("Event annotation: {}", eventDef); boolean localHandlerMethodFound = false; final boolean fallbackOnParent = parent != null; String eventName = method.getName(); String eventHandlerName = buildExpectedEventHandlerMethodName(eventName); Class<?>[] handlerTypes = eventDef.handlers(); for (Class<?> handlerType : handlerTypes) { Object handler = handlerRegistry.lookupReceiver(handlerType); if (handler == null) { logger.info("Handler {} not registered", handlerType.getName()); continue; } Method handlerMethod = lookupHandlerMethod(method, eventName, eventHandlerName, handler); if (handlerMethod == null) { continue; } try { localHandlerMethodFound = true; handlerMethod.invoke(handler, args); } catch (Exception e) { logger.debug("Failed to propagate event {} to handler {}", eventName, handlerType.getName()); throw new RuntimeException("During the invocations of the handler method an exception has occurred",e); } } if (!localHandlerMethodFound && fallbackOnParent) { delegateToParent(method.getName(),method.getParameterTypes(), args); } return null; } EventBusHandler(IEventReceiverRegistry hr, String name); EventBusHandler(IEventReceiverRegistry hr, String name, EventBus parent); @Override Object invoke(Object proxy, Method method, Object[] args); }
|
@Test public void testCreate() { IPresenter<?, ? extends EventBus> presenter = instance.createPresenter("spring"); assertNotNull("created presenter is null", presenter); assertNotNull("presenters view is null", presenter.getView()); assertTrue("presenters bind() method has not been called", ((SpringPresenter)presenter).bound); assertNotNull("presenter eventbus is null", presenter.getEventBus()); }
|
@SuppressWarnings("unchecked") public IPresenter<?, ? extends EventBus> create(Object name,EventBus parentEventBus) { if (!(name instanceof String)) { throw new IllegalArgumentException("Argument is expected to be a bean name (string)"); } String beanName = (String) name; if (applicationContext.containsBean(beanName)) { IPresenter p = applicationContext.getBean(beanName, IPresenter.class); p.setApplication(application); p.setMessageSource(messageSource); Presenter def = p.getClass().getAnnotation(Presenter.class); if (def == null) { throw new IllegalArgumentException("Missing @Presenter annotation on bean '" + beanName + "'"); } EventBus eventBus = createEventBus((Class<IPresenter>) p.getClass(), p,parentEventBus); p.setEventBus(eventBus); try { Object view = viewFactory.createView(eventBusManager, p, def.view(), locale); p.setView(view); } catch (ViewFactoryException e) { logger.error("Failed to create view for presenter", e); } p.bind(); return p; } throw new IllegalArgumentException("No presenter is defined for name: " + name); }
|
SpringPresenterFactory extends AbstractPresenterFactory implements ApplicationContextAware { @SuppressWarnings("unchecked") public IPresenter<?, ? extends EventBus> create(Object name,EventBus parentEventBus) { if (!(name instanceof String)) { throw new IllegalArgumentException("Argument is expected to be a bean name (string)"); } String beanName = (String) name; if (applicationContext.containsBean(beanName)) { IPresenter p = applicationContext.getBean(beanName, IPresenter.class); p.setApplication(application); p.setMessageSource(messageSource); Presenter def = p.getClass().getAnnotation(Presenter.class); if (def == null) { throw new IllegalArgumentException("Missing @Presenter annotation on bean '" + beanName + "'"); } EventBus eventBus = createEventBus((Class<IPresenter>) p.getClass(), p,parentEventBus); p.setEventBus(eventBus); try { Object view = viewFactory.createView(eventBusManager, p, def.view(), locale); p.setView(view); } catch (ViewFactoryException e) { logger.error("Failed to create view for presenter", e); } p.bind(); return p; } throw new IllegalArgumentException("No presenter is defined for name: " + name); } }
|
SpringPresenterFactory extends AbstractPresenterFactory implements ApplicationContextAware { @SuppressWarnings("unchecked") public IPresenter<?, ? extends EventBus> create(Object name,EventBus parentEventBus) { if (!(name instanceof String)) { throw new IllegalArgumentException("Argument is expected to be a bean name (string)"); } String beanName = (String) name; if (applicationContext.containsBean(beanName)) { IPresenter p = applicationContext.getBean(beanName, IPresenter.class); p.setApplication(application); p.setMessageSource(messageSource); Presenter def = p.getClass().getAnnotation(Presenter.class); if (def == null) { throw new IllegalArgumentException("Missing @Presenter annotation on bean '" + beanName + "'"); } EventBus eventBus = createEventBus((Class<IPresenter>) p.getClass(), p,parentEventBus); p.setEventBus(eventBus); try { Object view = viewFactory.createView(eventBusManager, p, def.view(), locale); p.setView(view); } catch (ViewFactoryException e) { logger.error("Failed to create view for presenter", e); } p.bind(); return p; } throw new IllegalArgumentException("No presenter is defined for name: " + name); } }
|
SpringPresenterFactory extends AbstractPresenterFactory implements ApplicationContextAware { @SuppressWarnings("unchecked") public IPresenter<?, ? extends EventBus> create(Object name,EventBus parentEventBus) { if (!(name instanceof String)) { throw new IllegalArgumentException("Argument is expected to be a bean name (string)"); } String beanName = (String) name; if (applicationContext.containsBean(beanName)) { IPresenter p = applicationContext.getBean(beanName, IPresenter.class); p.setApplication(application); p.setMessageSource(messageSource); Presenter def = p.getClass().getAnnotation(Presenter.class); if (def == null) { throw new IllegalArgumentException("Missing @Presenter annotation on bean '" + beanName + "'"); } EventBus eventBus = createEventBus((Class<IPresenter>) p.getClass(), p,parentEventBus); p.setEventBus(eventBus); try { Object view = viewFactory.createView(eventBusManager, p, def.view(), locale); p.setView(view); } catch (ViewFactoryException e) { logger.error("Failed to create view for presenter", e); } p.bind(); return p; } throw new IllegalArgumentException("No presenter is defined for name: " + name); } @Override void setApplicationContext(ApplicationContext applicationContext); @SuppressWarnings("unchecked") IPresenter<?, ? extends EventBus> create(Object name,EventBus parentEventBus); @Override IViewFactory getViewFactory(); }
|
SpringPresenterFactory extends AbstractPresenterFactory implements ApplicationContextAware { @SuppressWarnings("unchecked") public IPresenter<?, ? extends EventBus> create(Object name,EventBus parentEventBus) { if (!(name instanceof String)) { throw new IllegalArgumentException("Argument is expected to be a bean name (string)"); } String beanName = (String) name; if (applicationContext.containsBean(beanName)) { IPresenter p = applicationContext.getBean(beanName, IPresenter.class); p.setApplication(application); p.setMessageSource(messageSource); Presenter def = p.getClass().getAnnotation(Presenter.class); if (def == null) { throw new IllegalArgumentException("Missing @Presenter annotation on bean '" + beanName + "'"); } EventBus eventBus = createEventBus((Class<IPresenter>) p.getClass(), p,parentEventBus); p.setEventBus(eventBus); try { Object view = viewFactory.createView(eventBusManager, p, def.view(), locale); p.setView(view); } catch (ViewFactoryException e) { logger.error("Failed to create view for presenter", e); } p.bind(); return p; } throw new IllegalArgumentException("No presenter is defined for name: " + name); } @Override void setApplicationContext(ApplicationContext applicationContext); @SuppressWarnings("unchecked") IPresenter<?, ? extends EventBus> create(Object name,EventBus parentEventBus); @Override IViewFactory getViewFactory(); }
|
@Test(expected = Exception.class) public void testDispatch_witArgument_exceptionOccurred_willBeRaised() { testEventBus.testEventWithArgument(THE_ARG); expectLastCall().andThrow(new RuntimeException("Faking an exception")); replay(testEventBus); eventBusDispatcher.dispatch("testEventWithArgument",THE_ARG); verify(testEventBus); }
|
@Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); }
|
EventBusDispatcher implements IEventDispatcher { @Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); } }
|
EventBusDispatcher implements IEventDispatcher { @Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); } EventBusDispatcher(EventBusManager ebManager, EventBus eb); }
|
EventBusDispatcher implements IEventDispatcher { @Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); } EventBusDispatcher(EventBusManager ebManager, EventBus eb); @Override void dispatch(String name, Object event); @Override void dispatch(String name, Object... args); }
|
EventBusDispatcher implements IEventDispatcher { @Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); } EventBusDispatcher(EventBusManager ebManager, EventBus eb); @Override void dispatch(String name, Object event); @Override void dispatch(String name, Object... args); }
|
@Test public void testDispatch_notExistingMethod() { replay(testEventBus); eventBusDispatcher.dispatch("notExistingMethod",THE_ARG); verify(testEventBus); }
|
@Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); }
|
EventBusDispatcher implements IEventDispatcher { @Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); } }
|
EventBusDispatcher implements IEventDispatcher { @Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); } EventBusDispatcher(EventBusManager ebManager, EventBus eb); }
|
EventBusDispatcher implements IEventDispatcher { @Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); } EventBusDispatcher(EventBusManager ebManager, EventBus eb); @Override void dispatch(String name, Object event); @Override void dispatch(String name, Object... args); }
|
EventBusDispatcher implements IEventDispatcher { @Override public void dispatch(String name, Object event) { logger.debug("DispatchEvent: {} ({})", name, event); final Object[] args = event!=null?new Object[]{event}:new Object[]{}; dispatch(name, args); } EventBusDispatcher(EventBusManager ebManager, EventBus eb); @Override void dispatch(String name, Object event); @Override void dispatch(String name, Object... args); }
|
@Test public void testBindSimpleComponents() throws UiBinderException { UiBinderView root = instance.bind(UiBinderView.class, new Locale("en"), null); assertNotNull("component is null", root); boolean isPanel = root instanceof Panel; assertTrue("not a panel", isPanel); Panel panel = (Panel) root; Component layout = panel.getContent(); assertTrue("first nested component should be a vertical layout", (layout instanceof VerticalLayout)); VerticalLayout verticalLayout = (VerticalLayout) layout; Component label = verticalLayout.getComponent(0); assertNotNull("label is null", label); assertTrue("not a label: " + label.getClass(), (label instanceof Label)); }
|
public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); void setUiMessageSource(IUiMessageSource messageSource); boolean isBindable(Class<?> viewClass); boolean isBindable(String viewName); T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder); Component bind(String viewName, Locale locale, IEventBinder eventBinder); }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); void setUiMessageSource(IUiMessageSource messageSource); boolean isBindable(Class<?> viewClass); boolean isBindable(String viewName); T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder); Component bind(String viewName, Locale locale, IEventBinder eventBinder); }
|
@Test public void testBindAttributes() throws Exception { UiBinderView root = instance.bind(UiBinderView.class, new Locale("en"), null); ComponentContainer content = root.getContent(); assertNotNull("content should be a layout", content); VerticalLayout layout = (VerticalLayout) content; float height = layout.getHeight(); assertEquals("height not set correctly", 67.0f, height, 0.0d); assertTrue("setSizeFull() has not been called", root.sizeFull); }
|
public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); void setUiMessageSource(IUiMessageSource messageSource); boolean isBindable(Class<?> viewClass); boolean isBindable(String viewName); T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder); Component bind(String viewName, Locale locale, IEventBinder eventBinder); }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); void setUiMessageSource(IUiMessageSource messageSource); boolean isBindable(Class<?> viewClass); boolean isBindable(String viewName); T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder); Component bind(String viewName, Locale locale, IEventBinder eventBinder); }
|
@Test public void testBindEventListener() throws Exception { UiBinderView root = instance.bind(UiBinderView.class, new Locale("en"), null); assertNotNull("event button not bound", root.eventButton); assertTrue("click listener not set", root.eventButton.clickListenerSet); }
|
public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); void setUiMessageSource(IUiMessageSource messageSource); boolean isBindable(Class<?> viewClass); boolean isBindable(String viewName); T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder); Component bind(String viewName, Locale locale, IEventBinder eventBinder); }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); void setUiMessageSource(IUiMessageSource messageSource); boolean isBindable(Class<?> viewClass); boolean isBindable(String viewName); T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder); Component bind(String viewName, Locale locale, IEventBinder eventBinder); }
|
@Test public void testBindCustomComponents() throws Exception { UiBinderCustomCompView view = instance.bind(UiBinderCustomCompView.class, new Locale("en"), null); assertNotNull("custom comp has not been added to the view", view.customComp); assertNotNull("custom comp content not added", view.customComp.getContent()); assertEquals("custom comp content is not a VerticalLayout", VerticalLayout.class, view.customComp.getContent().getClass()); assertEquals("custom comp content is not a Label", Label.class, view.customComp.getContent().getComponentIterator().next().getClass()); assertNotNull("custom comp field 'label' not bound to UiField", view.customComp.label); assertEquals("custom comp field 'label' not translated", "This is the view title", view.customComp.label.getCaption()); }
|
public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); void setUiMessageSource(IUiMessageSource messageSource); boolean isBindable(Class<?> viewClass); boolean isBindable(String viewName); T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder); Component bind(String viewName, Locale locale, IEventBinder eventBinder); }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); void setUiMessageSource(IUiMessageSource messageSource); boolean isBindable(Class<?> viewClass); boolean isBindable(String viewName); T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder); Component bind(String viewName, Locale locale, IEventBinder eventBinder); }
|
@Test public void testBindNestedComponents() throws UiBinderException { UiBinderView root = instance.bind(UiBinderView.class, new Locale("en"), null); assertNotNull("component is null", root); boolean isPanel = root instanceof Panel; assertTrue("not a panel", isPanel); Panel panel = (Panel) root; Component layout = panel.getContent(); assertTrue("first nested component should be a vertical layout", (layout instanceof VerticalLayout)); Component label = ((VerticalLayout) layout).getComponent(0); assertNotNull("label is null", label); assertTrue("not a label: " + label.getClass(), (label instanceof Label)); }
|
public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); void setUiMessageSource(IUiMessageSource messageSource); boolean isBindable(Class<?> viewClass); boolean isBindable(String viewName); T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder); Component bind(String viewName, Locale locale, IEventBinder eventBinder); }
|
UiBinder { public <T extends Component> T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder) throws UiBinderException { try { T view = (T) viewClass.newInstance(); view = bind(viewClass.getName(), view, locale, eventBinder); return (T) view; } catch (InstantiationException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } catch (IllegalAccessException e) { throw new UiConstraintException("Failed to instantiate component type: " + viewClass.getName()); } } UiBinder(); void setUiMessageSource(IUiMessageSource messageSource); boolean isBindable(Class<?> viewClass); boolean isBindable(String viewName); T bind(Class<T> viewClass, Locale locale, IEventBinder eventBinder); Component bind(String viewName, Locale locale, IEventBinder eventBinder); }
|
@Test public void testBasicDeserialization() throws Exception { Event event = create("type", "id", 0) .attr("key", "value") .attr("key1", "valu1") .build(); String json = objectMapper.writeValueAsString(event); Event actualEntity = objectMapper.readValue(json, Event.class); assertEquals(actualEntity.getId(), event.getId()); assertEquals(actualEntity.getTimestamp(), event.getTimestamp()); assertEquals(new HashSet<>(actualEntity.getAttributes()), new HashSet<>(event.getAttributes())); }
|
@Override public BaseEvent build(EventBuilder entityBuilder) { return (BaseEvent) entityBuilder.build(); }
|
EventDeserializer extends AbstractAttributeStoreDeserializer<BaseEvent, EventBuilder> { @Override public BaseEvent build(EventBuilder entityBuilder) { return (BaseEvent) entityBuilder.build(); } }
|
EventDeserializer extends AbstractAttributeStoreDeserializer<BaseEvent, EventBuilder> { @Override public BaseEvent build(EventBuilder entityBuilder) { return (BaseEvent) entityBuilder.build(); } }
|
EventDeserializer extends AbstractAttributeStoreDeserializer<BaseEvent, EventBuilder> { @Override public BaseEvent build(EventBuilder entityBuilder) { return (BaseEvent) entityBuilder.build(); } @Override EventBuilder deserialize(JsonNode root); @Override BaseEvent build(EventBuilder entityBuilder); }
|
EventDeserializer extends AbstractAttributeStoreDeserializer<BaseEvent, EventBuilder> { @Override public BaseEvent build(EventBuilder entityBuilder) { return (BaseEvent) entityBuilder.build(); } @Override EventBuilder deserialize(JsonNode root); @Override BaseEvent build(EventBuilder entityBuilder); }
|
@Test public void testLimit() { CloseableIterator<Integer> firstThree = limit(testIterator(), 3); assertTrue(elementsEqual(asList(1, 2, 3).iterator(), firstThree)); assertFalse(firstThree.hasNext()); firstThree.close(); }
|
public static <T> CloseableIterator<T> limit(final CloseableIterator<T> iterator, final int limitSize) { return wrap(Iterators.limit(iterator, limitSize), iterator); }
|
CloseableIterators { public static <T> CloseableIterator<T> limit(final CloseableIterator<T> iterator, final int limitSize) { return wrap(Iterators.limit(iterator, limitSize), iterator); } }
|
CloseableIterators { public static <T> CloseableIterator<T> limit(final CloseableIterator<T> iterator, final int limitSize) { return wrap(Iterators.limit(iterator, limitSize), iterator); } private CloseableIterators(); }
|
CloseableIterators { public static <T> CloseableIterator<T> limit(final CloseableIterator<T> iterator, final int limitSize) { return wrap(Iterators.limit(iterator, limitSize), iterator); } private CloseableIterators(); static CloseableIterator<T> fromStream(Stream<T> stream); static CloseableIterator<T> fromIterator(Iterator<T> iterator); static CloseableIterator<T> distinct(final CloseableIterator<T> iterator); static CloseableIterator<List<T>> groupBy(final CloseableIterator<? extends T> iterator, final Function<? super T, ?> groupingFunction); static CloseableIterator<T> concat(final CloseableIterator<? extends Iterator<? extends T>> iterators); @SuppressWarnings("unchecked") static CloseableIterator<T> emptyIterator(); static CloseableIterator<T> filter(final CloseableIterator<T> iterator, final Predicate<T> filter); static CloseableIterator<T> filter(final CloseableIterator<?> iterator, final Class<T> type); static CloseableIterator<T> limit(final CloseableIterator<T> iterator, final int limitSize); static CloseableIterator<List<T>> paddedParition(final CloseableIterator<T> iterator, final int size); static CloseableIterator<List<T>> partition(final CloseableIterator<T> iterator, final int size); static PeekingCloseableIterator<T> peekingIterator(final CloseableIterator<T> iterator); static CloseableIterator<T> singletonIterator(T value); static CloseableIterator<T> transform(CloseableIterator<F> iterator, Function<F, T> function); @SafeVarargs static CloseableIterator<T> chain(CloseableIterator<? extends T>... iterators); static CloseableIterator<T> chain(final Iterator<? extends CloseableIterator<? extends T>> iterator); static CloseableIterator<T> autoClose(final CloseableIterator<? extends T> iterator); @Deprecated static CloseableIterator<T> wrap(final Iterator<T> iterator); }
|
CloseableIterators { public static <T> CloseableIterator<T> limit(final CloseableIterator<T> iterator, final int limitSize) { return wrap(Iterators.limit(iterator, limitSize), iterator); } private CloseableIterators(); static CloseableIterator<T> fromStream(Stream<T> stream); static CloseableIterator<T> fromIterator(Iterator<T> iterator); static CloseableIterator<T> distinct(final CloseableIterator<T> iterator); static CloseableIterator<List<T>> groupBy(final CloseableIterator<? extends T> iterator, final Function<? super T, ?> groupingFunction); static CloseableIterator<T> concat(final CloseableIterator<? extends Iterator<? extends T>> iterators); @SuppressWarnings("unchecked") static CloseableIterator<T> emptyIterator(); static CloseableIterator<T> filter(final CloseableIterator<T> iterator, final Predicate<T> filter); static CloseableIterator<T> filter(final CloseableIterator<?> iterator, final Class<T> type); static CloseableIterator<T> limit(final CloseableIterator<T> iterator, final int limitSize); static CloseableIterator<List<T>> paddedParition(final CloseableIterator<T> iterator, final int size); static CloseableIterator<List<T>> partition(final CloseableIterator<T> iterator, final int size); static PeekingCloseableIterator<T> peekingIterator(final CloseableIterator<T> iterator); static CloseableIterator<T> singletonIterator(T value); static CloseableIterator<T> transform(CloseableIterator<F> iterator, Function<F, T> function); @SafeVarargs static CloseableIterator<T> chain(CloseableIterator<? extends T>... iterators); static CloseableIterator<T> chain(final Iterator<? extends CloseableIterator<? extends T>> iterator); static CloseableIterator<T> autoClose(final CloseableIterator<? extends T> iterator); @Deprecated static CloseableIterator<T> wrap(final Iterator<T> iterator); }
|
@Test public void testFilter() { CloseableIterator<Integer> odd = filter(testIterator(), input -> input % 2 == 0); assertTrue(elementsEqual(asList(2, 4).iterator(), odd)); assertFalse(odd.hasNext()); odd.close(); }
|
public static <T> CloseableIterator<T> filter(final CloseableIterator<T> iterator, final Predicate<T> filter) { return wrap(Iterators.filter(iterator, filter::test), iterator); }
|
CloseableIterators { public static <T> CloseableIterator<T> filter(final CloseableIterator<T> iterator, final Predicate<T> filter) { return wrap(Iterators.filter(iterator, filter::test), iterator); } }
|
CloseableIterators { public static <T> CloseableIterator<T> filter(final CloseableIterator<T> iterator, final Predicate<T> filter) { return wrap(Iterators.filter(iterator, filter::test), iterator); } private CloseableIterators(); }
|
CloseableIterators { public static <T> CloseableIterator<T> filter(final CloseableIterator<T> iterator, final Predicate<T> filter) { return wrap(Iterators.filter(iterator, filter::test), iterator); } private CloseableIterators(); static CloseableIterator<T> fromStream(Stream<T> stream); static CloseableIterator<T> fromIterator(Iterator<T> iterator); static CloseableIterator<T> distinct(final CloseableIterator<T> iterator); static CloseableIterator<List<T>> groupBy(final CloseableIterator<? extends T> iterator, final Function<? super T, ?> groupingFunction); static CloseableIterator<T> concat(final CloseableIterator<? extends Iterator<? extends T>> iterators); @SuppressWarnings("unchecked") static CloseableIterator<T> emptyIterator(); static CloseableIterator<T> filter(final CloseableIterator<T> iterator, final Predicate<T> filter); static CloseableIterator<T> filter(final CloseableIterator<?> iterator, final Class<T> type); static CloseableIterator<T> limit(final CloseableIterator<T> iterator, final int limitSize); static CloseableIterator<List<T>> paddedParition(final CloseableIterator<T> iterator, final int size); static CloseableIterator<List<T>> partition(final CloseableIterator<T> iterator, final int size); static PeekingCloseableIterator<T> peekingIterator(final CloseableIterator<T> iterator); static CloseableIterator<T> singletonIterator(T value); static CloseableIterator<T> transform(CloseableIterator<F> iterator, Function<F, T> function); @SafeVarargs static CloseableIterator<T> chain(CloseableIterator<? extends T>... iterators); static CloseableIterator<T> chain(final Iterator<? extends CloseableIterator<? extends T>> iterator); static CloseableIterator<T> autoClose(final CloseableIterator<? extends T> iterator); @Deprecated static CloseableIterator<T> wrap(final Iterator<T> iterator); }
|
CloseableIterators { public static <T> CloseableIterator<T> filter(final CloseableIterator<T> iterator, final Predicate<T> filter) { return wrap(Iterators.filter(iterator, filter::test), iterator); } private CloseableIterators(); static CloseableIterator<T> fromStream(Stream<T> stream); static CloseableIterator<T> fromIterator(Iterator<T> iterator); static CloseableIterator<T> distinct(final CloseableIterator<T> iterator); static CloseableIterator<List<T>> groupBy(final CloseableIterator<? extends T> iterator, final Function<? super T, ?> groupingFunction); static CloseableIterator<T> concat(final CloseableIterator<? extends Iterator<? extends T>> iterators); @SuppressWarnings("unchecked") static CloseableIterator<T> emptyIterator(); static CloseableIterator<T> filter(final CloseableIterator<T> iterator, final Predicate<T> filter); static CloseableIterator<T> filter(final CloseableIterator<?> iterator, final Class<T> type); static CloseableIterator<T> limit(final CloseableIterator<T> iterator, final int limitSize); static CloseableIterator<List<T>> paddedParition(final CloseableIterator<T> iterator, final int size); static CloseableIterator<List<T>> partition(final CloseableIterator<T> iterator, final int size); static PeekingCloseableIterator<T> peekingIterator(final CloseableIterator<T> iterator); static CloseableIterator<T> singletonIterator(T value); static CloseableIterator<T> transform(CloseableIterator<F> iterator, Function<F, T> function); @SafeVarargs static CloseableIterator<T> chain(CloseableIterator<? extends T>... iterators); static CloseableIterator<T> chain(final Iterator<? extends CloseableIterator<? extends T>> iterator); static CloseableIterator<T> autoClose(final CloseableIterator<? extends T> iterator); @Deprecated static CloseableIterator<T> wrap(final Iterator<T> iterator); }
|
@Test public void testDistinct() { CloseableIterator<Integer> distinct = distinct(fromIterator(asList(1, 1, 2, 2, 3, 3, 3, 4, 5, 6, 7, 7, 7).iterator())); assertTrue(elementsEqual(asList(1, 2, 3, 4, 5, 6, 7).iterator(), distinct)); assertFalse(distinct.hasNext()); distinct.close(); }
|
public static <T> CloseableIterator<T> distinct(final CloseableIterator<T> iterator) { return wrap(Iterators2.distinct(iterator), iterator); }
|
CloseableIterators { public static <T> CloseableIterator<T> distinct(final CloseableIterator<T> iterator) { return wrap(Iterators2.distinct(iterator), iterator); } }
|
CloseableIterators { public static <T> CloseableIterator<T> distinct(final CloseableIterator<T> iterator) { return wrap(Iterators2.distinct(iterator), iterator); } private CloseableIterators(); }
|
CloseableIterators { public static <T> CloseableIterator<T> distinct(final CloseableIterator<T> iterator) { return wrap(Iterators2.distinct(iterator), iterator); } private CloseableIterators(); static CloseableIterator<T> fromStream(Stream<T> stream); static CloseableIterator<T> fromIterator(Iterator<T> iterator); static CloseableIterator<T> distinct(final CloseableIterator<T> iterator); static CloseableIterator<List<T>> groupBy(final CloseableIterator<? extends T> iterator, final Function<? super T, ?> groupingFunction); static CloseableIterator<T> concat(final CloseableIterator<? extends Iterator<? extends T>> iterators); @SuppressWarnings("unchecked") static CloseableIterator<T> emptyIterator(); static CloseableIterator<T> filter(final CloseableIterator<T> iterator, final Predicate<T> filter); static CloseableIterator<T> filter(final CloseableIterator<?> iterator, final Class<T> type); static CloseableIterator<T> limit(final CloseableIterator<T> iterator, final int limitSize); static CloseableIterator<List<T>> paddedParition(final CloseableIterator<T> iterator, final int size); static CloseableIterator<List<T>> partition(final CloseableIterator<T> iterator, final int size); static PeekingCloseableIterator<T> peekingIterator(final CloseableIterator<T> iterator); static CloseableIterator<T> singletonIterator(T value); static CloseableIterator<T> transform(CloseableIterator<F> iterator, Function<F, T> function); @SafeVarargs static CloseableIterator<T> chain(CloseableIterator<? extends T>... iterators); static CloseableIterator<T> chain(final Iterator<? extends CloseableIterator<? extends T>> iterator); static CloseableIterator<T> autoClose(final CloseableIterator<? extends T> iterator); @Deprecated static CloseableIterator<T> wrap(final Iterator<T> iterator); }
|
CloseableIterators { public static <T> CloseableIterator<T> distinct(final CloseableIterator<T> iterator) { return wrap(Iterators2.distinct(iterator), iterator); } private CloseableIterators(); static CloseableIterator<T> fromStream(Stream<T> stream); static CloseableIterator<T> fromIterator(Iterator<T> iterator); static CloseableIterator<T> distinct(final CloseableIterator<T> iterator); static CloseableIterator<List<T>> groupBy(final CloseableIterator<? extends T> iterator, final Function<? super T, ?> groupingFunction); static CloseableIterator<T> concat(final CloseableIterator<? extends Iterator<? extends T>> iterators); @SuppressWarnings("unchecked") static CloseableIterator<T> emptyIterator(); static CloseableIterator<T> filter(final CloseableIterator<T> iterator, final Predicate<T> filter); static CloseableIterator<T> filter(final CloseableIterator<?> iterator, final Class<T> type); static CloseableIterator<T> limit(final CloseableIterator<T> iterator, final int limitSize); static CloseableIterator<List<T>> paddedParition(final CloseableIterator<T> iterator, final int size); static CloseableIterator<List<T>> partition(final CloseableIterator<T> iterator, final int size); static PeekingCloseableIterator<T> peekingIterator(final CloseableIterator<T> iterator); static CloseableIterator<T> singletonIterator(T value); static CloseableIterator<T> transform(CloseableIterator<F> iterator, Function<F, T> function); @SafeVarargs static CloseableIterator<T> chain(CloseableIterator<? extends T>... iterators); static CloseableIterator<T> chain(final Iterator<? extends CloseableIterator<? extends T>> iterator); static CloseableIterator<T> autoClose(final CloseableIterator<? extends T> iterator); @Deprecated static CloseableIterator<T> wrap(final Iterator<T> iterator); }
|
@SuppressWarnings({"unchecked", "rawtypes"}) @Test public void testChain() { CloseableIterator iterator = chain(emptyIterator(), emptyIterator(), emptyIterator()); assertFalse(iterator.hasNext()); try { iterator.next(); fail(); } catch (NoSuchElementException ignored) { } iterator.close(); iterator = chain(fromIterator(asList(1).iterator())); try { assertTrue(iterator.hasNext()); iterator.next(); } catch (NoSuchElementException ex) { fail("should not throw NoSuchElementException here"); } finally { iterator.closeQuietly(); } iterator.close(); iterator = chain( fromIterator(asList(1, 2).iterator()), fromIterator(asList(3, 4).iterator()), fromIterator(asList(5, 6).iterator())); assertTrue(iterator.hasNext()); assertTrue(Iterators.elementsEqual(asList(1, 2, 3, 4, 5, 6).iterator(), iterator)); assertFalse(iterator.hasNext()); iterator.close(); }
|
@SafeVarargs public static <T> CloseableIterator<T> chain(CloseableIterator<? extends T>... iterators) { return chain(Iterators.forArray(iterators)); }
|
CloseableIterators { @SafeVarargs public static <T> CloseableIterator<T> chain(CloseableIterator<? extends T>... iterators) { return chain(Iterators.forArray(iterators)); } }
|
CloseableIterators { @SafeVarargs public static <T> CloseableIterator<T> chain(CloseableIterator<? extends T>... iterators) { return chain(Iterators.forArray(iterators)); } private CloseableIterators(); }
|
CloseableIterators { @SafeVarargs public static <T> CloseableIterator<T> chain(CloseableIterator<? extends T>... iterators) { return chain(Iterators.forArray(iterators)); } private CloseableIterators(); static CloseableIterator<T> fromStream(Stream<T> stream); static CloseableIterator<T> fromIterator(Iterator<T> iterator); static CloseableIterator<T> distinct(final CloseableIterator<T> iterator); static CloseableIterator<List<T>> groupBy(final CloseableIterator<? extends T> iterator, final Function<? super T, ?> groupingFunction); static CloseableIterator<T> concat(final CloseableIterator<? extends Iterator<? extends T>> iterators); @SuppressWarnings("unchecked") static CloseableIterator<T> emptyIterator(); static CloseableIterator<T> filter(final CloseableIterator<T> iterator, final Predicate<T> filter); static CloseableIterator<T> filter(final CloseableIterator<?> iterator, final Class<T> type); static CloseableIterator<T> limit(final CloseableIterator<T> iterator, final int limitSize); static CloseableIterator<List<T>> paddedParition(final CloseableIterator<T> iterator, final int size); static CloseableIterator<List<T>> partition(final CloseableIterator<T> iterator, final int size); static PeekingCloseableIterator<T> peekingIterator(final CloseableIterator<T> iterator); static CloseableIterator<T> singletonIterator(T value); static CloseableIterator<T> transform(CloseableIterator<F> iterator, Function<F, T> function); @SafeVarargs static CloseableIterator<T> chain(CloseableIterator<? extends T>... iterators); static CloseableIterator<T> chain(final Iterator<? extends CloseableIterator<? extends T>> iterator); static CloseableIterator<T> autoClose(final CloseableIterator<? extends T> iterator); @Deprecated static CloseableIterator<T> wrap(final Iterator<T> iterator); }
|
CloseableIterators { @SafeVarargs public static <T> CloseableIterator<T> chain(CloseableIterator<? extends T>... iterators) { return chain(Iterators.forArray(iterators)); } private CloseableIterators(); static CloseableIterator<T> fromStream(Stream<T> stream); static CloseableIterator<T> fromIterator(Iterator<T> iterator); static CloseableIterator<T> distinct(final CloseableIterator<T> iterator); static CloseableIterator<List<T>> groupBy(final CloseableIterator<? extends T> iterator, final Function<? super T, ?> groupingFunction); static CloseableIterator<T> concat(final CloseableIterator<? extends Iterator<? extends T>> iterators); @SuppressWarnings("unchecked") static CloseableIterator<T> emptyIterator(); static CloseableIterator<T> filter(final CloseableIterator<T> iterator, final Predicate<T> filter); static CloseableIterator<T> filter(final CloseableIterator<?> iterator, final Class<T> type); static CloseableIterator<T> limit(final CloseableIterator<T> iterator, final int limitSize); static CloseableIterator<List<T>> paddedParition(final CloseableIterator<T> iterator, final int size); static CloseableIterator<List<T>> partition(final CloseableIterator<T> iterator, final int size); static PeekingCloseableIterator<T> peekingIterator(final CloseableIterator<T> iterator); static CloseableIterator<T> singletonIterator(T value); static CloseableIterator<T> transform(CloseableIterator<F> iterator, Function<F, T> function); @SafeVarargs static CloseableIterator<T> chain(CloseableIterator<? extends T>... iterators); static CloseableIterator<T> chain(final Iterator<? extends CloseableIterator<? extends T>> iterator); static CloseableIterator<T> autoClose(final CloseableIterator<? extends T> iterator); @Deprecated static CloseableIterator<T> wrap(final Iterator<T> iterator); }
|
@Test public void testAutoClose() { MockIterator<Integer> iterator = testIterator(); CloseableIterator<Integer> closeableIterator = autoClose(iterator); closeableIterator.close(); assertTrue(iterator.isClosed()); iterator = testIterator(); closeableIterator = autoClose(iterator); Iterators.size(closeableIterator); assertTrue(iterator.isClosed()); iterator = testExceptionThrowingIterator(); closeableIterator = autoClose(iterator); try { closeableIterator.next(); fail(); } catch (RuntimeException ignored) { } assertTrue(iterator.isClosed()); iterator = testIterator(); closeableIterator = autoClose(iterator); closeableIterator.close(); try { closeableIterator.next(); } catch (NoSuchElementException ignored) { } assertTrue(iterator.isClosed()); iterator = testExceptionThrowingIterator(); closeableIterator = autoClose(iterator); try { closeableIterator.remove(); fail(); } catch (RuntimeException ignored) { } assertTrue(iterator.isClosed()); iterator = testIterator(); closeableIterator = autoClose(iterator); closeableIterator.close(); try { closeableIterator.remove(); } catch (IllegalStateException ignored) { } assertTrue(iterator.isClosed()); }
|
public static <T> CloseableIterator<T> autoClose(final CloseableIterator<? extends T> iterator) { requireNonNull(iterator); return new CloseableIterator<T>() { private boolean closed = false; @Override public void close() { if (closed) return; closed = true; iterator.close(); } @Override public boolean hasNext() { try { if (closed) return false; if (!iterator.hasNext()) { closeQuietly(); return false; } return true; } catch (RuntimeException re) { closeQuietly(); throw re; } } @Override public T next() { if (!closed) { try { return iterator.next(); } catch (RuntimeException re) { closeQuietly(); throw re; } } throw new NoSuchElementException(); } @Override public void remove() { if (!closed) { try { iterator.remove(); } catch (RuntimeException re) { closeQuietly(); throw re; } } throw new IllegalStateException(); } }; }
|
CloseableIterators { public static <T> CloseableIterator<T> autoClose(final CloseableIterator<? extends T> iterator) { requireNonNull(iterator); return new CloseableIterator<T>() { private boolean closed = false; @Override public void close() { if (closed) return; closed = true; iterator.close(); } @Override public boolean hasNext() { try { if (closed) return false; if (!iterator.hasNext()) { closeQuietly(); return false; } return true; } catch (RuntimeException re) { closeQuietly(); throw re; } } @Override public T next() { if (!closed) { try { return iterator.next(); } catch (RuntimeException re) { closeQuietly(); throw re; } } throw new NoSuchElementException(); } @Override public void remove() { if (!closed) { try { iterator.remove(); } catch (RuntimeException re) { closeQuietly(); throw re; } } throw new IllegalStateException(); } }; } }
|
CloseableIterators { public static <T> CloseableIterator<T> autoClose(final CloseableIterator<? extends T> iterator) { requireNonNull(iterator); return new CloseableIterator<T>() { private boolean closed = false; @Override public void close() { if (closed) return; closed = true; iterator.close(); } @Override public boolean hasNext() { try { if (closed) return false; if (!iterator.hasNext()) { closeQuietly(); return false; } return true; } catch (RuntimeException re) { closeQuietly(); throw re; } } @Override public T next() { if (!closed) { try { return iterator.next(); } catch (RuntimeException re) { closeQuietly(); throw re; } } throw new NoSuchElementException(); } @Override public void remove() { if (!closed) { try { iterator.remove(); } catch (RuntimeException re) { closeQuietly(); throw re; } } throw new IllegalStateException(); } }; } private CloseableIterators(); }
|
CloseableIterators { public static <T> CloseableIterator<T> autoClose(final CloseableIterator<? extends T> iterator) { requireNonNull(iterator); return new CloseableIterator<T>() { private boolean closed = false; @Override public void close() { if (closed) return; closed = true; iterator.close(); } @Override public boolean hasNext() { try { if (closed) return false; if (!iterator.hasNext()) { closeQuietly(); return false; } return true; } catch (RuntimeException re) { closeQuietly(); throw re; } } @Override public T next() { if (!closed) { try { return iterator.next(); } catch (RuntimeException re) { closeQuietly(); throw re; } } throw new NoSuchElementException(); } @Override public void remove() { if (!closed) { try { iterator.remove(); } catch (RuntimeException re) { closeQuietly(); throw re; } } throw new IllegalStateException(); } }; } private CloseableIterators(); static CloseableIterator<T> fromStream(Stream<T> stream); static CloseableIterator<T> fromIterator(Iterator<T> iterator); static CloseableIterator<T> distinct(final CloseableIterator<T> iterator); static CloseableIterator<List<T>> groupBy(final CloseableIterator<? extends T> iterator, final Function<? super T, ?> groupingFunction); static CloseableIterator<T> concat(final CloseableIterator<? extends Iterator<? extends T>> iterators); @SuppressWarnings("unchecked") static CloseableIterator<T> emptyIterator(); static CloseableIterator<T> filter(final CloseableIterator<T> iterator, final Predicate<T> filter); static CloseableIterator<T> filter(final CloseableIterator<?> iterator, final Class<T> type); static CloseableIterator<T> limit(final CloseableIterator<T> iterator, final int limitSize); static CloseableIterator<List<T>> paddedParition(final CloseableIterator<T> iterator, final int size); static CloseableIterator<List<T>> partition(final CloseableIterator<T> iterator, final int size); static PeekingCloseableIterator<T> peekingIterator(final CloseableIterator<T> iterator); static CloseableIterator<T> singletonIterator(T value); static CloseableIterator<T> transform(CloseableIterator<F> iterator, Function<F, T> function); @SafeVarargs static CloseableIterator<T> chain(CloseableIterator<? extends T>... iterators); static CloseableIterator<T> chain(final Iterator<? extends CloseableIterator<? extends T>> iterator); static CloseableIterator<T> autoClose(final CloseableIterator<? extends T> iterator); @Deprecated static CloseableIterator<T> wrap(final Iterator<T> iterator); }
|
CloseableIterators { public static <T> CloseableIterator<T> autoClose(final CloseableIterator<? extends T> iterator) { requireNonNull(iterator); return new CloseableIterator<T>() { private boolean closed = false; @Override public void close() { if (closed) return; closed = true; iterator.close(); } @Override public boolean hasNext() { try { if (closed) return false; if (!iterator.hasNext()) { closeQuietly(); return false; } return true; } catch (RuntimeException re) { closeQuietly(); throw re; } } @Override public T next() { if (!closed) { try { return iterator.next(); } catch (RuntimeException re) { closeQuietly(); throw re; } } throw new NoSuchElementException(); } @Override public void remove() { if (!closed) { try { iterator.remove(); } catch (RuntimeException re) { closeQuietly(); throw re; } } throw new IllegalStateException(); } }; } private CloseableIterators(); static CloseableIterator<T> fromStream(Stream<T> stream); static CloseableIterator<T> fromIterator(Iterator<T> iterator); static CloseableIterator<T> distinct(final CloseableIterator<T> iterator); static CloseableIterator<List<T>> groupBy(final CloseableIterator<? extends T> iterator, final Function<? super T, ?> groupingFunction); static CloseableIterator<T> concat(final CloseableIterator<? extends Iterator<? extends T>> iterators); @SuppressWarnings("unchecked") static CloseableIterator<T> emptyIterator(); static CloseableIterator<T> filter(final CloseableIterator<T> iterator, final Predicate<T> filter); static CloseableIterator<T> filter(final CloseableIterator<?> iterator, final Class<T> type); static CloseableIterator<T> limit(final CloseableIterator<T> iterator, final int limitSize); static CloseableIterator<List<T>> paddedParition(final CloseableIterator<T> iterator, final int size); static CloseableIterator<List<T>> partition(final CloseableIterator<T> iterator, final int size); static PeekingCloseableIterator<T> peekingIterator(final CloseableIterator<T> iterator); static CloseableIterator<T> singletonIterator(T value); static CloseableIterator<T> transform(CloseableIterator<F> iterator, Function<F, T> function); @SafeVarargs static CloseableIterator<T> chain(CloseableIterator<? extends T>... iterators); static CloseableIterator<T> chain(final Iterator<? extends CloseableIterator<? extends T>> iterator); static CloseableIterator<T> autoClose(final CloseableIterator<? extends T> iterator); @Deprecated static CloseableIterator<T> wrap(final Iterator<T> iterator); }
|
@Test public void testCloseEmptyMultipleTimes() { CloseableIterable<Integer> iterable = CloseableIterables.emptyIterable(); iterable.iterator(); iterable.closeQuietly(); iterable = CloseableIterables.emptyIterable(); iterable.iterator(); iterable.closeQuietly(); }
|
@SuppressWarnings("unchecked") public static <T> CloseableIterable<T> emptyIterable() { return EMPTY_ITERABLE; }
|
CloseableIterables { @SuppressWarnings("unchecked") public static <T> CloseableIterable<T> emptyIterable() { return EMPTY_ITERABLE; } }
|
CloseableIterables { @SuppressWarnings("unchecked") public static <T> CloseableIterable<T> emptyIterable() { return EMPTY_ITERABLE; } private CloseableIterables(); }
|
CloseableIterables { @SuppressWarnings("unchecked") public static <T> CloseableIterable<T> emptyIterable() { return EMPTY_ITERABLE; } private CloseableIterables(); static CloseableIterable<T> fromStream(Stream<T> stream); static CloseableIterable<T> fromIterable(Iterable<T> iterable); static CloseableIterable<T> distinct(final CloseableIterable<T> iterable); static CloseableIterable<List<T>> groupBy(final CloseableIterable<? extends T> iterable, final Function<? super T, ?> groupingFunction); static CloseableIterable<T> concat(final CloseableIterable<? extends Iterable<? extends T>> inputs); static CloseableIterable<T> cycle(final CloseableIterable<T> iterable); static CloseableIterable<T> filter(final CloseableIterable<?> iterable, final Class<T> type); static CloseableIterable<T> filter(final CloseableIterable<T> iterable, final Predicate<? super T> filter); static CloseableIterable<T> limit(final CloseableIterable<T> iterable, final int limitSize); static CloseableIterable<List<T>> paddedParition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<List<T>> partition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<T> skip(final CloseableIterable<T> iterable, final int numberToSkip); static CloseableIterable<T> transform(final CloseableIterable<F> iterable, final Function<? super F, ? extends T> function); @SafeVarargs static CloseableIterable<T> chain(CloseableIterable<? extends T>... iterables); static CloseableIterable<T> chain(final Iterable<? extends CloseableIterable<? extends T>> iterables); static CloseableIterable<T> autoClose(final CloseableIterable<? extends T> iterable); @SuppressWarnings("unchecked") static CloseableIterable<T> emptyIterable(); static CloseableIterable<T> singleton(T value); @Deprecated static CloseableIterable<T> wrap(final Iterable<T> iterable); }
|
CloseableIterables { @SuppressWarnings("unchecked") public static <T> CloseableIterable<T> emptyIterable() { return EMPTY_ITERABLE; } private CloseableIterables(); static CloseableIterable<T> fromStream(Stream<T> stream); static CloseableIterable<T> fromIterable(Iterable<T> iterable); static CloseableIterable<T> distinct(final CloseableIterable<T> iterable); static CloseableIterable<List<T>> groupBy(final CloseableIterable<? extends T> iterable, final Function<? super T, ?> groupingFunction); static CloseableIterable<T> concat(final CloseableIterable<? extends Iterable<? extends T>> inputs); static CloseableIterable<T> cycle(final CloseableIterable<T> iterable); static CloseableIterable<T> filter(final CloseableIterable<?> iterable, final Class<T> type); static CloseableIterable<T> filter(final CloseableIterable<T> iterable, final Predicate<? super T> filter); static CloseableIterable<T> limit(final CloseableIterable<T> iterable, final int limitSize); static CloseableIterable<List<T>> paddedParition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<List<T>> partition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<T> skip(final CloseableIterable<T> iterable, final int numberToSkip); static CloseableIterable<T> transform(final CloseableIterable<F> iterable, final Function<? super F, ? extends T> function); @SafeVarargs static CloseableIterable<T> chain(CloseableIterable<? extends T>... iterables); static CloseableIterable<T> chain(final Iterable<? extends CloseableIterable<? extends T>> iterables); static CloseableIterable<T> autoClose(final CloseableIterable<? extends T> iterable); @SuppressWarnings("unchecked") static CloseableIterable<T> emptyIterable(); static CloseableIterable<T> singleton(T value); @Deprecated static CloseableIterable<T> wrap(final Iterable<T> iterable); }
|
@Test public void testWrap() { CloseableIterable<Integer> wrapped = CloseableIterables.fromIterable(asList(1, 2, 3, 4, 5)); assertTrue(elementsEqual(asList(1, 2, 3, 4, 5), wrapped)); wrapped.close(); try { wrapped.iterator(); fail(); } catch (IllegalStateException ignored) { } }
|
@Deprecated public static <T> CloseableIterable<T> wrap(final Iterable<T> iterable) { return fromIterable(iterable); }
|
CloseableIterables { @Deprecated public static <T> CloseableIterable<T> wrap(final Iterable<T> iterable) { return fromIterable(iterable); } }
|
CloseableIterables { @Deprecated public static <T> CloseableIterable<T> wrap(final Iterable<T> iterable) { return fromIterable(iterable); } private CloseableIterables(); }
|
CloseableIterables { @Deprecated public static <T> CloseableIterable<T> wrap(final Iterable<T> iterable) { return fromIterable(iterable); } private CloseableIterables(); static CloseableIterable<T> fromStream(Stream<T> stream); static CloseableIterable<T> fromIterable(Iterable<T> iterable); static CloseableIterable<T> distinct(final CloseableIterable<T> iterable); static CloseableIterable<List<T>> groupBy(final CloseableIterable<? extends T> iterable, final Function<? super T, ?> groupingFunction); static CloseableIterable<T> concat(final CloseableIterable<? extends Iterable<? extends T>> inputs); static CloseableIterable<T> cycle(final CloseableIterable<T> iterable); static CloseableIterable<T> filter(final CloseableIterable<?> iterable, final Class<T> type); static CloseableIterable<T> filter(final CloseableIterable<T> iterable, final Predicate<? super T> filter); static CloseableIterable<T> limit(final CloseableIterable<T> iterable, final int limitSize); static CloseableIterable<List<T>> paddedParition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<List<T>> partition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<T> skip(final CloseableIterable<T> iterable, final int numberToSkip); static CloseableIterable<T> transform(final CloseableIterable<F> iterable, final Function<? super F, ? extends T> function); @SafeVarargs static CloseableIterable<T> chain(CloseableIterable<? extends T>... iterables); static CloseableIterable<T> chain(final Iterable<? extends CloseableIterable<? extends T>> iterables); static CloseableIterable<T> autoClose(final CloseableIterable<? extends T> iterable); @SuppressWarnings("unchecked") static CloseableIterable<T> emptyIterable(); static CloseableIterable<T> singleton(T value); @Deprecated static CloseableIterable<T> wrap(final Iterable<T> iterable); }
|
CloseableIterables { @Deprecated public static <T> CloseableIterable<T> wrap(final Iterable<T> iterable) { return fromIterable(iterable); } private CloseableIterables(); static CloseableIterable<T> fromStream(Stream<T> stream); static CloseableIterable<T> fromIterable(Iterable<T> iterable); static CloseableIterable<T> distinct(final CloseableIterable<T> iterable); static CloseableIterable<List<T>> groupBy(final CloseableIterable<? extends T> iterable, final Function<? super T, ?> groupingFunction); static CloseableIterable<T> concat(final CloseableIterable<? extends Iterable<? extends T>> inputs); static CloseableIterable<T> cycle(final CloseableIterable<T> iterable); static CloseableIterable<T> filter(final CloseableIterable<?> iterable, final Class<T> type); static CloseableIterable<T> filter(final CloseableIterable<T> iterable, final Predicate<? super T> filter); static CloseableIterable<T> limit(final CloseableIterable<T> iterable, final int limitSize); static CloseableIterable<List<T>> paddedParition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<List<T>> partition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<T> skip(final CloseableIterable<T> iterable, final int numberToSkip); static CloseableIterable<T> transform(final CloseableIterable<F> iterable, final Function<? super F, ? extends T> function); @SafeVarargs static CloseableIterable<T> chain(CloseableIterable<? extends T>... iterables); static CloseableIterable<T> chain(final Iterable<? extends CloseableIterable<? extends T>> iterables); static CloseableIterable<T> autoClose(final CloseableIterable<? extends T> iterable); @SuppressWarnings("unchecked") static CloseableIterable<T> emptyIterable(); static CloseableIterable<T> singleton(T value); @Deprecated static CloseableIterable<T> wrap(final Iterable<T> iterable); }
|
@Test public void testTransform() { CloseableIterable<Integer> addOne = transform(testIterable(), input -> input + 1); CloseableIterable<Integer> multTen = transform(addOne, input -> input * 10); assertTrue(elementsEqual(asList(20, 30, 40, 50, 60), multTen)); multTen.close(); try { multTen.iterator(); fail(); } catch (IllegalStateException ignored) { } }
|
public static <F, T> CloseableIterable<T> transform(final CloseableIterable<F> iterable, final Function<? super F, ? extends T> function) { return wrap(Iterables.transform(iterable, function::apply), iterable); }
|
CloseableIterables { public static <F, T> CloseableIterable<T> transform(final CloseableIterable<F> iterable, final Function<? super F, ? extends T> function) { return wrap(Iterables.transform(iterable, function::apply), iterable); } }
|
CloseableIterables { public static <F, T> CloseableIterable<T> transform(final CloseableIterable<F> iterable, final Function<? super F, ? extends T> function) { return wrap(Iterables.transform(iterable, function::apply), iterable); } private CloseableIterables(); }
|
CloseableIterables { public static <F, T> CloseableIterable<T> transform(final CloseableIterable<F> iterable, final Function<? super F, ? extends T> function) { return wrap(Iterables.transform(iterable, function::apply), iterable); } private CloseableIterables(); static CloseableIterable<T> fromStream(Stream<T> stream); static CloseableIterable<T> fromIterable(Iterable<T> iterable); static CloseableIterable<T> distinct(final CloseableIterable<T> iterable); static CloseableIterable<List<T>> groupBy(final CloseableIterable<? extends T> iterable, final Function<? super T, ?> groupingFunction); static CloseableIterable<T> concat(final CloseableIterable<? extends Iterable<? extends T>> inputs); static CloseableIterable<T> cycle(final CloseableIterable<T> iterable); static CloseableIterable<T> filter(final CloseableIterable<?> iterable, final Class<T> type); static CloseableIterable<T> filter(final CloseableIterable<T> iterable, final Predicate<? super T> filter); static CloseableIterable<T> limit(final CloseableIterable<T> iterable, final int limitSize); static CloseableIterable<List<T>> paddedParition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<List<T>> partition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<T> skip(final CloseableIterable<T> iterable, final int numberToSkip); static CloseableIterable<T> transform(final CloseableIterable<F> iterable, final Function<? super F, ? extends T> function); @SafeVarargs static CloseableIterable<T> chain(CloseableIterable<? extends T>... iterables); static CloseableIterable<T> chain(final Iterable<? extends CloseableIterable<? extends T>> iterables); static CloseableIterable<T> autoClose(final CloseableIterable<? extends T> iterable); @SuppressWarnings("unchecked") static CloseableIterable<T> emptyIterable(); static CloseableIterable<T> singleton(T value); @Deprecated static CloseableIterable<T> wrap(final Iterable<T> iterable); }
|
CloseableIterables { public static <F, T> CloseableIterable<T> transform(final CloseableIterable<F> iterable, final Function<? super F, ? extends T> function) { return wrap(Iterables.transform(iterable, function::apply), iterable); } private CloseableIterables(); static CloseableIterable<T> fromStream(Stream<T> stream); static CloseableIterable<T> fromIterable(Iterable<T> iterable); static CloseableIterable<T> distinct(final CloseableIterable<T> iterable); static CloseableIterable<List<T>> groupBy(final CloseableIterable<? extends T> iterable, final Function<? super T, ?> groupingFunction); static CloseableIterable<T> concat(final CloseableIterable<? extends Iterable<? extends T>> inputs); static CloseableIterable<T> cycle(final CloseableIterable<T> iterable); static CloseableIterable<T> filter(final CloseableIterable<?> iterable, final Class<T> type); static CloseableIterable<T> filter(final CloseableIterable<T> iterable, final Predicate<? super T> filter); static CloseableIterable<T> limit(final CloseableIterable<T> iterable, final int limitSize); static CloseableIterable<List<T>> paddedParition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<List<T>> partition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<T> skip(final CloseableIterable<T> iterable, final int numberToSkip); static CloseableIterable<T> transform(final CloseableIterable<F> iterable, final Function<? super F, ? extends T> function); @SafeVarargs static CloseableIterable<T> chain(CloseableIterable<? extends T>... iterables); static CloseableIterable<T> chain(final Iterable<? extends CloseableIterable<? extends T>> iterables); static CloseableIterable<T> autoClose(final CloseableIterable<? extends T> iterable); @SuppressWarnings("unchecked") static CloseableIterable<T> emptyIterable(); static CloseableIterable<T> singleton(T value); @Deprecated static CloseableIterable<T> wrap(final Iterable<T> iterable); }
|
@Test public void testLimit() { CloseableIterable<Integer> firstThree = limit(testIterable(), 3); assertEquals(3, Iterables.size(firstThree)); assertTrue(elementsEqual(asList(1, 2, 3), firstThree)); firstThree.close(); try { firstThree.iterator(); fail(); } catch (IllegalStateException ignored) { } }
|
public static <T> CloseableIterable<T> limit(final CloseableIterable<T> iterable, final int limitSize) { return wrap(Iterables.limit(iterable, limitSize), iterable); }
|
CloseableIterables { public static <T> CloseableIterable<T> limit(final CloseableIterable<T> iterable, final int limitSize) { return wrap(Iterables.limit(iterable, limitSize), iterable); } }
|
CloseableIterables { public static <T> CloseableIterable<T> limit(final CloseableIterable<T> iterable, final int limitSize) { return wrap(Iterables.limit(iterable, limitSize), iterable); } private CloseableIterables(); }
|
CloseableIterables { public static <T> CloseableIterable<T> limit(final CloseableIterable<T> iterable, final int limitSize) { return wrap(Iterables.limit(iterable, limitSize), iterable); } private CloseableIterables(); static CloseableIterable<T> fromStream(Stream<T> stream); static CloseableIterable<T> fromIterable(Iterable<T> iterable); static CloseableIterable<T> distinct(final CloseableIterable<T> iterable); static CloseableIterable<List<T>> groupBy(final CloseableIterable<? extends T> iterable, final Function<? super T, ?> groupingFunction); static CloseableIterable<T> concat(final CloseableIterable<? extends Iterable<? extends T>> inputs); static CloseableIterable<T> cycle(final CloseableIterable<T> iterable); static CloseableIterable<T> filter(final CloseableIterable<?> iterable, final Class<T> type); static CloseableIterable<T> filter(final CloseableIterable<T> iterable, final Predicate<? super T> filter); static CloseableIterable<T> limit(final CloseableIterable<T> iterable, final int limitSize); static CloseableIterable<List<T>> paddedParition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<List<T>> partition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<T> skip(final CloseableIterable<T> iterable, final int numberToSkip); static CloseableIterable<T> transform(final CloseableIterable<F> iterable, final Function<? super F, ? extends T> function); @SafeVarargs static CloseableIterable<T> chain(CloseableIterable<? extends T>... iterables); static CloseableIterable<T> chain(final Iterable<? extends CloseableIterable<? extends T>> iterables); static CloseableIterable<T> autoClose(final CloseableIterable<? extends T> iterable); @SuppressWarnings("unchecked") static CloseableIterable<T> emptyIterable(); static CloseableIterable<T> singleton(T value); @Deprecated static CloseableIterable<T> wrap(final Iterable<T> iterable); }
|
CloseableIterables { public static <T> CloseableIterable<T> limit(final CloseableIterable<T> iterable, final int limitSize) { return wrap(Iterables.limit(iterable, limitSize), iterable); } private CloseableIterables(); static CloseableIterable<T> fromStream(Stream<T> stream); static CloseableIterable<T> fromIterable(Iterable<T> iterable); static CloseableIterable<T> distinct(final CloseableIterable<T> iterable); static CloseableIterable<List<T>> groupBy(final CloseableIterable<? extends T> iterable, final Function<? super T, ?> groupingFunction); static CloseableIterable<T> concat(final CloseableIterable<? extends Iterable<? extends T>> inputs); static CloseableIterable<T> cycle(final CloseableIterable<T> iterable); static CloseableIterable<T> filter(final CloseableIterable<?> iterable, final Class<T> type); static CloseableIterable<T> filter(final CloseableIterable<T> iterable, final Predicate<? super T> filter); static CloseableIterable<T> limit(final CloseableIterable<T> iterable, final int limitSize); static CloseableIterable<List<T>> paddedParition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<List<T>> partition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<T> skip(final CloseableIterable<T> iterable, final int numberToSkip); static CloseableIterable<T> transform(final CloseableIterable<F> iterable, final Function<? super F, ? extends T> function); @SafeVarargs static CloseableIterable<T> chain(CloseableIterable<? extends T>... iterables); static CloseableIterable<T> chain(final Iterable<? extends CloseableIterable<? extends T>> iterables); static CloseableIterable<T> autoClose(final CloseableIterable<? extends T> iterable); @SuppressWarnings("unchecked") static CloseableIterable<T> emptyIterable(); static CloseableIterable<T> singleton(T value); @Deprecated static CloseableIterable<T> wrap(final Iterable<T> iterable); }
|
@Test public void testFilter() { CloseableIterable<Integer> odd = filter(testIterable(), input -> input % 2 == 0); assertTrue(elementsEqual(asList(2, 4), odd)); odd.close(); try { odd.iterator(); fail(); } catch (IllegalStateException ignored) { } }
|
public static <T> CloseableIterable<T> filter(final CloseableIterable<?> iterable, final Class<T> type) { return wrap(Iterables.filter(iterable, type), iterable); }
|
CloseableIterables { public static <T> CloseableIterable<T> filter(final CloseableIterable<?> iterable, final Class<T> type) { return wrap(Iterables.filter(iterable, type), iterable); } }
|
CloseableIterables { public static <T> CloseableIterable<T> filter(final CloseableIterable<?> iterable, final Class<T> type) { return wrap(Iterables.filter(iterable, type), iterable); } private CloseableIterables(); }
|
CloseableIterables { public static <T> CloseableIterable<T> filter(final CloseableIterable<?> iterable, final Class<T> type) { return wrap(Iterables.filter(iterable, type), iterable); } private CloseableIterables(); static CloseableIterable<T> fromStream(Stream<T> stream); static CloseableIterable<T> fromIterable(Iterable<T> iterable); static CloseableIterable<T> distinct(final CloseableIterable<T> iterable); static CloseableIterable<List<T>> groupBy(final CloseableIterable<? extends T> iterable, final Function<? super T, ?> groupingFunction); static CloseableIterable<T> concat(final CloseableIterable<? extends Iterable<? extends T>> inputs); static CloseableIterable<T> cycle(final CloseableIterable<T> iterable); static CloseableIterable<T> filter(final CloseableIterable<?> iterable, final Class<T> type); static CloseableIterable<T> filter(final CloseableIterable<T> iterable, final Predicate<? super T> filter); static CloseableIterable<T> limit(final CloseableIterable<T> iterable, final int limitSize); static CloseableIterable<List<T>> paddedParition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<List<T>> partition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<T> skip(final CloseableIterable<T> iterable, final int numberToSkip); static CloseableIterable<T> transform(final CloseableIterable<F> iterable, final Function<? super F, ? extends T> function); @SafeVarargs static CloseableIterable<T> chain(CloseableIterable<? extends T>... iterables); static CloseableIterable<T> chain(final Iterable<? extends CloseableIterable<? extends T>> iterables); static CloseableIterable<T> autoClose(final CloseableIterable<? extends T> iterable); @SuppressWarnings("unchecked") static CloseableIterable<T> emptyIterable(); static CloseableIterable<T> singleton(T value); @Deprecated static CloseableIterable<T> wrap(final Iterable<T> iterable); }
|
CloseableIterables { public static <T> CloseableIterable<T> filter(final CloseableIterable<?> iterable, final Class<T> type) { return wrap(Iterables.filter(iterable, type), iterable); } private CloseableIterables(); static CloseableIterable<T> fromStream(Stream<T> stream); static CloseableIterable<T> fromIterable(Iterable<T> iterable); static CloseableIterable<T> distinct(final CloseableIterable<T> iterable); static CloseableIterable<List<T>> groupBy(final CloseableIterable<? extends T> iterable, final Function<? super T, ?> groupingFunction); static CloseableIterable<T> concat(final CloseableIterable<? extends Iterable<? extends T>> inputs); static CloseableIterable<T> cycle(final CloseableIterable<T> iterable); static CloseableIterable<T> filter(final CloseableIterable<?> iterable, final Class<T> type); static CloseableIterable<T> filter(final CloseableIterable<T> iterable, final Predicate<? super T> filter); static CloseableIterable<T> limit(final CloseableIterable<T> iterable, final int limitSize); static CloseableIterable<List<T>> paddedParition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<List<T>> partition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<T> skip(final CloseableIterable<T> iterable, final int numberToSkip); static CloseableIterable<T> transform(final CloseableIterable<F> iterable, final Function<? super F, ? extends T> function); @SafeVarargs static CloseableIterable<T> chain(CloseableIterable<? extends T>... iterables); static CloseableIterable<T> chain(final Iterable<? extends CloseableIterable<? extends T>> iterables); static CloseableIterable<T> autoClose(final CloseableIterable<? extends T> iterable); @SuppressWarnings("unchecked") static CloseableIterable<T> emptyIterable(); static CloseableIterable<T> singleton(T value); @Deprecated static CloseableIterable<T> wrap(final Iterable<T> iterable); }
|
@Test public void testBasicDeserialization2() throws Exception { Event event = create("type", "id", currentTimeMillis()) .attr("key", "value") .attr("key1", "valu1") .build(); String json = objectMapper.writeValueAsString(event); Event actualEntity = objectMapper.readValue(json, Event.class); assertEquals(actualEntity.getId(), event.getId()); assertEquals(actualEntity.getTimestamp(), event.getTimestamp()); assertEquals(new HashSet<>(actualEntity.getAttributes()), new HashSet<>(event.getAttributes())); }
|
@Override public BaseEvent build(EventBuilder entityBuilder) { return (BaseEvent) entityBuilder.build(); }
|
EventDeserializer extends AbstractAttributeStoreDeserializer<BaseEvent, EventBuilder> { @Override public BaseEvent build(EventBuilder entityBuilder) { return (BaseEvent) entityBuilder.build(); } }
|
EventDeserializer extends AbstractAttributeStoreDeserializer<BaseEvent, EventBuilder> { @Override public BaseEvent build(EventBuilder entityBuilder) { return (BaseEvent) entityBuilder.build(); } }
|
EventDeserializer extends AbstractAttributeStoreDeserializer<BaseEvent, EventBuilder> { @Override public BaseEvent build(EventBuilder entityBuilder) { return (BaseEvent) entityBuilder.build(); } @Override EventBuilder deserialize(JsonNode root); @Override BaseEvent build(EventBuilder entityBuilder); }
|
EventDeserializer extends AbstractAttributeStoreDeserializer<BaseEvent, EventBuilder> { @Override public BaseEvent build(EventBuilder entityBuilder) { return (BaseEvent) entityBuilder.build(); } @Override EventBuilder deserialize(JsonNode root); @Override BaseEvent build(EventBuilder entityBuilder); }
|
@Test public void testDistinct() { CloseableIterable<Integer> distinct = distinct(fromIterable(asList(1, 1, 2, 2, 3, 3, 3, 4, 5, 6, 7, 7, 7))); assertEquals(7, Iterables.size(distinct)); assertTrue(elementsEqual(asList(1, 2, 3, 4, 5, 6, 7), distinct)); distinct.close(); try { distinct.iterator(); fail(); } catch (IllegalStateException ignored) { } }
|
public static <T> CloseableIterable<T> distinct(final CloseableIterable<T> iterable) { return wrap(Iterables2.distinct(iterable), iterable); }
|
CloseableIterables { public static <T> CloseableIterable<T> distinct(final CloseableIterable<T> iterable) { return wrap(Iterables2.distinct(iterable), iterable); } }
|
CloseableIterables { public static <T> CloseableIterable<T> distinct(final CloseableIterable<T> iterable) { return wrap(Iterables2.distinct(iterable), iterable); } private CloseableIterables(); }
|
CloseableIterables { public static <T> CloseableIterable<T> distinct(final CloseableIterable<T> iterable) { return wrap(Iterables2.distinct(iterable), iterable); } private CloseableIterables(); static CloseableIterable<T> fromStream(Stream<T> stream); static CloseableIterable<T> fromIterable(Iterable<T> iterable); static CloseableIterable<T> distinct(final CloseableIterable<T> iterable); static CloseableIterable<List<T>> groupBy(final CloseableIterable<? extends T> iterable, final Function<? super T, ?> groupingFunction); static CloseableIterable<T> concat(final CloseableIterable<? extends Iterable<? extends T>> inputs); static CloseableIterable<T> cycle(final CloseableIterable<T> iterable); static CloseableIterable<T> filter(final CloseableIterable<?> iterable, final Class<T> type); static CloseableIterable<T> filter(final CloseableIterable<T> iterable, final Predicate<? super T> filter); static CloseableIterable<T> limit(final CloseableIterable<T> iterable, final int limitSize); static CloseableIterable<List<T>> paddedParition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<List<T>> partition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<T> skip(final CloseableIterable<T> iterable, final int numberToSkip); static CloseableIterable<T> transform(final CloseableIterable<F> iterable, final Function<? super F, ? extends T> function); @SafeVarargs static CloseableIterable<T> chain(CloseableIterable<? extends T>... iterables); static CloseableIterable<T> chain(final Iterable<? extends CloseableIterable<? extends T>> iterables); static CloseableIterable<T> autoClose(final CloseableIterable<? extends T> iterable); @SuppressWarnings("unchecked") static CloseableIterable<T> emptyIterable(); static CloseableIterable<T> singleton(T value); @Deprecated static CloseableIterable<T> wrap(final Iterable<T> iterable); }
|
CloseableIterables { public static <T> CloseableIterable<T> distinct(final CloseableIterable<T> iterable) { return wrap(Iterables2.distinct(iterable), iterable); } private CloseableIterables(); static CloseableIterable<T> fromStream(Stream<T> stream); static CloseableIterable<T> fromIterable(Iterable<T> iterable); static CloseableIterable<T> distinct(final CloseableIterable<T> iterable); static CloseableIterable<List<T>> groupBy(final CloseableIterable<? extends T> iterable, final Function<? super T, ?> groupingFunction); static CloseableIterable<T> concat(final CloseableIterable<? extends Iterable<? extends T>> inputs); static CloseableIterable<T> cycle(final CloseableIterable<T> iterable); static CloseableIterable<T> filter(final CloseableIterable<?> iterable, final Class<T> type); static CloseableIterable<T> filter(final CloseableIterable<T> iterable, final Predicate<? super T> filter); static CloseableIterable<T> limit(final CloseableIterable<T> iterable, final int limitSize); static CloseableIterable<List<T>> paddedParition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<List<T>> partition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<T> skip(final CloseableIterable<T> iterable, final int numberToSkip); static CloseableIterable<T> transform(final CloseableIterable<F> iterable, final Function<? super F, ? extends T> function); @SafeVarargs static CloseableIterable<T> chain(CloseableIterable<? extends T>... iterables); static CloseableIterable<T> chain(final Iterable<? extends CloseableIterable<? extends T>> iterables); static CloseableIterable<T> autoClose(final CloseableIterable<? extends T> iterable); @SuppressWarnings("unchecked") static CloseableIterable<T> emptyIterable(); static CloseableIterable<T> singleton(T value); @Deprecated static CloseableIterable<T> wrap(final Iterable<T> iterable); }
|
@Test public void testAutoClose() { MockIterable<Integer> iterable = testIterable(); CloseableIterable<Integer> closeableIterable = autoClose(iterable); closeableIterable.close(); assertTrue(iterable.isClosed()); iterable = testIterable(); closeableIterable = autoClose(iterable); Iterator<Integer> iterator = closeableIterable.iterator(); Iterators.size(iterator); assertTrue(iterable.isClosed()); iterable = testExceptionThrowingIterable(); closeableIterable = autoClose(iterable); iterator = closeableIterable.iterator(); try { iterator.next(); fail(); } catch (RuntimeException ignored) { } assertTrue(iterable.isClosed()); }
|
public static <T> CloseableIterable<T> autoClose(final CloseableIterable<? extends T> iterable) { requireNonNull(iterable); return new FluentCloseableIterable<T>() { @Override protected void doClose() { iterable.close(); } @Override protected Iterator<T> retrieveIterator() { return CloseableIterators.autoClose( CloseableIterators.wrap(iterable.iterator(), iterable) ); } }; }
|
CloseableIterables { public static <T> CloseableIterable<T> autoClose(final CloseableIterable<? extends T> iterable) { requireNonNull(iterable); return new FluentCloseableIterable<T>() { @Override protected void doClose() { iterable.close(); } @Override protected Iterator<T> retrieveIterator() { return CloseableIterators.autoClose( CloseableIterators.wrap(iterable.iterator(), iterable) ); } }; } }
|
CloseableIterables { public static <T> CloseableIterable<T> autoClose(final CloseableIterable<? extends T> iterable) { requireNonNull(iterable); return new FluentCloseableIterable<T>() { @Override protected void doClose() { iterable.close(); } @Override protected Iterator<T> retrieveIterator() { return CloseableIterators.autoClose( CloseableIterators.wrap(iterable.iterator(), iterable) ); } }; } private CloseableIterables(); }
|
CloseableIterables { public static <T> CloseableIterable<T> autoClose(final CloseableIterable<? extends T> iterable) { requireNonNull(iterable); return new FluentCloseableIterable<T>() { @Override protected void doClose() { iterable.close(); } @Override protected Iterator<T> retrieveIterator() { return CloseableIterators.autoClose( CloseableIterators.wrap(iterable.iterator(), iterable) ); } }; } private CloseableIterables(); static CloseableIterable<T> fromStream(Stream<T> stream); static CloseableIterable<T> fromIterable(Iterable<T> iterable); static CloseableIterable<T> distinct(final CloseableIterable<T> iterable); static CloseableIterable<List<T>> groupBy(final CloseableIterable<? extends T> iterable, final Function<? super T, ?> groupingFunction); static CloseableIterable<T> concat(final CloseableIterable<? extends Iterable<? extends T>> inputs); static CloseableIterable<T> cycle(final CloseableIterable<T> iterable); static CloseableIterable<T> filter(final CloseableIterable<?> iterable, final Class<T> type); static CloseableIterable<T> filter(final CloseableIterable<T> iterable, final Predicate<? super T> filter); static CloseableIterable<T> limit(final CloseableIterable<T> iterable, final int limitSize); static CloseableIterable<List<T>> paddedParition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<List<T>> partition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<T> skip(final CloseableIterable<T> iterable, final int numberToSkip); static CloseableIterable<T> transform(final CloseableIterable<F> iterable, final Function<? super F, ? extends T> function); @SafeVarargs static CloseableIterable<T> chain(CloseableIterable<? extends T>... iterables); static CloseableIterable<T> chain(final Iterable<? extends CloseableIterable<? extends T>> iterables); static CloseableIterable<T> autoClose(final CloseableIterable<? extends T> iterable); @SuppressWarnings("unchecked") static CloseableIterable<T> emptyIterable(); static CloseableIterable<T> singleton(T value); @Deprecated static CloseableIterable<T> wrap(final Iterable<T> iterable); }
|
CloseableIterables { public static <T> CloseableIterable<T> autoClose(final CloseableIterable<? extends T> iterable) { requireNonNull(iterable); return new FluentCloseableIterable<T>() { @Override protected void doClose() { iterable.close(); } @Override protected Iterator<T> retrieveIterator() { return CloseableIterators.autoClose( CloseableIterators.wrap(iterable.iterator(), iterable) ); } }; } private CloseableIterables(); static CloseableIterable<T> fromStream(Stream<T> stream); static CloseableIterable<T> fromIterable(Iterable<T> iterable); static CloseableIterable<T> distinct(final CloseableIterable<T> iterable); static CloseableIterable<List<T>> groupBy(final CloseableIterable<? extends T> iterable, final Function<? super T, ?> groupingFunction); static CloseableIterable<T> concat(final CloseableIterable<? extends Iterable<? extends T>> inputs); static CloseableIterable<T> cycle(final CloseableIterable<T> iterable); static CloseableIterable<T> filter(final CloseableIterable<?> iterable, final Class<T> type); static CloseableIterable<T> filter(final CloseableIterable<T> iterable, final Predicate<? super T> filter); static CloseableIterable<T> limit(final CloseableIterable<T> iterable, final int limitSize); static CloseableIterable<List<T>> paddedParition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<List<T>> partition(final CloseableIterable<T> iterable, final int size); static CloseableIterable<T> skip(final CloseableIterable<T> iterable, final int numberToSkip); static CloseableIterable<T> transform(final CloseableIterable<F> iterable, final Function<? super F, ? extends T> function); @SafeVarargs static CloseableIterable<T> chain(CloseableIterable<? extends T>... iterables); static CloseableIterable<T> chain(final Iterable<? extends CloseableIterable<? extends T>> iterables); static CloseableIterable<T> autoClose(final CloseableIterable<? extends T> iterable); @SuppressWarnings("unchecked") static CloseableIterable<T> emptyIterable(); static CloseableIterable<T> singleton(T value); @Deprecated static CloseableIterable<T> wrap(final Iterable<T> iterable); }
|
@Test public void testLimit() { CloseableIterable<Integer> closeableIterable = fromIterable(asList(1, 2, 3, 4, 5)); FluentCloseableIterable<Integer> limit = FluentCloseableIterable. from(closeableIterable).limit(3); assertEquals(3, Iterables.size(limit)); limit.close(); }
|
public final FluentCloseableIterable<T> limit(int size) { return from(CloseableIterables.limit(this, size)); }
|
FluentCloseableIterable extends AbstractCloseableIterable<T> { public final FluentCloseableIterable<T> limit(int size) { return from(CloseableIterables.limit(this, size)); } }
|
FluentCloseableIterable extends AbstractCloseableIterable<T> { public final FluentCloseableIterable<T> limit(int size) { return from(CloseableIterables.limit(this, size)); } protected FluentCloseableIterable(); }
|
FluentCloseableIterable extends AbstractCloseableIterable<T> { public final FluentCloseableIterable<T> limit(int size) { return from(CloseableIterables.limit(this, size)); } protected FluentCloseableIterable(); static FluentCloseableIterable<E> from(final CloseableIterable<E> iterable); final FluentCloseableIterable<T> autoClose(); @Override String toString(); final int size(); final boolean contains(Object target); final FluentCloseableIterable<T> cycle(); final FluentCloseableIterable<T> append(Iterable<? extends T> other); @SafeVarargs final FluentCloseableIterable<T> append(T... elements); final FluentCloseableIterable<T> filter(Predicate<? super T> predicate); final FluentCloseableIterable<E> filter(Class<E> type); final boolean anyMatch(Predicate<? super T> predicate); final boolean allMatch(Predicate<? super T> predicate); final Optional<T> firstMatch(Predicate<? super T> predicate); final FluentCloseableIterable<E> transform(Function<? super T, ? extends E> function); final FluentCloseableIterable<E> transformAndConcat(Function<? super T, ? extends Iterable<E>> function); final Optional<T> first(); final Optional<T> last(); final FluentCloseableIterable<T> skip(int numberToSkip); final FluentCloseableIterable<T> limit(int size); final boolean isEmpty(); final ImmutableList<T> toList(); final ImmutableList<T> toSortedList(Comparator<? super T> comparator); final ImmutableSet<T> toSet(); final ImmutableSortedSet<T> toSortedSet(Comparator<? super T> comparator); final ImmutableMultiset<T> toMultiset(); final ImmutableMap<T, V> toMap(Function<? super T, V> valueFunction); final ImmutableListMultimap<K, T> index(Function<? super T, K> keyFunction); final ImmutableMap<K, T> uniqueIndex(Function<? super T, K> keyFunction); final T[] toArray(Class<T> type); final C copyInto(C collection); final String join(Joiner joiner); final T get(int position); final Iterable<T> toSimpleIterable(); }
|
FluentCloseableIterable extends AbstractCloseableIterable<T> { public final FluentCloseableIterable<T> limit(int size) { return from(CloseableIterables.limit(this, size)); } protected FluentCloseableIterable(); static FluentCloseableIterable<E> from(final CloseableIterable<E> iterable); final FluentCloseableIterable<T> autoClose(); @Override String toString(); final int size(); final boolean contains(Object target); final FluentCloseableIterable<T> cycle(); final FluentCloseableIterable<T> append(Iterable<? extends T> other); @SafeVarargs final FluentCloseableIterable<T> append(T... elements); final FluentCloseableIterable<T> filter(Predicate<? super T> predicate); final FluentCloseableIterable<E> filter(Class<E> type); final boolean anyMatch(Predicate<? super T> predicate); final boolean allMatch(Predicate<? super T> predicate); final Optional<T> firstMatch(Predicate<? super T> predicate); final FluentCloseableIterable<E> transform(Function<? super T, ? extends E> function); final FluentCloseableIterable<E> transformAndConcat(Function<? super T, ? extends Iterable<E>> function); final Optional<T> first(); final Optional<T> last(); final FluentCloseableIterable<T> skip(int numberToSkip); final FluentCloseableIterable<T> limit(int size); final boolean isEmpty(); final ImmutableList<T> toList(); final ImmutableList<T> toSortedList(Comparator<? super T> comparator); final ImmutableSet<T> toSet(); final ImmutableSortedSet<T> toSortedSet(Comparator<? super T> comparator); final ImmutableMultiset<T> toMultiset(); final ImmutableMap<T, V> toMap(Function<? super T, V> valueFunction); final ImmutableListMultimap<K, T> index(Function<? super T, K> keyFunction); final ImmutableMap<K, T> uniqueIndex(Function<? super T, K> keyFunction); final T[] toArray(Class<T> type); final C copyInto(C collection); final String join(Joiner joiner); final T get(int position); final Iterable<T> toSimpleIterable(); }
|
@Test public void distinctTest() throws Exception { Iterator<Integer> distinct = distinct(asList(1, 1, 2, 2, 3, 3, 3, 4, 5, 6, 7, 7, 7).iterator()); assertTrue(elementsEqual(asList(1, 2, 3, 4, 5, 6, 7).iterator(), distinct)); assertFalse(distinct.hasNext()); }
|
public static <T> Iterator<T> distinct(final Iterator<T> iterator) { requireNonNull(iterator); return new AbstractIterator<T>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); private T curr = null; @Override protected T computeNext() { while (peekingIterator.hasNext() && Objects.equals(curr, peekingIterator.peek())) { peekingIterator.next(); } if (!peekingIterator.hasNext()) return endOfData(); curr = peekingIterator.next(); return curr; } }; }
|
Iterators2 { public static <T> Iterator<T> distinct(final Iterator<T> iterator) { requireNonNull(iterator); return new AbstractIterator<T>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); private T curr = null; @Override protected T computeNext() { while (peekingIterator.hasNext() && Objects.equals(curr, peekingIterator.peek())) { peekingIterator.next(); } if (!peekingIterator.hasNext()) return endOfData(); curr = peekingIterator.next(); return curr; } }; } }
|
Iterators2 { public static <T> Iterator<T> distinct(final Iterator<T> iterator) { requireNonNull(iterator); return new AbstractIterator<T>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); private T curr = null; @Override protected T computeNext() { while (peekingIterator.hasNext() && Objects.equals(curr, peekingIterator.peek())) { peekingIterator.next(); } if (!peekingIterator.hasNext()) return endOfData(); curr = peekingIterator.next(); return curr; } }; } private Iterators2(); }
|
Iterators2 { public static <T> Iterator<T> distinct(final Iterator<T> iterator) { requireNonNull(iterator); return new AbstractIterator<T>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); private T curr = null; @Override protected T computeNext() { while (peekingIterator.hasNext() && Objects.equals(curr, peekingIterator.peek())) { peekingIterator.next(); } if (!peekingIterator.hasNext()) return endOfData(); curr = peekingIterator.next(); return curr; } }; } private Iterators2(); static Iterator<T> distinct(final Iterator<T> iterator); static Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction); }
|
Iterators2 { public static <T> Iterator<T> distinct(final Iterator<T> iterator) { requireNonNull(iterator); return new AbstractIterator<T>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); private T curr = null; @Override protected T computeNext() { while (peekingIterator.hasNext() && Objects.equals(curr, peekingIterator.peek())) { peekingIterator.next(); } if (!peekingIterator.hasNext()) return endOfData(); curr = peekingIterator.next(); return curr; } }; } private Iterators2(); static Iterator<T> distinct(final Iterator<T> iterator); static Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction); }
|
@Test(expected = NullPointerException.class) public void distinctNullIteratorTest() { distinct(null); }
|
public static <T> Iterator<T> distinct(final Iterator<T> iterator) { requireNonNull(iterator); return new AbstractIterator<T>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); private T curr = null; @Override protected T computeNext() { while (peekingIterator.hasNext() && Objects.equals(curr, peekingIterator.peek())) { peekingIterator.next(); } if (!peekingIterator.hasNext()) return endOfData(); curr = peekingIterator.next(); return curr; } }; }
|
Iterators2 { public static <T> Iterator<T> distinct(final Iterator<T> iterator) { requireNonNull(iterator); return new AbstractIterator<T>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); private T curr = null; @Override protected T computeNext() { while (peekingIterator.hasNext() && Objects.equals(curr, peekingIterator.peek())) { peekingIterator.next(); } if (!peekingIterator.hasNext()) return endOfData(); curr = peekingIterator.next(); return curr; } }; } }
|
Iterators2 { public static <T> Iterator<T> distinct(final Iterator<T> iterator) { requireNonNull(iterator); return new AbstractIterator<T>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); private T curr = null; @Override protected T computeNext() { while (peekingIterator.hasNext() && Objects.equals(curr, peekingIterator.peek())) { peekingIterator.next(); } if (!peekingIterator.hasNext()) return endOfData(); curr = peekingIterator.next(); return curr; } }; } private Iterators2(); }
|
Iterators2 { public static <T> Iterator<T> distinct(final Iterator<T> iterator) { requireNonNull(iterator); return new AbstractIterator<T>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); private T curr = null; @Override protected T computeNext() { while (peekingIterator.hasNext() && Objects.equals(curr, peekingIterator.peek())) { peekingIterator.next(); } if (!peekingIterator.hasNext()) return endOfData(); curr = peekingIterator.next(); return curr; } }; } private Iterators2(); static Iterator<T> distinct(final Iterator<T> iterator); static Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction); }
|
Iterators2 { public static <T> Iterator<T> distinct(final Iterator<T> iterator) { requireNonNull(iterator); return new AbstractIterator<T>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); private T curr = null; @Override protected T computeNext() { while (peekingIterator.hasNext() && Objects.equals(curr, peekingIterator.peek())) { peekingIterator.next(); } if (!peekingIterator.hasNext()) return endOfData(); curr = peekingIterator.next(); return curr; } }; } private Iterators2(); static Iterator<T> distinct(final Iterator<T> iterator); static Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction); }
|
@Test public void groupByTest() { List<Integer> testdata = asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); Iterator<List<Integer>> grouped = groupBy(testdata.iterator(), input -> input / 5); assertTrue(grouped.hasNext()); assertEquals(asList(0, 1, 2, 3, 4), grouped.next()); assertEquals(asList(5, 6, 7, 8, 9), grouped.next()); assertFalse(grouped.hasNext()); grouped = groupBy(testdata.iterator(), input -> null); assertTrue(grouped.hasNext()); assertEquals(testdata, grouped.next()); assertFalse(grouped.hasNext()); grouped = groupBy(testdata.iterator(), input -> input); assertTrue(grouped.hasNext()); for (int i = 0; i< testdata.size(); i++) { assertTrue(grouped.hasNext()); List<Integer> group = grouped.next(); assertEquals(1, group.size()); assertEquals(new Integer(i), group.get(0)); } assertFalse(grouped.hasNext()); }
|
public static <T> Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction) { requireNonNull(iterator); requireNonNull(groupingFunction); return new AbstractIterator<List<T>>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); @Override protected List<T> computeNext() { if (!peekingIterator.hasNext()) return endOfData(); Object key = groupingFunction.apply(peekingIterator.peek()); List<T> group = new ArrayList<>(); do { group.add(peekingIterator.next()); } while (peekingIterator.hasNext() && Objects.equals(key, groupingFunction.apply(peekingIterator.peek()))); return unmodifiableList(group); } }; }
|
Iterators2 { public static <T> Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction) { requireNonNull(iterator); requireNonNull(groupingFunction); return new AbstractIterator<List<T>>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); @Override protected List<T> computeNext() { if (!peekingIterator.hasNext()) return endOfData(); Object key = groupingFunction.apply(peekingIterator.peek()); List<T> group = new ArrayList<>(); do { group.add(peekingIterator.next()); } while (peekingIterator.hasNext() && Objects.equals(key, groupingFunction.apply(peekingIterator.peek()))); return unmodifiableList(group); } }; } }
|
Iterators2 { public static <T> Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction) { requireNonNull(iterator); requireNonNull(groupingFunction); return new AbstractIterator<List<T>>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); @Override protected List<T> computeNext() { if (!peekingIterator.hasNext()) return endOfData(); Object key = groupingFunction.apply(peekingIterator.peek()); List<T> group = new ArrayList<>(); do { group.add(peekingIterator.next()); } while (peekingIterator.hasNext() && Objects.equals(key, groupingFunction.apply(peekingIterator.peek()))); return unmodifiableList(group); } }; } private Iterators2(); }
|
Iterators2 { public static <T> Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction) { requireNonNull(iterator); requireNonNull(groupingFunction); return new AbstractIterator<List<T>>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); @Override protected List<T> computeNext() { if (!peekingIterator.hasNext()) return endOfData(); Object key = groupingFunction.apply(peekingIterator.peek()); List<T> group = new ArrayList<>(); do { group.add(peekingIterator.next()); } while (peekingIterator.hasNext() && Objects.equals(key, groupingFunction.apply(peekingIterator.peek()))); return unmodifiableList(group); } }; } private Iterators2(); static Iterator<T> distinct(final Iterator<T> iterator); static Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction); }
|
Iterators2 { public static <T> Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction) { requireNonNull(iterator); requireNonNull(groupingFunction); return new AbstractIterator<List<T>>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); @Override protected List<T> computeNext() { if (!peekingIterator.hasNext()) return endOfData(); Object key = groupingFunction.apply(peekingIterator.peek()); List<T> group = new ArrayList<>(); do { group.add(peekingIterator.next()); } while (peekingIterator.hasNext() && Objects.equals(key, groupingFunction.apply(peekingIterator.peek()))); return unmodifiableList(group); } }; } private Iterators2(); static Iterator<T> distinct(final Iterator<T> iterator); static Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction); }
|
@Test(expected = NullPointerException.class) public void groupByNullIteratorTest() { groupBy(null, input -> null); }
|
public static <T> Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction) { requireNonNull(iterator); requireNonNull(groupingFunction); return new AbstractIterator<List<T>>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); @Override protected List<T> computeNext() { if (!peekingIterator.hasNext()) return endOfData(); Object key = groupingFunction.apply(peekingIterator.peek()); List<T> group = new ArrayList<>(); do { group.add(peekingIterator.next()); } while (peekingIterator.hasNext() && Objects.equals(key, groupingFunction.apply(peekingIterator.peek()))); return unmodifiableList(group); } }; }
|
Iterators2 { public static <T> Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction) { requireNonNull(iterator); requireNonNull(groupingFunction); return new AbstractIterator<List<T>>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); @Override protected List<T> computeNext() { if (!peekingIterator.hasNext()) return endOfData(); Object key = groupingFunction.apply(peekingIterator.peek()); List<T> group = new ArrayList<>(); do { group.add(peekingIterator.next()); } while (peekingIterator.hasNext() && Objects.equals(key, groupingFunction.apply(peekingIterator.peek()))); return unmodifiableList(group); } }; } }
|
Iterators2 { public static <T> Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction) { requireNonNull(iterator); requireNonNull(groupingFunction); return new AbstractIterator<List<T>>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); @Override protected List<T> computeNext() { if (!peekingIterator.hasNext()) return endOfData(); Object key = groupingFunction.apply(peekingIterator.peek()); List<T> group = new ArrayList<>(); do { group.add(peekingIterator.next()); } while (peekingIterator.hasNext() && Objects.equals(key, groupingFunction.apply(peekingIterator.peek()))); return unmodifiableList(group); } }; } private Iterators2(); }
|
Iterators2 { public static <T> Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction) { requireNonNull(iterator); requireNonNull(groupingFunction); return new AbstractIterator<List<T>>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); @Override protected List<T> computeNext() { if (!peekingIterator.hasNext()) return endOfData(); Object key = groupingFunction.apply(peekingIterator.peek()); List<T> group = new ArrayList<>(); do { group.add(peekingIterator.next()); } while (peekingIterator.hasNext() && Objects.equals(key, groupingFunction.apply(peekingIterator.peek()))); return unmodifiableList(group); } }; } private Iterators2(); static Iterator<T> distinct(final Iterator<T> iterator); static Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction); }
|
Iterators2 { public static <T> Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction) { requireNonNull(iterator); requireNonNull(groupingFunction); return new AbstractIterator<List<T>>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); @Override protected List<T> computeNext() { if (!peekingIterator.hasNext()) return endOfData(); Object key = groupingFunction.apply(peekingIterator.peek()); List<T> group = new ArrayList<>(); do { group.add(peekingIterator.next()); } while (peekingIterator.hasNext() && Objects.equals(key, groupingFunction.apply(peekingIterator.peek()))); return unmodifiableList(group); } }; } private Iterators2(); static Iterator<T> distinct(final Iterator<T> iterator); static Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction); }
|
@Test(expected = NullPointerException.class) public void groupByNullEquivTest() { groupBy(emptyIterator(), null); }
|
public static <T> Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction) { requireNonNull(iterator); requireNonNull(groupingFunction); return new AbstractIterator<List<T>>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); @Override protected List<T> computeNext() { if (!peekingIterator.hasNext()) return endOfData(); Object key = groupingFunction.apply(peekingIterator.peek()); List<T> group = new ArrayList<>(); do { group.add(peekingIterator.next()); } while (peekingIterator.hasNext() && Objects.equals(key, groupingFunction.apply(peekingIterator.peek()))); return unmodifiableList(group); } }; }
|
Iterators2 { public static <T> Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction) { requireNonNull(iterator); requireNonNull(groupingFunction); return new AbstractIterator<List<T>>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); @Override protected List<T> computeNext() { if (!peekingIterator.hasNext()) return endOfData(); Object key = groupingFunction.apply(peekingIterator.peek()); List<T> group = new ArrayList<>(); do { group.add(peekingIterator.next()); } while (peekingIterator.hasNext() && Objects.equals(key, groupingFunction.apply(peekingIterator.peek()))); return unmodifiableList(group); } }; } }
|
Iterators2 { public static <T> Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction) { requireNonNull(iterator); requireNonNull(groupingFunction); return new AbstractIterator<List<T>>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); @Override protected List<T> computeNext() { if (!peekingIterator.hasNext()) return endOfData(); Object key = groupingFunction.apply(peekingIterator.peek()); List<T> group = new ArrayList<>(); do { group.add(peekingIterator.next()); } while (peekingIterator.hasNext() && Objects.equals(key, groupingFunction.apply(peekingIterator.peek()))); return unmodifiableList(group); } }; } private Iterators2(); }
|
Iterators2 { public static <T> Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction) { requireNonNull(iterator); requireNonNull(groupingFunction); return new AbstractIterator<List<T>>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); @Override protected List<T> computeNext() { if (!peekingIterator.hasNext()) return endOfData(); Object key = groupingFunction.apply(peekingIterator.peek()); List<T> group = new ArrayList<>(); do { group.add(peekingIterator.next()); } while (peekingIterator.hasNext() && Objects.equals(key, groupingFunction.apply(peekingIterator.peek()))); return unmodifiableList(group); } }; } private Iterators2(); static Iterator<T> distinct(final Iterator<T> iterator); static Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction); }
|
Iterators2 { public static <T> Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction) { requireNonNull(iterator); requireNonNull(groupingFunction); return new AbstractIterator<List<T>>() { private final PeekingIterator<T> peekingIterator = peekingIterator(iterator); @Override protected List<T> computeNext() { if (!peekingIterator.hasNext()) return endOfData(); Object key = groupingFunction.apply(peekingIterator.peek()); List<T> group = new ArrayList<>(); do { group.add(peekingIterator.next()); } while (peekingIterator.hasNext() && Objects.equals(key, groupingFunction.apply(peekingIterator.peek()))); return unmodifiableList(group); } }; } private Iterators2(); static Iterator<T> distinct(final Iterator<T> iterator); static Iterator<List<T>> groupBy(final Iterator<? extends T> iterator, final Function<? super T, ?> groupingFunction); }
|
@Test public void forStringTest() { InetAddress address; address = MoreInetAddresses.forString("1.2.3.4"); assertTrue(address instanceof Inet4Address); assertEquals("1.2.3.4", toAddrString(address)); address = MoreInetAddresses.forString("::1.2.3.4"); assertTrue(address instanceof Inet6Address); assertEquals("::102:304", toAddrString(address)); address = MoreInetAddresses.forString("::ffff:1.2.3.4"); assertTrue(address instanceof Inet6Address); assertEquals("::ffff:102:304", toAddrString(address)); }
|
public static InetAddress forString(String ipString) { requireNonNull(ipString); InetAddress address = InetAddresses.forString(ipString); if (address instanceof Inet4Address && ipString.contains(":")) return getIPv4MappedIPv6Address((Inet4Address) address); return address; }
|
MoreInetAddresses { public static InetAddress forString(String ipString) { requireNonNull(ipString); InetAddress address = InetAddresses.forString(ipString); if (address instanceof Inet4Address && ipString.contains(":")) return getIPv4MappedIPv6Address((Inet4Address) address); return address; } }
|
MoreInetAddresses { public static InetAddress forString(String ipString) { requireNonNull(ipString); InetAddress address = InetAddresses.forString(ipString); if (address instanceof Inet4Address && ipString.contains(":")) return getIPv4MappedIPv6Address((Inet4Address) address); return address; } private MoreInetAddresses(); }
|
MoreInetAddresses { public static InetAddress forString(String ipString) { requireNonNull(ipString); InetAddress address = InetAddresses.forString(ipString); if (address instanceof Inet4Address && ipString.contains(":")) return getIPv4MappedIPv6Address((Inet4Address) address); return address; } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static InetAddress forString(String ipString) { requireNonNull(ipString); InetAddress address = InetAddresses.forString(ipString); if (address instanceof Inet4Address && ipString.contains(":")) return getIPv4MappedIPv6Address((Inet4Address) address); return address; } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test(expected = NullPointerException.class) public void forStringNullTest() { MoreInetAddresses.forString(null); }
|
public static InetAddress forString(String ipString) { requireNonNull(ipString); InetAddress address = InetAddresses.forString(ipString); if (address instanceof Inet4Address && ipString.contains(":")) return getIPv4MappedIPv6Address((Inet4Address) address); return address; }
|
MoreInetAddresses { public static InetAddress forString(String ipString) { requireNonNull(ipString); InetAddress address = InetAddresses.forString(ipString); if (address instanceof Inet4Address && ipString.contains(":")) return getIPv4MappedIPv6Address((Inet4Address) address); return address; } }
|
MoreInetAddresses { public static InetAddress forString(String ipString) { requireNonNull(ipString); InetAddress address = InetAddresses.forString(ipString); if (address instanceof Inet4Address && ipString.contains(":")) return getIPv4MappedIPv6Address((Inet4Address) address); return address; } private MoreInetAddresses(); }
|
MoreInetAddresses { public static InetAddress forString(String ipString) { requireNonNull(ipString); InetAddress address = InetAddresses.forString(ipString); if (address instanceof Inet4Address && ipString.contains(":")) return getIPv4MappedIPv6Address((Inet4Address) address); return address; } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static InetAddress forString(String ipString) { requireNonNull(ipString); InetAddress address = InetAddresses.forString(ipString); if (address instanceof Inet4Address && ipString.contains(":")) return getIPv4MappedIPv6Address((Inet4Address) address); return address; } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test public void testBasicDeserialization() throws Exception { Entity entity = create("type", "id") .attr("key", "value") .build(); String json = objectMapper.writeValueAsString(entity); Entity actualEntity = objectMapper.readValue(json, Entity.class); assertEquals(actualEntity.getType(), entity.getType()); assertEquals(actualEntity.getId(), entity.getId()); assertEquals(new HashSet<>(actualEntity.getAttributes()), new HashSet<>(entity.getAttributes())); }
|
@Override public BaseEntity build(EntityBuilder entityBuilder) { return (BaseEntity)entityBuilder.build(); }
|
EntityDeserializer extends AbstractAttributeStoreDeserializer<BaseEntity, EntityBuilder> { @Override public BaseEntity build(EntityBuilder entityBuilder) { return (BaseEntity)entityBuilder.build(); } }
|
EntityDeserializer extends AbstractAttributeStoreDeserializer<BaseEntity, EntityBuilder> { @Override public BaseEntity build(EntityBuilder entityBuilder) { return (BaseEntity)entityBuilder.build(); } }
|
EntityDeserializer extends AbstractAttributeStoreDeserializer<BaseEntity, EntityBuilder> { @Override public BaseEntity build(EntityBuilder entityBuilder) { return (BaseEntity)entityBuilder.build(); } @Override EntityBuilder deserialize(JsonNode root); @Override BaseEntity build(EntityBuilder entityBuilder); }
|
EntityDeserializer extends AbstractAttributeStoreDeserializer<BaseEntity, EntityBuilder> { @Override public BaseEntity build(EntityBuilder entityBuilder) { return (BaseEntity)entityBuilder.build(); } @Override EntityBuilder deserialize(JsonNode root); @Override BaseEntity build(EntityBuilder entityBuilder); }
|
@Test public void forIpv4StringTest() { Inet4Address address; address = forIPv4String("1.2.3.4"); assertEquals("1.2.3.4", toAddrString(address)); }
|
public static Inet4Address forIPv4String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet4Address) return (Inet4Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv4 representation: %s", ipString)); }
|
MoreInetAddresses { public static Inet4Address forIPv4String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet4Address) return (Inet4Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv4 representation: %s", ipString)); } }
|
MoreInetAddresses { public static Inet4Address forIPv4String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet4Address) return (Inet4Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv4 representation: %s", ipString)); } private MoreInetAddresses(); }
|
MoreInetAddresses { public static Inet4Address forIPv4String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet4Address) return (Inet4Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv4 representation: %s", ipString)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static Inet4Address forIPv4String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet4Address) return (Inet4Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv4 representation: %s", ipString)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test(expected = NullPointerException.class) public void forIpv4StringNullTest() { forIPv4String(null); }
|
public static Inet4Address forIPv4String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet4Address) return (Inet4Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv4 representation: %s", ipString)); }
|
MoreInetAddresses { public static Inet4Address forIPv4String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet4Address) return (Inet4Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv4 representation: %s", ipString)); } }
|
MoreInetAddresses { public static Inet4Address forIPv4String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet4Address) return (Inet4Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv4 representation: %s", ipString)); } private MoreInetAddresses(); }
|
MoreInetAddresses { public static Inet4Address forIPv4String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet4Address) return (Inet4Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv4 representation: %s", ipString)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static Inet4Address forIPv4String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet4Address) return (Inet4Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv4 representation: %s", ipString)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test(expected = IllegalArgumentException.class) public void forIpv4StringWithIpv6Test() { forIPv4String("::1.2.3.4"); }
|
public static Inet4Address forIPv4String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet4Address) return (Inet4Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv4 representation: %s", ipString)); }
|
MoreInetAddresses { public static Inet4Address forIPv4String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet4Address) return (Inet4Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv4 representation: %s", ipString)); } }
|
MoreInetAddresses { public static Inet4Address forIPv4String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet4Address) return (Inet4Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv4 representation: %s", ipString)); } private MoreInetAddresses(); }
|
MoreInetAddresses { public static Inet4Address forIPv4String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet4Address) return (Inet4Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv4 representation: %s", ipString)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static Inet4Address forIPv4String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet4Address) return (Inet4Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv4 representation: %s", ipString)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test(expected = IllegalArgumentException.class) public void forIpv4StringWithMappedIpv4Test() { forIPv4String("::ffff:1.2.3.4"); }
|
public static Inet4Address forIPv4String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet4Address) return (Inet4Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv4 representation: %s", ipString)); }
|
MoreInetAddresses { public static Inet4Address forIPv4String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet4Address) return (Inet4Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv4 representation: %s", ipString)); } }
|
MoreInetAddresses { public static Inet4Address forIPv4String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet4Address) return (Inet4Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv4 representation: %s", ipString)); } private MoreInetAddresses(); }
|
MoreInetAddresses { public static Inet4Address forIPv4String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet4Address) return (Inet4Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv4 representation: %s", ipString)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static Inet4Address forIPv4String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet4Address) return (Inet4Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv4 representation: %s", ipString)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test public void forIpv6StringTest() { Inet6Address address; address = forIPv6String("::1.2.3.4"); assertEquals("::102:304", toAddrString(address)); address = forIPv6String("::ffff:1.2.3.4"); assertEquals("::ffff:102:304", toAddrString(address)); }
|
public static Inet6Address forIPv6String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet6Address) return (Inet6Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv6 representation: %s", ipString)); }
|
MoreInetAddresses { public static Inet6Address forIPv6String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet6Address) return (Inet6Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv6 representation: %s", ipString)); } }
|
MoreInetAddresses { public static Inet6Address forIPv6String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet6Address) return (Inet6Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv6 representation: %s", ipString)); } private MoreInetAddresses(); }
|
MoreInetAddresses { public static Inet6Address forIPv6String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet6Address) return (Inet6Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv6 representation: %s", ipString)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static Inet6Address forIPv6String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet6Address) return (Inet6Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv6 representation: %s", ipString)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test(expected = NullPointerException.class) public void forIpv6StringNullTest() { forIPv6String(null); }
|
public static Inet6Address forIPv6String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet6Address) return (Inet6Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv6 representation: %s", ipString)); }
|
MoreInetAddresses { public static Inet6Address forIPv6String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet6Address) return (Inet6Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv6 representation: %s", ipString)); } }
|
MoreInetAddresses { public static Inet6Address forIPv6String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet6Address) return (Inet6Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv6 representation: %s", ipString)); } private MoreInetAddresses(); }
|
MoreInetAddresses { public static Inet6Address forIPv6String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet6Address) return (Inet6Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv6 representation: %s", ipString)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static Inet6Address forIPv6String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet6Address) return (Inet6Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv6 representation: %s", ipString)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test(expected = IllegalArgumentException.class) public void forIpv6StringWithIpv4Test() { forIPv6String("1.2.3.4"); }
|
public static Inet6Address forIPv6String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet6Address) return (Inet6Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv6 representation: %s", ipString)); }
|
MoreInetAddresses { public static Inet6Address forIPv6String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet6Address) return (Inet6Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv6 representation: %s", ipString)); } }
|
MoreInetAddresses { public static Inet6Address forIPv6String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet6Address) return (Inet6Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv6 representation: %s", ipString)); } private MoreInetAddresses(); }
|
MoreInetAddresses { public static Inet6Address forIPv6String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet6Address) return (Inet6Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv6 representation: %s", ipString)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static Inet6Address forIPv6String(String ipString) { requireNonNull(ipString); try{ InetAddress parsed = forString(ipString); if (parsed instanceof Inet6Address) return (Inet6Address) parsed; } catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid IPv6 representation: %s", ipString)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test public void isMappedIPv4AddressTest() throws UnknownHostException { byte[] bytes = new byte[]{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, (byte) 0xff, (byte) 0xff, 0x1, 0x2, 0x3, 0x4 }; Inet6Address address = Inet6Address.getByAddress(null, bytes, -1); assertTrue(MoreInetAddresses.isMappedIPv4Address(address)); bytes = new byte[]{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x2, 0x3, 0x4 }; address = Inet6Address.getByAddress(null, bytes, -1); assertFalse(MoreInetAddresses.isMappedIPv4Address(address)); }
|
public static boolean isMappedIPv4Address(Inet6Address ip) { byte bytes[] = ip.getAddress(); return ((bytes[0] == 0x00) && (bytes[1] == 0x00) && (bytes[2] == 0x00) && (bytes[3] == 0x00) && (bytes[4] == 0x00) && (bytes[5] == 0x00) && (bytes[6] == 0x00) && (bytes[7] == 0x00) && (bytes[8] == 0x00) && (bytes[9] == 0x00) && (bytes[10] == (byte)0xff) && (bytes[11] == (byte)0xff)); }
|
MoreInetAddresses { public static boolean isMappedIPv4Address(Inet6Address ip) { byte bytes[] = ip.getAddress(); return ((bytes[0] == 0x00) && (bytes[1] == 0x00) && (bytes[2] == 0x00) && (bytes[3] == 0x00) && (bytes[4] == 0x00) && (bytes[5] == 0x00) && (bytes[6] == 0x00) && (bytes[7] == 0x00) && (bytes[8] == 0x00) && (bytes[9] == 0x00) && (bytes[10] == (byte)0xff) && (bytes[11] == (byte)0xff)); } }
|
MoreInetAddresses { public static boolean isMappedIPv4Address(Inet6Address ip) { byte bytes[] = ip.getAddress(); return ((bytes[0] == 0x00) && (bytes[1] == 0x00) && (bytes[2] == 0x00) && (bytes[3] == 0x00) && (bytes[4] == 0x00) && (bytes[5] == 0x00) && (bytes[6] == 0x00) && (bytes[7] == 0x00) && (bytes[8] == 0x00) && (bytes[9] == 0x00) && (bytes[10] == (byte)0xff) && (bytes[11] == (byte)0xff)); } private MoreInetAddresses(); }
|
MoreInetAddresses { public static boolean isMappedIPv4Address(Inet6Address ip) { byte bytes[] = ip.getAddress(); return ((bytes[0] == 0x00) && (bytes[1] == 0x00) && (bytes[2] == 0x00) && (bytes[3] == 0x00) && (bytes[4] == 0x00) && (bytes[5] == 0x00) && (bytes[6] == 0x00) && (bytes[7] == 0x00) && (bytes[8] == 0x00) && (bytes[9] == 0x00) && (bytes[10] == (byte)0xff) && (bytes[11] == (byte)0xff)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static boolean isMappedIPv4Address(Inet6Address ip) { byte bytes[] = ip.getAddress(); return ((bytes[0] == 0x00) && (bytes[1] == 0x00) && (bytes[2] == 0x00) && (bytes[3] == 0x00) && (bytes[4] == 0x00) && (bytes[5] == 0x00) && (bytes[6] == 0x00) && (bytes[7] == 0x00) && (bytes[8] == 0x00) && (bytes[9] == 0x00) && (bytes[10] == (byte)0xff) && (bytes[11] == (byte)0xff)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test(expected = NullPointerException.class) public void isMappedIPv4AddressNullTest() { MoreInetAddresses.isMappedIPv4Address(null); }
|
public static boolean isMappedIPv4Address(Inet6Address ip) { byte bytes[] = ip.getAddress(); return ((bytes[0] == 0x00) && (bytes[1] == 0x00) && (bytes[2] == 0x00) && (bytes[3] == 0x00) && (bytes[4] == 0x00) && (bytes[5] == 0x00) && (bytes[6] == 0x00) && (bytes[7] == 0x00) && (bytes[8] == 0x00) && (bytes[9] == 0x00) && (bytes[10] == (byte)0xff) && (bytes[11] == (byte)0xff)); }
|
MoreInetAddresses { public static boolean isMappedIPv4Address(Inet6Address ip) { byte bytes[] = ip.getAddress(); return ((bytes[0] == 0x00) && (bytes[1] == 0x00) && (bytes[2] == 0x00) && (bytes[3] == 0x00) && (bytes[4] == 0x00) && (bytes[5] == 0x00) && (bytes[6] == 0x00) && (bytes[7] == 0x00) && (bytes[8] == 0x00) && (bytes[9] == 0x00) && (bytes[10] == (byte)0xff) && (bytes[11] == (byte)0xff)); } }
|
MoreInetAddresses { public static boolean isMappedIPv4Address(Inet6Address ip) { byte bytes[] = ip.getAddress(); return ((bytes[0] == 0x00) && (bytes[1] == 0x00) && (bytes[2] == 0x00) && (bytes[3] == 0x00) && (bytes[4] == 0x00) && (bytes[5] == 0x00) && (bytes[6] == 0x00) && (bytes[7] == 0x00) && (bytes[8] == 0x00) && (bytes[9] == 0x00) && (bytes[10] == (byte)0xff) && (bytes[11] == (byte)0xff)); } private MoreInetAddresses(); }
|
MoreInetAddresses { public static boolean isMappedIPv4Address(Inet6Address ip) { byte bytes[] = ip.getAddress(); return ((bytes[0] == 0x00) && (bytes[1] == 0x00) && (bytes[2] == 0x00) && (bytes[3] == 0x00) && (bytes[4] == 0x00) && (bytes[5] == 0x00) && (bytes[6] == 0x00) && (bytes[7] == 0x00) && (bytes[8] == 0x00) && (bytes[9] == 0x00) && (bytes[10] == (byte)0xff) && (bytes[11] == (byte)0xff)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static boolean isMappedIPv4Address(Inet6Address ip) { byte bytes[] = ip.getAddress(); return ((bytes[0] == 0x00) && (bytes[1] == 0x00) && (bytes[2] == 0x00) && (bytes[3] == 0x00) && (bytes[4] == 0x00) && (bytes[5] == 0x00) && (bytes[6] == 0x00) && (bytes[7] == 0x00) && (bytes[8] == 0x00) && (bytes[9] == 0x00) && (bytes[10] == (byte)0xff) && (bytes[11] == (byte)0xff)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test public void getMappedIPv4AddressTest() throws UnknownHostException { byte[] bytes = new byte[]{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, (byte) 0xff, (byte) 0xff, 0x1, 0x2, 0x3, 0x4 }; Inet6Address address = Inet6Address.getByAddress(null, bytes, -1); Inet4Address inet4Address = MoreInetAddresses.getMappedIPv4Address(address); assertEquals(InetAddress.getByAddress(bytes), inet4Address); }
|
public static Inet4Address getMappedIPv4Address(Inet6Address ip) { if (!isMappedIPv4Address(ip)) throw new IllegalArgumentException(String.format("Address '%s' is not IPv4-mapped.", toAddrString(ip))); return getInet4Address(copyOfRange(ip.getAddress(), 12, 16)); }
|
MoreInetAddresses { public static Inet4Address getMappedIPv4Address(Inet6Address ip) { if (!isMappedIPv4Address(ip)) throw new IllegalArgumentException(String.format("Address '%s' is not IPv4-mapped.", toAddrString(ip))); return getInet4Address(copyOfRange(ip.getAddress(), 12, 16)); } }
|
MoreInetAddresses { public static Inet4Address getMappedIPv4Address(Inet6Address ip) { if (!isMappedIPv4Address(ip)) throw new IllegalArgumentException(String.format("Address '%s' is not IPv4-mapped.", toAddrString(ip))); return getInet4Address(copyOfRange(ip.getAddress(), 12, 16)); } private MoreInetAddresses(); }
|
MoreInetAddresses { public static Inet4Address getMappedIPv4Address(Inet6Address ip) { if (!isMappedIPv4Address(ip)) throw new IllegalArgumentException(String.format("Address '%s' is not IPv4-mapped.", toAddrString(ip))); return getInet4Address(copyOfRange(ip.getAddress(), 12, 16)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static Inet4Address getMappedIPv4Address(Inet6Address ip) { if (!isMappedIPv4Address(ip)) throw new IllegalArgumentException(String.format("Address '%s' is not IPv4-mapped.", toAddrString(ip))); return getInet4Address(copyOfRange(ip.getAddress(), 12, 16)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test public void distinctTest() throws Exception { Iterable<Integer> distinct = distinct(asList(1, 1, 2, 2, 3, 3, 3, 4, 5, 6, 7, 7, 7)); assertEquals(asList(1, 2, 3, 4, 5, 6, 7), newArrayList(distinct)); }
|
public static <T> Iterable<T> distinct(final Iterable<T> iterable) { requireNonNull(iterable); return () -> Iterators2.distinct(iterable.iterator()); }
|
Iterables2 { public static <T> Iterable<T> distinct(final Iterable<T> iterable) { requireNonNull(iterable); return () -> Iterators2.distinct(iterable.iterator()); } }
|
Iterables2 { public static <T> Iterable<T> distinct(final Iterable<T> iterable) { requireNonNull(iterable); return () -> Iterators2.distinct(iterable.iterator()); } private Iterables2(); }
|
Iterables2 { public static <T> Iterable<T> distinct(final Iterable<T> iterable) { requireNonNull(iterable); return () -> Iterators2.distinct(iterable.iterator()); } private Iterables2(); static Iterable<T> simpleIterable(final Iterable<T> iterable); static Iterable<T> distinct(final Iterable<T> iterable); static Iterable<List<T>> groupBy(final Iterable<? extends T> iterable, final Function<? super T, ?> groupingFunction); }
|
Iterables2 { public static <T> Iterable<T> distinct(final Iterable<T> iterable) { requireNonNull(iterable); return () -> Iterators2.distinct(iterable.iterator()); } private Iterables2(); static Iterable<T> simpleIterable(final Iterable<T> iterable); static Iterable<T> distinct(final Iterable<T> iterable); static Iterable<List<T>> groupBy(final Iterable<? extends T> iterable, final Function<? super T, ?> groupingFunction); }
|
@Test(expected = NullPointerException.class) public void getMappedIPv4AddressNullTest() { MoreInetAddresses.getMappedIPv4Address(null); }
|
public static Inet4Address getMappedIPv4Address(Inet6Address ip) { if (!isMappedIPv4Address(ip)) throw new IllegalArgumentException(String.format("Address '%s' is not IPv4-mapped.", toAddrString(ip))); return getInet4Address(copyOfRange(ip.getAddress(), 12, 16)); }
|
MoreInetAddresses { public static Inet4Address getMappedIPv4Address(Inet6Address ip) { if (!isMappedIPv4Address(ip)) throw new IllegalArgumentException(String.format("Address '%s' is not IPv4-mapped.", toAddrString(ip))); return getInet4Address(copyOfRange(ip.getAddress(), 12, 16)); } }
|
MoreInetAddresses { public static Inet4Address getMappedIPv4Address(Inet6Address ip) { if (!isMappedIPv4Address(ip)) throw new IllegalArgumentException(String.format("Address '%s' is not IPv4-mapped.", toAddrString(ip))); return getInet4Address(copyOfRange(ip.getAddress(), 12, 16)); } private MoreInetAddresses(); }
|
MoreInetAddresses { public static Inet4Address getMappedIPv4Address(Inet6Address ip) { if (!isMappedIPv4Address(ip)) throw new IllegalArgumentException(String.format("Address '%s' is not IPv4-mapped.", toAddrString(ip))); return getInet4Address(copyOfRange(ip.getAddress(), 12, 16)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static Inet4Address getMappedIPv4Address(Inet6Address ip) { if (!isMappedIPv4Address(ip)) throw new IllegalArgumentException(String.format("Address '%s' is not IPv4-mapped.", toAddrString(ip))); return getInet4Address(copyOfRange(ip.getAddress(), 12, 16)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test(expected = IllegalArgumentException.class) public void getMappedIPv4AddressInvalidTypeTest() throws UnknownHostException { byte[] bytes = new byte[]{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x2, 0x3, 0x4 }; Inet6Address address = Inet6Address.getByAddress(null, bytes, -1); MoreInetAddresses.getMappedIPv4Address(address); }
|
public static Inet4Address getMappedIPv4Address(Inet6Address ip) { if (!isMappedIPv4Address(ip)) throw new IllegalArgumentException(String.format("Address '%s' is not IPv4-mapped.", toAddrString(ip))); return getInet4Address(copyOfRange(ip.getAddress(), 12, 16)); }
|
MoreInetAddresses { public static Inet4Address getMappedIPv4Address(Inet6Address ip) { if (!isMappedIPv4Address(ip)) throw new IllegalArgumentException(String.format("Address '%s' is not IPv4-mapped.", toAddrString(ip))); return getInet4Address(copyOfRange(ip.getAddress(), 12, 16)); } }
|
MoreInetAddresses { public static Inet4Address getMappedIPv4Address(Inet6Address ip) { if (!isMappedIPv4Address(ip)) throw new IllegalArgumentException(String.format("Address '%s' is not IPv4-mapped.", toAddrString(ip))); return getInet4Address(copyOfRange(ip.getAddress(), 12, 16)); } private MoreInetAddresses(); }
|
MoreInetAddresses { public static Inet4Address getMappedIPv4Address(Inet6Address ip) { if (!isMappedIPv4Address(ip)) throw new IllegalArgumentException(String.format("Address '%s' is not IPv4-mapped.", toAddrString(ip))); return getInet4Address(copyOfRange(ip.getAddress(), 12, 16)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static Inet4Address getMappedIPv4Address(Inet6Address ip) { if (!isMappedIPv4Address(ip)) throw new IllegalArgumentException(String.format("Address '%s' is not IPv4-mapped.", toAddrString(ip))); return getInet4Address(copyOfRange(ip.getAddress(), 12, 16)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test public void hasEmbeddedIPv4ClientAddressTest() { assertTrue(MoreInetAddresses.hasEmbeddedIPv4ClientAddress(forIPv6String("::ffff:1.2.3.4"))); assertTrue(MoreInetAddresses.hasEmbeddedIPv4ClientAddress(forIPv6String("::1.2.3.4"))); assertTrue(MoreInetAddresses.hasEmbeddedIPv4ClientAddress(forIPv6String("2002:102:304::"))); assertFalse(MoreInetAddresses.hasEmbeddedIPv4ClientAddress(forIPv6String("1::1.2.3.4"))); }
|
public static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip) { return isMappedIPv4Address(ip) || InetAddresses.hasEmbeddedIPv4ClientAddress(ip); }
|
MoreInetAddresses { public static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip) { return isMappedIPv4Address(ip) || InetAddresses.hasEmbeddedIPv4ClientAddress(ip); } }
|
MoreInetAddresses { public static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip) { return isMappedIPv4Address(ip) || InetAddresses.hasEmbeddedIPv4ClientAddress(ip); } private MoreInetAddresses(); }
|
MoreInetAddresses { public static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip) { return isMappedIPv4Address(ip) || InetAddresses.hasEmbeddedIPv4ClientAddress(ip); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip) { return isMappedIPv4Address(ip) || InetAddresses.hasEmbeddedIPv4ClientAddress(ip); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test(expected = NullPointerException.class) public void hasEmbeddedIPv4ClientAddressNullTest() { MoreInetAddresses.hasEmbeddedIPv4ClientAddress(null); }
|
public static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip) { return isMappedIPv4Address(ip) || InetAddresses.hasEmbeddedIPv4ClientAddress(ip); }
|
MoreInetAddresses { public static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip) { return isMappedIPv4Address(ip) || InetAddresses.hasEmbeddedIPv4ClientAddress(ip); } }
|
MoreInetAddresses { public static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip) { return isMappedIPv4Address(ip) || InetAddresses.hasEmbeddedIPv4ClientAddress(ip); } private MoreInetAddresses(); }
|
MoreInetAddresses { public static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip) { return isMappedIPv4Address(ip) || InetAddresses.hasEmbeddedIPv4ClientAddress(ip); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip) { return isMappedIPv4Address(ip) || InetAddresses.hasEmbeddedIPv4ClientAddress(ip); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test public void getEmbeddedIPv4ClientAddressTest() { assertEquals(MoreInetAddresses.forString("1.2.3.4"), MoreInetAddresses.getEmbeddedIPv4ClientAddress(forIPv6String("::ffff:1.2.3.4"))); assertEquals(MoreInetAddresses.forString("1.2.3.4"), MoreInetAddresses.getEmbeddedIPv4ClientAddress(forIPv6String("::1.2.3.4"))); assertEquals(MoreInetAddresses.forString("1.2.3.4"), MoreInetAddresses.getEmbeddedIPv4ClientAddress(forIPv6String("2002:102:304::"))); }
|
public static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip) { if (isMappedIPv4Address(ip)) return getMappedIPv4Address(ip); return InetAddresses.getEmbeddedIPv4ClientAddress(ip); }
|
MoreInetAddresses { public static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip) { if (isMappedIPv4Address(ip)) return getMappedIPv4Address(ip); return InetAddresses.getEmbeddedIPv4ClientAddress(ip); } }
|
MoreInetAddresses { public static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip) { if (isMappedIPv4Address(ip)) return getMappedIPv4Address(ip); return InetAddresses.getEmbeddedIPv4ClientAddress(ip); } private MoreInetAddresses(); }
|
MoreInetAddresses { public static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip) { if (isMappedIPv4Address(ip)) return getMappedIPv4Address(ip); return InetAddresses.getEmbeddedIPv4ClientAddress(ip); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip) { if (isMappedIPv4Address(ip)) return getMappedIPv4Address(ip); return InetAddresses.getEmbeddedIPv4ClientAddress(ip); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test(expected = NullPointerException.class) public void getEmbeddedIPv4ClientAddressNullTest() { MoreInetAddresses.getEmbeddedIPv4ClientAddress(null); }
|
public static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip) { if (isMappedIPv4Address(ip)) return getMappedIPv4Address(ip); return InetAddresses.getEmbeddedIPv4ClientAddress(ip); }
|
MoreInetAddresses { public static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip) { if (isMappedIPv4Address(ip)) return getMappedIPv4Address(ip); return InetAddresses.getEmbeddedIPv4ClientAddress(ip); } }
|
MoreInetAddresses { public static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip) { if (isMappedIPv4Address(ip)) return getMappedIPv4Address(ip); return InetAddresses.getEmbeddedIPv4ClientAddress(ip); } private MoreInetAddresses(); }
|
MoreInetAddresses { public static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip) { if (isMappedIPv4Address(ip)) return getMappedIPv4Address(ip); return InetAddresses.getEmbeddedIPv4ClientAddress(ip); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip) { if (isMappedIPv4Address(ip)) return getMappedIPv4Address(ip); return InetAddresses.getEmbeddedIPv4ClientAddress(ip); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test public void getIPv4MappedIPv6AddressTest() { assertEquals("::ffff:102:304", toAddrString(MoreInetAddresses.getIPv4MappedIPv6Address(forIPv4String("1.2.3.4")))); }
|
public static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip) { byte[] from = ip.getAddress(); byte[] bytes = new byte[] { 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,(byte)0xff,(byte)0xff, from[0],from[1],from[2],from[3] }; return getInet6Address(bytes); }
|
MoreInetAddresses { public static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip) { byte[] from = ip.getAddress(); byte[] bytes = new byte[] { 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,(byte)0xff,(byte)0xff, from[0],from[1],from[2],from[3] }; return getInet6Address(bytes); } }
|
MoreInetAddresses { public static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip) { byte[] from = ip.getAddress(); byte[] bytes = new byte[] { 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,(byte)0xff,(byte)0xff, from[0],from[1],from[2],from[3] }; return getInet6Address(bytes); } private MoreInetAddresses(); }
|
MoreInetAddresses { public static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip) { byte[] from = ip.getAddress(); byte[] bytes = new byte[] { 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,(byte)0xff,(byte)0xff, from[0],from[1],from[2],from[3] }; return getInet6Address(bytes); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip) { byte[] from = ip.getAddress(); byte[] bytes = new byte[] { 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,(byte)0xff,(byte)0xff, from[0],from[1],from[2],from[3] }; return getInet6Address(bytes); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test(expected = NullPointerException.class) public void getIPv4MappedIPv6AddressNullTest() { MoreInetAddresses.getIPv4MappedIPv6Address(null); }
|
public static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip) { byte[] from = ip.getAddress(); byte[] bytes = new byte[] { 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,(byte)0xff,(byte)0xff, from[0],from[1],from[2],from[3] }; return getInet6Address(bytes); }
|
MoreInetAddresses { public static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip) { byte[] from = ip.getAddress(); byte[] bytes = new byte[] { 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,(byte)0xff,(byte)0xff, from[0],from[1],from[2],from[3] }; return getInet6Address(bytes); } }
|
MoreInetAddresses { public static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip) { byte[] from = ip.getAddress(); byte[] bytes = new byte[] { 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,(byte)0xff,(byte)0xff, from[0],from[1],from[2],from[3] }; return getInet6Address(bytes); } private MoreInetAddresses(); }
|
MoreInetAddresses { public static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip) { byte[] from = ip.getAddress(); byte[] bytes = new byte[] { 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,(byte)0xff,(byte)0xff, from[0],from[1],from[2],from[3] }; return getInet6Address(bytes); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip) { byte[] from = ip.getAddress(); byte[] bytes = new byte[] { 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,(byte)0xff,(byte)0xff, from[0],from[1],from[2],from[3] }; return getInet6Address(bytes); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test public void getIPv4CompatIPv6AddressTest() { assertEquals("::102:304", toAddrString(MoreInetAddresses.getIPV4CompatIPv6Address(forIPv4String("1.2.3.4")))); }
|
public static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip) { byte[] from = ip.getAddress(); byte[] bytes = new byte[] { 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, from[0],from[1],from[2],from[3] }; return getInet6Address(bytes); }
|
MoreInetAddresses { public static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip) { byte[] from = ip.getAddress(); byte[] bytes = new byte[] { 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, from[0],from[1],from[2],from[3] }; return getInet6Address(bytes); } }
|
MoreInetAddresses { public static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip) { byte[] from = ip.getAddress(); byte[] bytes = new byte[] { 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, from[0],from[1],from[2],from[3] }; return getInet6Address(bytes); } private MoreInetAddresses(); }
|
MoreInetAddresses { public static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip) { byte[] from = ip.getAddress(); byte[] bytes = new byte[] { 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, from[0],from[1],from[2],from[3] }; return getInet6Address(bytes); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip) { byte[] from = ip.getAddress(); byte[] bytes = new byte[] { 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, from[0],from[1],from[2],from[3] }; return getInet6Address(bytes); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test(expected = NullPointerException.class) public void getIPv4CompatIPv6AddressNullTest() { MoreInetAddresses.getIPV4CompatIPv6Address(null); }
|
public static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip) { byte[] from = ip.getAddress(); byte[] bytes = new byte[] { 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, from[0],from[1],from[2],from[3] }; return getInet6Address(bytes); }
|
MoreInetAddresses { public static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip) { byte[] from = ip.getAddress(); byte[] bytes = new byte[] { 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, from[0],from[1],from[2],from[3] }; return getInet6Address(bytes); } }
|
MoreInetAddresses { public static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip) { byte[] from = ip.getAddress(); byte[] bytes = new byte[] { 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, from[0],from[1],from[2],from[3] }; return getInet6Address(bytes); } private MoreInetAddresses(); }
|
MoreInetAddresses { public static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip) { byte[] from = ip.getAddress(); byte[] bytes = new byte[] { 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, from[0],from[1],from[2],from[3] }; return getInet6Address(bytes); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip) { byte[] from = ip.getAddress(); byte[] bytes = new byte[] { 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, from[0],from[1],from[2],from[3] }; return getInet6Address(bytes); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test(expected = NullPointerException.class) public void distinctNullIteratorTest() { distinct(null); }
|
public static <T> Iterable<T> distinct(final Iterable<T> iterable) { requireNonNull(iterable); return () -> Iterators2.distinct(iterable.iterator()); }
|
Iterables2 { public static <T> Iterable<T> distinct(final Iterable<T> iterable) { requireNonNull(iterable); return () -> Iterators2.distinct(iterable.iterator()); } }
|
Iterables2 { public static <T> Iterable<T> distinct(final Iterable<T> iterable) { requireNonNull(iterable); return () -> Iterators2.distinct(iterable.iterator()); } private Iterables2(); }
|
Iterables2 { public static <T> Iterable<T> distinct(final Iterable<T> iterable) { requireNonNull(iterable); return () -> Iterators2.distinct(iterable.iterator()); } private Iterables2(); static Iterable<T> simpleIterable(final Iterable<T> iterable); static Iterable<T> distinct(final Iterable<T> iterable); static Iterable<List<T>> groupBy(final Iterable<? extends T> iterable, final Function<? super T, ?> groupingFunction); }
|
Iterables2 { public static <T> Iterable<T> distinct(final Iterable<T> iterable) { requireNonNull(iterable); return () -> Iterators2.distinct(iterable.iterator()); } private Iterables2(); static Iterable<T> simpleIterable(final Iterable<T> iterable); static Iterable<T> distinct(final Iterable<T> iterable); static Iterable<List<T>> groupBy(final Iterable<? extends T> iterable, final Function<? super T, ?> groupingFunction); }
|
@Test public void forCIDRStringTest() { MoreInetAddresses.CidrInfo cidr = MoreInetAddresses.parseCIDR("255.255.255.255/16"); assertTrue(cidr.getNetwork() instanceof Inet4Address); assertEquals("255.255.0.0", toAddrString(cidr.getNetwork())); assertEquals("255.255.255.255", toAddrString(cidr.getBroadcast())); cidr = MoreInetAddresses.parseCIDR("0.0.0.0/16"); assertTrue(cidr.getNetwork() instanceof Inet4Address); assertEquals("0.0.0.0", toAddrString(cidr.getNetwork())); assertEquals("0.0.255.255", toAddrString(cidr.getBroadcast())); cidr = MoreInetAddresses.parseCIDR("255.255.255.255/20"); assertTrue(cidr.getNetwork() instanceof Inet4Address); assertEquals("255.255.240.0", toAddrString(cidr.getNetwork())); assertEquals("255.255.255.255", toAddrString(cidr.getBroadcast())); cidr = MoreInetAddresses.parseCIDR("0.0.0.0/20"); assertTrue(cidr.getNetwork() instanceof Inet4Address); assertEquals("0.0.0.0", toAddrString(cidr.getNetwork())); assertEquals("0.0.15.255", toAddrString(cidr.getBroadcast())); cidr = MoreInetAddresses.parseCIDR("123.45.67.0/21"); assertTrue(cidr.getNetwork() instanceof Inet4Address); assertEquals("123.45.64.0", toAddrString(cidr.getNetwork())); assertEquals("123.45.71.255", toAddrString(cidr.getBroadcast())); cidr = MoreInetAddresses.parseCIDR("1.2.3.4/32"); assertTrue(cidr.getNetwork() instanceof Inet4Address); assertEquals("1.2.3.4", toAddrString(cidr.getNetwork())); assertEquals("1.2.3.4", toAddrString(cidr.getBroadcast())); cidr = MoreInetAddresses.parseCIDR("1.2.3.4/0"); assertTrue(cidr.getNetwork() instanceof Inet4Address); assertEquals("0.0.0.0", toAddrString(cidr.getNetwork())); assertEquals("255.255.255.255", toAddrString(cidr.getBroadcast())); cidr = MoreInetAddresses.parseCIDR("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/64"); assertTrue(cidr.getNetwork() instanceof Inet6Address); assertEquals("ffff:ffff:ffff:ffff::", toAddrString(cidr.getNetwork())); assertEquals("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", toAddrString(cidr.getBroadcast())); cidr = MoreInetAddresses.parseCIDR("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/68"); assertTrue(cidr.getNetwork() instanceof Inet6Address); assertEquals("ffff:ffff:ffff:ffff:f000::", toAddrString(cidr.getNetwork())); assertEquals("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", toAddrString(cidr.getBroadcast())); cidr = MoreInetAddresses.parseCIDR("::/64"); assertTrue(cidr.getNetwork() instanceof Inet6Address); assertEquals("::", toAddrString(cidr.getNetwork())); assertEquals("::ffff:ffff:ffff:ffff", toAddrString(cidr.getBroadcast())); cidr = MoreInetAddresses.parseCIDR("::/68"); assertTrue(cidr.getNetwork() instanceof Inet6Address); assertEquals("::", toAddrString(cidr.getNetwork())); assertEquals("::fff:ffff:ffff:ffff", toAddrString(cidr.getBroadcast())); cidr = MoreInetAddresses.parseCIDR("1:2:3:4:5:6:7:8/128"); assertTrue(cidr.getNetwork() instanceof Inet6Address); assertEquals("1:2:3:4:5:6:7:8", toAddrString(cidr.getNetwork())); assertEquals("1:2:3:4:5:6:7:8", toAddrString(cidr.getBroadcast())); cidr = MoreInetAddresses.parseCIDR("1:2:3:4:5:6:7:8/0"); assertTrue(cidr.getNetwork() instanceof Inet6Address); assertEquals("::", toAddrString(cidr.getNetwork())); assertEquals("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", toAddrString(cidr.getBroadcast())); cidr = MoreInetAddresses.parseCIDR("::ffff:1.2.3.4/112"); assertTrue(cidr.getNetwork() instanceof Inet6Address); assertEquals("::ffff:102:0", toAddrString(cidr.getNetwork())); assertEquals("::ffff:102:ffff", toAddrString(cidr.getBroadcast())); }
|
public static CidrInfo parseCIDR(String cidr) { requireNonNull(cidr); try { String[] parts = cidr.split("/"); checkArgument(parts.length == 2); byte[] bytes = forString(parts[0]).getAddress(); int maskBits = parseInt(parts[1]); checkArgument(maskBits >= 0 && maskBits <= bytes.length * 8); int remainingBits = maskBits; byte[] network = new byte[bytes.length]; byte[] broadcast = new byte[bytes.length]; for (int i = 0; i< bytes.length; i++) { if (remainingBits >= 8) { network[i] = bytes[i]; broadcast[i] = bytes[i]; } else if (remainingBits > 0) { int byteMask = -1 << (8 - remainingBits); network [i] = (byte) (bytes[i] & byteMask); broadcast [i] = (byte) (bytes[i] | ~byteMask); } else { network[i] = 0; broadcast[i] = (byte)0xff; } remainingBits -= 8; } return new CidrInfo(maskBits, bytesToInetAddress(network), bytesToInetAddress(broadcast)); }catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid CIDR string: %s", cidr)); }
|
MoreInetAddresses { public static CidrInfo parseCIDR(String cidr) { requireNonNull(cidr); try { String[] parts = cidr.split("/"); checkArgument(parts.length == 2); byte[] bytes = forString(parts[0]).getAddress(); int maskBits = parseInt(parts[1]); checkArgument(maskBits >= 0 && maskBits <= bytes.length * 8); int remainingBits = maskBits; byte[] network = new byte[bytes.length]; byte[] broadcast = new byte[bytes.length]; for (int i = 0; i< bytes.length; i++) { if (remainingBits >= 8) { network[i] = bytes[i]; broadcast[i] = bytes[i]; } else if (remainingBits > 0) { int byteMask = -1 << (8 - remainingBits); network [i] = (byte) (bytes[i] & byteMask); broadcast [i] = (byte) (bytes[i] | ~byteMask); } else { network[i] = 0; broadcast[i] = (byte)0xff; } remainingBits -= 8; } return new CidrInfo(maskBits, bytesToInetAddress(network), bytesToInetAddress(broadcast)); }catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid CIDR string: %s", cidr)); } }
|
MoreInetAddresses { public static CidrInfo parseCIDR(String cidr) { requireNonNull(cidr); try { String[] parts = cidr.split("/"); checkArgument(parts.length == 2); byte[] bytes = forString(parts[0]).getAddress(); int maskBits = parseInt(parts[1]); checkArgument(maskBits >= 0 && maskBits <= bytes.length * 8); int remainingBits = maskBits; byte[] network = new byte[bytes.length]; byte[] broadcast = new byte[bytes.length]; for (int i = 0; i< bytes.length; i++) { if (remainingBits >= 8) { network[i] = bytes[i]; broadcast[i] = bytes[i]; } else if (remainingBits > 0) { int byteMask = -1 << (8 - remainingBits); network [i] = (byte) (bytes[i] & byteMask); broadcast [i] = (byte) (bytes[i] | ~byteMask); } else { network[i] = 0; broadcast[i] = (byte)0xff; } remainingBits -= 8; } return new CidrInfo(maskBits, bytesToInetAddress(network), bytesToInetAddress(broadcast)); }catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid CIDR string: %s", cidr)); } private MoreInetAddresses(); }
|
MoreInetAddresses { public static CidrInfo parseCIDR(String cidr) { requireNonNull(cidr); try { String[] parts = cidr.split("/"); checkArgument(parts.length == 2); byte[] bytes = forString(parts[0]).getAddress(); int maskBits = parseInt(parts[1]); checkArgument(maskBits >= 0 && maskBits <= bytes.length * 8); int remainingBits = maskBits; byte[] network = new byte[bytes.length]; byte[] broadcast = new byte[bytes.length]; for (int i = 0; i< bytes.length; i++) { if (remainingBits >= 8) { network[i] = bytes[i]; broadcast[i] = bytes[i]; } else if (remainingBits > 0) { int byteMask = -1 << (8 - remainingBits); network [i] = (byte) (bytes[i] & byteMask); broadcast [i] = (byte) (bytes[i] | ~byteMask); } else { network[i] = 0; broadcast[i] = (byte)0xff; } remainingBits -= 8; } return new CidrInfo(maskBits, bytesToInetAddress(network), bytesToInetAddress(broadcast)); }catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid CIDR string: %s", cidr)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
MoreInetAddresses { public static CidrInfo parseCIDR(String cidr) { requireNonNull(cidr); try { String[] parts = cidr.split("/"); checkArgument(parts.length == 2); byte[] bytes = forString(parts[0]).getAddress(); int maskBits = parseInt(parts[1]); checkArgument(maskBits >= 0 && maskBits <= bytes.length * 8); int remainingBits = maskBits; byte[] network = new byte[bytes.length]; byte[] broadcast = new byte[bytes.length]; for (int i = 0; i< bytes.length; i++) { if (remainingBits >= 8) { network[i] = bytes[i]; broadcast[i] = bytes[i]; } else if (remainingBits > 0) { int byteMask = -1 << (8 - remainingBits); network [i] = (byte) (bytes[i] & byteMask); broadcast [i] = (byte) (bytes[i] | ~byteMask); } else { network[i] = 0; broadcast[i] = (byte)0xff; } remainingBits -= 8; } return new CidrInfo(maskBits, bytesToInetAddress(network), bytesToInetAddress(broadcast)); }catch(Exception ignored){} throw new IllegalArgumentException(format("Invalid CIDR string: %s", cidr)); } private MoreInetAddresses(); static InetAddress forString(String ipString); static Inet4Address forIPv4String(String ipString); static Inet6Address forIPv6String(String ipString); static boolean isMappedIPv4Address(Inet6Address ip); static Inet4Address getMappedIPv4Address(Inet6Address ip); static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip); static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip); static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip); static Inet4Address increment(Inet4Address ip); static Inet6Address increment(Inet6Address ip); static Inet4Address decrement(Inet4Address ip); static Inet6Address decrement(Inet6Address ip); static CidrInfo parseCIDR(String cidr); }
|
@Test public void ipv4ToStringTest() { IPv4 ip = new IPv4(forIPv4String("1.2.3.4")); assertEquals("1.2.3.4", ip.toString()); }
|
@Override public String toString() { return toAddrString(address); }
|
IP implements Serializable { @Override public String toString() { return toAddrString(address); } }
|
IP implements Serializable { @Override public String toString() { return toAddrString(address); } protected IP(T address); }
|
IP implements Serializable { @Override public String toString() { return toAddrString(address); } protected IP(T address); @SuppressWarnings("unchecked") T getAddress(); byte[] toByteArray(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); }
|
IP implements Serializable { @Override public String toString() { return toAddrString(address); } protected IP(T address); @SuppressWarnings("unchecked") T getAddress(); byte[] toByteArray(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); }
|
@Test public void ipv6ToStringTest() { IPv6 ip = new IPv6(forIPv6String("::1.2.3.4")); assertEquals("::102:304", ip.toString()); ip = new IPv6(forIPv6String("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")); assertEquals("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", ip.toString()); ip = new IPv6(forIPv6String("1234:0000:0000:0000:0000:0000:0000:1234")); assertEquals("1234::1234", ip.toString()); }
|
@Override public String toString() { return toAddrString(address); }
|
IP implements Serializable { @Override public String toString() { return toAddrString(address); } }
|
IP implements Serializable { @Override public String toString() { return toAddrString(address); } protected IP(T address); }
|
IP implements Serializable { @Override public String toString() { return toAddrString(address); } protected IP(T address); @SuppressWarnings("unchecked") T getAddress(); byte[] toByteArray(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); }
|
IP implements Serializable { @Override public String toString() { return toAddrString(address); } protected IP(T address); @SuppressWarnings("unchecked") T getAddress(); byte[] toByteArray(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); }
|
@Test public void testEq() throws Exception { Node build = QueryBuilder.create().eq("feedName", "netflowv9").build(); StringWriter writer = new StringWriter(); build.accept(new PrintNodeVisitor(writer)); assertEquals("AndNode(Equals[feedName,netflowv9],),", writer.toString()); }
|
public QueryBuilder eq(String type, Object value) { checkFinished(); if (this.current == null) { this.current = new AndNode(); finished = true; } EqualsLeaf equalsLeaf = new EqualsLeaf<>(type, value, current); this.current.addChild(equalsLeaf); return this; }
|
QueryBuilder { public QueryBuilder eq(String type, Object value) { checkFinished(); if (this.current == null) { this.current = new AndNode(); finished = true; } EqualsLeaf equalsLeaf = new EqualsLeaf<>(type, value, current); this.current.addChild(equalsLeaf); return this; } }
|
QueryBuilder { public QueryBuilder eq(String type, Object value) { checkFinished(); if (this.current == null) { this.current = new AndNode(); finished = true; } EqualsLeaf equalsLeaf = new EqualsLeaf<>(type, value, current); this.current.addChild(equalsLeaf); return this; } protected QueryBuilder(); protected QueryBuilder(ParentNode current, QueryBuilder parentBuilder); }
|
QueryBuilder { public QueryBuilder eq(String type, Object value) { checkFinished(); if (this.current == null) { this.current = new AndNode(); finished = true; } EqualsLeaf equalsLeaf = new EqualsLeaf<>(type, value, current); this.current.addChild(equalsLeaf); return this; } protected QueryBuilder(); protected QueryBuilder(ParentNode current, QueryBuilder parentBuilder); static QueryBuilder create(); QueryBuilder and(); QueryBuilder or(); Node build(); QueryBuilder eq(String type, Object value); QueryBuilder has(String key); QueryBuilder hasNot(String key); QueryBuilder in(String key, Collection<Object> values); QueryBuilder in(String key, Object... values); QueryBuilder notIn(String key, Collection<Object> values); QueryBuilder notIn(String key, Object... values); QueryBuilder notEq(String type, Object value); QueryBuilder lessThan(String type, Object value); QueryBuilder lessThanEq(String type, Object value); QueryBuilder greaterThan(String type, Object value); QueryBuilder greaterThanEq(String type, Object value); QueryBuilder range(String type, Object start, Object end); QueryBuilder end(); }
|
QueryBuilder { public QueryBuilder eq(String type, Object value) { checkFinished(); if (this.current == null) { this.current = new AndNode(); finished = true; } EqualsLeaf equalsLeaf = new EqualsLeaf<>(type, value, current); this.current.addChild(equalsLeaf); return this; } protected QueryBuilder(); protected QueryBuilder(ParentNode current, QueryBuilder parentBuilder); static QueryBuilder create(); QueryBuilder and(); QueryBuilder or(); Node build(); QueryBuilder eq(String type, Object value); QueryBuilder has(String key); QueryBuilder hasNot(String key); QueryBuilder in(String key, Collection<Object> values); QueryBuilder in(String key, Object... values); QueryBuilder notIn(String key, Collection<Object> values); QueryBuilder notIn(String key, Object... values); QueryBuilder notEq(String type, Object value); QueryBuilder lessThan(String type, Object value); QueryBuilder lessThanEq(String type, Object value); QueryBuilder greaterThan(String type, Object value); QueryBuilder greaterThanEq(String type, Object value); QueryBuilder range(String type, Object start, Object end); QueryBuilder end(); }
|
@Test public void testCollapseAndAndChildren() throws Exception { StringWriter writer = new StringWriter(); Node node = QueryBuilder.create().and().and().eq("k1", "v1").eq("k2", "v2").end().end().build(); node.accept(new PrintNodeVisitor(writer)); writer.append('\n'); node.accept(new CollapseParentClauseVisitor()); node.accept(new PrintNodeVisitor(writer)); writer.append('\n'); }
|
@Override public void end(ParentNode node) { }
|
CollapseParentClauseVisitor implements NodeVisitor { @Override public void end(ParentNode node) { } }
|
CollapseParentClauseVisitor implements NodeVisitor { @Override public void end(ParentNode node) { } }
|
CollapseParentClauseVisitor implements NodeVisitor { @Override public void end(ParentNode node) { } @Override void begin(ParentNode node); @Override void end(ParentNode node); @Override void visit(Leaf node); }
|
CollapseParentClauseVisitor implements NodeVisitor { @Override public void end(ParentNode node) { } @Override void begin(ParentNode node); @Override void end(ParentNode node); @Override void visit(Leaf node); }
|
@Test public void testCollapseAndAndOrChildren() throws Exception { StringWriter writer = new StringWriter(); Node node = QueryBuilder.create().and().and().eq("k1", "v1").eq("k2", "v2").end().or().eq("k3", "v3").eq("k4", "v4").end().end().build(); node.accept(new PrintNodeVisitor(writer)); writer.append('\n'); node.accept(new CollapseParentClauseVisitor()); node.accept(new PrintNodeVisitor(writer)); writer.append('\n'); }
|
@Override public void end(ParentNode node) { }
|
CollapseParentClauseVisitor implements NodeVisitor { @Override public void end(ParentNode node) { } }
|
CollapseParentClauseVisitor implements NodeVisitor { @Override public void end(ParentNode node) { } }
|
CollapseParentClauseVisitor implements NodeVisitor { @Override public void end(ParentNode node) { } @Override void begin(ParentNode node); @Override void end(ParentNode node); @Override void visit(Leaf node); }
|
CollapseParentClauseVisitor implements NodeVisitor { @Override public void end(ParentNode node) { } @Override void begin(ParentNode node); @Override void end(ParentNode node); @Override void visit(Leaf node); }
|
@Test public void test() { LessThanEqualsCriteria criteria = new LessThanEqualsCriteria<>("key1", 5, naturalOrder(), null); EntityBuilder entity = EntityBuilder.create("type", "id"); assertFalse(criteria.test(entity.build())); entity = entity.attr("key1", 10); assertFalse(criteria.test(entity.build())); entity = entity.attr("key1", 5); assertTrue(criteria.test(entity.build())); entity = entity.attr("key1", 4); assertTrue(criteria.test(entity.build())); }
|
@Override public boolean test(AttributeStore obj) { for (Attribute attribute : obj.getAttributes(getTerm())) { if (getComparator().compare((T)(attribute.getValue()), getValue()) <= 0) return true; } return false; }
|
LessThanEqualsCriteria extends ComparableTermValueCriteria<T> { @Override public boolean test(AttributeStore obj) { for (Attribute attribute : obj.getAttributes(getTerm())) { if (getComparator().compare((T)(attribute.getValue()), getValue()) <= 0) return true; } return false; } }
|
LessThanEqualsCriteria extends ComparableTermValueCriteria<T> { @Override public boolean test(AttributeStore obj) { for (Attribute attribute : obj.getAttributes(getTerm())) { if (getComparator().compare((T)(attribute.getValue()), getValue()) <= 0) return true; } return false; } LessThanEqualsCriteria(String term, T value, Comparator<T> comparator, ParentCriteria parentCriteria); }
|
LessThanEqualsCriteria extends ComparableTermValueCriteria<T> { @Override public boolean test(AttributeStore obj) { for (Attribute attribute : obj.getAttributes(getTerm())) { if (getComparator().compare((T)(attribute.getValue()), getValue()) <= 0) return true; } return false; } LessThanEqualsCriteria(String term, T value, Comparator<T> comparator, ParentCriteria parentCriteria); @Override boolean test(AttributeStore obj); @Override Criteria clone(ParentCriteria parentCriteria); @Override String toString(); }
|
LessThanEqualsCriteria extends ComparableTermValueCriteria<T> { @Override public boolean test(AttributeStore obj) { for (Attribute attribute : obj.getAttributes(getTerm())) { if (getComparator().compare((T)(attribute.getValue()), getValue()) <= 0) return true; } return false; } LessThanEqualsCriteria(String term, T value, Comparator<T> comparator, ParentCriteria parentCriteria); @Override boolean test(AttributeStore obj); @Override Criteria clone(ParentCriteria parentCriteria); @Override String toString(); }
|
@Test public void testEquals() { Criteria eq = new EqualsCriteria<>("key1", "val1", naturalOrder(), null); EntityBuilder entity = EntityBuilder.create("type", "id") .attr("key1", "val1"); assertTrue(eq.test(entity.build())); }
|
@Override public boolean test(AttributeStore obj) { for (Attribute attribute : obj.getAttributes(getTerm())) { if (getComparator().compare((T)(attribute.getValue()), getValue()) == 0) return true; } return false; }
|
EqualsCriteria extends ComparableTermValueCriteria<T> { @Override public boolean test(AttributeStore obj) { for (Attribute attribute : obj.getAttributes(getTerm())) { if (getComparator().compare((T)(attribute.getValue()), getValue()) == 0) return true; } return false; } }
|
EqualsCriteria extends ComparableTermValueCriteria<T> { @Override public boolean test(AttributeStore obj) { for (Attribute attribute : obj.getAttributes(getTerm())) { if (getComparator().compare((T)(attribute.getValue()), getValue()) == 0) return true; } return false; } EqualsCriteria(String term, T value, Comparator<T> comparator, ParentCriteria parentCriteria); }
|
EqualsCriteria extends ComparableTermValueCriteria<T> { @Override public boolean test(AttributeStore obj) { for (Attribute attribute : obj.getAttributes(getTerm())) { if (getComparator().compare((T)(attribute.getValue()), getValue()) == 0) return true; } return false; } EqualsCriteria(String term, T value, Comparator<T> comparator, ParentCriteria parentCriteria); @Override boolean test(AttributeStore obj); @Override Criteria clone(ParentCriteria parentCriteria); @Override String toString(); }
|
EqualsCriteria extends ComparableTermValueCriteria<T> { @Override public boolean test(AttributeStore obj) { for (Attribute attribute : obj.getAttributes(getTerm())) { if (getComparator().compare((T)(attribute.getValue()), getValue()) == 0) return true; } return false; } EqualsCriteria(String term, T value, Comparator<T> comparator, ParentCriteria parentCriteria); @Override boolean test(AttributeStore obj); @Override Criteria clone(ParentCriteria parentCriteria); @Override String toString(); }
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.