Skip to content

added functions for Sequential Date Generator and Sequential String Generation from Array #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.oltpbenchmark.benchmarks.featurebench.utils;

import java.lang.reflect.InvocationTargetException;
import java.time.LocalDate;
import java.util.List;

public class CyclicSeqDateGen implements BaseUtil {

private final int yearLowerBound;
private final int yearUpperBound;
private LocalDate currentDate;


public CyclicSeqDateGen(List<Object> values) {
if (values.size() != 2) {
throw new RuntimeException("Incorrect number of parameters for util function "
+ this.getClass());
}
this.yearLowerBound = ((Number) values.get(0)).intValue();
this.yearUpperBound = ((Number) values.get(1)).intValue();
if (yearLowerBound > yearUpperBound) {
throw new RuntimeException("Please enter correct values for yearLowerBound and yearUpperBound");
}
this.currentDate = LocalDate.of(yearLowerBound, 1, 1).minusDays(1);
}

public CyclicSeqDateGen(List<Object> values,int workerId,int totalWorkers) {
if (values.size() != 2) {
throw new RuntimeException("Incorrect number of parameters for util function "
+ this.getClass());
}
this.yearLowerBound = ((Number) values.get(0)).intValue();
this.yearUpperBound = ((Number) values.get(1)).intValue();
if (yearLowerBound > yearUpperBound) {
throw new RuntimeException("Please enter correct values for yearLowerBound and yearUpperBound");
}
this.currentDate = LocalDate.of(yearLowerBound, 1, 1).minusDays(1);;
}

private LocalDate findNextHigherValue() {
return currentDate.plusDays(1);
}

@Override
public Object run() throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
currentDate=findNextHigherValue();
if(currentDate.getYear()>yearUpperBound)
{
currentDate=LocalDate.of(yearLowerBound, 1, 1);
}
return currentDate;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.oltpbenchmark.benchmarks.featurebench.utils;

import java.lang.reflect.InvocationTargetException;
import java.time.LocalDate;
import java.util.List;

public class CyclicSeqDateGenWithRep implements BaseUtil {

private final int yearLowerBound;
private final int yearUpperBound;
private final int maxDays;
private int dayCounter=0;
private LocalDate currentDate;


public CyclicSeqDateGenWithRep(List<Object> values) {
if (values.size() != 3) {
throw new RuntimeException("Incorrect number of parameters for util function "
+ this.getClass());
}
this.yearLowerBound = ((Number) values.get(0)).intValue();
this.yearUpperBound = ((Number) values.get(1)).intValue();
this.maxDays = ((Number) values.get(2)).intValue();
if (yearLowerBound > yearUpperBound) {
throw new RuntimeException("Please enter correct values for yearLowerBound and yearUpperBound");
}
this.currentDate = LocalDate.of(yearLowerBound, 1, 1).minusDays(1);
}

public CyclicSeqDateGenWithRep(List<Object> values,int workerId,int totalWorkers) {
if (values.size() != 3) {
throw new RuntimeException("Incorrect number of parameters for util function "
+ this.getClass());
}
this.yearLowerBound = ((Number) values.get(0)).intValue();
this.yearUpperBound = ((Number) values.get(1)).intValue();
this.maxDays = ((Number) values.get(2)).intValue();
if (yearLowerBound > yearUpperBound) {
throw new RuntimeException("Please enter correct values for yearLowerBound and yearUpperBound");
}
this.currentDate = LocalDate.of(yearLowerBound, 1, 1).minusDays(1);
}

private LocalDate findNextHigherValue() {
dayCounter++;
return currentDate.plusDays(1);
}

@Override
public Object run() throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
currentDate=findNextHigherValue();
if(currentDate.getYear()>yearUpperBound || dayCounter>maxDays)
{
currentDate=LocalDate.of(yearLowerBound, 1, 1);
if(dayCounter>maxDays)
dayCounter=1;
}
return currentDate;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.oltpbenchmark.benchmarks.featurebench.utils;

import java.lang.reflect.InvocationTargetException;
import java.util.*;

/*
Description :- Chooses a string randomly from an array of strings passed.
Params :
1.Array of Strings (values)
Eg:-
str :- ["abc","hty","iki","pou","qwe"]
Return type (String) :- "abc" OR "hty" OR "iki" OR "pou" OR "qwe" (randomly chosen).
*/


public class SeqStringGenFromArray implements BaseUtil {
private List<String> str;
private int c=-1;

public SeqStringGenFromArray(List<Object> values) {
if (values.size() == 0) {
throw new RuntimeException("Incorrect number of parameters for util function "
+ this.getClass());
}
str = new ArrayList<>();
for (Object value : values) {
str.add((String) value);
}
}
public SeqStringGenFromArray(List<Object> values,int workerId,int totalWorkers) {
if (values.size() == 0) {
throw new RuntimeException("Incorrect number of parameters for util function "
+ this.getClass());
}
str = new ArrayList<>();
for (Object value : values) {
str.add((String) value);
}
}

public Object run() throws ClassNotFoundException, InvocationTargetException,
NoSuchMethodException, InstantiationException, IllegalAccessException {
try {
c=(c+1)%str.size();
return str.get(c);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
}