Example usage for java.util Objects equals

List of usage examples for java.util Objects equals

Introduction

In this page you can find the example usage for java.util Objects equals.

Prototype

public static boolean equals(Object a, Object b) 

Source Link

Document

Returns true if the arguments are equal to each other and false otherwise.

Usage

From source file:com.jgabriellima.viridis.entity.Medidor.java

@Override
public boolean equals(Object obj) {
    if (obj == null) {
        return false;
    }/*w  ww .  j  a v  a  2  s.  c  o m*/
    if (getClass() != obj.getClass()) {
        return false;
    }
    final Medidor other = (Medidor) obj;
    if (!Objects.equals(this.id, other.id)) {
        return false;
    }
    if (!Objects.equals(this.valor, other.valor)) {
        return false;
    }
    if (!Objects.equals(this.medidor, other.medidor)) {
        return false;
    }
    return true;
}

From source file:org.mascherl.example.service.SendMailService.java

@Transactional
public void sendMail(Mail mail, User currentUser) {
    if (!Objects.equals(currentUser.getEmail(), mail.getFrom().getAddress())) {
        throw new IllegalArgumentException("User can only send an email from his own address");
    }/*  w w w  .  j a v  a 2s.  c  om*/
    if (mail.getTo() == null || mail.getTo().isEmpty()) {
        throw new IllegalArgumentException("Receiver list cannot be empty");
    }

    ZonedDateTime sendTime = ZonedDateTime.now();

    MailEntity sendEntity;
    if (mail.getUuid() != null) {
        sendEntity = em.find(MailEntity.class, mail.getUuid());
        if (!Objects.equals(sendEntity.getUser().getUuid(), currentUser.getUuid())) {
            throw new IllegalArgumentException("The mail to be sent is not a draft of the current user.");
        }
        if (sendEntity.getMailType() != MailType.DRAFT) {
            throw new IllegalArgumentException(
                    "The mail to be sent needs to be a draft, but it is of type " + sendEntity.getMailType());
        }
        sendEntity.setMailType(MailType.SENT);
    } else {
        sendEntity = new MailEntity(MailType.SENT);
        sendEntity.setUser(em.getReference(UserEntity.class, currentUser.getUuid()));
    }
    sendEntity.setDateTime(sendTime);
    sendEntity.setUnread(false);
    sendEntity.setFrom(mail.getFrom());
    sendEntity.setTo(mail.getTo());
    sendEntity.setCc(mail.getCc());
    sendEntity.setBcc(mail.getBcc());
    sendEntity.setSubject(mail.getSubject());
    sendEntity.setMessageText(mail.getMessageText());
    em.persist(sendEntity);

    List<String> receiveUserUuids = findReceiveUserUuids(mail);
    for (String receiveUserUuid : receiveUserUuids) {
        MailEntity receiveEntity = new MailEntity(MailType.RECEIVED);
        receiveEntity.setUser(em.getReference(UserEntity.class, receiveUserUuid));
        receiveEntity.setDateTime(sendTime);
        receiveEntity.setUnread(true);
        receiveEntity.setFrom(mail.getFrom());
        receiveEntity.setTo(mail.getTo());
        receiveEntity.setCc(mail.getCc());
        receiveEntity.setBcc(mail.getBcc());
        receiveEntity.setSubject(mail.getSubject());
        receiveEntity.setMessageText(mail.getMessageText());
        em.persist(receiveEntity);
    }

    em.flush();
}

From source file:com.example.session.domain.service.order.OrderService.java

public Order purchase(Account account, Cart cart, String signature) {
    if (cart.isEmpty()) {
        ResultMessages messages = ResultMessages.error();
        messages.add("e.st.od.8001");
        throw new EmptyCartOrderException(messages);
    }// ww  w  . j  a  va 2  s.c o  m

    if (!Objects.equals(cart.calcSignature(), signature)) {
        ResultMessages messages = ResultMessages.error();
        messages.add("e.st.od.8002");
        throw new InvalidCartOrderException(messages);
    }

    String orderId = UUID.randomUUID().toString();

    Order order = beanMapper.map(cart, Order.class);
    order.setOrderIdToALllOrderLines(orderId);
    order.setEmail(account.getEmail());
    order.setOrderDate(new Date());

    orderRepository.createOrder(order);
    orderRepository.createOrderLines(order.getOrderLines());

    cart.clear();

    return order;
}

From source file:io.pivotal.strepsirrhini.chaosloris.data.ScheduleCreatedEvent.java

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }/*from   w  w  w. j  ava2 s .  c o m*/
    if (o == null || getClass() != o.getClass()) {
        return false;
    }
    ScheduleCreatedEvent that = (ScheduleCreatedEvent) o;
    return Objects.equals(this.schedule, that.schedule) && Objects.equals(getSource(), that.getSource());
}

From source file:io.pivotal.strepsirrhini.chaosloris.data.ScheduleUpdatedEvent.java

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }//  www.  j  a  v  a2s. c  o m
    if (o == null || getClass() != o.getClass()) {
        return false;
    }
    ScheduleUpdatedEvent that = (ScheduleUpdatedEvent) o;
    return Objects.equals(this.schedule, that.schedule) && Objects.equals(getSource(), that.getSource());
}

From source file:com.jivesoftware.os.routing.bird.shared.InstanceDescriptorsRequest.java

@Override
public boolean equals(Object obj) {
    if (obj == null) {
        return false;
    }/*from  w  w  w . j a v  a2s  .c  om*/
    if (getClass() != obj.getClass()) {
        return false;
    }
    final InstanceDescriptorsRequest other = (InstanceDescriptorsRequest) obj;
    if (!Objects.equals(this.hostKey, other.hostKey)) {
        return false;
    }
    return true;
}

From source file:fi.hsl.parkandride.core.domain.Utilization.java

@Override
public boolean equals(Object obj) {
    if (!(obj instanceof Utilization)) {
        return false;
    }//w  w w.  j  av  a 2 s.c o m
    Utilization that = (Utilization) obj;
    return Objects.equals(this.facilityId, that.facilityId)
            && Objects.equals(this.capacityType, that.capacityType) && Objects.equals(this.usage, that.usage)
            && Objects.equals(this.timestamp, that.timestamp)
            && Objects.equals(this.spacesAvailable, that.spacesAvailable);
}

From source file:org.hawkular.client.metrics.model.Gauge.java

@Override
public boolean equals(Object o) {
    if (this == o)
        return true;
    if (o == null || getClass() != o.getClass())
        return false;
    Gauge gauge = (Gauge) o;//w  ww.j a  v a 2 s  . c o  m
    return Objects.equals(id, gauge.id) && Objects.equals(data, gauge.data);
}

From source file:com.jivesoftware.os.routing.bird.shared.TenantChanged.java

@Override
public boolean equals(Object obj) {
    if (obj == null) {
        return false;
    }//from w  w  w . j av a  2 s. co m
    if (getClass() != obj.getClass()) {
        return false;
    }
    final TenantChanged other = (TenantChanged) obj;
    if (!Objects.equals(this.tenantId, other.tenantId)) {
        return false;
    }
    return true;
}

From source file:com.mycompany.wolf.Router.java

public void unregister(Session session) {
    ServerInfo server = servers.stream()
            .filter(s -> Objects.equals(s.getIntranetAddress(), remoteAddress(session))).findAny().orElse(null);
    if (server != null) {
        server.setCurrentSession(null);//from   www. j  a  v  a  2 s.c  o  m
    }
}