<commit_before>/*******************************************************************************
 * Copyright (c) 2004, 2008 <NAME> and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     <NAME> - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.internal.jira.core.model;

/**
 * JIRA version holder
 * 
 * @author <NAME>
 * @author <NAME>
 */
public class JiraVersion implements Comparable<JiraVersion> {

	public final static JiraVersion MIN_VERSION = new JiraVersion("3.3.3"); //$NON-NLS-1$

	public static final JiraVersion JIRA_3_3 = new JiraVersion("3.3"); //$NON-NLS-1$

	public static final JiraVersion JIRA_3_4 = new JiraVersion("3.4"); //$NON-NLS-1$

	public static final JiraVersion JIRA_3_7 = new JiraVersion("3.7"); //$NON-NLS-1$

	public static final JiraVersion JIRA_3_10 = new JiraVersion("3.10"); //$NON-NLS-1$

	public static final JiraVersion JIRA_3_11 = new JiraVersion("3.11"); //$NON-NLS-1$

	public static final JiraVersion JIRA_3_12 = new JiraVersion("3.12"); //$NON-NLS-1$

	public static final JiraVersion JIRA_3_13 = new JiraVersion("3.13"); //$NON-NLS-1$

	private final int major;

	private final int minor;

	private final int micro;

	private final String qualifier;

	public JiraVersion(String version) {
		String[] segments = version == null ? new String[0] : version.split("\\."); //$NON-NLS-1$
		major = segments.length > 0 ? parse(segments[0]) : 0;
		minor = segments.length > 1 ? parse(segments[1]) : 0;
		micro = segments.length > 2 ? parse(segments[2]) : 0;
		qualifier = segments.length == 0 ? "" : getQualifier(segments[segments.length - 1]); //$NON-NLS-1$
	}

	private int parse(String segment) throws NumberFormatException {
		return segment.length() == 0 ? 0 : Integer.parseInt(getVersion(segment));
	}

	private String getVersion(String segment) {
		int n = segment.indexOf('-');
		return n == -1 ? segment : segment.substring(0, n);
	}

	private String getQualifier(String segment) {
		int n = segment.indexOf('-');
		return n == -1 ? "" : segment.substring(n + 1); //$NON-NLS-1$<commit_msg>NEW - bug 260963: [patch] string compare for Bugzilla versions is not robust https://bugs.eclipse.org/bugs/show_bug.cgi?id=260963<commit_after>/*******************************************************************************
 * Copyright (c) 2004, 2008 <NAME> and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     <NAME> - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.internal.jira.core.model;

/**
 * JIRA version holder
 * 
 * @author <NAME>
 * @author <NAME>
 */
public class JiraVersion implements Comparable<JiraVersion> {

	public final static JiraVersion MIN_VERSION = new JiraVersion("3.3.3"); //$NON-NLS-1$

	public static final JiraVersion JIRA_3_3 = new JiraVersion("3.3"); //$NON-NLS-1$

	public static final JiraVersion JIRA_3_4 = new JiraVersion("3.4"); //$NON-NLS-1$

	public static final JiraVersion JIRA_3_7 = new JiraVersion("3.7"); //$NON-NLS-1$

	public static final JiraVersion JIRA_3_10 = new JiraVersion("3.10"); //$NON-NLS-1$

	public static final JiraVersion JIRA_3_11 = new JiraVersion("3.11"); //$NON-NLS-1$

	public static final JiraVersion JIRA_3_12 = new JiraVersion("3.12"); //$NON-NLS-1$

	public static final JiraVersion JIRA_3_13 = new JiraVersion("3.13"); //$NON-NLS-1$

	private final int major;

	private final int minor;

	private final int micro;

	private final String qualifier;

	public JiraVersion(String version) {
		String[] segments = version == null ? new String[0] : version.split("\\."); //$NON-NLS-1$
		major = segments.length > 0 ? parse(segments[0]) : 0;
		minor = segments.length > 1 ? parse(segments[1]) : 0;
		micro = segments.length > 2 ? parse(segments[2]) : 0;
		qualifier = segments.length == 0 ? "" : getQualifier(segments[segments.length - 1]); //$NON-NLS-1$
	}

	private int parse(String segment) {
		try {
			return segment.length() == 0 ? 0 : Integer.parseInt(getVersion(segment));
		} catch (NumberFormatException e) {
			return 0;
		}
	}

	private String getVersion(String segment) {
		int n = segment.indexOf('-');
		return n == -1 ? segment : segment.substring(0, n);
	}

	private String getQualifier(String segment) {
		int n = segment.indexOf('-');
		return n == -1 ? "" : segment.substring(n + 1); //$NON-NLS-1$
{'fraction_non_alphanumeric': 0.19925971622455274, 'fraction_numerical': 0.03557474809788196, 'mean_word_length': 4.241379310344827, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, 'https://': 1, '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': '7665028', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1538, 'n_words': 429}