<commit_before>/*
 * Copyright 2012 The Clustermeister Team.
 *
 * 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.github.nethad.clustermeister.provisioning.ec2;

import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Optional;
import static com.google.common.base.Preconditions.*;
import com.google.common.collect.ComparisonChain;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.domain.LocationScope;

/**
 * Represents a profile configuration list entry.
 * 
 * This class parses and holds AWS EC2 instance configurations.
 *
 * @author daniel
 */
public class AWSInstanceProfile implements Comparable<AWSInstanceProfile> {
    private String profileName;
    private String region;
    private String type;
    private Optional<String> zone;
    private Optional<String> amiId;
    
    /**
     * Create a new {@link AWSInstanceProfile} from AWS EC2 instance meta data.
     * 
     * @param instanceMetadata  the instance meta data.
     * @return a new {@link AWSInstanceProfile} constructed from the instance meta data.
     */
    public static AWSInstanceProfile fromInstanceMetadata(NodeMetadata instanceMetadata) {
        String zoneId = null;
        String regionId;
        if(instanceMetadata.getLocation().getScope() == LocationScope.ZONE) {
            zoneId = instanceMetadata.getLocation().getId();
            regionId = instanceMetadata.getLocation().getParent().getId();
        } else if(instanceMetadata.getLocation().getScope() == LocationScope.REGION) {
            regionId = instanceMetadata.getLocation().getId();
        } else {
            throw new IllegalStateException(String.format(
                    "Instance metadata for '%s' does not contain a region.", 
                    instanceMetadata.getId()));
        }
        
        return newAmiIdBuilder().
                profileName(String.format("<generated fro %s>", instanceMetadata.getId())).
                region(regionId).
                zone(zoneId).
                type(instanceMetadata.getHardware().getId()).
                amiId(instanceMetadata.getImageId()).
                build();
        
    }
    
    /**
     * A builder to construct a new {@link AWSInstanceProfile} with an 
     * AMI (Amazon Machine Image) ID.
     * 
     * @see AmiIdBuilder
     * 
     * @return a new builder.
     */
    public static AmiIdBuilder newAmiIdBuilder() {
        return new AmiIdBuilder();
    }

    /**
     * Private Default Constructor.
     * 
     * Only use with Builders.
     */
    private AWSInstanceProfile() {}
    
    /**
     * Returns the configured name for this profile.
     * 
     * This value is mandatory.
     * 
     * @return the profile name. 
     */
    public String getProfileName() {
        return profileName;
    }

    /**
     * Returns the AMI (Amazon Machine Image) ID configured for this profile.
     * 
     * @return the AMI ID.
     */
    public Optional<String> getAmiId() {
        return amiId;
    }
    
    /**
     * Returns the AWS region ID configured for this profile.
     * 
     * This value is mandatory.
     * 
     * @return the AWS region ID (e.g. eu-west-1).
     */
    public String getRegion() {
        return region;
    }
    
    /**
     * Returns the AWS Availability Zone configured for this profile.
     * 
     * @return the AWS availability zone (e.g. eu-west-1a).
     */
    public Optional<String> getZone() {
        return zone;
    }
    
    /**
     * Returns the AWS hardware type configured for this profile.
     * 
     * @return the AWS hardware type (e.g. t1.micro). 
     * 
     * @see 
     *      <a href="http://aws.amazon.com/ec2/instance-types/">
     *      Amazon EC2 Instance Types</a>
     */
    public String getType() {
        return type;
    }
    
    @Override
    public String toString() {
        ToStringHelper helper = Objects.toStringHelper(profileName).
                add("Region", region).add("Type", type);
        if(zone.isPresent()) {
            helper.add("Zone", zone.get());
        }
        if(amiId.isPresent()) {
            helper.add("AMI ID", amiId.get());
        }
                
        return helper.toString();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        if (obj.getClass() != (getClass())) {
            return false;
        }
        AWSInstanceProfile otherProfile = (AWSInstanceProfile) obj;<commit_msg>fixed toString implementation of AWSInstanceProfile<commit_after>/*
 * Copyright 2012 The Clustermeister Team.
 *
 * 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.github.nethad.clustermeister.provisioning.ec2;

import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Optional;
import static com.google.common.base.Preconditions.*;
import com.google.common.collect.ComparisonChain;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.domain.LocationScope;

/**
 * Represents a profile configuration list entry.
 * 
 * This class parses and holds AWS EC2 instance configurations.
 *
 * @author daniel
 */
public class AWSInstanceProfile implements Comparable<AWSInstanceProfile> {
    private String profileName;
    private String region;
    private String type;
    private Optional<String> zone;
    private Optional<String> amiId;
    
    /**
     * Create a new {@link AWSInstanceProfile} from AWS EC2 instance meta data.
     * 
     * @param instanceMetadata  the instance meta data.
     * @return a new {@link AWSInstanceProfile} constructed from the instance meta data.
     */
    public static AWSInstanceProfile fromInstanceMetadata(NodeMetadata instanceMetadata) {
        String zoneId = null;
        String regionId;
        if(instanceMetadata.getLocation().getScope() == LocationScope.ZONE) {
            zoneId = instanceMetadata.getLocation().getId();
            regionId = instanceMetadata.getLocation().getParent().getId();
        } else if(instanceMetadata.getLocation().getScope() == LocationScope.REGION) {
            regionId = instanceMetadata.getLocation().getId();
        } else {
            throw new IllegalStateException(String.format(
                    "Instance metadata for '%s' does not contain a region.", 
                    instanceMetadata.getId()));
        }
        
        return newAmiIdBuilder().
                profileName(String.format("<generated fro %s>", instanceMetadata.getId())).
                region(regionId).
                zone(zoneId).
                type(instanceMetadata.getHardware().getId()).
                amiId(instanceMetadata.getImageId()).
                build();
        
    }
    
    /**
     * A builder to construct a new {@link AWSInstanceProfile} with an 
     * AMI (Amazon Machine Image) ID.
     * 
     * @see AmiIdBuilder
     * 
     * @return a new builder.
     */
    public static AmiIdBuilder newAmiIdBuilder() {
        return new AmiIdBuilder();
    }

    /**
     * Private Default Constructor.
     * 
     * Only use with Builders.
     */
    private AWSInstanceProfile() {}
    
    /**
     * Returns the configured name for this profile.
     * 
     * This value is mandatory.
     * 
     * @return the profile name. 
     */
    public String getProfileName() {
        return profileName;
    }

    /**
     * Returns the AMI (Amazon Machine Image) ID configured for this profile.
     * 
     * @return the AMI ID.
     */
    public Optional<String> getAmiId() {
        return amiId;
    }
    
    /**
     * Returns the AWS region ID configured for this profile.
     * 
     * This value is mandatory.
     * 
     * @return the AWS region ID (e.g. eu-west-1).
     */
    public String getRegion() {
        return region;
    }
    
    /**
     * Returns the AWS Availability Zone configured for this profile.
     * 
     * @return the AWS availability zone (e.g. eu-west-1a).
     */
    public Optional<String> getZone() {
        return zone;
    }
    
    /**
     * Returns the AWS hardware type configured for this profile.
     * 
     * @return the AWS hardware type (e.g. t1.micro). 
     * 
     * @see 
     *      <a href="http://aws.amazon.com/ec2/instance-types/">
     *      Amazon EC2 Instance Types</a>
     */
    public String getType() {
        return type;
    }
    
    @Override
    public String toString() {
        ToStringHelper helper = Objects.toStringHelper(profileName).
                add("Region", region);
        if(zone.isPresent()) {
            helper.add("Zone", zone.get());
        }
        if(amiId.isPresent()) {
            helper.add("AMI ID", amiId.get());
        }
        
        helper.add("Type", type);
        
        return helper.toString();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        if (obj.getClass() != (getClass())) {
            return false;
        }
        AWSInstanceProfile otherProfile = (AWSInstanceProfile) obj;
{'fraction_non_alphanumeric': 0.10139356078808265, 'fraction_numerical': 0.003267659778952427, 'mean_word_length': 2.185185185185185, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '3026476', 'n_tokens_mistral': 2805, 'n_tokens_neox': 2748, 'n_words': 820}