SessionSettings { public static int[] parseSettingReconnectInterval(String raw) { if (raw == null || raw.length() == 0) { return null; } final String multiplierCharacter = raw.contains("*") ? "\\*" : "x"; final String[] data = raw.split(";"); final List<Integer> result = new ArrayList<>(); for (final String multi : data) { final String[] timesSec = multi.split(multiplierCharacter); int times; int secs; try { if (timesSec.length > 1) { times = Integer.parseInt(timesSec[0]); secs = Integer.parseInt(timesSec[1]); } else { times = 1; secs = Integer.parseInt(timesSec[0]); } } catch (final NumberFormatException e) { throw new InvalidParameterException( "Invalid number '" + multi + "' in '" + raw + "'. Expected format: [<multiplier>x]<seconds>;[<multiplier>x]<seconds>;..."); } for (int ii = 0; ii != times; ++ii) { result.add(secs); } } final int[] ret = new int[result.size()]; int ii = 0; for (final Integer sec : result) { ret[ii++] = sec; } return ret; } SessionSettings();  SessionSettings(Properties variableValues);  SessionSettings(String filename, Properties variableValues);  SessionSettings(String filename);  SessionSettings(InputStream stream);  SessionSettings(InputStream stream, Properties variableValues); String getString(String key); String getString(SessionID sessionID, String key); Properties getSessionProperties(SessionID sessionID, boolean includeDefaults); Properties getSessionProperties(SessionID sessionID); Properties getDefaultProperties(); long getLong(String key); long getLong(SessionID sessionID, String key); int getInt(String key); int getInt(SessionID sessionID, String key); double getDouble(String key); double getDouble(SessionID sessionID, String key); boolean getBool(String key); boolean getBool(SessionID sessionID, String key); void setString(SessionID sessionID, String key, String value); void setLong(SessionID sessionID, String key, long value); void setDouble(SessionID sessionID, String key, double value); void setBool(SessionID sessionID, String key, boolean value); Iterator<SessionID> sectionIterator(); boolean isSetting(String key); boolean isSetting(SessionID sessionID, String key); void removeSetting(SessionID sessionID, String key); void setVariableValues(Properties variableValues); void set(Map<Object, Object> defaults); void setBool(String key, boolean value); void setDouble(String key, double value); void setLong(String key, long value); void setString(String key, String value); int size(); Dictionary get(SessionID sessionID); void set(SessionID sessionID, Dictionary dictionary); Dictionary get(); void set(Dictionary dictionary); void toString(PrintWriter writer); void toStream(OutputStream out); @Override String toString(); static int[] parseSettingReconnectInterval(String raw); static Set<InetAddress> parseRemoteAddresses(String raw); static final String BEGINSTRING; static final String SENDERCOMPID; static final String SENDERSUBID; static final String SENDERLOCID; static final String TARGETCOMPID; static final String TARGETSUBID; static final String TARGETLOCID; static final String SESSION_QUALIFIER; }
@Test public void testParseSettingReconnectInterval() { assertTrue(Arrays.equals(null, SessionSettings.parseSettingReconnectInterval(""))); assertTrue(Arrays.equals(null, SessionSettings.parseSettingReconnectInterval(null))); assertTrue(Arrays.equals(new int[] { 5 }, SessionSettings.parseSettingReconnectInterval("5"))); assertTrue(Arrays.equals(new int[] { 5, 5 }, SessionSettings.parseSettingReconnectInterval("2x5"))); assertTrue(Arrays.equals(new int[] { 5, 5, 5, 5 }, SessionSettings.parseSettingReconnectInterval("4x5"))); assertTrue(Arrays.equals(new int[] { 5, 5, 15, 15 }, SessionSettings.parseSettingReconnectInterval("2x5;2x15"))); assertTrue(Arrays.equals(new int[] { 5, 5, 15 }, SessionSettings.parseSettingReconnectInterval("2x5;15"))); assertTrue(Arrays.equals(new int[] { 5, 5, 15, 30 }, SessionSettings.parseSettingReconnectInterval("2x5;15;30"))); assertTrue(Arrays.equals(new int[] { 5, 5, 5, 15, 15, 30 }, SessionSettings.parseSettingReconnectInterval("3x5;2x15;30"))); assertTrue(Arrays.equals(new int[] { 5, 5 }, SessionSettings.parseSettingReconnectInterval("2*5"))); assertTrue(Arrays.equals(new int[] { 5, 5, 5, 5 }, SessionSettings.parseSettingReconnectInterval("4*5"))); assertTrue(Arrays.equals(new int[] { 5, 5, 15, 15 }, SessionSettings.parseSettingReconnectInterval("2*5;2*15"))); assertTrue(Arrays.equals(new int[] { 5, 5, 15 }, SessionSettings.parseSettingReconnectInterval("2*5;15"))); assertTrue(Arrays.equals(new int[] { 5, 5, 15, 30 }, SessionSettings.parseSettingReconnectInterval("2*5;15;30"))); assertTrue(Arrays.equals(new int[] { 5, 5, 5, 15, 15, 30 }, SessionSettings.parseSettingReconnectInterval("3*5;2*15;30"))); try { SessionSettings.parseSettingReconnectInterval("2*5;A"); fail("Must throw InvalidParameterException"); } catch (final InvalidParameterException ex) { } }