Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8254996: make jdk.net.UnixDomainPrincipal a record class
Reviewed-by: dfuchs, michaelm
  • Loading branch information
pconcannon committed Dec 9, 2020
1 parent bd22aa5 commit 6dd06ad
Showing 1 changed file with 7 additions and 49 deletions.
56 changes: 7 additions & 49 deletions src/jdk.net/share/classes/jdk/net/UnixDomainPrincipal.java
Expand Up @@ -34,65 +34,23 @@
* <a href="../../../java.base/java/nio/channels/package-summary.html#unixdomain">
* Unix domain</a> socket.
*
* @param user the user identity
* @param group the group identity
*
* @since 16
*/

public final class UnixDomainPrincipal {
private final UserPrincipal user;
private final GroupPrincipal group;
public record UnixDomainPrincipal(UserPrincipal user, GroupPrincipal group) {

/**
* Creates a UnixDomainPrincipal.
*
* @param user the user identity
*
* @param group the group identity
*
* @throws NullPointerException if {@code user} or {@code group} are {@code null}.
*/
public UnixDomainPrincipal(UserPrincipal user, GroupPrincipal group) {
this.user = Objects.requireNonNull(user);
this.group = Objects.requireNonNull(group);
}

/**
* Returns true if {@code obj} is a {@code UnixDomainPrincipal}
* and its user and group are equal to this user and group.
*
* @param obj the object to compare with
* @return true if this equal to obj
*/
public boolean equals(Object obj) {
if (obj instanceof UnixDomainPrincipal) {
UnixDomainPrincipal that = (UnixDomainPrincipal) obj;
return Objects.equals(this.user, that.user)
&& Objects.equals(this.group, that.group);
}
return false;
}

/**
* Returns a hashcode calculated from the user and group
*/
public int hashCode() {
return Objects.hash(user, group);
}

/**
* Returns this object's {@link UserPrincipal}
*
* @return this object's user
*/
public UserPrincipal user() {
return user;
}

/**
* Returns this object's {@link GroupPrincipal}
*
* @return this object's user
*/
public GroupPrincipal group() {
return group;
public UnixDomainPrincipal {
Objects.requireNonNull(user);
Objects.requireNonNull(group);
}
}

1 comment on commit 6dd06ad

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.