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 testLessSimpleProgram(){ List<Token> tList=new LinkedList<>(); tList.add(new TokenJb(TokenType.LONG_SYMBOL, "long")); tList.add(new TokenJb(TokenType.ID, "i")); tList.add(new TokenJb(TokenType.SEMICOLON,";")); tList.add(new TokenJb(TokenType.ID, "i")); tList.add(new TokenJb(TokenType.ASSIGNOP, "=")); tList.add(new RealTokenJb(TokenType.REAL,"2.0")); tList.add(new TokenJb(TokenType.DIVIDE,"/")); tList.add(new NumTokenJb(TokenType.NUM,"2")); tList.add(new TokenJb(TokenType.SEMICOLON,";")); TargetGrammar.SourceCode sc = syn.new SourceCode(tList); List<Reduction> res= syn.derivateDFLeftToRight(sc); instance=new ASTGenerator(res); AST ast=instance.generateAST(); }
public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; }
ASTGenerator { public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; } }
ASTGenerator { public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; } ASTGenerator(List<TargetGrammar.Reduction> reductions); }
ASTGenerator { public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; } ASTGenerator(List<TargetGrammar.Reduction> reductions); ASTJb generateAST(); }
ASTGenerator { public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; } ASTGenerator(List<TargetGrammar.Reduction> reductions); ASTJb generateAST(); }
@Test public void testComplexProgram(){ List<Token> tList = new LinkedList<>(); tList.add(new TokenJb(TokenType.LONG_SYMBOL, "long")); tList.add(new TokenJb(TokenType.ID, "i")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); tList.add(new TokenJb(TokenType.LONG_SYMBOL, "long")); tList.add(new TokenJb(TokenType.ID, "j")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); tList.add(new TokenJb(TokenType.ID, "i")); tList.add(new TokenJb(TokenType.ASSIGNOP, "=")); tList.add(new TokenJb(TokenType.LEFT_PARAN, "(")); tList.add(new NumTokenJb(TokenType.NUM, "2")); tList.add(new TokenJb(TokenType.PLUS, "+")); tList.add(new NumTokenJb(TokenType.NUM, "2")); tList.add(new TokenJb(TokenType.RIGHT_PARAN, ")")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); tList.add(new TokenJb(TokenType.ID, "j")); tList.add(new TokenJb(TokenType.ASSIGNOP, "=")); tList.add(new NumTokenJb(TokenType.NUM, "2")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); tList.add(new TokenJb(TokenType.RETURN, "return")); tList.add(new TokenJb(TokenType.ID, "j")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); TargetGrammar.SourceCode sc = syn.new SourceCode(tList); List<Reduction> res= syn.derivateDFLeftToRight(sc); instance=new ASTGenerator(res); AST ast=instance.generateAST(); }
public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; }
ASTGenerator { public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; } }
ASTGenerator { public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; } ASTGenerator(List<TargetGrammar.Reduction> reductions); }
ASTGenerator { public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; } ASTGenerator(List<TargetGrammar.Reduction> reductions); ASTJb generateAST(); }
ASTGenerator { public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; } ASTGenerator(List<TargetGrammar.Reduction> reductions); ASTJb generateAST(); }
@Test public void testComplexProgramSymbolTable(){ List<Token> tList = new LinkedList<>(); tList.add(new TokenJb(TokenType.LONG_SYMBOL, "long")); tList.add(new TokenJb(TokenType.ID, "i")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); tList.add(new TokenJb(TokenType.LONG_SYMBOL, "long")); tList.add(new TokenJb(TokenType.ID, "j")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); tList.add(new TokenJb(TokenType.ID, "i")); tList.add(new TokenJb(TokenType.ASSIGNOP, "=")); tList.add(new TokenJb(TokenType.LEFT_PARAN, "(")); tList.add(new NumTokenJb(TokenType.NUM, "2")); tList.add(new TokenJb(TokenType.PLUS, "+")); tList.add(new NumTokenJb(TokenType.NUM, "2")); tList.add(new TokenJb(TokenType.RIGHT_PARAN, ")")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); tList.add(new TokenJb(TokenType.ID, "j")); tList.add(new TokenJb(TokenType.ASSIGNOP, "=")); tList.add(new NumTokenJb(TokenType.NUM, "2")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); tList.add(new TokenJb(TokenType.RETURN, "return")); tList.add(new TokenJb(TokenType.ID, "j")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); TargetGrammar.SourceCode sc = syn.new SourceCode(tList); List<Reduction> res= syn.derivateDFLeftToRight(sc); instance=new ASTGenerator(res); AST ast=instance.generateAST(); SymbolTable table=ast.getRootNode().getSymbolTable(); assertTrue("should be declared",table.isDeclared("i")); assertTrue("should be declared",table.isDeclared("j")); assertFalse("should be not declared",table.isDeclared("ij")); assertEquals("should be the same",Kind.LONG,table.lookupType("i").getKind()); assertEquals("should be the same",Kind.LONG,table.lookupType("j").getKind()); assertNull("should not exist",table.lookupType("ij")); BlockNode root=ast.getRootNode(); assertEquals(21,root.coverage().size()); assertEquals(3,root.getDeclarationList().get(0).coverage().size()); assertEquals(8,root.getStatementList().get(0).coverage().size()); }
public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; }
ASTGenerator { public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; } }
ASTGenerator { public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; } ASTGenerator(List<TargetGrammar.Reduction> reductions); }
ASTGenerator { public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; } ASTGenerator(List<TargetGrammar.Reduction> reductions); ASTJb generateAST(); }
ASTGenerator { public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; } ASTGenerator(List<TargetGrammar.Reduction> reductions); ASTJb generateAST(); }
@Test public void testM2AddProgram() { List<Token> tList = new LinkedList<>(); tList.add(new TokenJb(TokenType.COMMENT, "returns 10")); tList.add(new TokenJb(TokenType.COMMENT, "prints nothing")); tList.add(new TokenJb(TokenType.LONG_SYMBOL, "long")); tList.add(new TokenJb(TokenType.ID, "a")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); tList.add(new TokenJb(TokenType.LONG_SYMBOL, "long")); tList.add(new TokenJb(TokenType.ID, "b")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); tList.add(new TokenJb(TokenType.LONG_SYMBOL, "long")); tList.add(new TokenJb(TokenType.ID, "c")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); tList.add(new TokenJb(TokenType.ID, "a")); tList.add(new TokenJb(TokenType.ASSIGNOP, "=")); tList.add(new NumTokenJb(TokenType.NUM, "4")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); tList.add(new TokenJb(TokenType.ID, "b")); tList.add(new TokenJb(TokenType.ASSIGNOP, "=")); tList.add(new NumTokenJb(TokenType.NUM, "3")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); tList.add(new TokenJb(TokenType.ID, "c")); tList.add(new TokenJb(TokenType.ASSIGNOP, "=")); tList.add(new NumTokenJb(TokenType.NUM, "2")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); tList.add(new TokenJb(TokenType.ID, "a")); tList.add(new TokenJb(TokenType.ASSIGNOP, "=")); tList.add(new TokenJb(TokenType.ID,"b")); tList.add(new TokenJb(TokenType.ASSIGNOP, "=")); tList.add(new NumTokenJb(TokenType.NUM, "4")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); tList.add(new TokenJb(TokenType.ID, "c")); tList.add(new TokenJb(TokenType.ASSIGNOP, "=")); tList.add(new TokenJb(TokenType.ID,"a")); tList.add(new TokenJb(TokenType.PLUS, "+")); tList.add(new TokenJb(TokenType.ID,"b")); tList.add(new TokenJb(TokenType.PLUS, "+")); tList.add(new TokenJb(TokenType.ID,"c")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); tList.add(new TokenJb(TokenType.RETURN,"return")); tList.add(new TokenJb(TokenType.ID,"c")); tList.add(new TokenJb(TokenType.SEMICOLON,";")); TargetGrammar.SourceCode sc = syn.new SourceCode(tList); List<Reduction> res = syn.derivateDFLeftToRight(sc); ASTGenerator astgen=new ASTGenerator(res); ASTJb ast=astgen.generateAST(); }
public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; }
ASTGenerator { public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; } }
ASTGenerator { public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; } ASTGenerator(List<TargetGrammar.Reduction> reductions); }
ASTGenerator { public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; } ASTGenerator(List<TargetGrammar.Reduction> reductions); ASTJb generateAST(); }
ASTGenerator { public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; } ASTGenerator(List<TargetGrammar.Reduction> reductions); ASTJb generateAST(); }
@Test(expected=WordNotInLanguageGrammarException.class) public void testM2CondProgram() { List<Token> tList = new LinkedList<>(); tList.add(new TokenJb(TokenType.COMMENT, "returns 5")); tList.add(new TokenJb(TokenType.COMMENT, "prints nothing")); tList.add(new TokenJb(TokenType.BOOL_SYMBOL, "bool")); tList.add(new TokenJb(TokenType.ID, "b")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); tList.add(new TokenJb(TokenType.BOOL_SYMBOL, "bool")); tList.add(new TokenJb(TokenType.ID, "c")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); tList.add(new TokenJb(TokenType.LONG_SYMBOL, "long")); tList.add(new TokenJb(TokenType.ID, "l")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); tList.add(new TokenJb(TokenType.ID, "b")); tList.add(new TokenJb(TokenType.ASSIGNOP, "=")); tList.add(new TokenJb(TokenType.TRUE, "true")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); tList.add(new TokenJb(TokenType.ID, "c")); tList.add(new TokenJb(TokenType.ASSIGNOP, "=")); tList.add(new TokenJb(TokenType.FALSE, "false")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); tList.add(new TokenJb(TokenType.ID, "c")); tList.add(new TokenJb(TokenType.ASSIGNOP, "=")); tList.add(new NumTokenJb(TokenType.NUM, "4")); tList.add(new TokenJb(TokenType.SEMICOLON, ";")); tList.add(new TokenJb(IF,"if")); tList.add(new TokenJb(LEFT_PARAN,"(")); tList.add(new TokenJb(ID,"b")); tList.add(new TokenJb(RIGHT_PARAN,")")); tList.add(new TokenJb(IF,"if")); tList.add(new TokenJb(LEFT_PARAN,"(")); tList.add(new TokenJb(ID,"c")); tList.add(new TokenJb(OR,"||")); tList.add(new TokenJb(NOT,"!")); tList.add(new TokenJb(ID,"b")); tList.add(new TokenJb(RIGHT_PARAN,")")); tList.add(new TokenJb(PRINT,"print")); tList.add(new TokenJb(STRING,"\"bla\"")); tList.add(new TokenJb(SEMICOLON,";")); tList.add(new TokenJb(ELSE,"else")); tList.add(new TokenJb(ID ,"l")); tList.add(new TokenJb(ASSIGNOP,"5")); tList.add(new NumTokenJb(NUM,"5")); tList.add(new TokenJb(TokenType.RETURN,"return")); tList.add(new TokenJb(TokenType.ID,"l")); tList.add(new TokenJb(TokenType.SEMICOLON,";")); TargetGrammar.SourceCode sc = syn.new SourceCode(tList); List<Reduction> res = syn.derivateDFLeftToRight(sc); ASTGenerator astgen=new ASTGenerator(res); ASTJb ast=astgen.generateAST(); }
public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; }
ASTGenerator { public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; } }
ASTGenerator { public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; } ASTGenerator(List<TargetGrammar.Reduction> reductions); }
ASTGenerator { public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; } ASTGenerator(List<TargetGrammar.Reduction> reductions); ASTJb generateAST(); }
ASTGenerator { public ASTJb generateAST() { ASTJb ast = new ASTJb(); BlockNode rootNode = this.useBlockProduction(); ast.setRootNode(rootNode); return ast; } ASTGenerator(List<TargetGrammar.Reduction> reductions); ASTJb generateAST(); }
@Test public void testWriteToString() { final String htmlReport = reportWriter.write(report); Assert.assertTrue(true); }
@Override public String write(Report report) { try (final StringWriter writer = new StringWriter()) { reportTemplate.process(report, writer); return writer.toString(); } catch (TemplateException e) { throw new RuntimeException("Error populating default report HTML template '"+ reportTemplate.getName() +"': " + e.getMessage(), e); } catch (IOException e) { throw new RuntimeException("Error writing HTML template to string: " + e.getMessage(), e); } }
HtmlReportWriter implements ReportWriter { @Override public String write(Report report) { try (final StringWriter writer = new StringWriter()) { reportTemplate.process(report, writer); return writer.toString(); } catch (TemplateException e) { throw new RuntimeException("Error populating default report HTML template '"+ reportTemplate.getName() +"': " + e.getMessage(), e); } catch (IOException e) { throw new RuntimeException("Error writing HTML template to string: " + e.getMessage(), e); } } }
HtmlReportWriter implements ReportWriter { @Override public String write(Report report) { try (final StringWriter writer = new StringWriter()) { reportTemplate.process(report, writer); return writer.toString(); } catch (TemplateException e) { throw new RuntimeException("Error populating default report HTML template '"+ reportTemplate.getName() +"': " + e.getMessage(), e); } catch (IOException e) { throw new RuntimeException("Error writing HTML template to string: " + e.getMessage(), e); } } HtmlReportWriter(); }
HtmlReportWriter implements ReportWriter { @Override public String write(Report report) { try (final StringWriter writer = new StringWriter()) { reportTemplate.process(report, writer); return writer.toString(); } catch (TemplateException e) { throw new RuntimeException("Error populating default report HTML template '"+ reportTemplate.getName() +"': " + e.getMessage(), e); } catch (IOException e) { throw new RuntimeException("Error writing HTML template to string: " + e.getMessage(), e); } } HtmlReportWriter(); @Override String write(Report report); @Override boolean write(Report report, String reportFile); boolean write(Report report, String reportFile, String freeMarkerTemplate); }
HtmlReportWriter implements ReportWriter { @Override public String write(Report report) { try (final StringWriter writer = new StringWriter()) { reportTemplate.process(report, writer); return writer.toString(); } catch (TemplateException e) { throw new RuntimeException("Error populating default report HTML template '"+ reportTemplate.getName() +"': " + e.getMessage(), e); } catch (IOException e) { throw new RuntimeException("Error writing HTML template to string: " + e.getMessage(), e); } } HtmlReportWriter(); @Override String write(Report report); @Override boolean write(Report report, String reportFile); boolean write(Report report, String reportFile, String freeMarkerTemplate); }
@Test public void checkAndInstallConfigurationTest() throws IOException { String configName = "com.rbmhtechnology.vind:backend-solr:1.1.2"; service.checkAndInstallConfiguration(configName); assertTrue(service.configurationIsDeployed(configName)); }
protected void checkAndInstallConfiguration(String configName) throws IOException { this.checkAndInstallConfiguration(configName, false); }
CollectionManagementService { protected void checkAndInstallConfiguration(String configName) throws IOException { this.checkAndInstallConfiguration(configName, false); } }
CollectionManagementService { protected void checkAndInstallConfiguration(String configName) throws IOException { this.checkAndInstallConfiguration(configName, false); } CollectionManagementService(List<String> zkHosts); CollectionManagementService(List<String> zkHost, String ... repositories); protected CollectionManagementService(String ... repositories); }
CollectionManagementService { protected void checkAndInstallConfiguration(String configName) throws IOException { this.checkAndInstallConfiguration(configName, false); } CollectionManagementService(List<String> zkHosts); CollectionManagementService(List<String> zkHost, String ... repositories); protected CollectionManagementService(String ... repositories); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas, Boolean autoAddReplicas); boolean collectionExists(String collectionName); void updateCollection(String collectionName, String configName); void updateCollection(String collectionName, String configName, Integer numOfShards, Integer numOfReplicas, Boolean autoAddReplicas); Long getVersionAndInstallIfNecessary(String dependency); }
CollectionManagementService { protected void checkAndInstallConfiguration(String configName) throws IOException { this.checkAndInstallConfiguration(configName, false); } CollectionManagementService(List<String> zkHosts); CollectionManagementService(List<String> zkHost, String ... repositories); protected CollectionManagementService(String ... repositories); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas, Boolean autoAddReplicas); boolean collectionExists(String collectionName); void updateCollection(String collectionName, String configName); void updateCollection(String collectionName, String configName, Integer numOfShards, Integer numOfReplicas, Boolean autoAddReplicas); Long getVersionAndInstallIfNecessary(String dependency); }
@Test public void listRuntimeDependenciesTest() throws IOException, SolrServerException { List<String> runtimeDependencies = service.listRuntimeDependencies("my-collection"); assertThat(runtimeDependencies, contains("org.apache.solr:solr-cell:6.1.0", "com.rbmhtechnology.solr.test:test-jar:1.0")); }
protected List<String> listRuntimeDependencies(String collectionName) throws IOException, SolrServerException { logger.debug("Checking runtime-dependencies for collection {}", collectionName); ModifiableSolrParams params = new ModifiableSolrParams().set("file",RUNTIME_LIB_FILE_NAME); SolrRequest request = new QueryRequest(params); request.setPath("/admin/file"); request.setResponseParser(new InputStreamResponseParser("json")); try (CloudSolrClient client = createCloudSolrClient()) { final NamedList o = client.request(request, collectionName); final LineIterator it = IOUtils.lineIterator((InputStream) o.get("stream"), "utf-8"); final List<String> returnValues = Streams.stream(it).collect(Collectors.toList()); if (returnValues.size() == 1 && returnValues.get(0).startsWith("{\"responseHeader\":{\"status\":404")) { logger.warn("Release does not yet contain rumtimelib configuration file. Runtimelibs have to be installed manually."); return Collections.emptyList(); } return returnValues; } }
CollectionManagementService { protected List<String> listRuntimeDependencies(String collectionName) throws IOException, SolrServerException { logger.debug("Checking runtime-dependencies for collection {}", collectionName); ModifiableSolrParams params = new ModifiableSolrParams().set("file",RUNTIME_LIB_FILE_NAME); SolrRequest request = new QueryRequest(params); request.setPath("/admin/file"); request.setResponseParser(new InputStreamResponseParser("json")); try (CloudSolrClient client = createCloudSolrClient()) { final NamedList o = client.request(request, collectionName); final LineIterator it = IOUtils.lineIterator((InputStream) o.get("stream"), "utf-8"); final List<String> returnValues = Streams.stream(it).collect(Collectors.toList()); if (returnValues.size() == 1 && returnValues.get(0).startsWith("{\"responseHeader\":{\"status\":404")) { logger.warn("Release does not yet contain rumtimelib configuration file. Runtimelibs have to be installed manually."); return Collections.emptyList(); } return returnValues; } } }
CollectionManagementService { protected List<String> listRuntimeDependencies(String collectionName) throws IOException, SolrServerException { logger.debug("Checking runtime-dependencies for collection {}", collectionName); ModifiableSolrParams params = new ModifiableSolrParams().set("file",RUNTIME_LIB_FILE_NAME); SolrRequest request = new QueryRequest(params); request.setPath("/admin/file"); request.setResponseParser(new InputStreamResponseParser("json")); try (CloudSolrClient client = createCloudSolrClient()) { final NamedList o = client.request(request, collectionName); final LineIterator it = IOUtils.lineIterator((InputStream) o.get("stream"), "utf-8"); final List<String> returnValues = Streams.stream(it).collect(Collectors.toList()); if (returnValues.size() == 1 && returnValues.get(0).startsWith("{\"responseHeader\":{\"status\":404")) { logger.warn("Release does not yet contain rumtimelib configuration file. Runtimelibs have to be installed manually."); return Collections.emptyList(); } return returnValues; } } CollectionManagementService(List<String> zkHosts); CollectionManagementService(List<String> zkHost, String ... repositories); protected CollectionManagementService(String ... repositories); }
CollectionManagementService { protected List<String> listRuntimeDependencies(String collectionName) throws IOException, SolrServerException { logger.debug("Checking runtime-dependencies for collection {}", collectionName); ModifiableSolrParams params = new ModifiableSolrParams().set("file",RUNTIME_LIB_FILE_NAME); SolrRequest request = new QueryRequest(params); request.setPath("/admin/file"); request.setResponseParser(new InputStreamResponseParser("json")); try (CloudSolrClient client = createCloudSolrClient()) { final NamedList o = client.request(request, collectionName); final LineIterator it = IOUtils.lineIterator((InputStream) o.get("stream"), "utf-8"); final List<String> returnValues = Streams.stream(it).collect(Collectors.toList()); if (returnValues.size() == 1 && returnValues.get(0).startsWith("{\"responseHeader\":{\"status\":404")) { logger.warn("Release does not yet contain rumtimelib configuration file. Runtimelibs have to be installed manually."); return Collections.emptyList(); } return returnValues; } } CollectionManagementService(List<String> zkHosts); CollectionManagementService(List<String> zkHost, String ... repositories); protected CollectionManagementService(String ... repositories); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas, Boolean autoAddReplicas); boolean collectionExists(String collectionName); void updateCollection(String collectionName, String configName); void updateCollection(String collectionName, String configName, Integer numOfShards, Integer numOfReplicas, Boolean autoAddReplicas); Long getVersionAndInstallIfNecessary(String dependency); }
CollectionManagementService { protected List<String> listRuntimeDependencies(String collectionName) throws IOException, SolrServerException { logger.debug("Checking runtime-dependencies for collection {}", collectionName); ModifiableSolrParams params = new ModifiableSolrParams().set("file",RUNTIME_LIB_FILE_NAME); SolrRequest request = new QueryRequest(params); request.setPath("/admin/file"); request.setResponseParser(new InputStreamResponseParser("json")); try (CloudSolrClient client = createCloudSolrClient()) { final NamedList o = client.request(request, collectionName); final LineIterator it = IOUtils.lineIterator((InputStream) o.get("stream"), "utf-8"); final List<String> returnValues = Streams.stream(it).collect(Collectors.toList()); if (returnValues.size() == 1 && returnValues.get(0).startsWith("{\"responseHeader\":{\"status\":404")) { logger.warn("Release does not yet contain rumtimelib configuration file. Runtimelibs have to be installed manually."); return Collections.emptyList(); } return returnValues; } } CollectionManagementService(List<String> zkHosts); CollectionManagementService(List<String> zkHost, String ... repositories); protected CollectionManagementService(String ... repositories); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas, Boolean autoAddReplicas); boolean collectionExists(String collectionName); void updateCollection(String collectionName, String configName); void updateCollection(String collectionName, String configName, Integer numOfShards, Integer numOfReplicas, Boolean autoAddReplicas); Long getVersionAndInstallIfNecessary(String dependency); }
@Test public void getVersionAndInstallIfNecessaryTest() { Long version = service.getVersionAndInstallIfNecessary("com.rbmhtechnology.solr.test:test-jar:1.0"); assertEquals(1L, version, 0); }
public Long getVersionAndInstallIfNecessary(String dependency) { try (CloudSolrClient client = createCloudSolrClient()) { SolrQuery query = new SolrQuery("blobName:"+Utils.toBlobName(dependency)); query.setSort("version", SolrQuery.ORDER.desc); QueryResponse response = client.query(".system",query); if(response.getResults().getNumFound() > 0) { return Long.valueOf(response.getResults().get(0).get("version").toString()); } else { Path configDirectory = Files.createTempDirectory(Utils.normalizeFileName(dependency)); Path jarFile = Utils.downloadToTempDir(configDirectory, repositories, dependency); return uploadRuntimeLib(dependency, jarFile); } } catch (SolrServerException | IOException e) { logger.warn("Cannot load runtime dependeny " + dependency + ". This may cause runtime issues."); return -1L; } }
CollectionManagementService { public Long getVersionAndInstallIfNecessary(String dependency) { try (CloudSolrClient client = createCloudSolrClient()) { SolrQuery query = new SolrQuery("blobName:"+Utils.toBlobName(dependency)); query.setSort("version", SolrQuery.ORDER.desc); QueryResponse response = client.query(".system",query); if(response.getResults().getNumFound() > 0) { return Long.valueOf(response.getResults().get(0).get("version").toString()); } else { Path configDirectory = Files.createTempDirectory(Utils.normalizeFileName(dependency)); Path jarFile = Utils.downloadToTempDir(configDirectory, repositories, dependency); return uploadRuntimeLib(dependency, jarFile); } } catch (SolrServerException | IOException e) { logger.warn("Cannot load runtime dependeny " + dependency + ". This may cause runtime issues."); return -1L; } } }
CollectionManagementService { public Long getVersionAndInstallIfNecessary(String dependency) { try (CloudSolrClient client = createCloudSolrClient()) { SolrQuery query = new SolrQuery("blobName:"+Utils.toBlobName(dependency)); query.setSort("version", SolrQuery.ORDER.desc); QueryResponse response = client.query(".system",query); if(response.getResults().getNumFound() > 0) { return Long.valueOf(response.getResults().get(0).get("version").toString()); } else { Path configDirectory = Files.createTempDirectory(Utils.normalizeFileName(dependency)); Path jarFile = Utils.downloadToTempDir(configDirectory, repositories, dependency); return uploadRuntimeLib(dependency, jarFile); } } catch (SolrServerException | IOException e) { logger.warn("Cannot load runtime dependeny " + dependency + ". This may cause runtime issues."); return -1L; } } CollectionManagementService(List<String> zkHosts); CollectionManagementService(List<String> zkHost, String ... repositories); protected CollectionManagementService(String ... repositories); }
CollectionManagementService { public Long getVersionAndInstallIfNecessary(String dependency) { try (CloudSolrClient client = createCloudSolrClient()) { SolrQuery query = new SolrQuery("blobName:"+Utils.toBlobName(dependency)); query.setSort("version", SolrQuery.ORDER.desc); QueryResponse response = client.query(".system",query); if(response.getResults().getNumFound() > 0) { return Long.valueOf(response.getResults().get(0).get("version").toString()); } else { Path configDirectory = Files.createTempDirectory(Utils.normalizeFileName(dependency)); Path jarFile = Utils.downloadToTempDir(configDirectory, repositories, dependency); return uploadRuntimeLib(dependency, jarFile); } } catch (SolrServerException | IOException e) { logger.warn("Cannot load runtime dependeny " + dependency + ". This may cause runtime issues."); return -1L; } } CollectionManagementService(List<String> zkHosts); CollectionManagementService(List<String> zkHost, String ... repositories); protected CollectionManagementService(String ... repositories); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas, Boolean autoAddReplicas); boolean collectionExists(String collectionName); void updateCollection(String collectionName, String configName); void updateCollection(String collectionName, String configName, Integer numOfShards, Integer numOfReplicas, Boolean autoAddReplicas); Long getVersionAndInstallIfNecessary(String dependency); }
CollectionManagementService { public Long getVersionAndInstallIfNecessary(String dependency) { try (CloudSolrClient client = createCloudSolrClient()) { SolrQuery query = new SolrQuery("blobName:"+Utils.toBlobName(dependency)); query.setSort("version", SolrQuery.ORDER.desc); QueryResponse response = client.query(".system",query); if(response.getResults().getNumFound() > 0) { return Long.valueOf(response.getResults().get(0).get("version").toString()); } else { Path configDirectory = Files.createTempDirectory(Utils.normalizeFileName(dependency)); Path jarFile = Utils.downloadToTempDir(configDirectory, repositories, dependency); return uploadRuntimeLib(dependency, jarFile); } } catch (SolrServerException | IOException e) { logger.warn("Cannot load runtime dependeny " + dependency + ". This may cause runtime issues."); return -1L; } } CollectionManagementService(List<String> zkHosts); CollectionManagementService(List<String> zkHost, String ... repositories); protected CollectionManagementService(String ... repositories); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas, Boolean autoAddReplicas); boolean collectionExists(String collectionName); void updateCollection(String collectionName, String configName); void updateCollection(String collectionName, String configName, Integer numOfShards, Integer numOfReplicas, Boolean autoAddReplicas); Long getVersionAndInstallIfNecessary(String dependency); }
@Test public void getVersionAndInstallIfNecessaryTest2() { Long version = service.getVersionAndInstallIfNecessary("org.apache.solr:solr-cell:6.1.0"); assertEquals(1L, version, 0); }
public Long getVersionAndInstallIfNecessary(String dependency) { try (CloudSolrClient client = createCloudSolrClient()) { SolrQuery query = new SolrQuery("blobName:"+Utils.toBlobName(dependency)); query.setSort("version", SolrQuery.ORDER.desc); QueryResponse response = client.query(".system",query); if(response.getResults().getNumFound() > 0) { return Long.valueOf(response.getResults().get(0).get("version").toString()); } else { Path configDirectory = Files.createTempDirectory(Utils.normalizeFileName(dependency)); Path jarFile = Utils.downloadToTempDir(configDirectory, repositories, dependency); return uploadRuntimeLib(dependency, jarFile); } } catch (SolrServerException | IOException e) { logger.warn("Cannot load runtime dependeny " + dependency + ". This may cause runtime issues."); return -1L; } }
CollectionManagementService { public Long getVersionAndInstallIfNecessary(String dependency) { try (CloudSolrClient client = createCloudSolrClient()) { SolrQuery query = new SolrQuery("blobName:"+Utils.toBlobName(dependency)); query.setSort("version", SolrQuery.ORDER.desc); QueryResponse response = client.query(".system",query); if(response.getResults().getNumFound() > 0) { return Long.valueOf(response.getResults().get(0).get("version").toString()); } else { Path configDirectory = Files.createTempDirectory(Utils.normalizeFileName(dependency)); Path jarFile = Utils.downloadToTempDir(configDirectory, repositories, dependency); return uploadRuntimeLib(dependency, jarFile); } } catch (SolrServerException | IOException e) { logger.warn("Cannot load runtime dependeny " + dependency + ". This may cause runtime issues."); return -1L; } } }
CollectionManagementService { public Long getVersionAndInstallIfNecessary(String dependency) { try (CloudSolrClient client = createCloudSolrClient()) { SolrQuery query = new SolrQuery("blobName:"+Utils.toBlobName(dependency)); query.setSort("version", SolrQuery.ORDER.desc); QueryResponse response = client.query(".system",query); if(response.getResults().getNumFound() > 0) { return Long.valueOf(response.getResults().get(0).get("version").toString()); } else { Path configDirectory = Files.createTempDirectory(Utils.normalizeFileName(dependency)); Path jarFile = Utils.downloadToTempDir(configDirectory, repositories, dependency); return uploadRuntimeLib(dependency, jarFile); } } catch (SolrServerException | IOException e) { logger.warn("Cannot load runtime dependeny " + dependency + ". This may cause runtime issues."); return -1L; } } CollectionManagementService(List<String> zkHosts); CollectionManagementService(List<String> zkHost, String ... repositories); protected CollectionManagementService(String ... repositories); }
CollectionManagementService { public Long getVersionAndInstallIfNecessary(String dependency) { try (CloudSolrClient client = createCloudSolrClient()) { SolrQuery query = new SolrQuery("blobName:"+Utils.toBlobName(dependency)); query.setSort("version", SolrQuery.ORDER.desc); QueryResponse response = client.query(".system",query); if(response.getResults().getNumFound() > 0) { return Long.valueOf(response.getResults().get(0).get("version").toString()); } else { Path configDirectory = Files.createTempDirectory(Utils.normalizeFileName(dependency)); Path jarFile = Utils.downloadToTempDir(configDirectory, repositories, dependency); return uploadRuntimeLib(dependency, jarFile); } } catch (SolrServerException | IOException e) { logger.warn("Cannot load runtime dependeny " + dependency + ". This may cause runtime issues."); return -1L; } } CollectionManagementService(List<String> zkHosts); CollectionManagementService(List<String> zkHost, String ... repositories); protected CollectionManagementService(String ... repositories); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas, Boolean autoAddReplicas); boolean collectionExists(String collectionName); void updateCollection(String collectionName, String configName); void updateCollection(String collectionName, String configName, Integer numOfShards, Integer numOfReplicas, Boolean autoAddReplicas); Long getVersionAndInstallIfNecessary(String dependency); }
CollectionManagementService { public Long getVersionAndInstallIfNecessary(String dependency) { try (CloudSolrClient client = createCloudSolrClient()) { SolrQuery query = new SolrQuery("blobName:"+Utils.toBlobName(dependency)); query.setSort("version", SolrQuery.ORDER.desc); QueryResponse response = client.query(".system",query); if(response.getResults().getNumFound() > 0) { return Long.valueOf(response.getResults().get(0).get("version").toString()); } else { Path configDirectory = Files.createTempDirectory(Utils.normalizeFileName(dependency)); Path jarFile = Utils.downloadToTempDir(configDirectory, repositories, dependency); return uploadRuntimeLib(dependency, jarFile); } } catch (SolrServerException | IOException e) { logger.warn("Cannot load runtime dependeny " + dependency + ". This may cause runtime issues."); return -1L; } } CollectionManagementService(List<String> zkHosts); CollectionManagementService(List<String> zkHost, String ... repositories); protected CollectionManagementService(String ... repositories); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas, Boolean autoAddReplicas); boolean collectionExists(String collectionName); void updateCollection(String collectionName, String configName); void updateCollection(String collectionName, String configName, Integer numOfShards, Integer numOfReplicas, Boolean autoAddReplicas); Long getVersionAndInstallIfNecessary(String dependency); }
@Test public void checkAndInstallRuntimeDependenciesTest() { Map<String,Long> dependencies = service.checkAndInstallRuntimeDependencies("my-collection"); assertThat(dependencies, hasEntry("org.apache.solr_solr-cell_6.1.0", 1L)); assertThat(dependencies, hasEntry("com.rbmhtechnology.solr.test_test-jar_1.0",1L)); }
protected Map<String,Long> checkAndInstallRuntimeDependencies(String collectionName) { List<String> dependencies = Collections.emptyList(); try { dependencies = listRuntimeDependencies(collectionName); } catch (SolrServerException | IOException e) { logger.warn("Cannot get runtime dependencies from configuration for collection " + collectionName); } Map<String,Long> runtimeLibVersions = new HashMap<>(); for(String dependency : dependencies) { long version = getVersionAndInstallIfNecessary(dependency); if(version > -1) { runtimeLibVersions.put(Utils.toBlobName(dependency), version); } } return runtimeLibVersions; }
CollectionManagementService { protected Map<String,Long> checkAndInstallRuntimeDependencies(String collectionName) { List<String> dependencies = Collections.emptyList(); try { dependencies = listRuntimeDependencies(collectionName); } catch (SolrServerException | IOException e) { logger.warn("Cannot get runtime dependencies from configuration for collection " + collectionName); } Map<String,Long> runtimeLibVersions = new HashMap<>(); for(String dependency : dependencies) { long version = getVersionAndInstallIfNecessary(dependency); if(version > -1) { runtimeLibVersions.put(Utils.toBlobName(dependency), version); } } return runtimeLibVersions; } }
CollectionManagementService { protected Map<String,Long> checkAndInstallRuntimeDependencies(String collectionName) { List<String> dependencies = Collections.emptyList(); try { dependencies = listRuntimeDependencies(collectionName); } catch (SolrServerException | IOException e) { logger.warn("Cannot get runtime dependencies from configuration for collection " + collectionName); } Map<String,Long> runtimeLibVersions = new HashMap<>(); for(String dependency : dependencies) { long version = getVersionAndInstallIfNecessary(dependency); if(version > -1) { runtimeLibVersions.put(Utils.toBlobName(dependency), version); } } return runtimeLibVersions; } CollectionManagementService(List<String> zkHosts); CollectionManagementService(List<String> zkHost, String ... repositories); protected CollectionManagementService(String ... repositories); }
CollectionManagementService { protected Map<String,Long> checkAndInstallRuntimeDependencies(String collectionName) { List<String> dependencies = Collections.emptyList(); try { dependencies = listRuntimeDependencies(collectionName); } catch (SolrServerException | IOException e) { logger.warn("Cannot get runtime dependencies from configuration for collection " + collectionName); } Map<String,Long> runtimeLibVersions = new HashMap<>(); for(String dependency : dependencies) { long version = getVersionAndInstallIfNecessary(dependency); if(version > -1) { runtimeLibVersions.put(Utils.toBlobName(dependency), version); } } return runtimeLibVersions; } CollectionManagementService(List<String> zkHosts); CollectionManagementService(List<String> zkHost, String ... repositories); protected CollectionManagementService(String ... repositories); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas, Boolean autoAddReplicas); boolean collectionExists(String collectionName); void updateCollection(String collectionName, String configName); void updateCollection(String collectionName, String configName, Integer numOfShards, Integer numOfReplicas, Boolean autoAddReplicas); Long getVersionAndInstallIfNecessary(String dependency); }
CollectionManagementService { protected Map<String,Long> checkAndInstallRuntimeDependencies(String collectionName) { List<String> dependencies = Collections.emptyList(); try { dependencies = listRuntimeDependencies(collectionName); } catch (SolrServerException | IOException e) { logger.warn("Cannot get runtime dependencies from configuration for collection " + collectionName); } Map<String,Long> runtimeLibVersions = new HashMap<>(); for(String dependency : dependencies) { long version = getVersionAndInstallIfNecessary(dependency); if(version > -1) { runtimeLibVersions.put(Utils.toBlobName(dependency), version); } } return runtimeLibVersions; } CollectionManagementService(List<String> zkHosts); CollectionManagementService(List<String> zkHost, String ... repositories); protected CollectionManagementService(String ... repositories); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas, Boolean autoAddReplicas); boolean collectionExists(String collectionName); void updateCollection(String collectionName, String configName); void updateCollection(String collectionName, String configName, Integer numOfShards, Integer numOfReplicas, Boolean autoAddReplicas); Long getVersionAndInstallIfNecessary(String dependency); }
@Test public void addOrUpdateRuntimeDependenciesTest() { service.addOrUpdateRuntimeDependencies(Collections.singletonMap("com.rbmhtechnology.solr.test_test-jar_1.0",1L),"my-collection"); }
protected void addOrUpdateRuntimeDependencies(Map<String, Long> runtimeDependencies, String collectionName) { logger.info("Adding runtime-dependencies for {}", collectionName); for(String blobName : runtimeDependencies.keySet()) { RuntimeLibRequest request = new RuntimeLibRequest(RuntimeLibRequestType.add, blobName, runtimeDependencies.get(blobName)); try (CloudSolrClient client = createCloudSolrClient()) { client.request(request, collectionName); logger.debug("Added {} (v{})", request.blobName, request.version); } catch (SolrServerException | IOException e) { logger.warn("Cannot add runtime dependency {} (v{}) to collection {}", blobName, runtimeDependencies.get(blobName), collectionName); logger.info("Try to update dependency"); request.setType(RuntimeLibRequestType.update); try (CloudSolrClient client = createCloudSolrClient()) { client.request(request, collectionName); } catch (SolrServerException | IOException e1) { logger.warn("Cannot update runtime dependency {} (v{}) to collection {}", blobName, runtimeDependencies.get(blobName), collectionName); } } } }
CollectionManagementService { protected void addOrUpdateRuntimeDependencies(Map<String, Long> runtimeDependencies, String collectionName) { logger.info("Adding runtime-dependencies for {}", collectionName); for(String blobName : runtimeDependencies.keySet()) { RuntimeLibRequest request = new RuntimeLibRequest(RuntimeLibRequestType.add, blobName, runtimeDependencies.get(blobName)); try (CloudSolrClient client = createCloudSolrClient()) { client.request(request, collectionName); logger.debug("Added {} (v{})", request.blobName, request.version); } catch (SolrServerException | IOException e) { logger.warn("Cannot add runtime dependency {} (v{}) to collection {}", blobName, runtimeDependencies.get(blobName), collectionName); logger.info("Try to update dependency"); request.setType(RuntimeLibRequestType.update); try (CloudSolrClient client = createCloudSolrClient()) { client.request(request, collectionName); } catch (SolrServerException | IOException e1) { logger.warn("Cannot update runtime dependency {} (v{}) to collection {}", blobName, runtimeDependencies.get(blobName), collectionName); } } } } }
CollectionManagementService { protected void addOrUpdateRuntimeDependencies(Map<String, Long> runtimeDependencies, String collectionName) { logger.info("Adding runtime-dependencies for {}", collectionName); for(String blobName : runtimeDependencies.keySet()) { RuntimeLibRequest request = new RuntimeLibRequest(RuntimeLibRequestType.add, blobName, runtimeDependencies.get(blobName)); try (CloudSolrClient client = createCloudSolrClient()) { client.request(request, collectionName); logger.debug("Added {} (v{})", request.blobName, request.version); } catch (SolrServerException | IOException e) { logger.warn("Cannot add runtime dependency {} (v{}) to collection {}", blobName, runtimeDependencies.get(blobName), collectionName); logger.info("Try to update dependency"); request.setType(RuntimeLibRequestType.update); try (CloudSolrClient client = createCloudSolrClient()) { client.request(request, collectionName); } catch (SolrServerException | IOException e1) { logger.warn("Cannot update runtime dependency {} (v{}) to collection {}", blobName, runtimeDependencies.get(blobName), collectionName); } } } } CollectionManagementService(List<String> zkHosts); CollectionManagementService(List<String> zkHost, String ... repositories); protected CollectionManagementService(String ... repositories); }
CollectionManagementService { protected void addOrUpdateRuntimeDependencies(Map<String, Long> runtimeDependencies, String collectionName) { logger.info("Adding runtime-dependencies for {}", collectionName); for(String blobName : runtimeDependencies.keySet()) { RuntimeLibRequest request = new RuntimeLibRequest(RuntimeLibRequestType.add, blobName, runtimeDependencies.get(blobName)); try (CloudSolrClient client = createCloudSolrClient()) { client.request(request, collectionName); logger.debug("Added {} (v{})", request.blobName, request.version); } catch (SolrServerException | IOException e) { logger.warn("Cannot add runtime dependency {} (v{}) to collection {}", blobName, runtimeDependencies.get(blobName), collectionName); logger.info("Try to update dependency"); request.setType(RuntimeLibRequestType.update); try (CloudSolrClient client = createCloudSolrClient()) { client.request(request, collectionName); } catch (SolrServerException | IOException e1) { logger.warn("Cannot update runtime dependency {} (v{}) to collection {}", blobName, runtimeDependencies.get(blobName), collectionName); } } } } CollectionManagementService(List<String> zkHosts); CollectionManagementService(List<String> zkHost, String ... repositories); protected CollectionManagementService(String ... repositories); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas, Boolean autoAddReplicas); boolean collectionExists(String collectionName); void updateCollection(String collectionName, String configName); void updateCollection(String collectionName, String configName, Integer numOfShards, Integer numOfReplicas, Boolean autoAddReplicas); Long getVersionAndInstallIfNecessary(String dependency); }
CollectionManagementService { protected void addOrUpdateRuntimeDependencies(Map<String, Long> runtimeDependencies, String collectionName) { logger.info("Adding runtime-dependencies for {}", collectionName); for(String blobName : runtimeDependencies.keySet()) { RuntimeLibRequest request = new RuntimeLibRequest(RuntimeLibRequestType.add, blobName, runtimeDependencies.get(blobName)); try (CloudSolrClient client = createCloudSolrClient()) { client.request(request, collectionName); logger.debug("Added {} (v{})", request.blobName, request.version); } catch (SolrServerException | IOException e) { logger.warn("Cannot add runtime dependency {} (v{}) to collection {}", blobName, runtimeDependencies.get(blobName), collectionName); logger.info("Try to update dependency"); request.setType(RuntimeLibRequestType.update); try (CloudSolrClient client = createCloudSolrClient()) { client.request(request, collectionName); } catch (SolrServerException | IOException e1) { logger.warn("Cannot update runtime dependency {} (v{}) to collection {}", blobName, runtimeDependencies.get(blobName), collectionName); } } } } CollectionManagementService(List<String> zkHosts); CollectionManagementService(List<String> zkHost, String ... repositories); protected CollectionManagementService(String ... repositories); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas, Boolean autoAddReplicas); boolean collectionExists(String collectionName); void updateCollection(String collectionName, String configName); void updateCollection(String collectionName, String configName, Integer numOfShards, Integer numOfReplicas, Boolean autoAddReplicas); Long getVersionAndInstallIfNecessary(String dependency); }
@Test public void testSearch() throws Exception { final DocumentFactoryBuilder docFactoryBuilder = new DocumentFactoryBuilder("asset"); FieldDescriptor descriptor = new FieldDescriptorBuilder().setFacet(true).buildTextField("text"); docFactoryBuilder.addField(descriptor); DocumentFactory documents = docFactoryBuilder.build(); server.execute(Search.fulltext("hello world").filter(eq("text", "123")).sort("id", Sort.Direction.Desc),documents); ArgumentCaptor<SolrQuery> argument = ArgumentCaptor.forClass(SolrQuery.class); verify(solrClient).query(argument.capture(), any(SolrRequest.METHOD.class)); SolrQuery query = argument.getValue(); assertEquals("hello world", query.getQuery()); assertEquals(2, query.getFilterQueries().length); assertThat(Arrays.asList(query.getFilterQueries()),containsInAnyOrder("_type_:asset","dynamic_single_facet_string_text:\"123\"")); assertEquals("id Desc", query.getSortField()); }
@Override public boolean execute(Update update,DocumentFactory factory) { final boolean isUpdatable = factory.isUpdatable() && factory.getFields().values().stream() .allMatch( descriptor -> descriptor.isUpdate()); if (isUpdatable) { final SolrInputDocument sdoc = getSolrUpdateDocument(update, factory.getType()); try { if (solrClientLogger.isTraceEnabled()) { solrClientLogger.debug(">>> add({}): {}", update.getId(), sdoc); } else { solrClientLogger.debug(">>> add({})", update.getId()); } SolrInputDocument finalDoc = sdoc; log.debug("Atomic Update - Get version of original document [{}].",update.getId()); final SolrDocument updatedDoc = solrClient.getById(update.getId()); if (updatedDoc == null){ throw new SearchServerException("Can not execute solr partial update for non existing document for update id " + update.getId()); } final Object version = updatedDoc.getFieldValue("_version_"); if (Objects.nonNull(version)) { finalDoc.setField("_version_", version); } else { log.warn("Error updating document [{}]: " + "Atomic updates in nested documents are not supported by Solr", updatedDoc.get(ID)); return false; } log.debug("Atomic Update - Get nested documents of [{}].",update.getId()); final NamedList<Object> paramList = new NamedList<>(); paramList.add(CommonParams.Q, "!( _id_:"+ update.getId()+")&(_root_:"+ update.getId()+")"); final QueryResponse query = solrClient.query(paramList.toSolrParams(), REQUEST_METHOD); if (CollectionUtils.isNotEmpty(query.getResults())) { log.debug("Update document [{}]: doc has {} nested documents, changing from partial update to full index.", finalDoc.getFieldValue(SolrUtils.Fieldname.ID), query.getResults().size()); final List<SolrInputDocument> childDocs = query.getResults().stream() .map(nestedDoc -> SolrUtils.toSolrInputDocument(nestedDoc)) .collect(Collectors.toList()); finalDoc = this.getUpdatedSolrDocument(sdoc, updatedDoc, childDocs); } try { log.debug("Atomic Update - Updating document [{}]: current version [{}]", finalDoc.getFieldValue(SolrUtils.Fieldname.ID), version); final UpdateResponse response = solrClient.add(finalDoc); log.debug("Atomic Update - Solr update time: query time [{}] - elapsed time [{}]", response.getQTime(), response.getQTime()); return true; } catch (HttpSolrClient.RemoteSolrException e) { log.warn("Error updating document [{}]: [{}]", finalDoc.getFieldValue(ID),e.getMessage(), e); return false; } } catch (SolrServerException | IOException e) { log.error("Unable to perform solr partial update on document with id [{}]", update.getId(), e); throw new SearchServerException("Can not execute solr partial update.", e); } } else { Exception e = new SearchServerException("It is not safe to execute solr partial update: Document contains non stored fields"); log.error("Unable to perform solr partial update on document with id [{}]", update.getId(), e); throw new RuntimeException("Can not execute solr partial update.", e); } }
SolrSearchServer extends SmartSearchServerBase { @Override public boolean execute(Update update,DocumentFactory factory) { final boolean isUpdatable = factory.isUpdatable() && factory.getFields().values().stream() .allMatch( descriptor -> descriptor.isUpdate()); if (isUpdatable) { final SolrInputDocument sdoc = getSolrUpdateDocument(update, factory.getType()); try { if (solrClientLogger.isTraceEnabled()) { solrClientLogger.debug(">>> add({}): {}", update.getId(), sdoc); } else { solrClientLogger.debug(">>> add({})", update.getId()); } SolrInputDocument finalDoc = sdoc; log.debug("Atomic Update - Get version of original document [{}].",update.getId()); final SolrDocument updatedDoc = solrClient.getById(update.getId()); if (updatedDoc == null){ throw new SearchServerException("Can not execute solr partial update for non existing document for update id " + update.getId()); } final Object version = updatedDoc.getFieldValue("_version_"); if (Objects.nonNull(version)) { finalDoc.setField("_version_", version); } else { log.warn("Error updating document [{}]: " + "Atomic updates in nested documents are not supported by Solr", updatedDoc.get(ID)); return false; } log.debug("Atomic Update - Get nested documents of [{}].",update.getId()); final NamedList<Object> paramList = new NamedList<>(); paramList.add(CommonParams.Q, "!( _id_:"+ update.getId()+")&(_root_:"+ update.getId()+")"); final QueryResponse query = solrClient.query(paramList.toSolrParams(), REQUEST_METHOD); if (CollectionUtils.isNotEmpty(query.getResults())) { log.debug("Update document [{}]: doc has {} nested documents, changing from partial update to full index.", finalDoc.getFieldValue(SolrUtils.Fieldname.ID), query.getResults().size()); final List<SolrInputDocument> childDocs = query.getResults().stream() .map(nestedDoc -> SolrUtils.toSolrInputDocument(nestedDoc)) .collect(Collectors.toList()); finalDoc = this.getUpdatedSolrDocument(sdoc, updatedDoc, childDocs); } try { log.debug("Atomic Update - Updating document [{}]: current version [{}]", finalDoc.getFieldValue(SolrUtils.Fieldname.ID), version); final UpdateResponse response = solrClient.add(finalDoc); log.debug("Atomic Update - Solr update time: query time [{}] - elapsed time [{}]", response.getQTime(), response.getQTime()); return true; } catch (HttpSolrClient.RemoteSolrException e) { log.warn("Error updating document [{}]: [{}]", finalDoc.getFieldValue(ID),e.getMessage(), e); return false; } } catch (SolrServerException | IOException e) { log.error("Unable to perform solr partial update on document with id [{}]", update.getId(), e); throw new SearchServerException("Can not execute solr partial update.", e); } } else { Exception e = new SearchServerException("It is not safe to execute solr partial update: Document contains non stored fields"); log.error("Unable to perform solr partial update on document with id [{}]", update.getId(), e); throw new RuntimeException("Can not execute solr partial update.", e); } } }
SolrSearchServer extends SmartSearchServerBase { @Override public boolean execute(Update update,DocumentFactory factory) { final boolean isUpdatable = factory.isUpdatable() && factory.getFields().values().stream() .allMatch( descriptor -> descriptor.isUpdate()); if (isUpdatable) { final SolrInputDocument sdoc = getSolrUpdateDocument(update, factory.getType()); try { if (solrClientLogger.isTraceEnabled()) { solrClientLogger.debug(">>> add({}): {}", update.getId(), sdoc); } else { solrClientLogger.debug(">>> add({})", update.getId()); } SolrInputDocument finalDoc = sdoc; log.debug("Atomic Update - Get version of original document [{}].",update.getId()); final SolrDocument updatedDoc = solrClient.getById(update.getId()); if (updatedDoc == null){ throw new SearchServerException("Can not execute solr partial update for non existing document for update id " + update.getId()); } final Object version = updatedDoc.getFieldValue("_version_"); if (Objects.nonNull(version)) { finalDoc.setField("_version_", version); } else { log.warn("Error updating document [{}]: " + "Atomic updates in nested documents are not supported by Solr", updatedDoc.get(ID)); return false; } log.debug("Atomic Update - Get nested documents of [{}].",update.getId()); final NamedList<Object> paramList = new NamedList<>(); paramList.add(CommonParams.Q, "!( _id_:"+ update.getId()+")&(_root_:"+ update.getId()+")"); final QueryResponse query = solrClient.query(paramList.toSolrParams(), REQUEST_METHOD); if (CollectionUtils.isNotEmpty(query.getResults())) { log.debug("Update document [{}]: doc has {} nested documents, changing from partial update to full index.", finalDoc.getFieldValue(SolrUtils.Fieldname.ID), query.getResults().size()); final List<SolrInputDocument> childDocs = query.getResults().stream() .map(nestedDoc -> SolrUtils.toSolrInputDocument(nestedDoc)) .collect(Collectors.toList()); finalDoc = this.getUpdatedSolrDocument(sdoc, updatedDoc, childDocs); } try { log.debug("Atomic Update - Updating document [{}]: current version [{}]", finalDoc.getFieldValue(SolrUtils.Fieldname.ID), version); final UpdateResponse response = solrClient.add(finalDoc); log.debug("Atomic Update - Solr update time: query time [{}] - elapsed time [{}]", response.getQTime(), response.getQTime()); return true; } catch (HttpSolrClient.RemoteSolrException e) { log.warn("Error updating document [{}]: [{}]", finalDoc.getFieldValue(ID),e.getMessage(), e); return false; } } catch (SolrServerException | IOException e) { log.error("Unable to perform solr partial update on document with id [{}]", update.getId(), e); throw new SearchServerException("Can not execute solr partial update.", e); } } else { Exception e = new SearchServerException("It is not safe to execute solr partial update: Document contains non stored fields"); log.error("Unable to perform solr partial update on document with id [{}]", update.getId(), e); throw new RuntimeException("Can not execute solr partial update.", e); } } SolrSearchServer(); SolrSearchServer(SolrClient client); protected SolrSearchServer(SolrClient client, boolean check); }
SolrSearchServer extends SmartSearchServerBase { @Override public boolean execute(Update update,DocumentFactory factory) { final boolean isUpdatable = factory.isUpdatable() && factory.getFields().values().stream() .allMatch( descriptor -> descriptor.isUpdate()); if (isUpdatable) { final SolrInputDocument sdoc = getSolrUpdateDocument(update, factory.getType()); try { if (solrClientLogger.isTraceEnabled()) { solrClientLogger.debug(">>> add({}): {}", update.getId(), sdoc); } else { solrClientLogger.debug(">>> add({})", update.getId()); } SolrInputDocument finalDoc = sdoc; log.debug("Atomic Update - Get version of original document [{}].",update.getId()); final SolrDocument updatedDoc = solrClient.getById(update.getId()); if (updatedDoc == null){ throw new SearchServerException("Can not execute solr partial update for non existing document for update id " + update.getId()); } final Object version = updatedDoc.getFieldValue("_version_"); if (Objects.nonNull(version)) { finalDoc.setField("_version_", version); } else { log.warn("Error updating document [{}]: " + "Atomic updates in nested documents are not supported by Solr", updatedDoc.get(ID)); return false; } log.debug("Atomic Update - Get nested documents of [{}].",update.getId()); final NamedList<Object> paramList = new NamedList<>(); paramList.add(CommonParams.Q, "!( _id_:"+ update.getId()+")&(_root_:"+ update.getId()+")"); final QueryResponse query = solrClient.query(paramList.toSolrParams(), REQUEST_METHOD); if (CollectionUtils.isNotEmpty(query.getResults())) { log.debug("Update document [{}]: doc has {} nested documents, changing from partial update to full index.", finalDoc.getFieldValue(SolrUtils.Fieldname.ID), query.getResults().size()); final List<SolrInputDocument> childDocs = query.getResults().stream() .map(nestedDoc -> SolrUtils.toSolrInputDocument(nestedDoc)) .collect(Collectors.toList()); finalDoc = this.getUpdatedSolrDocument(sdoc, updatedDoc, childDocs); } try { log.debug("Atomic Update - Updating document [{}]: current version [{}]", finalDoc.getFieldValue(SolrUtils.Fieldname.ID), version); final UpdateResponse response = solrClient.add(finalDoc); log.debug("Atomic Update - Solr update time: query time [{}] - elapsed time [{}]", response.getQTime(), response.getQTime()); return true; } catch (HttpSolrClient.RemoteSolrException e) { log.warn("Error updating document [{}]: [{}]", finalDoc.getFieldValue(ID),e.getMessage(), e); return false; } } catch (SolrServerException | IOException e) { log.error("Unable to perform solr partial update on document with id [{}]", update.getId(), e); throw new SearchServerException("Can not execute solr partial update.", e); } } else { Exception e = new SearchServerException("It is not safe to execute solr partial update: Document contains non stored fields"); log.error("Unable to perform solr partial update on document with id [{}]", update.getId(), e); throw new RuntimeException("Can not execute solr partial update.", e); } } SolrSearchServer(); SolrSearchServer(SolrClient client); protected SolrSearchServer(SolrClient client, boolean check); @Override Object getBackend(); @Override StatusResult getBackendStatus(); @Override IndexResult index(Document ... docs); @Override IndexResult index(List<Document> docs); @Override IndexResult indexWithin(Document doc, int withinMs); @Override IndexResult indexWithin(List<Document> doc, int withinMs); @Override void commit(boolean optimize); @Override DeleteResult delete(Document doc); @Override DeleteResult deleteWithin(Document doc, int withinMs); @Override String getRawQuery(FulltextSearch search, DocumentFactory factory); @Override String getRawQuery(FulltextSearch search, Class<T> c); @Override boolean execute(Update update,DocumentFactory factory); @Override DeleteResult execute(Delete delete, DocumentFactory factory); @Override SuggestionResult execute(ExecutableSuggestionSearch search, Class<T> c); @Override SuggestionResult execute(ExecutableSuggestionSearch search, DocumentFactory assets); @Override SuggestionResult execute(ExecutableSuggestionSearch search, DocumentFactory assets,DocumentFactory childFactory); @Override String getRawQuery(ExecutableSuggestionSearch search, DocumentFactory factory); @Override String getRawQuery(ExecutableSuggestionSearch search, DocumentFactory factory, DocumentFactory childFactory); @Override String getRawQuery(ExecutableSuggestionSearch search, Class<T> c); @Override BeanGetResult<T> execute(RealTimeGet search, Class<T> c); @Override GetResult execute(RealTimeGet search, DocumentFactory assets); @Override InverseSearchResult execute(InverseSearch inverseSearch, DocumentFactory factory); @Override IndexResult addInverseSearchQuery(InverseSearchQuery query); @Override void clearIndex(); @Override void close(); @Override Class<? extends ServiceProvider> getServiceProviderClass(); }
SolrSearchServer extends SmartSearchServerBase { @Override public boolean execute(Update update,DocumentFactory factory) { final boolean isUpdatable = factory.isUpdatable() && factory.getFields().values().stream() .allMatch( descriptor -> descriptor.isUpdate()); if (isUpdatable) { final SolrInputDocument sdoc = getSolrUpdateDocument(update, factory.getType()); try { if (solrClientLogger.isTraceEnabled()) { solrClientLogger.debug(">>> add({}): {}", update.getId(), sdoc); } else { solrClientLogger.debug(">>> add({})", update.getId()); } SolrInputDocument finalDoc = sdoc; log.debug("Atomic Update - Get version of original document [{}].",update.getId()); final SolrDocument updatedDoc = solrClient.getById(update.getId()); if (updatedDoc == null){ throw new SearchServerException("Can not execute solr partial update for non existing document for update id " + update.getId()); } final Object version = updatedDoc.getFieldValue("_version_"); if (Objects.nonNull(version)) { finalDoc.setField("_version_", version); } else { log.warn("Error updating document [{}]: " + "Atomic updates in nested documents are not supported by Solr", updatedDoc.get(ID)); return false; } log.debug("Atomic Update - Get nested documents of [{}].",update.getId()); final NamedList<Object> paramList = new NamedList<>(); paramList.add(CommonParams.Q, "!( _id_:"+ update.getId()+")&(_root_:"+ update.getId()+")"); final QueryResponse query = solrClient.query(paramList.toSolrParams(), REQUEST_METHOD); if (CollectionUtils.isNotEmpty(query.getResults())) { log.debug("Update document [{}]: doc has {} nested documents, changing from partial update to full index.", finalDoc.getFieldValue(SolrUtils.Fieldname.ID), query.getResults().size()); final List<SolrInputDocument> childDocs = query.getResults().stream() .map(nestedDoc -> SolrUtils.toSolrInputDocument(nestedDoc)) .collect(Collectors.toList()); finalDoc = this.getUpdatedSolrDocument(sdoc, updatedDoc, childDocs); } try { log.debug("Atomic Update - Updating document [{}]: current version [{}]", finalDoc.getFieldValue(SolrUtils.Fieldname.ID), version); final UpdateResponse response = solrClient.add(finalDoc); log.debug("Atomic Update - Solr update time: query time [{}] - elapsed time [{}]", response.getQTime(), response.getQTime()); return true; } catch (HttpSolrClient.RemoteSolrException e) { log.warn("Error updating document [{}]: [{}]", finalDoc.getFieldValue(ID),e.getMessage(), e); return false; } } catch (SolrServerException | IOException e) { log.error("Unable to perform solr partial update on document with id [{}]", update.getId(), e); throw new SearchServerException("Can not execute solr partial update.", e); } } else { Exception e = new SearchServerException("It is not safe to execute solr partial update: Document contains non stored fields"); log.error("Unable to perform solr partial update on document with id [{}]", update.getId(), e); throw new RuntimeException("Can not execute solr partial update.", e); } } SolrSearchServer(); SolrSearchServer(SolrClient client); protected SolrSearchServer(SolrClient client, boolean check); @Override Object getBackend(); @Override StatusResult getBackendStatus(); @Override IndexResult index(Document ... docs); @Override IndexResult index(List<Document> docs); @Override IndexResult indexWithin(Document doc, int withinMs); @Override IndexResult indexWithin(List<Document> doc, int withinMs); @Override void commit(boolean optimize); @Override DeleteResult delete(Document doc); @Override DeleteResult deleteWithin(Document doc, int withinMs); @Override String getRawQuery(FulltextSearch search, DocumentFactory factory); @Override String getRawQuery(FulltextSearch search, Class<T> c); @Override boolean execute(Update update,DocumentFactory factory); @Override DeleteResult execute(Delete delete, DocumentFactory factory); @Override SuggestionResult execute(ExecutableSuggestionSearch search, Class<T> c); @Override SuggestionResult execute(ExecutableSuggestionSearch search, DocumentFactory assets); @Override SuggestionResult execute(ExecutableSuggestionSearch search, DocumentFactory assets,DocumentFactory childFactory); @Override String getRawQuery(ExecutableSuggestionSearch search, DocumentFactory factory); @Override String getRawQuery(ExecutableSuggestionSearch search, DocumentFactory factory, DocumentFactory childFactory); @Override String getRawQuery(ExecutableSuggestionSearch search, Class<T> c); @Override BeanGetResult<T> execute(RealTimeGet search, Class<T> c); @Override GetResult execute(RealTimeGet search, DocumentFactory assets); @Override InverseSearchResult execute(InverseSearch inverseSearch, DocumentFactory factory); @Override IndexResult addInverseSearchQuery(InverseSearchQuery query); @Override void clearIndex(); @Override void close(); @Override Class<? extends ServiceProvider> getServiceProviderClass(); static final String SOLR_WILDCARD; static final String SUGGESTION_DF_FIELD; static SolrRequest.METHOD REQUEST_METHOD; }
@Test public void testIndex() throws Exception { FieldDescriptor<String> title = new FieldDescriptorBuilder<>().setFullText(true).buildTextField("title"); SingleValueFieldDescriptor.DateFieldDescriptor<ZonedDateTime> created = new FieldDescriptorBuilder<>().setFacet(true).buildDateField("created"); MultiValueFieldDescriptor.NumericFieldDescriptor<Integer> category = new FieldDescriptorBuilder<>().setFacet(true).buildMultivaluedNumericField("category", Integer.class); final DocumentFactoryBuilder docFactoryBuilder = new DocumentFactoryBuilder("asset"); DocumentFactory documents = docFactoryBuilder.addField(title).addField(created).addField(category).build(); final ZonedDateTime creationDate = ZonedDateTime.of(2016, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()); Document d1 = documents.createDoc("1") .setValue(title, "Hello World") .setValue(created, creationDate) .setValues(category, Arrays.asList(1, 2)); Document d2 = documents.createDoc("2") .setValue(title, "Hello Austria") .setValue(created, creationDate) .setValue(category, 4); server.index(d1); ArgumentCaptor<ArrayList<SolrInputDocument>> argument = ArgumentCaptor.forClass((Class)ArrayList.class); verify(solrClient).add(argument.capture()); ArrayList<SolrInputDocument> docs = argument.getValue(); SolrInputDocument doc = docs.get(0); assertThat(doc.get(SolrUtils.Fieldname.ID), solrInputField(SolrUtils.Fieldname.ID, "1")); assertThat(doc.get(SolrUtils.Fieldname.TYPE), solrInputField(SolrUtils.Fieldname.TYPE, "asset")); assertThat(doc.get("dynamic_multi_int_category"), solrInputField("dynamic_multi_int_category", Matchers.containsInAnyOrder(1,2))); assertThat(doc.get("dynamic_single_string_title"), solrInputField("dynamic_single_string_title", "Hello World")); assertThat(doc.get("dynamic_single_date_created"), solrInputField("dynamic_single_date_created", Date.from(creationDate.toInstant()))); server.commit(); SearchResult result = server.execute(Search .fulltext("hello") .filter(or(category.between(3, 5), created.before(ZonedDateTime.now()))) , documents); }
@Override public IndexResult index(Document ... docs) { Asserts.notNull(docs,"Document to index should not be null."); Asserts.check(docs.length > 0, "Should be at least one document to index."); return indexMultipleDocuments(Arrays.asList(docs), -1); }
SolrSearchServer extends SmartSearchServerBase { @Override public IndexResult index(Document ... docs) { Asserts.notNull(docs,"Document to index should not be null."); Asserts.check(docs.length > 0, "Should be at least one document to index."); return indexMultipleDocuments(Arrays.asList(docs), -1); } }
SolrSearchServer extends SmartSearchServerBase { @Override public IndexResult index(Document ... docs) { Asserts.notNull(docs,"Document to index should not be null."); Asserts.check(docs.length > 0, "Should be at least one document to index."); return indexMultipleDocuments(Arrays.asList(docs), -1); } SolrSearchServer(); SolrSearchServer(SolrClient client); protected SolrSearchServer(SolrClient client, boolean check); }
SolrSearchServer extends SmartSearchServerBase { @Override public IndexResult index(Document ... docs) { Asserts.notNull(docs,"Document to index should not be null."); Asserts.check(docs.length > 0, "Should be at least one document to index."); return indexMultipleDocuments(Arrays.asList(docs), -1); } SolrSearchServer(); SolrSearchServer(SolrClient client); protected SolrSearchServer(SolrClient client, boolean check); @Override Object getBackend(); @Override StatusResult getBackendStatus(); @Override IndexResult index(Document ... docs); @Override IndexResult index(List<Document> docs); @Override IndexResult indexWithin(Document doc, int withinMs); @Override IndexResult indexWithin(List<Document> doc, int withinMs); @Override void commit(boolean optimize); @Override DeleteResult delete(Document doc); @Override DeleteResult deleteWithin(Document doc, int withinMs); @Override String getRawQuery(FulltextSearch search, DocumentFactory factory); @Override String getRawQuery(FulltextSearch search, Class<T> c); @Override boolean execute(Update update,DocumentFactory factory); @Override DeleteResult execute(Delete delete, DocumentFactory factory); @Override SuggestionResult execute(ExecutableSuggestionSearch search, Class<T> c); @Override SuggestionResult execute(ExecutableSuggestionSearch search, DocumentFactory assets); @Override SuggestionResult execute(ExecutableSuggestionSearch search, DocumentFactory assets,DocumentFactory childFactory); @Override String getRawQuery(ExecutableSuggestionSearch search, DocumentFactory factory); @Override String getRawQuery(ExecutableSuggestionSearch search, DocumentFactory factory, DocumentFactory childFactory); @Override String getRawQuery(ExecutableSuggestionSearch search, Class<T> c); @Override BeanGetResult<T> execute(RealTimeGet search, Class<T> c); @Override GetResult execute(RealTimeGet search, DocumentFactory assets); @Override InverseSearchResult execute(InverseSearch inverseSearch, DocumentFactory factory); @Override IndexResult addInverseSearchQuery(InverseSearchQuery query); @Override void clearIndex(); @Override void close(); @Override Class<? extends ServiceProvider> getServiceProviderClass(); }
SolrSearchServer extends SmartSearchServerBase { @Override public IndexResult index(Document ... docs) { Asserts.notNull(docs,"Document to index should not be null."); Asserts.check(docs.length > 0, "Should be at least one document to index."); return indexMultipleDocuments(Arrays.asList(docs), -1); } SolrSearchServer(); SolrSearchServer(SolrClient client); protected SolrSearchServer(SolrClient client, boolean check); @Override Object getBackend(); @Override StatusResult getBackendStatus(); @Override IndexResult index(Document ... docs); @Override IndexResult index(List<Document> docs); @Override IndexResult indexWithin(Document doc, int withinMs); @Override IndexResult indexWithin(List<Document> doc, int withinMs); @Override void commit(boolean optimize); @Override DeleteResult delete(Document doc); @Override DeleteResult deleteWithin(Document doc, int withinMs); @Override String getRawQuery(FulltextSearch search, DocumentFactory factory); @Override String getRawQuery(FulltextSearch search, Class<T> c); @Override boolean execute(Update update,DocumentFactory factory); @Override DeleteResult execute(Delete delete, DocumentFactory factory); @Override SuggestionResult execute(ExecutableSuggestionSearch search, Class<T> c); @Override SuggestionResult execute(ExecutableSuggestionSearch search, DocumentFactory assets); @Override SuggestionResult execute(ExecutableSuggestionSearch search, DocumentFactory assets,DocumentFactory childFactory); @Override String getRawQuery(ExecutableSuggestionSearch search, DocumentFactory factory); @Override String getRawQuery(ExecutableSuggestionSearch search, DocumentFactory factory, DocumentFactory childFactory); @Override String getRawQuery(ExecutableSuggestionSearch search, Class<T> c); @Override BeanGetResult<T> execute(RealTimeGet search, Class<T> c); @Override GetResult execute(RealTimeGet search, DocumentFactory assets); @Override InverseSearchResult execute(InverseSearch inverseSearch, DocumentFactory factory); @Override IndexResult addInverseSearchQuery(InverseSearchQuery query); @Override void clearIndex(); @Override void close(); @Override Class<? extends ServiceProvider> getServiceProviderClass(); static final String SOLR_WILDCARD; static final String SUGGESTION_DF_FIELD; static SolrRequest.METHOD REQUEST_METHOD; }
@Test @Ignore public void testFilterSerialization() { final ChildrenFilterSerializer serializer = new ChildrenFilterSerializer(parent, child, null, false, true); final Filter.DescriptorFilter<String> parentFilter = new Filter.DescriptorFilter<>(parent_value, "p_v", Scope.Facet); final Filter.DescriptorFilter<String> sharedFilter = new Filter.DescriptorFilter<>(shared_value, "s_v", Scope.Facet); final Filter.DescriptorFilter<String> childrenFilter = new Filter.DescriptorFilter<>(child_value, "c_v", Scope.Facet); final AndFilter andFilter = new AndFilter(parentFilter, sharedFilter); String serializedFilter = serializer.serialize(andFilter); assertEquals("_type_:parent AND dynamic_single_stored_facet_string_parent_value:\"p_v\" AND {!parent which='_type_:parent' v='_type_:child AND dynamic_single_stored_facet_string_shared_value:\"s_v\"'}",serializedFilter); serializedFilter = serializer.serialize(new AndFilter(new OrFilter(childrenFilter, andFilter),not(childrenFilter))); assertEquals("({!parent which='_type_:parent' v='_type_:child AND NOT(dynamic_single_stored_facet_string_child_value:\"c_v\") AND dynamic_single_stored_facet_string_child_value:\"c_v\"'} ) OR (_type_:parent AND dynamic_single_stored_facet_string_parent_value:\"p_v\" AND {!parent which='_type_:parent' v='_type_:child AND NOT(dynamic_single_stored_facet_string_child_value:\"c_v\") AND dynamic_single_stored_facet_string_shared_value:\"s_v\"'} )",serializedFilter); }
public String serialize(Filter filter){ final Filter normalizedFilter = normalize(filter); if (AndFilter.class.isAssignableFrom(normalizedFilter.getClass())) return serialize((AndFilter)normalizedFilter); else if (OrFilter.class.isAssignableFrom(normalizedFilter.getClass())) return serialize((OrFilter)normalizedFilter); else if (isHierarchicalFilter(normalizedFilter)) { final String parentFilter = new SolrFilterSerializer(parentFactory, strict).serialize(normalizedFilter,searchContext); return parentFilter; } else { final String childFilter = new SolrFilterSerializer(childFactory, strict).serialize(normalizedFilter,searchContext); return String.format(CHILD_QUERY_TEMPLATE, TYPE, parentFactory.getType(), String.format(TYPE_FILTER, TYPE, childFactory.getType()), childFilter); } }
ChildrenFilterSerializer { public String serialize(Filter filter){ final Filter normalizedFilter = normalize(filter); if (AndFilter.class.isAssignableFrom(normalizedFilter.getClass())) return serialize((AndFilter)normalizedFilter); else if (OrFilter.class.isAssignableFrom(normalizedFilter.getClass())) return serialize((OrFilter)normalizedFilter); else if (isHierarchicalFilter(normalizedFilter)) { final String parentFilter = new SolrFilterSerializer(parentFactory, strict).serialize(normalizedFilter,searchContext); return parentFilter; } else { final String childFilter = new SolrFilterSerializer(childFactory, strict).serialize(normalizedFilter,searchContext); return String.format(CHILD_QUERY_TEMPLATE, TYPE, parentFactory.getType(), String.format(TYPE_FILTER, TYPE, childFactory.getType()), childFilter); } } }
ChildrenFilterSerializer { public String serialize(Filter filter){ final Filter normalizedFilter = normalize(filter); if (AndFilter.class.isAssignableFrom(normalizedFilter.getClass())) return serialize((AndFilter)normalizedFilter); else if (OrFilter.class.isAssignableFrom(normalizedFilter.getClass())) return serialize((OrFilter)normalizedFilter); else if (isHierarchicalFilter(normalizedFilter)) { final String parentFilter = new SolrFilterSerializer(parentFactory, strict).serialize(normalizedFilter,searchContext); return parentFilter; } else { final String childFilter = new SolrFilterSerializer(childFactory, strict).serialize(normalizedFilter,searchContext); return String.format(CHILD_QUERY_TEMPLATE, TYPE, parentFactory.getType(), String.format(TYPE_FILTER, TYPE, childFactory.getType()), childFilter); } } ChildrenFilterSerializer(DocumentFactory parentFactory, DocumentFactory childFactory, String searchContext, boolean strict, boolean childrenSearch); }
ChildrenFilterSerializer { public String serialize(Filter filter){ final Filter normalizedFilter = normalize(filter); if (AndFilter.class.isAssignableFrom(normalizedFilter.getClass())) return serialize((AndFilter)normalizedFilter); else if (OrFilter.class.isAssignableFrom(normalizedFilter.getClass())) return serialize((OrFilter)normalizedFilter); else if (isHierarchicalFilter(normalizedFilter)) { final String parentFilter = new SolrFilterSerializer(parentFactory, strict).serialize(normalizedFilter,searchContext); return parentFilter; } else { final String childFilter = new SolrFilterSerializer(childFactory, strict).serialize(normalizedFilter,searchContext); return String.format(CHILD_QUERY_TEMPLATE, TYPE, parentFactory.getType(), String.format(TYPE_FILTER, TYPE, childFactory.getType()), childFilter); } } ChildrenFilterSerializer(DocumentFactory parentFactory, DocumentFactory childFactory, String searchContext, boolean strict, boolean childrenSearch); String serialize(Filter filter); }
ChildrenFilterSerializer { public String serialize(Filter filter){ final Filter normalizedFilter = normalize(filter); if (AndFilter.class.isAssignableFrom(normalizedFilter.getClass())) return serialize((AndFilter)normalizedFilter); else if (OrFilter.class.isAssignableFrom(normalizedFilter.getClass())) return serialize((OrFilter)normalizedFilter); else if (isHierarchicalFilter(normalizedFilter)) { final String parentFilter = new SolrFilterSerializer(parentFactory, strict).serialize(normalizedFilter,searchContext); return parentFilter; } else { final String childFilter = new SolrFilterSerializer(childFactory, strict).serialize(normalizedFilter,searchContext); return String.format(CHILD_QUERY_TEMPLATE, TYPE, parentFactory.getType(), String.format(TYPE_FILTER, TYPE, childFactory.getType()), childFilter); } } ChildrenFilterSerializer(DocumentFactory parentFactory, DocumentFactory childFactory, String searchContext, boolean strict, boolean childrenSearch); String serialize(Filter filter); }
@Test public void testNormalization() { final ChildrenFilterSerializer serializer = new ChildrenFilterSerializer(parent, child, null, false, false); Filter parentValueFilter = new OrFilter(eq(parent_value,"value1"), eq(parent_value,"value2")); Filter sharedValueFilter = new OrFilter(new OrFilter(eq(shared_value,"shared1"), eq(shared_value,"shared2")), eq(shared_value,"shared3")); Filter mainFilter = new AndFilter(parentValueFilter, sharedValueFilter); Filter normalizedFilter = serializer.normalize(mainFilter); assertEquals("OrFilter",normalizedFilter.getType()); assertEquals(6,((OrFilter)normalizedFilter).getChildren().size()); Filter parentChildrenValueFilter = new AndFilter(eq(shared_value,"shared4"), eq(child_value,"child1")); mainFilter = new AndFilter(new AndFilter(parentValueFilter, sharedValueFilter), parentChildrenValueFilter); normalizedFilter = serializer.normalize(mainFilter); assertEquals("OrFilter",normalizedFilter.getType()); assertEquals(6,((OrFilter)normalizedFilter).getChildren().size()); parentChildrenValueFilter = new AndFilter(eq(shared_value,"shared1"), eq(child_value,"child1")); sharedValueFilter = new OrFilter(new OrFilter(parentChildrenValueFilter, eq(shared_value,"shared2")), eq(shared_value,"shared3")); mainFilter = new AndFilter(parentValueFilter, sharedValueFilter); normalizedFilter = serializer.normalize(mainFilter); assertEquals("OrFilter",normalizedFilter.getType()); assertEquals(6,((OrFilter)normalizedFilter).getChildren().size()); parentChildrenValueFilter = new AndFilter(eq(shared_value,"shared1"), eq(child_value,"child1")); sharedValueFilter = new OrFilter(new OrFilter(parentChildrenValueFilter, eq(shared_value,"shared2")), eq(shared_value,"shared3")); mainFilter = new OrFilter(new AndFilter(eq(parent_value,"value1"), eq(parent_value,"value2")), sharedValueFilter); normalizedFilter = serializer.normalize(mainFilter); assertEquals("OrFilter",normalizedFilter.getType()); assertEquals(4,((OrFilter)normalizedFilter).getChildren().size()); }
private Filter normalize(AndFilter filter){ final Set<Filter> normalizedFilters = filter.getChildren().stream() .map(this::normalize) .collect(Collectors.toSet()); final Set<Filter> normalizedChildren = normalizedFilters.stream() .filter(f -> !f.getType().equals(filter.getType()) && !f.getType().equals("OrFilter")) .collect(Collectors.toSet()); normalizedFilters.stream(). filter(f -> f.getType().equals(filter.getType())) .forEach( af -> normalizedChildren.addAll(((AndFilter)af).getChildren())); final Set<Filter> orChildren = normalizedFilters.stream(). filter(f -> f.getType().equals("OrFilter")) .map( of -> normalize((OrFilter) of)) .collect(Collectors.toSet()); final Filter orFilterPivot = orChildren.stream() .findFirst() .orElse(null); if(Objects.nonNull(orFilterPivot)) { orChildren.remove(orFilterPivot); final Set<Filter> andResultFilters= ((OrFilter) orFilterPivot).getChildren().stream() .map( f-> AndFilter.fromSet(Sets.union( normalizedChildren, Sets.newHashSet(f)))) .map( af -> AndFilter.fromSet(Sets.union( orChildren, Sets.newHashSet(af)))) .collect(Collectors.toSet()); final Set<Filter> andResultNormalizedFilters = andResultFilters.stream() .map(f -> normalize(f)) .collect(Collectors.toSet()); if(CollectionUtils.isNotEmpty(andResultNormalizedFilters)) { return OrFilter.fromSet(andResultNormalizedFilters); } } if(CollectionUtils.isNotEmpty(orChildren)) { return OrFilter.fromSet(orChildren); } return AndFilter.fromSet(normalizedChildren); }
ChildrenFilterSerializer { private Filter normalize(AndFilter filter){ final Set<Filter> normalizedFilters = filter.getChildren().stream() .map(this::normalize) .collect(Collectors.toSet()); final Set<Filter> normalizedChildren = normalizedFilters.stream() .filter(f -> !f.getType().equals(filter.getType()) && !f.getType().equals("OrFilter")) .collect(Collectors.toSet()); normalizedFilters.stream(). filter(f -> f.getType().equals(filter.getType())) .forEach( af -> normalizedChildren.addAll(((AndFilter)af).getChildren())); final Set<Filter> orChildren = normalizedFilters.stream(). filter(f -> f.getType().equals("OrFilter")) .map( of -> normalize((OrFilter) of)) .collect(Collectors.toSet()); final Filter orFilterPivot = orChildren.stream() .findFirst() .orElse(null); if(Objects.nonNull(orFilterPivot)) { orChildren.remove(orFilterPivot); final Set<Filter> andResultFilters= ((OrFilter) orFilterPivot).getChildren().stream() .map( f-> AndFilter.fromSet(Sets.union( normalizedChildren, Sets.newHashSet(f)))) .map( af -> AndFilter.fromSet(Sets.union( orChildren, Sets.newHashSet(af)))) .collect(Collectors.toSet()); final Set<Filter> andResultNormalizedFilters = andResultFilters.stream() .map(f -> normalize(f)) .collect(Collectors.toSet()); if(CollectionUtils.isNotEmpty(andResultNormalizedFilters)) { return OrFilter.fromSet(andResultNormalizedFilters); } } if(CollectionUtils.isNotEmpty(orChildren)) { return OrFilter.fromSet(orChildren); } return AndFilter.fromSet(normalizedChildren); } }
ChildrenFilterSerializer { private Filter normalize(AndFilter filter){ final Set<Filter> normalizedFilters = filter.getChildren().stream() .map(this::normalize) .collect(Collectors.toSet()); final Set<Filter> normalizedChildren = normalizedFilters.stream() .filter(f -> !f.getType().equals(filter.getType()) && !f.getType().equals("OrFilter")) .collect(Collectors.toSet()); normalizedFilters.stream(). filter(f -> f.getType().equals(filter.getType())) .forEach( af -> normalizedChildren.addAll(((AndFilter)af).getChildren())); final Set<Filter> orChildren = normalizedFilters.stream(). filter(f -> f.getType().equals("OrFilter")) .map( of -> normalize((OrFilter) of)) .collect(Collectors.toSet()); final Filter orFilterPivot = orChildren.stream() .findFirst() .orElse(null); if(Objects.nonNull(orFilterPivot)) { orChildren.remove(orFilterPivot); final Set<Filter> andResultFilters= ((OrFilter) orFilterPivot).getChildren().stream() .map( f-> AndFilter.fromSet(Sets.union( normalizedChildren, Sets.newHashSet(f)))) .map( af -> AndFilter.fromSet(Sets.union( orChildren, Sets.newHashSet(af)))) .collect(Collectors.toSet()); final Set<Filter> andResultNormalizedFilters = andResultFilters.stream() .map(f -> normalize(f)) .collect(Collectors.toSet()); if(CollectionUtils.isNotEmpty(andResultNormalizedFilters)) { return OrFilter.fromSet(andResultNormalizedFilters); } } if(CollectionUtils.isNotEmpty(orChildren)) { return OrFilter.fromSet(orChildren); } return AndFilter.fromSet(normalizedChildren); } ChildrenFilterSerializer(DocumentFactory parentFactory, DocumentFactory childFactory, String searchContext, boolean strict, boolean childrenSearch); }
ChildrenFilterSerializer { private Filter normalize(AndFilter filter){ final Set<Filter> normalizedFilters = filter.getChildren().stream() .map(this::normalize) .collect(Collectors.toSet()); final Set<Filter> normalizedChildren = normalizedFilters.stream() .filter(f -> !f.getType().equals(filter.getType()) && !f.getType().equals("OrFilter")) .collect(Collectors.toSet()); normalizedFilters.stream(). filter(f -> f.getType().equals(filter.getType())) .forEach( af -> normalizedChildren.addAll(((AndFilter)af).getChildren())); final Set<Filter> orChildren = normalizedFilters.stream(). filter(f -> f.getType().equals("OrFilter")) .map( of -> normalize((OrFilter) of)) .collect(Collectors.toSet()); final Filter orFilterPivot = orChildren.stream() .findFirst() .orElse(null); if(Objects.nonNull(orFilterPivot)) { orChildren.remove(orFilterPivot); final Set<Filter> andResultFilters= ((OrFilter) orFilterPivot).getChildren().stream() .map( f-> AndFilter.fromSet(Sets.union( normalizedChildren, Sets.newHashSet(f)))) .map( af -> AndFilter.fromSet(Sets.union( orChildren, Sets.newHashSet(af)))) .collect(Collectors.toSet()); final Set<Filter> andResultNormalizedFilters = andResultFilters.stream() .map(f -> normalize(f)) .collect(Collectors.toSet()); if(CollectionUtils.isNotEmpty(andResultNormalizedFilters)) { return OrFilter.fromSet(andResultNormalizedFilters); } } if(CollectionUtils.isNotEmpty(orChildren)) { return OrFilter.fromSet(orChildren); } return AndFilter.fromSet(normalizedChildren); } ChildrenFilterSerializer(DocumentFactory parentFactory, DocumentFactory childFactory, String searchContext, boolean strict, boolean childrenSearch); String serialize(Filter filter); }
ChildrenFilterSerializer { private Filter normalize(AndFilter filter){ final Set<Filter> normalizedFilters = filter.getChildren().stream() .map(this::normalize) .collect(Collectors.toSet()); final Set<Filter> normalizedChildren = normalizedFilters.stream() .filter(f -> !f.getType().equals(filter.getType()) && !f.getType().equals("OrFilter")) .collect(Collectors.toSet()); normalizedFilters.stream(). filter(f -> f.getType().equals(filter.getType())) .forEach( af -> normalizedChildren.addAll(((AndFilter)af).getChildren())); final Set<Filter> orChildren = normalizedFilters.stream(). filter(f -> f.getType().equals("OrFilter")) .map( of -> normalize((OrFilter) of)) .collect(Collectors.toSet()); final Filter orFilterPivot = orChildren.stream() .findFirst() .orElse(null); if(Objects.nonNull(orFilterPivot)) { orChildren.remove(orFilterPivot); final Set<Filter> andResultFilters= ((OrFilter) orFilterPivot).getChildren().stream() .map( f-> AndFilter.fromSet(Sets.union( normalizedChildren, Sets.newHashSet(f)))) .map( af -> AndFilter.fromSet(Sets.union( orChildren, Sets.newHashSet(af)))) .collect(Collectors.toSet()); final Set<Filter> andResultNormalizedFilters = andResultFilters.stream() .map(f -> normalize(f)) .collect(Collectors.toSet()); if(CollectionUtils.isNotEmpty(andResultNormalizedFilters)) { return OrFilter.fromSet(andResultNormalizedFilters); } } if(CollectionUtils.isNotEmpty(orChildren)) { return OrFilter.fromSet(orChildren); } return AndFilter.fromSet(normalizedChildren); } ChildrenFilterSerializer(DocumentFactory parentFactory, DocumentFactory childFactory, String searchContext, boolean strict, boolean childrenSearch); String serialize(Filter filter); }
@Test public void testWriteToString() { final String jsonReport = reportWriter.write(report); Assert.assertTrue(true); }
@Override public String write(Report report) { try { return mapper.writeValueAsString(report); } catch (JsonProcessingException e) { log.error("Error writing report as Json string: {}", e.getMessage(), e); return null; } }
JsonReportWriter implements ReportWriter { @Override public String write(Report report) { try { return mapper.writeValueAsString(report); } catch (JsonProcessingException e) { log.error("Error writing report as Json string: {}", e.getMessage(), e); return null; } } }
JsonReportWriter implements ReportWriter { @Override public String write(Report report) { try { return mapper.writeValueAsString(report); } catch (JsonProcessingException e) { log.error("Error writing report as Json string: {}", e.getMessage(), e); return null; } } JsonReportWriter(); }
JsonReportWriter implements ReportWriter { @Override public String write(Report report) { try { return mapper.writeValueAsString(report); } catch (JsonProcessingException e) { log.error("Error writing report as Json string: {}", e.getMessage(), e); return null; } } JsonReportWriter(); @Override String write(Report report); @Override boolean write(Report report, String reportFile); }
JsonReportWriter implements ReportWriter { @Override public String write(Report report) { try { return mapper.writeValueAsString(report); } catch (JsonProcessingException e) { log.error("Error writing report as Json string: {}", e.getMessage(), e); return null; } } JsonReportWriter(); @Override String write(Report report); @Override boolean write(Report report, String reportFile); }
@Test public void test() throws SyntaxError { HashMap<String, String> dateIntervals = new HashMap<>(); dateIntervals.put("after","[NOW+23DAYS/DAY TO *]"); dateIntervals.put("before","[* TO NOW+23DAYS/DAY]"); HashMap<String, String> numberIntervals = new HashMap<>(); numberIntervals.put("bigger","[23 TO *]"); numberIntervals.put("smaller","[* TO 22]"); SingleValueFieldDescriptor.UtilDateFieldDescriptor<Date> testDateField = new FieldDescriptorBuilder().buildUtilDateField("test1"); FieldDescriptor<Float> testNumericField = new FieldDescriptorBuilder().buildNumericField("numericTest", Float.class); Assert.assertTrue(FacetMapper.stringQuery2FacetMapper(testDateField, "dateFacet",dateIntervals).getName().equals("dateFacet")); Assert.assertTrue(FacetMapper.stringQuery2FacetMapper(testNumericField, "numericFacet", numberIntervals).getName().equals("numericFacet")); Assert.assertTrue(true); }
public static <T> Facet stringQuery2FacetMapper(FieldDescriptor<T> field,String facetName, Map<String,String> query) { final String stringQuery = query.values().iterator().next(); Class<T> type = field.getType(); if (ComplexFieldDescriptor.class.isAssignableFrom(field.getClass())) { type = ((ComplexFieldDescriptor)field).getFacetType(); } if (query.size() == 1 && !intervalDateFacetMatcher(stringQuery) && !INTERVAL_NUMERIC_FACET.matcher(stringQuery).matches()) { return queryFacetMapper(facetName,field.getName(), stringQuery); } else { if (Date.class.isAssignableFrom(type) || ZonedDateTime.class.isAssignableFrom(type)) { Interval.DateMathInterval[] intervals = query.keySet().stream() .map(key -> intervalDateFacetMapper(key, query.get(key))) .toArray(Interval.DateMathInterval[]::new); if (SingleValueFieldDescriptor.DateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValueFieldDescriptor.DateFieldDescriptor) field, intervals); } else if (SingleValueFieldDescriptor.UtilDateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValueFieldDescriptor.UtilDateFieldDescriptor) field, intervals); } else if (MultiValueFieldDescriptor.DateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValueFieldDescriptor.DateFieldDescriptor) field, intervals); } else if (MultiValueFieldDescriptor.UtilDateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValueFieldDescriptor.UtilDateFieldDescriptor) field, intervals); }if (MultiValuedComplexField.UtilDateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValuedComplexField.UtilDateComplexField) field, intervals); }if (SingleValuedComplexField.UtilDateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValuedComplexField.UtilDateComplexField) field, intervals); }if (MultiValuedComplexField.DateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValuedComplexField.DateComplexField) field, intervals); }if (SingleValuedComplexField.DateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValuedComplexField.DateComplexField) field, intervals); } else { throw new RuntimeException("Invalid interval query string definition: '"+query+"'"); } } else if (Number.class.isAssignableFrom(type)){ Interval.NumericInterval[] intervals = query.keySet().stream() .map(key -> intervalNumericFacetMapper(key, (FieldDescriptor<Number>) field, query.get(key))) .toArray(Interval.NumericInterval[]::new); return Facets.interval(facetName,(FieldDescriptor<Number>)field,intervals); } else { throw new RuntimeException("Invalid facet query string definition: '"+query+"'"); } } }
FacetMapper { public static <T> Facet stringQuery2FacetMapper(FieldDescriptor<T> field,String facetName, Map<String,String> query) { final String stringQuery = query.values().iterator().next(); Class<T> type = field.getType(); if (ComplexFieldDescriptor.class.isAssignableFrom(field.getClass())) { type = ((ComplexFieldDescriptor)field).getFacetType(); } if (query.size() == 1 && !intervalDateFacetMatcher(stringQuery) && !INTERVAL_NUMERIC_FACET.matcher(stringQuery).matches()) { return queryFacetMapper(facetName,field.getName(), stringQuery); } else { if (Date.class.isAssignableFrom(type) || ZonedDateTime.class.isAssignableFrom(type)) { Interval.DateMathInterval[] intervals = query.keySet().stream() .map(key -> intervalDateFacetMapper(key, query.get(key))) .toArray(Interval.DateMathInterval[]::new); if (SingleValueFieldDescriptor.DateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValueFieldDescriptor.DateFieldDescriptor) field, intervals); } else if (SingleValueFieldDescriptor.UtilDateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValueFieldDescriptor.UtilDateFieldDescriptor) field, intervals); } else if (MultiValueFieldDescriptor.DateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValueFieldDescriptor.DateFieldDescriptor) field, intervals); } else if (MultiValueFieldDescriptor.UtilDateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValueFieldDescriptor.UtilDateFieldDescriptor) field, intervals); }if (MultiValuedComplexField.UtilDateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValuedComplexField.UtilDateComplexField) field, intervals); }if (SingleValuedComplexField.UtilDateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValuedComplexField.UtilDateComplexField) field, intervals); }if (MultiValuedComplexField.DateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValuedComplexField.DateComplexField) field, intervals); }if (SingleValuedComplexField.DateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValuedComplexField.DateComplexField) field, intervals); } else { throw new RuntimeException("Invalid interval query string definition: '"+query+"'"); } } else if (Number.class.isAssignableFrom(type)){ Interval.NumericInterval[] intervals = query.keySet().stream() .map(key -> intervalNumericFacetMapper(key, (FieldDescriptor<Number>) field, query.get(key))) .toArray(Interval.NumericInterval[]::new); return Facets.interval(facetName,(FieldDescriptor<Number>)field,intervals); } else { throw new RuntimeException("Invalid facet query string definition: '"+query+"'"); } } } }
FacetMapper { public static <T> Facet stringQuery2FacetMapper(FieldDescriptor<T> field,String facetName, Map<String,String> query) { final String stringQuery = query.values().iterator().next(); Class<T> type = field.getType(); if (ComplexFieldDescriptor.class.isAssignableFrom(field.getClass())) { type = ((ComplexFieldDescriptor)field).getFacetType(); } if (query.size() == 1 && !intervalDateFacetMatcher(stringQuery) && !INTERVAL_NUMERIC_FACET.matcher(stringQuery).matches()) { return queryFacetMapper(facetName,field.getName(), stringQuery); } else { if (Date.class.isAssignableFrom(type) || ZonedDateTime.class.isAssignableFrom(type)) { Interval.DateMathInterval[] intervals = query.keySet().stream() .map(key -> intervalDateFacetMapper(key, query.get(key))) .toArray(Interval.DateMathInterval[]::new); if (SingleValueFieldDescriptor.DateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValueFieldDescriptor.DateFieldDescriptor) field, intervals); } else if (SingleValueFieldDescriptor.UtilDateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValueFieldDescriptor.UtilDateFieldDescriptor) field, intervals); } else if (MultiValueFieldDescriptor.DateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValueFieldDescriptor.DateFieldDescriptor) field, intervals); } else if (MultiValueFieldDescriptor.UtilDateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValueFieldDescriptor.UtilDateFieldDescriptor) field, intervals); }if (MultiValuedComplexField.UtilDateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValuedComplexField.UtilDateComplexField) field, intervals); }if (SingleValuedComplexField.UtilDateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValuedComplexField.UtilDateComplexField) field, intervals); }if (MultiValuedComplexField.DateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValuedComplexField.DateComplexField) field, intervals); }if (SingleValuedComplexField.DateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValuedComplexField.DateComplexField) field, intervals); } else { throw new RuntimeException("Invalid interval query string definition: '"+query+"'"); } } else if (Number.class.isAssignableFrom(type)){ Interval.NumericInterval[] intervals = query.keySet().stream() .map(key -> intervalNumericFacetMapper(key, (FieldDescriptor<Number>) field, query.get(key))) .toArray(Interval.NumericInterval[]::new); return Facets.interval(facetName,(FieldDescriptor<Number>)field,intervals); } else { throw new RuntimeException("Invalid facet query string definition: '"+query+"'"); } } } }
FacetMapper { public static <T> Facet stringQuery2FacetMapper(FieldDescriptor<T> field,String facetName, Map<String,String> query) { final String stringQuery = query.values().iterator().next(); Class<T> type = field.getType(); if (ComplexFieldDescriptor.class.isAssignableFrom(field.getClass())) { type = ((ComplexFieldDescriptor)field).getFacetType(); } if (query.size() == 1 && !intervalDateFacetMatcher(stringQuery) && !INTERVAL_NUMERIC_FACET.matcher(stringQuery).matches()) { return queryFacetMapper(facetName,field.getName(), stringQuery); } else { if (Date.class.isAssignableFrom(type) || ZonedDateTime.class.isAssignableFrom(type)) { Interval.DateMathInterval[] intervals = query.keySet().stream() .map(key -> intervalDateFacetMapper(key, query.get(key))) .toArray(Interval.DateMathInterval[]::new); if (SingleValueFieldDescriptor.DateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValueFieldDescriptor.DateFieldDescriptor) field, intervals); } else if (SingleValueFieldDescriptor.UtilDateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValueFieldDescriptor.UtilDateFieldDescriptor) field, intervals); } else if (MultiValueFieldDescriptor.DateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValueFieldDescriptor.DateFieldDescriptor) field, intervals); } else if (MultiValueFieldDescriptor.UtilDateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValueFieldDescriptor.UtilDateFieldDescriptor) field, intervals); }if (MultiValuedComplexField.UtilDateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValuedComplexField.UtilDateComplexField) field, intervals); }if (SingleValuedComplexField.UtilDateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValuedComplexField.UtilDateComplexField) field, intervals); }if (MultiValuedComplexField.DateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValuedComplexField.DateComplexField) field, intervals); }if (SingleValuedComplexField.DateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValuedComplexField.DateComplexField) field, intervals); } else { throw new RuntimeException("Invalid interval query string definition: '"+query+"'"); } } else if (Number.class.isAssignableFrom(type)){ Interval.NumericInterval[] intervals = query.keySet().stream() .map(key -> intervalNumericFacetMapper(key, (FieldDescriptor<Number>) field, query.get(key))) .toArray(Interval.NumericInterval[]::new); return Facets.interval(facetName,(FieldDescriptor<Number>)field,intervals); } else { throw new RuntimeException("Invalid facet query string definition: '"+query+"'"); } } } static Facet stringQuery2FacetMapper(FieldDescriptor<T> field,String facetName, Map<String,String> query); static Interval<DateMathExpression> intervalDateFacetMapper(String name, String query); static Interval intervalNumericFacetMapper(String name, FieldDescriptor<T> field, String query); static Facet queryFacetMapper(String name, String fieldName, String query); }
FacetMapper { public static <T> Facet stringQuery2FacetMapper(FieldDescriptor<T> field,String facetName, Map<String,String> query) { final String stringQuery = query.values().iterator().next(); Class<T> type = field.getType(); if (ComplexFieldDescriptor.class.isAssignableFrom(field.getClass())) { type = ((ComplexFieldDescriptor)field).getFacetType(); } if (query.size() == 1 && !intervalDateFacetMatcher(stringQuery) && !INTERVAL_NUMERIC_FACET.matcher(stringQuery).matches()) { return queryFacetMapper(facetName,field.getName(), stringQuery); } else { if (Date.class.isAssignableFrom(type) || ZonedDateTime.class.isAssignableFrom(type)) { Interval.DateMathInterval[] intervals = query.keySet().stream() .map(key -> intervalDateFacetMapper(key, query.get(key))) .toArray(Interval.DateMathInterval[]::new); if (SingleValueFieldDescriptor.DateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValueFieldDescriptor.DateFieldDescriptor) field, intervals); } else if (SingleValueFieldDescriptor.UtilDateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValueFieldDescriptor.UtilDateFieldDescriptor) field, intervals); } else if (MultiValueFieldDescriptor.DateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValueFieldDescriptor.DateFieldDescriptor) field, intervals); } else if (MultiValueFieldDescriptor.UtilDateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValueFieldDescriptor.UtilDateFieldDescriptor) field, intervals); }if (MultiValuedComplexField.UtilDateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValuedComplexField.UtilDateComplexField) field, intervals); }if (SingleValuedComplexField.UtilDateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValuedComplexField.UtilDateComplexField) field, intervals); }if (MultiValuedComplexField.DateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValuedComplexField.DateComplexField) field, intervals); }if (SingleValuedComplexField.DateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValuedComplexField.DateComplexField) field, intervals); } else { throw new RuntimeException("Invalid interval query string definition: '"+query+"'"); } } else if (Number.class.isAssignableFrom(type)){ Interval.NumericInterval[] intervals = query.keySet().stream() .map(key -> intervalNumericFacetMapper(key, (FieldDescriptor<Number>) field, query.get(key))) .toArray(Interval.NumericInterval[]::new); return Facets.interval(facetName,(FieldDescriptor<Number>)field,intervals); } else { throw new RuntimeException("Invalid facet query string definition: '"+query+"'"); } } } static Facet stringQuery2FacetMapper(FieldDescriptor<T> field,String facetName, Map<String,String> query); static Interval<DateMathExpression> intervalDateFacetMapper(String name, String query); static Interval intervalNumericFacetMapper(String name, FieldDescriptor<T> field, String query); static Facet queryFacetMapper(String name, String fieldName, String query); static final String SOLR_MATH_UNITS_GROUP; static final String SOLR_ROOT_UNITS_GROUP; }
@Test public void testComplexField() throws SyntaxError { HashMap<String, String> dateIntervals = new HashMap<>(); dateIntervals.put("after","[NOW+23DAYS/DAY TO *]"); dateIntervals.put("before","[* TO NOW+23DAYS/DAY]"); HashMap<String, String> numberIntervals = new HashMap<>(); numberIntervals.put("bigger","[23 TO *]"); numberIntervals.put("smaller","[* TO 22]"); SingleValuedComplexField.UtilDateComplexField<Taxonomy,Date,Date> complexDateField = new ComplexFieldDescriptorBuilder<Taxonomy,Date,Date>() .setFacet(true, tax -> Arrays.asList(tax.getDate())) .buildUtilDateComplexField("complexDateTax", Taxonomy.class, Date.class, Date.class); SingleValuedComplexField.NumericComplexField<Taxonomy,Number,Number> complexNumberField = new ComplexFieldDescriptorBuilder<Taxonomy,Number,Number>() .setFacet(true, tax -> Arrays.asList(tax.getTerm())) .buildNumericComplexField("complexNumberTax", Taxonomy.class, Number.class, Number.class); Assert.assertTrue(FacetMapper.stringQuery2FacetMapper(complexDateField, "dateFacet",dateIntervals).getName().equals("dateFacet")); Assert.assertTrue(FacetMapper.stringQuery2FacetMapper(complexNumberField, "numericFacet", numberIntervals).getName().equals("numericFacet")); Assert.assertTrue(true); }
public static <T> Facet stringQuery2FacetMapper(FieldDescriptor<T> field,String facetName, Map<String,String> query) { final String stringQuery = query.values().iterator().next(); Class<T> type = field.getType(); if (ComplexFieldDescriptor.class.isAssignableFrom(field.getClass())) { type = ((ComplexFieldDescriptor)field).getFacetType(); } if (query.size() == 1 && !intervalDateFacetMatcher(stringQuery) && !INTERVAL_NUMERIC_FACET.matcher(stringQuery).matches()) { return queryFacetMapper(facetName,field.getName(), stringQuery); } else { if (Date.class.isAssignableFrom(type) || ZonedDateTime.class.isAssignableFrom(type)) { Interval.DateMathInterval[] intervals = query.keySet().stream() .map(key -> intervalDateFacetMapper(key, query.get(key))) .toArray(Interval.DateMathInterval[]::new); if (SingleValueFieldDescriptor.DateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValueFieldDescriptor.DateFieldDescriptor) field, intervals); } else if (SingleValueFieldDescriptor.UtilDateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValueFieldDescriptor.UtilDateFieldDescriptor) field, intervals); } else if (MultiValueFieldDescriptor.DateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValueFieldDescriptor.DateFieldDescriptor) field, intervals); } else if (MultiValueFieldDescriptor.UtilDateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValueFieldDescriptor.UtilDateFieldDescriptor) field, intervals); }if (MultiValuedComplexField.UtilDateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValuedComplexField.UtilDateComplexField) field, intervals); }if (SingleValuedComplexField.UtilDateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValuedComplexField.UtilDateComplexField) field, intervals); }if (MultiValuedComplexField.DateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValuedComplexField.DateComplexField) field, intervals); }if (SingleValuedComplexField.DateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValuedComplexField.DateComplexField) field, intervals); } else { throw new RuntimeException("Invalid interval query string definition: '"+query+"'"); } } else if (Number.class.isAssignableFrom(type)){ Interval.NumericInterval[] intervals = query.keySet().stream() .map(key -> intervalNumericFacetMapper(key, (FieldDescriptor<Number>) field, query.get(key))) .toArray(Interval.NumericInterval[]::new); return Facets.interval(facetName,(FieldDescriptor<Number>)field,intervals); } else { throw new RuntimeException("Invalid facet query string definition: '"+query+"'"); } } }
FacetMapper { public static <T> Facet stringQuery2FacetMapper(FieldDescriptor<T> field,String facetName, Map<String,String> query) { final String stringQuery = query.values().iterator().next(); Class<T> type = field.getType(); if (ComplexFieldDescriptor.class.isAssignableFrom(field.getClass())) { type = ((ComplexFieldDescriptor)field).getFacetType(); } if (query.size() == 1 && !intervalDateFacetMatcher(stringQuery) && !INTERVAL_NUMERIC_FACET.matcher(stringQuery).matches()) { return queryFacetMapper(facetName,field.getName(), stringQuery); } else { if (Date.class.isAssignableFrom(type) || ZonedDateTime.class.isAssignableFrom(type)) { Interval.DateMathInterval[] intervals = query.keySet().stream() .map(key -> intervalDateFacetMapper(key, query.get(key))) .toArray(Interval.DateMathInterval[]::new); if (SingleValueFieldDescriptor.DateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValueFieldDescriptor.DateFieldDescriptor) field, intervals); } else if (SingleValueFieldDescriptor.UtilDateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValueFieldDescriptor.UtilDateFieldDescriptor) field, intervals); } else if (MultiValueFieldDescriptor.DateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValueFieldDescriptor.DateFieldDescriptor) field, intervals); } else if (MultiValueFieldDescriptor.UtilDateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValueFieldDescriptor.UtilDateFieldDescriptor) field, intervals); }if (MultiValuedComplexField.UtilDateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValuedComplexField.UtilDateComplexField) field, intervals); }if (SingleValuedComplexField.UtilDateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValuedComplexField.UtilDateComplexField) field, intervals); }if (MultiValuedComplexField.DateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValuedComplexField.DateComplexField) field, intervals); }if (SingleValuedComplexField.DateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValuedComplexField.DateComplexField) field, intervals); } else { throw new RuntimeException("Invalid interval query string definition: '"+query+"'"); } } else if (Number.class.isAssignableFrom(type)){ Interval.NumericInterval[] intervals = query.keySet().stream() .map(key -> intervalNumericFacetMapper(key, (FieldDescriptor<Number>) field, query.get(key))) .toArray(Interval.NumericInterval[]::new); return Facets.interval(facetName,(FieldDescriptor<Number>)field,intervals); } else { throw new RuntimeException("Invalid facet query string definition: '"+query+"'"); } } } }
FacetMapper { public static <T> Facet stringQuery2FacetMapper(FieldDescriptor<T> field,String facetName, Map<String,String> query) { final String stringQuery = query.values().iterator().next(); Class<T> type = field.getType(); if (ComplexFieldDescriptor.class.isAssignableFrom(field.getClass())) { type = ((ComplexFieldDescriptor)field).getFacetType(); } if (query.size() == 1 && !intervalDateFacetMatcher(stringQuery) && !INTERVAL_NUMERIC_FACET.matcher(stringQuery).matches()) { return queryFacetMapper(facetName,field.getName(), stringQuery); } else { if (Date.class.isAssignableFrom(type) || ZonedDateTime.class.isAssignableFrom(type)) { Interval.DateMathInterval[] intervals = query.keySet().stream() .map(key -> intervalDateFacetMapper(key, query.get(key))) .toArray(Interval.DateMathInterval[]::new); if (SingleValueFieldDescriptor.DateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValueFieldDescriptor.DateFieldDescriptor) field, intervals); } else if (SingleValueFieldDescriptor.UtilDateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValueFieldDescriptor.UtilDateFieldDescriptor) field, intervals); } else if (MultiValueFieldDescriptor.DateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValueFieldDescriptor.DateFieldDescriptor) field, intervals); } else if (MultiValueFieldDescriptor.UtilDateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValueFieldDescriptor.UtilDateFieldDescriptor) field, intervals); }if (MultiValuedComplexField.UtilDateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValuedComplexField.UtilDateComplexField) field, intervals); }if (SingleValuedComplexField.UtilDateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValuedComplexField.UtilDateComplexField) field, intervals); }if (MultiValuedComplexField.DateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValuedComplexField.DateComplexField) field, intervals); }if (SingleValuedComplexField.DateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValuedComplexField.DateComplexField) field, intervals); } else { throw new RuntimeException("Invalid interval query string definition: '"+query+"'"); } } else if (Number.class.isAssignableFrom(type)){ Interval.NumericInterval[] intervals = query.keySet().stream() .map(key -> intervalNumericFacetMapper(key, (FieldDescriptor<Number>) field, query.get(key))) .toArray(Interval.NumericInterval[]::new); return Facets.interval(facetName,(FieldDescriptor<Number>)field,intervals); } else { throw new RuntimeException("Invalid facet query string definition: '"+query+"'"); } } } }
FacetMapper { public static <T> Facet stringQuery2FacetMapper(FieldDescriptor<T> field,String facetName, Map<String,String> query) { final String stringQuery = query.values().iterator().next(); Class<T> type = field.getType(); if (ComplexFieldDescriptor.class.isAssignableFrom(field.getClass())) { type = ((ComplexFieldDescriptor)field).getFacetType(); } if (query.size() == 1 && !intervalDateFacetMatcher(stringQuery) && !INTERVAL_NUMERIC_FACET.matcher(stringQuery).matches()) { return queryFacetMapper(facetName,field.getName(), stringQuery); } else { if (Date.class.isAssignableFrom(type) || ZonedDateTime.class.isAssignableFrom(type)) { Interval.DateMathInterval[] intervals = query.keySet().stream() .map(key -> intervalDateFacetMapper(key, query.get(key))) .toArray(Interval.DateMathInterval[]::new); if (SingleValueFieldDescriptor.DateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValueFieldDescriptor.DateFieldDescriptor) field, intervals); } else if (SingleValueFieldDescriptor.UtilDateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValueFieldDescriptor.UtilDateFieldDescriptor) field, intervals); } else if (MultiValueFieldDescriptor.DateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValueFieldDescriptor.DateFieldDescriptor) field, intervals); } else if (MultiValueFieldDescriptor.UtilDateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValueFieldDescriptor.UtilDateFieldDescriptor) field, intervals); }if (MultiValuedComplexField.UtilDateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValuedComplexField.UtilDateComplexField) field, intervals); }if (SingleValuedComplexField.UtilDateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValuedComplexField.UtilDateComplexField) field, intervals); }if (MultiValuedComplexField.DateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValuedComplexField.DateComplexField) field, intervals); }if (SingleValuedComplexField.DateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValuedComplexField.DateComplexField) field, intervals); } else { throw new RuntimeException("Invalid interval query string definition: '"+query+"'"); } } else if (Number.class.isAssignableFrom(type)){ Interval.NumericInterval[] intervals = query.keySet().stream() .map(key -> intervalNumericFacetMapper(key, (FieldDescriptor<Number>) field, query.get(key))) .toArray(Interval.NumericInterval[]::new); return Facets.interval(facetName,(FieldDescriptor<Number>)field,intervals); } else { throw new RuntimeException("Invalid facet query string definition: '"+query+"'"); } } } static Facet stringQuery2FacetMapper(FieldDescriptor<T> field,String facetName, Map<String,String> query); static Interval<DateMathExpression> intervalDateFacetMapper(String name, String query); static Interval intervalNumericFacetMapper(String name, FieldDescriptor<T> field, String query); static Facet queryFacetMapper(String name, String fieldName, String query); }
FacetMapper { public static <T> Facet stringQuery2FacetMapper(FieldDescriptor<T> field,String facetName, Map<String,String> query) { final String stringQuery = query.values().iterator().next(); Class<T> type = field.getType(); if (ComplexFieldDescriptor.class.isAssignableFrom(field.getClass())) { type = ((ComplexFieldDescriptor)field).getFacetType(); } if (query.size() == 1 && !intervalDateFacetMatcher(stringQuery) && !INTERVAL_NUMERIC_FACET.matcher(stringQuery).matches()) { return queryFacetMapper(facetName,field.getName(), stringQuery); } else { if (Date.class.isAssignableFrom(type) || ZonedDateTime.class.isAssignableFrom(type)) { Interval.DateMathInterval[] intervals = query.keySet().stream() .map(key -> intervalDateFacetMapper(key, query.get(key))) .toArray(Interval.DateMathInterval[]::new); if (SingleValueFieldDescriptor.DateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValueFieldDescriptor.DateFieldDescriptor) field, intervals); } else if (SingleValueFieldDescriptor.UtilDateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValueFieldDescriptor.UtilDateFieldDescriptor) field, intervals); } else if (MultiValueFieldDescriptor.DateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValueFieldDescriptor.DateFieldDescriptor) field, intervals); } else if (MultiValueFieldDescriptor.UtilDateFieldDescriptor.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValueFieldDescriptor.UtilDateFieldDescriptor) field, intervals); }if (MultiValuedComplexField.UtilDateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValuedComplexField.UtilDateComplexField) field, intervals); }if (SingleValuedComplexField.UtilDateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValuedComplexField.UtilDateComplexField) field, intervals); }if (MultiValuedComplexField.DateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (MultiValuedComplexField.DateComplexField) field, intervals); }if (SingleValuedComplexField.DateComplexField.class.isAssignableFrom(field.getClass())) { return Facets.interval(facetName, (SingleValuedComplexField.DateComplexField) field, intervals); } else { throw new RuntimeException("Invalid interval query string definition: '"+query+"'"); } } else if (Number.class.isAssignableFrom(type)){ Interval.NumericInterval[] intervals = query.keySet().stream() .map(key -> intervalNumericFacetMapper(key, (FieldDescriptor<Number>) field, query.get(key))) .toArray(Interval.NumericInterval[]::new); return Facets.interval(facetName,(FieldDescriptor<Number>)field,intervals); } else { throw new RuntimeException("Invalid facet query string definition: '"+query+"'"); } } } static Facet stringQuery2FacetMapper(FieldDescriptor<T> field,String facetName, Map<String,String> query); static Interval<DateMathExpression> intervalDateFacetMapper(String name, String query); static Interval intervalNumericFacetMapper(String name, FieldDescriptor<T> field, String query); static Facet queryFacetMapper(String name, String fieldName, String query); static final String SOLR_MATH_UNITS_GROUP; static final String SOLR_ROOT_UNITS_GROUP; }
@Test @Ignore public void testGetDocument() throws Exception { MetadataProvider p = new RESTMetadataProvider( "https: "rbmh", "admin", "global", "1315204862832-1123067022", "asset", "user", "passw" ); Asset a = p.getObject("1359078847993-766700833",Asset.class); Assert.assertEquals("Sean Pettit - Portrait", a.getTitle()); Asset a2 = p.getObject(new Asset("1359078847993-766700833")); Assert.assertEquals("Sean Pettit - Portrait", a2.getTitle()); }
@Override public Document getDocument(Document document, DocumentFactory factory) throws IOException { HttpMethod request = new GetMethod(baseURL); request.addRequestHeader("Authorization", String.format("Bearer %s", bearerToken)); request.setPath(path + document.getId()); int status = client.executeMethod(request); if(status == 200) { JsonNode json = mapper.readValue(request.getResponseBody(), JsonNode.class); for(FieldDescriptor descriptor : factory.listFields()) { try { Object value = getValue(json, descriptor); if(value != null) { document.setValue(descriptor, value); } else LOG.warn("No data found for id {}", document.getId()); } catch (IOException e) { LOG.warn("Cannot use data for id {}: {}", document.getId(), e.getMessage()); } } return document; } else throw new IOException(request.getStatusText()); }
RESTMetadataProvider implements MetadataProvider { @Override public Document getDocument(Document document, DocumentFactory factory) throws IOException { HttpMethod request = new GetMethod(baseURL); request.addRequestHeader("Authorization", String.format("Bearer %s", bearerToken)); request.setPath(path + document.getId()); int status = client.executeMethod(request); if(status == 200) { JsonNode json = mapper.readValue(request.getResponseBody(), JsonNode.class); for(FieldDescriptor descriptor : factory.listFields()) { try { Object value = getValue(json, descriptor); if(value != null) { document.setValue(descriptor, value); } else LOG.warn("No data found for id {}", document.getId()); } catch (IOException e) { LOG.warn("Cannot use data for id {}: {}", document.getId(), e.getMessage()); } } return document; } else throw new IOException(request.getStatusText()); } }
RESTMetadataProvider implements MetadataProvider { @Override public Document getDocument(Document document, DocumentFactory factory) throws IOException { HttpMethod request = new GetMethod(baseURL); request.addRequestHeader("Authorization", String.format("Bearer %s", bearerToken)); request.setPath(path + document.getId()); int status = client.executeMethod(request); if(status == 200) { JsonNode json = mapper.readValue(request.getResponseBody(), JsonNode.class); for(FieldDescriptor descriptor : factory.listFields()) { try { Object value = getValue(json, descriptor); if(value != null) { document.setValue(descriptor, value); } else LOG.warn("No data found for id {}", document.getId()); } catch (IOException e) { LOG.warn("Cannot use data for id {}: {}", document.getId(), e.getMessage()); } } return document; } else throw new IOException(request.getStatusText()); } RESTMetadataProvider(String baseURL, String tnt, String app, String ws, String fs, String type, String bearerToken); RESTMetadataProvider(String baseURL, String tnt, String app, String ws, String fs, String type, String username, String password); }
RESTMetadataProvider implements MetadataProvider { @Override public Document getDocument(Document document, DocumentFactory factory) throws IOException { HttpMethod request = new GetMethod(baseURL); request.addRequestHeader("Authorization", String.format("Bearer %s", bearerToken)); request.setPath(path + document.getId()); int status = client.executeMethod(request); if(status == 200) { JsonNode json = mapper.readValue(request.getResponseBody(), JsonNode.class); for(FieldDescriptor descriptor : factory.listFields()) { try { Object value = getValue(json, descriptor); if(value != null) { document.setValue(descriptor, value); } else LOG.warn("No data found for id {}", document.getId()); } catch (IOException e) { LOG.warn("Cannot use data for id {}: {}", document.getId(), e.getMessage()); } } return document; } else throw new IOException(request.getStatusText()); } RESTMetadataProvider(String baseURL, String tnt, String app, String ws, String fs, String type, String bearerToken); RESTMetadataProvider(String baseURL, String tnt, String app, String ws, String fs, String type, String username, String password); @Override Collection<Document> getDocuments(Collection<Document> documents, DocumentFactory factory); @Override Document getDocument(Document document, DocumentFactory factory); @Override Document getDocumentById(String id, DocumentFactory factory); @Override Collection<Document> getDocumentsByIds(Collection<String> ids, DocumentFactory factory); @Override T getObject(String id, Class<T> t); @Override Collection<T> getObjects(Collection<String> ids, Class<T> t); @Override T getObject(T o); @Override Collection<T> getObjects(Collection<T> os); }
RESTMetadataProvider implements MetadataProvider { @Override public Document getDocument(Document document, DocumentFactory factory) throws IOException { HttpMethod request = new GetMethod(baseURL); request.addRequestHeader("Authorization", String.format("Bearer %s", bearerToken)); request.setPath(path + document.getId()); int status = client.executeMethod(request); if(status == 200) { JsonNode json = mapper.readValue(request.getResponseBody(), JsonNode.class); for(FieldDescriptor descriptor : factory.listFields()) { try { Object value = getValue(json, descriptor); if(value != null) { document.setValue(descriptor, value); } else LOG.warn("No data found for id {}", document.getId()); } catch (IOException e) { LOG.warn("Cannot use data for id {}: {}", document.getId(), e.getMessage()); } } return document; } else throw new IOException(request.getStatusText()); } RESTMetadataProvider(String baseURL, String tnt, String app, String ws, String fs, String type, String bearerToken); RESTMetadataProvider(String baseURL, String tnt, String app, String ws, String fs, String type, String username, String password); @Override Collection<Document> getDocuments(Collection<Document> documents, DocumentFactory factory); @Override Document getDocument(Document document, DocumentFactory factory); @Override Document getDocumentById(String id, DocumentFactory factory); @Override Collection<Document> getDocumentsByIds(Collection<String> ids, DocumentFactory factory); @Override T getObject(String id, Class<T> t); @Override Collection<T> getObjects(Collection<String> ids, Class<T> t); @Override T getObject(T o); @Override Collection<T> getObjects(Collection<T> os); static final String ID; }
@Test @Ignore public void logTest(){ final ElasticWriter elasticWriter = new ElasticWriter("localhost", "9200", "logindex"); elasticWriter.log(new FullTextEntry()); }
@Override public void log(MonitoringEntry log) { logger.debug("Indexing log entry: {}", log.toJson()); elasticClient.put(log.toJson()); }
ElasticWriter extends MonitoringWriter { @Override public void log(MonitoringEntry log) { logger.debug("Indexing log entry: {}", log.toJson()); elasticClient.put(log.toJson()); } }
ElasticWriter extends MonitoringWriter { @Override public void log(MonitoringEntry log) { logger.debug("Indexing log entry: {}", log.toJson()); elasticClient.put(log.toJson()); } ElasticWriter(String elasticHost, String elasticPort, String elasticIndex); }
ElasticWriter extends MonitoringWriter { @Override public void log(MonitoringEntry log) { logger.debug("Indexing log entry: {}", log.toJson()); elasticClient.put(log.toJson()); } ElasticWriter(String elasticHost, String elasticPort, String elasticIndex); @Override void log(MonitoringEntry log); }
ElasticWriter extends MonitoringWriter { @Override public void log(MonitoringEntry log) { logger.debug("Indexing log entry: {}", log.toJson()); elasticClient.put(log.toJson()); } ElasticWriter(String elasticHost, String elasticPort, String elasticIndex); @Override void log(MonitoringEntry log); }
@Test public void setValuesTest() { Document doc = factory.createDoc("idTest"); doc.setValues("multipleStringField","1","2","3"); Collection<Object> values = new ArrayList<>(); values.add("4"); values.add("5"); doc.setValues("multipleStringField", values); Collection<Object> invalidValues = new ArrayList<>(); invalidValues.add("6"); invalidValues.add(7); exception.expect(IllegalArgumentException.class); doc.setValues("multipleStringField", invalidValues); doc.setValues("multipleStringField",1); }
public Document createDoc(String id) { return new DocumentImpl(id, this.type); }
DocumentFactory { public Document createDoc(String id) { return new DocumentImpl(id, this.type); } }
DocumentFactory { public Document createDoc(String id) { return new DocumentImpl(id, this.type); } protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields); protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields, Map<String, FieldDescriptor<?>> inverseSearchMetaFields); }
DocumentFactory { public Document createDoc(String id) { return new DocumentImpl(id, this.type); } protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields); protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields, Map<String, FieldDescriptor<?>> inverseSearchMetaFields); Collection<FieldDescriptor<?>> listFields(); boolean hasField(String name); FieldDescriptor getField(String name); FieldDescriptor getInverseSearchMetaField(String name); Map<String, FieldDescriptor<?>> getFields(); Map<String, FieldDescriptor<?>> getInverseSearchMetaFields(); Document createDoc(String id); String getType(); boolean isUpdatable(); InverseSearchQuery createInverseSearchQuery(String id, Filter query); @Override String toString(); }
DocumentFactory { public Document createDoc(String id) { return new DocumentImpl(id, this.type); } protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields); protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields, Map<String, FieldDescriptor<?>> inverseSearchMetaFields); Collection<FieldDescriptor<?>> listFields(); boolean hasField(String name); FieldDescriptor getField(String name); FieldDescriptor getInverseSearchMetaField(String name); Map<String, FieldDescriptor<?>> getFields(); Map<String, FieldDescriptor<?>> getInverseSearchMetaFields(); Document createDoc(String id); String getType(); boolean isUpdatable(); InverseSearchQuery createInverseSearchQuery(String id, Filter query); @Override String toString(); static final String ID; static final String TYPE; }
@Test public void addValueTest() { Document doc = factory.createDoc("idTest"); doc.addValue("multipleStringField", "0"); doc.addValue("multipleStringField", "4"); exception.expect(IllegalArgumentException.class); doc.addValue("singleStringField", "5"); doc.addValue("multipleStringField", 4); }
public Document createDoc(String id) { return new DocumentImpl(id, this.type); }
DocumentFactory { public Document createDoc(String id) { return new DocumentImpl(id, this.type); } }
DocumentFactory { public Document createDoc(String id) { return new DocumentImpl(id, this.type); } protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields); protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields, Map<String, FieldDescriptor<?>> inverseSearchMetaFields); }
DocumentFactory { public Document createDoc(String id) { return new DocumentImpl(id, this.type); } protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields); protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields, Map<String, FieldDescriptor<?>> inverseSearchMetaFields); Collection<FieldDescriptor<?>> listFields(); boolean hasField(String name); FieldDescriptor getField(String name); FieldDescriptor getInverseSearchMetaField(String name); Map<String, FieldDescriptor<?>> getFields(); Map<String, FieldDescriptor<?>> getInverseSearchMetaFields(); Document createDoc(String id); String getType(); boolean isUpdatable(); InverseSearchQuery createInverseSearchQuery(String id, Filter query); @Override String toString(); }
DocumentFactory { public Document createDoc(String id) { return new DocumentImpl(id, this.type); } protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields); protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields, Map<String, FieldDescriptor<?>> inverseSearchMetaFields); Collection<FieldDescriptor<?>> listFields(); boolean hasField(String name); FieldDescriptor getField(String name); FieldDescriptor getInverseSearchMetaField(String name); Map<String, FieldDescriptor<?>> getFields(); Map<String, FieldDescriptor<?>> getInverseSearchMetaFields(); Document createDoc(String id); String getType(); boolean isUpdatable(); InverseSearchQuery createInverseSearchQuery(String id, Filter query); @Override String toString(); static final String ID; static final String TYPE; }
@Test public void removeValueTest() { Document doc = factory.createDoc("idTest"); doc.setValues("multipleStringField","1","2","3"); doc.removeValue("multipleStringField","1"); exception.expect(IllegalArgumentException.class); doc.removeValue("multipleStringField",1); }
public Document createDoc(String id) { return new DocumentImpl(id, this.type); }
DocumentFactory { public Document createDoc(String id) { return new DocumentImpl(id, this.type); } }
DocumentFactory { public Document createDoc(String id) { return new DocumentImpl(id, this.type); } protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields); protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields, Map<String, FieldDescriptor<?>> inverseSearchMetaFields); }
DocumentFactory { public Document createDoc(String id) { return new DocumentImpl(id, this.type); } protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields); protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields, Map<String, FieldDescriptor<?>> inverseSearchMetaFields); Collection<FieldDescriptor<?>> listFields(); boolean hasField(String name); FieldDescriptor getField(String name); FieldDescriptor getInverseSearchMetaField(String name); Map<String, FieldDescriptor<?>> getFields(); Map<String, FieldDescriptor<?>> getInverseSearchMetaFields(); Document createDoc(String id); String getType(); boolean isUpdatable(); InverseSearchQuery createInverseSearchQuery(String id, Filter query); @Override String toString(); }
DocumentFactory { public Document createDoc(String id) { return new DocumentImpl(id, this.type); } protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields); protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields, Map<String, FieldDescriptor<?>> inverseSearchMetaFields); Collection<FieldDescriptor<?>> listFields(); boolean hasField(String name); FieldDescriptor getField(String name); FieldDescriptor getInverseSearchMetaField(String name); Map<String, FieldDescriptor<?>> getFields(); Map<String, FieldDescriptor<?>> getInverseSearchMetaFields(); Document createDoc(String id); String getType(); boolean isUpdatable(); InverseSearchQuery createInverseSearchQuery(String id, Filter query); @Override String toString(); static final String ID; static final String TYPE; }
@Test public void getValueTest() { Document doc = factory.createDoc("idTest"); doc.setValues("multipleStringField","1","2","3"); doc.setValue("singleStringField", "4"); Assert.assertEquals("get single value", doc.getValue("singleStringField"),"4"); exception.expect(IllegalArgumentException.class); doc.getValue("imaginaryField"); }
public Document createDoc(String id) { return new DocumentImpl(id, this.type); }
DocumentFactory { public Document createDoc(String id) { return new DocumentImpl(id, this.type); } }
DocumentFactory { public Document createDoc(String id) { return new DocumentImpl(id, this.type); } protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields); protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields, Map<String, FieldDescriptor<?>> inverseSearchMetaFields); }
DocumentFactory { public Document createDoc(String id) { return new DocumentImpl(id, this.type); } protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields); protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields, Map<String, FieldDescriptor<?>> inverseSearchMetaFields); Collection<FieldDescriptor<?>> listFields(); boolean hasField(String name); FieldDescriptor getField(String name); FieldDescriptor getInverseSearchMetaField(String name); Map<String, FieldDescriptor<?>> getFields(); Map<String, FieldDescriptor<?>> getInverseSearchMetaFields(); Document createDoc(String id); String getType(); boolean isUpdatable(); InverseSearchQuery createInverseSearchQuery(String id, Filter query); @Override String toString(); }
DocumentFactory { public Document createDoc(String id) { return new DocumentImpl(id, this.type); } protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields); protected DocumentFactory(String type,boolean updatable, Map<String, FieldDescriptor<?>> fields, Map<String, FieldDescriptor<?>> inverseSearchMetaFields); Collection<FieldDescriptor<?>> listFields(); boolean hasField(String name); FieldDescriptor getField(String name); FieldDescriptor getInverseSearchMetaField(String name); Map<String, FieldDescriptor<?>> getFields(); Map<String, FieldDescriptor<?>> getInverseSearchMetaFields(); Document createDoc(String id); String getType(); boolean isUpdatable(); InverseSearchQuery createInverseSearchQuery(String id, Filter query); @Override String toString(); static final String ID; static final String TYPE; }
@Test public void indexTest(){ server.clearIndex(); final DocumentFactoryBuilder docFactoryBuilder = new DocumentFactoryBuilder("TestDoc"); final FieldDescriptor descriptor = new FieldDescriptorBuilder().setFacet(true).buildTextField("title"); docFactoryBuilder.addField(descriptor); final DocumentFactory documents = docFactoryBuilder.build(); final Document doc1 = documents.createDoc("AA-2X3451") .setValue(descriptor, "The last ascent of man"); final Document doc2 = documents.createDoc("AA-2X6891") .setValue(descriptor, "Dawn of humanity: the COVID-19 chronicles"); final IndexResult indexResult = server.index(doc1,doc2); assertNotNull(indexResult); }
@Override public IndexResult index(Document... docs) { Asserts.notNull(docs,"Document to index should not be null."); Asserts.check(docs.length > 0, "Should be at least one document to index."); return indexMultipleDocuments(Arrays.asList(docs), -1); }
ElasticSearchServer extends SmartSearchServerBase { @Override public IndexResult index(Document... docs) { Asserts.notNull(docs,"Document to index should not be null."); Asserts.check(docs.length > 0, "Should be at least one document to index."); return indexMultipleDocuments(Arrays.asList(docs), -1); } }
ElasticSearchServer extends SmartSearchServerBase { @Override public IndexResult index(Document... docs) { Asserts.notNull(docs,"Document to index should not be null."); Asserts.check(docs.length > 0, "Should be at least one document to index."); return indexMultipleDocuments(Arrays.asList(docs), -1); } ElasticSearchServer(); ElasticSearchServer(ElasticVindClient client); protected ElasticSearchServer(ElasticVindClient client, boolean check); }
ElasticSearchServer extends SmartSearchServerBase { @Override public IndexResult index(Document... docs) { Asserts.notNull(docs,"Document to index should not be null."); Asserts.check(docs.length > 0, "Should be at least one document to index."); return indexMultipleDocuments(Arrays.asList(docs), -1); } ElasticSearchServer(); ElasticSearchServer(ElasticVindClient client); protected ElasticSearchServer(ElasticVindClient client, boolean check); @Override Object getBackend(); @Override StatusResult getBackendStatus(); @Override IndexResult index(Document... docs); @Override IndexResult index(List<Document> docs); @Override IndexResult indexWithin(Document doc, int withinMs); @Override IndexResult indexWithin(List<Document> docs, int withinMs); @Override DeleteResult delete(Document doc); @Override DeleteResult deleteWithin(Document doc, int withinMs); @Override boolean execute(Update update, DocumentFactory factory); @Override DeleteResult execute(Delete delete, DocumentFactory factory); @Override void commit(boolean optimize); @Override String getRawQuery(FulltextSearch search, DocumentFactory factory); @Override String getRawQuery(FulltextSearch search, Class<T> c); @Override SuggestionResult execute(ExecutableSuggestionSearch search, Class<T> c); @Override SuggestionResult execute(ExecutableSuggestionSearch search, DocumentFactory factory); @Override SuggestionResult execute(ExecutableSuggestionSearch search, DocumentFactory assets, DocumentFactory childFactory); @Override String getRawQuery(ExecutableSuggestionSearch search, DocumentFactory factory); @Override String getRawQuery(ExecutableSuggestionSearch search, DocumentFactory factory, DocumentFactory childFactory); @Override String getRawQuery(ExecutableSuggestionSearch search, Class<T> c); @Override BeanGetResult<T> execute(RealTimeGet search, Class<T> c); @Override GetResult execute(RealTimeGet search, DocumentFactory assets); @Override InverseSearchResult execute(InverseSearch inverseSearch, DocumentFactory documentFactory); @Override IndexResult addInverseSearchQuery(InverseSearchQuery query); @Override void clearIndex(); @Override void close(); @Override Class<? extends ServiceProvider> getServiceProviderClass(); }
ElasticSearchServer extends SmartSearchServerBase { @Override public IndexResult index(Document... docs) { Asserts.notNull(docs,"Document to index should not be null."); Asserts.check(docs.length > 0, "Should be at least one document to index."); return indexMultipleDocuments(Arrays.asList(docs), -1); } ElasticSearchServer(); ElasticSearchServer(ElasticVindClient client); protected ElasticSearchServer(ElasticVindClient client, boolean check); @Override Object getBackend(); @Override StatusResult getBackendStatus(); @Override IndexResult index(Document... docs); @Override IndexResult index(List<Document> docs); @Override IndexResult indexWithin(Document doc, int withinMs); @Override IndexResult indexWithin(List<Document> docs, int withinMs); @Override DeleteResult delete(Document doc); @Override DeleteResult deleteWithin(Document doc, int withinMs); @Override boolean execute(Update update, DocumentFactory factory); @Override DeleteResult execute(Delete delete, DocumentFactory factory); @Override void commit(boolean optimize); @Override String getRawQuery(FulltextSearch search, DocumentFactory factory); @Override String getRawQuery(FulltextSearch search, Class<T> c); @Override SuggestionResult execute(ExecutableSuggestionSearch search, Class<T> c); @Override SuggestionResult execute(ExecutableSuggestionSearch search, DocumentFactory factory); @Override SuggestionResult execute(ExecutableSuggestionSearch search, DocumentFactory assets, DocumentFactory childFactory); @Override String getRawQuery(ExecutableSuggestionSearch search, DocumentFactory factory); @Override String getRawQuery(ExecutableSuggestionSearch search, DocumentFactory factory, DocumentFactory childFactory); @Override String getRawQuery(ExecutableSuggestionSearch search, Class<T> c); @Override BeanGetResult<T> execute(RealTimeGet search, Class<T> c); @Override GetResult execute(RealTimeGet search, DocumentFactory assets); @Override InverseSearchResult execute(InverseSearch inverseSearch, DocumentFactory documentFactory); @Override IndexResult addInverseSearchQuery(InverseSearchQuery query); @Override void clearIndex(); @Override void close(); @Override Class<? extends ServiceProvider> getServiceProviderClass(); }
@Test public void deleteTest(){ server.clearIndex(); final DocumentFactoryBuilder docFactoryBuilder = new DocumentFactoryBuilder("TestDoc"); final SingleValueFieldDescriptor.TextFieldDescriptor<String> descriptor = new FieldDescriptorBuilder() .setFacet(true) .setFullText(true) .buildTextField("title"); docFactoryBuilder.addField(descriptor); final DocumentFactory documents = docFactoryBuilder.build(); final Document doc1 = documents.createDoc("AA-2X3451") .setValue(descriptor, "The last ascent of man"); final Document doc2 = documents.createDoc("AA-2X6891") .setValue(descriptor, "Dawn of humanity: the COVID-19 chronicles"); server.index(doc1,doc2); DeleteResult result = server.execute(new Delete(descriptor.equals("The last ascent of man")), documents); assertNotNull(result); SearchResult searchResult = server.execute(Search.fulltext(), documents); assertNotNull(searchResult); assertEquals(1, searchResult.getNumOfResults()); result = server.delete(doc2); assertNotNull(result); searchResult = server.execute(Search.fulltext(), documents); assertNotNull(searchResult); assertEquals(0, searchResult.getNumOfResults()); }
@Override public DeleteResult delete(Document doc) { return deleteWithin(doc, -1); }
ElasticSearchServer extends SmartSearchServerBase { @Override public DeleteResult delete(Document doc) { return deleteWithin(doc, -1); } }
ElasticSearchServer extends SmartSearchServerBase { @Override public DeleteResult delete(Document doc) { return deleteWithin(doc, -1); } ElasticSearchServer(); ElasticSearchServer(ElasticVindClient client); protected ElasticSearchServer(ElasticVindClient client, boolean check); }
ElasticSearchServer extends SmartSearchServerBase { @Override public DeleteResult delete(Document doc) { return deleteWithin(doc, -1); } ElasticSearchServer(); ElasticSearchServer(ElasticVindClient client); protected ElasticSearchServer(ElasticVindClient client, boolean check); @Override Object getBackend(); @Override StatusResult getBackendStatus(); @Override IndexResult index(Document... docs); @Override IndexResult index(List<Document> docs); @Override IndexResult indexWithin(Document doc, int withinMs); @Override IndexResult indexWithin(List<Document> docs, int withinMs); @Override DeleteResult delete(Document doc); @Override DeleteResult deleteWithin(Document doc, int withinMs); @Override boolean execute(Update update, DocumentFactory factory); @Override DeleteResult execute(Delete delete, DocumentFactory factory); @Override void commit(boolean optimize); @Override String getRawQuery(FulltextSearch search, DocumentFactory factory); @Override String getRawQuery(FulltextSearch search, Class<T> c); @Override SuggestionResult execute(ExecutableSuggestionSearch search, Class<T> c); @Override SuggestionResult execute(ExecutableSuggestionSearch search, DocumentFactory factory); @Override SuggestionResult execute(ExecutableSuggestionSearch search, DocumentFactory assets, DocumentFactory childFactory); @Override String getRawQuery(ExecutableSuggestionSearch search, DocumentFactory factory); @Override String getRawQuery(ExecutableSuggestionSearch search, DocumentFactory factory, DocumentFactory childFactory); @Override String getRawQuery(ExecutableSuggestionSearch search, Class<T> c); @Override BeanGetResult<T> execute(RealTimeGet search, Class<T> c); @Override GetResult execute(RealTimeGet search, DocumentFactory assets); @Override InverseSearchResult execute(InverseSearch inverseSearch, DocumentFactory documentFactory); @Override IndexResult addInverseSearchQuery(InverseSearchQuery query); @Override void clearIndex(); @Override void close(); @Override Class<? extends ServiceProvider> getServiceProviderClass(); }
ElasticSearchServer extends SmartSearchServerBase { @Override public DeleteResult delete(Document doc) { return deleteWithin(doc, -1); } ElasticSearchServer(); ElasticSearchServer(ElasticVindClient client); protected ElasticSearchServer(ElasticVindClient client, boolean check); @Override Object getBackend(); @Override StatusResult getBackendStatus(); @Override IndexResult index(Document... docs); @Override IndexResult index(List<Document> docs); @Override IndexResult indexWithin(Document doc, int withinMs); @Override IndexResult indexWithin(List<Document> docs, int withinMs); @Override DeleteResult delete(Document doc); @Override DeleteResult deleteWithin(Document doc, int withinMs); @Override boolean execute(Update update, DocumentFactory factory); @Override DeleteResult execute(Delete delete, DocumentFactory factory); @Override void commit(boolean optimize); @Override String getRawQuery(FulltextSearch search, DocumentFactory factory); @Override String getRawQuery(FulltextSearch search, Class<T> c); @Override SuggestionResult execute(ExecutableSuggestionSearch search, Class<T> c); @Override SuggestionResult execute(ExecutableSuggestionSearch search, DocumentFactory factory); @Override SuggestionResult execute(ExecutableSuggestionSearch search, DocumentFactory assets, DocumentFactory childFactory); @Override String getRawQuery(ExecutableSuggestionSearch search, DocumentFactory factory); @Override String getRawQuery(ExecutableSuggestionSearch search, DocumentFactory factory, DocumentFactory childFactory); @Override String getRawQuery(ExecutableSuggestionSearch search, Class<T> c); @Override BeanGetResult<T> execute(RealTimeGet search, Class<T> c); @Override GetResult execute(RealTimeGet search, DocumentFactory assets); @Override InverseSearchResult execute(InverseSearch inverseSearch, DocumentFactory documentFactory); @Override IndexResult addInverseSearchQuery(InverseSearchQuery query); @Override void clearIndex(); @Override void close(); @Override Class<? extends ServiceProvider> getServiceProviderClass(); }
@Test public void configurationIsDeployedTest() throws IOException { assertTrue(service.configurationIsDeployed("com.rbmhtechnology.solr.test:test-config:1.0")); assertFalse(service.configurationIsDeployed("com.rbmhtechnology.solr.test:wrong-config:1.0")); }
protected boolean configurationIsDeployed(String configName) throws IOException { logger.debug("Checking if config '{}' is present", configName); ConfigSetAdminRequest.List list = new ConfigSetAdminRequest.List(); try (CloudSolrClient client = createCloudSolrClient()) { final ConfigSetAdminResponse.List configList = list.process(client); final List<String> configSets = configList.getConfigSets(); return configSets.contains(configName); } catch (SolrServerException | IOException e) { throw new IOException("Cannot list config sets", e); } }
CollectionManagementService { protected boolean configurationIsDeployed(String configName) throws IOException { logger.debug("Checking if config '{}' is present", configName); ConfigSetAdminRequest.List list = new ConfigSetAdminRequest.List(); try (CloudSolrClient client = createCloudSolrClient()) { final ConfigSetAdminResponse.List configList = list.process(client); final List<String> configSets = configList.getConfigSets(); return configSets.contains(configName); } catch (SolrServerException | IOException e) { throw new IOException("Cannot list config sets", e); } } }
CollectionManagementService { protected boolean configurationIsDeployed(String configName) throws IOException { logger.debug("Checking if config '{}' is present", configName); ConfigSetAdminRequest.List list = new ConfigSetAdminRequest.List(); try (CloudSolrClient client = createCloudSolrClient()) { final ConfigSetAdminResponse.List configList = list.process(client); final List<String> configSets = configList.getConfigSets(); return configSets.contains(configName); } catch (SolrServerException | IOException e) { throw new IOException("Cannot list config sets", e); } } CollectionManagementService(List<String> zkHosts); CollectionManagementService(List<String> zkHost, String ... repositories); protected CollectionManagementService(String ... repositories); }
CollectionManagementService { protected boolean configurationIsDeployed(String configName) throws IOException { logger.debug("Checking if config '{}' is present", configName); ConfigSetAdminRequest.List list = new ConfigSetAdminRequest.List(); try (CloudSolrClient client = createCloudSolrClient()) { final ConfigSetAdminResponse.List configList = list.process(client); final List<String> configSets = configList.getConfigSets(); return configSets.contains(configName); } catch (SolrServerException | IOException e) { throw new IOException("Cannot list config sets", e); } } CollectionManagementService(List<String> zkHosts); CollectionManagementService(List<String> zkHost, String ... repositories); protected CollectionManagementService(String ... repositories); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas, Boolean autoAddReplicas); boolean collectionExists(String collectionName); void updateCollection(String collectionName, String configName); void updateCollection(String collectionName, String configName, Integer numOfShards, Integer numOfReplicas, Boolean autoAddReplicas); Long getVersionAndInstallIfNecessary(String dependency); }
CollectionManagementService { protected boolean configurationIsDeployed(String configName) throws IOException { logger.debug("Checking if config '{}' is present", configName); ConfigSetAdminRequest.List list = new ConfigSetAdminRequest.List(); try (CloudSolrClient client = createCloudSolrClient()) { final ConfigSetAdminResponse.List configList = list.process(client); final List<String> configSets = configList.getConfigSets(); return configSets.contains(configName); } catch (SolrServerException | IOException e) { throw new IOException("Cannot list config sets", e); } } CollectionManagementService(List<String> zkHosts); CollectionManagementService(List<String> zkHost, String ... repositories); protected CollectionManagementService(String ... repositories); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas); void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas, Boolean autoAddReplicas); boolean collectionExists(String collectionName); void updateCollection(String collectionName, String configName); void updateCollection(String collectionName, String configName, Integer numOfShards, Integer numOfReplicas, Boolean autoAddReplicas); Long getVersionAndInstallIfNecessary(String dependency); }
@Test public void testMacroContext() throws Exception { final MacroContext context = new MacroContext("A=a1, B=b1"); assertThat(context.getValue("A"), equalTo("a1")); assertThat(context.getValue("B"), equalTo("b1")); context.pushMacros("A=a2"); assertThat(context.getValue("A"), equalTo("a2")); assertThat(context.getValue("B"), equalTo("b1")); context.pushMacros("B=b2"); assertThat(context.getValue("A"), equalTo("a2")); assertThat(context.getValue("B"), equalTo("b2")); context.popMacros(); assertThat(context.getValue("A"), equalTo("a2")); assertThat(context.getValue("B"), equalTo("b1")); context.popMacros(); assertThat(context.getValue("A"), equalTo("a1")); assertThat(context.getValue("B"), equalTo("b1")); }
public MacroContext(final String names_and_values) throws Exception { pushMacros(names_and_values); }
MacroContext implements MacroValueProvider { public MacroContext(final String names_and_values) throws Exception { pushMacros(names_and_values); } }
MacroContext implements MacroValueProvider { public MacroContext(final String names_and_values) throws Exception { pushMacros(names_and_values); } MacroContext(final String names_and_values); }
MacroContext implements MacroValueProvider { public MacroContext(final String names_and_values) throws Exception { pushMacros(names_and_values); } MacroContext(final String names_and_values); void pushMacros(final String names_and_values); void popMacros(); @Override String getValue(final String name); String resolveMacros(final String text); @Override String toString(); }
MacroContext implements MacroValueProvider { public MacroContext(final String names_and_values) throws Exception { pushMacros(names_and_values); } MacroContext(final String names_and_values); void pushMacros(final String names_and_values); void popMacros(); @Override String getValue(final String name); String resolveMacros(final String text); @Override String toString(); }
@Test public void testToString() { assertNotNull(ConfigPv.builder().build().toString()); assertNotNull(ConfigPv.builder().readbackPvName("a").build().toString()); assertNotNull(ConfigPv.builder().readbackPvName("").build().toString()); }
@Override public String toString() { return new StringBuffer() .append("PV name=").append(pvName) .append(", readback PV name=").append(readbackPvName) .append(", readOnly=").append(readOnly) .toString(); }
ConfigPv implements Comparable<ConfigPv> { @Override public String toString() { return new StringBuffer() .append("PV name=").append(pvName) .append(", readback PV name=").append(readbackPvName) .append(", readOnly=").append(readOnly) .toString(); } }
ConfigPv implements Comparable<ConfigPv> { @Override public String toString() { return new StringBuffer() .append("PV name=").append(pvName) .append(", readback PV name=").append(readbackPvName) .append(", readOnly=").append(readOnly) .toString(); } }
ConfigPv implements Comparable<ConfigPv> { @Override public String toString() { return new StringBuffer() .append("PV name=").append(pvName) .append(", readback PV name=").append(readbackPvName) .append(", readOnly=").append(readOnly) .toString(); } @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); @Override int compareTo(ConfigPv other); }
ConfigPv implements Comparable<ConfigPv> { @Override public String toString() { return new StringBuffer() .append("PV name=").append(pvName) .append(", readback PV name=").append(readbackPvName) .append(", readOnly=").append(readOnly) .toString(); } @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); @Override int compareTo(ConfigPv other); }
@Test public void testCompareTo(){ ConfigPv configPV1 = ConfigPv.builder().pvName("a").readbackPvName("b").readOnly(true).build(); ConfigPv configPV2 = ConfigPv.builder().pvName("a").readbackPvName("b").readOnly(true).build(); ConfigPv configPV3 = ConfigPv.builder().pvName("b").readbackPvName("b").readOnly(true).build(); assertTrue(configPV1.compareTo(configPV2) == 0); assertTrue(configPV1.compareTo(configPV3) < 0); assertTrue(configPV3.compareTo(configPV1) > 0); }
@Override public int compareTo(ConfigPv other) { return pvName.compareTo(other.getPvName()); }
ConfigPv implements Comparable<ConfigPv> { @Override public int compareTo(ConfigPv other) { return pvName.compareTo(other.getPvName()); } }
ConfigPv implements Comparable<ConfigPv> { @Override public int compareTo(ConfigPv other) { return pvName.compareTo(other.getPvName()); } }
ConfigPv implements Comparable<ConfigPv> { @Override public int compareTo(ConfigPv other) { return pvName.compareTo(other.getPvName()); } @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); @Override int compareTo(ConfigPv other); }
ConfigPv implements Comparable<ConfigPv> { @Override public int compareTo(ConfigPv other) { return pvName.compareTo(other.getPvName()); } @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); @Override int compareTo(ConfigPv other); }
@Test public void testToString() { SnapshotItem item = SnapshotItem.builder() .configPv(ConfigPv.builder().pvName("pvname").build()) .build(); assertNotNull(item.toString()); item.setValue(VType.toVType(1)); assertNotNull(item.toString()); item.setReadbackValue(VType.toVType(1.1)); assertNotNull(item.toString()); assertFalse(item.toString().contains("READ FAILED")); }
@Override public String toString() { return new StringBuffer() .append("value=") .append(value != null ? value.toString() : "READ FAILED") .append(", config pv=").append(configPv.toString()) .append(readbackValue != null ? (", readback pv=" + readbackValue.toString()) : (", readback pv=READ_FAILED")) .toString(); }
SnapshotItem { @Override public String toString() { return new StringBuffer() .append("value=") .append(value != null ? value.toString() : "READ FAILED") .append(", config pv=").append(configPv.toString()) .append(readbackValue != null ? (", readback pv=" + readbackValue.toString()) : (", readback pv=READ_FAILED")) .toString(); } }
SnapshotItem { @Override public String toString() { return new StringBuffer() .append("value=") .append(value != null ? value.toString() : "READ FAILED") .append(", config pv=").append(configPv.toString()) .append(readbackValue != null ? (", readback pv=" + readbackValue.toString()) : (", readback pv=READ_FAILED")) .toString(); } }
SnapshotItem { @Override public String toString() { return new StringBuffer() .append("value=") .append(value != null ? value.toString() : "READ FAILED") .append(", config pv=").append(configPv.toString()) .append(readbackValue != null ? (", readback pv=" + readbackValue.toString()) : (", readback pv=READ_FAILED")) .toString(); } @Override String toString(); }
SnapshotItem { @Override public String toString() { return new StringBuffer() .append("value=") .append(value != null ? value.toString() : "READ FAILED") .append(", config pv=").append(configPv.toString()) .append(readbackValue != null ? (", readback pv=" + readbackValue.toString()) : (", readback pv=READ_FAILED")) .toString(); } @Override String toString(); }
@Test public void TestMultiplyDouble() { assertEquals(0d, SafeMultiply.multiply(3d, 0d)); assertEquals(18d, SafeMultiply.multiply(3d, 6d)); assertEquals(-18d, SafeMultiply.multiply(-3d, 6d)); assertEquals(18d, SafeMultiply.multiply(-3d, -6d)); assertEquals(Double.MAX_VALUE, SafeMultiply.multiply(Double.MAX_VALUE, 6d)); assertEquals(-Double.MAX_VALUE, SafeMultiply.multiply(-Double.MAX_VALUE, 6d)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestMultiplyFloat() { assertEquals(0f, SafeMultiply.multiply(3f, 0f)); assertEquals(18f, SafeMultiply.multiply(3f, 6f)); assertEquals(-18f, SafeMultiply.multiply(-3f, 6f)); assertEquals(18f, SafeMultiply.multiply(-3f, -6f)); assertEquals(Float.MAX_VALUE, SafeMultiply.multiply(Float.MAX_VALUE, 6f)); assertEquals(-Float.MAX_VALUE, SafeMultiply.multiply(-Float.MAX_VALUE, 6f)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestMultiplyULong() { final BigInteger ULONG_MAX = BigInteger.valueOf(9223372036854775807L).multiply(BigInteger.valueOf(2)).add(BigInteger.valueOf(1)); assertEquals(ULong.valueOf(0), SafeMultiply.multiply(ULong.valueOf(3), ULong.valueOf(0))); assertEquals(ULong.valueOf(18), SafeMultiply.multiply(ULong.valueOf(3), ULong.valueOf(6))); assertEquals(ULong.valueOf(ULONG_MAX.longValue()), SafeMultiply.multiply(ULong.valueOf(Long.MAX_VALUE), ULong.valueOf(6))); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestMultiplyLong() { assertEquals(0L, SafeMultiply.multiply(3L, 0L)); assertEquals(18L, SafeMultiply.multiply(3L, 6L)); assertEquals(-18L, SafeMultiply.multiply(-3L, 6L)); assertEquals(18L, SafeMultiply.multiply(-3L, -6L)); assertEquals(Long.MAX_VALUE, SafeMultiply.multiply(Long.MAX_VALUE, 6L)); assertEquals(Long.MIN_VALUE, SafeMultiply.multiply(Long.MIN_VALUE, 6L)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestMultiplyUInteger() { final long UINT_MAX = 4294967295L; assertEquals(UInteger.valueOf(0), SafeMultiply.multiply(UInteger.valueOf(3), UInteger.valueOf(0))); assertEquals(UInteger.valueOf(18), SafeMultiply.multiply(UInteger.valueOf(3), UInteger.valueOf(6))); assertEquals(UInteger.valueOf((int) UINT_MAX), SafeMultiply.multiply(UInteger.valueOf(Integer.MAX_VALUE), UInteger.valueOf(6))); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestMultiplyInteger() { assertEquals(0, SafeMultiply.multiply(3, 0)); assertEquals(18, SafeMultiply.multiply(3, 6)); assertEquals(-18, SafeMultiply.multiply(-3, 6)); assertEquals(18, SafeMultiply.multiply(-3, -6)); assertEquals(Integer.MAX_VALUE, SafeMultiply.multiply(Integer.MAX_VALUE, 6)); assertEquals(Integer.MIN_VALUE, SafeMultiply.multiply(Integer.MIN_VALUE, 6)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestMultiplyUShort() { final int USHORT_MAX = 65535; assertEquals(UShort.valueOf(Short.parseShort("0")), SafeMultiply.multiply(UShort.valueOf(Short.parseShort("3")), UShort.valueOf(Short.parseShort("0")))); assertEquals(UShort.valueOf(Short.parseShort("18")), SafeMultiply.multiply(UShort.valueOf(Short.parseShort("3")), UShort.valueOf(Short.parseShort("6")))); assertEquals(UShort.valueOf((short) USHORT_MAX), SafeMultiply.multiply(UShort.valueOf(Short.MAX_VALUE), UShort.valueOf(Short.parseShort("6")))); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void testDeleteConfiguration() { services.deleteNode("a"); verify(nodeDAO, atLeast(1)).deleteNode("a"); reset(nodeDAO); }
@Override @Transactional public void deleteNode(String nodeId) { logger.info("Deleting node id={}", nodeId); nodeDAO.deleteNode(nodeId); }
Services implements IServices { @Override @Transactional public void deleteNode(String nodeId) { logger.info("Deleting node id={}", nodeId); nodeDAO.deleteNode(nodeId); } }
Services implements IServices { @Override @Transactional public void deleteNode(String nodeId) { logger.info("Deleting node id={}", nodeId); nodeDAO.deleteNode(nodeId); } }
Services implements IServices { @Override @Transactional public void deleteNode(String nodeId) { logger.info("Deleting node id={}", nodeId); nodeDAO.deleteNode(nodeId); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName, String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
Services implements IServices { @Override @Transactional public void deleteNode(String nodeId) { logger.info("Deleting node id={}", nodeId); nodeDAO.deleteNode(nodeId); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName, String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
@Test public void TestMultiplyShort() { assertEquals(Short.valueOf("0"), SafeMultiply.multiply(Short.valueOf("3"), Short.valueOf("0"))); assertEquals(Short.valueOf("18"), SafeMultiply.multiply(Short.valueOf("3"), Short.valueOf("6"))); assertEquals(Short.valueOf("-18"), SafeMultiply.multiply(Short.valueOf("-3"), Short.valueOf("6"))); assertEquals(Short.valueOf("18"), SafeMultiply.multiply(Short.valueOf("-3"), Short.valueOf("-6"))); assertEquals(Short.MAX_VALUE, SafeMultiply.multiply(Short.MAX_VALUE, Short.valueOf("6"))); assertEquals(Short.MIN_VALUE, SafeMultiply.multiply(Short.MIN_VALUE, Short.valueOf("6"))); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestMultiplyUByte() { final int UBYTE_MAX = 255; assertEquals(UByte.valueOf(Byte.parseByte("0")), SafeMultiply.multiply(UByte.valueOf(Byte.parseByte("3")), UByte.valueOf(Byte.parseByte("0")))); assertEquals(UByte.valueOf(Byte.parseByte("18")), SafeMultiply.multiply(UByte.valueOf(Byte.parseByte("3")), UByte.valueOf(Byte.parseByte("6")))); assertEquals(UByte.valueOf((byte) UBYTE_MAX), SafeMultiply.multiply(UByte.valueOf(Byte.MAX_VALUE), UByte.valueOf(Byte.parseByte("6")))); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestMultiplyByte() { assertEquals(Byte.valueOf("0"), SafeMultiply.multiply(Byte.valueOf("3"), Byte.valueOf("0"))); assertEquals(Byte.valueOf("18"), SafeMultiply.multiply(Byte.valueOf("3"), Byte.valueOf("6"))); assertEquals(Byte.valueOf("-18"), SafeMultiply.multiply(Byte.valueOf("-3"), Byte.valueOf("6"))); assertEquals(Byte.valueOf("18"), SafeMultiply.multiply(Byte.valueOf("-3"), Byte.valueOf("-6"))); assertEquals(Byte.MAX_VALUE, SafeMultiply.multiply(Byte.MAX_VALUE, Byte.valueOf("6"))); assertEquals(Byte.MIN_VALUE, SafeMultiply.multiply(Byte.MIN_VALUE, Byte.valueOf("6"))); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestMultiplyWithDouble() { assertEquals(18d, SafeMultiply.multiply(6d, 3d)); assertEquals(-18d, SafeMultiply.multiply(6d, -3d)); assertEquals(-18d, SafeMultiply.multiply(-6d, 3d)); assertEquals(18f, SafeMultiply.multiply(6f, 3d)); assertEquals(-18f, SafeMultiply.multiply(6f, -3d)); assertEquals(-18f, SafeMultiply.multiply(-6f, 3d)); assertEquals(ULong.valueOf(0), SafeMultiply.multiply(ULong.valueOf(0), 3d)); assertEquals(ULong.valueOf(18), SafeMultiply.multiply(ULong.valueOf(6), 3d)); assertEquals(18L, SafeMultiply.multiply(6L, 3d)); assertEquals(-18L, SafeMultiply.multiply(6L, -3d)); assertEquals(-18L, SafeMultiply.multiply(-6L, 3d)); assertEquals(UInteger.valueOf(0), SafeMultiply.multiply(UInteger.valueOf(0), 3d)); assertEquals(UInteger.valueOf(18), SafeMultiply.multiply(UInteger.valueOf(6), 3d)); assertEquals(18, SafeMultiply.multiply(6, 3d)); assertEquals(-18, SafeMultiply.multiply(6, -3d)); assertEquals(-18, SafeMultiply.multiply(-6, 3d)); assertEquals(UShort.valueOf(Short.parseShort("0")), SafeMultiply.multiply(UShort.valueOf(Short.parseShort("0")), 3d)); assertEquals(UShort.valueOf(Short.parseShort("18")), SafeMultiply.multiply(UShort.valueOf(Short.parseShort("6")), 3d)); assertEquals(Short.parseShort("18"), SafeMultiply.multiply(Short.parseShort("6"), 3d)); assertEquals(Short.parseShort("-18"), SafeMultiply.multiply(Short.parseShort("6"), -3d)); assertEquals(Short.parseShort("-18"), SafeMultiply.multiply(Short.parseShort("-6"), 3d)); assertEquals(UByte.valueOf(Byte.parseByte("0")), SafeMultiply.multiply(UByte.valueOf(Byte.parseByte("0")), 3d)); assertEquals(UByte.valueOf(Byte.parseByte("18")), SafeMultiply.multiply(UByte.valueOf(Byte.parseByte("6")), 3d)); assertEquals(Byte.parseByte("18"), SafeMultiply.multiply(Byte.parseByte("6"), 3d)); assertEquals(Byte.parseByte("-18"), SafeMultiply.multiply(Byte.parseByte("6"), -3d)); assertEquals(Byte.parseByte("-18"), SafeMultiply.multiply(Byte.parseByte("-6"), 3d)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestMultiplyVDouble() { VDouble goodResult_1 = VDouble.of(Double.valueOf(0), alarm_1, time_1, display_1); VDouble goodResult_2 = VDouble.of(Double.valueOf(18), alarm_1, time_1, display_1); VDouble goodResult_3 = VDouble.of(Double.valueOf(-18), alarm_1, time_1, display_1); VDouble number_1 = VDouble.of(Double.valueOf(3), alarm_1, time_1, display_1); VDouble number_2 = VDouble.of(Double.valueOf(-3), alarm_1, time_1, display_1); VDouble multiplier_1 = VDouble.of(Double.valueOf(0), alarm_2, time_2, display_2); VDouble multiplier_2 = VDouble.of(Double.valueOf(6), alarm_2, time_2, display_2); VDouble multiplier_3 = VDouble.of(Double.valueOf(-6), alarm_2, time_2, display_2); VDouble posMax = VDouble.of(Double.MAX_VALUE, alarm_1, time_1, display_1); VDouble negMax = VDouble.of(-Double.MAX_VALUE, alarm_1, time_1, display_1); VNumber result = SafeMultiply.multiply(number_1, multiplier_1); assertTrue(Utilities.areVTypesIdentical(goodResult_1, result, true)); result = SafeMultiply.multiply(multiplier_1, number_1); assertFalse(Utilities.areVTypesIdentical(goodResult_1, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_1, result, false)); result = SafeMultiply.multiply(number_1, multiplier_2); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, true)); result = SafeMultiply.multiply(multiplier_2, number_1); assertFalse(Utilities.areVTypesIdentical(goodResult_2, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, false)); result = SafeMultiply.multiply(number_2, multiplier_3); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, true)); result = SafeMultiply.multiply(multiplier_3, number_2); assertFalse(Utilities.areVTypesIdentical(goodResult_2, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, false)); result = SafeMultiply.multiply(number_2, multiplier_2); assertTrue(Utilities.areVTypesIdentical(goodResult_3, result, true)); result = SafeMultiply.multiply(multiplier_2, number_2); assertFalse(Utilities.areVTypesIdentical(goodResult_3, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_3, result, false)); result = SafeMultiply.multiply(posMax, multiplier_2); assertTrue(Utilities.areVTypesIdentical(posMax, result, true)); result = SafeMultiply.multiply(multiplier_2, posMax); assertFalse(Utilities.areVTypesIdentical(posMax, result, true)); assertTrue(Utilities.areVTypesIdentical(posMax, result, false)); result = SafeMultiply.multiply(negMax, multiplier_2); assertTrue(Utilities.areVTypesIdentical(negMax, result, true)); result = SafeMultiply.multiply(multiplier_2, negMax); assertFalse(Utilities.areVTypesIdentical(negMax, result, true)); assertTrue(Utilities.areVTypesIdentical(negMax, result, false)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestMultiplyVFloat() { VFloat goodResult_1 = VFloat.of(Float.valueOf(0), alarm_1, time_1, display_1); VFloat goodResult_2 = VFloat.of(Float.valueOf(18), alarm_1, time_1, display_1); VFloat goodResult_3 = VFloat.of(Float.valueOf(-18), alarm_1, time_1, display_1); VFloat number_1 = VFloat.of(Float.valueOf(3), alarm_1, time_1, display_1); VFloat number_2 = VFloat.of(Float.valueOf(-3), alarm_1, time_1, display_1); VFloat multiplier_1 = VFloat.of(Float.valueOf(0), alarm_2, time_2, display_2); VFloat multiplier_2 = VFloat.of(Float.valueOf(6), alarm_2, time_2, display_2); VFloat multiplier_3 = VFloat.of(Float.valueOf(-6), alarm_2, time_2, display_2); VFloat posMax = VFloat.of(Float.MAX_VALUE, alarm_1, time_1, display_1); VFloat negMax = VFloat.of(-Float.MAX_VALUE, alarm_1, time_1, display_1); VNumber result = SafeMultiply.multiply(number_1, multiplier_1); assertTrue(Utilities.areVTypesIdentical(goodResult_1, result, true)); result = SafeMultiply.multiply(multiplier_1, number_1); assertFalse(Utilities.areVTypesIdentical(goodResult_1, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_1, result, false)); result = SafeMultiply.multiply(number_1, multiplier_2); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, true)); result = SafeMultiply.multiply(multiplier_2, number_1); assertFalse(Utilities.areVTypesIdentical(goodResult_2, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, false)); result = SafeMultiply.multiply(number_2, multiplier_3); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, true)); result = SafeMultiply.multiply(multiplier_3, number_2); assertFalse(Utilities.areVTypesIdentical(goodResult_2, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, false)); result = SafeMultiply.multiply(number_2, multiplier_2); assertTrue(Utilities.areVTypesIdentical(goodResult_3, result, true)); result = SafeMultiply.multiply(multiplier_2, number_2); assertFalse(Utilities.areVTypesIdentical(goodResult_3, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_3, result, false)); result = SafeMultiply.multiply(posMax, multiplier_2); assertTrue(Utilities.areVTypesIdentical(posMax, result, true)); result = SafeMultiply.multiply(multiplier_2, posMax); assertFalse(Utilities.areVTypesIdentical(posMax, result, true)); assertTrue(Utilities.areVTypesIdentical(posMax, result, false)); result = SafeMultiply.multiply(negMax, multiplier_2); assertTrue(Utilities.areVTypesIdentical(negMax, result, true)); result = SafeMultiply.multiply(multiplier_2, negMax); assertFalse(Utilities.areVTypesIdentical(negMax, result, true)); assertTrue(Utilities.areVTypesIdentical(negMax, result, false)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestMultiplyVULong() { final BigInteger ULONG_MAX = BigInteger.valueOf(9223372036854775807L).multiply(BigInteger.valueOf(2)).add(BigInteger.valueOf(1)); VULong goodResult_1 = VULong.of(ULong.valueOf(0), alarm_1, time_1, display_1); VULong goodResult_2 = VULong.of(ULong.valueOf(18), alarm_1, time_1, display_1); VULong number = VULong.of(ULong.valueOf(3), alarm_1, time_1, display_1); VULong multiplier_1 = VULong.of(ULong.valueOf(0), alarm_2, time_2, display_2); VULong multiplier_2 = VULong.of(ULong.valueOf(6), alarm_2, time_2, display_2); VULong maxValue = VULong.of(ULONG_MAX, alarm_1, time_1, display_1); VNumber result = SafeMultiply.multiply(number, multiplier_1); assertTrue(Utilities.areVTypesIdentical(goodResult_1, result, true)); result = SafeMultiply.multiply(multiplier_1, number); assertFalse(Utilities.areVTypesIdentical(goodResult_1, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_1, result, false)); result = SafeMultiply.multiply(number, multiplier_2); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, true)); result = SafeMultiply.multiply(multiplier_2, number); assertFalse(Utilities.areVTypesIdentical(goodResult_2, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, false)); result = SafeMultiply.multiply(maxValue, multiplier_2); assertTrue(Utilities.areVTypesIdentical(maxValue, result, true)); result = SafeMultiply.multiply(multiplier_2, maxValue); assertFalse(Utilities.areVTypesIdentical(maxValue, result, true)); assertTrue(Utilities.areVTypesIdentical(maxValue, result, false)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestMultiplyVLong() { VLong goodResult_1 = VLong.of(Long.valueOf(0), alarm_1, time_1, display_1); VLong goodResult_2 = VLong.of(Long.valueOf(18), alarm_1, time_1, display_1); VLong goodResult_3 = VLong.of(Long.valueOf(-18), alarm_1, time_1, display_1); VLong number_1 = VLong.of(Long.valueOf(3), alarm_1, time_1, display_1); VLong number_2 = VLong.of(Long.valueOf(-3), alarm_1, time_1, display_1); VLong multiplier_1 = VLong.of(Long.valueOf(0), alarm_2, time_2, display_2); VLong multiplier_2 = VLong.of(Long.valueOf(6), alarm_2, time_2, display_2); VLong multiplier_3 = VLong.of(Long.valueOf(-6), alarm_2, time_2, display_2); VLong posMax = VLong.of(Long.MAX_VALUE, alarm_1, time_1, display_1); VLong negMax = VLong.of(Long.MIN_VALUE, alarm_1, time_1, display_1); VNumber result = SafeMultiply.multiply(number_1, multiplier_1); assertTrue(Utilities.areVTypesIdentical(goodResult_1, result, true)); result = SafeMultiply.multiply(multiplier_1, number_1); assertFalse(Utilities.areVTypesIdentical(goodResult_1, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_1, result, false)); result = SafeMultiply.multiply(number_1, multiplier_2); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, true)); result = SafeMultiply.multiply(multiplier_2, number_1); assertFalse(Utilities.areVTypesIdentical(goodResult_2, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, false)); result = SafeMultiply.multiply(number_2, multiplier_3); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, true)); result = SafeMultiply.multiply(multiplier_3, number_2); assertFalse(Utilities.areVTypesIdentical(goodResult_2, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, false)); result = SafeMultiply.multiply(number_2, multiplier_2); assertTrue(Utilities.areVTypesIdentical(goodResult_3, result, true)); result = SafeMultiply.multiply(multiplier_2, number_2); assertFalse(Utilities.areVTypesIdentical(goodResult_3, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_3, result, false)); result = SafeMultiply.multiply(posMax, multiplier_2); assertTrue(Utilities.areVTypesIdentical(posMax, result, true)); result = SafeMultiply.multiply(multiplier_2, posMax); assertFalse(Utilities.areVTypesIdentical(posMax, result, true)); assertTrue(Utilities.areVTypesIdentical(posMax, result, false)); result = SafeMultiply.multiply(negMax, multiplier_2); assertTrue(Utilities.areVTypesIdentical(negMax, result, true)); result = SafeMultiply.multiply(multiplier_2, negMax); assertFalse(Utilities.areVTypesIdentical(negMax, result, true)); assertTrue(Utilities.areVTypesIdentical(negMax, result, false)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestMultiplyVUInt() { final long UINT_MAX = 4294967295L; VUInt goodResult_1 = VUInt.of(UInteger.valueOf(0), alarm_1, time_1, display_1); VUInt goodResult_2 = VUInt.of(UInteger.valueOf(18), alarm_1, time_1, display_1); VUInt number = VUInt.of(UInteger.valueOf(3), alarm_1, time_1, display_1); VUInt multiplier_1 = VUInt.of(UInteger.valueOf(0), alarm_2, time_2, display_2); VUInt multiplier_2 = VUInt.of(UInteger.valueOf(6), alarm_2, time_2, display_2); VUInt maxValue = VUInt.of(UINT_MAX, alarm_1, time_1, display_1); VNumber result = SafeMultiply.multiply(number, multiplier_1); assertTrue(Utilities.areVTypesIdentical(goodResult_1, result, true)); result = SafeMultiply.multiply(multiplier_1, number); assertFalse(Utilities.areVTypesIdentical(goodResult_1, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_1, result, false)); result = SafeMultiply.multiply(number, multiplier_2); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, true)); result = SafeMultiply.multiply(multiplier_2, number); assertFalse(Utilities.areVTypesIdentical(goodResult_2, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, false)); result = SafeMultiply.multiply(maxValue, multiplier_2); assertTrue(Utilities.areVTypesIdentical(maxValue, result, true)); result = SafeMultiply.multiply(multiplier_2, maxValue); assertFalse(Utilities.areVTypesIdentical(maxValue, result, true)); assertTrue(Utilities.areVTypesIdentical(maxValue, result, false)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestMultiplyVInt() { VInt goodResult_1 = VInt.of(0, alarm_1, time_1, display_1); VInt goodResult_2 = VInt.of(18, alarm_1, time_1, display_1); VInt goodResult_3 = VInt.of(-18, alarm_1, time_1, display_1); VInt number_1 = VInt.of(3, alarm_1, time_1, display_1); VInt number_2 = VInt.of(-3, alarm_1, time_1, display_1); VInt multiplier_1 = VInt.of(0, alarm_2, time_2, display_2); VInt multiplier_2 = VInt.of(6, alarm_2, time_2, display_2); VInt multiplier_3 = VInt.of(-6, alarm_2, time_2, display_2); VInt posMax = VInt.of(Integer.MAX_VALUE, alarm_1, time_1, display_1); VInt negMax = VInt.of(Integer.MIN_VALUE, alarm_1, time_1, display_1); VNumber result = SafeMultiply.multiply(number_1, multiplier_1); assertTrue(Utilities.areVTypesIdentical(goodResult_1, result, true)); result = SafeMultiply.multiply(multiplier_1, number_1); assertFalse(Utilities.areVTypesIdentical(goodResult_1, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_1, result, false)); result = SafeMultiply.multiply(number_1, multiplier_2); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, true)); result = SafeMultiply.multiply(multiplier_2, number_1); assertFalse(Utilities.areVTypesIdentical(goodResult_2, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, false)); result = SafeMultiply.multiply(number_2, multiplier_3); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, true)); result = SafeMultiply.multiply(multiplier_3, number_2); assertFalse(Utilities.areVTypesIdentical(goodResult_2, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, false)); result = SafeMultiply.multiply(number_2, multiplier_2); assertTrue(Utilities.areVTypesIdentical(goodResult_3, result, true)); result = SafeMultiply.multiply(multiplier_2, number_2); assertFalse(Utilities.areVTypesIdentical(goodResult_3, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_3, result, false)); result = SafeMultiply.multiply(posMax, multiplier_2); assertTrue(Utilities.areVTypesIdentical(posMax, result, true)); result = SafeMultiply.multiply(multiplier_2, posMax); assertFalse(Utilities.areVTypesIdentical(posMax, result, true)); assertTrue(Utilities.areVTypesIdentical(posMax, result, false)); result = SafeMultiply.multiply(negMax, multiplier_2); assertTrue(Utilities.areVTypesIdentical(negMax, result, true)); result = SafeMultiply.multiply(multiplier_2, negMax); assertFalse(Utilities.areVTypesIdentical(negMax, result, true)); assertTrue(Utilities.areVTypesIdentical(negMax, result, false)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void testDeleteFolder() { services.deleteNode("a"); verify(nodeDAO, atLeast(1)).deleteNode("a"); reset(nodeDAO); }
@Override @Transactional public void deleteNode(String nodeId) { logger.info("Deleting node id={}", nodeId); nodeDAO.deleteNode(nodeId); }
Services implements IServices { @Override @Transactional public void deleteNode(String nodeId) { logger.info("Deleting node id={}", nodeId); nodeDAO.deleteNode(nodeId); } }
Services implements IServices { @Override @Transactional public void deleteNode(String nodeId) { logger.info("Deleting node id={}", nodeId); nodeDAO.deleteNode(nodeId); } }
Services implements IServices { @Override @Transactional public void deleteNode(String nodeId) { logger.info("Deleting node id={}", nodeId); nodeDAO.deleteNode(nodeId); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName, String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
Services implements IServices { @Override @Transactional public void deleteNode(String nodeId) { logger.info("Deleting node id={}", nodeId); nodeDAO.deleteNode(nodeId); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName, String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
@Test public void TestMultiplyVUShort() { final int USHORT_MAX = 65535; VUShort goodResult_1 = VUShort.of(UShort.valueOf(Short.parseShort("0")), alarm_1, time_1, display_1); VUShort goodResult_2 = VUShort.of(UShort.valueOf(Short.parseShort("18")), alarm_1, time_1, display_1); VUShort number = VUShort.of(UShort.valueOf(Short.parseShort("3")), alarm_1, time_1, display_1); VUShort multiplier_1 = VUShort.of(UShort.valueOf(Short.parseShort("0")), alarm_2, time_2, display_2); VUShort multiplier_2 = VUShort.of(UShort.valueOf(Short.parseShort("6")), alarm_2, time_2, display_2); VUShort maxValue = VUShort.of(USHORT_MAX, alarm_1, time_1, display_1); VNumber result = SafeMultiply.multiply(number, multiplier_1); assertTrue(Utilities.areVTypesIdentical(goodResult_1, result, true)); result = SafeMultiply.multiply(multiplier_1, number); assertFalse(Utilities.areVTypesIdentical(goodResult_1, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_1, result, false)); result = SafeMultiply.multiply(number, multiplier_2); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, true)); result = SafeMultiply.multiply(multiplier_2, number); assertFalse(Utilities.areVTypesIdentical(goodResult_2, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, false)); result = SafeMultiply.multiply(maxValue, multiplier_2); assertTrue(Utilities.areVTypesIdentical(maxValue, result, true)); result = SafeMultiply.multiply(multiplier_2, maxValue); assertFalse(Utilities.areVTypesIdentical(maxValue, result, true)); assertTrue(Utilities.areVTypesIdentical(maxValue, result, false)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestMultiplyVShort() { VShort goodResult_1 = VShort.of(Short.valueOf("0"), alarm_1, time_1, display_1); VShort goodResult_2 = VShort.of(Short.valueOf("18"), alarm_1, time_1, display_1); VShort goodResult_3 = VShort.of(Short.valueOf("-18"), alarm_1, time_1, display_1); VShort number_1 = VShort.of(Short.valueOf("3"), alarm_1, time_1, display_1); VShort number_2 = VShort.of(Short.valueOf("-3"), alarm_1, time_1, display_1); VShort multiplier_1 = VShort.of(Short.valueOf("0"), alarm_2, time_2, display_2); VShort multiplier_2 = VShort.of(Short.valueOf("6"), alarm_2, time_2, display_2); VShort multiplier_3 = VShort.of(Short.valueOf("-6"), alarm_2, time_2, display_2); VShort posMax = VShort.of(Short.MAX_VALUE, alarm_1, time_1, display_1); VShort negMax = VShort.of(Short.MIN_VALUE, alarm_1, time_1, display_1); VNumber result = SafeMultiply.multiply(number_1, multiplier_1); assertTrue(Utilities.areVTypesIdentical(goodResult_1, result, true)); result = SafeMultiply.multiply(multiplier_1, number_1); assertFalse(Utilities.areVTypesIdentical(goodResult_1, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_1, result, false)); result = SafeMultiply.multiply(number_1, multiplier_2); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, true)); result = SafeMultiply.multiply(multiplier_2, number_1); assertFalse(Utilities.areVTypesIdentical(goodResult_2, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, false)); result = SafeMultiply.multiply(number_2, multiplier_3); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, true)); result = SafeMultiply.multiply(multiplier_3, number_2); assertFalse(Utilities.areVTypesIdentical(goodResult_2, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, false)); result = SafeMultiply.multiply(number_2, multiplier_2); assertTrue(Utilities.areVTypesIdentical(goodResult_3, result, true)); result = SafeMultiply.multiply(multiplier_2, number_2); assertFalse(Utilities.areVTypesIdentical(goodResult_3, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_3, result, false)); result = SafeMultiply.multiply(posMax, multiplier_2); assertTrue(Utilities.areVTypesIdentical(posMax, result, true)); result = SafeMultiply.multiply(multiplier_2, posMax); assertFalse(Utilities.areVTypesIdentical(posMax, result, true)); assertTrue(Utilities.areVTypesIdentical(posMax, result, false)); result = SafeMultiply.multiply(negMax, multiplier_2); assertTrue(Utilities.areVTypesIdentical(negMax, result, true)); result = SafeMultiply.multiply(multiplier_2, negMax); assertFalse(Utilities.areVTypesIdentical(negMax, result, true)); assertTrue(Utilities.areVTypesIdentical(negMax, result, false)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestMultiplyVUByte() { final int UBYTE_MAX = 255; VUByte goodResult_1 = VUByte.of(UByte.valueOf(Byte.parseByte("0")), alarm_1, time_1, display_1); VUByte goodResult_2 = VUByte.of(UByte.valueOf(Byte.parseByte("18")), alarm_1, time_1, display_1); VUByte number = VUByte.of(UByte.valueOf(Byte.parseByte("3")), alarm_1, time_1, display_1); VUByte multiplier_1 = VUByte.of(UByte.valueOf(Byte.parseByte("0")), alarm_2, time_2, display_2); VUByte multiplier_2 = VUByte.of(UByte.valueOf(Byte.parseByte("6")), alarm_2, time_2, display_2); VUByte maxValue = VUByte.of(UBYTE_MAX, alarm_1, time_1, display_1); VNumber result = SafeMultiply.multiply(number, multiplier_1); assertTrue(Utilities.areVTypesIdentical(goodResult_1, result, true)); result = SafeMultiply.multiply(multiplier_1, number); assertFalse(Utilities.areVTypesIdentical(goodResult_1, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_1, result, false)); result = SafeMultiply.multiply(number, multiplier_2); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, true)); result = SafeMultiply.multiply(multiplier_2, number); assertFalse(Utilities.areVTypesIdentical(goodResult_2, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, false)); result = SafeMultiply.multiply(maxValue, multiplier_2); assertTrue(Utilities.areVTypesIdentical(maxValue, result, true)); result = SafeMultiply.multiply(multiplier_2, maxValue); assertFalse(Utilities.areVTypesIdentical(maxValue, result, true)); assertTrue(Utilities.areVTypesIdentical(maxValue, result, false)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestMultiplyVByte() { VByte goodResult_1 = VByte.of(Byte.valueOf("0"), alarm_1, time_1, display_1); VByte goodResult_2 = VByte.of(Byte.valueOf("18"), alarm_1, time_1, display_1); VByte goodResult_3 = VByte.of(Byte.valueOf("-18"), alarm_1, time_1, display_1); VByte number_1 = VByte.of(Byte.valueOf("3"), alarm_1, time_1, display_1); VByte number_2 = VByte.of(Byte.valueOf("-3"), alarm_1, time_1, display_1); VByte multiplier_1 = VByte.of(Byte.valueOf("0"), alarm_2, time_2, display_2); VByte multiplier_2 = VByte.of(Byte.valueOf("6"), alarm_2, time_2, display_2); VByte multiplier_3 = VByte.of(Byte.valueOf("-6"), alarm_2, time_2, display_2); VByte posMax = VByte.of(Byte.MAX_VALUE, alarm_1, time_1, display_1); VByte negMax = VByte.of(Byte.MIN_VALUE, alarm_1, time_1, display_1); VNumber result = SafeMultiply.multiply(number_1, multiplier_1); assertTrue(Utilities.areVTypesIdentical(goodResult_1, result, true)); result = SafeMultiply.multiply(multiplier_1, number_1); assertFalse(Utilities.areVTypesIdentical(goodResult_1, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_1, result, false)); result = SafeMultiply.multiply(number_1, multiplier_2); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, true)); result = SafeMultiply.multiply(multiplier_2, number_1); assertFalse(Utilities.areVTypesIdentical(goodResult_2, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, false)); result = SafeMultiply.multiply(number_2, multiplier_3); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, true)); result = SafeMultiply.multiply(multiplier_3, number_2); assertFalse(Utilities.areVTypesIdentical(goodResult_2, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_2, result, false)); result = SafeMultiply.multiply(number_2, multiplier_2); assertTrue(Utilities.areVTypesIdentical(goodResult_3, result, true)); result = SafeMultiply.multiply(multiplier_2, number_2); assertFalse(Utilities.areVTypesIdentical(goodResult_3, result, true)); assertTrue(Utilities.areVTypesIdentical(goodResult_3, result, false)); result = SafeMultiply.multiply(posMax, multiplier_2); assertTrue(Utilities.areVTypesIdentical(posMax, result, true)); result = SafeMultiply.multiply(multiplier_2, posMax); assertFalse(Utilities.areVTypesIdentical(posMax, result, true)); assertTrue(Utilities.areVTypesIdentical(posMax, result, false)); result = SafeMultiply.multiply(negMax, multiplier_2); assertTrue(Utilities.areVTypesIdentical(negMax, result, true)); result = SafeMultiply.multiply(multiplier_2, negMax); assertFalse(Utilities.areVTypesIdentical(negMax, result, true)); assertTrue(Utilities.areVTypesIdentical(negMax, result, false)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestVDoubleArray() { final double multiplier = 2d; final List<Double> list = Arrays.asList(0.1d, 2.3d, 4.5d, 6.7d); ListDouble listDouble = new ListDouble() { @Override public double getDouble(int i) { return list.get(i); } @Override public int size() { return list.size(); } }; VDoubleArray doubleArray = VDoubleArray.of(listDouble, alarm_1, time_1, display_1); VNumberArray multipliedDoubleArray = SafeMultiply.multiply(doubleArray, multiplier); for (int index = 0; index < list.size(); index++) { assertTrue(Double.compare((Double) SafeMultiply.multiply(list.get(index), multiplier), multipliedDoubleArray.getData().getDouble(index)) == 0); } System.out.println("multiplier: " + multiplier); System.out.println(" Original: " + doubleArray); System.out.println("Multiplied: " + SafeMultiply.multiply(doubleArray, multiplier)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestVFloatArray() { final double multiplier = 2d; final List<Float> list = Arrays.asList(0.1f, 2.3f, 4.5f, 6.7f); ListFloat listFloat = new ListFloat() { @Override public float getFloat(int i) { return list.get(i); } @Override public int size() { return list.size(); } }; VFloatArray floatArray = VFloatArray.of(listFloat, alarm_1, time_1, display_1); VNumberArray multipliedFloatArray = SafeMultiply.multiply(floatArray, multiplier); for (int index = 0; index < list.size(); index++) { assertTrue(Float.compare((Float) SafeMultiply.multiply(list.get(index), multiplier), multipliedFloatArray.getData().getFloat(index)) == 0); } System.out.println("multiplier: " + multiplier); System.out.println(" Original: " + floatArray); System.out.println("Multiplied: " + SafeMultiply.multiply(floatArray, multiplier)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestVULongArray() { final double multiplier = 2d; final List<ULong> list = Arrays.asList(ULong.valueOf(0L), ULong.valueOf(1L), ULong.valueOf(2L), ULong.valueOf(3L)); ListULong listULong = new ListULong() { @Override public long getLong(int i) { return list.get(i).longValue(); } @Override public int size() { return list.size(); } }; VULongArray ulongArray = VULongArray.of(listULong, alarm_1, time_1, display_1); VNumberArray multipliedULongArray = SafeMultiply.multiply(ulongArray, multiplier); for (int index = 0; index < list.size(); index++) { assertTrue(Long.compareUnsigned(SafeMultiply.multiply(list.get(index), multiplier).longValue(), multipliedULongArray.getData().getLong(index)) == 0); } System.out.println("multiplier: " + multiplier); System.out.println(" Original: " + ulongArray); System.out.println("Multiplied: " + SafeMultiply.multiply(ulongArray, multiplier)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestVLongArray() { final double multiplier = 2d; final List<Long> list = Arrays.asList(0L, 1L, 2L, 3L); ListLong listLong = new ListLong() { @Override public long getLong(int i) { return list.get(i); } @Override public int size() { return list.size(); } }; VLongArray longArray = VLongArray.of(listLong, alarm_1, time_1, display_1); VNumberArray multipliedLongArray = SafeMultiply.multiply(longArray, multiplier); for (int index = 0; index < list.size(); index++) { assertTrue(Long.compareUnsigned(SafeMultiply.multiply(list.get(index), multiplier).longValue(), multipliedLongArray.getData().getLong(index)) == 0); } System.out.println("multiplier: " + multiplier); System.out.println(" Original: " + longArray); System.out.println("Multiplied: " + SafeMultiply.multiply(longArray, multiplier)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestVUIntegerArray() { final double multiplier = 2d; final List<UInteger> list = Arrays.asList(UInteger.valueOf(0), UInteger.valueOf(1), UInteger.valueOf(2), UInteger.valueOf(3)); ListUInteger listUInteger = new ListUInteger() { @Override public int getInt(int i) { return list.get(i).intValue(); } @Override public int size() { return list.size(); } }; VUIntArray integerArray = VUIntArray.of(listUInteger, alarm_1, time_1, display_1); VNumberArray multipliedUIntegerArray = SafeMultiply.multiply(integerArray, multiplier); for (int index = 0; index < list.size(); index++) { assertTrue(Integer.compareUnsigned(SafeMultiply.multiply(list.get(index), multiplier).intValue(), multipliedUIntegerArray.getData().getInt(index)) == 0); } System.out.println("multiplier: " + multiplier); System.out.println(" Original: " + integerArray); System.out.println("Multiplied: " + SafeMultiply.multiply(integerArray, multiplier)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestVIntegerArray() { final double multiplier = 2d; final List<Integer> list = Arrays.asList(0, 1, 2, 3); ListInteger listInteger = new ListInteger() { @Override public int getInt(int i) { return list.get(i); } @Override public int size() { return list.size(); } }; VIntArray intArray = VIntArray.of(listInteger, alarm_1, time_1, display_1); VNumberArray multipliedIntegerArray = SafeMultiply.multiply(intArray, multiplier); for (int index = 0; index < list.size(); index++) { assertTrue(Integer.compareUnsigned(SafeMultiply.multiply(list.get(index), multiplier).intValue(), multipliedIntegerArray.getData().getInt(index)) == 0); } System.out.println("multiplier: " + multiplier); System.out.println(" Original: " + intArray); System.out.println("Multiplied: " + SafeMultiply.multiply(intArray, multiplier)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void testMoveNode() { services.moveNode("a", "b", "username"); verify(nodeDAO, atLeast(1)).moveNode("a", "b", "username"); reset(nodeDAO); }
@Override @Transactional public Node moveNode(String nodeId, String targetNodeId, String userName) { logger.info("Moving node id {} to raget node id {}", nodeId, targetNodeId); return nodeDAO.moveNode(nodeId, targetNodeId, userName); }
Services implements IServices { @Override @Transactional public Node moveNode(String nodeId, String targetNodeId, String userName) { logger.info("Moving node id {} to raget node id {}", nodeId, targetNodeId); return nodeDAO.moveNode(nodeId, targetNodeId, userName); } }
Services implements IServices { @Override @Transactional public Node moveNode(String nodeId, String targetNodeId, String userName) { logger.info("Moving node id {} to raget node id {}", nodeId, targetNodeId); return nodeDAO.moveNode(nodeId, targetNodeId, userName); } }
Services implements IServices { @Override @Transactional public Node moveNode(String nodeId, String targetNodeId, String userName) { logger.info("Moving node id {} to raget node id {}", nodeId, targetNodeId); return nodeDAO.moveNode(nodeId, targetNodeId, userName); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName, String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
Services implements IServices { @Override @Transactional public Node moveNode(String nodeId, String targetNodeId, String userName) { logger.info("Moving node id {} to raget node id {}", nodeId, targetNodeId); return nodeDAO.moveNode(nodeId, targetNodeId, userName); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName, String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
@Test public void TestVUShortArray() { final double multiplier = 2d; final List<UShort> list = Arrays.asList(UShort.valueOf(Short.parseShort("0")), UShort.valueOf(Short.parseShort("1")), UShort.valueOf(Short.parseShort("2")), UShort.valueOf(Short.parseShort("3"))); ListUShort listUShort = new ListUShort() { @Override public short getShort(int i) { return list.get(i).shortValue(); } @Override public int size() { return list.size(); } }; VUShortArray shortArray = VUShortArray.of(listUShort, alarm_1, time_1, display_1); VNumberArray multipliedUShortArray = SafeMultiply.multiply(shortArray, multiplier); for (int index = 0; index < list.size(); index++) { assertTrue(Short.compareUnsigned(SafeMultiply.multiply(list.get(index), multiplier).shortValue(), multipliedUShortArray.getData().getShort(index)) == 0); } System.out.println("multiplier: " + multiplier); System.out.println(" Original: " + shortArray); System.out.println("Multiplied: " + SafeMultiply.multiply(shortArray, multiplier)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestVShortArray() { final double multiplier = 2d; final List<Short> list = Arrays.asList(Short.parseShort("0"), Short.parseShort("1"), Short.parseShort("2"), Short.parseShort("3")); ListShort listShort = new ListShort() { @Override public short getShort(int i) { return list.get(i); } @Override public int size() { return list.size(); } }; VShortArray shortArray = VShortArray.of(listShort, alarm_1, time_1, display_1); VNumberArray multipliedShortArray = SafeMultiply.multiply(shortArray, multiplier); for (int index = 0; index < list.size(); index++) { assertTrue(Short.compareUnsigned(SafeMultiply.multiply(list.get(index), multiplier).shortValue(), multipliedShortArray.getData().getShort(index)) == 0); } System.out.println("multiplier: " + multiplier); System.out.println(" Original: " + shortArray); System.out.println("Multiplied: " + SafeMultiply.multiply(shortArray, multiplier)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestVUByteArray() { final double multiplier = 2d; final List<UByte> list = Arrays.asList(UByte.valueOf(Byte.parseByte("0")), UByte.valueOf(Byte.parseByte("1")), UByte.valueOf(Byte.parseByte("2")), UByte.valueOf(Byte.parseByte("3"))); ListUByte listUByte = new ListUByte() { @Override public byte getByte(int i) { return list.get(i).byteValue(); } @Override public int size() { return list.size(); } }; VUByteArray byteArray = VUByteArray.of(listUByte, alarm_1, time_1, display_1); VNumberArray multipliedUByteArray = SafeMultiply.multiply(byteArray, multiplier); for (int index = 0; index < list.size(); index++) { assertTrue(Byte.compareUnsigned(SafeMultiply.multiply(list.get(index), multiplier).byteValue(), multipliedUByteArray.getData().getByte(index)) == 0); } System.out.println("multiplier: " + multiplier); System.out.println(" Original: " + byteArray); System.out.println("Multiplied: " + SafeMultiply.multiply(byteArray, multiplier)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void TestVByteArray() { final double multiplier = 2d; final List<Byte> list = Arrays.asList(Byte.parseByte("0"), Byte.parseByte("1"), Byte.parseByte("2"), Byte.parseByte("3")); ListByte listByte = new ListByte() { @Override public byte getByte(int i) { return list.get(i); } @Override public int size() { return list.size(); } }; VByteArray byteArray = VByteArray.of(listByte, alarm_1, time_1, display_1); VNumberArray multipliedByteArray = SafeMultiply.multiply(byteArray, multiplier); for (int index = 0; index < list.size(); index++) { assertTrue(Byte.compareUnsigned(SafeMultiply.multiply(list.get(index), multiplier).byteValue(), multipliedByteArray.getData().getByte(index)) == 0); } System.out.println("multiplier: " + multiplier); System.out.println(" Original: " + byteArray); System.out.println("Multiplied: " + SafeMultiply.multiply(byteArray, multiplier)); }
public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
SafeMultiply { public static Number multiply(Number a, Number b) throws UnsupportedOperationException { if (a instanceof Double && b instanceof Double) { return multiply((Double) a, (Double) b); } else if (a instanceof Float && b instanceof Float) { return multiply((Float) a, (Float) b); } else if (a instanceof ULong && b instanceof ULong) { return multiply((ULong) a, (ULong) b); } else if (a instanceof Long && b instanceof Long) { return multiply((Long) a, (Long) b); } else if (a instanceof UInteger && b instanceof UInteger) { return multiply((UInteger) a, (UInteger) b); } else if (a instanceof Integer && b instanceof Integer) { return multiply((Integer) a, (Integer) b); } else if (a instanceof UShort && b instanceof UShort) { return multiply((UShort) a, (UShort) b); } else if (a instanceof Short && b instanceof Short) { return multiply((Short) a, (Short) b); } else if (a instanceof UByte && b instanceof UByte) { return multiply((UByte) a, (UByte) b); } else if (a instanceof Byte && b instanceof Byte) { return multiply((Byte) a, (Byte) b); } if (!a.getClass().equals(b.getClass())) { throw new UnsupportedOperationException("Multiplication between different types is allowed only when second argument is Double!"); } else { throw new UnsupportedOperationException("Provided Number extension " + a.getClass() + " is unsupported!"); } } static Number multiply(Number a, Number b); static Number multiply(Number a, Double b); static VNumber multiply(VNumber number, VNumber multiplier); static VNumber multiply(VNumber number, VDouble multiplier); static VNumber multiply(VNumber number, Double multiplier); static VNumberArray multiply(VNumberArray numberArray, Double multiplier); }
@Test public void testPathWrangler() { final PathWrangler wrangler = new PathWrangler("phoebus\\.app/Content/.*,phoebus\\.app/,phoebus-[^/]+/,product-[^/]+/,jdk/.*"); assertThat(wrangler.wrangle("phoebus-0.0.1/doc/applications.html"), equalTo("doc/applications.html")); assertThat(wrangler.wrangle("product-sns-0.0.1/lib/somelib.jar"), equalTo("lib/somelib.jar")); assertThat(wrangler.wrangle("product-sns-0.0.1/doc/phoebus/app/display/editor/doc/html/generated/org/csstudio/display/builder/model/DisplayModel.html"), equalTo("doc/phoebus/app/display/editor/doc/html/generated/org/csstudio/display/builder/model/DisplayModel.html")); assertThat(wrangler.wrangle("jdk/bin/java"), equalTo("")); assertThat(wrangler.wrangle("phoebus.app/product-sns-0.0.1/lib/somelib.jar"), equalTo("lib/somelib.jar")); assertThat(wrangler.wrangle("phoebus.app/jdk/bin/java"), equalTo("")); assertThat(wrangler.wrangle("phoebus.app/Content/Whateer/Else"), equalTo("")); }
public PathWrangler(final String removals) { for (String remove : removals.split(",")) this.removals.add(Pattern.compile(remove)); }
PathWrangler { public PathWrangler(final String removals) { for (String remove : removals.split(",")) this.removals.add(Pattern.compile(remove)); } }
PathWrangler { public PathWrangler(final String removals) { for (String remove : removals.split(",")) this.removals.add(Pattern.compile(remove)); } PathWrangler(final String removals); }
PathWrangler { public PathWrangler(final String removals) { for (String remove : removals.split(",")) this.removals.add(Pattern.compile(remove)); } PathWrangler(final String removals); String wrangle(String path); }
PathWrangler { public PathWrangler(final String removals) { for (String remove : removals.split(",")) this.removals.add(Pattern.compile(remove)); } PathWrangler(final String removals); String wrangle(String path); }
@Test public void listPrefixes() { final Collection<String> prefs = PVPool.getSupportedPrefixes(); System.out.println("Prefixes: " + prefs); assertThat(prefs, hasItem("ca")); assertThat(prefs, hasItem("sim")); }
public static Collection<String> getSupportedPrefixes() { return factories.keySet(); }
PVPool { public static Collection<String> getSupportedPrefixes() { return factories.keySet(); } }
PVPool { public static Collection<String> getSupportedPrefixes() { return factories.keySet(); } private PVPool(); }
PVPool { public static Collection<String> getSupportedPrefixes() { return factories.keySet(); } private PVPool(); static Collection<String> getSupportedPrefixes(); static PV getPV(final String name); static void releasePV(final PV pv); static Collection<ReferencedEntry<PV>> getPVReferences(); }
PVPool { public static Collection<String> getSupportedPrefixes() { return factories.keySet(); } private PVPool(); static Collection<String> getSupportedPrefixes(); static PV getPV(final String name); static void releasePV(final PV pv); static Collection<ReferencedEntry<PV>> getPVReferences(); static final String DEFAULT; final static String SEPARATOR; }
@Test public void dateSpanValueZero() throws Exception { IndexNameHelper inh = new IndexNameHelper("test_index", "y", 0); String indexName = inh.getIndexName(Instant.now()); assertEquals("test_index", indexName); }
public String getIndexName(Instant time) { if (dateSpanValue < 1) return baseIndexName; if (null != time && (null == spanEnd || time.isAfter(spanEnd))) { setDateSpanStartAndEnd(time); currentDateSpan = parseCurrentDateSpan(); } return baseIndexName + "_" + currentDateSpan; }
IndexNameHelper { public String getIndexName(Instant time) { if (dateSpanValue < 1) return baseIndexName; if (null != time && (null == spanEnd || time.isAfter(spanEnd))) { setDateSpanStartAndEnd(time); currentDateSpan = parseCurrentDateSpan(); } return baseIndexName + "_" + currentDateSpan; } }
IndexNameHelper { public String getIndexName(Instant time) { if (dateSpanValue < 1) return baseIndexName; if (null != time && (null == spanEnd || time.isAfter(spanEnd))) { setDateSpanStartAndEnd(time); currentDateSpan = parseCurrentDateSpan(); } return baseIndexName + "_" + currentDateSpan; } IndexNameHelper(final String baseIndexName, final String dateSpanUnit, final Integer dateSpanValue); }
IndexNameHelper { public String getIndexName(Instant time) { if (dateSpanValue < 1) return baseIndexName; if (null != time && (null == spanEnd || time.isAfter(spanEnd))) { setDateSpanStartAndEnd(time); currentDateSpan = parseCurrentDateSpan(); } return baseIndexName + "_" + currentDateSpan; } IndexNameHelper(final String baseIndexName, final String dateSpanUnit, final Integer dateSpanValue); String getIndexName(Instant time); Instant getCurrentDateSpanStart(); Instant getCurrentDateSpanEnd(); }
IndexNameHelper { public String getIndexName(Instant time) { if (dateSpanValue < 1) return baseIndexName; if (null != time && (null == spanEnd || time.isAfter(spanEnd))) { setDateSpanStartAndEnd(time); currentDateSpan = parseCurrentDateSpan(); } return baseIndexName + "_" + currentDateSpan; } IndexNameHelper(final String baseIndexName, final String dateSpanUnit, final Integer dateSpanValue); String getIndexName(Instant time); Instant getCurrentDateSpanStart(); Instant getCurrentDateSpanEnd(); }
@Test public void dateSpanValueLessThanZero() throws Exception { IndexNameHelper inh = new IndexNameHelper("test_index", "y", -5); String indexName = inh.getIndexName(Instant.now()); assertEquals("test_index", indexName); }
public String getIndexName(Instant time) { if (dateSpanValue < 1) return baseIndexName; if (null != time && (null == spanEnd || time.isAfter(spanEnd))) { setDateSpanStartAndEnd(time); currentDateSpan = parseCurrentDateSpan(); } return baseIndexName + "_" + currentDateSpan; }
IndexNameHelper { public String getIndexName(Instant time) { if (dateSpanValue < 1) return baseIndexName; if (null != time && (null == spanEnd || time.isAfter(spanEnd))) { setDateSpanStartAndEnd(time); currentDateSpan = parseCurrentDateSpan(); } return baseIndexName + "_" + currentDateSpan; } }
IndexNameHelper { public String getIndexName(Instant time) { if (dateSpanValue < 1) return baseIndexName; if (null != time && (null == spanEnd || time.isAfter(spanEnd))) { setDateSpanStartAndEnd(time); currentDateSpan = parseCurrentDateSpan(); } return baseIndexName + "_" + currentDateSpan; } IndexNameHelper(final String baseIndexName, final String dateSpanUnit, final Integer dateSpanValue); }
IndexNameHelper { public String getIndexName(Instant time) { if (dateSpanValue < 1) return baseIndexName; if (null != time && (null == spanEnd || time.isAfter(spanEnd))) { setDateSpanStartAndEnd(time); currentDateSpan = parseCurrentDateSpan(); } return baseIndexName + "_" + currentDateSpan; } IndexNameHelper(final String baseIndexName, final String dateSpanUnit, final Integer dateSpanValue); String getIndexName(Instant time); Instant getCurrentDateSpanStart(); Instant getCurrentDateSpanEnd(); }
IndexNameHelper { public String getIndexName(Instant time) { if (dateSpanValue < 1) return baseIndexName; if (null != time && (null == spanEnd || time.isAfter(spanEnd))) { setDateSpanStartAndEnd(time); currentDateSpan = parseCurrentDateSpan(); } return baseIndexName + "_" + currentDateSpan; } IndexNameHelper(final String baseIndexName, final String dateSpanUnit, final Integer dateSpanValue); String getIndexName(Instant time); Instant getCurrentDateSpanStart(); Instant getCurrentDateSpanEnd(); }
@Test public void testFile() throws Exception { File bob = new File("/some/path/file.bob"); File file = FileExtensionUtil.enforceFileExtension(new File("/some/path/file"), "bob"); assertThat(file, equalTo(bob)); file = FileExtensionUtil.enforceFileExtension(new File("/some/path/file.abc"), "bob"); assertThat(file, equalTo(bob)); file = FileExtensionUtil.enforceFileExtension(new File("/some/path/file.bob"), "bob"); assertThat(file, equalTo(bob)); }
public static File enforceFileExtension(final File file, final String desiredExtension) { final String path = file.getPath(); final int sep = path.lastIndexOf('.'); if (sep < 0){ return new File(path + "." + desiredExtension); } final String ext = path.substring(sep + 1); if (! ext.equals(desiredExtension)){ return new File(path.substring(0, sep) + "." + desiredExtension); } return file; }
FileExtensionUtil { public static File enforceFileExtension(final File file, final String desiredExtension) { final String path = file.getPath(); final int sep = path.lastIndexOf('.'); if (sep < 0){ return new File(path + "." + desiredExtension); } final String ext = path.substring(sep + 1); if (! ext.equals(desiredExtension)){ return new File(path.substring(0, sep) + "." + desiredExtension); } return file; } }
FileExtensionUtil { public static File enforceFileExtension(final File file, final String desiredExtension) { final String path = file.getPath(); final int sep = path.lastIndexOf('.'); if (sep < 0){ return new File(path + "." + desiredExtension); } final String ext = path.substring(sep + 1); if (! ext.equals(desiredExtension)){ return new File(path.substring(0, sep) + "." + desiredExtension); } return file; } }
FileExtensionUtil { public static File enforceFileExtension(final File file, final String desiredExtension) { final String path = file.getPath(); final int sep = path.lastIndexOf('.'); if (sep < 0){ return new File(path + "." + desiredExtension); } final String ext = path.substring(sep + 1); if (! ext.equals(desiredExtension)){ return new File(path.substring(0, sep) + "." + desiredExtension); } return file; } static File enforceFileExtension(final File file, final String desiredExtension); }
FileExtensionUtil { public static File enforceFileExtension(final File file, final String desiredExtension) { final String path = file.getPath(); final int sep = path.lastIndexOf('.'); if (sep < 0){ return new File(path + "." + desiredExtension); } final String ext = path.substring(sep + 1); if (! ext.equals(desiredExtension)){ return new File(path.substring(0, sep) + "." + desiredExtension); } return file; } static File enforceFileExtension(final File file, final String desiredExtension); }
@Test public void sec1() { Duration duration = TimeDuration.ofSeconds(1.0); assertThat(duration.getNano(), equalTo(0)); assertThat(duration.getSeconds(), equalTo(1L)); }
public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void testUpdateNode() { Node node = Node.builder().build(); services.updateNode(node); verify(nodeDAO, atLeast(1)).updateNode(node, false); reset(nodeDAO); }
@Override public Node updateNode(Node nodeToUpdate) { return updateNode(nodeToUpdate, false); }
Services implements IServices { @Override public Node updateNode(Node nodeToUpdate) { return updateNode(nodeToUpdate, false); } }
Services implements IServices { @Override public Node updateNode(Node nodeToUpdate) { return updateNode(nodeToUpdate, false); } }
Services implements IServices { @Override public Node updateNode(Node nodeToUpdate) { return updateNode(nodeToUpdate, false); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName, String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
Services implements IServices { @Override public Node updateNode(Node nodeToUpdate) { return updateNode(nodeToUpdate, false); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName, String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
@Test public void sec2() { Duration duration = TimeDuration.ofSeconds(0.123456789); assertThat(duration.getNano(), equalTo(123456789)); assertThat(duration.getSeconds(), equalTo(0L)); }
public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void sec3() { Duration duration = TimeDuration.ofSeconds(-1.23456789); assertThat(duration.getNano(), equalTo(765432110)); assertThat(duration.getSeconds(), equalTo(-2L)); }
public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void min1() { Duration duration = TimeDuration.ofMinutes(1.0); assertThat(duration.getNano(), equalTo(0)); assertThat(duration.getSeconds(), equalTo(60L)); }
public static Duration ofMinutes(double min) { return Duration.ofNanos((long) (min * 60 * NANOSEC_IN_SEC)); }
TimeDuration { public static Duration ofMinutes(double min) { return Duration.ofNanos((long) (min * 60 * NANOSEC_IN_SEC)); } }
TimeDuration { public static Duration ofMinutes(double min) { return Duration.ofNanos((long) (min * 60 * NANOSEC_IN_SEC)); } private TimeDuration(); }
TimeDuration { public static Duration ofMinutes(double min) { return Duration.ofNanos((long) (min * 60 * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofMinutes(double min) { return Duration.ofNanos((long) (min * 60 * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void min2() { Duration duration = TimeDuration.ofMinutes(0.123456789); assertThat(duration.getNano(), equalTo(407407340)); assertThat(duration.getSeconds(), equalTo(7L)); }
public static Duration ofMinutes(double min) { return Duration.ofNanos((long) (min * 60 * NANOSEC_IN_SEC)); }
TimeDuration { public static Duration ofMinutes(double min) { return Duration.ofNanos((long) (min * 60 * NANOSEC_IN_SEC)); } }
TimeDuration { public static Duration ofMinutes(double min) { return Duration.ofNanos((long) (min * 60 * NANOSEC_IN_SEC)); } private TimeDuration(); }
TimeDuration { public static Duration ofMinutes(double min) { return Duration.ofNanos((long) (min * 60 * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofMinutes(double min) { return Duration.ofNanos((long) (min * 60 * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void min3() { Duration duration = TimeDuration.ofMinutes(-1.23456789); assertThat(duration.getNano(), equalTo(925926601)); assertThat(duration.getSeconds(), equalTo(-75L)); }
public static Duration ofMinutes(double min) { return Duration.ofNanos((long) (min * 60 * NANOSEC_IN_SEC)); }
TimeDuration { public static Duration ofMinutes(double min) { return Duration.ofNanos((long) (min * 60 * NANOSEC_IN_SEC)); } }
TimeDuration { public static Duration ofMinutes(double min) { return Duration.ofNanos((long) (min * 60 * NANOSEC_IN_SEC)); } private TimeDuration(); }
TimeDuration { public static Duration ofMinutes(double min) { return Duration.ofNanos((long) (min * 60 * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofMinutes(double min) { return Duration.ofNanos((long) (min * 60 * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void hour1() { Duration duration = TimeDuration.ofHours(1.0); assertThat(duration.getNano(), equalTo(0)); assertThat(duration.getSeconds(), equalTo(3600L)); }
public static Duration ofHours(double hour) { return Duration.ofNanos((long) (hour * 60 * 60 * NANOSEC_IN_SEC)); }
TimeDuration { public static Duration ofHours(double hour) { return Duration.ofNanos((long) (hour * 60 * 60 * NANOSEC_IN_SEC)); } }
TimeDuration { public static Duration ofHours(double hour) { return Duration.ofNanos((long) (hour * 60 * 60 * NANOSEC_IN_SEC)); } private TimeDuration(); }
TimeDuration { public static Duration ofHours(double hour) { return Duration.ofNanos((long) (hour * 60 * 60 * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofHours(double hour) { return Duration.ofNanos((long) (hour * 60 * 60 * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void hour2() { Duration duration = TimeDuration.ofHours(0.123456789); assertThat(duration.getNano(), equalTo(444440399)); assertThat(duration.getSeconds(), equalTo(444L)); }
public static Duration ofHours(double hour) { return Duration.ofNanos((long) (hour * 60 * 60 * NANOSEC_IN_SEC)); }
TimeDuration { public static Duration ofHours(double hour) { return Duration.ofNanos((long) (hour * 60 * 60 * NANOSEC_IN_SEC)); } }
TimeDuration { public static Duration ofHours(double hour) { return Duration.ofNanos((long) (hour * 60 * 60 * NANOSEC_IN_SEC)); } private TimeDuration(); }
TimeDuration { public static Duration ofHours(double hour) { return Duration.ofNanos((long) (hour * 60 * 60 * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofHours(double hour) { return Duration.ofNanos((long) (hour * 60 * 60 * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void hour3() { Duration duration = TimeDuration.ofHours(-1.23456789); assertThat(duration.getNano(), equalTo(555596001)); assertThat(duration.getSeconds(), equalTo(-4445L)); }
public static Duration ofHours(double hour) { return Duration.ofNanos((long) (hour * 60 * 60 * NANOSEC_IN_SEC)); }
TimeDuration { public static Duration ofHours(double hour) { return Duration.ofNanos((long) (hour * 60 * 60 * NANOSEC_IN_SEC)); } }
TimeDuration { public static Duration ofHours(double hour) { return Duration.ofNanos((long) (hour * 60 * 60 * NANOSEC_IN_SEC)); } private TimeDuration(); }
TimeDuration { public static Duration ofHours(double hour) { return Duration.ofNanos((long) (hour * 60 * 60 * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofHours(double hour) { return Duration.ofNanos((long) (hour * 60 * 60 * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void hz1() { Duration duration = TimeDuration.ofHertz(1.0); assertThat(duration.getNano(), equalTo(0)); assertThat(duration.getSeconds(), equalTo(1L)); }
public static Duration ofHertz(double hz) { if (hz <= 0.0) { throw new IllegalArgumentException("Frequency has to be greater than 0.0"); } return Duration.ofNanos((long) (1000000000.0 / hz)); }
TimeDuration { public static Duration ofHertz(double hz) { if (hz <= 0.0) { throw new IllegalArgumentException("Frequency has to be greater than 0.0"); } return Duration.ofNanos((long) (1000000000.0 / hz)); } }
TimeDuration { public static Duration ofHertz(double hz) { if (hz <= 0.0) { throw new IllegalArgumentException("Frequency has to be greater than 0.0"); } return Duration.ofNanos((long) (1000000000.0 / hz)); } private TimeDuration(); }
TimeDuration { public static Duration ofHertz(double hz) { if (hz <= 0.0) { throw new IllegalArgumentException("Frequency has to be greater than 0.0"); } return Duration.ofNanos((long) (1000000000.0 / hz)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofHertz(double hz) { if (hz <= 0.0) { throw new IllegalArgumentException("Frequency has to be greater than 0.0"); } return Duration.ofNanos((long) (1000000000.0 / hz)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void hz2() { Duration duration = TimeDuration.ofHertz(100.0); assertThat(duration.getNano(), equalTo(10000000)); assertThat(duration.getSeconds(), equalTo(0L)); }
public static Duration ofHertz(double hz) { if (hz <= 0.0) { throw new IllegalArgumentException("Frequency has to be greater than 0.0"); } return Duration.ofNanos((long) (1000000000.0 / hz)); }
TimeDuration { public static Duration ofHertz(double hz) { if (hz <= 0.0) { throw new IllegalArgumentException("Frequency has to be greater than 0.0"); } return Duration.ofNanos((long) (1000000000.0 / hz)); } }
TimeDuration { public static Duration ofHertz(double hz) { if (hz <= 0.0) { throw new IllegalArgumentException("Frequency has to be greater than 0.0"); } return Duration.ofNanos((long) (1000000000.0 / hz)); } private TimeDuration(); }
TimeDuration { public static Duration ofHertz(double hz) { if (hz <= 0.0) { throw new IllegalArgumentException("Frequency has to be greater than 0.0"); } return Duration.ofNanos((long) (1000000000.0 / hz)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofHertz(double hz) { if (hz <= 0.0) { throw new IllegalArgumentException("Frequency has to be greater than 0.0"); } return Duration.ofNanos((long) (1000000000.0 / hz)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void testUpdateConfiguration() { when(nodeDAO.updateConfiguration(config1, configPvList)).thenReturn(config1); assertNotNull(services.updateConfiguration(config1, configPvList)); }
@Override @Transactional public Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs) { logger.info("Updating configuration unique id: {}", configToUpdate.getUniqueId()); return nodeDAO.updateConfiguration(configToUpdate, configPvs); }
Services implements IServices { @Override @Transactional public Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs) { logger.info("Updating configuration unique id: {}", configToUpdate.getUniqueId()); return nodeDAO.updateConfiguration(configToUpdate, configPvs); } }
Services implements IServices { @Override @Transactional public Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs) { logger.info("Updating configuration unique id: {}", configToUpdate.getUniqueId()); return nodeDAO.updateConfiguration(configToUpdate, configPvs); } }
Services implements IServices { @Override @Transactional public Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs) { logger.info("Updating configuration unique id: {}", configToUpdate.getUniqueId()); return nodeDAO.updateConfiguration(configToUpdate, configPvs); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName, String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
Services implements IServices { @Override @Transactional public Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs) { logger.info("Updating configuration unique id: {}", configToUpdate.getUniqueId()); return nodeDAO.updateConfiguration(configToUpdate, configPvs); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName, String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
@Test public void hz3() { Duration duration = TimeDuration.ofHertz(0.123456789); assertThat(duration.getNano(), equalTo(100000073)); assertThat(duration.getSeconds(), equalTo(8L)); }
public static Duration ofHertz(double hz) { if (hz <= 0.0) { throw new IllegalArgumentException("Frequency has to be greater than 0.0"); } return Duration.ofNanos((long) (1000000000.0 / hz)); }
TimeDuration { public static Duration ofHertz(double hz) { if (hz <= 0.0) { throw new IllegalArgumentException("Frequency has to be greater than 0.0"); } return Duration.ofNanos((long) (1000000000.0 / hz)); } }
TimeDuration { public static Duration ofHertz(double hz) { if (hz <= 0.0) { throw new IllegalArgumentException("Frequency has to be greater than 0.0"); } return Duration.ofNanos((long) (1000000000.0 / hz)); } private TimeDuration(); }
TimeDuration { public static Duration ofHertz(double hz) { if (hz <= 0.0) { throw new IllegalArgumentException("Frequency has to be greater than 0.0"); } return Duration.ofNanos((long) (1000000000.0 / hz)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofHertz(double hz) { if (hz <= 0.0) { throw new IllegalArgumentException("Frequency has to be greater than 0.0"); } return Duration.ofNanos((long) (1000000000.0 / hz)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void plus1() { Duration duration = Duration.ofMillis(800); assertThat(duration.plus(Duration.ofMillis(300)), equalTo(TimeDuration.ofSeconds(1.1))); }
public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void plus2() { Duration duration = Duration.ofMillis(-100); assertThat(duration.plus(Duration.ofMillis(300)), equalTo(TimeDuration.ofSeconds(0.2))); }
public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void plus3() { Duration duration = Duration.ofMillis(100); assertThat(duration.plus(Duration.ofMillis(-200)), equalTo(TimeDuration.ofSeconds(-0.1))); }
public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void plus4() { Duration duration = TimeDuration.ofSeconds(1.250); assertThat(duration.plus(TimeDuration.ofSeconds(1.250)), equalTo(TimeDuration.ofSeconds(2.5))); }
public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void plus5() { Duration duration = TimeDuration.ofSeconds(10.250); assertThat(duration.plus(TimeDuration.ofSeconds(-1.750)), equalTo(TimeDuration.ofSeconds(8.5))); }
public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void minus1() { Duration duration = Duration.ofMillis(800); assertThat(duration.minus(Duration.ofMillis(300)), equalTo(TimeDuration.ofSeconds(0.5))); }
public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void minus2() { Duration duration = Duration.ofMillis(800); assertThat(duration.minus(Duration.ofMillis(-300)), equalTo(TimeDuration.ofSeconds(1.1))); }
public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void minus3() { Duration duration = Duration.ofMillis(1300); assertThat(duration.minus(Duration.ofMillis(800)), equalTo(TimeDuration.ofSeconds(0.5))); }
public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void minus4() { Duration duration = Duration.ofMillis(800); assertThat(duration.minus(Duration.ofMillis(1300)), equalTo(TimeDuration.ofSeconds(-0.5))); }
public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void testGetSnapshotItems() { when(nodeDAO.getSnapshotItems("a")).thenReturn(Collections.emptyList()); assertNotNull(services.getSnapshotItems("a")); }
@Override public List<SnapshotItem> getSnapshotItems(String snapshotUniqueId) { logger.info("Getting snapshot items for snapshot id {}", snapshotUniqueId); return nodeDAO.getSnapshotItems(snapshotUniqueId); }
Services implements IServices { @Override public List<SnapshotItem> getSnapshotItems(String snapshotUniqueId) { logger.info("Getting snapshot items for snapshot id {}", snapshotUniqueId); return nodeDAO.getSnapshotItems(snapshotUniqueId); } }
Services implements IServices { @Override public List<SnapshotItem> getSnapshotItems(String snapshotUniqueId) { logger.info("Getting snapshot items for snapshot id {}", snapshotUniqueId); return nodeDAO.getSnapshotItems(snapshotUniqueId); } }
Services implements IServices { @Override public List<SnapshotItem> getSnapshotItems(String snapshotUniqueId) { logger.info("Getting snapshot items for snapshot id {}", snapshotUniqueId); return nodeDAO.getSnapshotItems(snapshotUniqueId); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName, String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
Services implements IServices { @Override public List<SnapshotItem> getSnapshotItems(String snapshotUniqueId) { logger.info("Getting snapshot items for snapshot id {}", snapshotUniqueId); return nodeDAO.getSnapshotItems(snapshotUniqueId); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName, String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
@Test public void minus5() { Duration duration = TimeDuration.ofSeconds(10.250); assertThat(duration.minus(Duration.ofMillis(1750)), equalTo(TimeDuration.ofSeconds(8.5))); }
public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void multipliedBy1() { Duration duration = Duration.ofMillis(300); assertThat(duration.multipliedBy(5), equalTo(TimeDuration.ofSeconds(1.5))); }
public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void multipliedBy2() { Duration duration = TimeDuration.ofSeconds(10.500); assertThat(duration.multipliedBy(5), equalTo(TimeDuration.ofSeconds(52.5))); }
public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void multipliedBy3() { Duration duration = TimeDuration.ofSeconds(10.500); assertThat(duration.multipliedBy(-5), equalTo(TimeDuration.ofSeconds(-52.5))); }
public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static Duration ofSeconds(double sec) { return Duration.ofNanos((long) (sec * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
@Test public void toString1() { Duration duration = Duration.ofMillis(10); assertThat(TimeDuration.toSecondString(duration), equalTo("0.010000000")); }
public static String toSecondString(Duration duration){ return duration.getSeconds() + "." + format.format(duration.getNano()); }
TimeDuration { public static String toSecondString(Duration duration){ return duration.getSeconds() + "." + format.format(duration.getNano()); } }
TimeDuration { public static String toSecondString(Duration duration){ return duration.getSeconds() + "." + format.format(duration.getNano()); } private TimeDuration(); }
TimeDuration { public static String toSecondString(Duration duration){ return duration.getSeconds() + "." + format.format(duration.getNano()); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }
TimeDuration { public static String toSecondString(Duration duration){ return duration.getSeconds() + "." + format.format(duration.getNano()); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(double min); static Duration ofSeconds(double sec); static Duration ofHertz(double hz); static int dividedBy(Duration dividendDuration, Duration divisorDuration); static double toSecondsDouble(Duration duration); static String toSecondString(Duration duration); }