Skip to content

Commit

Permalink
restore alternatives and mark safevarargs
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Santos Izaguirre <[email protected]>
  • Loading branch information
antoniosanct committed Mar 12, 2023
1 parent 3060801 commit 0d8fe1d
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
39 changes: 39 additions & 0 deletions rome-utils/src/main/java/com/rometools/utils/Alternatives.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.rometools.utils;

import java.util.Objects;
import java.util.stream.Stream;

public final class Alternatives {

private Alternatives() {
}

/**
* Returns the first object that is not null
*
* @param objects The objects to process
* @return The first value that is not null. null when there is no not-null value
*/
@SafeVarargs
public static <T> T firstNotNull(final T... objects) {
return Stream.of(objects)
.filter(Objects::nonNull)
.findFirst()
.orElse(null);
}

}
37 changes: 37 additions & 0 deletions rome-utils/src/test/java/com/rometools/utils/AlternativesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.rometools.utils;

import static org.hamcrest.core.Is.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;

import org.junit.Test;

public class AlternativesTest {

@Test
public void testFirstNotNull() {

final Integer nullInteger = null;
final Integer notNullInteger = 1;

assertThat(Alternatives.firstNotNull(notNullInteger, nullInteger), is(notNullInteger));
assertThat(Alternatives.firstNotNull(nullInteger, notNullInteger), is(notNullInteger));
assertThat(Alternatives.firstNotNull(nullInteger, nullInteger), is(nullValue()));

}

}
3 changes: 2 additions & 1 deletion rome/src/main/java/com/rometools/rome/feed/atom/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.rometools.rome.feed.impl.CloneableBean;
import com.rometools.rome.feed.impl.EqualsBean;
import com.rometools.rome.feed.impl.ToStringBean;
import com.rometools.rome.feed.module.Extendable;
import com.rometools.rome.feed.module.Module;
import com.rometools.rome.feed.module.impl.ModuleUtils;
import com.rometools.rome.feed.synd.SyndPerson;
Expand All @@ -33,7 +34,7 @@
/**
* Bean for person elements of Atom feeds.
*/
public class Person implements SyndPerson, Serializable {
public class Person implements SyndPerson, Cloneable, Serializable, Extendable {

private static final long serialVersionUID = 1L;

Expand Down

0 comments on commit 0d8fe1d

Please sign in to comment.