]> source.dussan.org Git - jgit.git/commitdiff
Add SystemReader.Delegate to reduce boiler-plate code needed to subclass 71/1177071/2
authorMatthias Sohn <matthias.sohn@sap.com>
Tue, 20 Feb 2024 00:12:55 +0000 (01:12 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Tue, 20 Feb 2024 00:17:55 +0000 (01:17 +0100)
Original implementation by Han-Wen Nienhuys in Gerrit [1].

[1] https://gerrit-review.googlesource.com/c/gerrit/+/235169

Bug: jgit-24
Change-Id: I745f8c1c07de013a68168b91c2d9962d530d07bf

org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java

index 4a4876271070624bbe89a60e0546a2ca34ce1854..ed62c7137180d8d4d04ccd682d09ebbd2f08c48d 100644 (file)
@@ -174,6 +174,67 @@ public abstract class SystemReader {
                }
        }
 
+       /**
+        * Delegating SystemReader. Reduces boiler-plate code applications need to
+        * implement when overriding only a few of the SystemReader's methods.
+        *
+        * @since 6.9
+        */
+       public static class Delegate extends SystemReader {
+
+               private final SystemReader delegate;
+
+               /**
+                * Create a delegating system reader
+                *
+                * @param delegate
+                *            the system reader to delegate to
+                */
+               public Delegate(SystemReader delegate) {
+                       this.delegate = delegate;
+               }
+
+               @Override
+               public String getHostname() {
+                       return delegate.getHostname();
+               }
+
+               @Override
+               public String getenv(String variable) {
+                       return delegate.getenv(variable);
+               }
+
+               @Override
+               public String getProperty(String key) {
+                       return delegate.getProperty(key);
+               }
+
+               @Override
+               public FileBasedConfig openUserConfig(Config parent, FS fs) {
+                       return delegate.openUserConfig(parent, fs);
+               }
+
+               @Override
+               public FileBasedConfig openSystemConfig(Config parent, FS fs) {
+                       return delegate.openSystemConfig(parent, fs);
+               }
+
+               @Override
+               public FileBasedConfig openJGitConfig(Config parent, FS fs) {
+                       return delegate.openJGitConfig(parent, fs);
+               }
+
+               @Override
+               public long getCurrentTime() {
+                       return delegate.getCurrentTime();
+               }
+
+               @Override
+               public int getTimezone(long when) {
+                       return delegate.getTimezone(when);
+               }
+       }
+
        private static volatile SystemReader INSTANCE = DEFAULT;
 
        /**