patrickfav/bytes-java

View on GitHub

Showing 50 of 54 total issues

File Util.java has 497 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*
 * Copyright 2017 Patrick Favre-Bulle
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
Severity: Minor
Found in src/main/java/at/favre/lib/bytes/Util.java - About 7 hrs to fix

    Method decode has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

        static byte[] decode(CharSequence in) {
            // Ignore trailing '=' padding and whitespace from the input.
            int limit = in.length();
            for (; limit > 0; limit--) {
                char c = in.charAt(limit - 1);
    Severity: Minor
    Found in src/main/java/at/favre/lib/bytes/Base64.java - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method shiftRight has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

            static byte[] shiftRight(byte[] byteArray, int shiftBitCount, ByteOrder byteOrder) {
                final int shiftMod = shiftBitCount % 8;
                final byte carryMask = (byte) (0xFF << (8 - shiftMod));
                final int offsetBytes = (shiftBitCount / 8);
    
    
    Severity: Minor
    Found in src/main/java/at/favre/lib/bytes/Util.java - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method shiftLeft has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

            static byte[] shiftLeft(byte[] byteArray, int shiftBitCount, ByteOrder byteOrder) {
                final int shiftMod = shiftBitCount % 8;
                final byte carryMask = (byte) ((1 << shiftMod) - 1);
                final int offsetBytes = (shiftBitCount / 8);
    
    
    Severity: Minor
    Found in src/main/java/at/favre/lib/bytes/Util.java - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method decode has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

            @Override
            public byte[] decode(CharSequence hexString) {
    
                int start;
                if (Objects.requireNonNull(hexString).length() > 2 &&
    Severity: Minor
    Found in src/main/java/at/favre/lib/bytes/BinaryToTextEncoding.java - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        private static final byte[] MAP = new byte[]{
                'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
                'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
                'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4',
                '5', '6', '7', '8', '9', '+', '/'
    Severity: Major
    Found in src/main/java/at/favre/lib/bytes/Base64.java and 1 other location - About 2 hrs to fix
    src/main/java/at/favre/lib/bytes/Base64.java on lines 43..48

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 138.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        private static final byte[] URL_MAP = new byte[]{
                'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
                'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
                'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4',
                '5', '6', '7', '8', '9', '-', '_'
    Severity: Major
    Found in src/main/java/at/favre/lib/bytes/Base64.java and 1 other location - About 2 hrs to fix
    src/main/java/at/favre/lib/bytes/Base64.java on lines 36..41

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 138.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Method decode has 50 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        static byte[] decode(CharSequence in) {
            // Ignore trailing '=' padding and whitespace from the input.
            int limit = in.length();
            for (; limit > 0; limit--) {
                char c = in.charAt(limit - 1);
    Severity: Minor
    Found in src/main/java/at/favre/lib/bytes/Base64.java - About 2 hrs to fix

      Similar blocks of code found in 5 locations. Consider refactoring.
      Open

              static byte[] toByteArray(short[] shortArray) {
                  byte[] primitivesArray = new byte[shortArray.length * 2];
                  ByteBuffer buffer = ByteBuffer.allocate(2);
                  for (int i = 0; i < shortArray.length; i++) {
                      buffer.clear();
      Severity: Major
      Found in src/main/java/at/favre/lib/bytes/Util.java and 4 other locations - About 1 hr to fix
      src/main/java/at/favre/lib/bytes/Util.java on lines 613..622
      src/main/java/at/favre/lib/bytes/Util.java on lines 640..649
      src/main/java/at/favre/lib/bytes/Util.java on lines 667..676
      src/main/java/at/favre/lib/bytes/Util.java on lines 694..703

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 108.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 5 locations. Consider refactoring.
      Open

              static byte[] toByteArray(float[] floatArray) {
                  byte[] primitivesArray = new byte[floatArray.length * 4];
                  ByteBuffer buffer = ByteBuffer.allocate(4);
                  for (int i = 0; i < floatArray.length; i++) {
                      buffer.clear();
      Severity: Major
      Found in src/main/java/at/favre/lib/bytes/Util.java and 4 other locations - About 1 hr to fix
      src/main/java/at/favre/lib/bytes/Util.java on lines 586..595
      src/main/java/at/favre/lib/bytes/Util.java on lines 613..622
      src/main/java/at/favre/lib/bytes/Util.java on lines 667..676
      src/main/java/at/favre/lib/bytes/Util.java on lines 694..703

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 108.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 5 locations. Consider refactoring.
      Open

              static byte[] toByteArray(double[] doubleArray) {
                  byte[] primitivesArray = new byte[doubleArray.length * 8];
                  ByteBuffer buffer = ByteBuffer.allocate(8);
                  for (int i = 0; i < doubleArray.length; i++) {
                      buffer.clear();
      Severity: Major
      Found in src/main/java/at/favre/lib/bytes/Util.java and 4 other locations - About 1 hr to fix
      src/main/java/at/favre/lib/bytes/Util.java on lines 586..595
      src/main/java/at/favre/lib/bytes/Util.java on lines 613..622
      src/main/java/at/favre/lib/bytes/Util.java on lines 640..649
      src/main/java/at/favre/lib/bytes/Util.java on lines 667..676

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 108.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 5 locations. Consider refactoring.
      Open

              static byte[] toByteArray(long[] longArray) {
                  byte[] primitivesArray = new byte[longArray.length * 8];
                  ByteBuffer buffer = ByteBuffer.allocate(8);
                  for (int i = 0; i < longArray.length; i++) {
                      buffer.clear();
      Severity: Major
      Found in src/main/java/at/favre/lib/bytes/Util.java and 4 other locations - About 1 hr to fix
      src/main/java/at/favre/lib/bytes/Util.java on lines 586..595
      src/main/java/at/favre/lib/bytes/Util.java on lines 613..622
      src/main/java/at/favre/lib/bytes/Util.java on lines 640..649
      src/main/java/at/favre/lib/bytes/Util.java on lines 694..703

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 108.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 5 locations. Consider refactoring.
      Open

              static byte[] toByteArray(int[] intArray) {
                  byte[] primitivesArray = new byte[intArray.length * 4];
                  ByteBuffer buffer = ByteBuffer.allocate(4);
                  for (int i = 0; i < intArray.length; i++) {
                      buffer.clear();
      Severity: Major
      Found in src/main/java/at/favre/lib/bytes/Util.java and 4 other locations - About 1 hr to fix
      src/main/java/at/favre/lib/bytes/Util.java on lines 586..595
      src/main/java/at/favre/lib/bytes/Util.java on lines 640..649
      src/main/java/at/favre/lib/bytes/Util.java on lines 667..676
      src/main/java/at/favre/lib/bytes/Util.java on lines 694..703

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 108.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Method countByteArray has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

              static int countByteArray(byte[] array, byte[] pattern) {
                  Objects.requireNonNull(pattern, "pattern must not be null");
                  if (pattern.length == 0 || array.length == 0) {
                      return 0;
                  }
      Severity: Minor
      Found in src/main/java/at/favre/lib/bytes/Util.java - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method indexOf has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

              static int indexOf(byte[] array, byte[] target, int start, int end) {
                  Objects.requireNonNull(array, "array must not be null");
                  Objects.requireNonNull(target, "target must not be null");
                  if (target.length == 0 || start < 0) {
                      return -1;
      Severity: Minor
      Found in src/main/java/at/favre/lib/bytes/Util.java - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method shiftLeft has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              static byte[] shiftLeft(byte[] byteArray, int shiftBitCount, ByteOrder byteOrder) {
                  final int shiftMod = shiftBitCount % 8;
                  final byte carryMask = (byte) ((1 << shiftMod) - 1);
                  final int offsetBytes = (shiftBitCount / 8);
      
      
      Severity: Minor
      Found in src/main/java/at/favre/lib/bytes/Util.java - About 1 hr to fix

        Method shiftRight has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                static byte[] shiftRight(byte[] byteArray, int shiftBitCount, ByteOrder byteOrder) {
                    final int shiftMod = shiftBitCount % 8;
                    final byte carryMask = (byte) (0xFF << (8 - shiftMod));
                    final int offsetBytes = (shiftBitCount / 8);
        
        
        Severity: Minor
        Found in src/main/java/at/favre/lib/bytes/Util.java - About 1 hr to fix

          Method decode has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  @Override
                  public byte[] decode(CharSequence hexString) {
          
                      int start;
                      if (Objects.requireNonNull(hexString).length() > 2 &&
          Severity: Minor
          Found in src/main/java/at/favre/lib/bytes/BinaryToTextEncoding.java - About 1 hr to fix

            Method validate has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

                    @Override
                    public boolean validate(byte[] byteArrayToValidate) {
                        for (byte b : byteArrayToValidate) {
                            if (mode == Mode.NONE_OF && b == refByte) {
                                return false;
            Severity: Minor
            Found in src/main/java/at/favre/lib/bytes/BytesValidator.java - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method encode has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private static byte[] encode(byte[] in, byte[] map, boolean usePadding) {
                    int length = outLength(in.length, usePadding);
                    byte[] out = new byte[length];
                    int index = 0, end = in.length - in.length % 3;
                    for (int i = 0; i < end; i += 3) {
            Severity: Minor
            Found in src/main/java/at/favre/lib/bytes/Base64.java - About 1 hr to fix
              Severity
              Category
              Status
              Source
              Language