|
| 1 | +/*- |
| 2 | + * #%L |
| 3 | + * Appose: multi-language interprocess cooperation with shared memory. |
| 4 | + * %% |
| 5 | + * Copyright (C) 2023 - 2026 Appose developers. |
| 6 | + * %% |
| 7 | + * Redistribution and use in source and binary forms, with or without |
| 8 | + * modification, are permitted provided that the following conditions are met: |
| 9 | + * |
| 10 | + * 1. Redistributions of source code must retain the above copyright notice, |
| 11 | + * this list of conditions and the following disclaimer. |
| 12 | + * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 13 | + * this list of conditions and the following disclaimer in the documentation |
| 14 | + * and/or other materials provided with the distribution. |
| 15 | + * |
| 16 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE |
| 20 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 23 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 24 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 25 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 | + * POSSIBILITY OF SUCH DAMAGE. |
| 27 | + * #L% |
| 28 | + */ |
| 29 | + |
| 30 | +package org.apposed.appose; |
| 31 | + |
| 32 | +/** |
| 33 | + * Result of an environment up-to-date check. |
| 34 | + * |
| 35 | + * @see Builder#checkUpToDate() |
| 36 | + * @see Environment#checkUpToDate() |
| 37 | + */ |
| 38 | +public interface CheckResult { |
| 39 | + |
| 40 | + /** |
| 41 | + * Whether the environment is up-to-date. |
| 42 | + */ |
| 43 | + boolean isUpToDate(); |
| 44 | + |
| 45 | + /** |
| 46 | + * Human-readable description of the check result. |
| 47 | + * Explains why the environment is (or is not) up-to-date. |
| 48 | + */ |
| 49 | + String description(); |
| 50 | + |
| 51 | + /** |
| 52 | + * Whether a real tool verification was performed |
| 53 | + * (as opposed to a fast config-level comparison). |
| 54 | + * <p> |
| 55 | + * When {@code true}, the underlying package manager was actually invoked |
| 56 | + * to verify the environment is in sync. When {@code false}, only a fast |
| 57 | + * comparison of the builder configuration against the stored state was done. |
| 58 | + * </p> |
| 59 | + */ |
| 60 | + boolean verified(); |
| 61 | + |
| 62 | + // -- Factory methods -- |
| 63 | + |
| 64 | + /** |
| 65 | + * Creates a CheckResult indicating the environment is up-to-date. |
| 66 | + * |
| 67 | + * @param description Human-readable explanation of the check result. |
| 68 | + * @param verified Whether a real tool verification was performed. |
| 69 | + * @return A CheckResult with {@link #isUpToDate()} returning {@code true}. |
| 70 | + */ |
| 71 | + static CheckResult upToDate(final String description, final boolean verified) { |
| 72 | + return new CheckResult() { |
| 73 | + @Override public boolean isUpToDate() { return true; } |
| 74 | + @Override public String description() { return description; } |
| 75 | + @Override public boolean verified() { return verified; } |
| 76 | + }; |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Creates a CheckResult indicating the environment is stale. |
| 81 | + * |
| 82 | + * @param description Human-readable explanation of why the environment is stale. |
| 83 | + * @param verified Whether a real tool verification was performed. |
| 84 | + * @return A CheckResult with {@link #isUpToDate()} returning {@code false}. |
| 85 | + */ |
| 86 | + static CheckResult stale(final String description, final boolean verified) { |
| 87 | + return new CheckResult() { |
| 88 | + @Override public boolean isUpToDate() { return false; } |
| 89 | + @Override public String description() { return description; } |
| 90 | + @Override public boolean verified() { return verified; } |
| 91 | + }; |
| 92 | + } |
| 93 | +} |
0 commit comments