Changeset View
Changeset View
Standalone View
Standalone View
java/src/main/java/org/softwareheritage/graph/SwhPerm.java
- This file was added.
| package org.softwareheritage.graph; | |||||
| /** | |||||
| * Permission types present in the Software Heritage graph. | |||||
| * | |||||
| * @author The Software Heritage developers | |||||
| */ | |||||
| public class SwhPerm { | |||||
seirl: Methods names aren't descriptive, and you're not passing octal, you're just passing integers… | |||||
| /** Software Heritage archives 5 types of permissions (listed below), so we only need 3 bits to compress them. */ | |||||
| public static final int TOTAL_NB_BITS = 3; | |||||
seirlAuthorUnsubmitted Done Inline ActionsUse .values().length seirl: Use `.values().length` | |||||
| public enum Type { | |||||
| CONTENT, | |||||
| EXECUTABLE_CONTENT, | |||||
| SYMLINK, | |||||
| DIRECTORY, | |||||
| REVISION; | |||||
| public static Type fromInt(int intType) { | |||||
| switch (intType) { | |||||
| case 0: | |||||
| return CONTENT; | |||||
| case 1: | |||||
| return EXECUTABLE_CONTENT; | |||||
| case 2: | |||||
| return SYMLINK; | |||||
| case 3: | |||||
| return DIRECTORY; | |||||
| case 4: | |||||
| return REVISION; | |||||
| } | |||||
| throw new IllegalArgumentException("Unknown node type: " + intType); | |||||
| } | |||||
| public static int toInt(Type type) { | |||||
| switch (type) { | |||||
| case CONTENT: | |||||
| return 0; | |||||
| case EXECUTABLE_CONTENT: | |||||
| return 1; | |||||
| case SYMLINK: | |||||
| return 2; | |||||
| case DIRECTORY: | |||||
| return 3; | |||||
| case REVISION: | |||||
| return 4; | |||||
| } | |||||
| throw new IllegalArgumentException("Unknown node type: " + type); | |||||
| } | |||||
| public static Type fromOct(int octType) { | |||||
| switch (octType) { | |||||
| case 0100644: | |||||
| return CONTENT; | |||||
| case 0100755: | |||||
| return EXECUTABLE_CONTENT; | |||||
| case 0120000: | |||||
| return SYMLINK; | |||||
| case 0040000: | |||||
| return DIRECTORY; | |||||
| case 0160000: | |||||
| return REVISION; | |||||
| } | |||||
| throw new IllegalArgumentException("Unknown node type: " + octType); | |||||
| } | |||||
| public static int toOct(Type type) { | |||||
| switch (type) { | |||||
| case CONTENT: | |||||
| return 0100644; | |||||
| case EXECUTABLE_CONTENT: | |||||
| return 0100755; | |||||
| case SYMLINK: | |||||
| return 0120000; | |||||
| case DIRECTORY: | |||||
| return 0040000; | |||||
| case REVISION: | |||||
| return 0160000; | |||||
| } | |||||
| throw new IllegalArgumentException("Unknown node type: " + type); | |||||
| } | |||||
| } | |||||
| } | |||||
Methods names aren't descriptive, and you're not passing octal, you're just passing integers all the time.
I suggest: