-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
8 changed files
with
308 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2017 dmfs GmbH | ||
* | ||
* 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 org.dmfs.tasks.utils; | ||
|
||
import org.dmfs.jems.single.Single; | ||
|
||
import java.util.Iterator; | ||
|
||
|
||
/** | ||
* A Fragile is similar to a {@link Single} but it may throw an {@link Exception} during retrieval of the value. | ||
* <p> | ||
* It's primary use case is to allow deferring checked Exceptions if they can't be thrown right away. A common example is Iterating elements, {@link | ||
* Iterator#next()} doesn't allow checked Exceptions to be thrown. In this case a {@link Fragile} can be returned to defer any exception to evaluation time. | ||
* | ||
* @author Marten Gajda | ||
* @deprecated use it from jems when available | ||
*/ | ||
@Deprecated | ||
public interface Fragile<T, E extends Throwable> | ||
{ | ||
T value() throws E; | ||
} |
57 changes: 57 additions & 0 deletions
57
opentasks/src/main/java/org/dmfs/tasks/utils/ValidatingUri.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2017 dmfs GmbH | ||
* | ||
* 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 org.dmfs.tasks.utils; | ||
|
||
import android.net.Uri; | ||
import android.support.annotation.Nullable; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
|
||
/** | ||
* A {@link Fragile} to create a valid {@link Uri} from a {@link Nullable} {@link CharSequence}. | ||
* <p> | ||
* Throws {@link URISyntaxException} for invalid or <code>null</code> or empty input. | ||
* | ||
* @author Gabor Keszthelyi | ||
*/ | ||
public final class ValidatingUri implements Fragile<Uri, URISyntaxException> | ||
{ | ||
private final CharSequence mUriCandidate; | ||
|
||
|
||
public ValidatingUri(@Nullable CharSequence uriCandidate) | ||
{ | ||
mUriCandidate = uriCandidate; | ||
} | ||
|
||
|
||
@Override | ||
public Uri value() throws URISyntaxException | ||
{ | ||
if (mUriCandidate == null) | ||
{ | ||
throw new URISyntaxException("null", "Uri input cannot be null"); | ||
} | ||
if (mUriCandidate.length() == 0) | ||
{ | ||
throw new URISyntaxException("", "Uri input cannot be empty"); | ||
} | ||
return Uri.parse(new URI(mUriCandidate.toString()).toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.