Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package net.datenstrudel.bulbs.shared.domain.model.bulb;
  
  
Value that contains address data in order to communicate with BulbBridge Hardware
 
     //~ Member(s) //////////////////////////////////////////////////////////////
     @NotNull @Size(min = 3)
 	private String host;
     @NotNull @Min(1) @Max(65535)
 	private Integer port;
 
     private String macAddress;
     
     //~ Construction ///////////////////////////////////////////////////////////
 	private BulbBridgeAddress(){}
     public BulbBridgeAddress(String hostInteger port) {
         setHost(host);
         setPort(port);
     }
     public BulbBridgeAddress(String hostInteger portString macAddress) {
         setHost(host);
         setPort(port);
         setMacAddress(macAddress);
     }
 
     //~ Method(s) //////////////////////////////////////////////////////////////
     public String getHost() {
         return ;
     }
     public Integer getPort() {
         return ;
     }
     private String getMacAddress() {
         return ;
     }
     public Optional<StringmacAddress() {
         return Optional.ofNullable();
     }
 
     public String toHttpAddress(){
         return "http://" +  + ":" +  + "/";
     }
     public InetAddress toInetAddress() {
         try {
             return InetAddress.getByName();
         } catch (UnknownHostException e) {
             throw new RuntimeException("Unknown host: " + );
         }
     }

    

Returns:
This' address broadcast address representation with subnet mask 255.255.255.0
 
     public InetAddress toBroadcastAddress(){
         byte[] addressHost = toInetAddress().getAddress();
         BitSet res = BitSet.valueOf(new byte[]{0, 0, 0, -1}); // flipped
         res.or(BitSet.valueOf(addressHost));
         try{
             return InetAddress.getByAddress(res.toByteArray());
         } catch (UnknownHostException e) {
             throw new RuntimeException("Unknown host: " + );
         }
     }

    

Parameters:
subnetMask which the broadcast address is based on
Returns:
The boradcast address of this by applying given subnetMask
 
     protected InetAddress toBroadcastAddress(InetAddress subnetMask){
         byte[] addressHost = toInetAddress().getAddress();
         byte[] sMask =  subnetMask.getAddress();
 
         for(int i = 0; i < sMask.lengthi++){
             sMask[i]= (byte) ~sMask[i];
         }
 
         BitSet res = BitSet.valueOf(sMask);
         res.or(BitSet.valueOf(addressHost));
         try{
             return InetAddress.getByAddress(res.toByteArray());
         } catch (UnknownHostException e) {
             throw new RuntimeException("Unknown host: " + );
         }
    }
    @Override
    public boolean sameValueAs(BulbBridgeAddress other) {
        if(other == null)return false;
        if(!.equals(other.host))return false;
        if(!.equals(other.port))return false;
        return true;
    }
    @Override
    public int hashCode() {
        int hash = 7;
        hash = 89 * hash + (this. != null ? this..hashCode() : 0);
        hash = 89 * hash + (this. != null ? this..hashCode() : 0);
        return hash;
    }
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final BulbBridgeAddress other = (BulbBridgeAddressobj;
        return this.sameValueAs(other);
    }
    @Override
    public String toString() {
        return "BulbBridgeAddress{" + toHttpAddress() + "}";
    }
    
    //~ Private Artifact(s) ////////////////////////////////////////////////////
    private void setHost(String host) {
        if(host.startsWith("http://"))
            this. = host.replace("http://""");
        this. = host;
    }
    private void setPort(Integer port) {
        this. = port;
    }
    private void setMacAddress(String macAddress) {
        this. = macAddress;
    }
New to GrepCode? Check out our FAQ X