// Path: src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/restrictions/JobRestriction.java
// public abstract class JobRestriction implements ExtensionPoint, Describable<JobRestriction>, Serializable {
//     
//     public static final JobRestriction DEFAULT = new AnyJobRestriction();
//     
//     /**
//      * Check if the {@link Queue} item can be taken.
//      * This method is being used to check if the {@link Node} can take the
//      * specified job. If the job cannot be taken, Jenkins will try to launch 
//      * the job on other nodes.
//      * @param item An item to be checked
//      * @return true if the node can take the item
//      */
//     public abstract boolean canTake(@Nonnull Queue.BuildableItem item);
//         
//     /**
//      * Check if the {@link Job} can be executed according to the specified {@link Run}.
//      * If the job cannot be executed, it will be aborted by the plugin.
//      * @param run A {@link Run} to be checked 
//      * @return true if the build can be executed
//      */
//     public abstract boolean canTake(@Nonnull Run run);
// 
//     @Override
//     public JobRestrictionDescriptor getDescriptor() {
//         return (JobRestrictionDescriptor) JenkinsHelper.getInstanceOrDie().getDescriptorOrDie(getClass());
//     }
// 
//     /**
//      * Get list of all registered {@link JobRestriction}s.
//      * @return List of {@link JobRestriction}s.
//      */    
//     public static DescriptorExtensionList<JobRestriction,JobRestrictionDescriptor> all() {
//         return JenkinsHelper.getInstanceOrDie().<JobRestriction,JobRestrictionDescriptor>getDescriptorList
//             (JobRestriction.class);
//     }
//     
//     /**
//      * Returns list of {@link JobRestrictionDescriptor}s.
//      * @return List of available descriptors.
//      * @since 0.2
//      */
//     public static List<JobRestrictionDescriptor> allDescriptors() {
//         return all().reverseView();
//     }
//     
// }
// 
// Path: src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/restrictions/JobRestrictionDescriptor.java
// public abstract class JobRestrictionDescriptor extends Descriptor<JobRestriction> {
//     public JobRestrictionDescriptor getDefaultSettingsProvider() {
//         return (JobRestrictionDescriptor)JobRestriction.all().find(AnyJobRestriction.class);
//     } 
// }
// 
// Path: src/main/java/io/jenkins/plugins/jobrestrictions/util/ClassSelector.java
// public class ClassSelector implements Describable<ClassSelector>, Serializable {
//     
//     /**ID of the user*/
//     final @CheckForNull String selectedClass;
// 
//     @DataBoundConstructor
//     public ClassSelector(@CheckForNull String selectedClass) {
//         this.selectedClass = hudson.Util.fixEmptyAndTrim(selectedClass);
//     }
// 
//     @CheckForNull
//     public String getSelectedClass() {
//         return selectedClass;
//     }
// 
//     @Override
//     public Descriptor<ClassSelector> getDescriptor() {
//         return DESCRIPTOR;
//     }
// 
//     @Override
//     public boolean equals(Object obj) {       
//         if (obj instanceof ClassSelector) {
//             ClassSelector cmp = (ClassSelector)obj;
//             return selectedClass != null ? selectedClass.equals(cmp.selectedClass) : cmp.selectedClass == null;
//         }           
//         return false;    
//     }
// 
//     @Override
//     public int hashCode() {
//         int hash = 7;
//         hash = 17 * hash + (selectedClass != null ? selectedClass.hashCode() : 0);
//         return hash;
//     }
//           
//     @Extension
//     public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();
//     public static class DescriptorImpl extends Descriptor<ClassSelector> {
//         
//         @Override
//         public String getDisplayName() {
//             return "N/A";
//         }
//         
//         public FormValidation doCheckSelectedClass(final @QueryParameter String selectedClass) {
//             String _selectedClass = Util.fixEmptyAndTrim(selectedClass);
//             if (_selectedClass == null) {
//                 return FormValidation.error("Field is empty");
//             }
// 
//             try {
//                 Jenkins.getInstance().getPluginManager().uberClassLoader.loadClass(_selectedClass);
//             } catch (Exception ex) {
//                 return FormValidation.warning("Class " + _selectedClass + " cannot be resolved: " + ex.toString());
//             }
// 
//             return FormValidation.ok();
//         }
//     }
// }


import hudson.model.Queue;
import hudson.model.Run;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.Nonnull;
import org.kohsuke.stapler.DataBoundConstructor;
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.Messages;
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.restrictions.JobRestriction;
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.restrictions.JobRestrictionDescriptor;
import io.jenkins.plugins.jobrestrictions.util.ClassSelector;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Extension;
    }

    @Nonnull
    public List<ClassSelector> getJobClasses() {
        return jobClasses;
    }
        
    @Nonnull 
    private synchronized Set<String> getAcceptedJobClasses() {
        if (acceptedClassesHash == null) {
            final List<ClassSelector> selectors = getJobClasses();
            acceptedClassesHash = new HashSet<String>(selectors.size());
            for (ClassSelector selector : selectors) {
                acceptedClassesHash.add(selector.getSelectedClass()); // merge equal entries
            }
        }
        return acceptedClassesHash;
    }

    @Override
    public boolean canTake(Queue.BuildableItem item) {
        return getAcceptedJobClasses().contains(item.task.getClass().getName());
    }

    @Override
    public boolean canTake(Run run) {
        return getAcceptedJobClasses().contains(run.getParent().getClass().getName());
    }
    
    @Extension
// Path: src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/restrictions/JobRestriction.java
// public abstract class JobRestriction implements ExtensionPoint, Describable<JobRestriction>, Serializable {
//     
//     public static final JobRestriction DEFAULT = new AnyJobRestriction();
//     
//     /**
//      * Check if the {@link Queue} item can be taken.
//      * This method is being used to check if the {@link Node} can take the
//      * specified job. If the job cannot be taken, Jenkins will try to launch 
//      * the job on other nodes.
//      * @param item An item to be checked
//      * @return true if the node can take the item
//      */
//     public abstract boolean canTake(@Nonnull Queue.BuildableItem item);
//         
//     /**
//      * Check if the {@link Job} can be executed according to the specified {@link Run}.
//      * If the job cannot be executed, it will be aborted by the plugin.
//      * @param run A {@link Run} to be checked 
//      * @return true if the build can be executed
//      */
//     public abstract boolean canTake(@Nonnull Run run);
// 
//     @Override
//     public JobRestrictionDescriptor getDescriptor() {
//         return (JobRestrictionDescriptor) JenkinsHelper.getInstanceOrDie().getDescriptorOrDie(getClass());
//     }
// 
//     /**
//      * Get list of all registered {@link JobRestriction}s.
//      * @return List of {@link JobRestriction}s.
//      */    
//     public static DescriptorExtensionList<JobRestriction,JobRestrictionDescriptor> all() {
//         return JenkinsHelper.getInstanceOrDie().<JobRestriction,JobRestrictionDescriptor>getDescriptorList
//             (JobRestriction.class);
//     }
//     
//     /**
//      * Returns list of {@link JobRestrictionDescriptor}s.
//      * @return List of available descriptors.
//      * @since 0.2
//      */
//     public static List<JobRestrictionDescriptor> allDescriptors() {
//         return all().reverseView();
//     }
//     
// }
// 
// Path: src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/restrictions/JobRestrictionDescriptor.java
// public abstract class JobRestrictionDescriptor extends Descriptor<JobRestriction> {
//     public JobRestrictionDescriptor getDefaultSettingsProvider() {
//         return (JobRestrictionDescriptor)JobRestriction.all().find(AnyJobRestriction.class);
//     } 
// }
// 
// Path: src/main/java/io/jenkins/plugins/jobrestrictions/util/ClassSelector.java
// public class ClassSelector implements Describable<ClassSelector>, Serializable {
//     
//     /**ID of the user*/
//     final @CheckForNull String selectedClass;
// 
//     @DataBoundConstructor
//     public ClassSelector(@CheckForNull String selectedClass) {
//         this.selectedClass = hudson.Util.fixEmptyAndTrim(selectedClass);
//     }
// 
//     @CheckForNull
//     public String getSelectedClass() {
//         return selectedClass;
//     }
// 
//     @Override
//     public Descriptor<ClassSelector> getDescriptor() {
//         return DESCRIPTOR;
//     }
// 
//     @Override
//     public boolean equals(Object obj) {       
//         if (obj instanceof ClassSelector) {
//             ClassSelector cmp = (ClassSelector)obj;
//             return selectedClass != null ? selectedClass.equals(cmp.selectedClass) : cmp.selectedClass == null;
//         }           
//         return false;    
//     }
// 
//     @Override
//     public int hashCode() {
//         int hash = 7;
//         hash = 17 * hash + (selectedClass != null ? selectedClass.hashCode() : 0);
//         return hash;
//     }
//           
//     @Extension
//     public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();
//     public static class DescriptorImpl extends Descriptor<ClassSelector> {
//         
//         @Override
//         public String getDisplayName() {
//             return "N/A";
//         }
//         
//         public FormValidation doCheckSelectedClass(final @QueryParameter String selectedClass) {
//             String _selectedClass = Util.fixEmptyAndTrim(selectedClass);
//             if (_selectedClass == null) {
//                 return FormValidation.error("Field is empty");
//             }
// 
//             try {
//                 Jenkins.getInstance().getPluginManager().uberClassLoader.loadClass(_selectedClass);
//             } catch (Exception ex) {
//                 return FormValidation.warning("Class " + _selectedClass + " cannot be resolved: " + ex.toString());
//             }
// 
//             return FormValidation.ok();
//         }
//     }
// }


// Path: src/main/java/io/jenkins/plugins/jobrestrictions/restrictions/job/JobClassNameRestriction.java
import hudson.model.Queue;
import hudson.model.Run;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.Nonnull;
import org.kohsuke.stapler.DataBoundConstructor;
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.Messages;
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.restrictions.JobRestriction;
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.restrictions.JobRestrictionDescriptor;
import io.jenkins.plugins.jobrestrictions.util.ClassSelector;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Extension;

    }

    @Nonnull
    public List<ClassSelector> getJobClasses() {
        return jobClasses;
    }
        
    @Nonnull 
    private synchronized Set<String> getAcceptedJobClasses() {
        if (acceptedClassesHash == null) {
            final List<ClassSelector> selectors = getJobClasses();
            acceptedClassesHash = new HashSet<String>(selectors.size());
            for (ClassSelector selector : selectors) {
                acceptedClassesHash.add(selector.getSelectedClass()); // merge equal entries
            }
        }
        return acceptedClassesHash;
    }

    @Override
    public boolean canTake(Queue.BuildableItem item) {
        return getAcceptedJobClasses().contains(item.task.getClass().getName());
    }

    @Override
    public boolean canTake(Run run) {
        return getAcceptedJobClasses().contains(run.getParent().getClass().getName());
    }
    
    @Extension
    public static class DescriptorImpl extends JobRestrictionDescriptor {