<commit_before>package net.rubygrapefruit.platform.internal;

import net.rubygrapefruit.platform.*;
import net.rubygrapefruit.platform.Process;
import net.rubygrapefruit.platform.internal.jni.NativeLibraryFunctions;

public abstract class Platform {
    private static Platform platform;

    public static Platform current() {
        synchronized (Platform.class) {
            if (platform == null) {
                String osName = getOperatingSystem().toLowerCase();
                String arch = getArchitecture();
                if (osName.contains("windows")) {
                    platform = new Windows();
                } else if (osName.contains("linux")) {
                    platform = new Linux();
                } else if (osName.contains("os x") && (arch.equals("i386") || arch.equals("x86_64"))) {
                    platform = new OsX();
                } else if (osName.contains("sunos")) {
                    platform = new Solaris();
                } else {
                    platform = new Unsupported();
                }
            }
            return platform;
        }
    }

    public boolean isWindows() {
        return false;
    }

    public <T extends NativeIntegration> T get(Class<T> type) {
        throw new NativeIntegrationUnavailableException(String.format("Native integration %s is not supported on this operating system (%s %s)",
                type.getSimpleName(), getOperatingSystem(), getArchitecture()));
    }

    public abstract String getLibraryName() throws NativeIntegrationUnavailableException;

    private static class Windows extends Platform {
        @Override
        public boolean isWindows() {
            return true;
        }

        @Override
        public String getLibraryName() {
            return "native-win32.dll";
        }

        @Override
        public <T extends NativeIntegration> T get(Class<T> type) {
            if (type.equals(net.rubygrapefruit.platform.Process.class)) {
                return type.cast(new DefaultProcess());
            }
            if (type.equals(Terminals.class)) {
                return type.cast(new WindowsTerminals());
            }
            return super.get(type);
        }
    }

    private static abstract class Posix extends Platform {
        @Override
        public <T extends NativeIntegration> T get(Class<T> type) {
            if (type.equals(PosixFile.class)) {
                return type.cast(new DefaultPosixFile());
            }
            if (type.equals(Process.class)) {
                return type.cast(new DefaultProcess());
            }
            if (type.equals(Terminals.class)) {
                return type.cast(new TerminfoTerminals());
            }
            if (type.equals(SystemInfo.class)) {
                MutableSystemInfo systemInfo = new MutableSystemInfo();
                FunctionResult result = new FunctionResult();
                NativeLibraryFunctions.getSystemInfo(systemInfo, result);
                if (result.isFailed()) {
                    throw new NativeException(String.format("Could not fetch system information: %s",
                            result.getMessage()));
                }
                return type.cast(systemInfo);
            }
            return super.get(type);
        }
    }

    private abstract static class Unix extends Posix {
    }

    private static class Linux extends Unix {
        @Override
        public <T extends NativeIntegration> T get(Class<T> type) {
            if (type.equals(FileSystems.class)) {
                return type.cast(new PosixFileSystems());
            }
            return super.get(type);
        }

        @Override
        public String getLibraryName() {
            if (getArchitecture().equals("amd64")) {
                return "libnative-linux-amd64.so";
            }
            if (getArchitecture().equals("i386")) {
                return "libnative-linux-i386.so";
            }
            throw new NativeIntegrationUnavailableException(String.format(
                    "Native integration is not available for this architecture (%s) on Linux.", getArchitecture()));
        }
    }<commit_msg>Fixed to work with 32bit ibm jvm.<commit_after>package net.rubygrapefruit.platform.internal;

import net.rubygrapefruit.platform.*;
import net.rubygrapefruit.platform.Process;
import net.rubygrapefruit.platform.internal.jni.NativeLibraryFunctions;

public abstract class Platform {
    private static Platform platform;

    public static Platform current() {
        synchronized (Platform.class) {
            if (platform == null) {
                String osName = getOperatingSystem().toLowerCase();
                String arch = getArchitecture();
                if (osName.contains("windows")) {
                    platform = new Windows();
                } else if (osName.contains("linux")) {
                    platform = new Linux();
                } else if (osName.contains("os x") && (arch.equals("i386") || arch.equals("x86_64"))) {
                    platform = new OsX();
                } else if (osName.contains("sunos")) {
                    platform = new Solaris();
                } else {
                    platform = new Unsupported();
                }
            }
            return platform;
        }
    }

    public boolean isWindows() {
        return false;
    }

    public <T extends NativeIntegration> T get(Class<T> type) {
        throw new NativeIntegrationUnavailableException(String.format("Native integration %s is not supported on this operating system (%s %s)",
                type.getSimpleName(), getOperatingSystem(), getArchitecture()));
    }

    public abstract String getLibraryName() throws NativeIntegrationUnavailableException;

    private static class Windows extends Platform {
        @Override
        public boolean isWindows() {
            return true;
        }

        @Override
        public String getLibraryName() {
            return "native-win32.dll";
        }

        @Override
        public <T extends NativeIntegration> T get(Class<T> type) {
            if (type.equals(net.rubygrapefruit.platform.Process.class)) {
                return type.cast(new DefaultProcess());
            }
            if (type.equals(Terminals.class)) {
                return type.cast(new WindowsTerminals());
            }
            return super.get(type);
        }
    }

    private static abstract class Posix extends Platform {
        @Override
        public <T extends NativeIntegration> T get(Class<T> type) {
            if (type.equals(PosixFile.class)) {
                return type.cast(new DefaultPosixFile());
            }
            if (type.equals(Process.class)) {
                return type.cast(new DefaultProcess());
            }
            if (type.equals(Terminals.class)) {
                return type.cast(new TerminfoTerminals());
            }
            if (type.equals(SystemInfo.class)) {
                MutableSystemInfo systemInfo = new MutableSystemInfo();
                FunctionResult result = new FunctionResult();
                NativeLibraryFunctions.getSystemInfo(systemInfo, result);
                if (result.isFailed()) {
                    throw new NativeException(String.format("Could not fetch system information: %s",
                            result.getMessage()));
                }
                return type.cast(systemInfo);
            }
            return super.get(type);
        }
    }

    private abstract static class Unix extends Posix {
    }

    private static class Linux extends Unix {
        @Override
        public <T extends NativeIntegration> T get(Class<T> type) {
            if (type.equals(FileSystems.class)) {
                return type.cast(new PosixFileSystems());
            }
            return super.get(type);
        }

        @Override
        public String getLibraryName() {
            if (getArchitecture().equals("amd64")) {
                return "libnative-linux-amd64.so";
            }
            if (getArchitecture().equals("i386") || getArchitecture().equals("x86")) {
                return "libnative-linux-i386.so";
            }
            throw new NativeIntegrationUnavailableException(String.format(
                    "Native integration is not available for this architecture (%s) on Linux.", getArchitecture()));
        }
    }
{'fraction_non_alphanumeric': 0.0995840760546643, 'fraction_numerical': 0.004991087344028521, 'mean_word_length': 1.7950846894719363, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3834559', 'n_tokens_mistral': 2124, 'n_tokens_neox': 1986, 'n_words': 503}