Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    public static String[] getContextWindow(String[] a, int index, int windowSize) {
        ArrayList<String> toReturnAL = new ArrayList<String>();

        int begin = Math.max(0, index - windowSize);
        int end = Math.min(a.length, index + windowSize + 1);

        for (int i = begin; i < end; i++) {
            if (i == index)
                toReturnAL.add("[h]" + a[i] + "[/h]");
            else
                toReturnAL.add(a[i]);
        }

        return toReturnAL.toArray(new String[0]);
    }
}