1 /* 2 * Copyright (C) 2017, Thomas Wolf <thomas.wolf@paranor.ch> and others 3 * 4 * This program and the accompanying materials are made available under the 5 * terms of the Eclipse Distribution License v. 1.0 which is available at 6 * https://www.eclipse.org/org/documents/edl-v10.php. 7 * 8 * SPDX-License-Identifier: BSD-3-Clause 9 */ 10 11 package org.eclipse.jgit.lib; 12 13 import java.util.List; 14 import java.util.concurrent.TimeUnit; 15 16 import org.eclipse.jgit.annotations.NonNull; 17 import org.eclipse.jgit.transport.RefSpec; 18 19 /** 20 * Something that knows how to convert plain strings from a git 21 * {@link org.eclipse.jgit.lib.Config} to typed values. 22 * 23 * @since 4.9 24 */ 25 public interface TypedConfigGetter { 26 27 /** 28 * Get a boolean value from a git {@link org.eclipse.jgit.lib.Config}. 29 * 30 * @param config 31 * to get the value from 32 * @param section 33 * section the key is grouped within. 34 * @param subsection 35 * subsection name, such a remote or branch name. 36 * @param name 37 * name of the key to get. 38 * @param defaultValue 39 * default value to return if no value was present. 40 * @return true if any value or defaultValue is true, false for missing or 41 * explicit false 42 */ 43 boolean getBoolean(Config config, String section, String subsection, 44 String name, boolean defaultValue); 45 46 /** 47 * Parse an enumeration from a git {@link org.eclipse.jgit.lib.Config}. 48 * 49 * @param config 50 * to get the value from 51 * @param all 52 * all possible values in the enumeration which should be 53 * recognized. Typically {@code EnumType.values()}. 54 * @param section 55 * section the key is grouped within. 56 * @param subsection 57 * subsection name, such a remote or branch name. 58 * @param name 59 * name of the key to get. 60 * @param defaultValue 61 * default value to return if no value was present. 62 * @return the selected enumeration value, or {@code defaultValue}. 63 */ 64 <T extends Enum<?>> T getEnum(Config config, T[] all, String section, 65 String subsection, String name, T defaultValue); 66 67 /** 68 * Obtain an integer value from a git {@link org.eclipse.jgit.lib.Config}. 69 * 70 * @param config 71 * to get the value from 72 * @param section 73 * section the key is grouped within. 74 * @param subsection 75 * subsection name, such a remote or branch name. 76 * @param name 77 * name of the key to get. 78 * @param defaultValue 79 * default value to return if no value was present. 80 * @return an integer value from the configuration, or defaultValue. 81 */ 82 int getInt(Config config, String section, String subsection, String name, 83 int defaultValue); 84 85 /** 86 * Obtain a long value from a git {@link org.eclipse.jgit.lib.Config}. 87 * 88 * @param config 89 * to get the value from 90 * @param section 91 * section the key is grouped within. 92 * @param subsection 93 * subsection name, such a remote or branch name. 94 * @param name 95 * name of the key to get. 96 * @param defaultValue 97 * default value to return if no value was present. 98 * @return a long value from the configuration, or defaultValue. 99 */ 100 long getLong(Config config, String section, String subsection, String name, 101 long defaultValue); 102 103 /** 104 * Parse a numerical time unit, such as "1 minute", from a git 105 * {@link org.eclipse.jgit.lib.Config}. 106 * 107 * @param config 108 * to get the value from 109 * @param section 110 * section the key is in. 111 * @param subsection 112 * subsection the key is in, or null if not in a subsection. 113 * @param name 114 * the key name. 115 * @param defaultValue 116 * default value to return if no value was present. 117 * @param wantUnit 118 * the units of {@code defaultValue} and the return value, as 119 * well as the units to assume if the value does not contain an 120 * indication of the units. 121 * @return the value, or {@code defaultValue} if not set, expressed in 122 * {@code units}. 123 */ 124 long getTimeUnit(Config config, String section, String subsection, 125 String name, long defaultValue, TimeUnit wantUnit); 126 127 128 /** 129 * Parse a list of {@link org.eclipse.jgit.transport.RefSpec}s from a git 130 * {@link org.eclipse.jgit.lib.Config}. 131 * 132 * @param config 133 * to get the list from 134 * @param section 135 * section the key is in. 136 * @param subsection 137 * subsection the key is in, or null if not in a subsection. 138 * @param name 139 * the key name. 140 * @return a possibly empty list of 141 * {@link org.eclipse.jgit.transport.RefSpec}s 142 */ 143 @NonNull 144 List<RefSpec> getRefSpecs(Config config, String section, String subsection, 145 String name); 146 }