You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TypedConfigGetter.java 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Copyright (C) 2017, Thomas Wolf <thomas.wolf@paranor.ch>
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.lib;
  44. import java.util.List;
  45. import java.util.concurrent.TimeUnit;
  46. import org.eclipse.jgit.annotations.NonNull;
  47. import org.eclipse.jgit.transport.RefSpec;
  48. /**
  49. * Something that knows how to convert plain strings from a git
  50. * {@link org.eclipse.jgit.lib.Config} to typed values.
  51. *
  52. * @since 4.9
  53. */
  54. public interface TypedConfigGetter {
  55. /**
  56. * Get a boolean value from a git {@link org.eclipse.jgit.lib.Config}.
  57. *
  58. * @param config
  59. * to get the value from
  60. * @param section
  61. * section the key is grouped within.
  62. * @param subsection
  63. * subsection name, such a remote or branch name.
  64. * @param name
  65. * name of the key to get.
  66. * @param defaultValue
  67. * default value to return if no value was present.
  68. * @return true if any value or defaultValue is true, false for missing or
  69. * explicit false
  70. */
  71. boolean getBoolean(Config config, String section, String subsection,
  72. String name, boolean defaultValue);
  73. /**
  74. * Parse an enumeration from a git {@link org.eclipse.jgit.lib.Config}.
  75. *
  76. * @param config
  77. * to get the value from
  78. * @param all
  79. * all possible values in the enumeration which should be
  80. * recognized. Typically {@code EnumType.values()}.
  81. * @param section
  82. * section the key is grouped within.
  83. * @param subsection
  84. * subsection name, such a remote or branch name.
  85. * @param name
  86. * name of the key to get.
  87. * @param defaultValue
  88. * default value to return if no value was present.
  89. * @return the selected enumeration value, or {@code defaultValue}.
  90. */
  91. <T extends Enum<?>> T getEnum(Config config, T[] all, String section,
  92. String subsection, String name, T defaultValue);
  93. /**
  94. * Obtain an integer value from a git {@link org.eclipse.jgit.lib.Config}.
  95. *
  96. * @param config
  97. * to get the value from
  98. * @param section
  99. * section the key is grouped within.
  100. * @param subsection
  101. * subsection name, such a remote or branch name.
  102. * @param name
  103. * name of the key to get.
  104. * @param defaultValue
  105. * default value to return if no value was present.
  106. * @return an integer value from the configuration, or defaultValue.
  107. */
  108. int getInt(Config config, String section, String subsection, String name,
  109. int defaultValue);
  110. /**
  111. * Obtain a long value from a git {@link org.eclipse.jgit.lib.Config}.
  112. *
  113. * @param config
  114. * to get the value from
  115. * @param section
  116. * section the key is grouped within.
  117. * @param subsection
  118. * subsection name, such a remote or branch name.
  119. * @param name
  120. * name of the key to get.
  121. * @param defaultValue
  122. * default value to return if no value was present.
  123. * @return a long value from the configuration, or defaultValue.
  124. */
  125. long getLong(Config config, String section, String subsection, String name,
  126. long defaultValue);
  127. /**
  128. * Parse a numerical time unit, such as "1 minute", from a git
  129. * {@link org.eclipse.jgit.lib.Config}.
  130. *
  131. * @param config
  132. * to get the value from
  133. * @param section
  134. * section the key is in.
  135. * @param subsection
  136. * subsection the key is in, or null if not in a subsection.
  137. * @param name
  138. * the key name.
  139. * @param defaultValue
  140. * default value to return if no value was present.
  141. * @param wantUnit
  142. * the units of {@code defaultValue} and the return value, as
  143. * well as the units to assume if the value does not contain an
  144. * indication of the units.
  145. * @return the value, or {@code defaultValue} if not set, expressed in
  146. * {@code units}.
  147. */
  148. long getTimeUnit(Config config, String section, String subsection,
  149. String name, long defaultValue, TimeUnit wantUnit);
  150. /**
  151. * Parse a list of {@link org.eclipse.jgit.transport.RefSpec}s from a git
  152. * {@link org.eclipse.jgit.lib.Config}.
  153. *
  154. * @param config
  155. * to get the list from
  156. * @param section
  157. * section the key is in.
  158. * @param subsection
  159. * subsection the key is in, or null if not in a subsection.
  160. * @param name
  161. * the key name.
  162. * @return a possibly empty list of
  163. * {@link org.eclipse.jgit.transport.RefSpec}s
  164. */
  165. @NonNull
  166. List<RefSpec> getRefSpecs(Config config, String section, String subsection,
  167. String name);
  168. }