小编Ish*_*rav的帖子

使用Set <String>和String作为参数创建自定义谓词

我有一个String"ishant"和一个Set<String>["Ishant","Gaurav","sdnj"].我需要为此编写谓词.我尝试过如下代码,但它无法正常工作

Predicate<Set<String>,String> checkIfCurrencyPresent = (currencyList,currency) -> currencyList.contains(currency);
Run Code Online (Sandbox Code Playgroud)

如何创建一个Predicate将采取Set<String>String作为参数,并可以给结果呢?

java predicate java-8 functional-interface

9
推荐指数
2
解决办法
209
查看次数

如何提高海量数据的prime ng下拉性能

我在我们的 angular 项目中使用了primeng 多选下拉菜单。但是我们需要加载的数据非常庞大,比如 4-5K 个元素。所以我的下拉菜单在加载过程中需要 10 秒。

请建议我提高性能以创建多选下拉列表的方法。

javascript primeng angular

7
推荐指数
1
解决办法
3848
查看次数

类型错误:无法读取 null 的属性“焦点”

我有一个 React 组件,如下所示。当我执行以下组件的测试用例时,我收到以下错误,尽管在浏览器上我看到元素已生成并且编译中没有错误。

错误 :

类型错误:无法读取 null 的属性“焦点”

  at Check.componentDidMount (src/components/Payments/Check.js:42:42)
  at node_modules/react-test-renderer/lib/ReactCompositeComponent.js:262:25
  at measureLifeCyclePerf (node_modules/react-test-renderer/lib/ReactCompositeComponent.js:73:12)
  at node_modules/react-test-renderer/lib/ReactCompositeComponent.js:261:11
  at CallbackQueue.notifyAll (node_modules/react-test-renderer/lib/CallbackQueue.js:74:22)
  at ReactTestReconcileTransaction.close (node_modules/react-test-renderer/lib/ReactTestReconcileTransaction.js:34:26)
  at ReactTestReconcileTransaction.closeAll (node_modules/react-test-renderer/lib/Transaction.js:207:25)
  at ReactTestReconcileTransaction.perform (node_modules/react-test-renderer/lib/Transaction.js:154:16)
  at batchedMountComponentIntoNode (node_modules/react-test-renderer/lib/ReactTestMount.js:67:27)
  at ReactDefaultBatchingStrategyTransaction.perform (node_modules/react-test-renderer/lib/Transaction.js:141:20)
  at Object.batchedUpdates (node_modules/react-test-renderer/lib/ReactDefaultBatchingStrategy.js:60:26)
Run Code Online (Sandbox Code Playgroud)

检查.js

export default class Check extends Component {
  static displayName = 'Check';

  static propTypes = {
    check: PropTypes.object,
    translate: PropTypes.func.isRequired,
    countries: PropTypes.object,
    states: PropTypes.object,
    setCheckState: PropTypes.func.isRequired
  };

  onChange = (fieldName, newValue) => {
    let sanitizedFieldName = fieldName.replace('selected', '');
    sanitizedFieldName = sanitizedFieldName.charAt(0).toLowerCase() …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

6
推荐指数
1
解决办法
2万
查看次数

将循环转换为lambda并抛出异常

如何在java8中使用lambda表达式编写下面的代码.我是Java 8的新手.

for (GlobalPricingRequest globalPricingRequest : globalPricingRequests) {
    BigDecimal feePerTrans = globalPricingRequest.getFeePerTransact();
    if (feePerTrans != null && feePerTrans.intValue() < 0) {
        throw ExceptionHelper.badRequest("Fee Per Transaction can't be less than zero");
    }
    List<EventTypePricingMapping> eventTypePricingMappings = globalPricingRequest.getEventTypePricingList();
    for (EventTypePricingMapping eventTypePricingMapping : eventTypePricingMappings) {
        BigDecimal feePerRevenue = eventTypePricingMapping.getFeePerRevenue();
        if (feePerRevenue != null && feePerRevenue.intValue() < 0) {
            throw ExceptionHelper.badRequest("Fee Per Transaction can't be less than zero");
        }
        if (eventTypePricingMapping.getFeePerRevenue().intValue() < 0) {
            throw ExceptionHelper.badRequest("Fee Per Transaction can't be less than zero");
        }
    } …
Run Code Online (Sandbox Code Playgroud)

java lambda java-8 java-stream

5
推荐指数
1
解决办法
135
查看次数

查找日期列时间戳 = 00:00:00.000 的所有行

我有一个表,其中一列作为注册日期,其类型为日期时间。我需要找到所有将 registrationDate 作为时间戳记为 00:00:00.000 的行。例如 :

registrationDate: '2019-03-20 00:00:00.000'
Run Code Online (Sandbox Code Playgroud)

我需要查询类似于下面的内容:

select * from table where registrationDate like '%00:00:00.000';
Run Code Online (Sandbox Code Playgroud)

sql t-sql sql-server datetime date

4
推荐指数
1
解决办法
2293
查看次数

自定义谓词链接

我正在学习Java 8.我正在尝试创建自定义Predicate链接方法,如下所示

@FunctionalInterface
public interface Predicate<T> {

    boolean test(T t);

    default Predicate<T> and(Predicate<T> other){
        return t -> this.test(t) && other.test(t);
    }
}
Run Code Online (Sandbox Code Playgroud)

当我如上所述定义我的谓词时它可以工作,但是如果我尝试实现与下面相同的它,它会给我StackOverflow异常

@FunctionalInterface
public interface Predicate<T> {

    boolean test(T t);

    default Predicate<T> and(Predicate<T> other){
        //return t -> this.test(t) && other.test(t);
        return new Predicate<T>() {
            @Override
            public boolean test(T t) {
                return test(t) && other.test(t);
            }
        };
    }
}
Run Code Online (Sandbox Code Playgroud)

你能解释一下为什么它给了我Java 7风格的stackoverflow异常,而如果我使用lambda定义它,不要给出任何异常.

java java-8

3
推荐指数
1
解决办法
116
查看次数

在反应中需要将注意力集中在 div 上

我有一个早先被包裹在 H1 标签中的文本。加载页面后,我需要专注于该文本。为了方便起见,我将它包装在一个 div 中。

render() {
    const { translate, billing: { primaryContactSelection = true } } = this.props;
    return (
      <div {...resolve(BillingStyles, 'billingContainer')}>
        <div id="mainHeader"><h1 {...resolve(BillingStyles, 'mainHeader')}>
          {translate('PanelBillingHeadingText')}
        </h1> </div>
        <div {...resolve(BillingStyles, 'billingInfoContainer')}>
         ......
         ......
        </div>
      </div>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

我试过下面的代码:

componentDidMount() {
    console.log('Component Did Mount .............');
    document.getElementById('#mainHeader').focus();
  }
Run Code Online (Sandbox Code Playgroud)

但它并不专注于 div。

javascript reactjs

3
推荐指数
1
解决办法
5690
查看次数

如果使用枚举,如何过多清除代码

我有以下代码要编写。它采用一种枚举类型并返回其他枚举值。如何删除代码中太多(如果没有)条件并使其干净?

private static QuestionType parseQuestionType(QuestionTypeInfo questionTypeInfo) {
        if (questionTypeInfo instanceof OpenEndedTextQuestionTypeInfo) {
            return QuestionType.OPEN_ENDED;
        } else if (questionTypeInfo instanceof MultiChoiceQuestionTypeInfo) {
            return QuestionType.MULTI_CHOICE;
        } else if (questionTypeInfo instanceof MatrixSinglePerRowQuestionTypeInfo) {
            return QuestionType.MATRIX_SINGLE_PER_ROW;
        } else if (questionTypeInfo instanceof OpenEndedTextQuestionTypeInfo) {
            return QuestionType.OPEN_ENDED;
        } else if (questionTypeInfo instanceof MatrixMultiPerRowQuestionTypeInfo) {
            return QuestionType.MATRIX_MULTI_PER_ROW;
        } else if (questionTypeInfo instanceof MatrixSideBySideQuestionTypeInfo) {
            return QuestionType.MATRIX_SIDE_BY_SIDE;
        } else if (questionTypeInfo instanceof MatrixSpreadSheetQuestionTypeInfo) {
            return QuestionType.MATRIX_SPREAD_SHEET;
        } else if (questionTypeInfo instanceof DataListQuestionTypeInfo) {
            return QuestionType.DATA_LIST;
        } else if …
Run Code Online (Sandbox Code Playgroud)

java code-cleanup java-8

3
推荐指数
1
解决办法
132
查看次数