use of java.util.Map.Entry in project elasticsearch by elastic.
the class TypeParsers method parseAnalyzersAndTermVectors.
private static void parseAnalyzersAndTermVectors(FieldMapper.Builder builder, String name, Map<String, Object> fieldNode, Mapper.TypeParser.ParserContext parserContext) {
NamedAnalyzer indexAnalyzer = null;
NamedAnalyzer searchAnalyzer = null;
NamedAnalyzer searchQuoteAnalyzer = null;
for (Iterator<Map.Entry<String, Object>> iterator = fieldNode.entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry<String, Object> entry = iterator.next();
final String propName = entry.getKey();
final Object propNode = entry.getValue();
if (propName.equals("term_vector")) {
parseTermVector(name, propNode.toString(), builder);
iterator.remove();
} else if (propName.equals("store_term_vectors")) {
builder.storeTermVectors(nodeBooleanValue(name, "store_term_vectors", propNode, parserContext));
iterator.remove();
} else if (propName.equals("store_term_vector_offsets")) {
builder.storeTermVectorOffsets(nodeBooleanValue(name, "store_term_vector_offsets", propNode, parserContext));
iterator.remove();
} else if (propName.equals("store_term_vector_positions")) {
builder.storeTermVectorPositions(nodeBooleanValue(name, "store_term_vector_positions", propNode, parserContext));
iterator.remove();
} else if (propName.equals("store_term_vector_payloads")) {
builder.storeTermVectorPayloads(nodeBooleanValue(name, "store_term_vector_payloads", propNode, parserContext));
iterator.remove();
} else if (propName.equals("analyzer")) {
NamedAnalyzer analyzer = parserContext.getIndexAnalyzers().get(propNode.toString());
if (analyzer == null) {
throw new MapperParsingException("analyzer [" + propNode.toString() + "] not found for field [" + name + "]");
}
indexAnalyzer = analyzer;
iterator.remove();
} else if (propName.equals("search_analyzer")) {
NamedAnalyzer analyzer = parserContext.getIndexAnalyzers().get(propNode.toString());
if (analyzer == null) {
throw new MapperParsingException("analyzer [" + propNode.toString() + "] not found for field [" + name + "]");
}
searchAnalyzer = analyzer;
iterator.remove();
} else if (propName.equals("search_quote_analyzer")) {
NamedAnalyzer analyzer = parserContext.getIndexAnalyzers().get(propNode.toString());
if (analyzer == null) {
throw new MapperParsingException("analyzer [" + propNode.toString() + "] not found for field [" + name + "]");
}
searchQuoteAnalyzer = analyzer;
iterator.remove();
}
}
if (indexAnalyzer == null && searchAnalyzer != null) {
throw new MapperParsingException("analyzer on field [" + name + "] must be set when search_analyzer is set");
}
if (searchAnalyzer == null && searchQuoteAnalyzer != null) {
throw new MapperParsingException("analyzer and search_analyzer on field [" + name + "] must be set when search_quote_analyzer is set");
}
if (searchAnalyzer == null) {
searchAnalyzer = indexAnalyzer;
}
if (searchQuoteAnalyzer == null) {
searchQuoteAnalyzer = searchAnalyzer;
}
if (indexAnalyzer != null) {
builder.indexAnalyzer(indexAnalyzer);
}
if (searchAnalyzer != null) {
builder.searchAnalyzer(searchAnalyzer);
}
if (searchQuoteAnalyzer != null) {
builder.searchQuoteAnalyzer(searchQuoteAnalyzer);
}
}
use of java.util.Map.Entry in project elasticsearch by elastic.
the class IndicesClusterStateServiceRandomUpdatesTests method updateNodes.
private void updateNodes(ClusterState state, Map<DiscoveryNode, IndicesClusterStateService> clusterStateServiceMap, Supplier<MockIndicesService> indicesServiceSupplier) {
for (DiscoveryNode node : state.nodes()) {
clusterStateServiceMap.computeIfAbsent(node, discoveryNode -> {
IndicesClusterStateService ics = createIndicesClusterStateService(discoveryNode, indicesServiceSupplier);
ics.start();
return ics;
});
}
for (Iterator<Entry<DiscoveryNode, IndicesClusterStateService>> it = clusterStateServiceMap.entrySet().iterator(); it.hasNext(); ) {
DiscoveryNode node = it.next().getKey();
if (state.nodes().nodeExists(node) == false) {
it.remove();
}
}
}
use of java.util.Map.Entry in project elasticsearch by elastic.
the class PhraseSuggestionBuilder method innerToXContent.
@Override
public XContentBuilder innerToXContent(XContentBuilder builder, Params params) throws IOException {
builder.field(RWE_LIKELIHOOD_FIELD.getPreferredName(), realWordErrorLikelihood);
builder.field(CONFIDENCE_FIELD.getPreferredName(), confidence);
builder.field(SEPARATOR_FIELD.getPreferredName(), separator);
builder.field(MAXERRORS_FIELD.getPreferredName(), maxErrors);
if (gramSize != null) {
builder.field(GRAMSIZE_FIELD.getPreferredName(), gramSize);
}
builder.field(FORCE_UNIGRAM_FIELD.getPreferredName(), forceUnigrams);
builder.field(TOKEN_LIMIT_FIELD.getPreferredName(), tokenLimit);
if (!generators.isEmpty()) {
Set<Entry<String, List<CandidateGenerator>>> entrySet = generators.entrySet();
for (Entry<String, List<CandidateGenerator>> entry : entrySet) {
builder.startArray(entry.getKey());
for (CandidateGenerator generator : entry.getValue()) {
generator.toXContent(builder, params);
}
builder.endArray();
}
}
if (model != null) {
builder.startObject(SMOOTHING_MODEL_FIELD.getPreferredName());
model.toXContent(builder, params);
builder.endObject();
}
if (preTag != null) {
builder.startObject(HIGHLIGHT_FIELD.getPreferredName());
builder.field(PRE_TAG_FIELD.getPreferredName(), preTag);
builder.field(POST_TAG_FIELD.getPreferredName(), postTag);
builder.endObject();
}
if (collateQuery != null) {
builder.startObject(COLLATE_FIELD.getPreferredName());
builder.field(COLLATE_QUERY_FIELD.getPreferredName(), collateQuery);
if (collateParams != null) {
builder.field(COLLATE_QUERY_PARAMS.getPreferredName(), collateParams);
}
builder.field(COLLATE_QUERY_PRUNE.getPreferredName(), collatePrune);
builder.endObject();
}
return builder;
}
use of java.util.Map.Entry in project UltimateAndroid by cymcsg.
the class MarkerManager method getViewFromTap.
private View getViewFromTap(int x, int y) {
Iterator<Entry<View, Rect>> iterator = markerMap.entrySet().iterator();
while (iterator.hasNext()) {
Entry<View, Rect> pairs = iterator.next();
Rect rect = (Rect) pairs.getValue();
if (rect.contains(x, y)) {
View view = (View) pairs.getKey();
return view;
}
}
return null;
}
use of java.util.Map.Entry in project che by eclipse.
the class InferTypeArgumentsRefactoring method checkFinalConditions.
/*
* @see org.eclipse.ltk.core.refactoring.Refactoring#checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public RefactoringStatus checkFinalConditions(final IProgressMonitor pm) throws CoreException, OperationCanceledException {
HashMap<IJavaProject, ArrayList<IJavaElement>> projectsToElements = getJavaElementsPerProject(fElements);
//$NON-NLS-1$
pm.beginTask("", projectsToElements.size() + 2);
final RefactoringStatus result = new RefactoringStatus();
try {
fTCModel = new InferTypeArgumentsTCModel();
final InferTypeArgumentsConstraintCreator unitCollector = new InferTypeArgumentsConstraintCreator(fTCModel, fAssumeCloneReturnsSameType);
for (Iterator<Entry<IJavaProject, ArrayList<IJavaElement>>> iter = projectsToElements.entrySet().iterator(); iter.hasNext(); ) {
Entry<IJavaProject, ArrayList<IJavaElement>> entry = iter.next();
IJavaProject project = entry.getKey();
ArrayList<IJavaElement> javaElementsList = entry.getValue();
IJavaElement[] javaElements = javaElementsList.toArray(new IJavaElement[javaElementsList.size()]);
List<ICompilationUnit> cus = Arrays.asList(JavaModelUtil.getAllCompilationUnits(javaElements));
int batchSize = 150;
int batches = ((cus.size() - 1) / batchSize) + 1;
SubProgressMonitor projectMonitor = new SubProgressMonitor(pm, 1);
//$NON-NLS-1$
projectMonitor.beginTask("", batches);
projectMonitor.setTaskName(RefactoringCoreMessages.InferTypeArgumentsRefactoring_building);
for (int i = 0; i < batches; i++) {
List<ICompilationUnit> batch = cus.subList(i * batchSize, Math.min(cus.size(), (i + 1) * batchSize));
ICompilationUnit[] batchCus = batch.toArray(new ICompilationUnit[batch.size()]);
final SubProgressMonitor batchMonitor = new SubProgressMonitor(projectMonitor, 1);
batchMonitor.subTask(RefactoringCoreMessages.InferTypeArgumentsRefactoring_calculating_dependencies);
ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setProject(project);
parser.setCompilerOptions(RefactoringASTParser.getCompilerOptions(project));
parser.setResolveBindings(true);
parser.createASTs(batchCus, new String[0], new ASTRequestor() {
@Override
public void acceptAST(final ICompilationUnit source, final CompilationUnit ast) {
batchMonitor.subTask(BasicElementLabels.getFileName(source));
SafeRunner.run(new ISafeRunnable() {
public void run() throws Exception {
IProblem[] problems = ast.getProblems();
for (int p = 0; p < problems.length; p++) {
if (problems[p].isError()) {
String cuName = JavaElementLabels.getElementLabel(source, JavaElementLabels.CU_QUALIFIED);
String msg = Messages.format(RefactoringCoreMessages.InferTypeArgumentsRefactoring_error_in_cu_skipped, new Object[] { cuName });
result.addError(msg, JavaStatusContext.create(source, SourceRangeFactory.create(problems[p])));
return;
}
}
ast.accept(unitCollector);
}
public void handleException(Throwable exception) {
String cuName = JavaElementLabels.getElementLabel(source, JavaElementLabels.CU_QUALIFIED);
String msg = Messages.format(RefactoringCoreMessages.InferTypeArgumentsRefactoring_internal_error, new Object[] { cuName });
JavaPlugin.log(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, msg, null));
String msg2 = Messages.format(RefactoringCoreMessages.InferTypeArgumentsRefactoring_error_skipped, new Object[] { cuName });
result.addError(msg2, JavaStatusContext.create(source));
}
});
fTCModel.newCu();
}
@Override
public void acceptBinding(String bindingKey, IBinding binding) {
//do nothing
}
}, batchMonitor);
}
projectMonitor.done();
fTCModel.newCu();
}
// Display.getDefault().syncExec(new Runnable() {
// public void run() {
// MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "Debugging...", "after constraint gen");
// }
// });
pm.setTaskName(RefactoringCoreMessages.InferTypeArgumentsRefactoring_solving);
InferTypeArgumentsConstraintsSolver solver = new InferTypeArgumentsConstraintsSolver(fTCModel);
InferTypeArgumentsUpdate updates = solver.solveConstraints(new SubProgressMonitor(pm, 1));
//free caches
solver = null;
fChangeManager = new TextChangeManager();
rewriteDeclarations(updates, new SubProgressMonitor(pm, 1));
IFile[] filesToModify = ResourceUtil.getFiles(fChangeManager.getAllCompilationUnits());
result.merge(Checks.validateModifiesFiles(filesToModify, getValidationContext()));
return result;
} finally {
pm.done();
clearGlobalState();
}
}
Aggregations