I am trying to check if the user select (u.userId) is not in the column (urid) then only return true and run the other function. If the user selected data already exists, then return false. I get it with return void.. what happens? I'm still new in asp.net, hoping for some help. Thanks.
public string URID { get; set; }
public void urid_existence(User u)
{
DBHandler dbh = new DBHandler();
dbh.OpenConnection();
string sql = "select urid from FCS_COUGRP";
if (u.UserID != u.URID)
{
userH.changeUrserGroup(u);
return true;
}
else
{
return false;
}
}
void means that the method does not return anything, but you want to return a bool. So this is the correct signature:
public bool urid_existence(User u)
{
// ...
if (u.UserID != u.URID)
{
userH.changeUrserGroup(u);
return true;
}
else
{
return false;
}
}
Related
I have the following code :
RuleFor(record => record)
.Must(WholeObject => Mandatory(WholeObject, keyValuePairs))
.WithName( X => X.KeyName).WithMessage("KeyValue is mandatory but some values are missing")
//Here X.KeyValue contains the value.
//I want to pass this value on error
private bool Mandatory(Object recObj, Object keyValuePairs)
{
//return true or false depeneds on the logic
}
How do I pass the X.KeyValue in WithMessage?, If there is an error it returns .WithMessage("KeyValue is mandatory but some values are missing") but how do I pass the actual value ?
X contains X.KeyName and X.KeyValue
Note:
X.KeyValue is not a string.
public class KeyValue
{
public List<string> Val { get; set; }
}
RuleFor(record => record)
.Must(WholeObject => SizeOF(WholeObject, keyValuePairs))
.WithName(X => X.KeyName).WithMessage(x => $"{x.KeyValue.Val[0]} is not in range(min, max) as defined");
unfortunately this prints only the first value. Is it a way to include only the error value?
I used this
.WithName(X => X.KeyName).WithMessage(x => $"
{x.KeyValue.Val.ToList().ForEach(s => s)} is not in range(min, max) as
defined");
but this didnot work.
private bool SizeOF(Entity.EigenData.Record recObj, IDictionary<string, Entity.EigenSchema.AttributeSet> keyValuePairs)
{
string strval = recObj.KeyName;
Entity.EigenSchema.AttributeSet obj = keyValuePairs[recObj.KeyName];
//if the size falls inbetween min and max
return recObj.KeyValue.ISSizeWithinRange(obj);
//string val = obj.KeyValue.ToString();
}
public static bool ISSizeWithinRange(this Validation.Entity.EigenData.KeyValue kv, Validation.Entity.EigenSchema.AttributeSet Obj)
{
try
{
if (kv.Val.Count > 0) //only if List<val> is available go inside the loop
{
foreach (string s in kv.Val)
{
//foreach val check if its empty or null, if its empty or null then return false
bool True = String.IsNullOrEmpty(s);
if (True)
{
return true;
}
else
{
bool False = (Enumerable.Range(Obj.Size.Min, Obj.Size.Max).Contains(s.Length));
// if it contains within range then do nothing, return true at the end
//if it doesnot fall with in range then return false immediately. No need to check the entire set of values
if(!False)
{
return false;
}
}
}
//if it contains some value then return true
return true;
}
else
{
//List<val> count is zero
return false;
}
}
catch
{
return false;
}
}
Change your code like below:
RuleFor(record => record)
.Must(WholeObject => Mandatory(WholeObject,keyValuePairs))
.WithName(X => X.KeyName).WithMessage(x => $"{x.KeyName} is mandatory but some values are missing");
Whole code:
public class Status
{
public string Name { get; set; }
}
public class CustomValidator : AbstractValidator<Status>
{
public CustomValidator ()
{
RuleFor(record => record)
.Must(WholeObject => Mandatory(WholeObject,keyValuePairs))
.WithName(X => X.Name).WithMessage(x => $"{x.Name} is mandatory but some values are missing");
}
private bool Mandatory(Object recObj, Object keyValuePairs)
{
//return true or false depeneds on the logic
return false;
}
}
Checkbox function: Using below function, I want to select a checkbox and want to skip it if already selected. But isSelected() is not working, neither clear() nor isEnabled() is working.
Maybe this help you understand more: Besides 'requiredId', there is also a class that appears only when checkbox is selected say 'requireIdClassName').
requiredId="checkbox_id";
public void clickRequiredId() {
if (helper.isElementPresent(helper.locateById(requiredId)) == true) {
if (!helper.findElementById(requiredId).isSelected()) {
helper.findElementById(requiredId).click();
}
}
}
isElementPresent:
public boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
locateById:
public By locateById(String element) {
return By.id(element);
}
findElementById:
public WebElement findElementById(String element) {
waitForElement(locateById(element), 10, element);
return driver.findElement(By.id(element));
}
getAttribute methods returns the attribute value or null if it isn't set. You can use it to determine if requireIdClassName appeared
public void clickRequiredId() {
if (helper.isElementPresent(helper.locateById(requiredId)) == true) {
if (helper.findElementById(requiredId).getAttribute("class") == null) {
helper.findElementById(requiredId).click();
}
}
}
Try this :
WebElement checkBox = driver.findElement(By.id("requiredId"));
boolean checkedState = checkBox.getAttribute("checked") != null;
if (desiredCheckState != checkedState) {
checkBox.click();
}
I've added an index to a cache. The index uses a custom extractor that extends AbstractExtractor and overrides only the extract method to return a List of Strings. Then I have a ContainsFilter which uses the same custom extractor that looks for the occurence of a single String in the List of Strings. It does not look like my index is being used based on the time it takes to execute my test. What am I doing wrong? Also, is there some debugging I can switch on to see which indices are used?
public class DependencyIdExtractor extends AbstractExtractor {
/**
*
*/
private static final long serialVersionUID = 1L;
#Override
public Object extract(Object oTarget) {
if (oTarget == null) {
return null;
}
if (oTarget instanceof CacheValue) {
CacheValue cacheValue = (CacheValue)oTarget;
// returns a List of String objects
return cacheValue.getDependencyIds();
}
throw new UnsupportedOperationException();
}
}
Adding the index:
mCache = CacheFactory.getCache(pCacheName);
mCache.addIndex(new DependencyIdExtractor(), false, null);
Performing the ContainsFilter query:
public void invalidateByDependencyId(String pDependencyId) {
ContainsFilter vContainsFilter = new ContainsFilter(new DependencyIdExtractor(), pDependencyId);
#SuppressWarnings("rawtypes")
Set setKeys = mCache.keySet(vContainsFilter);
mCache.keySet().removeAll(setKeys);
}
I solved this by adding a hashCode and equals method implementation to the DependencyIdExtractor class. It is important that you use exactly the same value extractor when adding an index and creating your filter.
public class DependencyIdExtractor extends AbstractExtractor {
/**
*
*/
private static final long serialVersionUID = 1L;
#Override
public Object extract(Object oTarget) {
if (oTarget == null) {
return null;
}
if (oTarget instanceof CacheValue) {
CacheValue cacheValue = (CacheValue)oTarget;
return cacheValue.getDependencyIds();
}
throw new UnsupportedOperationException();
}
#Override
public int hashCode() {
return 1;
}
#Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj instanceof DependencyIdExtractor) {
return true;
}
return false;
}
}
To debug Coherence indices/queries, you can generate an explain plan similar to database query explain plans.
http://www.oracle.com/technetwork/tutorials/tutorial-1841899.html
#SuppressWarnings("unchecked")
public void invalidateByDependencyId(String pDependencyId) {
ContainsFilter vContainsFilter = new ContainsFilter(new DependencyIdExtractor(), pDependencyId);
if (mLog.isTraceEnabled()) {
QueryRecorder agent = new QueryRecorder(RecordType.EXPLAIN);
Object resultsExplain = mCache.aggregate(vContainsFilter, agent);
mLog.trace("resultsExplain = \n" + resultsExplain + "\n");
}
#SuppressWarnings("rawtypes")
Set setKeys = mCache.keySet(vContainsFilter);
mCache.keySet().removeAll(setKeys);
}
I have a function that creates regular Objects of a same type and I cannot avoid that step.
When I use List.addAll(*) I will get many "Duplications" that are not equal in sense of Objectivity.
I have a very bad coded solution and want to ask if there could be a better or more effective one maybe with Java-Util-functions and defining a Comparator for that single intermezzo?
Here is my bad smell:
private void addPartial(List<SeMo_WikiArticle> allnewWiki, List<SeMo_WikiArticle> newWiki) {
if(allnewWiki.isEmpty())
allnewWiki.addAll(newWiki);
else{
for(SeMo_WikiArticle nn : newWiki){
boolean allreadyIn = false;
for(SeMo_WikiArticle oo : allnewWiki){
if(nn.getID()==oo.getID())
allreadyIn= true;
}
if(!allreadyIn)
allnewWiki.add(nn);
}
}
}
Any Ideas?
Add an override function of equals() into class SeMo_WikiArticle :
class SeMo_WikiArticle {
// assuming this class has two properties below
int id;
String name;
SeMo_WikiArticle(int id, String name) {
this.id = id;
this.name = name;
}
#Override
public boolean equals(Object obj) {
// implement your own comparison policy
// here is an example
if (obj instanceof SeMo_WikiArticle) {
SeMo_WikiArticle sw = (SeMo_WikiArticle)obj;
if (this.id == sw.id && (this.name == sw.name || this.name.equals(sw.name))) {
return true;
}
}
return false;
}
}
After that you can use contains() to judge if the list has already contains the specific object of SeMo_WikiArticle.
Here is the code:
private void addPartial(List<SeMo_WikiArticle> allnewWiki, List<SeMo_WikiArticle> newWiki) {
for (SeMo_WikiArticle sw : newWiki) {
if (!allnewWiki.contains(sw)) {
allnewWiki.add(sw);
}
}
}
In the GenericUDAFCount.java:
#Description(name = "count",
value = "_FUNC_(*) - Returns the total number of retrieved rows, including "
+ "rows containing NULL values.\n"
+ "_FUNC_(expr) - Returns the number of rows for which the supplied "
+ "expression is non-NULL.\n"
+ "_FUNC_(DISTINCT expr[, expr...]) - Returns the number of rows for "
+ "which the supplied expression(s) are unique and non-NULL.")
but I don`t see any code to deal with the 'distinct' expression.
public static class GenericUDAFCountEvaluator extends GenericUDAFEvaluator {
private boolean countAllColumns = false;
private LongObjectInspector partialCountAggOI;
private LongWritable result;
#Override
public ObjectInspector init(Mode m, ObjectInspector[] parameters)
throws HiveException {
super.init(m, parameters);
partialCountAggOI =
PrimitiveObjectInspectorFactory.writableLongObjectInspector;
result = new LongWritable(0);
return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
}
private GenericUDAFCountEvaluator setCountAllColumns(boolean countAllCols) {
countAllColumns = countAllCols;
return this;
}
/** class for storing count value. */
static class CountAgg implements AggregationBuffer {
long value;
}
#Override
public AggregationBuffer getNewAggregationBuffer() throws HiveException {
CountAgg buffer = new CountAgg();
reset(buffer);
return buffer;
}
#Override
public void reset(AggregationBuffer agg) throws HiveException {
((CountAgg) agg).value = 0;
}
#Override
public void iterate(AggregationBuffer agg, Object[] parameters)
throws HiveException {
// parameters == null means the input table/split is empty
if (parameters == null) {
return;
}
if (countAllColumns) {
assert parameters.length == 0;
((CountAgg) agg).value++;
} else {
assert parameters.length > 0;
boolean countThisRow = true;
for (Object nextParam : parameters) {
if (nextParam == null) {
countThisRow = false;
break;
}
}
if (countThisRow) {
((CountAgg) agg).value++;
}
}
}
#Override
public void merge(AggregationBuffer agg, Object partial)
throws HiveException {
if (partial != null) {
long p = partialCountAggOI.get(partial);
((CountAgg) agg).value += p;
}
}
#Override
public Object terminate(AggregationBuffer agg) throws HiveException {
result.set(((CountAgg) agg).value);
return result;
}
#Override
public Object terminatePartial(AggregationBuffer agg) throws HiveException {
return terminate(agg);
}
}
How does hive achieve count(distinct ...)? When task runs, it really cost much time.
Where is it in the source code?
As you can just run SELECT DISTINCT column1 FROM table1, DISTINCT expression isn't a flag or option, it's evaluated independently
This page says:
The actual filtering of data bound to parameter types for DISTINCT
implementation is handled by the framework and not the COUNT UDAF
implementation.
If you want drill down to source details, have a look into hive git repository