From 806052bf4df8bd023cfb391794bc5937f2624716 Mon Sep 17 00:00:00 2001 From: Marcus G K Williams Date: Wed, 2 Aug 2017 15:09:24 -0700 Subject: Convert tabs to spaces Per Java Code Style Guide: https://wiki.onap.org/display/DW/Java+code+style Converting tabs to 4 spaces. Issue-Id: SDNC-25 Change-Id: I99ce6c244df72f805b52d0d66403d8b76d9929ae Signed-off-by: Marcus G K Williams --- .../sdnc/util/db/CachedDataSourceWrap.java | 174 +++--- .../org/openecomp/sdnc/util/db/ConnectionWrap.java | 588 ++++++++++----------- .../org/openecomp/sdnc/util/db/DataSourceWrap.java | 96 ++-- .../sdnc/util/expr/ExpressionEvaluator.java | 360 ++++++------- .../org/openecomp/sdnc/util/speed/SpeedUtil.java | 28 +- .../java/org/openecomp/sdnc/util/str/StrUtil.java | 532 +++++++++---------- .../java/org/openecomp/sdnc/util/vrf/VpnParam.java | 10 +- .../java/org/openecomp/sdnc/util/vrf/VrfUtil.java | 84 +-- 8 files changed, 936 insertions(+), 936 deletions(-) (limited to 'resource-assignment/provider/src/main/java/org/openecomp/sdnc/util') diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/CachedDataSourceWrap.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/CachedDataSourceWrap.java index 8918ce0c..12ba1586 100644 --- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/CachedDataSourceWrap.java +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/CachedDataSourceWrap.java @@ -3,7 +3,7 @@ * openECOMP : SDN-C * ================================================================================ * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,90 +33,90 @@ import org.slf4j.LoggerFactory; public class CachedDataSourceWrap implements DataSource { - private static final Logger log = LoggerFactory.getLogger(CachedDataSourceWrap.class); - - private ThreadLocal con = new ThreadLocal<>(); - - private DataSource dataSource; - - @Override - public PrintWriter getLogWriter() throws SQLException { - return dataSource.getLogWriter(); - } - - @Override - public void setLogWriter(PrintWriter out) throws SQLException { - dataSource.setLogWriter(out); - } - - @Override - public void setLoginTimeout(int seconds) throws SQLException { - dataSource.setLoginTimeout(seconds); - } - - @Override - public int getLoginTimeout() throws SQLException { - return dataSource.getLoginTimeout(); - } - - @Override - public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException { - return dataSource.getParentLogger(); - } - - @Override - public T unwrap(Class iface) throws SQLException { - return dataSource.unwrap(iface); - } - - @Override - public boolean isWrapperFor(Class iface) throws SQLException { - return dataSource.isWrapperFor(iface); - } - - @Override - public Connection getConnection() throws SQLException { - if (con.get() == null) { - Connection c = dataSource.getConnection(); - ConnectionWrap cc = new ConnectionWrap(c); - con.set(cc); - - log.info("Got new DB connection: " + c); - } else - log.info("Using thread DB connection: " + con.get().getCon()); - - return con.get(); - } - - @Override - public Connection getConnection(String username, String password) throws SQLException { - if (con.get() == null) { - Connection c = dataSource.getConnection(username, password); - ConnectionWrap cc = new ConnectionWrap(c); - con.set(cc); - - log.info("Got new DB connection: " + c); - } else - log.info("Using thread DB connection: " + con.get().getCon()); - - return con.get(); - } - - public void releaseConnection() { - if (con.get() != null) { - try { - con.get().realClose(); - - log.info("DB Connection released: " + con.get().getCon()); - } catch (SQLException e) { - log.warn("Failed to release DB connection", e); - } finally { - con.remove(); - } - } - } - - public void setDataSource(DataSource dataSource) { - this.dataSource = dataSource; - } + private static final Logger log = LoggerFactory.getLogger(CachedDataSourceWrap.class); + + private ThreadLocal con = new ThreadLocal<>(); + + private DataSource dataSource; + + @Override + public PrintWriter getLogWriter() throws SQLException { + return dataSource.getLogWriter(); + } + + @Override + public void setLogWriter(PrintWriter out) throws SQLException { + dataSource.setLogWriter(out); + } + + @Override + public void setLoginTimeout(int seconds) throws SQLException { + dataSource.setLoginTimeout(seconds); + } + + @Override + public int getLoginTimeout() throws SQLException { + return dataSource.getLoginTimeout(); + } + + @Override + public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException { + return dataSource.getParentLogger(); + } + + @Override + public T unwrap(Class iface) throws SQLException { + return dataSource.unwrap(iface); + } + + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + return dataSource.isWrapperFor(iface); + } + + @Override + public Connection getConnection() throws SQLException { + if (con.get() == null) { + Connection c = dataSource.getConnection(); + ConnectionWrap cc = new ConnectionWrap(c); + con.set(cc); + + log.info("Got new DB connection: " + c); + } else + log.info("Using thread DB connection: " + con.get().getCon()); + + return con.get(); + } + + @Override + public Connection getConnection(String username, String password) throws SQLException { + if (con.get() == null) { + Connection c = dataSource.getConnection(username, password); + ConnectionWrap cc = new ConnectionWrap(c); + con.set(cc); + + log.info("Got new DB connection: " + c); + } else + log.info("Using thread DB connection: " + con.get().getCon()); + + return con.get(); + } + + public void releaseConnection() { + if (con.get() != null) { + try { + con.get().realClose(); + + log.info("DB Connection released: " + con.get().getCon()); + } catch (SQLException e) { + log.warn("Failed to release DB connection", e); + } finally { + con.remove(); + } + } + } + + public void setDataSource(DataSource dataSource) { + this.dataSource = dataSource; + } } diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/ConnectionWrap.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/ConnectionWrap.java index 1927fdb9..11560498 100644 --- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/ConnectionWrap.java +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/ConnectionWrap.java @@ -3,7 +3,7 @@ * openECOMP : SDN-C * ================================================================================ * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,297 +42,297 @@ import java.util.concurrent.Executor; public class ConnectionWrap implements Connection { - private Connection cc; - - public ConnectionWrap(Connection cc) { - super(); - this.cc = cc; - } - - public Connection getCon() { - return cc; - } - - public void realClose() throws SQLException { - cc.close(); - } - - @Override - public T unwrap(Class iface) throws SQLException { - return cc.unwrap(iface); - } - - @Override - public boolean isWrapperFor(Class iface) throws SQLException { - return cc.isWrapperFor(iface); - } - - @Override - public Statement createStatement() throws SQLException { - return cc.createStatement(); - } - - @Override - public PreparedStatement prepareStatement(String sql) throws SQLException { - return cc.prepareStatement(sql); - } - - @Override - public CallableStatement prepareCall(String sql) throws SQLException { - return cc.prepareCall(sql); - } - - @Override - public String nativeSQL(String sql) throws SQLException { - return cc.nativeSQL(sql); - } - - @Override - public void setAutoCommit(boolean autoCommit) throws SQLException { - cc.setAutoCommit(autoCommit); - } - - @Override - public boolean getAutoCommit() throws SQLException { - return cc.getAutoCommit(); - } - - @Override - public void commit() throws SQLException { - cc.commit(); - } - - @Override - public void rollback() throws SQLException { - cc.rollback(); - } - - @Override - public void close() throws SQLException { - } - - @Override - public boolean isClosed() throws SQLException { - return cc.isClosed(); - } - - @Override - public DatabaseMetaData getMetaData() throws SQLException { - return cc.getMetaData(); - } - - @Override - public void setReadOnly(boolean readOnly) throws SQLException { - cc.setReadOnly(readOnly); - } - - @Override - public boolean isReadOnly() throws SQLException { - return cc.isReadOnly(); - } - - @Override - public void setCatalog(String catalog) throws SQLException { - cc.setCatalog(catalog); - } - - @Override - public String getCatalog() throws SQLException { - return cc.getCatalog(); - } - - @Override - public void setTransactionIsolation(int level) throws SQLException { - cc.setTransactionIsolation(level); - } - - @Override - public int getTransactionIsolation() throws SQLException { - return cc.getTransactionIsolation(); - } - - @Override - public SQLWarning getWarnings() throws SQLException { - return cc.getWarnings(); - } - - @Override - public void clearWarnings() throws SQLException { - cc.clearWarnings(); - } - - @Override - public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { - return cc.createStatement(resultSetType, resultSetConcurrency); - } - - @Override - public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) - throws SQLException { - return cc.prepareStatement(sql, resultSetType, resultSetConcurrency); - } - - @Override - public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { - return cc.prepareCall(sql, resultSetType, resultSetConcurrency); - } - - @Override - public Map> getTypeMap() throws SQLException { - return cc.getTypeMap(); - } - - @Override - public void setTypeMap(Map> map) throws SQLException { - cc.setTypeMap(map); - } - - @Override - public void setHoldability(int holdability) throws SQLException { - cc.setHoldability(holdability); - } - - @Override - public int getHoldability() throws SQLException { - return cc.getHoldability(); - } - - @Override - public Savepoint setSavepoint() throws SQLException { - return cc.setSavepoint(); - } - - @Override - public Savepoint setSavepoint(String name) throws SQLException { - return cc.setSavepoint(name); - } - - @Override - public void rollback(Savepoint savepoint) throws SQLException { - cc.rollback(savepoint); - } - - @Override - public void releaseSavepoint(Savepoint savepoint) throws SQLException { - cc.releaseSavepoint(savepoint); - } - - @Override - public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) - throws SQLException { - return cc.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); - } - - @Override - public PreparedStatement prepareStatement( - String sql, - int resultSetType, - int resultSetConcurrency, - int resultSetHoldability) throws SQLException { - return cc.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); - } - - @Override - public CallableStatement prepareCall( - String sql, - int resultSetType, - int resultSetConcurrency, - int resultSetHoldability) throws SQLException { - return cc.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability); - } - - @Override - public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { - return cc.prepareStatement(sql, autoGeneratedKeys); - } - - @Override - public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { - return cc.prepareStatement(sql, columnIndexes); - } - - @Override - public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { - return cc.prepareStatement(sql, columnNames); - } - - @Override - public Clob createClob() throws SQLException { - return cc.createClob(); - } - - @Override - public Blob createBlob() throws SQLException { - return cc.createBlob(); - } - - @Override - public NClob createNClob() throws SQLException { - return cc.createNClob(); - } - - @Override - public SQLXML createSQLXML() throws SQLException { - return cc.createSQLXML(); - } - - @Override - public boolean isValid(int timeout) throws SQLException { - return cc.isValid(timeout); - } - - @Override - public void setClientInfo(String name, String value) throws SQLClientInfoException { - cc.setClientInfo(name, value); - } - - @Override - public void setClientInfo(Properties properties) throws SQLClientInfoException { - cc.setClientInfo(properties); - } - - @Override - public String getClientInfo(String name) throws SQLException { - return cc.getClientInfo(name); - } - - @Override - public Properties getClientInfo() throws SQLException { - return cc.getClientInfo(); - } - - @Override - public Array createArrayOf(String typeName, Object[] elements) throws SQLException { - return cc.createArrayOf(typeName, elements); - } - - @Override - public Struct createStruct(String typeName, Object[] attributes) throws SQLException { - return cc.createStruct(typeName, attributes); - } - - @Override - public void setSchema(String schema) throws SQLException { - cc.setSchema(schema); - } - - @Override - public String getSchema() throws SQLException { - return cc.getSchema(); - } - - @Override - public void abort(Executor executor) throws SQLException { - cc.abort(executor); - } - - @Override - public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { - cc.setNetworkTimeout(executor, milliseconds); - } - - @Override - public int getNetworkTimeout() throws SQLException { - return cc.getNetworkTimeout(); - } + private Connection cc; + + public ConnectionWrap(Connection cc) { + super(); + this.cc = cc; + } + + public Connection getCon() { + return cc; + } + + public void realClose() throws SQLException { + cc.close(); + } + + @Override + public T unwrap(Class iface) throws SQLException { + return cc.unwrap(iface); + } + + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + return cc.isWrapperFor(iface); + } + + @Override + public Statement createStatement() throws SQLException { + return cc.createStatement(); + } + + @Override + public PreparedStatement prepareStatement(String sql) throws SQLException { + return cc.prepareStatement(sql); + } + + @Override + public CallableStatement prepareCall(String sql) throws SQLException { + return cc.prepareCall(sql); + } + + @Override + public String nativeSQL(String sql) throws SQLException { + return cc.nativeSQL(sql); + } + + @Override + public void setAutoCommit(boolean autoCommit) throws SQLException { + cc.setAutoCommit(autoCommit); + } + + @Override + public boolean getAutoCommit() throws SQLException { + return cc.getAutoCommit(); + } + + @Override + public void commit() throws SQLException { + cc.commit(); + } + + @Override + public void rollback() throws SQLException { + cc.rollback(); + } + + @Override + public void close() throws SQLException { + } + + @Override + public boolean isClosed() throws SQLException { + return cc.isClosed(); + } + + @Override + public DatabaseMetaData getMetaData() throws SQLException { + return cc.getMetaData(); + } + + @Override + public void setReadOnly(boolean readOnly) throws SQLException { + cc.setReadOnly(readOnly); + } + + @Override + public boolean isReadOnly() throws SQLException { + return cc.isReadOnly(); + } + + @Override + public void setCatalog(String catalog) throws SQLException { + cc.setCatalog(catalog); + } + + @Override + public String getCatalog() throws SQLException { + return cc.getCatalog(); + } + + @Override + public void setTransactionIsolation(int level) throws SQLException { + cc.setTransactionIsolation(level); + } + + @Override + public int getTransactionIsolation() throws SQLException { + return cc.getTransactionIsolation(); + } + + @Override + public SQLWarning getWarnings() throws SQLException { + return cc.getWarnings(); + } + + @Override + public void clearWarnings() throws SQLException { + cc.clearWarnings(); + } + + @Override + public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { + return cc.createStatement(resultSetType, resultSetConcurrency); + } + + @Override + public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) + throws SQLException { + return cc.prepareStatement(sql, resultSetType, resultSetConcurrency); + } + + @Override + public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { + return cc.prepareCall(sql, resultSetType, resultSetConcurrency); + } + + @Override + public Map> getTypeMap() throws SQLException { + return cc.getTypeMap(); + } + + @Override + public void setTypeMap(Map> map) throws SQLException { + cc.setTypeMap(map); + } + + @Override + public void setHoldability(int holdability) throws SQLException { + cc.setHoldability(holdability); + } + + @Override + public int getHoldability() throws SQLException { + return cc.getHoldability(); + } + + @Override + public Savepoint setSavepoint() throws SQLException { + return cc.setSavepoint(); + } + + @Override + public Savepoint setSavepoint(String name) throws SQLException { + return cc.setSavepoint(name); + } + + @Override + public void rollback(Savepoint savepoint) throws SQLException { + cc.rollback(savepoint); + } + + @Override + public void releaseSavepoint(Savepoint savepoint) throws SQLException { + cc.releaseSavepoint(savepoint); + } + + @Override + public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) + throws SQLException { + return cc.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); + } + + @Override + public PreparedStatement prepareStatement( + String sql, + int resultSetType, + int resultSetConcurrency, + int resultSetHoldability) throws SQLException { + return cc.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); + } + + @Override + public CallableStatement prepareCall( + String sql, + int resultSetType, + int resultSetConcurrency, + int resultSetHoldability) throws SQLException { + return cc.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability); + } + + @Override + public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { + return cc.prepareStatement(sql, autoGeneratedKeys); + } + + @Override + public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { + return cc.prepareStatement(sql, columnIndexes); + } + + @Override + public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { + return cc.prepareStatement(sql, columnNames); + } + + @Override + public Clob createClob() throws SQLException { + return cc.createClob(); + } + + @Override + public Blob createBlob() throws SQLException { + return cc.createBlob(); + } + + @Override + public NClob createNClob() throws SQLException { + return cc.createNClob(); + } + + @Override + public SQLXML createSQLXML() throws SQLException { + return cc.createSQLXML(); + } + + @Override + public boolean isValid(int timeout) throws SQLException { + return cc.isValid(timeout); + } + + @Override + public void setClientInfo(String name, String value) throws SQLClientInfoException { + cc.setClientInfo(name, value); + } + + @Override + public void setClientInfo(Properties properties) throws SQLClientInfoException { + cc.setClientInfo(properties); + } + + @Override + public String getClientInfo(String name) throws SQLException { + return cc.getClientInfo(name); + } + + @Override + public Properties getClientInfo() throws SQLException { + return cc.getClientInfo(); + } + + @Override + public Array createArrayOf(String typeName, Object[] elements) throws SQLException { + return cc.createArrayOf(typeName, elements); + } + + @Override + public Struct createStruct(String typeName, Object[] attributes) throws SQLException { + return cc.createStruct(typeName, attributes); + } + + @Override + public void setSchema(String schema) throws SQLException { + cc.setSchema(schema); + } + + @Override + public String getSchema() throws SQLException { + return cc.getSchema(); + } + + @Override + public void abort(Executor executor) throws SQLException { + cc.abort(executor); + } + + @Override + public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { + cc.setNetworkTimeout(executor, milliseconds); + } + + @Override + public int getNetworkTimeout() throws SQLException { + return cc.getNetworkTimeout(); + } } diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/DataSourceWrap.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/DataSourceWrap.java index d729e127..b01b31f9 100644 --- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/DataSourceWrap.java +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/DataSourceWrap.java @@ -3,7 +3,7 @@ * openECOMP : SDN-C * ================================================================================ * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,66 +33,66 @@ import org.slf4j.LoggerFactory; public class DataSourceWrap implements DataSource { - private static final Logger log = LoggerFactory.getLogger(DataSourceWrap.class); + private static final Logger log = LoggerFactory.getLogger(DataSourceWrap.class); - private DataSource dataSource; + private DataSource dataSource; - @Override - public PrintWriter getLogWriter() throws SQLException { - return dataSource.getLogWriter(); - } + @Override + public PrintWriter getLogWriter() throws SQLException { + return dataSource.getLogWriter(); + } - @Override - public void setLogWriter(PrintWriter out) throws SQLException { - dataSource.setLogWriter(out); - } + @Override + public void setLogWriter(PrintWriter out) throws SQLException { + dataSource.setLogWriter(out); + } - @Override - public void setLoginTimeout(int seconds) throws SQLException { - dataSource.setLoginTimeout(seconds); - } + @Override + public void setLoginTimeout(int seconds) throws SQLException { + dataSource.setLoginTimeout(seconds); + } - @Override - public int getLoginTimeout() throws SQLException { - return dataSource.getLoginTimeout(); - } + @Override + public int getLoginTimeout() throws SQLException { + return dataSource.getLoginTimeout(); + } - @Override - public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException { - return dataSource.getParentLogger(); - } + @Override + public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException { + return dataSource.getParentLogger(); + } - @Override - public T unwrap(Class iface) throws SQLException { - return dataSource.unwrap(iface); - } + @Override + public T unwrap(Class iface) throws SQLException { + return dataSource.unwrap(iface); + } - @Override - public boolean isWrapperFor(Class iface) throws SQLException { - return dataSource.isWrapperFor(iface); - } + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + return dataSource.isWrapperFor(iface); + } - @Override - public Connection getConnection() throws SQLException { - Connection c = dataSource.getConnection(); + @Override + public Connection getConnection() throws SQLException { + Connection c = dataSource.getConnection(); - log.debug("getConnection: " + c.getClass().getName()); + log.debug("getConnection: " + c.getClass().getName()); - c.setAutoCommit(true); - return c; - } + c.setAutoCommit(true); + return c; + } - @Override - public Connection getConnection(String username, String password) throws SQLException { - Connection c = dataSource.getConnection(username, password); + @Override + public Connection getConnection(String username, String password) throws SQLException { + Connection c = dataSource.getConnection(username, password); - log.debug("getConnection: " + c.getClass().getName()); + log.debug("getConnection: " + c.getClass().getName()); - c.setAutoCommit(true); - return c; - } + c.setAutoCommit(true); + return c; + } - public void setDataSource(DataSource dataSource) { - this.dataSource = dataSource; - } + public void setDataSource(DataSource dataSource) { + this.dataSource = dataSource; + } } diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/expr/ExpressionEvaluator.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/expr/ExpressionEvaluator.java index ff15d770..345a6263 100644 --- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/expr/ExpressionEvaluator.java +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/expr/ExpressionEvaluator.java @@ -3,7 +3,7 @@ * openECOMP : SDN-C * ================================================================================ * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,183 +25,183 @@ import java.util.Map; public class ExpressionEvaluator { - public static long evalLong(String expr, Map vars) { - return (long) evalFloat(expr, vars); - } - - public static float evalFloat(String expr, Map vars) { - expr = expr.trim(); - int sl = expr.length(); - if (sl == 0) - throw new IllegalArgumentException("Cannot interpret empty string."); - - // Remove parentheses if any - if (expr.charAt(0) == '(' && expr.charAt(sl - 1) == ')') - return evalFloat(expr.substring(1, sl - 1), vars); - - // Look for operators in the order of least priority - String[] sss = findOperator(expr, "-", true); - if (sss != null) - return evalFloat(sss[0], vars) - evalFloat(sss[1], vars); - - sss = findOperator(expr, "+", true); - if (sss != null) - return evalFloat(sss[0], vars) + evalFloat(sss[1], vars); - - sss = findOperator(expr, "/", true); - if (sss != null) - return evalFloat(sss[0], vars) / evalFloat(sss[1], vars); - - sss = findOperator(expr, "*", true); - if (sss != null) - return evalFloat(sss[0], vars) * evalFloat(sss[1], vars); - - // Check if expr is a number - try { - return Float.valueOf(expr); - } catch (Exception e) { - } - - // Must be a variable - Object v = vars.get(expr); - if (v != null) { - if (v instanceof Float) - return (Float) v; - if (v instanceof Long) - return (Long) v; - if (v instanceof Integer) - return (Integer) v; - } - return 0; - } - - public static boolean evalBoolean(String expr, Map vars) { - expr = expr.trim(); - int sl = expr.length(); - if (sl == 0) - throw new IllegalArgumentException("Cannot interpret empty string."); - - if (expr.equalsIgnoreCase("true")) - return true; - - if (expr.equalsIgnoreCase("false")) - return false; - - // Remove parentheses if any - if (expr.charAt(0) == '(' && expr.charAt(sl - 1) == ')') - return evalBoolean(expr.substring(1, sl - 1), vars); - - // Look for operators in the order of least priority - String[] sss = findOperator(expr, "or", true); - if (sss != null) - return evalBoolean(sss[0], vars) || evalBoolean(sss[1], vars); - - sss = findOperator(expr, "and", true); - if (sss != null) - return evalBoolean(sss[0], vars) && evalBoolean(sss[1], vars); - - sss = findOperator(expr, "not", true); - if (sss != null) - return !evalBoolean(sss[1], vars); - - sss = findOperator(expr, "!=", false); - if (sss == null) - sss = findOperator(expr, "<>", false); - if (sss != null) - return evalLong(sss[0], vars) != evalLong(sss[1], vars); - - sss = findOperator(expr, "==", false); - if (sss == null) - sss = findOperator(expr, "=", false); - if (sss != null) - return evalLong(sss[0], vars) == evalLong(sss[1], vars); - - sss = findOperator(expr, ">=", false); - if (sss != null) - return evalLong(sss[0], vars) >= evalLong(sss[1], vars); - - sss = findOperator(expr, ">", false); - if (sss != null) - return evalLong(sss[0], vars) > evalLong(sss[1], vars); - - sss = findOperator(expr, "<=", false); - if (sss != null) - return evalLong(sss[0], vars) <= evalLong(sss[1], vars); - - sss = findOperator(expr, "<", false); - if (sss != null) - return evalLong(sss[0], vars) < evalLong(sss[1], vars); - - throw new IllegalArgumentException("Cannot interpret '" + expr + "': Invalid expression."); - } - - private static String[] findOperator(String s, String op, boolean delimiterRequired) { - int opl = op.length(); - int sl = s.length(); - String delimiters = " \0\t\r\n()"; - int pcount = 0, qcount = 0; - for (int i = 0; i < sl; i++) { - char c = s.charAt(i); - if (c == '(' && qcount == 0) - pcount++; - else if (c == ')' && qcount == 0) { - pcount--; - if (pcount < 0) - throw new IllegalArgumentException("Cannot interpret '" + s + "': Parentheses do not match."); - } else if (c == '\'') - qcount = (qcount + 1) % 2; - else if (i <= sl - opl && pcount == 0 && qcount == 0) { - String ss = s.substring(i, i + opl); - if (ss.equalsIgnoreCase(op)) { - boolean found = true; - if (delimiterRequired) { - // Check for delimiter before and after to make sure it is not part of another word - char chbefore = '\0'; - if (i > 0) - chbefore = s.charAt(i - 1); - char chafter = '\0'; - if (i < sl - opl) - chafter = s.charAt(i + opl); - found = delimiters.indexOf(chbefore) >= 0 && delimiters.indexOf(chafter) >= 0; - } - if (found) { - // We've found the operator, split the string - String[] sss = new String[2]; - sss[0] = s.substring(0, i); - sss[1] = s.substring(i + opl); - return sss; - } - } - } - } - if (pcount > 0) - throw new IllegalArgumentException("Cannot interpret '" + s + "': Parentheses do not match."); - if (qcount > 0) - throw new IllegalArgumentException("Cannot interpret '" + s + "': No closing '."); - return null; - } - - private static Object parseObject(String s) { - s = s.trim(); - int sl = s.length(); - if (sl == 0) - throw new IllegalArgumentException("Cannot interpret empty string."); - if (s.equalsIgnoreCase("null")) - return null; - if (s.charAt(0) == '\'') { - if (sl < 2 || s.charAt(sl - 1) != '\'') - throw new IllegalArgumentException("Cannot interpret '" + s + "': No closing '."); - return s.substring(1, sl - 1); - } - // Not in quotes - must be a number - try { - return Long.valueOf(s); - } catch (Exception e) { - } - try { - return Double.valueOf(s); - } catch (Exception e) { - throw new IllegalArgumentException("Cannot interpret '" + s + "': Invalid number."); - } - } + public static long evalLong(String expr, Map vars) { + return (long) evalFloat(expr, vars); + } + + public static float evalFloat(String expr, Map vars) { + expr = expr.trim(); + int sl = expr.length(); + if (sl == 0) + throw new IllegalArgumentException("Cannot interpret empty string."); + + // Remove parentheses if any + if (expr.charAt(0) == '(' && expr.charAt(sl - 1) == ')') + return evalFloat(expr.substring(1, sl - 1), vars); + + // Look for operators in the order of least priority + String[] sss = findOperator(expr, "-", true); + if (sss != null) + return evalFloat(sss[0], vars) - evalFloat(sss[1], vars); + + sss = findOperator(expr, "+", true); + if (sss != null) + return evalFloat(sss[0], vars) + evalFloat(sss[1], vars); + + sss = findOperator(expr, "/", true); + if (sss != null) + return evalFloat(sss[0], vars) / evalFloat(sss[1], vars); + + sss = findOperator(expr, "*", true); + if (sss != null) + return evalFloat(sss[0], vars) * evalFloat(sss[1], vars); + + // Check if expr is a number + try { + return Float.valueOf(expr); + } catch (Exception e) { + } + + // Must be a variable + Object v = vars.get(expr); + if (v != null) { + if (v instanceof Float) + return (Float) v; + if (v instanceof Long) + return (Long) v; + if (v instanceof Integer) + return (Integer) v; + } + return 0; + } + + public static boolean evalBoolean(String expr, Map vars) { + expr = expr.trim(); + int sl = expr.length(); + if (sl == 0) + throw new IllegalArgumentException("Cannot interpret empty string."); + + if (expr.equalsIgnoreCase("true")) + return true; + + if (expr.equalsIgnoreCase("false")) + return false; + + // Remove parentheses if any + if (expr.charAt(0) == '(' && expr.charAt(sl - 1) == ')') + return evalBoolean(expr.substring(1, sl - 1), vars); + + // Look for operators in the order of least priority + String[] sss = findOperator(expr, "or", true); + if (sss != null) + return evalBoolean(sss[0], vars) || evalBoolean(sss[1], vars); + + sss = findOperator(expr, "and", true); + if (sss != null) + return evalBoolean(sss[0], vars) && evalBoolean(sss[1], vars); + + sss = findOperator(expr, "not", true); + if (sss != null) + return !evalBoolean(sss[1], vars); + + sss = findOperator(expr, "!=", false); + if (sss == null) + sss = findOperator(expr, "<>", false); + if (sss != null) + return evalLong(sss[0], vars) != evalLong(sss[1], vars); + + sss = findOperator(expr, "==", false); + if (sss == null) + sss = findOperator(expr, "=", false); + if (sss != null) + return evalLong(sss[0], vars) == evalLong(sss[1], vars); + + sss = findOperator(expr, ">=", false); + if (sss != null) + return evalLong(sss[0], vars) >= evalLong(sss[1], vars); + + sss = findOperator(expr, ">", false); + if (sss != null) + return evalLong(sss[0], vars) > evalLong(sss[1], vars); + + sss = findOperator(expr, "<=", false); + if (sss != null) + return evalLong(sss[0], vars) <= evalLong(sss[1], vars); + + sss = findOperator(expr, "<", false); + if (sss != null) + return evalLong(sss[0], vars) < evalLong(sss[1], vars); + + throw new IllegalArgumentException("Cannot interpret '" + expr + "': Invalid expression."); + } + + private static String[] findOperator(String s, String op, boolean delimiterRequired) { + int opl = op.length(); + int sl = s.length(); + String delimiters = " \0\t\r\n()"; + int pcount = 0, qcount = 0; + for (int i = 0; i < sl; i++) { + char c = s.charAt(i); + if (c == '(' && qcount == 0) + pcount++; + else if (c == ')' && qcount == 0) { + pcount--; + if (pcount < 0) + throw new IllegalArgumentException("Cannot interpret '" + s + "': Parentheses do not match."); + } else if (c == '\'') + qcount = (qcount + 1) % 2; + else if (i <= sl - opl && pcount == 0 && qcount == 0) { + String ss = s.substring(i, i + opl); + if (ss.equalsIgnoreCase(op)) { + boolean found = true; + if (delimiterRequired) { + // Check for delimiter before and after to make sure it is not part of another word + char chbefore = '\0'; + if (i > 0) + chbefore = s.charAt(i - 1); + char chafter = '\0'; + if (i < sl - opl) + chafter = s.charAt(i + opl); + found = delimiters.indexOf(chbefore) >= 0 && delimiters.indexOf(chafter) >= 0; + } + if (found) { + // We've found the operator, split the string + String[] sss = new String[2]; + sss[0] = s.substring(0, i); + sss[1] = s.substring(i + opl); + return sss; + } + } + } + } + if (pcount > 0) + throw new IllegalArgumentException("Cannot interpret '" + s + "': Parentheses do not match."); + if (qcount > 0) + throw new IllegalArgumentException("Cannot interpret '" + s + "': No closing '."); + return null; + } + + private static Object parseObject(String s) { + s = s.trim(); + int sl = s.length(); + if (sl == 0) + throw new IllegalArgumentException("Cannot interpret empty string."); + if (s.equalsIgnoreCase("null")) + return null; + if (s.charAt(0) == '\'') { + if (sl < 2 || s.charAt(sl - 1) != '\'') + throw new IllegalArgumentException("Cannot interpret '" + s + "': No closing '."); + return s.substring(1, sl - 1); + } + // Not in quotes - must be a number + try { + return Long.valueOf(s); + } catch (Exception e) { + } + try { + return Double.valueOf(s); + } catch (Exception e) { + throw new IllegalArgumentException("Cannot interpret '" + s + "': Invalid number."); + } + } } diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/speed/SpeedUtil.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/speed/SpeedUtil.java index 8a0b006b..f382a639 100644 --- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/speed/SpeedUtil.java +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/speed/SpeedUtil.java @@ -3,7 +3,7 @@ * openECOMP : SDN-C * ================================================================================ * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,19 +23,19 @@ package org.openecomp.sdnc.util.speed; public class SpeedUtil { - private long unitFactor = 1000; + private long unitFactor = 1000; - public long convertToKbps(long maxSpeed, String unit) { - if (unit.equalsIgnoreCase("kbps")) - return maxSpeed; - if (unit.equalsIgnoreCase("Mbps")) - return maxSpeed * unitFactor; - if (unit.equalsIgnoreCase("Gbps")) - return maxSpeed * unitFactor * unitFactor; - return 0; - } + public long convertToKbps(long maxSpeed, String unit) { + if (unit.equalsIgnoreCase("kbps")) + return maxSpeed; + if (unit.equalsIgnoreCase("Mbps")) + return maxSpeed * unitFactor; + if (unit.equalsIgnoreCase("Gbps")) + return maxSpeed * unitFactor * unitFactor; + return 0; + } - public void setUnitFactor(long unitFactor) { - this.unitFactor = unitFactor; - } + public void setUnitFactor(long unitFactor) { + this.unitFactor = unitFactor; + } } diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/str/StrUtil.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/str/StrUtil.java index 02857e10..f7fa81d1 100644 --- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/str/StrUtil.java +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/str/StrUtil.java @@ -3,7 +3,7 @@ * openECOMP : SDN-C * ================================================================================ * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,269 +37,269 @@ import org.slf4j.LoggerFactory; public class StrUtil { - private static final Logger log = LoggerFactory.getLogger(StrUtil.class); - - public static final String INDENT_STR = " "; - - public static void indent(StringBuilder ss, int ind) { - for (int i = 0; i < ind; i++) - ss.append(INDENT_STR); - } - - public static void info(Logger log, Object o) { - if (log.isInfoEnabled()) { - StringBuilder ss = new StringBuilder(); - struct(ss, o); - log.info(ss.toString()); - } - } - - public static void debug(Logger log, Object o) { - if (log.isDebugEnabled()) { - StringBuilder ss = new StringBuilder(); - struct(ss, o); - log.debug(ss.toString()); - } - } - - public static void struct(StringBuilder ss, Object o) { - struct(ss, o, 0); - } - - public static void struct(StringBuilder ss, Object o, int ind) { - if (o == null) { - ss.append("null"); - return; - } - - if (isSimple(o)) { - ss.append(o); - return; - } - - Class cls = o.getClass(); - - if (cls.isEnum()) { - ss.append(o); - return; - } - - if (cls.isArray()) { - int n = Array.getLength(o); - if (n == 0) { - ss.append("[]"); - return; - } - - Object o1 = Array.get(o, 0); - if (isSimple(o1)) { - ss.append('[').append(o1); - for (int i = 1; i < n; i++) { - o1 = Array.get(o, i); - ss.append(", ").append(o1); - } - ss.append(']'); - return; - } - - ss.append('\n'); - indent(ss, ind + 1); - ss.append('['); - struct(ss, o1, ind + 1); - for (int i = 1; i < n; i++) { - o1 = Array.get(o, i); - struct(ss, o1, ind + 1); - } - ss.append('\n'); - indent(ss, ind + 1); - ss.append(']'); - return; - } - - if (o instanceof Collection) { - Collection ll = (Collection) o; - - int n = ll.size(); - if (n == 0) { - ss.append("[]"); - return; - } - - Iterator ii = ll.iterator(); - Object o1 = ii.next(); - if (isSimple(o1)) { - ss.append('[').append(o1); - while (ii.hasNext()) { - o1 = ii.next(); - ss.append(", ").append(o1); - } - ss.append(']'); - return; - } - - ss.append('\n'); - indent(ss, ind + 1); - ss.append('['); - struct(ss, o1, ind + 1); - while (ii.hasNext()) { - o1 = ii.next(); - struct(ss, o1, ind + 1); - } - ss.append('\n'); - indent(ss, ind + 1); - ss.append(']'); - return; - - } - - if (o instanceof Map) { - Map mm = (Map) o; - - int n = mm.size(); - if (n == 0) { - ss.append("{}"); - return; - } - - ss.append('{'); - - for (Object k : mm.keySet()) { - ss.append('\n'); - indent(ss, ind + 1); - ss.append(k).append(": "); - - Object o1 = mm.get(k); - struct(ss, o1, ind + 2); - } - - ss.append('\n'); - indent(ss, ind); - ss.append('}'); - - return; - } - - Field[] fields = cls.getFields(); - - if (fields.length == 0) { - ss.append(o); - return; - } - - ss.append('\n'); - indent(ss, ind + 1); - ss.append('<').append(cls.getSimpleName()).append("> {"); - for (Field f : fields) { - ss.append('\n'); - indent(ss, ind + 2); - ss.append(f.getName()).append(": "); - Object v = null; - try { - v = f.get(o); - } catch (IllegalAccessException e) { - v = "*** Cannot obtain value *** : " + e.getMessage(); - } - struct(ss, v, ind + 2); - } - ss.append('\n'); - indent(ss, ind + 1); - ss.append('}'); - } - - public static SortedSet listInt(String ss, String warning) { - if (ss == null || ss.length() == 0) - return null; - - SortedSet ll = new TreeSet(); - String[] str = ss.split(","); - for (String s : str) { - try { - int i1 = s.indexOf('-'); - int start, end; - if (i1 > 0) { - String s1 = s.substring(0, i1); - String s2 = s.substring(i1 + 1); - start = Integer.parseInt(s1); - end = Integer.parseInt(s2); - } else - start = end = Integer.parseInt(s); - for (int i = start; i <= end; i++) - ll.add(i); - } catch (NumberFormatException e) { - // Skip this - bad data in DB - log.warn(warning + " [" + s + "].", e); - } - } - return ll; - } - - public static String listInt(SortedSet ll) { - if (ll == null || ll.size() == 0) - return null; - - StringBuilder sb = new StringBuilder(2000); - Iterator i = ll.iterator(); - int n = i.next(); - int start = n; - int end = n; - boolean first = true; - while (i.hasNext()) { - n = i.next(); - if (n != end + 1) { - if (!first) - sb.append(','); - first = false; - - if (start == end) - sb.append(start); - else if (start == end - 1) - sb.append(start).append(',').append(end); - else - sb.append(start).append('-').append(end); - - start = n; - } - end = n; - } - - if (!first) - sb.append(','); - - if (start == end) - sb.append(start); - else if (start == end - 1) - sb.append(start).append(',').append(end); - else - sb.append(start).append('-').append(end); - - return sb.toString(); - } - - public static List listStr(String s) { - if (s == null || s.length() == 0) - return null; - String[] ss = s.split(","); - return Arrays.asList(ss); - } - - public static String listStr(Collection ll) { - if (ll == null || ll.isEmpty()) - return null; - StringBuilder ss = new StringBuilder(1000); - Iterator i = ll.iterator(); - ss.append(i.next()); - while (i.hasNext()) - ss.append(',').append(i.next()); - return ss.toString(); - } - - private static boolean isSimple(Object o) { - if (o == null) - return true; - - if (o instanceof Number || o instanceof String || o instanceof Boolean || o instanceof Date) - return true; - - return false; - } + private static final Logger log = LoggerFactory.getLogger(StrUtil.class); + + public static final String INDENT_STR = " "; + + public static void indent(StringBuilder ss, int ind) { + for (int i = 0; i < ind; i++) + ss.append(INDENT_STR); + } + + public static void info(Logger log, Object o) { + if (log.isInfoEnabled()) { + StringBuilder ss = new StringBuilder(); + struct(ss, o); + log.info(ss.toString()); + } + } + + public static void debug(Logger log, Object o) { + if (log.isDebugEnabled()) { + StringBuilder ss = new StringBuilder(); + struct(ss, o); + log.debug(ss.toString()); + } + } + + public static void struct(StringBuilder ss, Object o) { + struct(ss, o, 0); + } + + public static void struct(StringBuilder ss, Object o, int ind) { + if (o == null) { + ss.append("null"); + return; + } + + if (isSimple(o)) { + ss.append(o); + return; + } + + Class cls = o.getClass(); + + if (cls.isEnum()) { + ss.append(o); + return; + } + + if (cls.isArray()) { + int n = Array.getLength(o); + if (n == 0) { + ss.append("[]"); + return; + } + + Object o1 = Array.get(o, 0); + if (isSimple(o1)) { + ss.append('[').append(o1); + for (int i = 1; i < n; i++) { + o1 = Array.get(o, i); + ss.append(", ").append(o1); + } + ss.append(']'); + return; + } + + ss.append('\n'); + indent(ss, ind + 1); + ss.append('['); + struct(ss, o1, ind + 1); + for (int i = 1; i < n; i++) { + o1 = Array.get(o, i); + struct(ss, o1, ind + 1); + } + ss.append('\n'); + indent(ss, ind + 1); + ss.append(']'); + return; + } + + if (o instanceof Collection) { + Collection ll = (Collection) o; + + int n = ll.size(); + if (n == 0) { + ss.append("[]"); + return; + } + + Iterator ii = ll.iterator(); + Object o1 = ii.next(); + if (isSimple(o1)) { + ss.append('[').append(o1); + while (ii.hasNext()) { + o1 = ii.next(); + ss.append(", ").append(o1); + } + ss.append(']'); + return; + } + + ss.append('\n'); + indent(ss, ind + 1); + ss.append('['); + struct(ss, o1, ind + 1); + while (ii.hasNext()) { + o1 = ii.next(); + struct(ss, o1, ind + 1); + } + ss.append('\n'); + indent(ss, ind + 1); + ss.append(']'); + return; + + } + + if (o instanceof Map) { + Map mm = (Map) o; + + int n = mm.size(); + if (n == 0) { + ss.append("{}"); + return; + } + + ss.append('{'); + + for (Object k : mm.keySet()) { + ss.append('\n'); + indent(ss, ind + 1); + ss.append(k).append(": "); + + Object o1 = mm.get(k); + struct(ss, o1, ind + 2); + } + + ss.append('\n'); + indent(ss, ind); + ss.append('}'); + + return; + } + + Field[] fields = cls.getFields(); + + if (fields.length == 0) { + ss.append(o); + return; + } + + ss.append('\n'); + indent(ss, ind + 1); + ss.append('<').append(cls.getSimpleName()).append("> {"); + for (Field f : fields) { + ss.append('\n'); + indent(ss, ind + 2); + ss.append(f.getName()).append(": "); + Object v = null; + try { + v = f.get(o); + } catch (IllegalAccessException e) { + v = "*** Cannot obtain value *** : " + e.getMessage(); + } + struct(ss, v, ind + 2); + } + ss.append('\n'); + indent(ss, ind + 1); + ss.append('}'); + } + + public static SortedSet listInt(String ss, String warning) { + if (ss == null || ss.length() == 0) + return null; + + SortedSet ll = new TreeSet(); + String[] str = ss.split(","); + for (String s : str) { + try { + int i1 = s.indexOf('-'); + int start, end; + if (i1 > 0) { + String s1 = s.substring(0, i1); + String s2 = s.substring(i1 + 1); + start = Integer.parseInt(s1); + end = Integer.parseInt(s2); + } else + start = end = Integer.parseInt(s); + for (int i = start; i <= end; i++) + ll.add(i); + } catch (NumberFormatException e) { + // Skip this - bad data in DB + log.warn(warning + " [" + s + "].", e); + } + } + return ll; + } + + public static String listInt(SortedSet ll) { + if (ll == null || ll.size() == 0) + return null; + + StringBuilder sb = new StringBuilder(2000); + Iterator i = ll.iterator(); + int n = i.next(); + int start = n; + int end = n; + boolean first = true; + while (i.hasNext()) { + n = i.next(); + if (n != end + 1) { + if (!first) + sb.append(','); + first = false; + + if (start == end) + sb.append(start); + else if (start == end - 1) + sb.append(start).append(',').append(end); + else + sb.append(start).append('-').append(end); + + start = n; + } + end = n; + } + + if (!first) + sb.append(','); + + if (start == end) + sb.append(start); + else if (start == end - 1) + sb.append(start).append(',').append(end); + else + sb.append(start).append('-').append(end); + + return sb.toString(); + } + + public static List listStr(String s) { + if (s == null || s.length() == 0) + return null; + String[] ss = s.split(","); + return Arrays.asList(ss); + } + + public static String listStr(Collection ll) { + if (ll == null || ll.isEmpty()) + return null; + StringBuilder ss = new StringBuilder(1000); + Iterator i = ll.iterator(); + ss.append(i.next()); + while (i.hasNext()) + ss.append(',').append(i.next()); + return ss.toString(); + } + + private static boolean isSimple(Object o) { + if (o == null) + return true; + + if (o instanceof Number || o instanceof String || o instanceof Boolean || o instanceof Date) + return true; + + return false; + } } diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/vrf/VpnParam.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/vrf/VpnParam.java index a9d69507..a28b0aff 100644 --- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/vrf/VpnParam.java +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/vrf/VpnParam.java @@ -3,7 +3,7 @@ * openECOMP : SDN-C * ================================================================================ * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,8 @@ package org.openecomp.sdnc.util.vrf; public class VpnParam { - public String vpnId; - public String siteType; - public String spokeServiceInstanceId; - public String routeGroupName; + public String vpnId; + public String siteType; + public String spokeServiceInstanceId; + public String routeGroupName; } diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/vrf/VrfUtil.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/vrf/VrfUtil.java index d5a691bb..2b90027c 100644 --- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/vrf/VrfUtil.java +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/vrf/VrfUtil.java @@ -3,7 +3,7 @@ * openECOMP : SDN-C * ================================================================================ * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,54 +23,54 @@ package org.openecomp.sdnc.util.vrf; public class VrfUtil { - public static String createVrfInstanceName( - String serviceInstanceId, - String vpnId, - String siteType, - String routeGroup) { - if (vpnId == null || vpnId.trim().length() == 0) - return null; + public static String createVrfInstanceName( + String serviceInstanceId, + String vpnId, + String siteType, + String routeGroup) { + if (vpnId == null || vpnId.trim().length() == 0) + return null; - String ss = "VPN-" + vpnId; - if (siteType != null && siteType.equalsIgnoreCase("hub")) - ss += "-HUB"; - if (siteType != null && siteType.equalsIgnoreCase("spoke")) - ss += "-SP-" + serviceInstanceId; - if (routeGroup != null && routeGroup.trim().length() > 0) - ss += "-RG-" + routeGroup; + String ss = "VPN-" + vpnId; + if (siteType != null && siteType.equalsIgnoreCase("hub")) + ss += "-HUB"; + if (siteType != null && siteType.equalsIgnoreCase("spoke")) + ss += "-SP-" + serviceInstanceId; + if (routeGroup != null && routeGroup.trim().length() > 0) + ss += "-RG-" + routeGroup; - return ss; - } + return ss; + } - public static VpnParam parseVrfInstanceName(String vrfInstanceName) { - VpnParam vpnParam = new VpnParam(); + public static VpnParam parseVrfInstanceName(String vrfInstanceName) { + VpnParam vpnParam = new VpnParam(); - int i1 = vrfInstanceName.indexOf("-HUB"); - if (i1 > 0) - vpnParam.siteType = "HUB"; + int i1 = vrfInstanceName.indexOf("-HUB"); + if (i1 > 0) + vpnParam.siteType = "HUB"; - int i2 = vrfInstanceName.indexOf("-SP-"); - if (i2 > 0) - vpnParam.siteType = "SPOKE"; + int i2 = vrfInstanceName.indexOf("-SP-"); + if (i2 > 0) + vpnParam.siteType = "SPOKE"; - int i3 = vrfInstanceName.indexOf("-RG-"); - if (i3 > 0) - vpnParam.routeGroupName = vrfInstanceName.substring(i3 + 4); + int i3 = vrfInstanceName.indexOf("-RG-"); + if (i3 > 0) + vpnParam.routeGroupName = vrfInstanceName.substring(i3 + 4); - int i4 = vrfInstanceName.length(); - if (i1 > 0) - i4 = i1; - else if (i2 > 0) - i4 = i2; - else if (i3 > 0) - i4 = i3; - vpnParam.vpnId = vrfInstanceName.substring(4, i4); + int i4 = vrfInstanceName.length(); + if (i1 > 0) + i4 = i1; + else if (i2 > 0) + i4 = i2; + else if (i3 > 0) + i4 = i3; + vpnParam.vpnId = vrfInstanceName.substring(4, i4); - if (i2 > 0 && i3 < 0) - vpnParam.spokeServiceInstanceId = vrfInstanceName.substring(i2 + 4); - if (i2 > 0 && i3 > 0) - vpnParam.spokeServiceInstanceId = vrfInstanceName.substring(i2 + 4, i3); + if (i2 > 0 && i3 < 0) + vpnParam.spokeServiceInstanceId = vrfInstanceName.substring(i2 + 4); + if (i2 > 0 && i3 > 0) + vpnParam.spokeServiceInstanceId = vrfInstanceName.substring(i2 + 4, i3); - return vpnParam; - } + return vpnParam; + } } -- cgit 1.2.3-korg