<commit_before>/*
 *  jETeL/Clover - Java based ETL application framework.
 *  Copyright (C) 2002  <NAME>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package org.jetel.component;

import java.io.*;
import java.nio.ByteBuffer;
import java.nio.BufferOverflowException;
import org.jetel.graph.*;
import org.jetel.data.DataRecord;
import org.jetel.data.SortDataRecordInternalNew;
import org.jetel.data.SortDataRecordInternal;
import org.jetel.data.Defaults;
import org.jetel.exception.ComponentNotReadyException;
import org.jetel.util.ComponentXMLAttributes;
/**
 *  <h3>Sort Component</h3>
 *
 * <!-- Sorts the incoming records based on specified key -->
 *
 * <table border="1">
 *  <th>Component:</th>
 * <tr><td><h4><i>Name:</i></h4></td>
 * <td>Sort</td></tr>
 * <tr><td><h4><i>Category:</i></h4></td>
 * <td></td></tr>
 * <tr><td><h4><i>Description:</i></h4></td>
 * <td>Sorts the incoming records based on specified key.<br>
 *  The key is name (or combination of names) of field(s) from input record.
 *  The sort order is either Ascending (default) or Descending.</td></tr>
 * <tr><td><h4><i>Inputs:</i></h4></td>
 * <td>[0]- input records</td></tr>
 * <tr><td><h4><i>Outputs:</i></h4></td>
 * <td>At least one connected output port.</td></tr>
 * <tr><td><h4><i>Comment:</i></h4></td>
 * <td></td></tr>
 * </table>
 *  <br>
 *  <table border="1">
 *  <th>XML attributes:</th>
 *  <tr><td><b>type</b></td><td>"SORT"</td></tr>
 *  <tr><td><b>id</b></td><td>component identification</td>
 *  <tr><td><b>sortKey</b></td><td>field names separated by :;|  {colon, semicolon, pipe}</td>
 *  <tr><td><b>sortOrder</b><br><i>optional</i></td><td>one of "Ascending|Descending" {the fist letter is sufficient, if not defined, then Ascending}</td>
 *  </tr>
 *  </table>
 *
 *  <h4>Example:</h4>
 *  <pre>&lt;Node id="SORT_CUSTOMER" type="SORT" sortKey="Name:Address" sortOrder="A"/&gt;</pre>
 *
 * @author      dpavlis
 * @since       April 4, 2002
 * @revision    $Revision$
 */
public class Sort extends Node {

	/**  Description of the Field */
	public final static String COMPONENT_TYPE = "SORT";

	private final static int WRITE_TO_PORT = 0;
	private final static int READ_FROM_PORT = 0;

	private SortDataRecordInternalNew newSorter;
	private SortDataRecordInternal sorter;
	private boolean sortOrderAscending;
	private String[] sortKeys;
	private ByteBuffer recordBuffer;
	private boolean lexicalSort;


	/**
	 *Constructor for the Sort object
	 *
	 * @param  id         Description of the Parameter
	 * @param  sortKeys   Description of the Parameter
	 * @param  sortOrder  Description of the Parameter
	 */
	public Sort(String id, String[] sortKeys, boolean sortOrder) {
		super(id);
		this.sortOrderAscending = sortOrder;
		this.sortKeys = sortKeys;
		this.lexicalSort=false;
	}


	/**
	 *Constructor for the Sort object
	 *
	 * @param  id        Description of the Parameter
	 * @param  sortKeys  Description of the Parameter
	 */
	public Sort(String id, String[] sortKeys) {
		super(id);
		this.sortOrderAscending = true;// default ascending
		this.sortKeys = sortKeys;
		this.lexicalSort=false;
	}


	/**
	 *  Main processing method for the SimpleCopy object
	 *
	 * @since    April 4, 2002
	 */
	public void run() {
		InputPort inPort = getInputPort(READ_FROM_PORT);
		DataRecord inRecord = new DataRecord(inPort.getMetadata());
		inRecord.init();
		//InputPortDirect inPort = (InputPortDirect) getInputPort(READ_FROM_PORT);
		boolean isData = true;
		
		while (inRecord!=null && runIt) {
			try {
				recordBuffer.clear();
				inRecord = inPort.readRecord(inRecord);// readRecord(READ_FROM_PORT,inRecord);
				if (inRecord!=null) {
					if (lexicalSort)
						sorter.put(inRecord);
					else
						newSorter.put(inRecord);
				}
			} catch (BufferOverflowException ex) {<commit_msg>cleaned run() method<commit_after>/*
 *  jETeL/Clover - Java based ETL application framework.
 *  Copyright (C) 2002  <NAME>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package org.jetel.component;

import java.io.*;
import java.nio.ByteBuffer;
import java.nio.BufferOverflowException;
import org.jetel.graph.*;
import org.jetel.data.DataRecord;
import org.jetel.data.SortDataRecordInternalNew;
import org.jetel.data.SortDataRecordInternal;
import org.jetel.data.Defaults;
import org.jetel.exception.ComponentNotReadyException;
import org.jetel.util.ComponentXMLAttributes;
/**
 *  <h3>Sort Component</h3>
 *
 * <!-- Sorts the incoming records based on specified key -->
 *
 * <table border="1">
 *  <th>Component:</th>
 * <tr><td><h4><i>Name:</i></h4></td>
 * <td>Sort</td></tr>
 * <tr><td><h4><i>Category:</i></h4></td>
 * <td></td></tr>
 * <tr><td><h4><i>Description:</i></h4></td>
 * <td>Sorts the incoming records based on specified key.<br>
 *  The key is name (or combination of names) of field(s) from input record.
 *  The sort order is either Ascending (default) or Descending.</td></tr>
 * <tr><td><h4><i>Inputs:</i></h4></td>
 * <td>[0]- input records</td></tr>
 * <tr><td><h4><i>Outputs:</i></h4></td>
 * <td>At least one connected output port.</td></tr>
 * <tr><td><h4><i>Comment:</i></h4></td>
 * <td></td></tr>
 * </table>
 *  <br>
 *  <table border="1">
 *  <th>XML attributes:</th>
 *  <tr><td><b>type</b></td><td>"SORT"</td></tr>
 *  <tr><td><b>id</b></td><td>component identification</td>
 *  <tr><td><b>sortKey</b></td><td>field names separated by :;|  {colon, semicolon, pipe}</td>
 *  <tr><td><b>sortOrder</b><br><i>optional</i></td><td>one of "Ascending|Descending" {the fist letter is sufficient, if not defined, then Ascending}</td>
 *  </tr>
 *  </table>
 *
 *  <h4>Example:</h4>
 *  <pre>&lt;Node id="SORT_CUSTOMER" type="SORT" sortKey="Name:Address" sortOrder="A"/&gt;</pre>
 *
 * @author      dpavlis
 * @since       April 4, 2002
 * @revision    $Revision$
 */
public class Sort extends Node {

	/**  Description of the Field */
	public final static String COMPONENT_TYPE = "SORT";

	private final static int WRITE_TO_PORT = 0;
	private final static int READ_FROM_PORT = 0;

	private SortDataRecordInternalNew newSorter;
	private SortDataRecordInternal sorter;
	private boolean sortOrderAscending;
	private String[] sortKeys;
	private ByteBuffer recordBuffer;
	private boolean lexicalSort;


	/**
	 *Constructor for the Sort object
	 *
	 * @param  id         Description of the Parameter
	 * @param  sortKeys   Description of the Parameter
	 * @param  sortOrder  Description of the Parameter
	 */
	public Sort(String id, String[] sortKeys, boolean sortOrder) {
		super(id);
		this.sortOrderAscending = sortOrder;
		this.sortKeys = sortKeys;
		this.lexicalSort=false;
	}


	/**
	 *Constructor for the Sort object
	 *
	 * @param  id        Description of the Parameter
	 * @param  sortKeys  Description of the Parameter
	 */
	public Sort(String id, String[] sortKeys) {
		super(id);
		this.sortOrderAscending = true;// default ascending
		this.sortKeys = sortKeys;
		this.lexicalSort=false;
	}


	/**
	 *  Main processing method for the SimpleCopy object
	 *
	 * @since    April 4, 2002
	 */
	public void run() {
		InputPort inPort = getInputPort(READ_FROM_PORT);
		DataRecord inRecord = new DataRecord(inPort.getMetadata());
		inRecord.init();
		//InputPortDirect inPort = (InputPortDirect) getInputPort(READ_FROM_PORT);
		boolean isData = true;
		
		while (inRecord!=null && runIt) {
			try {
				inRecord = inPort.readRecord(inRecord);// readRecord(READ_FROM_PORT,inRecord);
				if (inRecord!=null) {
					if (lexicalSort)
						sorter.put(inRecord);
					else
						newSorter.put(inRecord);
				}
			} catch (BufferOverflowException ex) {
{'fraction_non_alphanumeric': 0.14447306529286594, 'fraction_numerical': 0.011199462425803561, 'mean_word_length': 3.9473684210526314, 'pattern_counts': {'":': 0, '<': 225, '<?xml version=': 0, '>': 225, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5038420', 'n_tokens_mistral': 3097, 'n_tokens_neox': 2871, 'n_words': 821}