/** * Returns the data type used in the mapping * * @return the name of the data type used in the mapping */ @SuppressWarnings("squid:S3400") @Explain("To be overwritten by subclasses.") protected String getMappingType() { return "keyword"; }
/** * Marks a class as sortable by its priority. * <p> * Classes implementing this interface can be used by the {@link PriorityParts} annotation and will * be auto sorted (ascending) by priority before they are made available. */ @SuppressWarnings("squid:S1214") @Explain("The constant is best defined here.") public interface Priorized { /** * Contains the default priority used by <tt>Priorized</tt> parts. */ int DEFAULT_PRIORITY = 100; /** * Returns the priority of this element. * * @return the priority - lower is better (comes first) */ int getPriority(); }
/** * Overrides the root node to reset this document to a subtree of the original input * * @param node the new root node of this input */ @SuppressWarnings("squid:S2589") @Explain("We really want to ensure that the given value is not null and not just rely on annotation.") public void setNewParent(@Nonnull StructuredNode node) { if (node != null) { this.node = node; } } }
@Override @SuppressWarnings({"unchecked", "rawtypes", "UseOfObsoleteCollectionType", "squid:S1149"}) @Explain("We use an old Java API here, which requires those collections") public synchronized Enumeration<Object> keys() { Enumeration<Object> keysEnum = super.keys(); Vector keyList = new Vector(); while (keysEnum.hasMoreElements()) { keyList.add(keysEnum.nextElement()); } Collections.sort(keyList); return keyList.elements(); } }
@Override @SuppressWarnings("squid:S1185") @Explain("We need to overwrite this to make it synchronized.") public synchronized void put(K key, V value) { super.put(key, value); }
@SuppressWarnings("squid:S2095") @Explain("The statement will be closed by the caller.") private PreparedStatement prepareStatement(Connection c) throws SQLException { PreparedStatement stmt = c.prepareStatement(getQuery(), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); for (int i = 0; i < parameters.size(); i++) { stmt.setObject(i + 1, parameters.get(i)); } return stmt; }
/** * Determines if the list of referenced entities contains the given entity. * * @param value the value to check for * @return <tt>true</tt> if the value is non null and contained in the list of referenced entities */ @SuppressWarnings("squid:S2250") @Explain("ids needs to be a List for Elasticsearch") public boolean contains(@Nullable E value) { if (value == null) { return false; } return ids.contains(value.getId()); }
/** * Determines if the list of referenced entities contains the given entity (referenced via the given id). * * @param id the id of the entity to check for * @return <tt>true</tt> if the id is non null and the id of an entity contained in the list of referenced entities */ @SuppressWarnings("squid:S2250") @Explain("ids needs to be a List for Elasticsearch") public boolean containsId(String id) { if (Strings.isEmpty(id)) { return false; } return ids.contains(id); }
/** * Translates the given string if it starts with a $ sign. * * @param keyOrString the string to translate if it starts with a $ sign * @param lang a two-letter language code for which the translation is requested * @return the translated string or the original string if it doesn't start with a $ sign or if no matching * translation was found */ @SuppressWarnings("squid:S2583") @Explain("Duplicate null check as predicate is not enforced by the compiler") public static String smartGet(@Nonnull String keyOrString, @Nullable String lang) { if (keyOrString == null) { return keyOrString; } if (keyOrString.length() > 2 && keyOrString.charAt(0) == '$' && keyOrString.charAt(1) != '{') { return NLS.getIfExists(keyOrString.substring(1), lang).orElseGet(() -> keyOrString.substring(1)); } return keyOrString; }
@SuppressWarnings({"squid:S1854", "squid:S1481"}) @Explain("False positive - the set is used.") void processAnnotations() { Set<Object> initializedObjects = new HashSet<>(); parts.getUnderlyingMap().values().stream().flatMap(Collection::stream).forEach(part -> { wire(part); if (part instanceof Initializable) { if (!initializedObjects.contains(part)) { initializedObjects.add(part); initialize(part); } } }); }
/** * Retrieves the <tt>Translation</tt> for the given property. * <p> * If no matching entry is found, the given <tt>fallback</tt> is used. If still no match was found, either * a new one is create (if <tt>create</tt> is <tt>true</tt>) or <tt>false</tt> otherwise. * * @param property the property key for which a translation is required * @param fallback a fallback key, if no translation is found. May be <tt>null</tt>. * @param create determines if a new <tt>Translation</tt> is created if non-existent * @return a <tt>Translation</tt> for the given property or fallback. * Returns <tt>null</tt> if no translation was found and <tt>create</tt> is false. */ @SuppressWarnings("squid:S2583") @Explain("Double check for @Nonnull property as it is not enforced by the compiler") protected Translation get(@Nonnull String property, @Nullable String fallback, boolean create) { if (property == null) { throw new IllegalArgumentException("property"); } Translation entry = translationMap.get(property); if (entry != null) { return entry; } return getWithFallback(property, fallback, create); }
/** * Represents <tt>field > value</tt> as constraint * * @param field the field to filter * @param value the value to filter with. If <tt>null</tt> is passed in, no constraint is generated * @return the generated constraint */ @Nullable @SuppressWarnings("squid:S2637") @Explain("False positive") public C gt(Mapping field, @Nullable Object value) { Object effectiveValue = transform(value); if (effectiveValue == null) { return null; } return gtValue(field, effectiveValue, false); }
/** * Represents <tt>field >= value</tt> as constraint * * @param field the field to filter * @param value the value to filter with. If <tt>null</tt> is passed in, no constraint is generated * @return the generated constraint */ @Nullable @SuppressWarnings("squid:S2637") @Explain("False positive") public C gte(Mapping field, @Nullable Object value) { Object effectiveValue = transform(value); if (effectiveValue == null) { return null; } return gtValue(field, effectiveValue, true); }
/** * Represents <tt>field <= value</tt> as constraint * * @param field the field to filter * @param value the value to filter with. If <tt>null</tt> is passed in, no constraint is generated * @return the generated constraint */ @Nullable @SuppressWarnings("squid:S2637") @Explain("False positive") public C lte(Mapping field, @Nullable Object value) { Object effectiveValue = transform(value); if (effectiveValue == null) { return null; } return ltValue(field, effectiveValue, true); }
@SuppressWarnings({"squid:S2274", "squid:S899"}) @Explain("We neither need a loop nor the result here.") private void idle() { try { schedulerLock.lock(); try { long waitTime = computeWaitTime(); if (waitTime < 0) { // No work available -> wait for something to do... workAvailable.await(); } else if (waitTime > 0) { // No task can be executed in the next millisecond. Sleep for // "waitTime" (or more work) until the next check for executable work... workAvailable.await(waitTime, TimeUnit.MILLISECONDS); } } finally { schedulerLock.unlock(); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); Exceptions.ignore(e); } }
/** * Executes a list of bulk statements. * * @param bulkData the statements to execute. * @return the response of the call * @see BulkContext */ @SuppressWarnings("squid:S1612") @Explain("Due to method overloading the compiler cannot deduce which method to pick") public JSONObject bulk(List<JSONObject> bulkData) { return performPost().rawData(bulkData.stream().map(obj -> obj.toJSONString()).collect(Collectors.joining("\n")) + "\n").execute("_bulk").response(); }
@Override @SuppressWarnings("squid:S1698") @Explain("Indentity against this is safe and a shortcut to speed up comparisons") public int compareTo(Metric o) { if (o == null) { return -1; } if (o == this) { return 0; } if (o.state != state) { return o.state.ordinal() - state.ordinal(); } return code.compareTo(o.code); }
/** * Represents <tt>field < value</tt> as constraint * * @param field the field to filter * @param value the value to filter with. If <tt>null</tt> is passed in, no constraint is generated * @return the generated constraint */ @Nullable @SuppressWarnings("squid:S2637") @Explain("False positive") public C lt(Mapping field, @Nullable Object value) { Object effectiveValue = transform(value); if (effectiveValue == null) { return null; } return ltValue(field, effectiveValue, false); }
/** * Generates a new logger with the given name * <p> * The given name should be short and simple. It is not recommended to create a logger per class but one for * each framework or subsystem. * * @param name the name of the logger. This should be a simple name, completely lowercase, without any dots * @return a new logger logging with the given name. */ @SuppressWarnings("squid:S2250") @Explain("Loggers are only created once, so there is no performance hotspot") public static synchronized Log get(String name) { Log result = new Log(Logger.getLogger(name)); all.add(result); if (!name.matches("[a-z0-9\\-]+")) { result.WARN("Invalid logger name: %s. Only numbers, lowercase letters and - are allowed!%n", name); } return result; }
/** * Compares this amount against the given amount and returns the one with the lower value. * <p> * If either of the amounts is empty, the filled one is returned. If both are empty, an empty amount is returned. * * @param other the amount to compare against * @return the amount with the lower value or an empty amount, if both amounts are empty */ @Nonnull @SuppressWarnings("squid:S1698") @Explain("Indentity against this is safe and a shortcut to speed up comparisons") public Amount min(@Nullable Amount other) { if (other == this || other == null) { return this; } if (isEmpty()) { return other; } if (other.isEmpty()) { return this; } return this.value.compareTo(other.value) < 0 ? this : other; }