<commit_before>/*
 * IzPack - Copyright 2001-2008 <NAME>, All Rights Reserved.
 *
 * http://izpack.org/
 * http://izpack.codehaus.org/
 *
 * Copyright 2006 <NAME>&#064;reddot.de
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.izforge.izpack.util.os.unix;

import com.izforge.izpack.util.StringTool;

import java.io.File;
import java.util.ArrayList;

/**
 * Unix Users Collection Class and related static Helper Methods
 *
 * @author marc.eppelmann&#064;reddot.de
 */
public class UnixUsers extends ArrayList
{

    // ~ Static fields/initializers *********************************************************

    /**
     * serialVersionUID = -4804842346742194981L;
     */
    private static final long serialVersionUID = -4804842346742194981L;

    // ~ Constructors ***********************************************************************

    /**
     * Creates a new UnixUsers object.
     */
    public UnixUsers()
    {
        fromUsersArrayList(getEtcPasswdUsersAsArrayList());
        fromUsersArrayList(getYpPasswdUsersAsArrayList());
    }

    // ~ Methods ****************************************************************************
    /**
     * Gets all known users with valid shells
     *
     * @return an UnixUsers arraylist of these users
     */
    public ArrayList<UnixUser> getUsersWithValidShells()
    {
        ArrayList<UnixUser> result = new ArrayList<UnixUser>();

        for (int idx = 0; idx < size(); idx++)
        {
            UnixUser user = (UnixUser) get(idx);

            if ((user.getShell() != null) && user.getShell().trim().endsWith("sh"))
            {
                result.add(user);
            }
        }

        return result;
    }

    /**
     * Gets all known users with valid shells and really existing (not dummy) Homefolders.
     *
     * @return an UnixUsers Arraylist of these users
     */
    public ArrayList<UnixUser> getUsersWithValidShellsAndExistingHomes()
    {
        ArrayList<UnixUser> result = new ArrayList<UnixUser>();

        ArrayList<UnixUser> usersWithValidShells = getUsersWithValidShells();

        for (int idx = 0; idx < usersWithValidShells.size(); idx++)
        {
            UnixUser user = usersWithValidShells.get(idx);

            if ((user.getHome() != null) && new File(user.getHome().trim()).exists())
            {
                result.add(user);
            }
        }

        return result;
    }

    /**
     * Gets all known users with valid shells and really existing (not dummy) Home And!
     * freedesktop.org/RFC-based "Desktop" folders.
     *
     * @return an UnixUsers Arraylist of these users
     */
    public ArrayList _getUsersWithValidShellsExistingHomesAndDesktops()
    {
        ArrayList result = new ArrayList();

        ArrayList<UnixUser> usersWithValidShellsAndExistingHomes = getUsersWithValidShellsAndExistingHomes();

        for (int idx = 0; idx < usersWithValidShellsAndExistingHomes.size(); idx++)
        {
            UnixUser user = usersWithValidShellsAndExistingHomes.get(idx);

            if ((user.getHome() != null)
                    && new File(user.getHome().trim() + File.separator + "Desktop").exists())
            {
                result.add(user);
            }
        }

        return result;
    }

    /**
     * An StringArray of the existing Desktop folders of all valid users.
     *
     * @return the Stringlist of ValidUsersDesktopFolders
     */
    public ArrayList<String> getValidUsersDesktopFolders()
    {
        ArrayList<String> result = new ArrayList<String>();

        ArrayList validUserDesktops = getUsersWithValidShellsExistingHomesAndDesktops();

        for (int idx = 0; idx < validUserDesktops.size(); idx++)
        {
            UnixUser user = (UnixUser) validUserDesktops.get(idx);
            new File(user.getHome().trim() + File.separator + "Desktop");

            if (user.getHome() != null)
            {
                File DesktopFolder = new File(user.getHome().trim() + File.separator + "Desktop");

                if (DesktopFolder.exists() && DesktopFolder.isDirectory())
                {
                    result.add(DesktopFolder.toString());
                }
            }
        }

        return result;
    }

    /**
     * Gets all known users with valid shells and really existing (not dummy) Home And!
     * freedesktop.org/RFC-based "Desktop" folders.
     *
     * @return an UnixUsers Arraylist of these users<commit_msg>IZPACK-201 Shortcut creation on non-english Linux (Ubuntu 8.10) Get all users with XDG desktop folders.<commit_after>/*
 * IzPack - Copyright 2001-2008 <NAME>, All Rights Reserved.
 *
 * http://izpack.org/
 * http://izpack.codehaus.org/
 *
 * Copyright 2006 <NAME>&#064;reddot.de
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.izforge.izpack.util.os.unix;

import com.izforge.izpack.util.StringTool;

import java.io.File;
import java.util.ArrayList;

/**
 * Unix Users Collection Class and related static Helper Methods
 *
 * @author marc.eppelmann&#064;reddot.de
 */
public class UnixUsers extends ArrayList
{

    // ~ Static fields/initializers *********************************************************

    /**
     * serialVersionUID = -4804842346742194981L;
     */
    private static final long serialVersionUID = -4804842346742194981L;

    // ~ Constructors ***********************************************************************

    /**
     * Creates a new UnixUsers object.
     */
    public UnixUsers()
    {
        fromUsersArrayList(getEtcPasswdUsersAsArrayList());
        fromUsersArrayList(getYpPasswdUsersAsArrayList());
    }

    // ~ Methods ****************************************************************************
    /**
     * Gets all known users with valid shells
     *
     * @return an UnixUsers arraylist of these users
     */
    public ArrayList<UnixUser> getUsersWithValidShells()
    {
        ArrayList<UnixUser> result = new ArrayList<UnixUser>();

        for (int idx = 0; idx < size(); idx++)
        {
            UnixUser user = (UnixUser) get(idx);

            if ((user.getShell() != null) && user.getShell().trim().endsWith("sh"))
            {
                result.add(user);
            }
        }

        return result;
    }

    /**
     * Gets all known users with valid shells and really existing (not dummy) Homefolders.
     *
     * @return an UnixUsers Arraylist of these users
     */
    public ArrayList<UnixUser> getUsersWithValidShellsAndExistingHomes()
    {
        ArrayList<UnixUser> result = new ArrayList<UnixUser>();

        ArrayList<UnixUser> usersWithValidShells = getUsersWithValidShells();

        for (int idx = 0; idx < usersWithValidShells.size(); idx++)
        {
            UnixUser user = usersWithValidShells.get(idx);

            if ((user.getHome() != null) && new File(user.getHome().trim()).exists())
            {
                result.add(user);
            }
        }

        return result;
    }

    /**
     * Gets all known users with valid shells and really existing (not dummy) Home And!
     * freedesktop.org/RFC-based "Desktop" folders.
     *
     * @return an UnixUsers Arraylist of these users
     */
    public ArrayList _getUsersWithValidShellsExistingHomesAndDesktops()
    {
        ArrayList result = new ArrayList();

        ArrayList<UnixUser> usersWithValidShellsAndExistingHomes = getUsersWithValidShellsAndExistingHomes();

        for (int idx = 0; idx < usersWithValidShellsAndExistingHomes.size(); idx++)
        {
            UnixUser user = usersWithValidShellsAndExistingHomes.get(idx);

            if ((user.getHome() != null)
                    && new File( user.getXdgDesktopfolder() ).exists())
            {
                result.add(user);
            }
        }

        return result;
    }

    /**
     * An StringArray of the existing Desktop folders of all valid users.
     *
     * @return the Stringlist of ValidUsersDesktopFolders
     */
    public ArrayList<String> getValidUsersDesktopFolders()
    {
        ArrayList<String> result = new ArrayList<String>();

        ArrayList validUserDesktops = getUsersWithValidShellsExistingHomesAndDesktops();

        for (int idx = 0; idx < validUserDesktops.size(); idx++)
        {
            UnixUser user = (UnixUser) validUserDesktops.get(idx);

            if (user.getHome() != null)
            {
                File DesktopFolder = new File( user.getXdgDesktopfolder() );

                if (DesktopFolder.exists() && DesktopFolder.isDirectory())
                {
                    result.add(DesktopFolder.toString());
                }
            }
        }

        return result;
    }

    /**
     * Gets all known users with valid shells and really existing (not dummy) Home And!
     * freedesktop.org/RFC-based "Desktop" folders.
     *
     * @return an UnixUsers Arraylist of these users
{'fraction_non_alphanumeric': 0.14035087719298245, 'fraction_numerical': 0.013510788465416415, 'mean_word_length': 2.4633379888268156, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6739520', 'n_tokens_mistral': 2864, 'n_tokens_neox': 2612, 'n_words': 722}