Skip to content

Commit c860779

Browse files
committed
[PLXCOMP-174] Switched to simpler solution
Original fix was troubling me. Using an Integer in the interface is much prettier
1 parent 6ed88f3 commit c860779

File tree

6 files changed

+41
-75
lines changed

6 files changed

+41
-75
lines changed

src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -95,38 +95,19 @@ protected void setLsModeParts( char[] mode )
9595
}
9696
}
9797

98-
public int getGroupId()
98+
public Integer getGroupId()
9999
{
100-
if ( !hasGroupId() )
101-
{
102-
throw new IllegalStateException( "Cannot get the group id because it has not been set" );
103-
}
104-
return groupId.intValue();
100+
return groupId;
105101
}
106102

107103
public String getGroupName()
108104
{
109105
return groupName;
110106
}
111107

112-
public int getUserId()
113-
{
114-
if ( !hasUserId() )
115-
{
116-
throw new IllegalStateException( "Cannot get the user id because it has not been set" );
117-
}
118-
119-
return userId.intValue();
120-
}
121-
122-
public boolean hasGroupId()
123-
{
124-
return groupId != null;
125-
}
126-
127-
public boolean hasUserId()
108+
public Integer getUserId()
128109
{
129-
return userId != null;
110+
return userId;
130111
}
131112

132113
public String getUserName()
@@ -192,9 +173,9 @@ public String toString()
192173
sb.append( "\ngroup: " );
193174
sb.append( groupName == null ? "" : groupName );
194175
sb.append( "\nuid: " );
195-
sb.append( hasUserId() ? userId.toString() : "");
176+
sb.append( userId != null ? userId.toString() : "");
196177
sb.append( "\ngid: " );
197-
sb.append( hasGroupId() ? groupId.toString() : "");
178+
sb.append( groupId != null ? groupId.toString() : "");
198179
sb.append( "\nmode: " );
199180
sb.append( mode == null ? "" : String.valueOf( mode ) );
200181

@@ -264,7 +245,7 @@ public PlexusIoResourceAttributes setGroupExecutable( boolean flag )
264245
return this;
265246
}
266247

267-
public PlexusIoResourceAttributes setGroupId( int gid )
248+
public PlexusIoResourceAttributes setGroupId( Integer gid )
268249
{
269250
this.groupId = new Integer( gid );
270251
return this;
@@ -306,7 +287,7 @@ public PlexusIoResourceAttributes setOwnerWritable( boolean flag )
306287
return this;
307288
}
308289

309-
public PlexusIoResourceAttributes setUserId( int uid )
290+
public PlexusIoResourceAttributes setUserId( Integer uid )
310291
{
311292
this.userId = new Integer( uid );
312293
return this;

src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public static PlexusIoResourceAttributes mergeAttributes( PlexusIoResourceAttrib
5555
}
5656
else
5757
{
58-
result = new SimpleResourceAttributes( base.hasUserId() ? new Integer( base.getUserId() ) : null,
58+
result = new SimpleResourceAttributes( base.getUserId(),
5959
base.getUserName(),
60-
base.hasGroupId() ? new Integer( base.getGroupId() ) : null,
60+
base.getGroupId(),
6161
base.getGroupName(), base.getOctalMode() );
6262
}
6363

src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributes.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,18 @@ public interface PlexusIoResourceAttributes
3535
boolean isWorldWritable();
3636

3737
boolean isWorldExecutable();
38-
39-
int getUserId();
40-
41-
int getGroupId();
4238

43-
boolean hasGroupId();
39+
/**
40+
* Gets the unix user id.
41+
* @return The unix user id, may be null ("not set"), even on unix
42+
*/
43+
Integer getUserId();
4444

45-
boolean hasUserId();
45+
/**
46+
* Gets the unix group id.
47+
* @return The unix group id, may be null ("not set"), even on unix
48+
*/
49+
Integer getGroupId();
4650

4751
String getUserName();
4852

@@ -70,9 +74,9 @@ public interface PlexusIoResourceAttributes
7074

7175
PlexusIoResourceAttributes setWorldExecutable( boolean flag );
7276

73-
PlexusIoResourceAttributes setUserId( int uid );
77+
PlexusIoResourceAttributes setUserId( Integer uid );
7478

75-
PlexusIoResourceAttributes setGroupId( int gid );
79+
PlexusIoResourceAttributes setGroupId( Integer gid );
7680

7781
PlexusIoResourceAttributes setUserName( String name );
7882

src/main/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttributes.java

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,9 @@ public int getOctalMode()
4848
return mode;
4949
}
5050

51-
public boolean hasGroupId()
51+
public Integer getGroupId()
5252
{
53-
return gid != null;
54-
}
55-
56-
public int getGroupId()
57-
{
58-
if ( !hasGroupId() )
59-
{
60-
throw new IllegalStateException( "Cannot get the groupid because it has not been set" );
61-
}
62-
return gid.intValue();
53+
return gid;
6354
}
6455

6556
public String getGroupName()
@@ -68,20 +59,10 @@ public String getGroupName()
6859
}
6960

7061

71-
public boolean hasUserId()
62+
public Integer getUserId()
7263
{
73-
return uid != null;
64+
return uid;
7465
}
75-
public int getUserId()
76-
{
77-
if ( !hasUserId() )
78-
{
79-
throw new IllegalStateException( "Cannot get the userid because it has not been set" );
80-
}
81-
return uid.intValue();
82-
}
83-
84-
8566

8667
public String getUserName()
8768
{
@@ -150,9 +131,9 @@ public PlexusIoResourceAttributes setGroupExecutable( boolean flag )
150131
return this;
151132
}
152133

153-
public PlexusIoResourceAttributes setGroupId( int gid )
134+
public PlexusIoResourceAttributes setGroupId( Integer gid )
154135
{
155-
this.gid = new Integer( gid);
136+
this.gid = gid;
156137
return this;
157138
}
158139

@@ -192,9 +173,9 @@ public PlexusIoResourceAttributes setOwnerWritable( boolean flag )
192173
return this;
193174
}
194175

195-
public PlexusIoResourceAttributes setUserId( int uid )
176+
public PlexusIoResourceAttributes setUserId( Integer uid )
196177
{
197-
this.uid = new Integer( uid);
178+
this.uid = uid;
198179
return this;
199180
}
200181

src/test/java/org/codehaus/plexus/components/io/attributes/AbstractResourceAttributesTCK.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,26 @@ public void testSetAndGetUserId()
3232
{
3333
PlexusIoResourceAttributes attrs = newAttributes();
3434

35-
assertFalse( attrs.hasUserId());
35+
assertNull( attrs.getUserId());
3636

3737
int uid = 501;
3838
attrs.setUserId( uid );
3939

40-
assertTrue( attrs.hasUserId());
41-
assertEquals( uid, attrs.getUserId() );
40+
assertNotNull( attrs.getUserId());
41+
assertEquals( uid, attrs.getUserId().intValue() );
4242
}
4343

4444
public final void testSetAndGetGroupId()
4545
{
4646
PlexusIoResourceAttributes attrs = newAttributes();
4747

48-
assertFalse( attrs.hasGroupId());
48+
assertNull( attrs.getGroupId());
4949

5050
int gid = 501;
5151
attrs.setGroupId( gid );
52-
53-
assertTrue( attrs.hasGroupId());
54-
assertEquals( gid, attrs.getGroupId() );
52+
53+
assertNotNull( attrs.getGroupId());
54+
assertEquals( gid, attrs.getGroupId().intValue() );
5555
}
5656

5757
public final void testSetAndGetUserName()

src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ public void testParserUbuntu10_04_en()
9494

9595
// -rw-r--r-- 1 1020 1030 11108 Mar 16 22:42 build.xml
9696
assertEquals( "-rw-rw-r--", new String( o.getLsModeParts() ) );
97-
assertEquals( 1020, o.getUserId() );
98-
assertEquals( 1030, o.getGroupId() );
97+
assertEquals( 1020, o.getUserId().intValue() );
98+
assertEquals( 1030, o.getGroupId().intValue() );
9999
// Should probably test pass 2 too...
100100
}
101101

@@ -128,8 +128,8 @@ public void testParserCygwin()
128128

129129
// -rw-r--r-- 1 1020 1030 11108 Mar 16 22:42 build.xml
130130
assertEquals( "-rw-r--r--", new String( o.getLsModeParts() ) );
131-
assertEquals( 203222, o.getUserId() );
132-
assertEquals( 10513, o.getGroupId() );
131+
assertEquals( 203222, o.getUserId().intValue() );
132+
assertEquals( 10513, o.getGroupId().intValue() );
133133
}
134134

135135
public void testParserSolaris()

0 commit comments

Comments
 (0)