PMD规则

2023-11-03

Design Rules

·  UseSingleton: If you have a class that has nothing but static methods, consider making it a Singleton. Note that this doesn't apply to abstract classes, since their subclasses may well include non-static methods. Also, if you want this class to be a Singleton, remember to add a private constructor to prevent instantiation.

翻译  使用单例:如果有一个类包含的只有静态方法,可以考虑做成单例的。注意这个规则不适用于抽象类,因为它们的子类可能包含非静态方法。还有,如果你想把一个类做成单例的,记得写一个私有的构造器以阻止外部实例化。

·  SimplifyBooleanReturns: Avoid unnecessary if..then..else statements when returning a boolean.

翻译  简化布尔量的返回:避免在返回布尔量时写不必要的if..then..else表达式。

代码示例:

public class Foo {

  private int bar =2;

  public boolean isBarEqualsTo(int x) {

    // this bit of code

    if (bar == x) {

     return true;

    } else {

     return false;

    }

    // 上面可以简化为:

    // return bar == x;

  }

}

·  SimplifyBooleanExpressions: Avoid unnecessary comparisons in boolean expressions - this complicates simple code.

翻译  简化布尔表达式:避免布尔表达式之间无用的比较——只会使代码复杂化

代码示例:

public class Bar {

 // 下面可以简化为: bar = isFoo();

 private boolean bar = (isFoo() == true);

 

 public isFoo() { return false;}

}

·  SwitchStmtsShouldHaveDefault: Switch statements should have a default label.

翻译  Switch表达式应该有default

·  AvoidDeeplyNestedIfStmts: Deeply nested if..then statements are hard to read.

翻译  避免深度嵌套的if表达式:深度嵌套的if..then表达式难以阅读

·  AvoidReassigningParameters: Reassigning values to parameters is a questionable practice. Use a temporary local variable instead.

翻译  避免给参数重新赋值:给传入方法的参数重新赋值是一种需要商榷的行为。使用临时本地变量来代替。

·  SwitchDensity: A high ratio of statements to labels in a switch statement implies that the switch statement is doing too much work. Consider moving the statements into new methods, or creating subclasses based on the switch variable.

翻译  密集的switchswitch表达式的case块中出现很高比例的表达式语句表明switch表达式做了太多的工作。考虑将表达式语句写进一个新的方法,或者创建基于switch变量的子类。

代码示例:

public class Foo {

 public void bar(int x) {

   switch (x) {

     case 1: {

       // lots of statements

       break;

     } case 2: {

       // lots of statements

       break;

     }

   }

 }

}

·  ConstructorCallsOverridableMethod: Calling overridable methods during construction poses a risk of invoking methods on an incompletely constructed object and can be difficult to discern. It may leave the sub-class unable to construct its superclass or forced to replicate the construction process completely within itself, losing the ability to call super(). If the default constructor contains a call to an overridable method, the subclass may be completely uninstantiable. Note that this includes method calls throughout the control flow graph - i.e., if a constructor Foo() calls a private method bar() that calls a public method buz(), this denotes a problem.

翻译  构造器调用了可重写的方法:在构造器中调用可被覆盖的方法可能引发在一个尚未构造完成的对象上调用方法的风险,而且是不易辨识的。它会使得子类不能构建父类或者自己强制重复构建过程,失去调用super()方法的能力。如果一个默认的构造器包含一个对可重写方法的调用,子类可能完全不能被实例化。注意这也包含在整个控制流图上的方法调用——例如:如果构造器Foo()调用了私有方法bar(),而bar()又调用了公开的方法buz(),这就会导致问题。

代码示例:

public class SeniorClass {

  public SeniorClass(){

      toString(); //may throw NullPointerException if overridden

  }

  public String toString(){

    return "IAmSeniorClass";

  }

}

public class JuniorClass extends SeniorClass {

  private String name;

  public JuniorClass(){

    super(); //Automatic call leads to NullPointerException

    name = "JuniorClass";

  }

  public String toString(){

    return name.toUpperCase();

  }

}

·  AccessorClassGeneration: Instantiation by way of private constructors from outside of the constructor's class often causes the generation of an accessor. A factory method, or non-privitization of the constructor can eliminate this situation. The generated class file is actually an interface. It gives the accessing class the ability to invoke a new hidden package scope constructor that takes the interface as a supplementary parameter. This turns a private constructor effectively into one with package scope, and is challenging to discern.

翻译  存取器类生成:从一个具有私有构建器的类的外部实例化这个类通常会导致存取器的生成。工厂方法,或者非私有化的构造器可以避免这个情况。生成的类文件事实上是一个接口。它赋予访问类调用一个新的隐藏的包范围的构建器并把这个接口作为补充参数的能力。这样就把私有的构造器有效地转换为一个包范围的构建器,而且是不易觉察的。

代码示例:

public class Outer {

 void method(){

  Inner ic = new Inner();//Causes generation of accessor class

 }

 public class Inner {

  private Inner(){}

 }

}

·  FinalFieldCouldBeStatic: If a final field is assigned to a compile-time constant, it could be made static, thus saving overhead in each object at runtime.

翻译  final类型的域可以同时是static的:如果一个final类型的域在编译时被赋值为常量,它也可以是static的,那样就在每个对象运行时节省开支。

·  CloseResource: Ensure that resources (like Connection, Statement, and ResultSet objects) are always closed after use.

翻译  关闭资源:确保这些资源(譬如:Connection,Statement,ResultSet对象)总在使用后被关闭。

·  NonStaticInitializer: A nonstatic initializer block will be called any time a constructor is invoked (just prior to invoking the constructor). While this is a valid language construct, it is rarely used and is confusing.

翻译  非静态的初始化器:非静态的初始化块将在构造器被调用的时候被访问(优先于调用构造器)。这是一个有效的语言结构,但使用很少且易造成迷惑。

代码示例:

public class MyClass {

 // this block gets run before any call to a constructor

 {

  System.out.println("I am about to construct myself");

 }

}

·  DefaultLabelNotLastInSwitchStmt: By convention, the default label should be the last label in a switch statement.

翻译  switch表达式中default块应该在最后:按照惯例,default标签应该是switch表达式的最后一个标签。

·  NonCaseLabelInSwitchStatement: A non-case label (e.g. a named break/continue label) was present in a switch statement. This legal, but confusing. It is easy to mix up the case labels and the non-case labels.

翻译  switch表达式中没有case标签:在switch表达式中没有case,是合法的,但是容易造成迷惑。容易将case标签和非case标签混淆。

·  OptimizableToArrayCall: A call to Collection.toArray can use the Collection's size vs an empty Array of the desired type.

翻译  优化toArray调用:调用Collection.toArray时使用集合的规模加上目标类型的空数组作为参数。

代码示例:

class Foo {

 void bar(Collection x) {

   // A bit inefficient

   x.toArray(new Foo[0]);

   // Much better; this one sizes the destination array, avoiding

   // a reflection call in some Collection implementations

   x.toArray(new Foo[x.size()]);

 }

}

·  BadComparison: Avoid equality comparisons with Double.NaN - these are likely to be logic errors.

翻译  错误的比较:避免Double.NaN的相等性比较-这些可能是逻辑错误

·  EqualsNull: Inexperienced programmers sometimes confuse comparison concepts and use equals() to compare to null.

翻译  等于空:经验缺乏的程序员有时候会迷惑于相等性概念,拿equals()方法和null比较

·  ConfusingTernary: In an "if" expression with an "else" clause, avoid negation in the test. For example, rephrase: if (x != y) diff(); else same(); as: if (x == y) same(); else diff(); Most "if (x != y)" cases without an "else" are often return cases, so consistent use of this rule makes the code easier to read. Also, this resolves trivial ordering problems, such as "does the error case go first?" or "does the common case go first?".

翻译  令人迷惑的三种性:在if表达式伴随else子句时,避免在if测试中使用否定表达。例如:不要使用if (x != y) diff(); else same()这种表述,而应该使用if (x == y) same(); else diff(),大多数时候使用if(x!=y)形式时不包含else分句,所以一贯地使用此规则能让代码更易于阅读。此外,这也解决了一个细节的排序问题,比如“应该是判断为false的代码块在前面?”,还是“判断通过的代码块在前?”

·  InstantiationToGetClass: Avoid instantiating an object just to call getClass() on it; use the .class public member instead.

翻译  通过getClass实例化:避免通过访问getClass()实例化对象,使用.class这个公共属性代替。

·  IdempotentOperations: Avoid idempotent operations - they are have no effect.

翻译  幂等性操作:避免幂等性操作-它们不起任何作用

幂等性操作,同样的操作无论执行多少次,其结果都跟第一次执行的结果相同。

代码示例:

public class Foo {

 public void bar() {

  int x = 2;

  x = x;

 }

}

·  SimpleDateFormatNeedsLocale: Be sure to specify a Locale when creating a new instance of SimpleDateFormat.

翻译  SimpleDateFormat类需要本地参数:确保在创建SimpleDateFormat类的实例时指定了Locale参数

·  ImmutableField: Identifies private fields whose values never change once they are initialized either in the declaration of the field or by a constructor. This aids in converting existing classes to immutable classes.

翻译  不变域:识别出一旦被声明就赋值或通过构造器赋值后就从不改变的私有域,它们将存在的类变成了不变类。这样的域可以是final

代码示例:

public class Foo {

  private int x; // could be final

  public Foo() {

      x = 7;

  }

  public void foo() {

     int a = x + 2;

  }

}

·  UseLocaleWithCaseConversions: When doing a String.toLowerCase()/toUpperCase() call, use a Locale. This avoids problems with certain locales, i.e. Turkish.

翻译  大小写转换时使用Locale:当访问String.toLowerCase()/toUpperCase()时使用Locale参数,这样可以避免某些特定的本地化问题,比如土耳其语

·  AvoidProtectedFieldInFinalClass: Do not use protected fields in final classes since they cannot be subclassed. Clarify your intent by using private or package access modifiers instead.

翻译  避免在final类中使用protected域:因为final类型的class不能被继承,所以不要使用protected域,通过使用private或包访问符来代替以修正你的意图。

·  AssignmentToNonFinalStatic: Identifies a possible unsafe usage of a static field.

翻译  给一个非finalstatic类型赋值:识别出一个非安全的static域使用

代码示例:

public class StaticField {

   static int x;

   public FinalFields(int y) {

    x = y; // unsafe

   }

}

·  MissingStaticMethodInNonInstantiatableClass: A class that has private constructors and does not have any static methods or fields cannot be used.

翻译  在不可实例化类中缺少静态方法:一个具有私有构造器且没有任何静态方法或静态变量的类不能被使用

·  AvoidSynchronizedAtMethodLevel: Method level synchronization can backfire when new code is added to the method. Block-level synchronization helps to ensure that only the code that needs synchronization gets it.

翻译  避免方法级的同步:当为一个同步的方法加入新代码时可能发生意外。块级别的同步可以确保内含真正需要同步的代码。

·  MissingBreakInSwitch: A switch statement without an enclosed break statement may be a bug.

翻译  switch块中缺少breakswitch表达式缺少内含的break块可能是bug

·  UseNotifyAllInsteadOfNotify: Thread.notify() awakens a thread monitoring the object. If more than one thread is monitoring, then only one is chosen. The thread chosen is arbitrary; thus it's usually safer to call notifyAll() instead.

翻译  使用notifyAll代替notify: Thread.notify()唤醒监控对象的线程。如果多余一个线程在监控中,只会有一个被选择。这个线程的选择是随机的,因此调用notifyAll()代替它更安全。

·  AvoidInstanceofChecksInCatchClause: Each caught exception type should be handled in its own catch clause.

翻译  避免在catch块中使用instanceof:每个产生的异常类型都应该在自己的catch块中被处理。

·  AbstractClassWithoutAbstractMethod: The abstract class does not contain any abstract methods. An abstract class suggests an incomplete implementation, which is to be completed by subclasses implementing the abstract methods. If the class is intended to be used as a base class only (not to be instantiated direcly) a protected constructor can be provided prevent direct instantiation.

翻译  抽象类没有抽象方法:抽象类没有包含抽象方法,抽象类建议未完成的方法实现,这个方法在子类中被完成。如果类意图被用作基础类(不被直接实例化),一个protected的构造器就能提供对直接实例化的阻止。

·  SimplifyConditional: No need to check for null before an instanceof; the instanceof keyword returns false when given a null argument.

翻译  简化条件:在使用instanceof之间不需要null校验,当给予一个null作为参数时,instanceof返回false

·  CompareObjectsWithEquals: Use equals() to compare object references; avoid comparing them with ==.

翻译  对象相等性比较:使用equals()比较对象的引用,避免使用”==”来比较

·  PositionLiteralsFirstInComparisons: Position literals first in String comparisons - that way if the String is null you won't get a NullPointerException, it'll just return false.

翻译  把字面量放在比较式的前面:在字符串比较时,将字面量放在前面-这种方法能够避免当字符串为空时的空指针异常,只是返回false

·  UnnecessaryLocalBeforeReturn: Avoid unnecessarily creating local variables

翻译  return之前不必要的本地变量:避免创建不必要的本地变量

代码示例:

public class Foo {

    public int foo() {

      int x = doSomething();

      return x;  // instead, just 'return doSomething();'

    }

  }

·  NonThreadSafeSingleton: Non-thread safe singletons can result in bad state changes. Eliminate static singletons if possible by instantiating the object directly. Static singletons are usually not needed as only a single instance exists anyway. Other possible fixes are to synchronize the entire method or to use an initialize-on-demand holder class (do not use the double-check idiom). See Effective Java, item 48.

翻译  非线程安全的单例:非线程安全的单例可以导致错误的状态转换。如果可能通过直接实例化消除静态的单例.因为事实上只存在一个实例,所以静态单例一般是不需要的。另外的解决办法是同步实际的方法或者使用一个按需实例化的持有类(不要使用双重检查机制)。请参阅:Effective Java,48章。

代码示例:

private static Foo foo = null;

//multiple simultaneous callers may see partially initialized objects

public static Foo getFoo() {

    if (foo==null)

        foo = new Foo();

    return foo;

}

·  UncommentedEmptyMethod: Uncommented Empty Method finds instances where a method does not contain statements, but there is no comment. By explicitly commenting empty methods it is easier to distinguish between intentional (commented) and unintentional empty methods.

翻译  不含注释的空方法:不含注释的空方法就是说一个方法内部没有任何程序代码也没有注释。通过明确的注释空方法能够容易的区分有潜在意向的和无意向的空方法。

·  UncommentedEmptyConstructor: Uncommented Empty Constructor finds instances where a constructor does not contain statements, but there is no comment. By explicitly commenting empty constructors it is easier to distinguish between intentional (commented) and unintentional empty constructors.

翻译  不含注释的空构造器:不含注释的空构造器就是说一个构造器内部没有任何程序代码也没有注释。通过明确的注释空构造器能够容易的区分有潜在意向的和无意向的空构造器

·  AvoidConstantsInterface: An interface should be used only to model a behaviour of a class: using an interface as a container of constants is a poor usage pattern.

翻译  避免常量接口:接口仅仅是应该用来建模类的行为的:使用接口作为常量的容器是一种劣质的用法。

·  UnsynchronizedStaticDateFormatter: SimpleDateFormat is not synchronized. Sun recomends separate format instances for each thread. If multiple threads must access a static formatter, the formatter must be synchronized either on method or block level.

翻译  不要同步静态的DateFormat类:SimpleDateFormat是非同步的。Sun公司建议对每个线程单独的format实例。如果多线程必须访问一个静态formatterformatter必须在方法或块级别同步。

代码示例:

public class Foo {

    private static final SimpleDateFormat sdf = new SimpleDateFormat();

    void bar() {

        sdf.format(); // bad

    }

    synchronized void foo() {

        sdf.format(); // good

    }

}

·  PreserveStackTrace: Throwing a new exception from a catch block without passing the original exception into the new exception will cause the true stack trace to be lost, and can make it difficult to debug effectively.

翻译  保留追踪栈:在一个catch块中抛出一个新的异常却不把原始的异常传递给新的异常会导致真正的追踪信息栈丢失,而且导致难以有效的调试。

代码示例:

public class Foo {

    void good() {

        try{

            Integer.parseInt("a");

        } catch(Exception e){

            throw new Exception(e);

        }

    }

    void bad() {

        try{

            Integer.parseInt("a");

        } catch(Exception e){

            throw new Exception(e.getMessage());

        }

    }

}

·  UseCollectionIsEmpty: The isEmpty() method on java.util.Collection is provided to see if a collection has any elements. Comparing the value of size() to 0 merely duplicates existing behavior.

翻译  使用集合类的isEmpty方法:java.util.Collection类的isEmpty方法提供判断一个集合类是否包含元素。不要是使用size()0比较来重复类库已经提供的方法。

public class Foo {

           void good() {

              List foo = getList();

                 if (foo.isEmpty()) {

                      // blah

                 }

          }

//下面是不推荐的方式

          void bad() {

              List foo = getList();

                      if (foo.size() == 0) {

                            // blah

                      }

                }

      }

·  ClassWithOnlyPrivateConstructorsShouldBeFinal: A class with only private constructors should be final, unless the private constructor is called by a inner class.

翻译  类只包含私有的构造器应该是final的:一个类只包含私有的构造器应该是final的,除非私有构造器被一个内部类访问。

public class Foo {  //Should be final

    private Foo() { }

}

·  EmptyMethodInAbstractClassShouldBeAbstract: An empty method in an abstract class should be abstract instead, as developer may rely on this empty implementation rather than code the appropriate one.

翻译  一个抽象类中的空方法也应该是抽象的:一个抽象类中的空方法也应该是抽象的,因为开发者有可能会信任这个空的实现而不去编写恰当的代码。

·  SingularField: This field is used in only one method and the first usage is assigning a value to the field. This probably means that the field can be changed to a local variable.

翻译  单数的域:域变量只在一个方法中被使用并且第一次使用时对这个域赋值。这种域可以改写为本地变量。

public class Foo {

    private int x;  //Why bother saving this?

    public void foo(int y) {

     x = y + 5;

     return x;

    }

}

·  ReturnEmptyArrayRatherThanNull: For any method that returns an array, it's a better behavior to return an empty array rather than a null reference.

翻译  返回空的数组而不要返回null:对于任何返回数组的方法,返回一个空的数组是一个比返回null引用更好的做法。

·  AbstractClassWithoutAnyMethod: If the abstract class does not provides any methods, it may be just a data container that is not to be instantiated. In this case, it's probably better to use a private or a protected constructor in order to prevent instantiation than make the class misleadingly abstract.

翻译  没有任何方法的抽象类:如果抽象类没有提供任何的方法,它可能只是一个不可被实例化的数据容器,在这种状况下,更好的方法是使用私有的或受保护的构造器以阻止实例化可以让类避免带有欺骗性的抽象。

·  TooFewBranchesForASwitchStatement: Switch are designed complex branches, and allow branches to share treatment. Using a switch for only a few branches is ill advised, as switches are not as easy to understand as if. In this case, it's most likely is a good idea to use a if statement instead, at least to increase code readability.

翻译  switch表达式带有太少的分支:switch表达式是被设计为处理复杂分支的,并且允许分支共享处理逻辑。对于较少分支的情况使用switch是不明智的,因为这样代码不易理解。因此,更好的主意是使用if表达式来代替,这样至少可以增加代码可读性。

Java Logging Rules

·  MoreThanOneLogger: Normally only one logger is used in each class.

翻译   多于一个日志记录器:一般而言一个日志记录器只用于一个类中。

·  LoggerIsNotStaticFinal: In most cases, the Logger can be declared static and final.

翻译   日志记录器不是static final的:大多数情况下,日志记录器应该被定义为static和final的

·  SystemPrintln: System.(out|err).print is used, consider using a logger.

翻译   SystemPrintln:如果发现代码当中使用了System.(out|err).print,应考虑使用日志记录代替

·  AvoidPrintStackTrace: Avoid printStackTrace(); use a logger call instead.

翻译   避免使用PrintStackTrace:避免使用printStackTrace();使用日志记录器代替。

String and StringBuffer Rules

·  AvoidDuplicateLiterals: Code containing duplicate String literals can usually be improved by declaring the String as a constant field.

翻译   避免重复的字面量:代码包含重复的字符串常常可以重构为将此字符串声明为常量

·  StringInstantiation: Avoid instantiating String objects; this is usually unnecessary.

翻译   字符串初始化:避免初始化字符串对象;这是不必要的。

·  StringToString: Avoid calling toString() on String objects; this is unnecessary.

翻译   String.toString():避免对字符串对象调用toString()方法,这是不必要的

·  InefficientStringBuffering: Avoid concatenating non literals in a StringBuffer constructor or append().

翻译   低效的StringBuffering:避免在StringBuffer的构造器或append()方法中连接非字面量类型

·  UnnecessaryCaseChange: Using equalsIgnoreCase() is faster than using toUpperCase/toLowerCase().equals()

翻译   不必要的大小写转换:使用equalsIgnoreCase()比将字符串大小写转换一致后再比较要快。

·  UseStringBufferLength: Use StringBuffer.length() to determine StringBuffer length rather than using StringBuffer.toString().equals("") or StringBuffer.toString().length() ==.

翻译   使用StringBuffer的length()方法:使用StringBuffer对象的length()方法来计算StringBuffer对象的长度,而不是使用StringBuffer.toString().equals("") or StringBuffer.toString().length() ==.等方法

·  AppendCharacterWithChar: Avoid concatenating characters as strings in StringBuffer.append.

翻译   用char类型连接字符:在使用StringBuffer的append()方法连接字符时,避免使用string类型。

·  ConsecutiveLiteralAppends: Consecutively calling StringBuffer.append with String literals

翻译   连续的字面量连接:连接字符串时连续的调用StringBuffer的append()方法

·  UseIndexOfChar: Use String.indexOf(char) when checking for the index of a single character; it executes faster.

翻译   使用indexOf(字符):当你检测单个字符的位置时使用String.indexOf(字符),它执行的很快。不要使用indexOf(字符串)

·  InefficientEmptyStringCheck: String.trim().length() is an inefficient way to check if a String is really empty, as it creates a new String object just to check its size. Consider creating a static function that loops through a string, checking Character.isWhitespace() on each character and returning false if a non-whitespace character is found.

翻译   低效的空字符串检查:用String.trim().length()来判断字符串是否空是低效的做法,因为它会创建一个新的字符串对象然后判断大小。考虑创建一个静态的方法循环String,用isWhitespace()检查每个字符如果遇到非空白字符就返回false

·  InsufficientStringBufferDeclaration: Failing to pre-size a StringBuffer properly could cause it to re-size many times during runtime. This rule checks the characters that are actually passed into StringBuffer.append(), but represents a best guess "worst case" scenario. An empty StringBuffer constructor initializes the object to 16 characters. This default is assumed if the length of the constructor can not be determined.

翻译   不充分的StringBuffer声明:如果不能在事前声明合适大小的StringBuffer容量可能导致运行期不断地重新分配大小。本规则检查字符事实上传递给StringBuffer.append(),但是表明了在最坏情况下的最好的预测。空参数的StringBuffer构造器默认将对象初始化为16个字符的容量。这个默认情况是在构造长度无法确定的情况下假定的。

·  UselessStringValueOf: No need to call String.valueOf to append to a string; just use the valueOf() argument directly.

翻译   无用的valueOf方法:调用append()方法时不需要把参数用valueOf()转换一次,直接将非String类型的值作为参数放在append()里面。

·  StringBufferInstantiationWithChar: StringBuffer sb = new StringBuffer('c'); The char will be converted into int to intialize StringBuffer size.

翻译   StringBuffer使用字符初始化:StringBuffer sb = new StringBuffer('c');字符c会转换为int值,作为StringBuffer的初始化大小参数。

·  UseEqualsToCompareStrings: Using '==' or '!=' to compare strings only works if intern version is used on both sides

翻译   使用equals方法比较字符串:使用‘==’或‘!=’比较字符串大小只是比较两边的常量池的引用。

·  AvoidStringBufferField: StringBuffers can grow quite a lot, and so may become a source of memory leak (if the owning class has a long life time).

翻译   避免在类中使用StringBuffer属性:StringBuffer类型变量可以变得非常庞大,所以可能造成内存泄漏。(如果宿主类有很长的生命期)

Braces Rules

·  IfStmtsMustUseBraces: Avoid using if statements without using curly braces.

翻译  if块必须用括号:避免使用if块时不使用花括号{}

·  WhileLoopsMustUseBraces: Avoid using 'while' statements without using curly braces.

翻译  while循环必须使用括号:避免使用while块时不使用{}

·  IfElseStmtsMustUseBraces: Avoid using if..else statements without using curly braces.

翻译  if…else…块必须使用括号:避免使用if…else…块时不使用{}

·  ForLoopsMustUseBraces: Avoid using 'for' statements without using curly braces.

翻译  for循环必须使用括号:避免在for循环时不使用{}



参考:PMD规则之Design Rules

PMD规则之Java Logging Rules

PMD规则之Braces Rules


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

PMD规则 的相关文章

  • 再聊聊财务自由

    前段时间有人在我星球讨论财务自由 说自由的本质是选择权 有读者觉得大受启发 我就翻了一下旧文 我2017年就说过了啊 谈谈财务自由 但时过境迁 其实我想改变一下之前的说法 所谓财务自由 你虽然拥有了选择权 但并不是无限选择的权力 坦白说 这
  • 电影知识图谱和基于模板的问答系统构建

    目录 前言 一 知识图谱的构建 二 问答系统的构建 1 数据准备 1 1数据获取 1 2数据处理 1 3数据读入 1 4代码 2 问答系统设计 2 1整体流程 2 2实体识别和问题分类 2 3 问题结果查询 2 4问答模板的匹配 三 优化方
  • requests.post 小坑: 默认无超时,会阻塞

    一 遇到问题 最近遇到一个小问题 发现我的进程在调某个 API 的时候 不能正常 work 了 马上一顿 strace p pid 操作 定睛一看 发现我的进程卡在了 recvfrom 23 不动了 一直不会进入 accept 或者 epo
  • 论文笔记 Spectral Regularization Algorithms for Learning Large IncompleteMatrices (soft-impute)

    2010 JMLR 0 摘要 使用凸松弛技术为大规模矩阵完成问题提供一系列正则化低秩解决方案 论文算法 SOFT IMPUTE 迭代地用从软阈值 SVD 获得的元素替换缺失的元素 通过热启动 这使算法能够有效地计算正则化参数值网格上解决方案
  • iOS架构-组件化(Carthage管理工具)

    一 Carthage项目管理工具使用 Step 1 安装 更新Homebrew工具 1 usr bin ruby e curl fsSL https raw githubusercontent com Homebrew install ma
  • 遍历列表中的字典并取出其中的值报错string indices must be integers

    今天写爬虫的时候遇到一个问题 为了方便看我截取出其中的一部分放到测试文件中测试 我想要的是使用for循环遍历列表中的每一个字典然后取出其中某个key对应的value值 但是却报错了 报错显示string indices must be in
  • Python 数据降噪处理的四种方法——均值滤波、小波变换、奇异值分解、改变binSize

    Python 数据降噪处理的四种方法 均值滤波 小波变换 奇异值分解 改变binSize github主页 https github com Taot chen 一 均值滤波 1 算法思想 给定均值滤波窗口长度 对窗口内数据求均值 作为窗口
  • 三基色配色表java_【调色】颜色配色表 适合重彩搭配用

    三基色是指红 绿 蓝三色 各自对应的波长分别为700nm 546 1nm 435 8nm 原色 又称为基色 即用以调配其他色彩的基本色 原色的色纯度最高 最纯净 最鲜艳 可以调配出绝大多数色彩 而其他颜色不能调配出三原色 三原色通常分为两类
  • mysql怎么更新单一值_MySQL 如何快速全表更新某个字段值

    这个问题似乎没有什么好的解决方法 有个朋友提示 能否将1千万条记录拆分成多个部分 并发更新 这种比单纯的一条SQL全表更新要快一些 真的是这样吗 我做了一个实验 1 环境配置 机器配置 16核 32G MySQL 版本 5 7 19 1主2
  • 2-蛇形矩阵

    蛇形矩阵 首先我们来看问题 上面这个矩阵我们要怎么将它输出呢 我们仔细观察这个矩阵 不难发现它是有一定规律的 它的数字沿着一条蛇一样弯曲排布 那么问题来了 我们在电脑中输出都是以一行一行这样来输出的 这个矩阵的顺序明显不符合以行为参考时的输
  • 利用MMPose进行姿态估计(训练、测试全流程)

    前言 MMPose是一款基于PyTorch的姿态分析开源工具箱 是OpenMMLab项目成员之一 主要特性 支持多种人体姿态分析相关任务 2D多人姿态估计 2D手部姿态估计 动物关键点检测等等 更高的精度和更快的速度 包括 自顶向下 和 自
  • C语言做的一个简单的系统

    这个适合初学者去学习 include
  • idea的控制台无法输入

    1 进入help gt Edit Custom VM Options 2 添加 Deditable java test console true 然后重启IDEA即可生效
  • 机器学习:集成学习

    一 集成学习算法简介 1 什么是集成学习 集成学习通过建立几个模型来解决单一预测问题 它的工作原理是生成多个分类器 模型 各自独立地学习和作出预测 这些预测最后结合成组合预测 因此优于任何一个单分类的做出预测 2 复习 机器学习的两个核心任
  • 死锁的成因和对应的解决方案

    目录 一 什么是死锁 二 产生死锁的三个典型场景 案例一 一个线程一把锁 案例二 两个线程两把锁 死锁原因分析 解决办法 案例三 N个线程M把锁 解决办法 三 形成死锁的四个条件 一 什么是死锁 所谓死锁 是指多个进程在运行过程中因争夺资源
  • mysql中脏读,幻读,不可重复读是什么意思及其解决办法

    mysql中脏读 幻读 不可重复读是什么意思 https blog csdn net lafengwnagzi article details 80660631 一个事务读到另外一个事务还没有提交的数据 我们称之为脏读 解决方法 把事务隔离
  • v-if与v-for的不共用问题

    v for的优先级比v if高 所以会优先执行v for 如果你需要v if与v for共用的话 需要把v if放在容器上 ul li user name li ul 这一段代码中 会先去循环v for 循环后再循环一次 对v if的进行显
  • 华为Android10怎样root,华为手机怎么root?详细的root教程在此

    随着华为手机的热销 相信不少机友都入手了华为手机 华为手机有华为和荣耀两个系列 那华为手机怎么获取root权限呢 很多入手了华为手机的朋友都在纠结于root权限获取的问题之上 因为找不到合适的华为手机root的方法 为此 小编为大家带来了华
  • 一图让你明白爬虫与反爬虫进化过程

    爬虫与发爬虫的厮杀 一方为了拿到数据 一方为了防止爬虫拿到数据 谁是最后的赢家 重新理解爬虫中的一些概念 爬虫 自动获取网站数据的程序 反爬虫 使用技术手段防止爬虫程序爬取数据 误伤 反爬虫技术将普通用户识别为爬虫 这种情况多出现在封ip中
  • 颜色分类Ⅱ

    题目 方法一 分治法 算法思路 每次选定一个中间的颜色 这个中间的颜色用给出的k来决定 将小于等于中间的颜色的就放到左边 大于中间颜色的就放到右边 然后分别再递归左右两半 代码思路 递归函数设置四个参数 序列需要处理区间的左右端点和处理的颜

随机推荐

  • async、await 实现原理

    JavaScript 异步编程回顾 由于 JavaScript 是单线程执行模型 因此必须支持异步编程才能提高运行效率 异步编程的语法目标是让异步过程写起来像同步过程 1 回调函数 回调函数 就是把任务的第二段单独写在一个函数里面 等到重新
  • 【程序员面试金典】输入一颗二叉树的跟节点和一个整数,打印出二叉树中结点值的和为输入整数的所有路径。

    题目描述 输入一颗二叉树的跟节点和一个整数 打印出二叉树中结点值的和为输入整数的所有路径 路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径 注意 在返回值的list中 数组长度大的数组靠前 struct TreeNode
  • 多个主机节点上的Hyperledger Fabric

    Hyperledger Fabric是由Linux Foundation托管的业务区块链项目 它是一个 分布式总账解决方案平台 以模块化架构为基础 提供高度机密性 弹性好 灵活性和可扩展性 它旨在支持不同组件的可插拔实现 并适应整个经济生态
  • 【Unity基础】2.网格材质贴图与资源打包

    Unity基础 2 网格材质贴图与资源打包 大家好 我是Lampard 欢迎来到Unity基础系列博客 所学知识来自B站阿发老师 感谢 一 网格材质纹理 第一次接触3D物体的话 会觉得好神奇啊 这个物体究竟是由什么组成的呢 其实3D物体基本
  • UNIX环境高级编程 学习笔记 第一章 UNIX基础知识

    所有OS都为它们所运行的程序提供服务 包括打开文件 执行新程序 分配存储区等 操作系统可定义为一种软件 它控制计算机硬件资源 提供程序运行环境 通常将这种软件称为内核 它相对较小 位于系统核心 内核接口被称为系统调用 公用函数库构建在系统调
  • bootstrap组件:fileinput控件的非常规操作

    在fileinput控件的使用中遇到了一个问题 就是分了三次选了三个文件 点击form提交的时候只会出现最后一次选择的文件 而我想要的是选中的所有文件一起上传 多方查找之后确定了一种可行方案 分享如下 1 引用 和基本引用一样 样式和js
  • Python基础第三集:函数+模块+类,花钱也买不到....

    Python基础知识第三集 Python第一话在这里 Python第二话在这里 今天的是Python第三话 前面的知识点给大家放在上面了 零基础的小伙伴可以自己动手领取 学好Python的基础知识对我们后期 去实现Python案例帮助很大
  • docker 镜像常用命令

    1 拉取镜像 docker pull ubuntu 18 04 2 存储镜像 docker save o tools ubuntu 18 04 tar ubuntu 18 04 3 载入镜像 docker load lt ubuntu 18
  • 模型训练-3D并行

    目录 1 数据并行 Data Parallel 1 1常规数据并行 1 3 数据并行带来的显存优化效果 2 模型并行 2 1 原理 2 2 模型并行带来的显存优化结果 3 ZeRO 3 1 ZeRO1 3 2 ZeRO2 3 3 ZeRO3
  • minio基础知识介绍

    minio基础知识介绍 文章目录 minio基础知识介绍 1 概述 1 1 特性 1 2 部署运行模式 2 存储机制 2 1 纠错码 2 2 RS code编码数据恢复原理 2 3 校验和 3 minio多租户和多用户 3 1 多租户 3
  • tomcat 9 编码问题导致乱码问题(web程序乱码)

    tomcat编码设置问题 由于刚更换tomcat 9 没有修改配置文件 致使项目运行之后 web端出现个别乱码的情况 接下来将配置文件中的设置一一调整 catalina bat文件 catalina bat配置文件中需要添加内容 catal
  • 企业在APP开发时一定要注意的几方面

    随着移动互联网的不断发展 市面上的需求也随着发生了一些改变 而最初的微信小程序已满足不了解一些企业发展的需求 因此 一部分企业开始着手于APP开发 在进行APP开发时 一定要考虑以下几个方面 请点击输入图片描述 最多18字 1 确立应用程序
  • 单片机毕业设计 STM32天气预报系统设计与实现 - 嵌入式 物联网

    文章目录 0 前言 1 简介 2 主要器件 3 实现效果 4 设计原理 5 部分核心代码 6 最后 0 前言 这两年开始毕业设计和毕业答辩的要求和难度不断提升 传统的毕设题目缺少创新和亮点 往往达不到毕业答辩的要求 这两年不断有学弟学妹告诉
  • 模拟实现atoi函数(将数字字符串转换为整型)附加leetcode练习题

    各位朋友们 大家好啊 今天我为大家分享的知识是如何模拟实现atoi函数 相信大家如果能够理解这个知识 对大家以后的刷题是有帮助的 文章目录 什么是atoi函数 atoi函数的作用 先直接使用库函数看看这个函数是什么作用 都是正整数字符的字符
  • [Python知识图谱] 三.Jieba工具中文分词、添加自定义词典及词性标注详解

    本系列文章主要结合Python语言实现知识图谱构建相关工程 具有一定创新性和实用性 非常希望各位博友交流讨论 相互促进成长 前面两篇文章详细讲解了哈工大Pyltp工具 包括中文分词 词性标注 实体识别 依存句法分析和语义角色标注等 但是其中
  • 多级指针和静动态内存的跨函数访问

    参考 多级指针 静动态内存的跨函数访问 作者 枕上 发布时间 2021 07 15 00 27 17 网址 https blog csdn net jinchi boke article details 118724993 spm 1001
  • RAC安装与维护遇到的几个问题

    author skatetime 2009 05 26 rac安装还是比较顺利的 弄了一天 下面是我在安装和使用中遇到的问题 参考文档 http www oracle com technology pub articles hunter r
  • prisma 开发遇到https://xxx failed, reason: read ECONNRESET

    在使用nodejs prisma 开发时使用如下命令遇到错误 npx prisma db pull 设置proxy和https proxy问题依旧 最后使用 f 参数解决问题 npx prisma db pull f
  • ngModel:numfmt

    angularJS 报 ngModel numfmt angularJS 前台报错 Error ngModel numfmt Model is not of type number 错误 ngModel numfmt模型的类型是 numbe
  • PMD规则

    Design Rules UseSingleton If you have a class that has nothing but static methods consider making it a Singleton Note th