public void TestReadFromBytes() { LongField field = new LongField(1); byte[] array = new byte[8]; try { field.ReadFromBytes(array); Assert.Fail("should have caught IndexOutOfRangeException"); } catch (IndexOutOfRangeException) { // as expected } field = new LongField(0); for (int j = 0; j < _test_array.Length; j++) { array[0] = ( byte )(_test_array[j] % 256); array[1] = ( byte )((_test_array[j] >> 8) % 256); array[2] = ( byte )((_test_array[j] >> 16) % 256); array[3] = ( byte )((_test_array[j] >> 24) % 256); array[4] = ( byte )((_test_array[j] >> 32) % 256); array[5] = ( byte )((_test_array[j] >> 40) % 256); array[6] = ( byte )((_test_array[j] >> 48) % 256); array[7] = ( byte )((_test_array[j] >> 56) % 256); field.ReadFromBytes(array); Assert.AreEqual(_test_array[j], field.Value, "testing " + j); } }
public static void TestLongField() { BehaviorTreeElement behaviorTree = new BehaviorTreeElement(); behaviorTree.StartNode = new NodeData(); LongField longField = new LongField(); longField.FieldName = "LongField"; longField.Value = 100; behaviorTree.StartNode.Fields.Add(longField); RepeatLongField repeatLongField = new RepeatLongField(); repeatLongField.FieldName = "RepeatLongField"; repeatLongField.Value = new List <long>(); repeatLongField.Value.Add(1); repeatLongField.Value.Add(100); repeatLongField.Value.Add(1000); repeatLongField.Value.Add(10000); behaviorTree.StartNode.Fields.Add(repeatLongField); byte[] bytes = Serializer.Serialize(behaviorTree); BehaviorTreeElement deBehaviorTreeData = Serializer.DeSerialize <BehaviorTreeElement>(bytes); }
public void TestSet() { LongField field = new LongField(0); byte[] array = new byte[8]; for (int j = 0; j < _test_array.Length; j++) { field.Value = _test_array[j]; Assert.AreEqual(_test_array[j], field.Value, "testing _1 " + j); field = new LongField(0); field.Set(_test_array[j], array); Assert.AreEqual(_test_array[j], field.Value, "testing _2 "); Assert.AreEqual(( byte )(_test_array[j] % 256), array[0], "testing _3.0 " + _test_array[j]); Assert.AreEqual(( byte )((_test_array[j] >> 8) % 256), array[1], "testing _3.1 " + _test_array[j]); Assert.AreEqual(( byte )((_test_array[j] >> 16) % 256), array[2], "testing _3.2 " + _test_array[j]); Assert.AreEqual(( byte )((_test_array[j] >> 24) % 256), array[3], "testing _3.3 " + _test_array[j]); Assert.AreEqual(( byte )((_test_array[j] >> 32) % 256), array[4], "testing _3.4 " + _test_array[j]); Assert.AreEqual(( byte )((_test_array[j] >> 40) % 256), array[5], "testing _3.5 " + _test_array[j]); Assert.AreEqual(( byte )((_test_array[j] >> 48) % 256), array[6], "testing _3.6 " + _test_array[j]); Assert.AreEqual(( byte )((_test_array[j] >> 56) % 256), array[7], "testing _3.7 " + _test_array[j]); } }
public static void TestLongField() { AgentData agent = new AgentData(); agent.StartNode = new NodeData(); LongField longField = new LongField(); longField.FieldName = "LongField"; longField.Value = 100; agent.StartNode.Fields.Add(longField); RepeatLongField repeatLongField = new RepeatLongField(); repeatLongField.FieldName = "RepeatLongField"; repeatLongField.Value = new List <long>(); repeatLongField.Value.Add(1); repeatLongField.Value.Add(100); repeatLongField.Value.Add(1000); repeatLongField.Value.Add(10000); agent.StartNode.Fields.Add(repeatLongField); byte[] bytes = Serializer.Serialize(agent); AgentData deAgentData = Serializer.DeSerialize <AgentData>(bytes); }
public static IndexableField InstantiateField(string key, object value, FieldType fieldType) { IndexableField field; if (value is Number) { Number number = ( Number )value; if (value is long?) { field = new LongField(key, number.longValue(), Field.Store.YES); } else if (value is float?) { field = new FloatField(key, number.floatValue(), Field.Store.YES); } else if (value is double?) { field = new DoubleField(key, number.doubleValue(), Field.Store.YES); } else { field = new IntField(key, number.intValue(), Field.Store.YES); } } else { field = new Field(key, value.ToString(), fieldType); } return(field); }
public void TestReadFromStream() { LongField field = new LongField(0); byte[] buffer = new byte[_test_array.Length * 8]; for (int j = 0; j < _test_array.Length; j++) { buffer[(j * 8) + 0] = ( byte )(_test_array[j] % 256); buffer[(j * 8) + 1] = ( byte )((_test_array[j] >> 8) % 256); buffer[(j * 8) + 2] = ( byte )((_test_array[j] >> 16) % 256); buffer[(j * 8) + 3] = ( byte )((_test_array[j] >> 24) % 256); buffer[(j * 8) + 4] = ( byte )((_test_array[j] >> 32) % 256); buffer[(j * 8) + 5] = ( byte )((_test_array[j] >> 40) % 256); buffer[(j * 8) + 6] = ( byte )((_test_array[j] >> 48) % 256); buffer[(j * 8) + 7] = ( byte )((_test_array[j] >> 56) % 256); } MemoryStream stream = new MemoryStream(buffer); for (int j = 0; j < buffer.Length / 8; j++) { field.ReadFromStream(stream); Assert.AreEqual(_test_array[j], field.Value, "Testing " + j); } }
/** * Checks if the supplied first 8 bytes of a stream / file * has a POIFS (OLE2) header. */ public static bool HasPOIFSHeader(byte[] header8Bytes) { LongField signature = new LongField(HeaderBlockConstants._signature_offset, header8Bytes); // Did it match the signature? return(signature.Value == HeaderBlockConstants._signature); }
/// <summary> /// Checks that the supplied Stream(which MUST /// support mark and reset, or be a PushbackInputStream) /// has a POIFS (OLE2) header at the start of it. /// If your Streamdoes not support mark / reset, /// then wrap it in a PushBackInputStream, then be /// sure to always use that, and not the original! /// </summary> /// <param name="inp">An Streamwhich supports either mark/reset, or is a PushbackStream</param> /// <returns> /// <c>true</c> if [has POIFS header] [the specified inp]; otherwise, <c>false</c>. /// </returns> public static bool HasPOIFSHeader(Stream inp) { byte[] header = new byte[8]; IOUtils.ReadFully(inp, header); LongField signature = new LongField(HeaderBlockConstants._signature_offset, header); return(signature.Value == HeaderBlockConstants._signature); }
public static void RenderLongProperty(VisualElement container, string name, object value, Action <object> setter) { var field = new LongField(name); field.SetValueWithoutNotify((long)value); field.MarkDirtyRepaint(); field.RegisterValueChangedCallback(evt => setter(evt.newValue)); container.Add(field); }
public virtual void TestLongFieldCache() { Directory dir = NewDirectory(); IndexWriterConfig cfg = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())); cfg.SetMergePolicy(NewLogMergePolicy()); RandomIndexWriter iw = new RandomIndexWriter(Random(), dir, cfg); Document doc = new Document(); LongField field = new LongField("f", 0L, Field.Store.YES); doc.Add(field); long[] values = new long[TestUtil.NextInt(Random(), 1, 10)]; for (int i = 0; i < values.Length; ++i) { long v; switch (Random().Next(10)) { case 0: v = long.MinValue; break; case 1: v = 0; break; case 2: v = long.MaxValue; break; default: v = TestUtil.NextLong(Random(), -10, 10); break; } values[i] = v; if (v == 0 && Random().NextBoolean()) { // missing iw.AddDocument(new Document()); } else { field.LongValue = v; iw.AddDocument(doc); } } iw.ForceMerge(1); DirectoryReader reader = iw.Reader; Longs longs = FieldCache.DEFAULT.GetLongs(GetOnlySegmentReader(reader), "f", false); for (int i = 0; i < values.Length; ++i) { Assert.AreEqual(values[i], longs.Get(i)); } reader.Dispose(); iw.Dispose(); dir.Dispose(); }
/** * Checks that the supplied InputStream (which MUST * support mark and reset, or be a PushbackInputStream) * has a POIFS (OLE2) header at the start of it. * If your InputStream does not support mark / reset, * then wrap it in a PushBackInputStream, then be * sure to always use that, and not the original! * @param inp An InputStream which supports either mark/reset, or is a PushbackInputStream */ public static bool HasPOIFSHeader(Stream inp) { // We want to peek at the first 8 bytes //inp.Mark(8); byte[] header = new byte[8]; IOUtils.ReadFully(inp, header); LongField signature = new LongField(HeaderBlockConstants._signature_offset, header); // Wind back those 8 bytes inp.Position = 0; // Did it match the signature? return(signature.Value == HeaderBlockConstants._signature); }
public VFXLongSliderField() { m_Slider = new Slider(0, 1, SliderDirection.Horizontal); m_Slider.AddToClassList("textfield"); m_Slider.RegisterValueChangedCallback(evt => ValueChanged(evt.newValue)); var integerField = new LongField(); integerField.RegisterValueChangedCallback(ValueChanged); integerField.name = "Field"; m_Field = integerField; Add(m_Slider); Add(integerField); RegisterCallBack(); }
public VFXLongSliderField() { m_Slider = new Slider(0, 1, ValueChanged, SliderDirection.Horizontal, 0.1f); m_Slider.AddToClassList("textfield"); m_Slider.valueChanged += ValueChanged; var integerField = new LongField(); integerField.RegisterCallback <ChangeEvent <long> >(ValueChanged); integerField.name = "Field"; m_Field = integerField; Add(m_Slider); Add(integerField); RegisterCallBack(); }
public override VisualElement Build() { var container = new VisualElement(); _isCreatedField = new Toggle("Is Created"); _addressField = new LongField("Address"); _typeField = new EnumField("Type", CCC.Fix2D.ColliderType.Invalid); _radiusField = new FloatField("Radius"); container.Add(_isCreatedField); container.Add(_addressField); container.Add(_typeField); container.Add(_radiusField); return(container); }
public override VisualElement CreatePropertyGUI(SerializedProperty property) { BindableElement newField = null; if (property.propertyType == SerializedPropertyType.Float) { if (property.type == "float") { newField = new FloatField(property.displayName); ((TextInputBaseField <float>)newField).isDelayed = true; } else if (property.type == "double") { newField = new DoubleField(property.displayName); ((TextInputBaseField <double>)newField).isDelayed = true; } } else if (property.propertyType == SerializedPropertyType.Integer) { if (property.type == "int") { newField = new IntegerField(property.displayName); ((TextInputBaseField <int>)newField).isDelayed = true; } else if (property.type == "long") { newField = new LongField(property.displayName); ((TextInputBaseField <long>)newField).isDelayed = true; } } else if (property.propertyType == SerializedPropertyType.String) { newField = new TextField(property.displayName); ((TextInputBaseField <string>)newField).isDelayed = true; } if (newField != null) { newField.bindingPath = property.propertyPath; return(newField); } return(new Label(s_InvalidTypeMessage)); }
private void DrawValueField() { // Clear previous field if (fieldContainer.Children().Any()) { fieldContainer.Clear(); } // Create a type-specific field for each different variable type, set the right value (mainly null handling), // and register the type-specific callback VisualElement field; switch (worldVars.GetType(guid)) { case VariableType.String: field = new TextField(); field.RegisterCallback <ChangeEvent <string> >(UpdateWorldvarValue); break; case VariableType.Bool: field = new Toggle(); field.RegisterCallback <ChangeEvent <bool> >(UpdateWorldvarValue); break; case VariableType.Long: field = new LongField(); field.RegisterCallback <ChangeEvent <long> >(UpdateWorldvarValue); break; case VariableType.Double: field = new DoubleField(); field.RegisterCallback <ChangeEvent <double> >(UpdateWorldvarValue); break; default: throw new ArgumentOutOfRangeException(); } field.name = fieldName; fieldContainer.Add(field); SetFieldValue(worldVars.GetValue(guid)); }
public static void TestNode() { //创建AgentData AgentData agent = new AgentData(); //添加开始节点 agent.StartNode = new NodeData(); //开始节点字段 IntField intField = new IntField(); intField.FieldName = "IntField"; intField.Value = 100; agent.StartNode.Fields.Add(intField); //创建开始节点的第一个子节点 NodeData node1 = new NodeData(); //子节点1的枚举字段 EnumField enumField = new EnumField(); enumField.FieldName = "EnumField"; enumField.Value = 100; node1.Fields.Add(enumField); //创建开始节点的第二个子节点 NodeData node2 = new NodeData(); //子节点2的Long字段 LongField longField = new LongField(); longField.FieldName = "LongField"; longField.Value = 100; node2.Fields.Add(longField); agent.StartNode.Childs = new List <NodeData>(); agent.StartNode.Childs.Add(node1); agent.StartNode.Childs.Add(node2); byte[] bytes = Serializer.Serialize(agent); AgentData deAgentData = Serializer.DeSerialize <AgentData>(bytes); }
public static void TestNode() { BehaviorTreeElement behaviorTree = new BehaviorTreeElement(); //添加开始节点 behaviorTree.StartNode = new NodeData(); //开始节点字段 IntField intField = new IntField(); intField.FieldName = "IntField"; intField.Value = 100; behaviorTree.StartNode.Fields.Add(intField); //创建开始节点的第一个子节点 NodeData node1 = new NodeData(); //子节点1的枚举字段 EnumField enumField = new EnumField(); enumField.FieldName = "EnumField"; enumField.Value = 100; node1.Fields.Add(enumField); //创建开始节点的第二个子节点 NodeData node2 = new NodeData(); //子节点2的Long字段 LongField longField = new LongField(); longField.FieldName = "LongField"; longField.Value = 100; node2.Fields.Add(longField); behaviorTree.StartNode.Childs = new List <NodeData>(); behaviorTree.StartNode.Childs.Add(node1); behaviorTree.StartNode.Childs.Add(node2); byte[] bytes = Serializer.Serialize(behaviorTree); BehaviorTreeElement deBehaviorTreeData = Serializer.DeSerialize <BehaviorTreeElement>(bytes); }
internal override void Apply(VisualElement container) { /// <sample> // Get a reference to the field from UXML and assign it its value. var uxmlField = container.Q <LongField>("the-uxml-field"); uxmlField.value = 42; // Create a new field, disable it, and give it a style class. var csharpField = new LongField("C# Field"); csharpField.SetEnabled(false); csharpField.AddToClassList("some-styled-field"); csharpField.value = uxmlField.value; container.Add(csharpField); // Mirror value of uxml field into the C# field. uxmlField.RegisterCallback <ChangeEvent <long> >((evt) => { csharpField.value = evt.newValue; }); /// </sample> }
public void TestWriteToBytes() { LongField field = new LongField(0); byte[] array = new byte[8]; for (int j = 0; j < _test_array.Length; j++) { field.Value = _test_array[j]; field.WriteToBytes(array); long val = (( long )array[7]) << 56; val &= unchecked ((long)0xFF00000000000000L); val += ((( long )array[6]) << 48) & 0x00FF000000000000L; val += ((( long )array[5]) << 40) & 0x0000FF0000000000L; val += ((( long )array[4]) << 32) & 0x000000FF00000000L; val += ((( long )array[3]) << 24) & 0x00000000FF000000L; val += ((( long )array[2]) << 16) & 0x0000000000FF0000L; val += ((( long )array[1]) << 8) & 0x000000000000FF00L; val += (array[0] & 0x00000000000000FFL); Assert.AreEqual(_test_array[j], val, "testing "); } }
/** * Checks that the supplied InputStream (which MUST * support mark and reset, or be a PushbackInputStream) * has a POIFS (OLE2) header at the start of it. * If your InputStream does not support mark / reset, * then wrap it in a PushBackInputStream, then be * sure to always use that, and not the original! * @param inp An InputStream which supports either mark/reset, or is a PushbackInputStream */ public static bool HasPOIFSHeader(Stream inp) { // We want to peek at the first 8 bytes //inp.Mark(8); byte[] header = new byte[8]; int bytesRead = IOUtils.ReadFully(inp, header); LongField signature = new LongField(HeaderBlockConstants._signature_offset, header); // Wind back those 8 bytes if (inp is PushbackInputStream) { PushbackInputStream pin = (PushbackInputStream)inp; pin.Unread(header, 0, bytesRead); } else { inp.Position = 0; } // Did it match the signature? return(signature.Value == HeaderBlockConstants._signature); }
public override VisualElement CreatePropertyGUI(SerializedProperty property) { BindableElement newField = null; if (property.propertyType == SerializedPropertyType.Float) { if (property.type == "float") { newField = new FloatField(property.displayName); ((BaseField <float>)newField).onValidateValue += OnValidateValue; } else if (property.type == "double") { newField = new DoubleField(property.displayName); ((BaseField <double>)newField).onValidateValue += OnValidateValue; } } else if (property.propertyType == SerializedPropertyType.Integer) { if (property.type == "int") { newField = new IntegerField(property.displayName); ((BaseField <int>)newField).onValidateValue += OnValidateValue; } else if (property.type == "long") { newField = new LongField(property.displayName); ((BaseField <long>)newField).onValidateValue += OnValidateValue; } } else if (property.propertyType == SerializedPropertyType.Vector2) { newField = new Vector2Field(property.displayName); ((BaseField <Vector2>)newField).onValidateValue += OnValidateValue; } else if (property.propertyType == SerializedPropertyType.Vector2Int) { newField = new Vector2IntField(property.displayName); ((BaseField <Vector2Int>)newField).onValidateValue += OnValidateValue; } else if (property.propertyType == SerializedPropertyType.Vector3) { newField = new Vector3Field(property.displayName); ((BaseField <Vector3>)newField).onValidateValue += OnValidateValue; } else if (property.propertyType == SerializedPropertyType.Vector3Int) { newField = new Vector3IntField(property.displayName); ((BaseField <Vector3Int>)newField).onValidateValue += OnValidateValue; } else if (property.propertyType == SerializedPropertyType.Vector4) { newField = new Vector4Field(property.displayName); ((BaseField <Vector4>)newField).onValidateValue += OnValidateValue; } if (newField != null) { newField.bindingPath = property.propertyPath; return(newField); } return(new Label(s_InvalidTypeMessage)); }
public void BeforeClass() { ANALYZER = new MockAnalyzer(Random()); qp = new StandardQueryParser(ANALYZER); HashMap <String, /*Number*/ object> randomNumberMap = new HashMap <string, object>(); /*SimpleDateFormat*/ string dateFormat; long randomDate; bool dateFormatSanityCheckPass; int count = 0; do { if (count > 100) { fail("This test has problems to find a sane random DateFormat/NumberFormat. Stopped trying after 100 iterations."); } dateFormatSanityCheckPass = true; LOCALE = randomLocale(Random()); TIMEZONE = randomTimeZone(Random()); DATE_STYLE = randomDateStyle(Random()); TIME_STYLE = randomDateStyle(Random()); //// assumes localized date pattern will have at least year, month, day, //// hour, minute //dateFormat = (SimpleDateFormat)DateFormat.getDateTimeInstance( // DATE_STYLE, TIME_STYLE, LOCALE); //// not all date patterns includes era, full year, timezone and second, //// so we add them here //dateFormat.applyPattern(dateFormat.toPattern() + " G s Z yyyy"); //dateFormat.setTimeZone(TIMEZONE); DATE_FORMAT = new NumberDateFormat(DATE_STYLE, TIME_STYLE, LOCALE) { TimeZone = TIMEZONE }; dateFormat = DATE_FORMAT.GetDateFormat(); do { randomDate = Random().nextLong(); // prune date value so it doesn't pass in insane values to some // calendars. randomDate = randomDate % 3400000000000L; // truncate to second randomDate = (randomDate / 1000L) * 1000L; // only positive values randomDate = Math.Abs(randomDate); } while (randomDate == 0L); dateFormatSanityCheckPass &= checkDateFormatSanity(dateFormat, randomDate); dateFormatSanityCheckPass &= checkDateFormatSanity(dateFormat, 0); dateFormatSanityCheckPass &= checkDateFormatSanity(dateFormat, -randomDate); count++; } while (!dateFormatSanityCheckPass); //NUMBER_FORMAT = NumberFormat.getNumberInstance(LOCALE); //NUMBER_FORMAT.setMaximumFractionDigits((Random().nextInt() & 20) + 1); //NUMBER_FORMAT.setMinimumFractionDigits((Random().nextInt() & 20) + 1); //NUMBER_FORMAT.setMaximumIntegerDigits((Random().nextInt() & 20) + 1); //NUMBER_FORMAT.setMinimumIntegerDigits((Random().nextInt() & 20) + 1); NUMBER_FORMAT = new NumberFormat(LOCALE); double randomDouble; long randomLong; int randomInt; float randomFloat; while ((randomLong = Convert.ToInt64(NormalizeNumber(Math.Abs(Random().nextLong())) )) == 0L) { ; } while ((randomDouble = Convert.ToDouble(NormalizeNumber(Math.Abs(Random().NextDouble())) )) == 0.0) { ; } while ((randomFloat = Convert.ToSingle(NormalizeNumber(Math.Abs(Random().nextFloat())) )) == 0.0f) { ; } while ((randomInt = Convert.ToInt32(NormalizeNumber(Math.Abs(Random().nextInt())))) == 0) { ; } randomNumberMap.Put(FieldType.NumericType.LONG.ToString(), randomLong); randomNumberMap.Put(FieldType.NumericType.INT.ToString(), randomInt); randomNumberMap.Put(FieldType.NumericType.FLOAT.ToString(), randomFloat); randomNumberMap.Put(FieldType.NumericType.DOUBLE.ToString(), randomDouble); randomNumberMap.Put(DATE_FIELD_NAME, randomDate); RANDOM_NUMBER_MAP = Collections.UnmodifiableMap(randomNumberMap); directory = NewDirectory(); RandomIndexWriter writer = new RandomIndexWriter(Random(), directory, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())) .SetMaxBufferedDocs(TestUtil.NextInt(Random(), 50, 1000)) .SetMergePolicy(NewLogMergePolicy())); Document doc = new Document(); HashMap <String, NumericConfig> numericConfigMap = new HashMap <String, NumericConfig>(); HashMap <String, Field> numericFieldMap = new HashMap <String, Field>(); qp.NumericConfigMap = (numericConfigMap); foreach (FieldType.NumericType type in Enum.GetValues(typeof(FieldType.NumericType))) { numericConfigMap.Put(type.ToString(), new NumericConfig(PRECISION_STEP, NUMBER_FORMAT, type)); FieldType ft2 = new FieldType(IntField.TYPE_NOT_STORED); ft2.NumericTypeValue = (type); ft2.Stored = (true); ft2.NumericPrecisionStep = (PRECISION_STEP); ft2.Freeze(); Field field; switch (type) { case FieldType.NumericType.INT: field = new IntField(type.ToString(), 0, ft2); break; case FieldType.NumericType.FLOAT: field = new FloatField(type.ToString(), 0.0f, ft2); break; case FieldType.NumericType.LONG: field = new LongField(type.ToString(), 0L, ft2); break; case FieldType.NumericType.DOUBLE: field = new DoubleField(type.ToString(), 0.0, ft2); break; default: fail(); field = null; break; } numericFieldMap.Put(type.ToString(), field); doc.Add(field); } numericConfigMap.Put(DATE_FIELD_NAME, new NumericConfig(PRECISION_STEP, DATE_FORMAT, FieldType.NumericType.LONG)); FieldType ft = new FieldType(LongField.TYPE_NOT_STORED); ft.Stored = (true); ft.NumericPrecisionStep = (PRECISION_STEP); LongField dateField = new LongField(DATE_FIELD_NAME, 0L, ft); numericFieldMap.Put(DATE_FIELD_NAME, dateField); doc.Add(dateField); foreach (NumberType numberType in Enum.GetValues(typeof(NumberType))) { setFieldValues(numberType, numericFieldMap); if (VERBOSE) { Console.WriteLine("Indexing document: " + doc); } writer.AddDocument(doc); } reader = writer.Reader; searcher = NewSearcher(reader); writer.Dispose(); }
public static long test() { var obj = new LongField(); return obj.method(); }
BuilderStyleRow CreateAttributeRow(UxmlAttributeDescription attribute) { var attributeType = attribute.GetType(); // Generate field label. var fieldLabel = BuilderNameUtilities.ConvertDashToHuman(attribute.name); BindableElement fieldElement; if (attribute is UxmlStringAttributeDescription) { // Hard-coded if (attribute.name.Equals("value") && currentVisualElement is EnumField enumField) { var uiField = new EnumField("Value"); if (null != enumField.value) { uiField.Init(enumField.value, enumField.includeObsoleteValues); } else { uiField.SetValueWithoutNotify(null); } uiField.RegisterValueChangedCallback(evt => PostAttributeValueChange(uiField, uiField.value.ToString())); fieldElement = uiField; } else if (attribute.name.Equals("value") && currentVisualElement is TagField tagField) { var uiField = new TagField("Value"); uiField.RegisterValueChangedCallback(evt => PostAttributeValueChange(uiField, uiField.value.ToString())); fieldElement = uiField; } else { var uiField = new TextField(fieldLabel); if (attribute.name.Equals("name") || attribute.name.Equals("view-data-key")) { uiField.RegisterValueChangedCallback(e => { OnValidatedAttributeValueChange(e, BuilderNameUtilities.attributeRegex, BuilderConstants.AttributeValidationSpacialCharacters); }); } else if (attribute.name.Equals("binding-path")) { uiField.RegisterValueChangedCallback(e => { OnValidatedAttributeValueChange(e, BuilderNameUtilities.bindingPathAttributeRegex, BuilderConstants.BindingPathAttributeValidationSpacialCharacters); }); } else { uiField.RegisterValueChangedCallback(OnAttributeValueChange); } if (attribute.name.Equals("text") || attribute.name.Equals("label")) { uiField.multiline = true; uiField.AddToClassList(BuilderConstants.InspectorMultiLineTextFieldClassName); } fieldElement = uiField; } } else if (attribute is UxmlFloatAttributeDescription) { var uiField = new FloatField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlDoubleAttributeDescription) { var uiField = new DoubleField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlIntAttributeDescription) { if (attribute.name.Equals("value") && currentVisualElement is LayerField) { var uiField = new LayerField("Value"); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute.name.Equals("value") && currentVisualElement is LayerMaskField) { var uiField = new LayerMaskField("Value"); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else { var uiField = new IntegerField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } } else if (attribute is UxmlLongAttributeDescription) { var uiField = new LongField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlBoolAttributeDescription) { var uiField = new Toggle(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlColorAttributeDescription) { var uiField = new ColorField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attributeType.IsGenericType && !attributeType.GetGenericArguments()[0].IsEnum && attributeType.GetGenericArguments()[0] is Type) { var desiredType = attributeType.GetGenericArguments()[0]; var uiField = new TextField(fieldLabel) { isDelayed = true }; var completer = new FieldSearchCompleter <TypeInfo>(uiField); uiField.RegisterCallback <AttachToPanelEvent, FieldSearchCompleter <TypeInfo> >((evt, c) => { // When possible, the popup should have the same width as the input field, so that the auto-complete // characters will try to match said input field. c.popup.anchoredControl = ((VisualElement)evt.target).Q(className: "unity-text-field__input"); }, completer); completer.matcherCallback += (str, info) => info.value.IndexOf(str, StringComparison.OrdinalIgnoreCase) >= 0; completer.itemHeight = 36; completer.dataSourceCallback += () => { return(TypeCache.GetTypesDerivedFrom(desiredType) .Where(t => !t.IsGenericType) // Remove UIBuilder types from the list .Where(t => t.Assembly != GetType().Assembly) .Select(GetTypeInfo)); }; completer.getTextFromDataCallback += info => info.value; completer.makeItem = () => s_TypeNameItemPool.Get(); completer.destroyItem = e => { if (e is BuilderAttributeTypeName typeItem) { s_TypeNameItemPool.Release(typeItem); } }; completer.bindItem = (v, i) => { if (v is BuilderAttributeTypeName l) { l.SetType(completer.results[i].type, completer.textField.text); } }; uiField.RegisterValueChangedCallback(e => OnValidatedTypeAttributeChange(e, desiredType)); fieldElement = uiField; uiField.RegisterCallback <DetachFromPanelEvent, FieldSearchCompleter <TypeInfo> >((evt, c) => { c.popup.RemoveFromHierarchy(); }, completer); uiField.userData = completer; } else if (attributeType.IsGenericType && attributeType.GetGenericArguments()[0].IsEnum) { var propInfo = attributeType.GetProperty("defaultValue"); var defaultEnumValue = propInfo.GetValue(attribute, null) as Enum; if (defaultEnumValue.GetType().GetCustomAttribute <FlagsAttribute>() == null) { // Create and initialize the EnumField. var uiField = new EnumField(fieldLabel); uiField.Init(defaultEnumValue); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else { // Create and initialize the EnumField. var uiField = new EnumFlagsField(fieldLabel); uiField.Init(defaultEnumValue); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } } else { var uiField = new TextField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } // Create row. var styleRow = new BuilderStyleRow(); styleRow.Add(fieldElement); // Link the field. fieldElement.SetProperty(BuilderConstants.InspectorLinkedStyleRowVEPropertyName, styleRow); fieldElement.SetProperty(BuilderConstants.InspectorLinkedAttributeDescriptionVEPropertyName, attribute); // Set initial value. RefreshAttributeField(fieldElement); // Setup field binding path. fieldElement.bindingPath = attribute.name; fieldElement.tooltip = attribute.name; // Context menu. fieldElement.AddManipulator(new ContextualMenuManipulator(BuildAttributeFieldContextualMenu)); return(styleRow); }
public void BeforeClass() { NoDocs = AtLeast(4096); Distance = (1L << 60) / NoDocs; Directory = NewDirectory(); RandomIndexWriter writer = new RandomIndexWriter(Random(), Directory, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetMaxBufferedDocs(TestUtil.NextInt(Random(), 100, 1000)).SetMergePolicy(NewLogMergePolicy())); FieldType storedLong = new FieldType(LongField.TYPE_NOT_STORED); storedLong.Stored = true; storedLong.Freeze(); FieldType storedLong8 = new FieldType(storedLong); storedLong8.NumericPrecisionStep = 8; FieldType storedLong4 = new FieldType(storedLong); storedLong4.NumericPrecisionStep = 4; FieldType storedLong6 = new FieldType(storedLong); storedLong6.NumericPrecisionStep = 6; FieldType storedLong2 = new FieldType(storedLong); storedLong2.NumericPrecisionStep = 2; FieldType storedLongNone = new FieldType(storedLong); storedLongNone.NumericPrecisionStep = int.MaxValue; FieldType unstoredLong = LongField.TYPE_NOT_STORED; FieldType unstoredLong8 = new FieldType(unstoredLong); unstoredLong8.NumericPrecisionStep = 8; FieldType unstoredLong6 = new FieldType(unstoredLong); unstoredLong6.NumericPrecisionStep = 6; FieldType unstoredLong4 = new FieldType(unstoredLong); unstoredLong4.NumericPrecisionStep = 4; FieldType unstoredLong2 = new FieldType(unstoredLong); unstoredLong2.NumericPrecisionStep = 2; LongField field8 = new LongField("field8", 0L, storedLong8), field6 = new LongField("field6", 0L, storedLong6), field4 = new LongField("field4", 0L, storedLong4), field2 = new LongField("field2", 0L, storedLong2), fieldNoTrie = new LongField("field" + int.MaxValue, 0L, storedLongNone), ascfield8 = new LongField("ascfield8", 0L, unstoredLong8), ascfield6 = new LongField("ascfield6", 0L, unstoredLong6), ascfield4 = new LongField("ascfield4", 0L, unstoredLong4), ascfield2 = new LongField("ascfield2", 0L, unstoredLong2); Document doc = new Document(); // add fields, that have a distance to test general functionality doc.Add(field8); doc.Add(field6); doc.Add(field4); doc.Add(field2); doc.Add(fieldNoTrie); // add ascending fields with a distance of 1, beginning at -noDocs/2 to test the correct splitting of range and inclusive/exclusive doc.Add(ascfield8); doc.Add(ascfield6); doc.Add(ascfield4); doc.Add(ascfield2); // Add a series of noDocs docs with increasing long values, by updating the fields for (int l = 0; l < NoDocs; l++) { long val = Distance * l + StartOffset; field8.LongValue = val; field6.LongValue = val; field4.LongValue = val; field2.LongValue = val; fieldNoTrie.LongValue = val; val = l - (NoDocs / 2); ascfield8.LongValue = val; ascfield6.LongValue = val; ascfield4.LongValue = val; ascfield2.LongValue = val; writer.AddDocument(doc); } Reader = writer.Reader; Searcher = NewSearcher(Reader); writer.Dispose(); }
BuilderStyleRow CreateAttributeRow(UxmlAttributeDescription attribute) { var attributeType = attribute.GetType(); // Generate field label. var fieldLabel = BuilderNameUtilities.ConvertDashToHuman(attribute.name); BindableElement fieldElement; if (attribute is UxmlStringAttributeDescription) { var uiField = new TextField(fieldLabel); if (attribute.name.Equals("name") || attribute.name.Equals("view-data-key")) { uiField.RegisterValueChangedCallback(e => { OnValidatedAttributeValueChange(e, BuilderNameUtilities.AttributeRegex, BuilderConstants.AttributeValidationSpacialCharacters); }); } else if (attribute.name.Equals("binding-path")) { uiField.RegisterValueChangedCallback(e => { OnValidatedAttributeValueChange(e, BuilderNameUtilities.BindingPathAttributeRegex, BuilderConstants.BindingPathAttributeValidationSpacialCharacters); }); } else { uiField.RegisterValueChangedCallback(OnAttributeValueChange); } if (attribute.name.Equals("text")) { uiField.multiline = true; uiField.AddToClassList(BuilderConstants.InspectorMultiLineTextFieldClassName); } fieldElement = uiField; } else if (attribute is UxmlFloatAttributeDescription) { var uiField = new FloatField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlDoubleAttributeDescription) { var uiField = new DoubleField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlIntAttributeDescription) { var uiField = new IntegerField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlLongAttributeDescription) { var uiField = new LongField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlBoolAttributeDescription) { var uiField = new Toggle(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlColorAttributeDescription) { var uiField = new ColorField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attributeType.IsGenericType && !attributeType.GetGenericArguments()[0].IsEnum && attributeType.GetGenericArguments()[0] is Type) { var uiField = new TextField(fieldLabel); uiField.isDelayed = true; uiField.RegisterValueChangedCallback(e => { OnValidatedTypeAttributeChange(e, attributeType.GetGenericArguments()[0]); }); fieldElement = uiField; } else if (attributeType.IsGenericType && attributeType.GetGenericArguments()[0].IsEnum) { var propInfo = attributeType.GetProperty("defaultValue"); var enumValue = propInfo.GetValue(attribute, null) as Enum; // Create and initialize the EnumField. var uiField = new EnumField(fieldLabel); uiField.Init(enumValue); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else { var uiField = new TextField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } // Create row. var styleRow = new BuilderStyleRow(); styleRow.Add(fieldElement); // Link the field. fieldElement.SetProperty(BuilderConstants.InspectorLinkedStyleRowVEPropertyName, styleRow); fieldElement.SetProperty(BuilderConstants.InspectorLinkedAttributeDescriptionVEPropertyName, attribute); // Set initial value. RefreshAttributeField(fieldElement); // Setup field binding path. fieldElement.bindingPath = attribute.name; // Tooltip. var label = fieldElement.Q <Label>(); if (label != null) { label.tooltip = attribute.name; } else { fieldElement.tooltip = attribute.name; } // Context menu. fieldElement.AddManipulator(new ContextualMenuManipulator(BuildAttributeFieldContextualMenu)); return(styleRow); }
void CreateUIElements() { var titleRow = new VisualElement() { style = { flexDirection = FlexDirection.Row, flexShrink = 0f, justifyContent = Justify.SpaceBetween } }; m_VisualElementContainer.Add(new Label("VisualElements Container")); var curveX = AnimationCurve.Linear(0, 0, 1, 0); var popupFieldValues = new List <SomeClass> { new SomeClass("First Class Value"), new SomeClass("Second Value"), new SomeClass("Another Value"), new SomeClass("Another Value with a very lonnnnnnnnnnnnnnnnnnnnnnnnng text to make sure this is really overflowing the popup field.") }; var maskFieldOptions = new List <string>(m_MaskFieldOptions); m_VisualElementContainer.Add(m_IntegerField = new IntegerField()); m_VisualElementContainer.Add(m_LongField = new LongField()); m_VisualElementContainer.Add(m_FloatField = new FloatField()); m_VisualElementContainer.Add(m_DoubleField = new DoubleField()); m_VisualElementContainer.Add(m_EnumField = new EnumField(EnumValues.Two)); m_VisualElementContainer.Add(m_TextField = new TextField()); m_VisualElementContainer.Add(m_PasswordField = new TextField() { isPasswordField = true, maskChar = '*' }); m_VisualElementContainer.Add(m_Vector3Field = new Vector3Field()); m_VisualElementContainer.Add(m_Vector3IntField = new Vector3IntField()); m_VisualElementContainer.Add(m_Vector2Field = new Vector2Field()); m_VisualElementContainer.Add(m_ColorField = new ColorField()); m_VisualElementContainer.Add(m_ObjectFieldCamera = new ObjectField() { objectType = typeof(Camera) }); m_VisualElementContainer.Add(m_ObjectFieldGameObject = new ObjectField() { objectType = typeof(GameObject) }); m_VisualElementContainer.Add(m_CurveField = new CurveField() { value = curveX }); m_VisualElementContainer.Add(m_CurveFieldMesh = new CurveField() { value = curveX, renderMode = CurveField.RenderMode.Mesh }); m_VisualElementContainer.Add(m_PopupField = new PopupField <SomeClass>(popupFieldValues, popupFieldValues[1])); m_VisualElementContainer.Add(m_RectField = new RectField()); m_VisualElementContainer.Add(m_BoundsField = new BoundsField()); m_VisualElementContainer.Add(m_ToggleField = new Toggle()); m_VisualElementContainer.Add(m_MaskField = new MaskField(maskFieldOptions, 6)); m_VisualElementContainer.Add(m_LayerField = new LayerField()); m_VisualElementContainer.Add(m_TagField = new TagField()); m_VisualElementContainer.Add(m_MinMaxSliderField = new MinMaxSlider(5, 10, 0, 125)); m_VisualElementContainer.Add(m_Slider = new Slider(2, 8)); m_VisualElementContainer.Add(m_SliderInt = new SliderInt(11, 23)); var buttonRow = new VisualElement() { style = { flexDirection = FlexDirection.Row, flexShrink = 0f, } }; buttonRow.Add(new Button() { text = k_ButtonLeftTitle, style = { flexGrow = 1 } }); buttonRow.Add(new Button() { text = k_ButtonRightTitle, style = { flexGrow = 1 } }); m_VisualElementContainer.Add(buttonRow); m_VisualElementContainer.Add(new Button() { text = k_ButtonTopTitle }); m_VisualElementContainer.Add(new Button() { text = k_ButtonBottomTitle }); m_VisualElementContainer.Add(m_ColorField1 = new ColorField()); m_VisualElementContainer.Add(m_LayerMaskField = new LayerMaskField(0)); m_VisualElementContainer.Add(m_MultiLineTextField = new TextField() { multiline = true }); m_VisualElementContainer.Add(m_SliderProgressBar = new SliderInt()); m_VisualElementContainer.Add(m_ProgressBar = new ProgressBar()); m_ProgressBar.title = nameof(ProgressBar); m_SliderProgressBar.lowValue = 0; m_SliderProgressBar.highValue = 100; m_SliderProgressBar.bindingPath = nameof(SliderProgressTestObject.exampleValue); m_ProgressBar.bindingPath = nameof(SliderProgressTestObject.exampleValue); m_SliderProgressBar.Bind(SliderProgressTestSO); m_ProgressBar.Bind(SliderProgressTestSO); // The progress bar by itself does not contain any margin in IMGUI... // In this example, we are artifically adding the textfield margin to it. (see below, in the IMGUI section, ProgressBar()) m_ProgressBar.style.marginBottom = 2f; m_VisualElementContainer.Add(m_GradientField = new GradientField()); RefreshUIElements(); }
public void TestNumericField() { Directory dir = NewDirectory(); var w = new RandomIndexWriter(Random(), dir); var numDocs = AtLeast(500); var answers = new object[numDocs]; FieldType.NumericType[] typeAnswers = new FieldType.NumericType[numDocs]; for (int id = 0; id < numDocs; id++) { Document doc = new Document(); Field nf; Field sf; object answer; FieldType.NumericType typeAnswer; if (Random().NextBoolean()) { // float/double if (Random().NextBoolean()) { float f = Random().NextFloat(); answer = Convert.ToSingle(f); nf = new FloatField("nf", f, Field.Store.NO); sf = new StoredField("nf", f); typeAnswer = FieldType.NumericType.FLOAT; } else { double d = Random().NextDouble(); answer = Convert.ToDouble(d); nf = new DoubleField("nf", d, Field.Store.NO); sf = new StoredField("nf", d); typeAnswer = FieldType.NumericType.DOUBLE; } } else { // int/long if (Random().NextBoolean()) { int i = Random().Next(); answer = Convert.ToInt32(i); nf = new IntField("nf", i, Field.Store.NO); sf = new StoredField("nf", i); typeAnswer = FieldType.NumericType.INT; } else { long l = Random().NextLong(); answer = Convert.ToInt64(l); nf = new LongField("nf", l, Field.Store.NO); sf = new StoredField("nf", l); typeAnswer = FieldType.NumericType.LONG; } } doc.Add(nf); doc.Add(sf); answers[id] = answer; typeAnswers[id] = typeAnswer; FieldType ft = new FieldType(IntField.TYPE_STORED); ft.NumericPrecisionStep = int.MaxValue; doc.Add(new IntField("id", id, ft)); w.AddDocument(doc); } DirectoryReader r = w.Reader; w.Dispose(); Assert.AreEqual(numDocs, r.NumDocs); foreach (AtomicReaderContext ctx in r.Leaves) { AtomicReader sub = (AtomicReader)ctx.Reader; FieldCache.Ints ids = FieldCache.DEFAULT.GetInts(sub, "id", false); for (int docID = 0; docID < sub.NumDocs; docID++) { Document doc = sub.Document(docID); Field f = (Field)doc.GetField("nf"); Assert.IsTrue(f is StoredField, "got f=" + f); Assert.AreEqual(answers[ids.Get(docID)], f.NumericValue); } } r.Dispose(); dir.Dispose(); }
public static long test() { var obj = new LongField(); return(obj.method()); }
public void Write(JceField field) { if (field is ByteField) { ByteField converted = (ByteField)field; Write(converted.Data, converted.Tag); } else if (field is ShortField) { ShortField converted = (ShortField)field; Write(converted.Data, converted.Tag); } else if (field is IntField) { IntField converted = (IntField)field; Write(converted.Data, converted.Tag); } else if (field is LongField) { LongField converted = (LongField)field; Write(converted.Data, converted.Tag); } else if (field is FloatField) { FloatField converted = (FloatField)field; Write(converted.Data, converted.Tag); } else if (field is DoubleField) { DoubleField converted = (DoubleField)field; Write(converted.Data, converted.Tag); } else if (field is StringField) { StringField converted = (StringField)field; Write(converted.Data, converted.Tag); } else if (field is MapField) { Write((MapField)field); } else if (field is ListField) { Write((ListField)field); } else if (field is StructField) { Write((StructField)field); } else if (field is ZeroField) { Write((ZeroField)field); } else if (field is ByteArrayField) { Write((ByteArrayField)field); } else { throw new ArgumentException("Unknown field type or not implented."); } }