/** * 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"; }
/** * 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); }
@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); } } }); }
/** * 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); }
/** * 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 OR empty(field)</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 gteOrEmpty(Mapping field, @Nullable Object value) { Object effectiveValue = transform(value); if (effectiveValue == null) { return null; } return or(gtValue(field, effectiveValue, true), notFilled(field)); }
/** * Represents <tt>field <= OR empty(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 lteOrEmpty(Mapping field, @Nullable Object value) { Object effectiveValue = transform(value); if (effectiveValue == null) { return null; } return or(ltValue(field, effectiveValue, true), notFilled(field)); }
/** * Represents <tt>field > value OR empty(field)</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 gtOrEmpty(Mapping field, @Nullable Object value) { Object effectiveValue = transform(value); if (effectiveValue == null) { return null; } return or(gtValue(field, effectiveValue, false), notFilled(field)); }
/** * Represents <tt>field < OR empty(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 ltOrEmpty(Mapping field, @Nullable Object value) { Object effectiveValue = transform(value); if (effectiveValue == null) { return null; } return or(ltValue(field, effectiveValue, false), notFilled(field)); }
@Override @SuppressWarnings("squid:S1215") @Explain("The whole purpose of this call is to invoke the garbage collector.") public void execute(Output output, String... params) throws Exception { output.apply(LINE_FORMAT, "TYPE", "SIZE"); output.separator(); output.apply(LINE_FORMAT, "Free", NLS.formatSize(Runtime.getRuntime().freeMemory())); output.apply(LINE_FORMAT, "Total", NLS.formatSize(Runtime.getRuntime().totalMemory())); output.apply(LINE_FORMAT, "Max", NLS.formatSize(Runtime.getRuntime().maxMemory())); Runtime.getRuntime().gc(); output.separator(); output.apply(LINE_FORMAT, "Free", NLS.formatSize(Runtime.getRuntime().freeMemory())); output.apply(LINE_FORMAT, "Total", NLS.formatSize(Runtime.getRuntime().totalMemory())); output.apply(LINE_FORMAT, "Max", NLS.formatSize(Runtime.getRuntime().maxMemory())); output.separator(); }
/** * Returns a translated text for the given property in the given language. * <p> * The same fallback rules as for {@link #get(String)} apply. * * @param property the key for which a translation is requested * @param lang a two-letter language code for which the translation is requested * @return a translated string in the requested language or a fallback value if no translation was found */ @SuppressWarnings("squid:S2637") @Explain("Strings.isEmpty checks for null on lang") public static String get(@Nonnull String property, @Nullable String lang) { return blubb.get(property, null, true) .translate(Strings.isEmpty(lang) ? getCurrentLang() : lang, getFallbackLanguage()); }
@SuppressWarnings("squid:S1067") @Explain("We rather have all checks in one place.") protected boolean hasEscapedDefaultValue(TableColumn col) { return Types.CHAR == col.getType() || Types.VARCHAR == col.getType() || Types.CLOB == col.getType() || Types.DATE == col.getType() || Types.TIMESTAMP == col.getType() || Types.LONGVARCHAR == col.getType() || Types.TIME == col.getType(); }
@SuppressWarnings("squid:S1067") @Explain("We rather have all mappings in one place, even if the complexity is too high") protected boolean isNeedsQuotation(TableColumn col) { return col.getType() != Types.BIGINT && col.getType() != Types.DECIMAL && col.getType() != Types.CLOB && col.getType() != Types.INTEGER && col.getType() != Types.TINYINT && col.getType() != Types.BOOLEAN && col.getType() != Types.DOUBLE && col.getType() != Types.FLOAT && col.getType() != Types.SMALLINT && col.getType() != Types.BLOB && col.getType() != Types.NUMERIC; }