Skip to content

Commit

Permalink
[Java] Apply strict indentation checkstyle and fix some warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpt777 committed Jan 7, 2018
1 parent f36c518 commit b21e1fd
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,9 @@ public static synchronized void removeTransformer()
if (alignmentTransformer != null)
{
instrumentation.removeTransformer(alignmentTransformer);
instrumentation.removeTransformer(
new AgentBuilder.Default()
.type(isSubTypeOf(DirectBuffer.class).and(not(isInterface())))
.transform(AgentBuilder.Transformer.NoOp.INSTANCE).installOn(instrumentation));
instrumentation.removeTransformer(new AgentBuilder.Default()
.type(isSubTypeOf(DirectBuffer.class).and(not(isInterface())))
.transform(AgentBuilder.Transformer.NoOp.INSTANCE).installOn(instrumentation));
alignmentTransformer = null;
instrumentation = null;
}
Expand Down
4 changes: 2 additions & 2 deletions agrona/src/main/java/org/agrona/IoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public static MappedByteBuffer mapExistingFile(final File location, final String

MappedByteBuffer mappedByteBuffer = null;
try (RandomAccessFile file = new RandomAccessFile(location, "rw");
FileChannel channel = file.getChannel())
FileChannel channel = file.getChannel())
{
mappedByteBuffer = channel.map(READ_WRITE, 0, channel.size());
}
Expand Down Expand Up @@ -293,7 +293,7 @@ public static MappedByteBuffer mapExistingFile(

MappedByteBuffer mappedByteBuffer = null;
try (RandomAccessFile file = new RandomAccessFile(location, "rw");
FileChannel channel = file.getChannel())
FileChannel channel = file.getChannel())
{
mappedByteBuffer = channel.map(READ_WRITE, offset, length);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,9 @@ private void putLabel(final int recordOffset, final String label)
{
if (StandardCharsets.US_ASCII == labelCharset)
{
metaDataBuffer.putInt(
recordOffset + LABEL_OFFSET,
metaDataBuffer.putStringWithoutLengthAscii(
recordOffset + LABEL_OFFSET + SIZE_OF_INT, label, 0, MAX_LABEL_LENGTH));
final int length = metaDataBuffer.putStringWithoutLengthAscii(
recordOffset + LABEL_OFFSET + SIZE_OF_INT, label, 0, MAX_LABEL_LENGTH);
metaDataBuffer.putInt(recordOffset + LABEL_OFFSET, length);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,22 @@ public class PackageOutputManager implements OutputManager
*
* @param baseDirName for the generated source code.
* @param packageName for the generated source code relative to the baseDirName.
* @throws java.io.IOException if an error occurs during output.
*/
public PackageOutputManager(final String baseDirName, final String packageName) throws IOException
public PackageOutputManager(final String baseDirName, final String packageName)
{
Objects.requireNonNull(baseDirName, "baseDirName");
Objects.requireNonNull(packageName, "packageName");

final char lastChar = baseDirName.charAt(baseDirName.length() - 1);
final String dirName =
(lastChar == separatorChar ? baseDirName : baseDirName + separatorChar) +
packageName.replace('.', separatorChar);
final String dirName = lastChar == separatorChar ? baseDirName : baseDirName + separatorChar;
final String dirNamePlusPackage = dirName + packageName.replace('.', separatorChar);

outputDir = new File(dirName);
outputDir = new File(dirNamePlusPackage);
if (!outputDir.exists())
{
if (!outputDir.mkdirs())
{
throw new IllegalStateException("Unable to create directory: " + dirName);
throw new IllegalStateException("Unable to create directory: " + dirNamePlusPackage);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
import org.mockito.InOrder;

import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.IntUnaryOperator;
import java.util.stream.IntStream;

import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
import static org.mockito.Mockito.inOrder;
Expand Down Expand Up @@ -176,26 +174,24 @@ public void shouldOnlyRemoveTheSpecifiedEntry()
IntStream
.range(1, 8)
.filter((i) -> i != 5L)
.forEach(
(i) ->
{
assertTrue(map.containsKey(i));
assertTrue(map.containsValue(2 * i));
});
.forEach((i) ->
{
assertTrue(map.containsKey(i));
assertTrue(map.containsValue(2 * i));
});
}

@Test
public void shouldResizeWhenMoreElementsAreAdded()
{
IntStream
.range(1, 100)
.forEach(
(key) ->
{
final int value = key * 2;
assertEquals(INITIAL_VALUE, map.put(key, value));
assertEquals(value, map.get(key));
});
.forEach((key) ->
{
final int value = key * 2;
assertEquals(INITIAL_VALUE, map.put(key, value));
assertEquals(value, map.get(key));
});
}

@Test
Expand Down Expand Up @@ -254,12 +250,13 @@ public void shouldNotSupportLoadFactorOfOne()
new Int2IntHashMap(4, 1, 0);
}

@SuppressWarnings("ConstantConditions")
@Test
public void correctSizeAfterRehash() throws Exception
public void correctSizeAfterRehash()
{
final Int2IntHashMap map = new Int2IntHashMap(16, 0.6f, -1);

IntStream.range(1, 17).forEach(i -> map.put(i, i));
IntStream.range(1, 17).forEach((i) -> map.put(i, i));
assertEquals("Map has correct size", 16, map.size());

final List<Integer> keys = new ArrayList<>(map.keySet());
Expand All @@ -282,39 +279,6 @@ public void shouldComputeIfAbsent()
assertThat(map.get(testKey), is(testValue));
}

private void assertEntryIs(final Entry<Integer, Integer> entry, final int expectedKey, final int expectedValue)
{
assertEquals(expectedKey, entry.getKey().intValue());
assertEquals(expectedValue, entry.getValue().intValue());
}

private void assertCollectionContainsElements(final Collection<Integer> keys)
{
assertEquals(2, keys.size());
assertFalse(keys.isEmpty());
assertTrue(keys.contains(1));
assertTrue(keys.contains(2));
assertFalse(keys.contains(3));
assertThat(keys, hasItems(1, 2));

assertThat("iterator has failed to be reset", keys, hasItems(1, 2));
}

private void assertContains(final Iterator<Integer> it, final int first, final int second)
{
assertTrue(it.hasNext());
assertEquals(Integer.valueOf(first), it.next());
assertTrue(it.hasNext());
assertEquals(Integer.valueOf(second), it.next());
assertFalse(it.hasNext());
}

private void addTwoElements()
{
map.put(1, 1);
map.put(2, 3);
}

@Test
public void shouldContainValueForIncAndDecEntries()
{
Expand Down Expand Up @@ -444,12 +408,11 @@ public void shouldAllowInitialValueAsKey()
assertEquals(1, map.size());

final int[] tuple = new int[2];
map.forEach(
(k, v) ->
{
tuple[0] = k;
tuple[1] = v;
});
map.forEach((k, v) ->
{
tuple[0] = k;
tuple[1] = v;
});

assertEquals(INITIAL_VALUE, tuple[0]);
assertEquals(1, tuple[1]);
Expand Down
50 changes: 23 additions & 27 deletions agrona/src/test/java/org/agrona/collections/Int2IntHashMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,26 +301,24 @@ public void shouldOnlyRemoveTheSpecifiedEntry()
IntStream
.range(0, 8)
.filter((i) -> i != 5L)
.forEach(
(i) ->
{
assertTrue(map.containsKey(i));
assertTrue(map.containsValue(2 * i));
});
.forEach((i) ->
{
assertTrue(map.containsKey(i));
assertTrue(map.containsValue(2 * i));
});
}

@Test
public void shouldResizeWhenMoreElementsAreAdded()
{
IntStream
.range(0, 100)
.forEach(
(key) ->
{
final int value = key * 2;
assertEquals(MISSING_VALUE, map.put(key, value));
assertEquals(value, map.get(key));
});
.forEach((key) ->
{
final int value = key * 2;
assertEquals(MISSING_VALUE, map.put(key, value));
assertEquals(value, map.get(key));
});
}

@Test
Expand Down Expand Up @@ -380,7 +378,7 @@ public void correctSizeAfterRehash() throws Exception
{
final Int2IntHashMap map = new Int2IntHashMap(16, 0.6f, -1);

IntStream.range(1, 17).forEach(i -> map.put(i, i));
IntStream.range(1, 17).forEach((i) -> map.put(i, i));
assertEquals("Map has correct size", 16, map.size());

final List<Integer> keys = new ArrayList<>(map.keySet());
Expand Down Expand Up @@ -429,13 +427,12 @@ public void shouldAllowMissingValueAsKey()
assertEquals(1, map.size());

final int[] tuple = new int[2];
map.intForEach(
(k, v) ->
{
tuple[0] = k;
tuple[1] = v;
}
);
map.intForEach((k, v) ->
{
tuple[0] = k;
tuple[1] = v;
});

assertEquals(MISSING_VALUE, tuple[0]);
assertEquals(1, tuple[1]);

Expand Down Expand Up @@ -614,12 +611,11 @@ public void shouldIterateEntriesBySpecialisedType()
final Map<Integer, Integer> expected = new HashMap<>();
final Int2IntHashMap map = new Int2IntHashMap(Integer.MIN_VALUE);

IntStream.range(1, 10).forEachOrdered(
(i) ->
{
map.put(i, -i);
expected.put(i, -i);
});
IntStream.range(1, 10).forEachOrdered((i) ->
{
map.put(i, -i);
expected.put(i, -i);
});

final Map<Integer, Integer> actual = new HashMap<>();
final Int2IntHashMap.EntryIterator iter = (Int2IntHashMap.EntryIterator)map.entrySet().iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,9 @@ public void shouldRecordTwoDistinctObservationsOnCause()

for (int i = 0; i < 2; i++)
{
assertTrue(log.record(
i == 1 ?
new RuntimeException("One") :
new RuntimeException("One", new Exception("Cause"))));
assertTrue(log.record(i == 1 ?
new RuntimeException("One") :
new RuntimeException("One", new Exception("Cause"))));
}

final ArgumentCaptor<Integer> lengthArg = ArgumentCaptor.forClass(Integer.class);
Expand Down
4 changes: 3 additions & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

<module name="SuppressWarningsHolder"/>

<module name="Indentation"/>
<module name="Indentation">
<property name="forceStrictCondition" value="true"/>
</module>

<module name="ConstantName"/>

Expand Down

0 comments on commit b21e1fd

Please sign in to comment.