com.github.rwhogg.git_vcr.Util.java Source code

Java tutorial

Introduction

Here is the source code for com.github.rwhogg.git_vcr.Util.java

Source

/*
Util.java: Assorted utility functions
       
Copyright  2015 Bob W. Hogg. All Rights Reserved.
       
This file is part of Git-VCR.
       
Git-VCR is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
       
Git-VCR 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 General Public License for more details.
       
You should have received a copy of the GNU General Public License
along with Git-VCR.  If not, see <http://www.gnu.org/licenses/>.
*/

package com.github.rwhogg.git_vcr;

import java.util.*;
import org.apache.commons.lang3.tuple.*;
import org.eclipse.jgit.patch.*;

/**
 * Various utility functions
 */
public class Util {
    private Util() {
    }

    /**
     * error prints an error string then immediately exits.
     * @param message The error string to print (excluding the word "Error: " itself) 
     */
    public static void error(String message) {
        System.err.println("Error: " + message);
        System.exit(1);
    }

    /**
     * getFilesChanged returns a list of all the files changed by this patch
     * @param patch The patch to check
     * @return a list of pairs of files changed (first is the old path, second is the new path)
     */
    public static List<ImmutablePair<String, String>> getFilesChanged(Patch patch) {
        List<ImmutablePair<String, String>> changeList = new LinkedList<>();
        List<? extends FileHeader> headers = patch.getFiles();
        for (FileHeader header : headers) {
            ImmutablePair<String, String> pair = new ImmutablePair<>(header.getOldPath(), header.getNewPath());
            changeList.add(pair);
        }
        return changeList;
    }
}