📄 fetcher.java
字号:
/*
* Fetcher.java
*
* Created on 2007年11月8日, 上午1:57
*
*/
package myUtil;
import java.util.*;
/**
* cyclely get n elements form an array with specified size.
* @author yuhui_bear
*/
public class Fetcher {
private int[] source;
private int size;
private int ite =0;
private ArrayList<NumberBox> st ;
/**
* Creates a new instance of Fetcher
*/
public Fetcher(int n) {
size = n;
source = new int[n];
for (int i =0;i<size;i++){
source[i] =i;
}
st = new ArrayList();
for ( int i= 0 ; i< size;i++){
st.add(new NumberBox(i));
}
}
/**
* get one group from the source.
* @param n ,get n elements form the source.
* @return ,array of index.
*/
public int[] nextGroupCycl(int n){
int[] temp = new int[n];
if ( source.length <n){
int k = 0;
for (int i =0; i< n; i++){
if(k >= source.length){
k=0;
}
temp[i]=source[k++];
}
}else{
temp = cycleFetch(n ,source, ite);
}
ite++;
if(ite >=size)
ite=0;
return temp;
}
public int[] nextGroupCycl(int n ,int gap ){
int[] temp = new int[n];
if ( source.length <n){
int k = 0;
for (int i =0; i< n; i++){
if(k >= source.length){
k=0;
}
temp[i]=source[k++];
}
}else{
temp = cycleFetch(n ,source, ite);
}
ite +=gap;
if(ite >=size)
ite=0;
return temp;
}
public int[] nextGroup(int fetch ){
int length =source.length;
int[] temp =new int[fetch];
if ( length < fetch){
int k = 0;
for (int i =0; i< fetch; i++){
if(k >= length){
k=0;
}
temp[i]=source[k++];
}
}else{
if(ite + fetch-1 < length){
for ( int i = 0 ; i< fetch; i++){
temp[i] = source[length - fetch + i];
}
ite = 0;
}else{
for ( int i = 0 ; i < fetch ; i++){
temp[i] = source[ite + i];
}
if(ite >= source.length){
ite = 0;
}else{
ite += fetch;
}
}
}
return temp;
}
/**
* cyclely fetch FETCH values from Arraylist neurallist.
* @param fetch , number to fetch.
* @param list , source list.
* @param iterator , access iterator of neuron list.
* @return return fetch values .
*/
private int[] cycleFetch(int fetch ,int[] list ,int iterator){
int length =list.length;
int[] temp =new int[fetch];
if( iterator + fetch-1 < length){
for(int i =0;i<fetch;i++){
temp[i]= list[iterator + i];
}
}else{
for (int k=0;k< length -iterator;k++){
temp[k]= list[iterator + k];
}
for (int k=0;k<fetch-length+iterator;k++){
temp[k+length -iterator] =list[k];
}
}
return temp;
}
/**
* generate a group of length n from range from.
* @param n ,length of the choosing group.
* @return the new random group.
*/
public int[] nextRandGroup(int n ){
Random myrand = new Random();
int[] temp = new int[n];
int t=0;
for ( int k = 0 ; k < n; k++){
t= myrand.nextInt(st.size());
temp[k] =st.get(t).intData;
st.remove(t);
}
return temp;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -