MCPcopy Create free account
hub / github.com/DiUS/java-faker / macAddress

Method macAddress

src/main/java/com/github/javafaker/Internet.java:147–162  ·  view source on GitHub ↗

Returns a MAC address in the following format: 6-bytes in MM:MM:MM:SS:SS:SS format. @return a correctly formatted MAC address @param prefix a prefix to put on the front of the address

(String prefix)

Source from the content-addressed store, hash-verified

145 * @param prefix a prefix to put on the front of the address
146 */
147 public String macAddress(String prefix) {
148 final String tmp = (prefix == null) ? "" : prefix;
149 final int prefixLength = tmp.trim().length() == 0
150 ? 0
151 : tmp.split(":").length;
152
153 final StringBuilder out = new StringBuilder(tmp);
154 for (int i=0;i < 6 - prefixLength;i++) {
155 if (out.length() > 0) {
156 out.append(':');
157 }
158 out.append(Integer.toHexString(faker.random().nextInt(16)));
159 out.append(Integer.toHexString(faker.random().nextInt(16)));
160 }
161 return out.toString();
162 }
163
164 /**
165 * @see Internet#macAddress(String)

Callers 1

testMacAddressMethod · 0.80

Calls 3

nextIntMethod · 0.80
toStringMethod · 0.80
randomMethod · 0.45

Tested by 1

testMacAddressMethod · 0.64