Java Code Examples for org.apache.commons.collections4.ListUtils#emptyIfNull()

The following examples show how to use org.apache.commons.collections4.ListUtils#emptyIfNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimesheetServiceImpl.java    From axelor-open-suite with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
@Transactional
public void removeAfterToDateTimesheetLines(Timesheet timesheet) {

  List<TimesheetLine> removedTimesheetLines = new ArrayList<>();

  for (TimesheetLine timesheetLine : ListUtils.emptyIfNull(timesheet.getTimesheetLineList())) {
    if (timesheetLine.getDate().isAfter(timesheet.getToDate())) {
      removedTimesheetLines.add(timesheetLine);
      if (timesheetLine.getId() != null) {
        timesheetlineRepo.remove(timesheetLine);
      }
    }
  }
  timesheet.getTimesheetLineList().removeAll(removedTimesheetLines);
}
 
Example 2
Source File: PrivacyEnforcementService.java    From prebid-server-java with Apache License 2.0 6 votes vote down vote up
private Set<String> extractCcpaEnforcedBidders(List<String> bidders, BidRequest bidRequest, BidderAliases aliases) {
    final Set<String> ccpaEnforcedBidders = new HashSet<>(bidders);

    final ExtBidRequest extBidRequest = requestExt(bidRequest);
    final ExtRequestPrebid extRequestPrebid = extBidRequest != null ? extBidRequest.getPrebid() : null;
    final List<String> nosaleBidders = extRequestPrebid != null
            ? ListUtils.emptyIfNull(extRequestPrebid.getNosale())
            : Collections.emptyList();

    if (nosaleBidders.size() == 1 && nosaleBidders.contains(CATCH_ALL_BIDDERS)) {
        ccpaEnforcedBidders.clear();
    } else {
        ccpaEnforcedBidders.removeAll(nosaleBidders);
    }

    ccpaEnforcedBidders.removeIf(bidder ->
            !bidderCatalog.bidderInfoByName(aliases.resolveBidder(bidder)).isCcpaEnforced());

    return ccpaEnforcedBidders;
}
 
Example 3
Source File: FieldCode.java    From nuls with MIT License 6 votes vote down vote up
public FieldCode(FieldNode fieldNode) {
    access = fieldNode.access;
    name = fieldNode.name;
    desc = fieldNode.desc;
    signature = fieldNode.signature;
    value = fieldNode.value;
    visibleAnnotations = ListUtils.emptyIfNull(fieldNode.visibleAnnotations);
    invisibleAnnotations = ListUtils.emptyIfNull(fieldNode.invisibleAnnotations);
    visibleTypeAnnotations = ListUtils.emptyIfNull(fieldNode.visibleTypeAnnotations);
    invisibleTypeAnnotations = ListUtils.emptyIfNull(fieldNode.invisibleTypeAnnotations);
    attrs = ListUtils.emptyIfNull(fieldNode.attrs);
    //
    variableType = VariableType.valueOf(desc);
    isStatic = (access & Opcodes.ACC_STATIC) != 0;
    isFinal = (access & Opcodes.ACC_FINAL) != 0;
    isSynthetic = (access & Opcodes.ACC_SYNTHETIC) != 0;
}
 
Example 4
Source File: CDOMObjectUtilities.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void addAdds(CDOMObject cdo, PlayerCharacter pc)
{
	if (!pc.isAllowInteraction())
	{
		return;
	}
	List<PersistentTransitionChoice<?>> addList = ListUtils.emptyIfNull(cdo.getListFor(ListKey.ADD));
	addList.forEach(tc -> driveChoice(cdo, tc, pc));
}
 
Example 5
Source File: Occasion.java    From sample-acmegifts with Eclipse Public License 1.0 5 votes vote down vote up
public static String listToString(List<Contribution> contributions) {
  String method = "listToString";
  logger.entering(clazz, method);
  StringBuilder sb = new StringBuilder();
  for (Contribution contribution : ListUtils.emptyIfNull(contributions)) {
    sb.append(contribution.toString());
  }
  String str = sb.toString();
  logger.exiting(clazz, method, str);
  return str;
}
 
Example 6
Source File: CDOMObjectUtilities.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void restoreRemovals(CDOMObject cdo, PlayerCharacter pc)
{
	if (!pc.isAllowInteraction())
	{
		return;
	}
	List<PersistentTransitionChoice<?>> removeList = ListUtils.emptyIfNull(cdo.getListFor(ListKey.REMOVE));
	removeList.forEach(tc -> tc.remove(cdo, pc));
}
 
Example 7
Source File: CDOMObjectUtilities.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void addAdds(CDOMObject cdo, PlayerCharacter pc)
{
	if (!pc.isAllowInteraction())
	{
		return;
	}
	List<PersistentTransitionChoice<?>> addList = ListUtils.emptyIfNull(cdo.getListFor(ListKey.ADD));
	addList.forEach(tc -> driveChoice(cdo, tc, pc));
}
 
Example 8
Source File: ExecutionPlanner.java    From samza with Apache License 2.0 5 votes vote down vote up
/**
 * Groups streams participating in joins together.
 */
private static List<StreamSet> groupJoinedStreams(JobGraph jobGraph) {
  // Group input operator specs (input/intermediate streams) by the joins they participate in.
  Multimap<OperatorSpec, InputOperatorSpec> joinOpSpecToInputOpSpecs =
      OperatorSpecGraphAnalyzer.getJoinToInputOperatorSpecs(
          jobGraph.getApplicationDescriptorImpl().getInputOperators().values());

  Map<String, TableDescriptor> tableDescriptors = jobGraph.getTables().stream()
      .collect(Collectors.toMap(TableDescriptor::getTableId, Function.identity()));

  // Convert every group of input operator specs into a group of corresponding stream edges.
  List<StreamSet> streamSets = new ArrayList<>();
  for (OperatorSpec joinOpSpec : joinOpSpecToInputOpSpecs.keySet()) {
    Collection<InputOperatorSpec> joinedInputOpSpecs = joinOpSpecToInputOpSpecs.get(joinOpSpec);
    StreamSet streamSet = getStreamSet(joinOpSpec.getOpId(), joinedInputOpSpecs, jobGraph);

    // If current join is a stream-table join, add the stream edges corresponding to side-input
    // streams associated with the joined table (if any).
    if (joinOpSpec instanceof StreamTableJoinOperatorSpec) {
      StreamTableJoinOperatorSpec streamTableJoinOperatorSpec = (StreamTableJoinOperatorSpec) joinOpSpec;
      TableDescriptor tableDescriptor = tableDescriptors.get(streamTableJoinOperatorSpec.getTableId());
      if (tableDescriptor instanceof LocalTableDescriptor) {
        LocalTableDescriptor localTableDescriptor = (LocalTableDescriptor) tableDescriptor;
        Collection<String> sideInputs = ListUtils.emptyIfNull(localTableDescriptor.getSideInputs());
        Iterable<StreamEdge> sideInputStreams = sideInputs.stream().map(jobGraph::getStreamEdge)::iterator;
        Iterable<StreamEdge> streams = streamSet.getStreamEdges();
        streamSet = new StreamSet(streamSet.getSetId(), Iterables.concat(streams, sideInputStreams));
      }
    }

    streamSets.add(streamSet);
  }

  return Collections.unmodifiableList(streamSets);
}
 
Example 9
Source File: DefaultProfileBuilder.java    From metron with Apache License 2.0 5 votes vote down vote up
/**
 * Executes the expressions contained within the profile definition.
 *
 * @param expressions A list of expressions to execute.
 * @param transientState Additional transient state provided to the expressions.
 * @param expressionType The type of expression; init, update, result.  Provides additional context if expression execution fails.
 * @return The result of executing each expression.
 */
private List<Object> execute(List<String> expressions, Map<String, Object> transientState, String expressionType) {
  List<Object> results = new ArrayList<>();

  for(String expr: ListUtils.emptyIfNull(expressions)) {
    try {

      // execute an expression
      Object result = executor.execute(expr, transientState, Object.class);
      results.add(result);

    } catch (Throwable e) {

      // in-scope variables = persistent state maintained by the profiler + the transient state
      Set<String> variablesInScope = new HashSet<>();
      variablesInScope.addAll(transientState.keySet());
      variablesInScope.addAll(executor.getState().keySet());

      String msg = format("Bad '%s' expression: error='%s', expr='%s', profile='%s', entity='%s', variables-available='%s'",
              expressionType, e.getMessage(), expr, profileName, entity, variablesInScope);
      LOG.error(msg, e);
      throw new ParseException(msg, e);
    }
  }

  return results;
}
 
Example 10
Source File: Occasion.java    From sample-acmegifts with Eclipse Public License 1.0 5 votes vote down vote up
public static BasicDBList jsonArrayToDbList(JsonArray jsonArray) {
  String method = "jsonArrayToDbList";
  logger.entering(clazz, method, jsonArray);

  BasicDBList dbl = new BasicDBList();
  for (JsonValue json : ListUtils.emptyIfNull(jsonArray)) {
    BasicDBObject dbo = new Occasion((JsonObject) json).toDbo();
    dbl.add(dbo);
  }

  logger.exiting(clazz, method, dbl);
  return dbl;
}
 
Example 11
Source File: WorkflowController.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
private boolean writeWorkflowRecipientTargetChangeLog(WorkflowRecipientImpl newIcon, WorkflowRecipientImpl oldIcon, ComAdmin admin, Workflow workflow) {
    List<Integer> oldTargets = ListUtils.emptyIfNull(oldIcon.getTargets());
    List<Integer> newTargets = ListUtils.emptyIfNull(newIcon.getTargets());

    if (!oldTargets.equals(newTargets)) {
        writeUserActivityLog(admin, "edit campaign recipient",
                getWorkflowDescription(workflow) + "; recipient icon with id: " + newIcon.getId() + "; target group changed");
        return true;
    }

    return false;
}
 
Example 12
Source File: ClassCode.java    From nuls-v2 with MIT License 4 votes vote down vote up
public ClassCode(ClassNode classNode) {
    version = classNode.version;
    access = classNode.access;
    name = classNode.name;
    signature = classNode.signature;
    superName = classNode.superName;
    interfaces = ListUtils.emptyIfNull(classNode.interfaces);
    sourceFile = classNode.sourceFile;
    sourceDebug = classNode.sourceDebug;
    module = classNode.module;
    outerClass = classNode.outerClass;
    outerMethod = classNode.outerMethod;
    outerMethodDesc = classNode.outerMethodDesc;
    visibleAnnotations = ListUtils.emptyIfNull(classNode.visibleAnnotations);
    invisibleAnnotations = ListUtils.emptyIfNull(classNode.invisibleAnnotations);
    visibleTypeAnnotations = ListUtils.emptyIfNull(classNode.visibleTypeAnnotations);
    invisibleTypeAnnotations = ListUtils.emptyIfNull(classNode.invisibleTypeAnnotations);
    attrs = ListUtils.emptyIfNull(classNode.attrs);
    innerClasses = ListUtils.emptyIfNull(classNode.innerClasses);
    nestHostClass = classNode.nestHostClass;
    nestMembers = ListUtils.emptyIfNull(classNode.nestMembers);
    //fields = ListUtils.emptyIfNull(classNode.fields);
    //methods = ListUtils.emptyIfNull(classNode.methods);
    final List<FieldNode> fieldNodes = ListUtils.emptyIfNull(classNode.fields);
    fields = new LinkedHashMap<>(hashMapInitialCapacity(fieldNodes.size()));
    for (FieldNode fieldNode : fieldNodes) {
        final FieldCode fieldCode = new FieldCode(fieldNode);
        fields.put(fieldCode.name, fieldCode);
    }
    final List<MethodNode> methodNodes = ListUtils.emptyIfNull(classNode.methods);
    methods = new ArrayList<>(arrayListInitialCapacity(methodNodes.size()));
    methodMap = new LinkedHashMap<>(hashMapInitialCapacity(methodNodes.size() * 2));
    for (MethodNode methodNode : methodNodes) {
        final MethodCode methodCode = new MethodCode(this, methodNode);
        methods.add(methodCode);
        methodMap.put(methodCode.nameDesc, methodCode);
        if (!methodMap.containsKey(methodCode.name)) {
            methodMap.put(methodCode.name, methodCode);
        }
    }
    variableType = VariableType.valueOf(name);
    isInterface = (access & Opcodes.ACC_INTERFACE) != 0;
    isSuper = (access & Opcodes.ACC_SUPER) != 0;
    isAbstract = (access & Opcodes.ACC_ABSTRACT) != 0;
    isV1_6 = (version & Opcodes.V1_6) != 0;
    isV1_8 = (version & Opcodes.V1_8) != 0;
    simpleName = getSimpleName();
}
 
Example 13
Source File: ClassCode.java    From nuls with MIT License 4 votes vote down vote up
public ClassCode(ClassNode classNode) {
    version = classNode.version;
    access = classNode.access;
    name = classNode.name;
    signature = classNode.signature;
    superName = classNode.superName;
    interfaces = ListUtils.emptyIfNull(classNode.interfaces);
    sourceFile = classNode.sourceFile;
    sourceDebug = classNode.sourceDebug;
    module = classNode.module;
    outerClass = classNode.outerClass;
    outerMethod = classNode.outerMethod;
    outerMethodDesc = classNode.outerMethodDesc;
    visibleAnnotations = ListUtils.emptyIfNull(classNode.visibleAnnotations);
    invisibleAnnotations = ListUtils.emptyIfNull(classNode.invisibleAnnotations);
    visibleTypeAnnotations = ListUtils.emptyIfNull(classNode.visibleTypeAnnotations);
    invisibleTypeAnnotations = ListUtils.emptyIfNull(classNode.invisibleTypeAnnotations);
    attrs = ListUtils.emptyIfNull(classNode.attrs);
    innerClasses = ListUtils.emptyIfNull(classNode.innerClasses);
    nestHostClassExperimental = classNode.nestHostClassExperimental;
    nestMembersExperimental = ListUtils.emptyIfNull(classNode.nestMembersExperimental);
    //fields = ListUtils.emptyIfNull(classNode.fields);
    //methods = ListUtils.emptyIfNull(classNode.methods);
    final List<FieldNode> fieldNodes = ListUtils.emptyIfNull(classNode.fields);
    fields = new LinkedHashMap<>(hashMapInitialCapacity(fieldNodes.size()));
    for (FieldNode fieldNode : fieldNodes) {
        final FieldCode fieldCode = new FieldCode(fieldNode);
        fields.put(fieldCode.name, fieldCode);
    }
    final List<MethodNode> methodNodes = ListUtils.emptyIfNull(classNode.methods);
    methods = new ArrayList<>(arrayListInitialCapacity(methodNodes.size()));
    methodMap = new LinkedHashMap<>(hashMapInitialCapacity(methodNodes.size() * 2));
    for (MethodNode methodNode : methodNodes) {
        final MethodCode methodCode = new MethodCode(this, methodNode);
        methods.add(methodCode);
        methodMap.put(methodCode.nameDesc, methodCode);
        if (!methodMap.containsKey(methodCode.name)) {
            methodMap.put(methodCode.name, methodCode);
        }
    }
    variableType = VariableType.valueOf(name);
    isInterface = (access & Opcodes.ACC_INTERFACE) != 0;
    isSuper = (access & Opcodes.ACC_SUPER) != 0;
    isAbstract = (access & Opcodes.ACC_ABSTRACT) != 0;
    isV1_6 = (version & Opcodes.V1_6) != 0;
    isV1_8 = (version & Opcodes.V1_8) != 0;
    simpleName = getSimpleName();
}
 
Example 14
Source File: QuantumReportiumListener.java    From Quantum with MIT License 4 votes vote down vote up
@Override
public void onTestFailure(ITestResult testResult) {
	ReportiumClient client = getReportClient();
	if (null != client) {

		String failMsg = "";
		List<CheckpointResultBean> checkpointsList = TestBaseProvider.instance().get().getCheckPointResults();
		for (CheckpointResultBean result : checkpointsList) {
			if (result.getType().equals(MessageTypes.TestStepFail.toString())) {
				failMsg += "Step:" + result.getMessage() + " failed" + "\n";
				// List<CheckpointResultBean> subList = result.getSubCheckPoints();
				// for (CheckpointResultBean sub : subList) {
				// if (sub.getType().equals(MessageTypes.Fail.toString())){
				// failMsg += sub.getMessage() + "\n";
				// }
				// }
			}
		}

		if (testResult.getThrowable() == null) {
			client.testStop(TestResultFactory.createFailure(failMsg.isEmpty() ? "An error occurred" : failMsg,
					new Exception(
							"There was some validation failure in the scenario which did not provide any throwable object.")));
		} else {
			ExceptionUtils.getStackTrace(testResult.getThrowable());
			String actualExceptionMessage = testResult.getThrowable().toString();
			Messages message = parseFailureJsonFile(actualExceptionMessage);

			if (message != null) {
				String customError = message.getCustomError();
				List<String> customFields = ListUtils.emptyIfNull(message.getCustomFields());
				List<String> tags = ListUtils.emptyIfNull(message.getTags());
				String fileLoc = message.getJsonFile();

				ArrayList<CustomField> cfc = new ArrayList<CustomField>();

				for (String customField : customFields) {
					try {
						cfc.add(new CustomField(
								customField.split(getBundle().getString("custom.field.delimiter", "-"))[0],
								customField.split(getBundle().getString("custom.field.delimiter", "-"))[1]));
					} catch (Exception ex) {
						throw new NullPointerException(
								"Custom field key/value pair not delimited properly in failure reason json file: "
										+ fileLoc
										+ ".  Example of proper default usage: Developer-Jeremy.  Check application properties custom.field.delimiter for custom values that may have been set.");
					}
				}

				ArrayList<String> tagsFinal = new ArrayList<String>();
				for (String tag : tags) {
					tagsFinal.add(tag);
				}

				Builder testContext = new TestContext.Builder();

				if (cfc.size() > 0) {
					testContext.withCustomFields(cfc);
				}

				if (tagsFinal.size() > 0) {
					testContext.withTestExecutionTags(tagsFinal);
				}

				TestResult reportiumResult = TestResultFactory.createFailure(
						failMsg.isEmpty() ? "An error occurred" : failMsg, testResult.getThrowable(), customError);
				client.testStop(reportiumResult, testContext.build());
			} else {
				client.testStop(TestResultFactory.createFailure(failMsg.isEmpty() ? "An error occurred" : failMsg,
						testResult.getThrowable()));
			}
		}

		logTestEnd(testResult);

		tearIt(testResult);
	}
}
 
Example 15
Source File: ComCompanyServiceImpl.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public List<AdminEntry> getAdmins(int companyId) {
    return ListUtils.emptyIfNull(adminService.listAdminsByCompanyID(companyId));
}
 
Example 16
Source File: DeploymentConfig.java    From testgrid with Apache License 2.0 4 votes vote down vote up
public List<DeploymentPattern> getDeploymentPatterns() {
    return ListUtils.emptyIfNull(deploymentPatterns);
}
 
Example 17
Source File: OptimizationStatisticDto.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
public void setTargetIds(List<Integer> targetIds) {
    this.targetIds = ListUtils.emptyIfNull(targetIds);
}
 
Example 18
Source File: CompositeSelector.java    From bean-query with Apache License 2.0 4 votes vote down vote up
CompositeSelector(List<? extends KeyValueMapSelector> selectors) {
  this.selectors = new ArrayList<KeyValueMapSelector>(ListUtils.emptyIfNull(selectors));
  removeNullSubSelectors();
}
 
Example 19
Source File: ComBirtReportSettings.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
protected List<String> getReportSettingAsList(String key) {
    String value = getReportSettingAsString(key);
    return ListUtils.emptyIfNull(parseExpression(value));
}
 
Example 20
Source File: JobConfig.java    From testgrid with Apache License 2.0 2 votes vote down vote up
public List<Build> getBuilds() {

        return ListUtils.emptyIfNull(builds);
    }