Source:
<code>public static FlowDocument from(final Flow flow) { final FlowDocument doc = new FlowDocument(); doc.setTimestamp(flow.getTimestamp()); doc.setBytes(flow.getBytes()); doc.setDirection(Direction.from(flow.getDirection())); doc.setDstAddr(flow.getDstAddr()); <START> doc.setDstAddrHostname(flow.getDstAddrHostname().orElse(null)); <END> doc.setDstAs(flow.getDstAs()); doc.setDstMaskLen(flow.getDstMaskLen()); doc.setDstPort(flow.getDstPort()); doc.setEngineId(flow.getEngineId()); doc.setEngineType(flow.getEngineType()); doc.setFirstSwitched(flow.getFirstSwitched()); doc.setFlowRecords(flow.getFlowRecords()); doc.setFlowSeqNum(flow.getFlowSeqNum()); doc.setInputSnmp(flow.getInputSnmp()); doc.setIpProtocolVersion(flow.getIpProtocolVersion()); doc.setLastSwitched(flow.getLastSwitched()); doc.setNextHop(flow.getNextHop()); doc.setNextHopHostname(flow.getNextHopHostname().orElse(null)); doc.setOutputSnmp(flow.getOutputSnmp()); doc.setPackets(flow.getPackets()); doc.setProtocol(flow.getProtocol()); doc.setSamplingAlgorithm(SamplingAlgorithm.from(flow.getSamplingAlgorithm())); doc.setSamplingInterval(flow.getSamplingInterval()); doc.setSrcAddr(flow.getSrcAddr()); doc.setSrcAddrHostname(flow.getSrcAddrHostname().orElse(null)); doc.setSrcAs(flow.getSrcAs()); doc.setSrcMaskLen(flow.getSrcMaskLen()); doc.setSrcPort(flow.getSrcPort()); doc.setTcpFlags(flow.getTcpFlags()); doc.setTos(flow.getTos()); doc.setNetflowVersion(NetflowVersion.from(flow.getNetflowVersion())); doc.setVlan(flow.getVlan() != null ? Integer.toUnsignedString(flow.getVlan()) : null); return doc; }</code><technical_language>avoid calling addHost() null: suggestion flow.getDstAddrHostname().ifPresent(doc::setDstAddrHostname);</technical_language>

Target:
public static FlowDocument from(final Flow flow) { final FlowDocument doc = new FlowDocument(); doc.setTimestamp(flow.getTimestamp()); doc.setBytes(flow.getBytes()); doc.setDirection(Direction.from(flow.getDirection())); doc.setDstAddr(flow.getDstAddr()); flow.getDstAddrHostname().ifPresent(doc::setDstAddrHostname); doc.setDstAs(flow.getDstAs()); doc.setDstMaskLen(flow.getDstMaskLen()); doc.setDstPort(flow.getDstPort()); doc.setEngineId(flow.getEngineId()); doc.setEngineType(flow.getEngineType()); doc.setFirstSwitched(flow.getFirstSwitched()); doc.setFlowRecords(flow.getFlowRecords()); doc.setFlowSeqNum(flow.getFlowSeqNum()); doc.setInputSnmp(flow.getInputSnmp()); doc.setIpProtocolVersion(flow.getIpProtocolVersion()); doc.setLastSwitched(flow.getLastSwitched()); doc.setNextHop(flow.getNextHop()); flow.getNextHopHostname().ifPresent(doc::setNextHopHostname); doc.setOutputSnmp(flow.getOutputSnmp()); doc.setPackets(flow.getPackets()); doc.setProtocol(flow.getProtocol()); doc.setSamplingAlgorithm(SamplingAlgorithm.from(flow.getSamplingAlgorithm())); doc.setSamplingInterval(flow.getSamplingInterval()); doc.setSrcAddr(flow.getSrcAddr()); flow.getSrcAddrHostname().ifPresent(doc::setSrcAddrHostname); doc.setSrcAs(flow.getSrcAs()); doc.setSrcMaskLen(flow.getSrcMaskLen()); doc.setSrcPort(flow.getSrcPort()); doc.setTcpFlags(flow.getTcpFlags()); doc.setTos(flow.getTos()); doc.setNetflowVersion(NetflowVersion.from(flow.getNetflowVersion())); doc.setVlan(flow.getVlan() != null ? Integer.toUnsignedString(flow.getVlan()) : null); return doc; }