Rewrite.

@param searchComponent the search component
@return the simple ordered map
@throws IOException Signals that an I/O exception has occurred.
507948
public SimpleOrderedMap<Object> rewrite(
      MtasSolrSearchComponent searchComponent) throws IOException {
    SimpleOrderedMap<Object> response = new SimpleOrderedMap<>();
    Iterator<Entry<String, Object>> it;
    switch (action) {
    case ComponentCollection.ACTION_LIST:
      response.add("now", now);
      response.add("list", list);
      break;
    case ComponentCollection.ACTION_CREATE:
    case ComponentCollection.ACTION_POST:
    case ComponentCollection.ACTION_IMPORT:
      if (componentCollection != null && status != null) {
        it = status.iterator();
        while (it.hasNext()) {
          Entry<String, Object> entry = it.next();
          response.add(entry.getKey(), entry.getValue());
        }
      }
      break;
    case ComponentCollection.ACTION_CHECK:
      if (status != null) {
        it = status.iterator();
        while (it.hasNext()) {
          Entry<String, Object> entry = it.next();
          response.add(entry.getKey(), entry.getValue());
        }
      }
      break;
    case ComponentCollection.ACTION_GET:
      if (status != null) {
        it = status.iterator();
        while (it.hasNext()) {
          Entry<String, Object> entry = it.next();
          response.add(entry.getKey(), entry.getValue());
        }
      }
      if (values != null) {
        response.add("values", values);
      }
      break;
    default:
      break;
    }
    return response;
  }
273955
private String _serializeComponent(Component component, Map<Object, String> done) throws ConverterException {
	StringBuilder sb = new StringBuilder();
	Component ca;
	component = new ComponentSpecificAccess(Component.ACCESS_PRIVATE, ca = component);
	boolean isPeristent = ca.isPersistent();

	deep++;
	Object member;
	Iterator<Key> it = component.keyIterator();
	Collection.Key key;
	while (it.hasNext()) {
	    key = it.next();
	    member = component.get(key, null);
	    if (member instanceof UDF) continue;
	    sb.append(goIn() + "<var scope=\"this\" name=" + del + key.toString() + del + ">");
	    sb.append(_serialize(member, done));
	    sb.append(goIn() + "</var>");
	}

	Property p;
	Boolean remotingFetch;
	Struct props = ignoreRemotingFetch ? null : ComponentUtil.getPropertiesAsStruct(ca, false);
	ComponentScope scope = ca.getComponentScope();
	it = scope.keyIterator();
	while (it.hasNext()) {
	    key = Caster.toKey(it.next(), null);
	    if (!ignoreRemotingFetch) {
		p = (Property) props.get(key, null);
		if (p != null) {
		    remotingFetch = Caster.toBoolean(p.getDynamicAttributes().get(REMOTING_FETCH, null), null);
		    if (remotingFetch == null) {
			if (isPeristent && ORMUtil.isRelated(p)) continue;
		    }
		    else if (!remotingFetch.booleanValue()) continue;
		}
	    }

	    member = scope.get(key, null);
	    if (member instanceof UDF || key.equals(KeyConstants._this)) continue;
	    sb.append(goIn() + "<var scope=\"variables\" name=" + del + key.toString() + del + ">");
	    sb.append(_serialize(member, done));
	    sb.append(goIn() + "</var>");
	}

	deep--;
	try {
	    // return goIn()+"<struct>"+sb+"</struct>";
	    return goIn() + "<component md5=\"" + ComponentUtil.md5(component) + "\" name=\"" + component.getAbsName() + "\">" + sb + "</component>";
	}
	catch (Exception e) {
	    throw toConverterException(e);
	}
    }
235408
@Override
  public MtasSpanQuery rewrite(IndexReader reader) throws IOException {
    if (items.size() == 1) {
      MtasSpanQuery singleQuery = items.get(0).getQuery();
      if (leftMaximum != 0 || rightMaximum != 0) {
        singleQuery = new MtasExpandSpanQuery(singleQuery, leftMinimum,
            leftMaximum, rightMinimum, rightMaximum);
      }
      return singleQuery.rewrite(reader);
    } else {
      MtasSpanSequenceItem newItem;
      MtasSpanSequenceItem previousNewItem = null;
      ArrayList<MtasSpanSequenceItem> newItems = new ArrayList<>(items.size());
      int newLeftMinimum = leftMinimum;
      int newLeftMaximum = leftMaximum;
      int newRightMinimum = rightMinimum;
      int newRightMaximum = rightMaximum;
      MtasSpanQuery newIgnoreClause = ignoreQuery != null
          ? ignoreQuery.rewrite(reader) : null;
      boolean actuallyRewritten = ignoreQuery != null
          ? !newIgnoreClause.equals(ignoreQuery) : false;
      for (int i = 0; i < items.size(); i++) {
        newItem = items.get(i).rewrite(reader);
        if (newItem.getQuery() instanceof MtasSpanMatchNoneQuery) {
          if (!newItem.isOptional()) {
            return new MtasSpanMatchNoneQuery(field);
          } else {
            actuallyRewritten = true;
          }
        } else {
          actuallyRewritten |= !items.get(i).equals(newItem);
          MtasSpanSequenceItem previousMergedItem = MtasSpanSequenceItem.merge(
              previousNewItem, newItem, ignoreQuery, maximumIgnoreLength);
          if (previousMergedItem != null) {
            newItems.set((newItems.size() - 1), previousMergedItem);
            actuallyRewritten = true;
          } else {
            newItems.add(newItem);
          }
          previousNewItem = newItem;
        }
      }
      // check first and last
      if (ignoreQuery == null) {
        ArrayList<MtasSpanSequenceItem> possibleTrimmedItems = new ArrayList<>(
            newItems.size());
        MtasSpanSequenceItem firstItem = newItems.get(0);
        MtasSpanQuery firstQuery = firstItem.getQuery();
        if (firstQuery instanceof MtasSpanMatchAllQuery) {
          newLeftMaximum++;
          if (!firstItem.isOptional()) {
            newLeftMinimum++;
          }
        } else if (firstQuery instanceof MtasSpanRecurrenceQuery) {
          MtasSpanRecurrenceQuery firstRecurrenceQuery = (MtasSpanRecurrenceQuery) firstQuery;
          if (firstRecurrenceQuery.getQuery() instanceof MtasSpanMatchAllQuery
              && firstRecurrenceQuery.getIgnoreQuery() == null) {
            if (!firstItem.isOptional()) {
              newLeftMinimum += firstRecurrenceQuery.getMinimumRecurrence();
              newLeftMaximum += firstRecurrenceQuery.getMaximumRecurrence();
            } else {
              if (firstRecurrenceQuery.getMinimumRecurrence() == 1
                  || firstRecurrenceQuery
                      .getMinimumRecurrence() <= newLeftMinimum) {
                newLeftMinimum += 0;
                newLeftMaximum += firstRecurrenceQuery.getMaximumRecurrence();
              } else {
                possibleTrimmedItems.add(firstItem);
              }
            }
          } else {
            possibleTrimmedItems.add(firstItem);
          }
        } else {
          possibleTrimmedItems.add(firstItem);
        }
        for (int i = 1; i < (newItems.size() - 1); i++) {
          possibleTrimmedItems.add(newItems.get(i));
        }
        if (newItems.size() > 1) {
          MtasSpanSequenceItem lastItem = newItems.get((newItems.size() - 1));
          MtasSpanQuery lastQuery = lastItem.getQuery();
          if (lastQuery instanceof MtasSpanMatchAllQuery) {
            newRightMaximum++;
            if (!lastItem.isOptional()) {
              newRightMinimum++;
            }
          } else if (lastQuery instanceof MtasSpanRecurrenceQuery) {
            MtasSpanRecurrenceQuery lastRecurrenceQuery = (MtasSpanRecurrenceQuery) lastQuery;
            if (lastRecurrenceQuery.getQuery() instanceof MtasSpanMatchAllQuery
                && lastRecurrenceQuery.getIgnoreQuery() == null) {
              if (!lastItem.isOptional()) {
                newRightMinimum += lastRecurrenceQuery.getMinimumRecurrence();
                newRightMaximum += lastRecurrenceQuery.getMaximumRecurrence();
              } else if (lastRecurrenceQuery.getMinimumRecurrence() == 1
                  || lastRecurrenceQuery
                      .getMinimumRecurrence() <= newRightMinimum) {
                newRightMinimum += 0;
                newRightMaximum += lastRecurrenceQuery.getMaximumRecurrence();
              } else {
                possibleTrimmedItems.add(lastItem);
              }
            } else {
              possibleTrimmedItems.add(lastItem);
            }
          } else {
            possibleTrimmedItems.add(lastItem);
          }
        }
        if (possibleTrimmedItems.size() < newItems.size()) {
          actuallyRewritten = true;
          newItems = possibleTrimmedItems;
        }
      }
      if (!actuallyRewritten) {
        if (leftMaximum != 0 || rightMaximum != 0) {
          newLeftMinimum = leftMinimum;
          newLeftMaximum = leftMaximum;
          newRightMinimum = rightMinimum;
          newRightMaximum = rightMaximum;
          leftMinimum = 0;
          leftMaximum = 0;
          rightMinimum = 0;
          rightMaximum = 0;
          MtasSpanQuery finalQuery = new MtasExpandSpanQuery(this,
              newLeftMinimum, newLeftMaximum, newRightMinimum, newRightMaximum);
          return finalQuery.rewrite(reader);
        } else {
          return super.rewrite(reader);
        }
      } else {
        if (!newItems.isEmpty()) {
          return new MtasSpanSequenceQuery(newItems, newLeftMinimum,
              newLeftMaximum, newRightMinimum, newRightMaximum, newIgnoreClause,
              maximumIgnoreLength).rewrite(reader);
        } else {
          return new MtasSpanMatchNoneQuery(field);
        }
      }
    }
  }
968867
public @NonNull TextComponent content(final @NonNull String content) {
    return new TextComponent(this.children, this.color, this.obfuscated, this.bold, this.strikethrough, this.underlined, this.italic, this.clickEvent, this.hoverEvent, this.insertion, requireNonNull(content, "content"));
  }
301330
public void writeStartComponent(String componentName) throws IOException {
		if (generator == null) {
			init();
		}

		componentEnded = false;

		if (!stack.isEmpty()) {
			Info parent = stack.getLast();
			if (!parent.wroteEndPropertiesArray) {
				generator.writeEndArray();
				parent.wroteEndPropertiesArray = true;
			}
			if (!parent.wroteStartSubComponentsArray) {
				generator.writeStartArray();
				parent.wroteStartSubComponentsArray = true;
			}
		}

		generator.writeStartArray();
		generator.writeString(componentName);
		generator.writeStartArray(); //start properties array

		stack.add(new Info());
	}
674031
public SimpleOrderedMap<Object> create(
      ComponentCollection componentCollection, Boolean encode)
      throws IOException {
    MtasSolrCollectionResult data = createMtasSolrCollectionResult(
        componentCollection, encode ? false : true);
    // Create response
    SimpleOrderedMap<Object> mtasCollectionResponse = new SimpleOrderedMap<>();
    mtasCollectionResponse.add("key", componentCollection.key);
    if (encode) {
      mtasCollectionResponse.add("_encoded_data",
          MtasSolrResultUtil.encode(data));
    } else {
      mtasCollectionResponse.add("data", data);
      MtasSolrResultUtil.rewrite(mtasCollectionResponse, searchComponent);
    }
    return mtasCollectionResponse;
  }
1322763
public PluginComponentCache components(long pluginId)
    {
        PluginComponentCache cache = components.get(pluginId);
        if(cache == null)
            components.put(pluginId, cache = new PluginComponentCache(pluginId));
        return cache;
    }
219695
protected final List<T> searchSorted(String searchString, String sort) {
        return this.dataAccess.searchSorted(searchString, sort);
    }
545418
public Object searchGreaterOrEqual(
                                      Object            searchKey)
    {
        SearchComparator comp = searchComparator(SearchComparator.GE);
        Object p = find(comp, searchKey);
        return p;
    }
113102
public Component getComponent(int componentIndex)
    {
        if (componentList != null)
            if (componentIndex < componentList.length)
                return componentList[componentIndex];
        return null;
    }
1299961
private void rewriteProperty(JSONObject node, String key, JSONArray rewriteProperty) throws JSONException {
    if (node.get(cleanup(key)) instanceof String) {
      if (rewriteProperty.length() == 2) {
        if (rewriteProperty.get(0) instanceof String && rewriteProperty.get(1) instanceof String) {
          String pattern = rewriteProperty.getString(0);
          String replacement = rewriteProperty.getString(1);

          Pattern compiledPattern = Pattern.compile(pattern);
          Matcher matcher = compiledPattern.matcher(node.getString(cleanup(key)));
          node.put(cleanup(key), matcher.replaceAll(replacement));
        }
      }
    }
  }
713313
public Object searchGreater(
                               Object            searchKey)
    {
        SearchComparator comp = searchComparator(SearchComparator.GT);
        Object p = find(comp, searchKey);
        return p;
    }
752369
@Override
  public MtasSpanQuery rewrite(IndexReader reader) throws IOException {
    MtasSpanQuery newClause = clause.rewrite(reader);
    if (!newClause.equals(clause)) {
      return new MtasSpanUniquePositionQuery(newClause).rewrite(reader);
    } else {
      return super.rewrite(reader);
    }
  }
989600
protected Map<String, Object> getAttributesForComponent(Component component) {

        Map<String, Object> result = Maps.newHashMap();
        if (component instanceof AbstractComponent) {
            AbstractComponent abstractComp = (AbstractComponent)component;
            if (abstractComp.getData() instanceof Map) {
                Map<?, ?> map = (Map<?, ?>)abstractComp.getData();
                for (Map.Entry<?, ?> entry : map.entrySet()) {
                    if (entry.getKey() instanceof String) {
                        result.put((String)(entry.getKey()), entry.getValue());
                    }
                }
            }
        }
        return result;
    }
769711
protected void addComponentMapping(Class<? extends IComponent> klazz, IComponent component) {
        components.put(klazz, component);
    }
44829
Component addComponent(Consumer<IOException> onError) {
        Component component;
        try {
            long readable = readableBytes(data);
            long offset = position.getAndUpdate(p -> readable);
            int length = new Long(readable - offset).intValue();
            component = new Component(length, offset);
            components.add(component);
        } catch (IOException e) {
            onError.accept(e);
            return null;
        }

        if (!data.isInMemory()) {
            fileAccess.getAndUpdate(channel -> {
                if (channel == null) {
                    try {
                        return new RandomAccessFile(data.getFile(), "r");
                    } catch (IOException e) {
                        onError.accept(e);
                    }
                }
                return channel;
            });
        }

        return component;
    }
600632
@Override
	public SimpleOrderedMap<Object> create(ComponentVersion version, Boolean encode) throws IOException {
		return getVersion();
	}