Here you can find the source of getYear(String referralId)
Parameter | Description |
---|---|
referralId | full referral id (e.g. "3500-10/11-0017") |
public static String getYear(String referralId)
//package com.java2s; /*/*www . jav a 2 s . co m*/ * Ktunaxa Referral Management System. * * Copyright (C) see version control system * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Get the full year from the referral id. * * @param referralId full referral id (e.g. "3500-10/11-0017") * @return year, e.g. "2011" */ public static String getYear(String referralId) { return "20" + parse(referralId)[2]; } private static String[] parse(String referralId) { String[] result = new String[4]; int position = referralId.indexOf('-'); result[0] = referralId.substring(0, position); String temp = referralId.substring(position + 1); position = temp.indexOf('/'); result[1] = temp.substring(0, position); temp = temp.substring(position + 1); position = temp.indexOf('-'); result[2] = temp.substring(0, position); result[3] = temp.substring(position + 1); return result; } }