@Test public void testNode2Provider() throws Exception { Node node = new Node("node1", "ip/8080/1", 0); ProviderInfo providerInfo = MapperUtil.node2Provider(node); assertNotNull(providerInfo); assertEquals("ip", providerInfo.getIp()); assertEquals(8080, providerInfo.getPort()); assertEquals(1, providerInfo.getWeight()); assertEquals("node1", providerInfo.getName()); node = new Node("node1", "ip/8081/2", 1); MapperUtil.node2Provider(node, providerInfo); assertEquals("ip", providerInfo.getIp()); assertEquals(8081, providerInfo.getPort()); assertEquals(2, providerInfo.getWeight()); assertEquals("node1", providerInfo.getName()); }
public static void node2Provider(Node node, ProviderInfo provider) { String key = node.getKey(); String value = node.getValue(); String[] store = Optional.ofNullable(value).orElse("").trim().split("/"); if (store.length != 2 && store.length != 3) { throw new IllegalArgumentException(String.format("illegal record: key: %s, value: %s", key, value)); } try { int port = Integer.valueOf(store[1]); int weight = store.length == 3 ? Integer.valueOf(store[2]) : 0; provider.setPort(port); provider.setWeight(weight); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("illegal record: illegal port or weight: key: %s, value: %s", key, value)); } String name = new File(key).getName(); provider.setName(name); provider.setIp(store[0]); provider.setVersion(node.getVersion()); }
MapperUtil { public static void node2Provider(Node node, ProviderInfo provider) { String key = node.getKey(); String value = node.getValue(); String[] store = Optional.ofNullable(value).orElse("").trim().split("/"); if (store.length != 2 && store.length != 3) { throw new IllegalArgumentException(String.format("illegal record: key: %s, value: %s", key, value)); } try { int port = Integer.valueOf(store[1]); int weight = store.length == 3 ? Integer.valueOf(store[2]) : 0; provider.setPort(port); provider.setWeight(weight); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("illegal record: illegal port or weight: key: %s, value: %s", key, value)); } String name = new File(key).getName(); provider.setName(name); provider.setIp(store[0]); provider.setVersion(node.getVersion()); } }
MapperUtil { public static void node2Provider(Node node, ProviderInfo provider) { String key = node.getKey(); String value = node.getValue(); String[] store = Optional.ofNullable(value).orElse("").trim().split("/"); if (store.length != 2 && store.length != 3) { throw new IllegalArgumentException(String.format("illegal record: key: %s, value: %s", key, value)); } try { int port = Integer.valueOf(store[1]); int weight = store.length == 3 ? Integer.valueOf(store[2]) : 0; provider.setPort(port); provider.setWeight(weight); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("illegal record: illegal port or weight: key: %s, value: %s", key, value)); } String name = new File(key).getName(); provider.setName(name); provider.setIp(store[0]); provider.setVersion(node.getVersion()); }  }
MapperUtil { public static void node2Provider(Node node, ProviderInfo provider) { String key = node.getKey(); String value = node.getValue(); String[] store = Optional.ofNullable(value).orElse("").trim().split("/"); if (store.length != 2 && store.length != 3) { throw new IllegalArgumentException(String.format("illegal record: key: %s, value: %s", key, value)); } try { int port = Integer.valueOf(store[1]); int weight = store.length == 3 ? Integer.valueOf(store[2]) : 0; provider.setPort(port); provider.setWeight(weight); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("illegal record: illegal port or weight: key: %s, value: %s", key, value)); } String name = new File(key).getName(); provider.setName(name); provider.setIp(store[0]); provider.setVersion(node.getVersion()); }  static void node2Provider(Node node, ProviderInfo provider); static ProviderInfo node2Provider(Node node); }
MapperUtil { public static void node2Provider(Node node, ProviderInfo provider) { String key = node.getKey(); String value = node.getValue(); String[] store = Optional.ofNullable(value).orElse("").trim().split("/"); if (store.length != 2 && store.length != 3) { throw new IllegalArgumentException(String.format("illegal record: key: %s, value: %s", key, value)); } try { int port = Integer.valueOf(store[1]); int weight = store.length == 3 ? Integer.valueOf(store[2]) : 0; provider.setPort(port); provider.setWeight(weight); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("illegal record: illegal port or weight: key: %s, value: %s", key, value)); } String name = new File(key).getName(); provider.setName(name); provider.setIp(store[0]); provider.setVersion(node.getVersion()); }  static void node2Provider(Node node, ProviderInfo provider); static ProviderInfo node2Provider(Node node);  }