text:
<?php

namespace MVNerds\ReportBundle\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpKernel\Exception\HttpException;

use MVNerds\CoreBundle\Model\UserReport;
use MVNerds\CoreBundle\Report\IReport;

/**
 * @Route("/Report")
 */
class ReportController extends Controller
{
	/**
	 * @Route("/report", name="report_report", options={"expose"=true})
	 */
	public function reportObjectAction()
	{
		//Uniquement AJAX
		$request = $this->getRequest();
		if (!$request->isXmlHttpRequest() || !$request->isMethod('POST'))
		{
			throw new HttpException(500, 'Request must be AJAX and POST method');
		}

		//Récupération et vérification des paramètres
		$objectSlug = $request->get('object_slug', null);
		$objectId = $request->get('object_id', null);
		$objectType = $request->get('object_type', null);
		$descriptionIndex = $request->get('description_index', null);
		if (($objectSlug == null && $objectId == null) || $objectType == null) {
			throw new HttpException(500, 'Missing parameters !');
		}
		$description = null;
		foreach(UserReport::$REPORT_MOTIVES as $key => $value) {
			if (isset($value[$descriptionIndex])) {
				$description = $value[$descriptionIndex];
				break;
			}
		}

		//Récupération de l utilisateur courant
		$user = $this->getUser();

		//On essaie de récupérer l objet depuis la BDD
		try {
			if ($objectSlug != null) {
				$object = $this->get('mvnerds.' . $objectType . '_manager')->findBySlug($objectSlug);
			} elseif ($objectId != null) {
				$object = $this->get('mvnerds.' . $objectType . '_manager')->findById($objectId / 47);
			}
		} catch (Exception $e) {
			throw new InvalidArgumentException('Object not found for slug:`'. $objectSlug .'` or for ID: `'. $objectId . '`');
		}

		//On essaie d effectuer le report de $object par $user
		try {
			$this->get('mvnerds.report_manager')->report($object, $user, $description);
			return new Response(json_encode('Report pris en compte'));
		} catch (\Exception $e) {
			return new Response($e->getMessage(), 400);
		}
	}

	public function renderReportBlockAction(IReport $object, $objectType, $isDetailed = false, $hasSlug = true)
	{
		/* @var $reportManager \MVNerds\CoreBundle\Report\ReportManager */
		$reportManager  = $this->get('mvnerds.report_manager');

		if (($user = $this->getUser())) {
			try {
				$reportManager->findByObjectAndUser($object, $user);
				$canReport = false;
			} catch (\Exception $e) {
				$canReport = true;
			}
		} else {
			$canReport = false;
		}

		$params = array(
			'can_report'	=> $canReport,
			'object_type'	=> $objectType
		);

		if ($hasSlug) {
			$params['object_slug'] = $object->getSlug();
		}
		else {
			$params['object_id'] = $object->getId() * 47;
		}

		if ($isDetailed) {
			$params['report_motives'] = UserReport::$REPORT_MOTIVES[$objectType];

			return $this->render('MVNerdsReportBundle:Report:detailed_report_block.html.twig', $params);
		} else {
			return $this->render('MVNerdsReportBundle:Report:simple_report_block.html.twig', $params);
		}
	}
}

redpajama_set_name: RedPajamaGithub


text:
package org.broad.igv.ui.panel;

import org.broad.igv.AbstractHeadlessTest;
import org.broad.igv.Globals;
import org.broad.igv.prefs.Constants;
import org.broad.igv.feature.Locus;
import org.broad.igv.lists.GeneList;
import org.broad.igv.prefs.PreferencesManager;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

import static junit.framework.Assert.assertEquals;

/**
 * User: jacob
 * Date: 2013-Mar-20
 */
public class ReferenceFrameTest extends AbstractHeadlessTest{

    private ReferenceFrame frame;

    @Override
    public void setUp() throws Exception {
        super.setUp();
        RFTSetup();
        frame = new ReferenceFrame("testFrame");
        frame.setChromosomeName(Globals.CHR_ALL);
        frame.setBounds(0, 500);
    }

    @Override
    public void tearDown() throws Exception {
        super.tearDown();
        frame = null;
    }

    @Test
    public void testSetBounds_chr1() throws Exception{
        frame.setChromosomeName("chr1");

        double oldLocScale = frame.getScale();
        double oldOrigin = frame.getOrigin();
        double oldEnd = frame.getEnd();
        int oldWidth = frame.getWidthInPixels();

        double multiplier = 1.2d;
        int newWidth = (int) (multiplier * oldWidth);
        frame.setBounds(0, newWidth);

        assertEquals(oldOrigin, frame.getOrigin());
        assertEquals(oldEnd, frame.getEnd(), 1.0);
        assertEquals(oldLocScale, frame.getScale() * multiplier, 2.0);

        assertConsistent();
    }

    @Test
    public void testJumpTo_00() throws Exception{
        Locus locus = new Locus("chr1", 1000, 2000);
        frame.jumpTo(locus);

        assertEquals(locus.getChr(), frame.getChrName());
        assertEquals(locus.getStart(), frame.getOrigin(), 1.0);
        assertEquals(locus.getEnd(), frame.getEnd(), 1.0);
        assertConsistent();
    }

    @Test
    public void testJumpTo_01() throws Exception{
        Locus locus = new Locus("chr1", 1000, 2000);
        frame.jumpTo(locus);
        double oldLocScale = frame.getScale();
        int oldZoom = frame.getZoom();
        int oldMidPoint = frame.getMidpoint();
        double oldCenter = frame.getCenter();

        int delta = 12344;
        frame.jumpTo(locus.getChr(), locus.getStart() + delta, locus.getEnd() + delta);

        assertEquals(oldLocScale, frame.getScale());
        assertEquals(oldZoom, frame.getZoom());
        assertEquals(oldMidPoint, frame.getMidpoint());

        assertEquals(oldCenter + delta, frame.getCenter(), 1.0);

        assertConsistent();
    }

    @Test
    public void testDoZoomIncrement() throws Exception{
        frame.setChromosomeName("chr1");

        double oldCenter = frame.getCenter();
        double oldLocScale = frame.getScale();
        int oldZoom = frame.getZoom();
        int incrAmount = 2;

        frame.doZoomIncrement(incrAmount);

        assertConsistent();

        assertEquals(oldZoom + incrAmount, frame.getZoom());
        assertEquals(oldCenter, frame.getCenter(), 2.0);

        double scaleMultiplier = Math.pow(2.0, incrAmount);
        assertEquals(oldLocScale, scaleMultiplier * frame.getScale(), 1.0);
    }

    /**
     * Test that when we view a gene list it displays correctly
     */
    @Test
    public void testGeneListView(){

        int paneSize = 300;

        List<String> loci = Arrays.asList("chr1:10000-20000", "chr2:30000-40000");
        GeneList geneList = new GeneList("", loci, false);
        FrameManager.resetFrames(geneList);
        List<ReferenceFrame> frameList = FrameManager.getFrames();

        //Simulate doing layout
        for(int ff = 0; ff < loci.size(); ff++){
            frameList.get(ff).setBounds(ff*paneSize, paneSize);
        }

        assertLociFramesConsistent(loci, frameList);
    }

    private void assertConsistent(){
        assertConsistent(frame);
    }

    static void assertConsistent(ReferenceFrame frame){
        assertEquals(frame.getEnd(), frame.getOrigin() + frame.getScale() * frame.getWidthInPixels());
    }

    static void assertLociFramesConsistent(List<String> loci, List<ReferenceFrame> frameList){
        assertEquals(loci.size(), frameList.size());

        for(int ii=0; ii < loci.size(); ii++){
            ReferenceFrame frame = frameList.get(ii);
            ReferenceFrameTest.assertConsistent(frame);

            Locus locus = Locus.fromString(loci.get(ii));

            assertEquals(locus.getChr(), frame.getChrName());
            assertEquals(locus.getStart() - 1, frame.getOrigin(), 0.5);
            assertEquals(locus.getEnd(), frame.getEnd(), 0.5);
        }
    }

    public static void RFTSetup() {
        PreferencesManager.getPreferences().put(Constants.FLANKING_REGION, "" + 0);
    }
}


text:
'use strict'

const argsUtil = require('./args')

/**
 * @typedef {Object} ExceptionWrapper
 * @property {String} ___jsonclass
 * @property {Number} code
 * @property {Number} httpStatusCode
 * @property {String} exceptionClass
 * @property {String} exceptionMessage
 */

/**
 * @param {String} requestId
 * @param {Object} context
 * @param {?Error|ExceptionWrapper|String} err
 * @param {*} args
 * @returns {Object}
 */
exports.invocationResult = function(requestId, context, err, args) {
  return {
    ___jsonclass          : 'com.backendless.coderunner.commons.protocol.InvocationResult',
    requestId,
    httpResponseStatusCode: context.response.statusCode,
    httpResponseHeaders   : context.response.headers,
    arguments             : args,
    exception             : err && exports.exception(err),
  }
}

/**
 * @param {*} args
 * @returns {Array}
 */
exports.encodeArguments = function(args) {
  return args !== undefined ? argsUtil.encode(args) : []
}

/**
 * @param {?Error|ExceptionWrapper|String} err
 * @returns {Object}
 */
exports.exception = function(err) {
  const errCode = typeof err.code === 'number' ? err.code : 0
  const httpStatusCode = typeof err.httpStatusCode === 'number' ? err.httpStatusCode : -1

  let message = err.exceptionMessage || err.message || err

  if (typeof message !== 'string') {
    message = JSON.stringify(message)
  }

  return {
    ___jsonclass    : err.___jsonclass || 'com.backendless.commons.exception.ExceptionWrapper',
    code            : errCode,
    httpStatusCode  : httpStatusCode,
    exceptionClass  : err.exceptionClass || 'java.lang.Exception',
    exceptionMessage: message
  }
}

/**
 * @param {?Error|ExceptionWrapper|String} err
 * @param {?*=} result
 * @returns {Object}
 */
exports.executionResult = function(err, result) {
  return {
    ___jsonclass: 'com.backendless.servercode.ExecutionResult',
    result      : result,
    exception   : err && exports.exception(err)
  }
}


text:
package com.amazonaws.services.redshift.model.transform;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.amazonaws.AmazonClientException;
import com.amazonaws.Request;
import com.amazonaws.DefaultRequest;
import com.amazonaws.internal.ListWithAutoConstructFlag;
import com.amazonaws.services.redshift.model.*;
import com.amazonaws.transform.Marshaller;
import com.amazonaws.util.StringUtils;

/**
 * Create Hsm Configuration Request Marshaller
 */
public class CreateHsmConfigurationRequestMarshaller implements Marshaller<Request<CreateHsmConfigurationRequest>, CreateHsmConfigurationRequest> {

    public Request<CreateHsmConfigurationRequest> marshall(CreateHsmConfigurationRequest createHsmConfigurationRequest) {

        if (createHsmConfigurationRequest == null) {
            throw new AmazonClientException("Invalid argument passed to marshall(...)");
        }

        Request<CreateHsmConfigurationRequest> request = new DefaultRequest<CreateHsmConfigurationRequest>(createHsmConfigurationRequest, "AmazonRedshift");
        request.addParameter("Action", "CreateHsmConfiguration");
        request.addParameter("Version", "2012-12-01");

        if (createHsmConfigurationRequest.getHsmConfigurationIdentifier() != null) {
            request.addParameter("HsmConfigurationIdentifier", StringUtils.fromString(createHsmConfigurationRequest.getHsmConfigurationIdentifier()));
        }
        if (createHsmConfigurationRequest.getDescription() != null) {
            request.addParameter("Description", StringUtils.fromString(createHsmConfigurationRequest.getDescription()));
        }
        if (createHsmConfigurationRequest.getHsmIpAddress() != null) {
            request.addParameter("HsmIpAddress", StringUtils.fromString(createHsmConfigurationRequest.getHsmIpAddress()));
        }
        if (createHsmConfigurationRequest.getHsmPartitionName() != null) {
            request.addParameter("HsmPartitionName", StringUtils.fromString(createHsmConfigurationRequest.getHsmPartitionName()));
        }
        if (createHsmConfigurationRequest.getHsmPartitionPassword() != null) {
            request.addParameter("HsmPartitionPassword", StringUtils.fromString(createHsmConfigurationRequest.getHsmPartitionPassword()));
        }
        if (createHsmConfigurationRequest.getHsmServerPublicCertificate() != null) {
            request.addParameter("HsmServerPublicCertificate", StringUtils.fromString(createHsmConfigurationRequest.getHsmServerPublicCertificate()));
        }

        java.util.List<Tag> tagsList = createHsmConfigurationRequest.getTags();
        int tagsListIndex = 1;

        for (Tag tagsListValue : tagsList) {
            Tag tagMember = tagsListValue;
            if (tagMember != null) {
                if (tagMember.getKey() != null) {
                    request.addParameter("Tags.Tag." + tagsListIndex + ".Key", StringUtils.fromString(tagMember.getKey()));
                }
                if (tagMember.getValue() != null) {
                    request.addParameter("Tags.Tag." + tagsListIndex + ".Value", StringUtils.fromString(tagMember.getValue()));
                }
            }

            tagsListIndex++;
        }

        return request;
    }
}


text:
package src.facundo.olano.getterAndSetterTester.sample;

import java.util.List;

public class SampleBean2 {
    private char aChar;
    private String aString;
    private List<Integer> theList;

    public char getAChar() {
        return aChar;
    }
    public void setAChar(char char1) {
        aChar = char1;
    }
    public String getAString() {
        return aString;
    }
    public void setAString(String string) {
        aString = string;
    }
    public List<Integer> getTheList() {
        return theList;
    }
    public void setTheList(List<Integer> theList) {
        this.theList = theList;
    }
}


text:
/*
  Function name:  sum(list);
  Input:          A list of numbers
  Returns:        The SUM of all the numbers in the list.
  Prints:         Nothing

  In English, the "sum" function takes as input a list of numbers and
  returns the SUM (total) of all the numbers in the list.

  Things we'll need:
    1. Something to keep track of the running total.
    2. Something that goes through the list one number at a time.
    3. Something that adds the current number to the running total.

  For (3), consider these bits of JavaScript:
    var total = 10;           // assign the value 10 to the variable "total"
    var total = total + 5;    // the value of "total" is now 15
    var total = total + 20;   // the value of "total" is now 35
    var total = total + 7;    // the value of "total" is now 42
    var total = total - 10;   // the value of "total" is now 32 (notice the minus)
    var total = total + 70;   // the value of "total" is now 102
*/

function sum(list) {
  // This is your job. =]

}

// console.log() prints something to the console as a means of basic debugging.

console.log(sum([1]) === 1);
console.log(sum([0]) === 0);
console.log(sum([-1]) === -1);
console.log(sum([1, -1]) === 0);
console.log(sum([0, 10, 0, 20]) === 30);
console.log(sum([-111, -111, -111]) === -333);
console.log(sum([11, 22, 33]) === 66);

/*
 Remember: these are rumble strips, not a driving instructor.
 If any are "false" then something is broken. But just because they all return
 "true" doesn't mean you've nailed it. =]
*/


text:
@implementation NTLNGrowlNotifier

- (id) init {
    [GrowlApplicationBridge setGrowlDelegate:self];
    return self;
}

- (void) dealloc
{
    [_callbackTarget release];
    [super dealloc];
}

- (void) setCallbackTarget:(NSObject<NTLNGrowlClickCallbackTarget>*)target
{
    _callbackTarget = target;
    [_callbackTarget retain];
}

- (NSDictionary *) registrationDictionaryForGrowl {
    NSMutableDictionary *d = [[[NSMutableDictionary alloc] initWithCapacity:10] autorelease];
    NSArray *notifications = [[[NSArray alloc] initWithObjects:
                               NTLN_GROWL_EVENT_MESSAGE_RECEIVED,
                               NTLN_GROWL_EVENT_REPLY_RECEIVED,
                               NTLN_GROWL_EVENT_DIRECT_MESSAGE_RECEIVED
                               , nil] autorelease];
    [d setObject:notifications forKey:GROWL_NOTIFICATIONS_ALL];
    [d setObject:notifications forKey:GROWL_NOTIFICATIONS_DEFAULT];
    return d;
}

- (void) growlNotificationWasClicked:(id)clickContext
{
    NSString* statusId = clickContext;
    [_callbackTarget markAsRead:statusId];
}

- (void) sendToGrowlTitle:(NSString*)title
              description:(NSString*)description
                replyType:(enum NTLNReplyType)type
                     icon:(NSData*)iconData
                 statusId:(NSString*)statusId
{
    int priority = 0;
    BOOL sticky = FALSE;
    NSString *notificationName = NTLN_GROWL_EVENT_MESSAGE_RECEIVED;
    switch (type) {
        case NTLN_MESSAGE_REPLY_TYPE_REPLY:
            priority = 2;
            sticky = TRUE;
            notificationName = NTLN_GROWL_EVENT_REPLY_RECEIVED;
            break;
        case NTLN_MESSAGE_REPLY_TYPE_REPLY_PROBABLE:
            priority = 1;
            sticky = TRUE;
            notificationName = NTLN_GROWL_EVENT_REPLY_RECEIVED;
            break;
        case NTLN_MESSAGE_REPLY_TYPE_DIRECT:
            priority = 2;
            sticky = TRUE;
            notificationName = NTLN_GROWL_EVENT_DIRECT_MESSAGE_RECEIVED;
            title = [@"(DM) " stringByAppendingString:title];
            break;
        default:
            break;
    }

    [GrowlApplicationBridge
     notifyWithTitle:title
     description:description
     notificationName:notificationName
     iconData:iconData
     priority:priority
     isSticky:sticky
     clickContext:statusId];
}

- (void) sendToGrowlTitle:(NSString*)title
              description:(NSString*)description
                replyType:(enum NTLNReplyType)type {
    [self sendToGrowlTitle:title description:description replyType:type icon:nil statusId:nil];
}

- (void) sendToGrowl:(NTLNMessage*)message {
    [self sendToGrowlTitle:[message name]
               description:[message text]
                 replyType:[message replyType]
                      icon:[[message icon] TIFFRepresentation]
                  statusId:[message statusId]];
}

@end


text:
package com.bct.gpstracker.zxing;

import java.io.IOException;
import java.util.Vector;

import android.content.Intent;
import android.content.res.AssetFileDescriptor;
import android.graphics.Bitmap;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.os.Handler;
import android.os.Vibrator;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

import com.bct.gpstracker.R;
import com.bct.gpstracker.base.BaseActivity;
import com.bct.gpstracker.zxing.camera.CameraManager;
import com.bct.gpstracker.zxing.decoding.CaptureActivityHandler;
import com.bct.gpstracker.zxing.decoding.InactivityTimer;
import com.bct.gpstracker.zxing.view.ViewfinderView;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.Result;

public class CaptureActivity extends BaseActivity implements Callback
{

	private CaptureActivityHandler handler;
	private ViewfinderView viewfinderView;
	private Button cancelButton;
	private boolean hasSurface;
	private Vector<BarcodeFormat> decodeFormats;
	private String characterSet;
	private InactivityTimer inactivityTimer;
	private MediaPlayer mediaPlayer;
	private boolean playBeep;
	private static final float BEEP_VOLUME = 0.10f;
	private boolean vibrate;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_zxing);

		CameraManager.init(getApplication());
		viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
		cancelButton = (Button) findViewById(R.id.btn_cancel_scan);
		hasSurface = false;
		inactivityTimer = new InactivityTimer(this);
		cancelButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				CaptureActivity.this.finish();
			}
		});
	}

	@Override
	protected void onResume()
	{
		super.onResume();
		SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
		SurfaceHolder surfaceHolder = surfaceView.getHolder();
		if (hasSurface)
		{
			initCamera(surfaceHolder);
		}
		else
		{
			surfaceHolder.addCallback(this);
			surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
		}
		decodeFormats = null;
		characterSet = null;

		playBeep = true;
		AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE);
		if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL)
		{
			playBeep = false;
		}
		initBeepSound();
		vibrate = true;
	}

	@Override
	protected void onPause()
	{
		super.onPause();
		if (handler != null)
		{
			handler.quitSynchronously();
			handler = null;
		}
		CameraManager.get().closeDriver();
	}

	@Override
	protected void onDestroy()
	{
		inactivityTimer.shutdown();
		super.onDestroy();
	}

	private void initCamera(SurfaceHolder surfaceHolder)
	{
		try
		{
			CameraManager.get().openDriver(surfaceHolder);
		}
		catch (IOException ioe)
		{
			return;
		}
		catch (RuntimeException e)
		{
			return;
		}
		if (handler == null)
		{
			handler = new CaptureActivityHandler(this, decodeFormats, characterSet);
		}
	}

	@Override
	public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
	{

	}

	@Override
	public void surfaceCreated(SurfaceHolder holder)
	{
		if (!hasSurface)
		{
			hasSurface = true;
			initCamera(holder);
		}

	}

	@Override
	public void surfaceDestroyed(SurfaceHolder holder)
	{
		hasSurface = false;

	}

	public ViewfinderView getViewfinderView()
	{
		return viewfinderView;
	}

	public Handler getHandler()
	{
		return handler;
	}

	public void drawViewfinder()
	{
		viewfinderView.drawViewfinder();

	}

	public void handleDecode(final Result obj, Bitmap barcode)
	{
	       inactivityTimer.onActivity();	//此处的代码是扫描成功直接进行返回上一个页面
	        playBeepSoundAndVibrate();
	        String resultString = obj.getText();
	        //FIXME
	        if (resultString.equals("")) {
	            Toast.makeText(CaptureActivity.this, "Scan failed!", Toast.LENGTH_SHORT).show();
	        }else {
//	            System.out.println("Result:"+resultString);
	            Intent resultIntent = new Intent();
	            Bundle bundle = new Bundle();
	            bundle.putString("result", resultString);
	            resultIntent.putExtras(bundle);
	            this.setResult(RESULT_OK, resultIntent);
	        }
	        CaptureActivity.this.finish();
//		inactivityTimer.onActivity();	//这里是弹出对话框进行IMEI号的显示
//		playBeepSoundAndVibrate();
//		AlertDialog.Builder dialog = new AlertDialog.Builder(this);
//		if (barcode == null)
//		{
//			dialog.setIcon(null);
//		}
//		else
//		{
//
//			Drawable drawable = new BitmapDrawable(barcode);
//			dialog.setIcon(drawable);
//		}
//		dialog.setTitle(R.string.zxing_dialog_title);
//		dialog.setMessage(obj.getText());
//		dialog.setNegativeButton(R.string.zxing_dialog__sure, new DialogInterface.OnClickListener()
//		{
//			@Override
//			public void onClick(DialogInterface dialog, int which)
//			{
////				Intent intent = new Intent();
////				intent.setAction("android.intent.action.VIEW");
////				Uri content_url = Uri.parse(obj.getText());
////				intent.setData(content_url);
////				startActivity(intent);
//
//				String objString=obj.getText();
//				String[] objStr=objString.split(";");
//				addDevice(objStr[0],objStr[1]);
////				finish();
//			}
//		});
//		dialog.setPositiveButton(R.string.zxing_dialog_cancel, new DialogInterface.OnClickListener()
//		{
//			@Override
//			public void onClick(DialogInterface dialog, int which)
//			{
//				finish();
//			}
//		});
//		dialog.create().show();
	}

	private void initBeepSound()
	{
		if (playBeep && mediaPlayer == null)
		{
			// The volume on STREAM_SYSTEM is not adjustable, and users found it
			// too loud,
			// so we now play on the music stream.
			setVolumeControlStream(AudioManager.STREAM_MUSIC);
			mediaPlayer = new MediaPlayer();
			mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
			mediaPlayer.setOnCompletionListener(beepListener);

			AssetFileDescriptor file = getResources().openRawResourceFd(R.raw.beep);
			try
			{
				mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
				file.close();
				mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
				mediaPlayer.prepare();
			}
			catch (IOException e)
			{
				mediaPlayer = null;
			}
		}
	}

	private static final long VIBRATE_DURATION = 200L;

	private void playBeepSoundAndVibrate()
	{
		if (playBeep && mediaPlayer != null)
		{
			mediaPlayer.start();
		}
		if (vibrate)
		{
			Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
			vibrator.vibrate(VIBRATE_DURATION);
		}
	}

	/**
	 * When the beep has finished playing, rewind to queue up another one.
	 */
	private final OnCompletionListener beepListener = new OnCompletionListener()
	{
		public void onCompletion(MediaPlayer mediaPlayer)
		{
			mediaPlayer.seekTo(0);
		}
	};

	/**
	 * 添加设备
	 * @param
	 */
	private void addDevice(String name,String imei){
//		try {
//			JSONObject object = new JSONObject();
//			object.put("id", "0");
//			object.put("name", name);
////			object.put("phone", phone);
//			object.put("imei", imei);
//			HttpEntity entity = new StringEntity(object.toString(),"UTF-8");
//			AsyncHttpClient client = new AsyncHttpClient();
//			client.addHeader("accesskey", Session.getInstance().getAccessKey());
//			client.post(CaptureActivity.this,
//					Utils.getMetaValue(CaptureActivity.this, "base_url")+CommonRestPath.deviceAdd(),
//					entity, "", new AsyncHttpResponseHandler(){
//				@Override
//				public void onSuccess(int statusCode, String content) {
//				//	System.out.println(content);
//					String retCode = "";
//					try {
//						JSONObject object = new JSONObject(content);
//						if(object.has("head")){
//							retCode = object.getJSONObject("head").getString("retcode");
//						}
//						if(!retCode.equals("")){
//							if(retCode.equals("1")){
//								CaptureActivity.this.finish();
//							}else{
//								Toast.makeText(CaptureActivity.this, R.string.add_device_err, Toast.LENGTH_SHORT).show();
//								CaptureActivity.this.finish();
//							}
//						}
//					} catch (Exception e) {
//						e.printStackTrace();
//					}
//				}
//				@Override
//				public void onFailure(Throwable error, String content) {
//				//	System.err.println(content);
//				}
//				@Override
//				public void onFinish() {
////					progressBar.setVisibility(View.GONE);
//					WizardAlertDialog.getInstance().closeProgressDialog();
//				}
//				@Override
//				public void onStart() {
////					System.out.println("接口URL:"+Utils.getMetaValue(RegistActivity.this, "base_url")+CommonRestPath.checkPhone());
//					WizardAlertDialog.getInstance().showProgressDialog(R.string.add_device_post_data, CaptureActivity.this);
////					progressBar.setVisibility(View.VISIBLE);
//				}
//			});
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
	}

}


text:
int socket(int domain, int type, int protocol)
{
  PRINT("socket(%d, %d, %d)\n", domain, type, protocol);
  // disallow strange domains, like ALG
  if (domain < 0 || domain > AF_INET6) { errno = EAFNOSUPPORT; return -1; }
  // disallow RAW etc
  if (type < 0 || type > SOCK_DGRAM) { errno = EINVAL; return -1; }
  // we are purposefully ignoring the protocol argument
  if (protocol < 0) { errno = EPROTONOSUPPORT; return -1; }

  return [](const int type)->int{
    switch(type)
    {
      case SOCK_STREAM:
        return FD_map::_open<TCP_FD>().get_id();
      case SOCK_DGRAM:
        return FD_map::_open<UDP_FD>().get_id();
      default:
        errno = EINVAL;
        return -1;
    }
  }(type);
}

int connect(int socket, const struct sockaddr *address, socklen_t len)
{
  PRINT("connect(%d, %p, %d)\n", socket, address, len);
  try {
    auto& fd = FD_map::_get(socket);
    return fd.connect(address, len);
  } catch (const FD_not_found&) {
    errno = EBADF;
    return -1;
  }
}

ssize_t send(int socket, const void *message, size_t len, int fmt)
{
  PRINT("send(%d, %p, %lu, %d)\n", socket, message, len, fmt);
  try {
    auto& fd = FD_map::_get(socket);
    return fd.send(message, len, fmt);
  } catch (const FD_not_found&) {
    errno = EBADF;
    return -1;
  }
}
ssize_t sendto(int socket, const void *message, size_t len, int flags,
  const struct sockaddr *dest_addr, socklen_t dest_len)
{
  PRINT("sendto(%d, %p, %lu, %d, %p, %d)\n", socket, message, len, flags, dest_addr, dest_len);
  try {
    auto& fd = FD_map::_get(socket);
    return fd.sendto(message, len, flags, dest_addr, dest_len);
  } catch (const FD_not_found&) {
    errno = EBADF;
    return -1;
  }
}
ssize_t recv(int socket, void *buffer, size_t length, int flags)
{
  PRINT("recv(%d, %p, %lu, %d)\n", socket, buffer, length, flags);
  try {
    auto& fd = FD_map::_get(socket);
    return fd.recv(buffer, length, flags);
  } catch (const FD_not_found&) {
    errno = EBADF;
    return -1;
  }
}
ssize_t recvfrom(int socket, void *buffer, size_t length,
  int flags, struct sockaddr *address, socklen_t *address_len)
{
  try {
    auto& fd = FD_map::_get(socket);
    return fd.recvfrom(buffer, length, flags, address, address_len);
  } catch (const FD_not_found&) {
    errno = EBADF;
    return -1;
  }
}
int listen(int socket, int backlog)
{
  PRINT("listen(%d, %d)\n", socket, backlog);
  try {
    auto& fd = FD_map::_get(socket);
    return fd.listen(backlog);
  } catch (const FD_not_found&) {
    errno = EBADF;
    return -1;
  }
}
int accept(int socket, struct sockaddr *address, socklen_t *len)
{
  PRINT("accept(%d, %p, %d)\n", socket, address, *len);
  try {
    auto& fd = FD_map::_get(socket);
    return fd.accept(address, len);
  } catch (const FD_not_found&) {
    errno = EBADF;
    return -1;
  }
}
int bind(int socket, const struct sockaddr* address, socklen_t len)
{
  PRINT("bind(%d, %p, %d)\n", socket, address, len);
  try {
    auto& fd = FD_map::_get(socket);
    return fd.bind(address, len);
  } catch (const FD_not_found&) {
    errno = EBADF;
    return -1;
  }
}
int getsockopt(int socket, int level, int option_name,
               void *option_value, socklen_t *option_len)
{
  PRINT("getsockopt(%d, %d, %d, %p, %d)\n", socket, level,
        option_name, option_value, option_len);
  try {
    auto& fd = FD_map::_get(socket);
    return fd.getsockopt(level, option_name, option_value, option_len);
  } catch (const FD_not_found&) {
    errno = EBADF;
    return -1;
  }
}
int setsockopt(int socket, int level, int option_name,
               const void *option_value, socklen_t option_len)
{
  PRINT("setsockopt(%d, %d, %d, %p, %d)\n", socket, level,
        option_name, option_value, option_len);
  try {
    auto& fd = FD_map::_get(socket);
    return fd.setsockopt(level, option_name, option_value, option_len);
  } catch (const FD_not_found&) {
    errno = EBADF;
    return -1;
  }
}
int shutdown(int socket, int how)
{
  PRINT("shutdown(%d, %d)\n", socket, how);
  try {
    auto& fd = FD_map::_get(socket);
    return fd.shutdown(how);
  } catch (const FD_not_found&) {
    errno = EBADF;
    return -1;
  }
}

bool validate_sockaddr_in(const struct sockaddr* address, socklen_t len)
{
  // The specified address is not a valid address for the address family of the specified socket.
  if (UNLIKELY(len < sizeof(struct sockaddr_in))) {
    PRINT("sockaddr_in length too short: %u vs %lu\n", len, sizeof(struct sockaddr_in));
    return false;
  }

  return true;
}


text:
using System;
using System.Collections.Generic;
using System.Composition.Hosting;
using System.Composition;

using Microsoft.Practices.ServiceLocation;

namespace Prism.SysComposition
{
    public class SysCompServiceLocator : ServiceLocatorImplBase
    {

        private CompositionHost _host;

        public void AssignCompositionHost(CompositionHost host)
        {
            _host = host;
        }

        public SysCompServiceLocator(CompositionHost host) : this()
        {
            _host = host;
        }

        public SysCompServiceLocator()
        {
            _host = null;
        }

        protected override object DoGetInstance(Type serviceType, string key)
        {
            return _host.GetExport(serviceType, key);
        }

        protected override IEnumerable<object> DoGetAllInstances(Type serviceType)
        {
            return _host.GetExports(serviceType);
        }
    }
}


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MockHttpContext
{
    public class UserContextValue
    {
        public UserContextValue(string identityUsername, string queryString, string userRole)
        {
            IdentityUsername = identityUsername;
            QueryString = queryString;
            UserRole = userRole;
        }

        public string IdentityUsername
        {
            private set;
            get;
        }

        public string QueryString
        {
            private set;
            get;
        }

        public string UserRole
        {
            private set;
            get;
        }
    }
}


text:
from django.db import models
from django.conf import settings
from empleadosapp.models import Empleado

class UsuarioEmpleado(models.Model):
	codigoEmpleado = models.OneToOneField(Empleado, on_delete=models.CASCADE,)
	codigoUsuario = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE,)
	numeroIngresos = models.PositiveSmallIntegerField(default=0)

	def __str__(self):
		return '%s' % (self.codigoEmpleado)


text:
package com.github.rholder.esthree.cli;

import com.github.rholder.esthree.command.GetMultipart;
import com.github.rholder.esthree.progress.MutableProgressListener;
import com.github.rholder.esthree.progress.PrintingProgressListener;
import com.github.rholder.esthree.progress.TimeProvider;
import com.github.rholder.esthree.util.S3PathUtils;
import io.airlift.command.Arguments;
import io.airlift.command.Command;
import io.airlift.command.Option;

import java.io.File;
import java.util.List;

import static com.google.common.base.Objects.firstNonNull;
import static java.util.Collections.emptyList;

@Command(name = "get-multi", description = "Download a file from S3, but download in multiple parts")
public class GetMultipartCommand extends EsthreeCommand {

    @Option(name = {"-c", "--chunk-size"}, arity = 1, description = "The request chunk size in bytes (e.g. 10485760 for 10MB chunks), defaults to 5MB")
    public Integer chunkSize;

    @Option(name = {"-np", "--no-progress"}, description = "Don't print a progress bar")
    public Boolean progress;

    @Arguments(usage = "<target bucket and key> [optional target file]", description = "The target bucket and key, as in \"s3://bucket/foo.html\"")
    public List<String> parameters;

    public String bucket;
    public String key;
    public File outputFile;
    public MutableProgressListener progressListener;

    @Override
    public void parse() {
        if (help) {
            showUsage(commandMetadata);
            return;
        }

        if (firstNonNull(parameters, emptyList()).size() == 0) {
            showUsage(commandMetadata);
            throw new IllegalArgumentException("No arguments specified");
        }

        String target = parameters.get(0);
        bucket = S3PathUtils.getBucket(target);
        key = S3PathUtils.getPrefix(target);
        progress = progress == null;

        // TODO validate get-multi params here
        if (parameters.size() > 1) {
            outputFile = new File(parameters.get(1));
        } else {
            String filename = S3PathUtils.getFilename(target);
            if(filename == null) {
                throw new IllegalArgumentException("Could not determine target filename from " + target);
            }
            outputFile = new File(filename);
        }

        if (progress) {
            progressListener = new PrintingProgressListener(output, new TimeProvider());
        }
    }

    @Override
    public void run() {
        if (!help) {
            try {
                new GetMultipart(amazonS3Client, bucket, key, outputFile, verbose)
                        .withChunkSize(chunkSize)
                        .withProgressListener(progressListener)
                        .call();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
}


text:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package automarker;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Chris
 *
 * parameterise ambiguity
 *
 */
public class Automarker {
    private final boolean debug;
    private final Stream stream;
    private List<String> finalResultsList;
    private Student student;
    private BufferedWriter writer;

    public Automarker(String stdSolution){
        debug = false;
        stream = new Stream();
        student = null;

        Solution [] solutions = loadFile(stdSolution);
        solutions = markSolutions(solutions);

        //check tests
        //performTests("all");
        if (student!=null){
            student.setSolutions(solutions);
            createReport();
        }else{
            System.err.println("error with student creation");
        }
    }

    //returns the Student which has a solutions file contained within it's object
    public Student result() /**CHANGE*/
    {
        return student;
    }

    //method used for test cases
    private void performTests(String tests){
        Debug("TESTING");
        Solution [] solns = TestCases.loadTest(tests);
        if(tests.equals("performance")){
            long before = System.currentTimeMillis();
            solns = markSolutions(solns);
            long after = System.currentTimeMillis();
            System.out.println("time taken: " + (after-before)/1000.0);
        }else{
            solns = markSolutions(solns);
            boolean check=false;
            String q_description = "";
            for(Solution sol: solns){
                check = TestCases.checkAnswer(sol);
                q_description = sol.getQuestion().getDescription();
                Debug(q_description.substring(0,q_description.indexOf(":")) + ": " + check);
                //System.out.println("\n"+sol.toString());
            }
        }
    }

    //method for quick System.out.println() for objects only when debugging
    private void Debug(Object o){
        if(debug)
            System.out.println(o);
    }

    /***
     * loadFile reads in a student's file which contains their solutions and places these solutions in the
     * "solutions" global array
     *
     * @param fName filename
     */

    private Solution [] loadFile(String fName){
        String line="", sol="", quest="",require="", start="", answer="", date=""; //Strings for solution
        int studIndex=-1, expressionIndex = 0, expressionEndIndex = 0, reasoningIndex = 0; //a few indices
        String reasoning = "",expression = "";
        char firstChar ='a';
        double mark = 0;
        int numS = 0;   //number of solutions
        List<Solution> solutionList = new ArrayList<>();
        List<Line> lineList = new ArrayList<>();
        boolean questionSection = false;

        try {
            File qFile = new File(fName);
            BufferedReader reader=new BufferedReader(new FileReader(qFile));
            while((line=reader.readLine())!=null){
                if (student == null){                                           //first line is student number and name
                    String[] id = line.split("#");                              //# separates student number and student name
                    student = new Student(id[0],id[1]);
                    continue;
                }

                if(line.equals("") || numS==0){                                 //blank line separating solutions
                    //Debug("NEW");
                    if(questionSection){
                        quest+="\n";
                        continue;
                    }
                    numS+=1;
                    if(numS>1){
                        solutionList.add(new Solution(new Question(quest,mark,require,start),lineList.toArray(new Line[1])));
                    }
                    mark=0;
                    require="";
                    start="";
                    lineList = new ArrayList<>();
                    continue;
                }
            	firstChar = line.charAt(0);
                //Question starts with '#', mark starts with '>', requirement starts with '!'

                if (!questionSection){                                          //read in solution specific info
                    if (firstChar =='S'){
                        sol = line;
                    }else if(firstChar=='D'){
                        date = line;
                    }else if(firstChar=='Q'){
                        questionSection = true;
                    }
                    else{
                        //Debug("line");
                        expressionIndex = line.indexOf("->") + 3;           //3 for "-> "
                        expressionEndIndex = line.indexOf("\t[");           //include "[" in case student used tab in answer
                        reasoningIndex = expressionEndIndex + 2;
                        reasoning = "";
                        expression = "";
                        if(expressionEndIndex<0){
                            expression = line.substring(expressionIndex);
                        }else{
                            expression = line.substring(expressionIndex,expressionEndIndex+1);
                            reasoning = line.substring(reasoningIndex);
                        }
                        Line linetemp = new Line(expression,firstChar,reasoning);
                        //Debug(linetemp);
                        lineList.add(linetemp);
                    }
                }else{ //read in question info
                    if (firstChar=='#'){
                        quest = line.substring(1);
                    }else if(firstChar=='<'){
                        mark = Double.parseDouble(line.substring(1));
                    }else if(firstChar=='!'){
                        require = line.substring(1);
                    }else if(firstChar=='>'){
                        start = line.substring(1);
                    }else if(line.equals("A:")){
                        questionSection = false;
                    }else{
                        quest+="\n" + line;
                    }
                }
            }
            reader.close();
            solutionList.add(new Solution(new Question(quest,mark,require,start),lineList.toArray(new Line[1])));
            //questions loaded succesfully

        } catch (IOException e) {
            System.err.print("error reading file: " + e.toString());
        }
        //Debug(solutionList);
        return solutionList.toArray(new Solution[1]);
    }

    /***
     * Method which processes solutions array to assign marks to each line of the solutions
     *
     * For each solution, assess if the reduction is correct
     * There are some common operations done regardless of reduction type
     * Then reduction-specific processing is done
     * If the reduction is correct, a mark is awarded
     *
     * Then assess if the reasoning (between the "[ ]") is correct
     * Some common operations are performed
     * Then reduction-specific reasoning processing is performed
     * If the reasoning is correct, a mark is awarded.
     * Partial marks are possible where alpha reduction reasoning is wrongly
     * generalised or where multiple alpha; so reasoning partially correct
     * could also happen when only one alpha conversion was done, but two
     * were required, then there may have been correct conversion of the one,
     * but overall wrong
     *
     * Multiple alpha reductions can be performed in one step
     * A premature alpha reduction can be performed and marked correctly
     * An unnecessary alpha reduction is not marked, but not penalised by default
     *
     * A false beta ('B') or eta ('n') reduction occurs a mark penalty - where the final mark is divided by the mark penalty (1 is start)
     * Multiple errors increases the mark penalty (increasing size of division)
     *
     * Conversion ('>') is not awarded marks, but not marked incorrect if wrong
     *
     * Arithmetic reduction ('=') is implemented
     *
     * The automarker defaults to Normal order reduction, but a student can use Applicative order if Normal order was not required in the question
     * If Normal order or Applicative order were explicitly required, only the appropriate reductions are considered and lines marked accordingly.
     *
     *
     * @param solutions - array with the student's answers to questions
     * @return solutions - the array of solutions with each question and line marked
     */
    private Solution [] markSolutions(Solution [] solutions){

        Options.getEtaReductionsOption().setValue(false);   //eta reduction is off by default
        Options.getEvaluationOrderOption().setValue(2); //default evaluation is normal (without thunks)

        for (Solution sol: solutions){

            //common reduction steps
            String qStart = sol.getQuestion().getStart();
            String require = sol.getQuestion().getRequirements();
            if(require.equalsIgnoreCase("Applicative")){
                Options.getEvaluationOrderOption().setValue(0); //set evaulation to applicative
                Debug("Applicative");
            }else{
                Options.getEvaluationOrderOption().setValue(2); //back to default normal (without thunks)
                Debug("Normal");
            }
            Line [] lines = sol.getLines();

            Line prev = new Line(qStart,'s',"");
            List<Expr> originalResult = stream.runExpr(qStart); //reductions from question
            List<Expr> finalResults = new ArrayList<>();
            List<Expr> tempResults;
            Expr previousResult = originalResult.get(originalResult.size()-1);
            Expr tempResult;

            finalResultsList = new ArrayList<>();
            //due diligence process for accuracy of calculator
            //what can happen is the final answer can change depending on alpha
            //conversion of calculator in terms of symbols in final result (semantically
            //the same) (see test cases for "(λx.x x) (λx.λy.x y)", "((λx.λy.λz. x y)(λx.x y z) λz.z)", and "(λx.λy. y y) y")
            for(Expr expr:originalResult){
                tempResults = stream.runExpr(expr.toString());
                tempResult = tempResults.get(tempResults.size()-1);
                finalResults.add(tempResult);
                finalResultsList.add(tempResult.toString());
                if(!previousResult.toString().equals(tempResult.toString())){
                    System.out.println(sol.getID()+"\tPOSSIBLE ERROR IN CALCULATOR");
                    System.out.println("list of possible results from " + qStart + " : " + finalResultsList);
                    //System.exit(0);
                }
                previousResult = tempResult;
            }
            Debug("originalResult: " + originalResult);
            Debug("finalResults: " + finalResults);

            List<Expr> currResult = originalResult;             //current set of reductions
            Expr prevReducedExpr = null;
            Expr currReducedExpr = null;
            Expr prevLastExpr;

            Expr currAlphaExpr = currResult.get(0);                     //calculator automatically alpha converts immediately before reducution
            Expr prevAlphaExpr = currAlphaExpr;
            Expr currLastExpr = currResult.get(currResult.size()-1);    //final reduced form
            String prevAlphaStr="";
            String currAlphaStr="";
            String trackAlphaChange="";

            boolean markAwarded=false;
            int markPenalty = 1; //divisor
            int numA = -1;
            int numAExpr = -1;
            for (Line curr: lines){
                markAwarded=false;
                Debug("\nLINE: " + curr);

                if(currResult.size()==1 && !(curr.getReduction()=='>'||curr.getReduction()=='→')){
                    //check if really last by enabling eta
                    Debug("size == 1: " + currResult);
                    Options.getEtaReductionsOption().setValue(true);
                    Debug(Options.getEtaReductionsOption().getValue());

                    currResult = stream.runExpr(prev.getExpression());
                    Options.getEtaReductionsOption().setValue(false);
                    Debug("currResult: " + currResult);

                    if(currResult.size()==1){
                        if((curr.getReduction()=='b'||curr.getReduction()=='B'||curr.getReduction()=='β')){
                            //may be the case that there is a redex in the middle of the expression that the calculator doesn't detect correctly
                            //detects by eleminating non-reducible symbols before said redex
                            Debug("currResult size still == 1: " + currResult);
                            if(prevReducedExpr==null){
                                prevReducedExpr = originalResult.get(0);
                                try {
                                    currReducedExpr = Parser.parse(curr.getExpression());
                                } catch (Parser.ParseException pe) {
                                    System.out.println(pe.getMessage());
                                    break;
                                }
                            }else{
                                prevReducedExpr = currResult.get(0);
                            }
                            String [] symbols = prevReducedExpr.toString().split(" ");
                            String [] tmpArray;
                            Debug("prevReducedExpr: " + prevReducedExpr);
                            int prevResultsLen = stream.runExpr(prevReducedExpr.toString()).size();
                            boolean symBeforeLam = !symbols[0].contains("\\");
                            boolean symLamAfter = false;
                            int index = -1;
                            for(int i=1;i<symbols.length-1;i++){
                                if(symbols[i].contains("\\")){
                                    symLamAfter = true;
                                    index=i;
                                    break;
                                }
                            }

                            if(symBeforeLam && symLamAfter){
                                Debug("symBeforeLam && symLamAfter, index: " + index);
                                StringBuilder sbPrev = new StringBuilder();
                                StringBuilder sbCurr = new StringBuilder();
                                String [] newSymbols = currReducedExpr.toString().split(" ");
                                for(int i=index;i<symbols.length;i++){
                                    sbPrev.append(symbols[i]).append(" ");
                                }
                                for(int i=index;i<newSymbols.length;i++){
                                    sbCurr.append(newSymbols[i]).append(" ");
                                }
                                List<Expr> tempResultsPrev = stream.runExpr(sbPrev.toString());
                                if(tempResultsPrev.size()>prevResultsLen){
                                    List<Expr> tempResultsCurr = stream.runExpr(sbCurr.toString());
                                    Debug("tempResultsPrev: " + tempResultsPrev);
                                    Debug("tempResultsCurr: " + tempResultsCurr);
                                    if(tempResultsCurr.size()>1)
                                        markAwarded = doBetaReduction(tempResultsPrev.get(tempResultsPrev.size()-1), tempResultsCurr.get(tempResultsCurr.size()-1), tempResultsPrev.get(1),tempResultsCurr.get(1), curr);
                                    else
                                        markAwarded = doBetaReduction(tempResultsPrev.get(tempResultsPrev.size()-1), tempResultsCurr.get(tempResultsCurr.size()-1), tempResultsPrev.get(1),tempResultsCurr.get(0), curr);
                                }
                            }
                        }else{
                            //if really done, break
                            break;
                        }
                    }
                }

                prevAlphaExpr = currAlphaExpr;    //should be used to keep track of alpha reductions
                if(currResult.size()>1){
                    prevReducedExpr = currResult.get(1);    //first line of reduction
                }else if(prevReducedExpr == null){
                    prevReducedExpr = currResult.get(0);
                }
                prevLastExpr = currLastExpr;

                Debug("prev.getExpression: " + prev.getExpression());
                Debug("curr.getExpression: " + curr.getExpression());
                currResult = stream.runExpr(curr.getExpression());  //get new reductions based on current line
                Debug("currResult: " + currResult);
                try {
                    currReducedExpr = Parser.parse(curr.getExpression());
                } catch (Parser.ParseException pe) {
                    System.out.println(pe.getMessage());
                    break;
                }
                currAlphaExpr = currResult.get(0);
                currLastExpr = currResult.get(currResult.size()-1);
                Debug("prev last reduced form: " + prevLastExpr);
                Debug("current last reduced form: " + currLastExpr);

                /*** important to note statements ***/
                //prevLastExpr.equals(currLastExpr); //false
                //prevLastExpr == currLastExpr;     //false
                //prevLastExpr.toString().equals(currLastExpr.toString()); //true

                //reduction specific processing for reduction marks
                switch(curr.getReduction()){
                    case 'a':
                    case 'α':
                        /*** ALPHA REDUCTION ***/
                        /*
                        check number of symbols converted by the calculator in the previous and current lines (which is done automatically for conflicts)
                        for each character in the previous line parsed by the calculator,
                        if it is an 'i' and the previous char is a lambda symbol (alpha conversion can only affect lambda symbols),
                        then check the character of the student's current line at the same relative point.
                        If the characters are different, means an alpha reduction has started to take place correctly
                        find bound variables (which have the same iX format as lambda symbol, and check if these were changed
                        in the current student line too.
                        If there was an alpha reduction performed at an earlier stage than strictly required (according to calculator),
                        then can check the total number of alpha converted symbols in all steps, and if the reduction was actually necessary.
                        A necessary reduction would decrease the number of symbols in the solution.
                        */
                        Debug("ALPHA");
                        prevAlphaStr = prevAlphaExpr.toString();
                        trackAlphaChange=prevAlphaStr;          //used to change symbols of prevAlphaStr according to what user performed
                        currAlphaStr = currAlphaExpr.toString();
                        Debug("previous alpha string: " + prevAlphaStr);
                        Debug("current alpha string:  " + currAlphaStr);

                        numA = countAlpha(prevAlphaStr);
                        numAExpr = countAlpha(currAlphaStr);
                        Debug("# alpha's in prev: " + (numA+1) + "\n# alpha's in curr: " + (numAExpr+1));
                        if(numAExpr<numA){
                            //there are less alpha reductions performed by calculator
                            //can award marks proportional to number of alpha reductions
                            if(numAExpr>-1){ //default is -1
                                //calculator changes ambiguous symbols automatically, so if there is still ambiguity, wrong
                                break;
                            }
                            int iOffset=0;  //if there are multiple 'i's, indices can shift between comparison lines
                            int alphaNum = -1;
                            boolean bound=false;
                            int numIs = 0;
                            int numIsTrack = 0;

                            for(int i = 0;i<prevAlphaStr.length();i++){
                                char c = prevAlphaStr.charAt(i);
                                if(c=='i'){
                                    if(prevAlphaStr.charAt(i-1)=='\\' || prevAlphaStr.charAt(i-1)=='λ'){    //check affected a lambda symbol
                                        alphaNum = Character.getNumericValue(prevAlphaStr.charAt(i+1));
                                        numIs = countI(prevAlphaStr.substring(0,i));
                                        char c2 = currAlphaStr.charAt(i-numIs);                             //retrieve character of line at same index
                                        Debug("alphaNum: i" + alphaNum +
                                                "i: " + i +
                                                "iOffset: " + iOffset +
                                                "c2: " + c2 +
                                                "numIs: " + numIs +
                                                "charAt(" + (i-numIs) + ")");
                                        if(c != c2){                                                        //if character changed, good!
                                            numIsTrack = countI(prevAlphaStr.substring(0,i-numIs)) - countI(trackAlphaChange.substring(0,i-numIs));
                                            trackAlphaChange = trackAlphaChange.substring(0,i-numIsTrack) + c2 + trackAlphaChange.substring(i-numIsTrack+2);
                                            Debug(" numIsTrack: " + numIsTrack +
                                                    "\n prevAlphaStr: " + prevAlphaStr +
                                                    "\n trackAlphaChange: " + trackAlphaChange);
                                            if(c2 != prev.getExpression().charAt(i-iOffset)){               //check lambda bound symbol changed
                                                int boundVarI = prevAlphaStr.indexOf("i"+alphaNum,i+1);     //find corresponding bound var
                                                if(boundVarI<0){
                                                    //no bound vars
                                                    Debug("no bound vars");
                                                    bound=true;
                                                }else{
                                                    //check all bound vars changed
                                                    while(boundVarI>0){
                                                        Debug("bound variable index: " + boundVarI);
                                                        if(prevAlphaStr.charAt(boundVarI-1) == '\\' || //calculator can start numbering again
                                                                prevAlphaStr.charAt(boundVarI-1)=='λ'){//if no more related alpha conversions
                                                            Debug("lambda encountered");
                                                            break;
                                                        }

                                                        numIs = countI(prevAlphaStr.substring(0,boundVarI));
                                                        char c3 = currAlphaStr.charAt(boundVarI-numIs);
                                                        Debug(" iOffset: " + iOffset +
                                                                "\n numIs: " + numIs +
                                                                "\n charAt(" + (boundVarI-numIs) + ")" +
                                                                "\n c3: " + c3);
                                                        if(c3==c2){                                             //bound var also changed
                                                            Debug("bound var changed");
                                                            bound = true;
                                                            numIsTrack = countI(prevAlphaStr.substring(0,boundVarI)) - countI(trackAlphaChange.substring(0,boundVarI-numIs));
                                                            trackAlphaChange = trackAlphaChange.substring(0,boundVarI-numIsTrack) + c2 + trackAlphaChange.substring(boundVarI-numIsTrack+2);
                                                            Debug(prevAlphaStr.substring(0,boundVarI) +
                                                                    "\n " + trackAlphaChange.substring(0,boundVarI-numIs) +
                                                                    "\n " + countI(prevAlphaStr.substring(0,boundVarI-numIs)) + " - " +  countI(trackAlphaChange.substring(0,boundVarI-numIs)) +
                                                                    "\n numIsTrack: " + numIsTrack +
                                                                    "\n prevAlphaStr: " + prevAlphaStr +
                                                                    "\n " + trackAlphaChange.substring(0,boundVarI-numIsTrack) + "\t[" + c2 + "]\t"+trackAlphaChange.substring(boundVarI-numIsTrack+2) +
                                                                    "\n trackAlphaChange: " + trackAlphaChange);
                                                        }else{
                                                            Debug("bound var not changed");
                                                            bound = false;                                      //bound var not changed
                                                            break;
                                                        }
                                                        boundVarI = prevAlphaStr.indexOf("i"+String.valueOf(alphaNum),boundVarI+1); //find other bound var
                                                    }//end while
                                                }
                                                if(bound){
                                                    Debug("award mark");
                                                    curr.addMark(1);
                                                    markAwarded=true;
                                                    bound = false;
                                                }
                                            }
                                        }
                                        iOffset+=1;
                                    }
                                }
                            }//end for loop
                            if(!trackAlphaChange.equals(currAlphaStr)){
                                //premature alpha reduction possible
                                //check total number of alpha conversions in all steps. If reduced, good
                                List<Expr> prevResult = stream.runExpr(prev.getExpression());
                                List<Expr> prevResultTrack = stream.runExpr(trackAlphaChange);
                                int numAlphasPrevResult = 0;
                                int numAlphasTrack = 0;
                                int numAlphasCurrResult = 0;
                                for(Expr expr: prevResult){
                                    numAlphasPrevResult += countAlpha(expr.toString());
                                }
                                for(Expr expr: prevResultTrack){
                                    numAlphasTrack += countAlpha(expr.toString());
                                }
                                for(Expr expr: currResult){
                                    numAlphasCurrResult += countAlpha(expr.toString());
                                }
                                Debug("prevResult: " + prevResult +
                                        "\n prevResultTrack: " + prevResultTrack +
                                        "\n currResult: " + currResult +
                                        "\n numAlphasPrevResult: " + numAlphasPrevResult +
                                        "\n numAlphasTrack: " + numAlphasTrack +
                                        "\n numAlphasCurrResult: " + numAlphasCurrResult);

                                if(numAlphasCurrResult<numAlphasTrack && numAlphasTrack<numAlphasPrevResult){
                                    //the user alphas were required at some point anyway, mark awarded
                                    Debug("award mark");
                                    curr.addMark(1);
                                    markAwarded=true;
                                }
                            }
                        }else{
                            //premature alpha reduction possible
                            //check total number of alpha conversions in all steps. If reduced, good
                            List<Expr> prevResult = stream.runExpr(prev.getExpression());
                            int numAlphasPrevResult = 0;
                            int numAlphasCurrResult = 0;
                            for(Expr expr: prevResult){
                                numAlphasPrevResult += countAlpha(expr.toString());
                            }
                            for(Expr expr: currResult){
                                numAlphasCurrResult += countAlpha(expr.toString());
                            }
                            Debug("prevResult: " + prevResult +
                                        "\n currResult: " + currResult +
                                        "\n numAlphasPrevResult: " + numAlphasPrevResult +
                                        "\n numAlphasCurrResult: " + numAlphasCurrResult);

                            if(numAlphasCurrResult<numAlphasPrevResult){
                                Debug("award mark");
                                curr.addMark(1);
                                markAwarded=true;
                            }else if(numAlphasCurrResult==numAlphasPrevResult){
                                Debug("mark not awarded, but not penalised");
                                markAwarded=true;
                            }

                        }
                        break;
                    case 'b':
                    case 'B':
                    case 'β':
                        /*** BETA REDUCTIONS ***/
                        /*
                        check beta reduction using doBetaReduction method
                        may be alpha conversions still required in future but not performed yet by student,
                        if so, change prevReducedExpr and prevLastExpr to have these alpha values
                        */
                        Debug("BETA");
                        if(!markAwarded) //see the situation where currResult.size()==1
                            markAwarded = doBetaReduction(prevLastExpr, currLastExpr, prevReducedExpr, currReducedExpr, curr);

                        if(markAwarded){
                            Debug("markAwarded, prevAlphaStr before: " + prevAlphaStr);
                            prevAlphaStr = prevReducedExpr.toString();
                            Debug("markAwarded, prevAlphaStr after: " + prevAlphaStr);
                        }
                        else{
                            prevAlphaStr = prevReducedExpr.toString();
                            prevAlphaExpr = prevReducedExpr;    //prevReducedExpr will change below, keep Alpha state(s)
                            currAlphaStr = currAlphaExpr.toString();
                            Debug("previous alpha string: " + prevAlphaStr);
                            Debug("current alpha string: " + currAlphaStr);
                            numA = countAlpha(prevAlphaStr);
                            numAExpr = countAlpha(currAlphaStr);
                            Debug("# alpha's in prev: " + (numA+1) + "\n# alpha's in curr: " + (numAExpr+1));
                            if(numAExpr<numA){
                               int [] aIndex = new int[numA+1];
                               int [] aIndexLast = new int[numA+1];
                               Debug("alpha indices:");
                               for(int i=0;i<aIndex.length;i++){
                                   aIndex[i] = prevReducedExpr.toString().indexOf("i"+i);
                                   aIndexLast[i] = prevLastExpr.toString().indexOf("i"+i);
                                   Debug(aIndex[i]);
                                   try {
                                        prevReducedExpr = Parser.parse(
                                                prevReducedExpr.toString().replace(
                                                                    "i"+i,
                                                        String.valueOf(currReducedExpr.toString().charAt(aIndex[i]))
                                                ));
                                        if(aIndexLast[i]>0){
                                            prevLastExpr = Parser.parse(
                                                    prevLastExpr.toString().replace(
                                                                        "i"+i,
                                                            String.valueOf(currLastExpr.toString().charAt(aIndexLast[i]))
                                                    ));
                                        }
                                    } catch (Parser.ParseException pe) {
                                        System.err.println(pe.getMessage());
                                        break;
                                    }

                               }
                               Debug(" prevReducedExpr: " + prevReducedExpr + "\ncurrReducedExpr: " + currReducedExpr +
                                        "\n prevLastExpr: " + prevLastExpr + "\ncurrLastExpr" + currLastExpr);

                               markAwarded = doBetaReduction(prevLastExpr, currLastExpr, prevReducedExpr, currReducedExpr, curr);

                            }
                        }

                        if(!markAwarded && require.equals("")){
                            //try applicative (default normal)
                            //don't try applicative if require is Normal (or anything else)
                            Debug("mark not awarded and require empty");
                            Options.getEvaluationOrderOption().setValue(0);
                            currResult = stream.runExpr(curr.getExpression());  //get new reductions based on current line
                            Debug("currResult: " + currResult);
                            try {
                                currReducedExpr = Parser.parse(curr.getExpression());
                            } catch (Parser.ParseException pe) {
                                System.out.println(pe.getMessage());
                                break;
                            }
                            prevReducedExpr = currResult.get(0);
                            currLastExpr = currResult.get(currResult.size()-1);
                            markAwarded = doBetaReduction(prevLastExpr, currLastExpr, prevReducedExpr, currReducedExpr, curr);
                            Options.getEvaluationOrderOption().setValue(2);
                        }

                        break;
                    case 'n':
                    case 'η':
                        /*** ETA REDUCTIONS ***/
                        /*
                        if an eta reduction was performed, then the initial currResult performed by default before the switch
                        statement needs to be re-calculated with eta reduction enabled.
                        Eta reductions happen relatively infrequently, so not too expensive to re-compute.
                        Can then check correctness using beta reduction method, but with eta results instead.
                        */
                        Debug("ETA");
                        Options.getEtaReductionsOption().setValue(true);
                        Debug(Options.getEtaReductionsOption().getValue());
                        currResult = stream.runExpr(prev.getExpression());
                        Options.getEtaReductionsOption().setValue(false);
                        Debug("currResult: " + currResult);

                        prevReducedExpr = currResult.get(1);
                        prevLastExpr = currResult.get(currResult.size()-1);
                        Debug("prev last reduced form: " + prevLastExpr);
                        Debug("current last reduced form: " + currLastExpr);

                        markAwarded = doBetaReduction(prevLastExpr, currLastExpr, prevReducedExpr, currReducedExpr, curr);

                        if(currResult.size()>2)
                            currResult.set(1,currResult.get(2)); //move an element up the list to compensate for the prev expression used to recalculate currResult

                        break;
                    case '>':
                    case '→':
                    case '=':
                        /*** CONVERSION or ARITHMETIC ***/
                        /*
                        "divergent" should be stated using conversion
                        if a student has a line the same as the previous, perhaps due to duplication
                        or changing of brackets. As long as semantics of expression is the same,
                        don't penalise but no marks are awarded
                        */
                        Debug("CONVERSION");
                        Debug("prevReducedExpr: " + prevReducedExpr);
                        Debug("currReducedExpr: " + currReducedExpr);
                        if(curr.getExpression().equalsIgnoreCase("divergent")){
                            String lastOriginal = originalResult.get(originalResult.size()-1).toString();
                            String secondLastOriginal = originalResult.get(originalResult.size()-2).toString();
                            if(lastOriginal.equals(secondLastOriginal)){
                                Debug("award mark");
                                curr.setMark(1);
                                markAwarded=true;
                            }
                        }
                        //user may have changed brackets, as long as still same semantic expression, fine
                        else if(prevReducedExpr.toString().equals(currReducedExpr.toString()) ){
                            markAwarded=true;
                            if(curr.getReduction()=='='){
                                curr.setMark(1);
                            }else{
                                //mark isn't actually awarded, just not penalised
                                Debug("no mark penalty");
                            }
                        }
                        else{
                            //mark isn't actually awarded, just not penalised
                            markAwarded = true;
                        }
                        break;
                    default:
                        break;
                }

                /*** REASONING ***/
                //common processing for reasoning
                Debug("-------REASONING-------");
                //check change of symbols correct
                String reasoning = curr.getReasoning();
                int splitIndex = reasoning.indexOf("/");
                if(splitIndex<0){
                    if(curr.getReduction()=='n'||curr.getReduction()=='η'){
                        Debug("award mark for reasoning");
                        curr.addMark(1);
                    }else{
                        System.out.println("no split in reasoning");
                    }
                }else{
                    String replacement = reasoning.substring(0,splitIndex);
                    String target = reasoning.substring(splitIndex+1);
                    String prevStr = "";//prev.getExpression();
                    try {
                        prevStr = Parser.parse(prev.getExpression()).toString();
                    } catch (Parser.ParseException pe) {
                        System.out.println(pe.getMessage());
                        break;
                    }
                    String currStr = currReducedExpr.toString();
                    Debug("prevStr: " + prevStr);
                    Debug("currStr: " + currStr);
                    String newStr = "";
                    Debug("target: " + target);
                    Debug("replacement: " + replacement);

                    //reduction specific processing for reasoning marks
                    switch(curr.getReduction()){
                        case 'a':
                        case 'α':
                        case '>':
                        case '→':
                        case '=':
                            if(curr.getReduction()=='a'||curr.getReduction()=='α')
                                Debug("ALPHA");
                            else
                                Debug("CONVERSION");
                            Debug("prevStr: " + prevStr);
                            //there can be multiple alpha conversions done in a step, separated by a comma (',')
                            //alpha conversions are described similarly to beta reductions:
                            //g/h means g replaces h, where h is a lambda expression
                            String [] alphaChanges = reasoning.split(",");
                            String [] targets = new String[alphaChanges.length];
                            String [] replacements = new String[alphaChanges.length];
                            for(int i=0;i<alphaChanges.length;i++){
                                splitIndex = alphaChanges[i].indexOf("/");
                                if(splitIndex<0){
                                    System.out.println("no split in reasoning");
                                }else{
                                    replacements[i] = alphaChanges[i].substring(0,splitIndex);
                                    targets[i] = alphaChanges[i].substring(splitIndex+1);
                                }
                            }
                            //the calculator automatically alpha-converts
                            //but separate expressions may have the same iX value
                            //changing these to a unique number helps with application
                            //of reasoning marking
                            int countUniqueAlphas = countAlpha(prevStr);
                            String compareStr = currStr;
                            Debug("countUniqueAlphas+1: " + (countUniqueAlphas+1) + " targets.length: " + targets.length);
                            Debug("currStr: " + currStr);
                            for(int i=0;i<alphaChanges.length;i++){
                                //for each unique iX
                                compareStr = compareStr.replace(replacements[i],targets[i]);
                                Debug("replacements[i]: " + replacements[i] + " targets[i]: " + targets[i]);
                            }

                            //count # in prev.getExpression and compareStr
                            //compareStr is currStr with each replacement replaced by it's corresponding target
                            int countTargetBefore = 0;
                            int countTargetAfter = 0;
                            int targetIndex = 0;
                            boolean [] replacementCorrect = new boolean[alphaChanges.length];
                            String prevExprStr = prev.getExpression();

                            Debug("prevExprStr: " + prevExprStr);
                            Debug("compareStr: " + compareStr);
                            for(int i=0;i<alphaChanges.length;i++){
                                countTargetBefore = 0;
                                countTargetAfter = 0;
                                targetIndex = 0;
                                Debug("targets[i]: " + targets[i]);

                                while(targetIndex>-1){
                                    targetIndex = prevExprStr.indexOf(targets[i],targetIndex+1);
                                    if(targetIndex>-1)
                                        countTargetBefore += 1;
                                    else
                                        break;
                                }
                                targetIndex = 0;

                                while(targetIndex>-1){
                                    targetIndex = compareStr.indexOf(targets[i],targetIndex+1);
                                    if(targetIndex>-1)
                                        countTargetAfter += 1;
                                    else
                                        break;
                                }
                                Debug("countTargetBefore: " + countTargetBefore);
                                Debug("countTargetAfter: " + countTargetAfter);
                                if(countTargetBefore==countTargetAfter){
                                    //if currStr correctly converted back to prev.getExpression() (from compareStr to prevExprStr)
                                    //using replace method then number of targets will be the same
                                    replacementCorrect[i] = true;
                                    Debug("replacementCorrect: " + replacementCorrect[i]);
                                    Debug("award half mark for reasoning (correctly replaced)");
                                    if(curr.getReduction()=='>'||curr.getReduction()=='→'){
                                        Debug("CONVERSION correct");//no marks for conversion
                                    }else if(curr.getReduction()=='='){
                                        curr.addMark(0.5);
                                        Debug("EQUALS correct");
                                    }else
                                        curr.addMark(0.5);
                                }
                            }

                            Debug("compareStr before parse: " + compareStr);
                            try {
                                compareStr = Parser.parse(compareStr).toString();
                            } catch (Parser.ParseException pe) {
                                System.out.println(pe.getMessage());
                            }

                            //parsing automatically does alpha conversion where necessary
                            //thus compareStr will be the same after parsing as prevStr
                            //if alpha converted correctly
                            Debug("compareStr: " + compareStr);

                            if(compareStr.equals(prevStr)){
                                Debug("award half mark(s) for reasoning (compareStr.equals(prevStr)): ");
                                Debug("alphaChanges.length/2: " + alphaChanges.length/2.0);
                                if(curr.getReduction()=='>'||curr.getReduction()=='→'){
                                    Debug("CONVERSION correct");//no marks for conversion
                                }else if(curr.getReduction()=='='){
                                    curr.addMark(alphaChanges.length/2.0);
                                    Debug("EQUALS correct");
                                }
                                else{
                                    curr.addMark(alphaChanges.length/2.0);
                                }
                            }else if(curr.getReduction()=='>'||curr.getReduction()=='→'){
                                    //could be converting, in which case should equal currStr not prevStr
                                    if(compareStr.equals(currStr)){
                                        Debug("CONVERSION correct");//no marks for conversion
                                    }
                            }

                            if(curr.getMark()==1&&curr.getReduction()=='='){
                                //mark not awarded for reasoning, but still correct line, have an extra check just for '=' (arithmetic)
                                int tarInd = prevStr.indexOf(target);
                                compareStr = prevStr.substring(0,tarInd) + replacement + prevStr.substring(tarInd+target.length());
                                Debug("last chance for compareStr: " + compareStr);
                                if(compareStr.equals(currStr)){
                                    curr.addMark(1);
                                    Debug("EQUALS correct");
                                }
                            }

                            break;
                        case 'b':
                        case 'B':
                        case 'β':
                            Debug("BETA");
                            if(replacement.contains("\\")||replacement.contains("λ")){
                                if(replacement.charAt(0)!='('||replacement.charAt(replacement.length()-1)!=')'){
                                    Debug("lambda expression, but not with parentheses");
                                    replacement = "(" + replacement + ")";//add brackets
                                    //break;
                                }
                            }
                            int pNum = 1;
                            int indexTarget = prevStr.indexOf("\\"+target);//find bound var if Normal
                            if(require.equals("Applicative")){
                                //indexTarget = prevStr.lastIndexOf("\\"+target);
                                //works better without
                            }
                            int numIReplace = 1;
                            String tempPrevStr = prevStr;
                            if(indexTarget<0&&tempPrevStr.contains("i0")){
                                //if target is the same as replacement, calculator may have alpha converted (unnecssarily perhaps)
                                tempPrevStr = tempPrevStr.replace("i0",target);
                                indexTarget = tempPrevStr.indexOf("\\"+target);//find bound var if Normal
                                while(tempPrevStr.contains("i"+numIReplace)){
                                    tempPrevStr=tempPrevStr.replace("i"+numIReplace,"i"+(numIReplace-1));
                                    numIReplace+=1;
                                }
                            }
                            Debug("prevStr: " + prevStr);
                            Debug("tempPrevStr: " + tempPrevStr);
                            prevStr = tempPrevStr;
                            int initialIndex = indexTarget;
                            Debug("indexTarget: " + indexTarget);
                            char cP = '?';
                            if(indexTarget>=0){
                                int p=indexTarget;
                                cP = prevStr.charAt(p-1);
                                if(cP=='('){
                                    newStr = prevStr.substring(0,indexTarget-1);
                                }else{
                                    newStr = prevStr.substring(0,indexTarget);
                                }
                                p=p+target.length()+2; //move to past '.' of lambda expression
                                Debug("newStr from prevStr: " + newStr);
                                Debug("p: " + p + " prevStr.length(): " + prevStr.length());
                                while(pNum>0){
                                    cP = prevStr.charAt(p);
                                    //Debug("cP: "+cP);
                                    if(prevStr.length()>=p+target.length()&&prevStr.substring(p,p+target.length()).equals(target)){
                                        newStr=newStr+replacement;
                                    }else if(newStr.equals(currStr)){
                                        break;
                                    }else if(cP == '('){
                                        pNum+=1;
                                        newStr=newStr+cP;
                                    }else if(cP == ')'){
                                        pNum-=1;
                                        if(pNum<1)
                                            break;
                                        newStr=newStr+cP;
                                    }else{
                                        newStr=newStr+cP;
                                    }
                                    p+=1;
                             //       Debug(newStr);
                                }
                                Debug("newStr: " + newStr);

                                if(currStr.charAt(0)=='(')
                                    newStr = "(" + newStr + ")";//add parentheses for separation and maintenance of logic

                                //based on number of parenthese, may need to include more at end of newStr before adding remaining
                                int cntP = 0;
                                for(int i=0;i<newStr.length();i++){
                                    if(newStr.charAt(i)=='(')
                                        cntP+=1;
                                    else if(newStr.charAt(i)==')')
                                        cntP-=1;
                                }
                                for(int i=1;i<cntP;i++)
                                    newStr= newStr+")";

                                Debug(prevStr.length() + " >? " + (p+3+replacement.length()));
                                if(prevStr.length()>(p+3+replacement.length())){
                                    newStr = newStr + " " + prevStr.substring(p+3+replacement.length());//3: 1 for parenthesis, 1 for space, 1 for last p not added
                                }
                            }

                            Debug("newStr: " + newStr + " length: " + newStr.length());
                            String newStrParsed = null;
                            while(newStrParsed==null&&newStr.length()>1){
                                try {
                                    newStrParsed = Parser.parse(newStr).toString();
                                } catch (Parser.ParseException pe) {
                                    Debug("ParseException: " + pe.getMessage());
                                    if(pe.getMessage().equals("Right parenthesis missing")){
                                        //
                                        if(tempPrevStr.charAt(tempPrevStr.length()-1) == ')')
                                            newStr = newStr+")";
                                        else
                                            newStr = newStr.substring(0,initialIndex-2) + newStr.substring(initialIndex-1);
                                            //for that rare occasion where this is better based on end of String before processing
                                            //occurs in:
                                            //a b ((λc.c) d) e
                                            //  = a b d e
                                            //but automarker here detects as
                                            //    a b (d e),
                                        Debug("newStr: " + newStr);
                                    }else if(newStr.charAt(newStr.length()-1)==')'){
                                        newStr = newStr.substring(0,newStr.length()-2);
                                    }
                                    else{
                                        newStrParsed="";
                                    }
                                }
                            }

                            Debug("newStrParsed: " + newStrParsed);
                            if(newStr.equals(currStr)||(newStrParsed!=null && newStrParsed.equals(currStr))){
                                Debug("award mark for reasoning");
                                curr.addMark(1);
                            }
                            break;
                        case 'n':
                        case 'η':
                            Debug("ETA");
                            Debug("award mark for reasoning");
                            if(curr.getMark()==1)   //eta reduction correctly done already, award for reasoning
                                curr.addMark(1);
                            break;
                        //case '>':
                        //case '→':
                        //    Debug("CONVERSION");

                        //    break;
                        default:
                            break;
                    }
                }
                if(!markAwarded){
                        //&& (curr.getReduction()=='B'||curr.getReduction()=='b'||curr.getReduction()=='β')){
                    markPenalty+=1;
                }
                Debug("line mark: " + curr.getMark());
                prev = curr;

            }
            sol.setMark(markPenalty);

            Debug("------------------------------\n" + sol + "\n\n---------------------------------------------------------------------------");
        }
        return solutions;
    }

    /***
     * countAlpha takes a string and counts the number of unique iX's where X = {INTEGER}.
     * It is important for an 'i' to be followed by a number (as the calculator does when alpha reducing/converting).
     * Thus no 'i' should be used in a typical student's answer.
     *
     * @param alpha
     * @return number of unique 'i's
     */
    public int countAlpha(String alpha){
        int countI = -1;
        int iNum=-1;
        for(int i = 0;i<alpha.length();i++){
            char c = alpha.charAt(i);
            if(c=='i'){
                iNum = Character.getNumericValue(alpha.charAt(i+1));
                if(iNum>countI){
                    countI+=1;
                }
            }
        }
        return countI;
    }

    /***
     * countI takes a string and counts the total number of iX's where X = {INTEGER}.
     * This includes bound variables (as opposed to countAlpha)
     *
     * @param alpha
     * @return
     */
    public int countI(String alpha){
        int counter = 0;
        for( int i=0; i<alpha.length(); i++ ) {
            if(alpha.charAt(i) == 'i' ) {
                counter++;
            }
        }
        return counter;
    }
    /***
     * doBetaReduction compares prevLastExpr to currLastExpr, then prevReducedExpr to currReducedExpr. If they are equal, a mark is assigned to curr
     * the last expressions are compared to ensure both expressions distill to the same final form (semantically the same)
     * the reduced expression from the previous calculation is compared to the reduced expression of the student's current line
     *
     * @param prevLastExpr
     * @param currLastExpr
     * @param prevReducedExpr
     * @param currReducedExpr
     * @param curr
     * @return true if the mark was awarded, false otherwise
     */
    private boolean doBetaReduction(Expr prevLastExpr, Expr currLastExpr, Expr prevReducedExpr, Expr currReducedExpr, Line curr){
        if(prevLastExpr.toString().equals(currLastExpr.toString())){
            //reduced to same form
            Debug("equal");
            Debug("prev reduced form: " + prevReducedExpr);
            Debug("curr reduced form: " + currReducedExpr);

            if(currReducedExpr!=null && prevReducedExpr.toString().equals(currReducedExpr.toString())){
                //same next line
                Debug("award mark");
                curr.setMark(1);
                return true;

            }
        }else if(finalResultsList.contains(currLastExpr.toString())){
            //finalResultsList contain the final exprs derived from the original question at each step of the reduction
            //thus, if there was a possible problem with the question in the calculator, this can help address it
            Debug("finalResultsList.contains(currReducedExpr.toString())");
            //reduced to same form
            Debug("equal");
            Debug("prev reduced form: " + prevReducedExpr);
            Debug("curr reduced form: " + currReducedExpr);

            if(currReducedExpr!=null && prevReducedExpr.toString().equals(currReducedExpr.toString())){
                //same next line
                Debug("award mark");
                curr.setMark(1);
                return true;

            }
        }
        return false;
    }

    private void createReport()
    {
            try{
                writer = new BufferedWriter(new FileWriter(new File("Report"+student.getStudentNum()+".txt"), false));	//new writer
                writer.write(student.getSummaryReport().toString());
                writer.close();
            } catch (Exception ex) {
            System.err.print("ReadError: " + ex.toString());
            }
    }

}