/*
(non-Javadoc)

@see
mtas.search.spans.util.MtasSpanQuery#createWeight(org.apache.lucene.search.
IndexSearcher, boolean)
775161
@Override
  public SpanWeight createWeight(IndexSearcher searcher, boolean needsScores, float boost)
      throws IOException {
    return baseQuery.createWeight(searcher, needsScores, boost);
  }
725386
protected function _initWeight(Zend_Search_Lucene_Interface $reader)
    {
        // Check, that it's a top-level query and query weight is not initialized yet.
        if ($this->_weight !== null) {
            return $this->_weight;
        }

        $this->createWeight($reader);
        $sum = $this->_weight->sumOfSquaredWeights();
        $queryNorm = $reader->getSimilarity()->queryNorm($sum);
        $this->_weight->normalize($queryNorm);
    }
119346
public JavaType create(ClassIndex index, ClassPlan plan) {

        // base class
        JavaInterfaceSource type = Roaster.parse(
                JavaInterfaceSource.class,
                "public interface " + plan.getClassName() + "Consumer<T extends " + plan.getClassName() + "<T>> {}"
        );

        type.setPackage(plan.getPackageName());

        type.addImport(plan.getPackageName() + "." + plan.getClassName());
        type.addAnnotation(FunctionalInterface.class);

        addAccept(type, plan);
        addAndThen(type, plan);

        return type;
    }
991083
int createGeometryUserIndex() {
		if (m_geometry_indices == null)
			m_geometry_indices = new ArrayList<AttributeStreamOfInt32>(4);

		// Try getting existing index. Use linear search. We do not expect many
		// indices to be created.
		for (int i = 0; i < m_geometry_indices.size(); i++) {
			if (m_geometry_indices.get(i) == null) {
				m_geometry_indices.set(i,
						(AttributeStreamOfInt32) AttributeStreamBase
								.createIndexStream(0));
				return i;
			}
		}

		m_geometry_indices.add((AttributeStreamOfInt32) AttributeStreamBase
				.createIndexStream(0));
		return m_geometry_indices.size() - 1;
	}
1022130
private static void handleLegacyWeightInitFromJson(String json, Layer layer, ObjectMapper mapper, JsonNode vertices) {
        if (layer instanceof BaseLayer && ((BaseLayer) layer).getWeightInitFn() == null) {
            String layerName = layer.getLayerName();

            try {
                if (vertices == null) {
                    JsonNode jsonNode = mapper.readTree(json);
                    vertices = jsonNode.get("vertices");
                }

                JsonNode vertexNode = vertices.get(layerName);
                JsonNode layerVertexNode = vertexNode.get("LayerVertex");
                if (layerVertexNode == null || !layerVertexNode.has("layerConf")
                        || !layerVertexNode.get("layerConf").has("layer")) {
                    return;
                }
                JsonNode layerWrapperNode = layerVertexNode.get("layerConf").get("layer");

                if (layerWrapperNode == null || layerWrapperNode.size() != 1) {
                    return;
                }

                JsonNode layerNode = layerWrapperNode.elements().next();
                JsonNode weightInit = layerNode.get("weightInit"); //Should only have 1 element: "dense", "output", etc
                JsonNode distribution = layerNode.get("dist");

                Distribution dist = null;
                if(distribution != null) {
                    dist = mapper.treeToValue(distribution, Distribution.class);
                }

                if (weightInit != null) {
                    final IWeightInit wi = WeightInit.valueOf(weightInit.asText()).getWeightInitFunction(dist);
                    ((BaseLayer) layer).setWeightInitFn(wi);
                }

            } catch (IOException e) {
                log.warn("Layer with null ActivationFn field or pre-0.7.2 activation function detected: could not parse JSON",
                        e);
            }
        }
    }
596236
public Weight add(Weight w) {
        if (w == null) {
            return new Weight(this);
        } else {
            boolean wIsInfinity = w.isInfinity;
            boolean wPosOrNeg = w.posOrNeg;
            if ((isInfinity && posOrNeg && wIsInfinity && !wPosOrNeg)
                    || (isInfinity && !posOrNeg && wIsInfinity && wPosOrNeg)) {
                throw new IllegalArgumentException("+inf - inf!");
            } else if ((isInfinity && posOrNeg) || (w.isInfinity && wPosOrNeg)) {
                return WeightFactory.POS_INFINITY;
            } else if ((isInfinity && !posOrNeg) || (wIsInfinity && !wPosOrNeg)) {
                return WeightFactory.NEG_INFINITY;
            } else {
                return new Weight(val + w.val);
            }
        }
    }
125217
public function addWeightFunction($weight, BuilderInterface $query = null)
    {
        $function = [
            'weight' => $weight,
        ];

        $this->applyFilter($function, $query);

        $this->functions[] = $function;

        return $this;
    }
1054426
public boolean fifoWeight(String pool) {
    Boolean result = poolFifoWeight.get(pool);
    return result == null ? false : result; // Default is false
  }
1044234
public static <T> FactorComparator<T> create(final String factorName, final int weight,
      final Comparator<T> comparator) {

    if (null == factorName || factorName.length() == 0 || weight < 0 || null == comparator) {
      logger.error(
          "failed to create instance of FactorComparator, at least one of the input paramters are invalid");
      return null;
    }

    return new FactorComparator<>(factorName, weight, comparator);
  }
651434
@Override
  public LoadBalancer createLoadBalancer(LoadBalancer loadBalancer)
      throws DigitalOceanException, RequestUnsuccessfulException {
    if (null == loadBalancer || StringUtils.isBlank(loadBalancer.getName())
        || null == loadBalancer.getRegion()) {
      throw new IllegalArgumentException(
          "Missing required parameters [Name, Region Slug] for create loadBalancer.");
    }
    validateForwardingRules(loadBalancer.getForwardingRules());
    validateHealthCheck(loadBalancer.getHealthCheck());

    return (LoadBalancer) perform(new ApiRequest(ApiAction.CREATE_LOAD_BALANCER, loadBalancer))
        .getData();
  }
1150572
public synchronized double getWeight(PoolInfo poolInfo) {
    Double weight = (poolInfoToWeight == null) ? null :
        poolInfoToWeight.get(poolInfo);
    return weight == null ? 1.0 : weight;
  }
1161413
@Override
  public SpanWeight createWeight(IndexSearcher searcher, boolean needsScores, float boost)
      throws IOException {
    final TermContext context;
    final IndexReaderContext topContext = searcher.getTopReaderContext();
    if (termContext == null) {
      context = TermContext.build(topContext, localTerm);
    } else {
      context = termContext;
    }
    return new SpanTermWeight(context, searcher,
        needsScores ? Collections.singletonMap(localTerm, context) : null, boost);
  }
589593
public IndexQueryBuilder setIndex(String indexName) {
        Preconditions.checkArgument(StringUtils.isNotBlank(indexName));
        this.indexName=indexName;
        return this;
    }
1210785
private MtasSolrCollectionResult createMtasSolrCollectionResult(
      ComponentCollection componentCollection, boolean storeIfRelevant)
      throws IOException {
    // System.out.println("collection: " + System.nanoTime() + " - "
    // + Thread.currentThread().getId() + " - " + " CREATE ");
    if (componentCollection != null) {
      // Create response
      MtasSolrCollectionResult data = new MtasSolrCollectionResult(
          componentCollection);
      if (componentCollection.action()
          .equals(ComponentCollection.ACTION_CREATE)) {
        if (storeIfRelevant && componentCollection.version == null) {
          componentCollection.version = searchComponent.getCollectionCache()
              .create(componentCollection.id,
                  componentCollection.values().size(),
                  componentCollection.values(), null);
        }
        data.setCreate(searchComponent.getCollectionCache().now(),
            searchComponent.getCollectionCache().check(componentCollection.id));
      } else if (componentCollection.action()
          .equals(ComponentCollection.ACTION_LIST)) {
        // retrieve and add list to result
        data.setList(searchComponent.getCollectionCache().now(),
            searchComponent.getCollectionCache().list());
      } else if (componentCollection.action()
          .equals(ComponentCollection.ACTION_CHECK)) {
        // retrieve and add status to result
        data.setCheck(searchComponent.getCollectionCache().now(),
            searchComponent.getCollectionCache().check(componentCollection.id));
      } else if (componentCollection.action()
          .equals(ComponentCollection.ACTION_GET)) {
        // retrieve and add status to result
        HashSet<String> values = searchComponent.getCollectionCache()
            .getDataById(componentCollection.id);
        if (values != null) {
          data.setGet(searchComponent.getCollectionCache().now(),
              searchComponent.getCollectionCache()
                  .check(componentCollection.id),
              values);
        }
      } else if (componentCollection.action()
          .equals(ComponentCollection.ACTION_EMPTY)) {
        // empty
        searchComponent.getCollectionCache().empty();
      } else if (componentCollection.action()
          .equals(ComponentCollection.ACTION_POST)) {
        // store if not already stored
        if (componentCollection.version == null) {
          componentCollection.version = searchComponent.getCollectionCache()
              .create(componentCollection.id,
                  componentCollection.values().size(),
                  componentCollection.values(), componentCollection.originalVersion());
        }
        // add status to result
        data.setPost(searchComponent.getCollectionCache().now(),
            searchComponent.getCollectionCache().check(componentCollection.id));
      } else if (componentCollection.action()
          .equals(ComponentCollection.ACTION_IMPORT)) {
        // import if not already stored
        if (componentCollection.version == null) {
          componentCollection.version = searchComponent.getCollectionCache()
              .create(componentCollection.id,
                  componentCollection.values().size(),
                  componentCollection.values(), null);
        }
        // add status to result
        data.setImport(searchComponent.getCollectionCache().now(),
            searchComponent.getCollectionCache().check(componentCollection.id));
      } else if (componentCollection.action()
          .equals(ComponentCollection.ACTION_DELETE)) {
        searchComponent.getCollectionCache().deleteById(componentCollection.id);
      }
      return data;
    } else {
      throw new IOException("no componentCollection available");
    }
  }
1342312
public Endpoint withWeight(int weight) {
        ensureSingle();
        validateWeight(weight);
        if (this.weight == weight) {
            return this;
        }
        return new Endpoint(host(), ipAddr(), port, weight, hostType);
    }
441627
def create_weight(self, weight, date=None):
        
        url = self._build_url('my', 'body', 'weight')
        data = {'weightInKilograms': weight}
        if date:
            if not date.is_aware():
                raise ValueError("provided date is not timezone aware")
            data.update(date=date.isoformat())
        headers = {'Content-Type': 'application/json; charset=utf8'}
        r = self.session.post(url, data=json.dumps(data), headers=headers)
        r.raise_for_status()
        return r
443340
@Override
  public SimpleOrderedMap<Object> create(ComponentStatus status, Boolean encode)
      throws IOException {
    SimpleOrderedMap<Object> mtasStatusResponse = new SimpleOrderedMap<>();
    if (status.getMtasHandler) {
      mtasStatusResponse.add(NAME_MTAS_STATUS_MTASHANDLER, status.handler);
    }
    if (status.getNumberOfDocuments) {
      mtasStatusResponse.add(NAME_MTAS_STATUS_NUMBEROFDOCUMENTS,
          status.numberOfDocuments);
    }
    if (status.getNumberOfSegments) {
      mtasStatusResponse.add(NAME_MTAS_STATUS_NUMBEROFSEGMENTS,
          status.numberOfSegments);
    }
    if(mtasStatusResponse.size()>0) {
      mtasStatusResponse.add(ShardInformation.NAME_NAME, status.name);
      if (status.key != null) {
        mtasStatusResponse.add(NAME_MTAS_STATUS_KEY, status.key); 
      }
      return mtasStatusResponse;
    } else {
      return null;
    }  
  }