@Test void shouldRemoveItems() { // GIVEN Integer[] numbers = ArrayUtil.concat( 0, 1, 2, 3, 4, 5 ); // WHEN Integer[] trimmed = ArrayUtil.without( numbers, 2 ); trimmed = ArrayUtil.without( trimmed, 5 ); trimmed = ArrayUtil.without( trimmed, 0 ); // THEN assertEquals( 3, trimmed.length ); assertFalse( ArrayUtil.contains( trimmed, 0 ) ); assertTrue( ArrayUtil.contains( trimmed, 1 ) ); assertFalse( ArrayUtil.contains( trimmed, 2 ) ); assertTrue( ArrayUtil.contains( trimmed, 3 ) ); assertTrue( ArrayUtil.contains( trimmed, 4 ) ); assertFalse( ArrayUtil.contains( trimmed, 5 ) ); }
@Deprecated public static boolean equals( Object firstArray, Object otherArray ) { return equals( firstArray, otherArray, DEFAULT_ARRAY_EQUALITY ); }
@SafeVarargs static NodeRecordCheck forSparseNodes( RecordField<NodeRecord,ConsistencyReport.NodeConsistencyReport>... additional ) { RecordField<NodeRecord,ConsistencyReport.NodeConsistencyReport>[] basic = ArrayUtil.<RecordField<NodeRecord,ConsistencyReport.NodeConsistencyReport>>array( LabelsField.LABELS ); return new NodeRecordCheck( union( basic, additional ) ); }
public boolean isType( CapabilityType type ) { return contains( types, type ); }
@Test void shouldMakeFromCanonical() throws IOException, CommandFailed, IncorrectUsage, IncorrectFormat { Path dataDir = testDirectory.directory( "some-other-path" ).toPath(); Path databaseDir = dataDir.resolve( "databases/foo.db" ); Files.createDirectories( databaseDir ); Files.write( configDir.resolve( Config.DEFAULT_CONFIG_FILE_NAME ), singletonList( formatProperty( data_directory, dataDir ) ) ); new LoadCommand( homeDir, configDir, loader ) .execute( ArrayUtil.concat( new String[]{"--database=foo.db", "--from=foo.dump"} ) ); verify( loader ).load( eq( Paths.get( new File( "foo.dump" ).getCanonicalPath() ) ), any(), any() ); }
@Override public void invoke( Object proxy, Method method, Object[] args, String... tags ) throws Throwable { if ( ArrayUtil.containsAll( this.tags, tags ) ) { super.invoke( proxy, method, args, tags ); } } }
/** * Check if array contains item. * * @param array Array to examine * @param arrayLength Number of items to check, from the start of the array * @param contains Single item to look for * @param <T> The type of the array items * @return {@code true} if {@code contains} exists in {@code array}, otherwise {@code false}. */ @Deprecated public static <T> boolean contains( T[] array, int arrayLength, T contains ) { for ( int i = 0; i < arrayLength; i++ ) { T item = array[i]; if ( nullSafeEquals( item, contains ) ) { return true; } } return false; }
@Override public int hashCode() { return ArrayUtil.hashCode( array ); }
@Deprecated public static <T> T[] without( T[] source, T... toRemove ) { T[] result = source.clone(); int length = result.length; for ( T candidate : toRemove ) { int index = indexOf( result, candidate ); if ( index != -1 ) { if ( index + 1 < length ) { // not the last one result[index] = result[length - 1]; } length--; } } return length == result.length ? result : Arrays.copyOf( result, length ); }
private boolean isFlag( String arg ) { return ArrayUtil.contains( flags, arg ); }
@SafeVarargs public static RelationshipRecordCheck relationshipRecordCheckBackwardPass( RecordField<RelationshipRecord,ConsistencyReport.RelationshipConsistencyReport>... additional ) { return new RelationshipRecordCheck( union( ArrayUtil.<RecordField<RelationshipRecord,ConsistencyReport.RelationshipConsistencyReport>>array( NodeField.SOURCE, NodeField.TARGET ), additional ) ); }
if ( !ArrayUtil.isEmpty( directory.listAll() ) )
@Test void shouldConcatArrays() { // GIVEN Integer[] initial = new Integer[] {0, 1, 2}; // WHEN Integer[] all = ArrayUtil.concat( initial, 3, 4, 5 ); // THEN assertArrayEquals( new Integer[] {0, 1, 2, 3, 4, 5}, all ); }
private void assertOrderCapability( UnionIndexCapability union, IndexOrder... expected ) { IndexOrder[] actual = union.orderCapability( someValueCategory() ); assertTrue( "Actual contains all expected", ArrayUtil.containsAll( expected, actual ) ); assertTrue( "Actual contains nothing else than expected", ArrayUtil.containsAll( actual, expected ) ); }
@Test void shouldCheckNullSafeEqual() { // WHEN/THEN assertTrue( ArrayUtil.nullSafeEquals( null, null ) ); assertFalse( ArrayUtil.nullSafeEquals( "1", null ) ); assertFalse( ArrayUtil.nullSafeEquals( null, "1" ) ); assertTrue( ArrayUtil.nullSafeEquals( "1", "1" ) ); }