Skip to content

Commit 3c7cc25

Browse files
committed
Refactor the code to use diamond operators (<>) and try with resources
1 parent 80a6c3d commit 3c7cc25

File tree

6 files changed

+11
-17
lines changed

6 files changed

+11
-17
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static void chmod( @Nonnull File file, int mode )
6565
@Nonnull
6666
public static Set<PosixFilePermission> getPermissions( int mode )
6767
{
68-
Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
68+
Set<PosixFilePermission> perms = new HashSet<>();
6969
//add owners permission
7070
if ( ( mode & 0400 ) > 0 )
7171
{

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ public static Map<String, PlexusIoResourceAttributes> getFileAttributesByPath( F
183183
public static @Nonnull Map<String, PlexusIoResourceAttributes> getFileAttributesByPath(@Nonnull File dir, boolean recursive )
184184
throws IOException
185185
{
186-
Map<Integer, String> userCache = new HashMap<Integer, String>();
187-
Map<Integer, String> groupCache = new HashMap<Integer, String>();
186+
Map<Integer, String> userCache = new HashMap<>();
187+
Map<Integer, String> groupCache = new HashMap<>();
188188
final List<String> fileAndDirectoryNames;
189189
if ( recursive && dir.isDirectory() )
190190
{
@@ -195,8 +195,7 @@ public static Map<String, PlexusIoResourceAttributes> getFileAttributesByPath( F
195195
fileAndDirectoryNames = Collections.singletonList( dir.getAbsolutePath() );
196196
}
197197

198-
final Map<String, PlexusIoResourceAttributes> attributesByPath =
199-
new LinkedHashMap<String, PlexusIoResourceAttributes>();
198+
final Map<String, PlexusIoResourceAttributes> attributesByPath = new LinkedHashMap<>();
200199

201200
for ( String fileAndDirectoryName : fileAndDirectoryNames )
202201
{

src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ private void addResources( List<PlexusIoResource> result, String[] resources )
145145
{
146146

147147
final File dir = getBaseDir();
148-
final HashMap<Integer, String> cache1 = new HashMap<Integer, String>();
149-
final HashMap<Integer, String> cache2 = new HashMap<Integer, String>();
148+
final HashMap<Integer, String> cache1 = new HashMap<>();
149+
final HashMap<Integer, String> cache2 = new HashMap<>();
150150
for ( String name : resources )
151151
{
152152
String sourceDir = name.replace( '\\', '/' );
@@ -241,7 +241,7 @@ public Iterator<PlexusIoResource> getResources()
241241
ds.setFollowSymlinks( isFollowingSymLinks() );
242242
ds.scan();
243243

244-
final List<PlexusIoResource> result = new ArrayList<PlexusIoResource>();
244+
final List<PlexusIoResource> result = new ArrayList<>();
245245
if ( isIncludingEmptyDirectories() )
246246
{
247247
String[] dirs = ds.getIncludedDirectories();

src/main/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class ProxyFactory
3030
public static PlexusIoResource createProxy(@Nonnull PlexusIoResource target, Object alternateSupplier)
3131
{
3232

33-
List<Class> interfaces = new ArrayList<Class>( );
33+
List<Class> interfaces = new ArrayList<>( );
3434
interfaces.add( PlexusIoResource.class);
3535
if (target instanceof SymlinkDestinationSupplier ) interfaces.add( SymlinkDestinationSupplier.class);
3636
if (target instanceof FileSupplier ) interfaces.add( FileSupplier.class);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public void testGetPosixFileAttributes()
3939
}
4040

4141
File file = new File( "." );
42-
Map<Integer, String> userCache = new HashMap<Integer, String>();
43-
Map<Integer, String> groupCache = new HashMap<Integer, String>();
42+
Map<Integer, String> userCache = new HashMap<>();
43+
Map<Integer, String> groupCache = new HashMap<>();
4444

4545
PlexusIoResourceAttributes fa = new FileAttributes( file, userCache, groupCache );
4646
assertNotNull( fa );

src/test/java/org/codehaus/plexus/components/io/filemappers/ResourcesTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ private void createZipFile( File dest, File dir ) throws IOException
114114
private void compare( InputStream in, File file )
115115
throws IOException
116116
{
117-
InputStream fIn = new FileInputStream( file );
118-
try
117+
try( InputStream fIn = new FileInputStream( file ) )
119118
{
120119
for ( ;; )
121120
{
@@ -128,10 +127,6 @@ private void compare( InputStream in, File file )
128127
}
129128
}
130129
}
131-
finally
132-
{
133-
fIn.close();
134-
}
135130
}
136131

137132
private void compare( PlexusIoResource res, File file )

0 commit comments

Comments
 (0)