<commit_before>package InterMine::Model::ClassDescriptor;

=head1 NAME

InterMine::Model::ClassDescriptor - represents a class in an InterMine model

=head1 SYNOPSIS

 use InterMine::Model::ClassDescriptor;

 ...
 my $cd = 
   new InterMine::Model::ClassDescriptor(model => $model,
                                         name => "Gene", extends => ["BioEntity"]);

=head1 DESCRIPTION

Objects of this class contain the metadata that describes a class in an
InterMine model.  Each class has a name, parent classes/interfaces and any
number of attributes, references and collections.

=head1 AUTHOR

FlyMine C<< <<EMAIL>> >>

=head1 BUGS

Please report any bugs or feature requests to C<<EMAIL>>.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc InterMine::Model::ClassDescriptor

You can also look for information at:

=over 4

=item * FlyMine

L<http://www.flymine.org>

=back

=head1 COPYRIGHT & LICENSE

Copyright 2006,2007,2008,2009 FlyMine, all rights reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=head1 FUNCTIONS

=cut

use strict;

=head2 new

 Usage   : my $cd = new InterMine::Model::ClassDescriptor(model => $model,
                             name => "Gene", extends => ["BioEntity"]);

 Function: create a new ClassDescriptor object
 Args    : model - the InterMine::Model that this class is a part of
           name - the class name
           extends - a list of the classes and interfaces that this classes
                     extends

=cut
sub new
{
  my $class = shift;
  my %opts = @_;
  my $self = {%opts};
  $self->{fields} = [];
  $self->{field_hash} = {};

  $self->{extends} = $opts{extends};

  if (!exists $opts{name}) {
    die "no name given to class constructor\n";
  }
  if (!exists $opts{model}) {
    die "no model given to class constructor\n";
  }

  $self->{attributes} = [];
  $self->{fields} = [];
  $self->{references} = [];
  $self->{collections} = [];

  bless $self, $class;
  return $self;
}

=head2 add_field
 
 Usage   : $cd->add_field($field); 
 Function: add a Field to this class
 Args    : $field - a sub class of InterMine::Model::Field

=cut
sub add_field
{
  # see also: Model->_fix_class_descriptors()

  my $self = shift;
  my $field = shift;

  return if defined $self->get_field_by_name($field->field_name());

  push @{$self->{fields}}, $field;

  if (!exists $self->{field_hash}{$field->field_name}) {
    $self->{field_hash}{$field->field_name()} = $field;
  }

  if (ref $field eq 'InterMine::Model::Attribute') {
    push @{$self->{attributes}}, $field;
  } else {
    if (ref $field eq 'InterMine::Model::Reference') {
      push @{$self->{references}}, $field;
    } else {
      if (ref $field eq 'InterMine::Model::Collection') {
        push @{$self->{collections}}, $field;
      } else {
        die "unknown reference: ", $field, "\n";
      }
    }
  }
}

=head2 name
 
 Usage   : $name = $cd->name();
 Function: Return the name of this class, eg. "org.intermine.model.bio.Gene"
 Args    : none

=cut
sub name
{
  my $self = shift;
  return $self->{name};
}

=head2 unqualified_name
 
 Usage   : $name = $cd->name();
 Function: Return the unqualified name of this class, eg. "Gene"
 Args    : none

=cut
sub unqualified_name
{
  my $self = shift;
  return ($self->{name} =~ /.*\.(.*)/)[0];
}

=head2 extends
 
 Usage   : @parent_class_names = $cd->extends();<commit_msg>Removed $cd->unqualified_name() method, as names are unqualified already by InterMine::Model::Handler in InterMine/Model. Its functionality is provided by $cd->name().<commit_after>package InterMine::Model::ClassDescriptor;

=head1 NAME

InterMine::Model::ClassDescriptor - represents a class in an InterMine model

=head1 SYNOPSIS

 use InterMine::Model::ClassDescriptor;

 ...
 my $cd = 
   new InterMine::Model::ClassDescriptor(model => $model,
                                         name => "Gene", extends => ["BioEntity"]);

=head1 DESCRIPTION

Objects of this class contain the metadata that describes a class in an
InterMine model.  Each class has a name, parent classes/interfaces and any
number of attributes, references and collections.

=head1 AUTHOR

FlyMine C<< <<EMAIL>> >>

=head1 BUGS

Please report any bugs or feature requests to C<<EMAIL>>.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc InterMine::Model::ClassDescriptor

You can also look for information at:

=over 4

=item * FlyMine

L<http://www.flymine.org>

=back

=head1 COPYRIGHT & LICENSE

Copyright 2006,2007,2008,2009 FlyMine, all rights reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=head1 FUNCTIONS

=cut

use strict;

=head2 new

 Usage   : my $cd = new InterMine::Model::ClassDescriptor(model => $model,
                             name => "Gene", extends => ["BioEntity"]);

 Function: create a new ClassDescriptor object
 Args    : model - the InterMine::Model that this class is a part of
           name - the class name
           extends - a list of the classes and interfaces that this classes
                     extends

=cut
sub new
{
  my $class = shift;
  my %opts = @_;
  my $self = {%opts};
  $self->{fields} = [];
  $self->{field_hash} = {};

  $self->{extends} = $opts{extends};

  if (!exists $opts{name}) {
    die "no name given to class constructor\n";
  }
  if (!exists $opts{model}) {
    die "no model given to class constructor\n";
  }

  $self->{attributes} = [];
  $self->{fields} = [];
  $self->{references} = [];
  $self->{collections} = [];

  bless $self, $class;
  return $self;
}

=head2 add_field
 
 Usage   : $cd->add_field($field); 
 Function: add a Field to this class
 Args    : $field - a sub class of InterMine::Model::Field

=cut
sub add_field
{
  # see also: Model->_fix_class_descriptors()

  my $self = shift;
  my $field = shift;

  return if defined $self->get_field_by_name($field->field_name());

  push @{$self->{fields}}, $field;

  if (!exists $self->{field_hash}{$field->field_name}) {
    $self->{field_hash}{$field->field_name()} = $field;
  }

  if (ref $field eq 'InterMine::Model::Attribute') {
    push @{$self->{attributes}}, $field;
  } else {
    if (ref $field eq 'InterMine::Model::Reference') {
      push @{$self->{references}}, $field;
    } else {
      if (ref $field eq 'InterMine::Model::Collection') {
        push @{$self->{collections}}, $field;
      } else {
        die "unknown reference: ", $field, "\n";
      }
    }
  }
}

=head2 name
 
 Usage   : $name = $cd->name();
 Function: Return the name of this class, eg. "Gene"
 Args    : none

=cut
sub name
{
  my $self = shift;
  return $self->{name};
}

=head2 extends
 
 Usage   : @parent_class_names = $cd->extends();
{'fraction_non_alphanumeric': 0.14022248243559718, 'fraction_numerical': 0.008782201405152224, 'mean_word_length': 3.2049230769230768, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1558539', 'n_tokens_mistral': 2285, 'n_tokens_neox': 2177, 'n_words': 694}