Skip to content

Commit

Permalink
Add Java 11 Optional.isEmpty() (#9853)
Browse files Browse the repository at this point in the history
Partial #9547
Co-authored-by: Alexey Abashev <[email protected]>
  • Loading branch information
niloc132 authored Nov 7, 2023
1 parent abceee4 commit d73d095
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 0 deletions.
4 changes: 4 additions & 0 deletions user/super/com/google/gwt/emul/java/util/OptionalDouble.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public boolean isPresent() {
return present;
}

public boolean isEmpty() {
return !present;
}

public double getAsDouble() {
checkCriticalElement(present);
return ref;
Expand Down
4 changes: 4 additions & 0 deletions user/super/com/google/gwt/emul/java/util/OptionalInt.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public boolean isPresent() {
return present;
}

public boolean isEmpty() {
return !present;
}

public int getAsInt() {
checkCriticalElement(present);
return ref;
Expand Down
4 changes: 4 additions & 0 deletions user/super/com/google/gwt/emul/java/util/OptionalLong.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public boolean isPresent() {
return present;
}

public boolean isEmpty() {
return !present;
}

public long getAsLong() {
checkCriticalElement(present);
return ref;
Expand Down
34 changes: 34 additions & 0 deletions user/test/com/google/gwt/emultest/EmulJava11Suite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2023 Google Inc.
*
* 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.google.gwt.emultest;

import com.google.gwt.emultest.java11.util.OptionalDoubleTest;
import com.google.gwt.emultest.java11.util.OptionalIntTest;
import com.google.gwt.emultest.java11.util.OptionalLongTest;
import com.google.gwt.emultest.java11.util.OptionalTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

/** Test JRE emulations. */
@RunWith(Suite.class)
@Suite.SuiteClasses({
OptionalDoubleTest.class,
OptionalIntTest.class,
OptionalLongTest.class,
OptionalTest.class,
})
public class EmulJava11Suite {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2023 Google Inc.
*
* 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.google.gwt.emultest.java11.util;

import com.google.gwt.emultest.java.util.EmulTestBase;

import java.util.OptionalDouble;

/**
* Tests for java.util.OptionalDouble Java 11 API emulation.
*/
public class OptionalDoubleTest extends EmulTestBase {
public void testIsEmpty() {
assertTrue(OptionalDouble.empty().isEmpty());
assertFalse(OptionalDouble.of(78.9).isEmpty());
}
}
30 changes: 30 additions & 0 deletions user/test/com/google/gwt/emultest/java11/util/OptionalIntTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2023 Google Inc.
*
* 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.google.gwt.emultest.java11.util;

import com.google.gwt.emultest.java.util.EmulTestBase;

import java.util.OptionalInt;

/**
* Tests for java.util.OptionalInt Java 11 API emulation.
*/
public class OptionalIntTest extends EmulTestBase {
public void testIsEmpty() {
assertTrue(OptionalInt.empty().isEmpty());
assertFalse(OptionalInt.of(456).isEmpty());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2023 Google Inc.
*
* 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.google.gwt.emultest.java11.util;

import com.google.gwt.emultest.java.util.EmulTestBase;

import java.util.OptionalLong;

/**
* Tests for java.util.OptionalLong Java 11 API emulation.
*/
public class OptionalLongTest extends EmulTestBase {
public void testIsEmpty() {
assertTrue(OptionalLong.empty().isEmpty());
assertFalse(OptionalLong.of(123L).isEmpty());
}
}
30 changes: 30 additions & 0 deletions user/test/com/google/gwt/emultest/java11/util/OptionalTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2023 Google Inc.
*
* 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.google.gwt.emultest.java11.util;

import com.google.gwt.emultest.java.util.EmulTestBase;

import java.util.Optional;

/**
* Tests for java.util.Optional Java 11 API emulation.
*/
public class OptionalTest extends EmulTestBase {
public void testIsEmpty() {
assertTrue(Optional.empty().isEmpty());
assertFalse(Optional.of(this).isEmpty());
}
}

0 comments on commit d73d095

Please sign in to comment.