@Override public BytesRef indexedValueForSearch(Object value) { if (value == null) { return Values.FALSE; } if (value instanceof Boolean) { return ((Boolean) value) ? Values.TRUE : Values.FALSE; } String sValue; if (value instanceof BytesRef) { sValue = ((BytesRef) value).utf8ToString(); } else { sValue = value.toString(); } if (sValue.length() == 0) { return Values.FALSE; } if (sValue.length() == 1 && sValue.charAt(0) == 'F') { return Values.FALSE; } if (Booleans.parseBoolean(sValue, false)) { return Values.TRUE; } return Values.FALSE; }
public Builder( String index, @Nullable Settings indexSettings, RootObjectMapper.Builder builder) { this.index = index; this.indexSettings = indexSettings; this.builderContext = new Mapper.BuilderContext(indexSettings, new ContentPath(1)); this.rootObjectMapper = builder.build(builderContext); IdFieldMapper idFieldMapper = new IdFieldMapper(); if (indexSettings != null) { String idIndexed = indexSettings.get("index.mapping._id.indexed"); if (idIndexed != null && Booleans.parseBoolean(idIndexed, false)) { FieldType fieldType = new FieldType(IdFieldMapper.Defaults.FIELD_TYPE); fieldType.setTokenized(false); idFieldMapper = new IdFieldMapper(fieldType); } } this.rootMappers.put(IdFieldMapper.class, idFieldMapper); // add default mappers, order is important (for example analyzer should come before the rest // to set context.analyzer) this.rootMappers.put(SizeFieldMapper.class, new SizeFieldMapper()); this.rootMappers.put(IndexFieldMapper.class, new IndexFieldMapper()); this.rootMappers.put(SourceFieldMapper.class, new SourceFieldMapper()); this.rootMappers.put(TypeFieldMapper.class, new TypeFieldMapper()); this.rootMappers.put(AnalyzerMapper.class, new AnalyzerMapper()); this.rootMappers.put(AllFieldMapper.class, new AllFieldMapper()); this.rootMappers.put(BoostFieldMapper.class, new BoostFieldMapper()); this.rootMappers.put(RoutingFieldMapper.class, new RoutingFieldMapper()); this.rootMappers.put(TimestampFieldMapper.class, new TimestampFieldMapper()); this.rootMappers.put(TTLFieldMapper.class, new TTLFieldMapper()); this.rootMappers.put(UidFieldMapper.class, new UidFieldMapper()); // don't add parent field, by default its "null" }
private ColumnPolicy getColumnPolicy() { Object dynamic = getNested(defaultMappingMap, "dynamic"); if (ColumnPolicy.STRICT.value().equals(String.valueOf(dynamic).toLowerCase(Locale.ENGLISH))) { return ColumnPolicy.STRICT; } else if (Booleans.isExplicitFalse(String.valueOf(dynamic))) { return ColumnPolicy.IGNORED; } else { return ColumnPolicy.DYNAMIC; } }
@Override public boolean booleanValue() throws IOException { Token token = currentToken(); if (token == Token.VALUE_NUMBER) { return intValue() != 0; } else if (token == Token.VALUE_STRING) { return Booleans.parseBoolean( textCharacters(), textOffset(), textLength(), false /* irrelevant */); } return doBooleanValue(); }
static List<DisplayHeader> buildDisplayHeaders(Table table, RestRequest request) { List<DisplayHeader> display = new ArrayList<>(); if (request.hasParam("h")) { Set<String> headers = expandHeadersFromRequest(table, request); for (String possibility : headers) { DisplayHeader dispHeader = null; if (table.getAsMap().containsKey(possibility)) { dispHeader = new DisplayHeader(possibility, possibility); } else { for (Table.Cell headerCell : table.getHeaders()) { String aliases = headerCell.attr.get("alias"); if (aliases != null) { for (String alias : Strings.splitStringByCommaToArray(aliases)) { if (possibility.equals(alias)) { dispHeader = new DisplayHeader(headerCell.value.toString(), alias); break; } } } } } if (dispHeader != null && checkOutputTimestamp(dispHeader, request)) { // We know we need the header asked for: display.add(dispHeader); // Look for accompanying sibling column Table.Cell hcell = table.getHeaderMap().get(dispHeader.name); String siblingFlag = hcell.attr.get("sibling"); if (siblingFlag != null) { // ...link the sibling and check that its flag is set String sibling = siblingFlag + "." + dispHeader.name; Table.Cell c = table.getHeaderMap().get(sibling); if (c != null && request.paramAsBoolean(siblingFlag, false)) { display.add( new DisplayHeader(c.value.toString(), siblingFlag + "." + dispHeader.display)); } } } } } else { for (Table.Cell cell : table.getHeaders()) { String d = cell.attr.get("default"); if (Booleans.parseBoolean(d, true) && checkOutputTimestamp(cell.value.toString(), request)) { display.add(new DisplayHeader(cell.value.toString(), cell.value.toString())); } } } return display; }
@Override public boolean isBooleanValue() throws IOException { switch (currentToken()) { case VALUE_BOOLEAN: return true; case VALUE_NUMBER: NumberType numberType = numberType(); return numberType == NumberType.LONG || numberType == NumberType.INT; case VALUE_STRING: return Booleans.isBoolean(textCharacters(), textOffset(), textLength()); default: return false; } }
private static Set<String> buildDisplayHeaders(Table table, RestRequest request) { String pHeaders = request.param("headers"); Set<String> display; if (pHeaders != null) { display = Strings.commaDelimitedListToSet(pHeaders); } else { display = new HashSet<String>(); for (Table.Cell cell : table.getHeaders()) { String d = cell.attr.get("default"); if (Booleans.parseBoolean(d, true)) { display.add(cell.value.toString()); } } } return display; }
@Override public Boolean value(Object value) { if (value == null) { return Boolean.FALSE; } String sValue = value.toString(); if (sValue.length() == 0) { return Boolean.FALSE; } if (sValue.length() == 1 && sValue.charAt(0) == 'F') { return Boolean.FALSE; } if (Booleans.parseBoolean(sValue, false)) { return Boolean.TRUE; } return Boolean.FALSE; }
@Override public Boolean paramAsBoolean(String key, Boolean defaultValue) { return Booleans.parseBoolean(param(key), defaultValue); }
@Override public Boolean getAsBoolean(String[] settings, Boolean defaultValue) { return Booleans.parseBoolean(get(settings), defaultValue); }
public String[] resolveNodesIds(String... nodesIds) { if (isAllNodes(nodesIds)) { int index = 0; nodesIds = new String[nodes.size()]; for (DiscoveryNode node : this) { nodesIds[index++] = node.id(); } return nodesIds; } else { Set<String> resolvedNodesIds = new HashSet<String>(nodesIds.length); for (String nodeId : nodesIds) { if (nodeId.equals("_local")) { String localNodeId = localNodeId(); if (localNodeId != null) { resolvedNodesIds.add(localNodeId); } } else if (nodeId.equals("_master")) { String masterNodeId = masterNodeId(); if (masterNodeId != null) { resolvedNodesIds.add(masterNodeId); } } else if (nodeExists(nodeId)) { resolvedNodesIds.add(nodeId); } else { // not a node id, try and search by name for (DiscoveryNode node : this) { if (Regex.simpleMatch(nodeId, node.name())) { resolvedNodesIds.add(node.id()); } } for (DiscoveryNode node : this) { if (node.address().match(nodeId)) { resolvedNodesIds.add(node.id()); } } int index = nodeId.indexOf(':'); if (index != -1) { String matchAttrName = nodeId.substring(0, index); String matchAttrValue = nodeId.substring(index + 1); if ("data".equals(matchAttrName)) { if (Booleans.parseBoolean(matchAttrValue, true)) { resolvedNodesIds.addAll(dataNodes.keySet()); } else { resolvedNodesIds.removeAll(dataNodes.keySet()); } } else if ("master".equals(matchAttrName)) { if (Booleans.parseBoolean(matchAttrValue, true)) { resolvedNodesIds.addAll(masterNodes.keySet()); } else { resolvedNodesIds.removeAll(masterNodes.keySet()); } } else { for (DiscoveryNode node : this) { for (Map.Entry<String, String> entry : node.attributes().entrySet()) { String attrName = entry.getKey(); String attrValue = entry.getValue(); if (Regex.simpleMatch(matchAttrName, attrName) && Regex.simpleMatch(matchAttrValue, attrValue)) { resolvedNodesIds.add(node.id()); } } } } } } } return resolvedNodesIds.toArray(new String[resolvedNodesIds.size()]); } }
@Override protected void doStart() { this.serverOpenChannels = new OpenChannelsHandler(logger); if (blockingServer) { serverBootstrap = new ServerBootstrap( new OioServerSocketChannelFactory( Executors.newCachedThreadPool(daemonThreadFactory(settings, "http_server_boss")), Executors.newCachedThreadPool( daemonThreadFactory(settings, "http_server_worker")))); } else { serverBootstrap = new ServerBootstrap( new NioServerSocketChannelFactory( Executors.newCachedThreadPool(daemonThreadFactory(settings, "http_server_boss")), Executors.newCachedThreadPool( daemonThreadFactory(settings, "http_server_worker")), workerCount)); } serverBootstrap.setPipelineFactory(configureServerChannelPipelineFactory()); if (!"default".equals(tcpNoDelay)) { serverBootstrap.setOption("child.tcpNoDelay", Booleans.parseBoolean(tcpNoDelay, null)); } if (!"default".equals(tcpKeepAlive)) { serverBootstrap.setOption("child.keepAlive", Booleans.parseBoolean(tcpKeepAlive, null)); } if (tcpSendBufferSize != null && tcpSendBufferSize.bytes() > 0) { serverBootstrap.setOption("child.sendBufferSize", tcpSendBufferSize.bytes()); } if (tcpReceiveBufferSize != null && tcpReceiveBufferSize.bytes() > 0) { serverBootstrap.setOption("child.receiveBufferSize", tcpReceiveBufferSize.bytes()); } serverBootstrap.setOption( "receiveBufferSizePredictorFactory", receiveBufferSizePredictorFactory); serverBootstrap.setOption( "child.receiveBufferSizePredictorFactory", receiveBufferSizePredictorFactory); serverBootstrap.setOption("reuseAddress", reuseAddress); serverBootstrap.setOption("child.reuseAddress", reuseAddress); // Bind and start to accept incoming connections. InetAddress hostAddresses[]; try { hostAddresses = networkService.resolveBindHostAddress(bindHost); } catch (IOException e) { throw new BindHttpException("Failed to resolve host [" + bindHost + "]", e); } for (InetAddress address : hostAddresses) { bindAddress(address); } InetSocketAddress boundAddress = (InetSocketAddress) serverChannels.get(0).getLocalAddress(); InetSocketAddress publishAddress; if (0 == publishPort) { publishPort = boundAddress.getPort(); } try { publishAddress = new InetSocketAddress(networkService.resolvePublishHostAddress(publishHost), publishPort); } catch (Exception e) { throw new BindTransportException("Failed to resolve publish address", e); } this.boundAddress = new BoundTransportAddress( new InetSocketTransportAddress(boundAddress), new InetSocketTransportAddress(publishAddress)); }