问:
Swift turn a country code into a emoji flag via unicode
I'm looking for a quick way to turn something like:

```<code>let germany = "DE"
</code>```

into

```<code>let flag = "\u{1f1e9}\u{1f1ea}"
</code>```

ie, what's the mapping of D to 1f1e9 and E to 1f1ea
I was looking at .utf8 for the string, but this returns an integer.

FWIW my general goal is to be able to take an arbitrary country code and get the corresponding emoji flag.

EDIT: I'm also fine with just holding a table that does this mapping if its available somewhere. I googled around but didn't find it.

答:
For a more functional approach, using no mutable variables, use this:

```<code>private func flag(country: String) -> String {
    let base: UInt32 = 127397
    return country.unicodeScalars
        .flatMap({ UnicodeScalar(base + $0.value) })
        |> String.UnicodeScalarView.init
        |> String.init
}
</code>```

Where the |> operator is the function application operator, working like a "pipe" for a more natural reading order: We take the scalars, map them into new scalars, turn that into a view, and that into a string.

It's defined like so:

```<code>infix operator |> : MultiplicationPrecedence
func |> <T, U>(left: T, right: (T) -> U) -> U {
    return right(left)
}
</code>```

Without custom operators, we can still do without mutable state, like so:

```<code>private func flag(country: String) -> String {
    let base: UInt32 = 127397
    return String(String.UnicodeScalarView(
        country.unicodeScalars.flatMap({ UnicodeScalar(base + $0.value) })
    ))
}
</code>```

But IMHO, this reads a little "backwards", since the natural flow of operations read neither out-in, nor in-out, but a little bit of both.

Body:
I'm looking for a quick way to turn something like:

let germany = "DE"

into

let flag = "\u{1f1e9}\u{1f1ea}"

ie, what's the mapping of D to 1f1e9 and E to 1f1ea
I was looking at .utf8 for the string, but this returns an integer.

FWIW my general goal is to be able to take an arbitrary country code and get the corresponding emoji flag.

EDIT: I'm also fine with just holding a table that does this mapping if its available somewhere. I googled around but didn't find it.

Body:
For a more functional approach, using no mutable variables, use this:

private func flag(country: String) -> String {
    let base: UInt32 = 127397
    return country.unicodeScalars
        .flatMap({ UnicodeScalar(base + $0.value) })
        |> String.UnicodeScalarView.init
        |> String.init
}

Where the |> operator is the function application operator, working like a "pipe" for a more natural reading order: We take the scalars, map them into new scalars, turn that into a view, and that into a string.

It's defined like so:

infix operator |> : MultiplicationPrecedence
func |> <T, U>(left: T, right: (T) -> U) -> U {
    return right(left)
}

Without custom operators, we can still do without mutable state, like so:

private func flag(country: String) -> String {
    let base: UInt32 = 127397
    return String(String.UnicodeScalarView(
        country.unicodeScalars.flatMap({ UnicodeScalar(base + $0.value) })
    ))
}

But IMHO, this reads a little "backwards", since the natural flow of operations read neither out-in, nor in-out, but a little bit of both.


来源: stackexchange

问:
Parsing and using list item content via Twig
I am experimenting with using Grav to create my next website.  One of the things I would be able to do is to build a unordered list using data provided in Grav frontmatter from the Grav page that uses the template.  Here is how I am trying to do this

```<code>---
sectionone:
     listitems: "['Benefit 1','Benefit 2','Benefit 3']"
---
</code>```

and then in the template somehow do the following

```<code>{% block featurelist %}
<ul>
{% set items = {{page.header.sectionone.consumers.benefits|json_decode}} %}
{% for item in {{}} %}
<li>{{item}}</li>
{% endfor %}
</ul>
{% endblock %}
</code>```

However, Twig does not like this and reports back an error along the lines of

Twig_Error_Syntax
  A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "punctuation" of value "{".

with the offending line being my {% set items = ... } statement.  I am clearly doing something wrong here but I am a Twig newbie so I fail to see what that might be.

答:
I figured this out eventually.  Grav documentation is by and large very good.  However, the documentation on page headers/frontmatter appears to be somewhat incomplete.  There is no full description of the entire syntax that is understood by the frontmatter processor.  In order to define an array in front matter all you need to do is the following

```<code>---
sectionone:
 benefits:
    - 'Benefit 1'
    - 'Benefit 2'
    - ...
---
</code>```

In essence the standard markdown syntax for an unordered list.  Grav's twig processor appears to convert this to a PHP array - no parsing required!

ContentLicense: CC BY-SA 4.0

Body:
I am experimenting with using Grav to create my next website.  One of the things I would be able to do is to build a unordered list using data provided in Grav frontmatter from the Grav page that uses the template.  Here is how I am trying to do this

---
sectionone:
     listitems: "['Benefit 1','Benefit 2','Benefit 3']"
---

and then in the template somehow do the following

{% block featurelist %}

{% set items = {{page.header.sectionone.consumers.benefits|json_decode}} %}
{% for item in {{}} %}

{{item}}

{% endfor %}

{% endblock %}

However, Twig does not like this and reports back an error along the lines of

Twig_Error_Syntax
  A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "punctuation" of value "{".

with the offending line being my {% set items = ... } statement.  I am clearly doing something wrong here but I am a Twig newbie so I fail to see what that might be.

Body:
I figured this out eventually.  Grav documentation is by and large very good.  However, the documentation on page headers/frontmatter appears to be somewhat incomplete.  There is no full description of the entire syntax that is understood by the frontmatter processor.  In order to define an array in front matter all you need to do is the following

---
sectionone:
 benefits:
    - 'Benefit 1'
    - 'Benefit 2'
    - ...
---

In essence the standard markdown syntax for an unordered list.  Grav's twig processor appears to convert this to a PHP array - no parsing required!

ContentLicense: CC BY-SA 3.0


问:
Communication between python client and java server
My aim is to send a message from python socket to java socket. I did look out on the resource mentioned above. However I am struggling to make the Python client talk to Java server. Mostly because (End of line) in python is different from that in java.

say i write from python client: message 1: abcd message 2: efgh message 3: q (to quit)

At java server: i receive message 1:abcdefghq followed by exception because the python client had closed the socket from its end.

Could anybody please suggest a solution for a consistent talk between java and python.

Reference I used: http://www.prasannatech.net/2008/07/socket-programming-tutorial.html

Update: I forgot to add, I am working on TCP.

My JAVA code goes like this:(server socket)

```<code>String fromclient;

ServerSocket Server = new ServerSocket (5000);

System.out.println ("TCPServer Waiting for client on port 5000");

while(true)
{
    Socket connected = Server.accept();
    System.out.println( " THE CLIENT"+" "+ connected.getInetAddress() +":"+connected.getPort()+" IS CONNECTED ");

    BufferedReader inFromClient = new BufferedReader(new InputStreamReader (connected.getInputStream()));

    while ( true )
    {
        fromclient = inFromClient.readLine();

        if ( fromclient.equals("q") || fromclient.equals("Q") )
        {
            connected.close();
            break;
        }
        else
        {
            System.out.println( "RECIEVED:" + fromclient );
        }
    }
}
</code>```

My PYTHON code : (Client Socket)

```<code>client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(("localhost", 5000))

while 1:

    data = raw_input ( "SEND( TYPE q or Q to Quit):" )
    if (data <> 'Q' and data <> 'q'):
        client_socket.send(data)
    else:
        client_socket.send(data)
        client_socket.close()
        break;
</code>```

OUTPUT::

ON PYTHON CONSOLE(Client):

SEND( TYPE q or Q to Quit):abcd ( pressing ENTER)

SEND( TYPE q or Q to Quit):efgh ( pressing ENTER)

SEND( TYPE q or Q to Quit):q ( pressing ENTER)

ON JAVA CONSOLE(Server):

TCPServer Waiting for client on port 5000

THE CLIENT /127.0.0.1:1335 IS CONNECTED

RECIEVED:abcdefghq

答:
Append \n to the end of data:

```<code>client_socket.send(data + '\n')
</code>```

Body:
My aim is to send a message from python socket to java socket. I did look out on the resource mentioned above. However I am struggling to make the Python client talk to Java server. Mostly because (End of line) in python is different from that in java.

say i write from python client: message 1: abcd message 2: efgh message 3: q (to quit)

At java server: i receive message 1:abcdefghq followed by exception because the python client had closed the socket from its end.

Could anybody please suggest a solution for a consistent talk between java and python.

Reference I used: http://www.prasannatech.net/2008/07/socket-programming-tutorial.html

Update: I forgot to add, I am working on TCP.

My JAVA code goes like this:(server socket)

String fromclient;

ServerSocket Server = new ServerSocket (5000);

System.out.println ("TCPServer Waiting for client on port 5000");

while(true)
{
    Socket connected = Server.accept();
    System.out.println( " THE CLIENT"+" "+ connected.getInetAddress() +":"+connected.getPort()+" IS CONNECTED ");

    BufferedReader inFromClient = new BufferedReader(new InputStreamReader (connected.getInputStream()));

    while ( true )
    {
        fromclient = inFromClient.readLine();

        if ( fromclient.equals("q") || fromclient.equals("Q") )
        {
            connected.close();
            break;
        }
        else
        {
            System.out.println( "RECIEVED:" + fromclient );
        }
    }
}

My PYTHON code : (Client Socket)

client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(("localhost", 5000))

while 1:

    data = raw_input ( "SEND( TYPE q or Q to Quit):" )
    if (data <> 'Q' and data <> 'q'):
        client_socket.send(data)
    else:
        client_socket.send(data)
        client_socket.close()
        break;

OUTPUT::

ON PYTHON CONSOLE(Client):

SEND( TYPE q or Q to Quit):abcd ( pressing ENTER)

SEND( TYPE q or Q to Quit):efgh ( pressing ENTER)

SEND( TYPE q or Q to Quit):q ( pressing ENTER)

ON JAVA CONSOLE(Server):

TCPServer Waiting for client on port 5000

THE CLIENT /127.0.0.1:1335 IS CONNECTED

RECIEVED:abcdefghq

Body:
Append \n to the end of data:

client_socket.send(data + '\n')


问:
Cassandra is not picking initial_token
I am following the official documentation for procedure for Restoring a snapshot into a new cluster. As per this,

```<code>4. Clear the system table data from each new node:
$ sudo rm -rf /var/lib/cassandra/data/system/*
This allows the new nodes to use the initial tokens defined in the cassandra.yaml when they restart.

5. Start each node using the specified list of token ranges in new cluster's cassandra.yaml:
initial_token: -9211270970129494930, -9138351317258731895, -8980763462514965928, ...
</code>```

I am following these 2 steps exactly.
In fact, it is verified by cassandra debug logs.

```<code>INFO  [main] 2017-11-16 09:36:59,353 Config.java:456 - Node configuration:[allocate_tokens_for_keyspace=null; authenticator=AllowAllAuthenticator; authorizer=AllowAllAuthorizer; auto_bootstrap=true; auto_snapshot=true; batch_size_fail_threshold_in_kb=50; batch_size_warn_threshold_in_kb=5; batchlog_replay_throttle_in_kb=1024; broadcast_address=null; broadcast_rpc_address=null; buffer_pool_use_heap_if_exhausted=true; cas_contention_timeout_in_ms=1000; client_encryption_options=<REDACTED>; cluster_name=cassandra-staging-restored; column_index_cache_size_in_kb=2; column_index_size_in_kb=64; commit_failure_policy=stop; commitlog_compression=null; commitlog_directory=/mnt/cassandra/data/commitlog; commitlog_max_compression_buffers_in_pool=3; commitlog_periodic_queue_size=-1; commitlog_segment_size_in_mb=32; commitlog_sync=periodic; commitlog_sync_batch_window_in_ms=null; commitlog_sync_period_in_ms=10000; commitlog_total_space_in_mb=null; compaction_large_partition_warning_threshold_mb=100; compaction_throughput_mb_per_sec=16; concurrent_compactors=null; concurrent_counter_writes=32; concurrent_materialized_view_writes=32; concurrent_reads=32; concurrent_replicates=null; concurrent_writes=32; counter_cache_keys_to_save=2147483647; counter_cache_save_period=7200; counter_cache_size_in_mb=null; counter_write_request_timeout_in_ms=5000; credentials_cache_max_entries=1000; credentials_update_interval_in_ms=-1; credentials_validity_in_ms=2000; cross_node_timeout=false; data_file_directories=[Ljava.lang.String;@43301423; disk_access_mode=auto; disk_failure_policy=stop; disk_optimization_estimate_percentile=0.95; disk_optimization_page_cross_chance=0.1; disk_optimization_strategy=ssd; dynamic_snitch=true; dynamic_snitch_badness_threshold=0.1; dynamic_snitch_reset_interval_in_ms=600000; dynamic_snitch_update_interval_in_ms=100; enable_scripted_user_defined_functions=false; enable_user_defined_functions=false; enable_user_defined_functions_threads=true; encryption_options=null; endpoint_snitch=SimpleSnitch; file_cache_size_in_mb=null; gc_warn_threshold_in_ms=1000; hinted_handoff_disabled_datacenters=[]; hinted_handoff_enabled=true; hinted_handoff_throttle_in_kb=1024; hints_compression=null; hints_directory=/mnt/cassandra/data/hints; hints_flush_period_in_ms=10000; incremental_backups=true; index_interval=null; index_summary_capacity_in_mb=null; index_summary_resize_interval_in_minutes=60; initial_token=-9095105683159122588, -9064001015036599926, -9013000709875877114, -8829167773634478741, -8730304531409075421, -8615439886540673174, -8270623326447012978, -8176731878564157082, -8106822260307184341, -8089230042068892584, -8048906315856045311, -8028060929375944874, -7997403222481000091, -7980484429523277359, -7974470050771642191, -7851931228156318619, -7803664353182134419, -7788144370469500201, -7757626955856652301, -7712114049802319218, -7567720775920874700, -7551341429242695915, -7541865877881094180, -7514992388769119302, -7453108576041420033, -7431137934229111567, -7385697214426296194, -7326461701752475949, -7229952075030336177, -7218589485893294366, -7135605539700697459, -7062493953257887070, -6920687217081027707, -6916831669158286277, -6834053763268440089, -6822142837027528938, -6803094670398379101, -6602427539566207665, -6568182869870496307, -6511459920765505444, -6475249533685490199, -6428402884562770941, -6404676233544011759, -6360685224996369272, -6247121131610539884, -6246197555819424550, -6237368585021940017, -6153182247036415095, -6111450384148334970, -6042018771685803203, -5944793473876873149, -5863379160236916223, -5856475313797546183, -5832717016324856051, -5638468189438508210, -5539167370710819367, -5485280601523987503, -5474309089162218374, -5319174053461867928, -5300518577149097037, -5245536441075283612, -5112569688111722752, -4898240302203107111, -4881568115746221858, -4824104622873342498, -4701179017811291386, -4429755340063878775, -4413214557193145518, -4345418978114596882, -4079966796765885842, -4061762443047240866, -4030858175577795653, -4021547736638981847, -3836302740108504981, -3751768720526789019, -3743461742087956083, -3608810097734181459, -3607048178493709454, -3581158125752648978, -3562376827907111596, -3534668228830524620, -3431416556842048483, -3393885233868129949, -3339504094398301776, -3339170395338364082, -3307612236986384680, -3265920212434927166, -3204785075022793989, -3140386460827349755, -3099066887010465462, -3080689217189133335, -3007133744629835172, -2959846903344801620, -2888247723844507160, -2797992536166356195, -2712194459828626645, -2684177990525837322, -2658075701966969657, -2561917844478305786, -2492629295365129028, -2487719825222497546, -2399789247381255821, -2241309724624423586, -2108173119695457257, -2052360610564904726, -1939271054812802955, -1917043893384955146, -1808888302673267763, -1646863387940805021, -1634994825307804368, -1609712683106528653, -1300771381145801651, -1278385576576119381, -1274643898977022746, -950901630804463153, -940580146197028656, -731515730336327054, -642040964228514704, -608433393788453231, -478573951386945456, -436153095069462168, -416275106775833677, -378149959056786595, -346798880456427869, -305717523770204725, -284546652114461767, -166337978258482678, -101574744252082785, -30754271282451326, -6946162971722353, -4662052994008400, 68233019263256270, 126207333796953658, 132958619259436796, 166586855936325288, 180257471364193954, 222412061324634542, 299152219068289859, 307967555141655158, 499885456475913627, 510710569344453193, 512082871639239079, 551467999030970818, 560270740776978967, 563581994761305584, 687058605177782549, 793693682518320692, 917345500055208403, 935027642243141249, 1167582121991529631, 1177005535757550036, 1226282557885818866, 1279109759358271230, 1376609314865350358, 1388467321396881673, 1422156903349974253, 1475548349950097082, 1586261249441981681, 1594387271495404471, 1637548112971596569, 1759270488237130010, 1936016394983722984, 1991608383818464987, 2208451829114082571, 2242674193749084268, 2461080713362404466, 2539772799528407861, 2559844306686112571, 2620884963938532750, 2631650124112820870, 2664129588892760377, 2704157604972767845, 2736768902813611411, 2843328646543212128, 2856803091245137446, 2872960500638572538, 3138686478845054074, 3162031242206258542, 3185538412991024850, 3256233823832431553, 3284337403758100585, 3382411519818362465, 3490207566034869602, 3594317170903296648, 3669639735626576929, 3787200951518921417, 3805575545151951881, 3930156481299524524, 4109302677069830167, 4162318623147816383, 4174122441845031013, 4184778082562775012, 4333398546246868435, 4429402131470597299, 4454026097116561450, 4505802367873280245, 4538296977730990054, 4556607070107659214, 4570854427961759192, 4623296353148907992, 4679204413345951708, 4835621991534530902, 4873358208143831472, 4877348486234759943, 4909265243325179596, 4916889701925751547, 5050438954348872869, 5095687454372630280, 5225622553567840544, 5362122150810830638, 5453189930700137106, 5607985707233264385, 5627412929991624017, 5715642638971959215, 5792552742790972143, 5958282382337339668, 5966221173142140715, 6034708041737829912, 6035042265093059146, 6044918925766439026, 6117274929043661295, 6287231019632644302, 6317296677286381680, 6347246668613761526, 6386913449650684351, 6484548945192165912, 6809960070854586220, 7007749647532345769, 7064744556786092960, 7188015426890314535, 7381000932719845319, 7587261946507044657, 7642859702759477380, 7880162680349272441, 7908612477022491169, 7933323898613557131, 7937658449054724067, 7970141900392419694, 7979202070554210097, 7990763252197782986, 7995201022333707512, 7995792407943250493, 8140167553977835725, 8207869160118839667, 8384513993725731980, 8425627379584317458, 8450167920418959385, 8558753444678316624, 8635896206896058589, 8655999832148389735, 8749247593003798317, 8793336959659815954, 8811175299936105223, 8960172117500802825, 9082531635065196023, 9119004294127950942; inter_dc_stream_throughput_outbound_megabits_per_sec=200; inter_dc_tcp_nodelay=false; internode_authenticator=null; internode_compression=dc; internode_recv_buff_size_in_bytes=null; internode_send_buff_size_in_bytes=null; key_cache_keys_to_save=2147483647; key_cache_save_period=14400; key_cache_size_in_mb=null; listen_address=10.120.8.116; listen_interface=null; listen_interface_prefer_ipv6=false; listen_on_broadcast_address=false; max_hint_window_in_ms=10800000; max_hints_delivery_threads=2; max_hints_file_size_in_mb=128; max_mutation_size_in_kb=null; max_streaming_retries=3; max_value_size_in_mb=256; memtable_allocation_type=heap_buffers; memtable_cleanup_threshold=null; memtable_flush_writers=1; memtable_heap_space_in_mb=null; memtable_offheap_space_in_mb=null; native_transport_max_concurrent_connections=-1; native_transport_max_concurrent_connections_per_ip=-1; native_transport_max_frame_size_in_mb=256; native_transport_max_threads=128; native_transport_port=9042; native_transport_port_ssl=null; num_tokens=256; otc_coalescing_strategy=TIMEHORIZON; otc_coalescing_window_us=200; partitioner=org.apache.cassandra.dht.Murmur3Partitioner; permissions_cache_max_entries=1000; permissions_update_interval_in_ms=-1; permissions_validity_in_ms=2000; phi_convict_threshold=8.0; prepared_statements_cache_size_mb=null; range_request_timeout_in_ms=10000; read_request_timeout_in_ms=5000; request_scheduler=org.apache.cassandra.scheduler.NoScheduler; request_scheduler_id=null; request_scheduler_options=null; request_timeout_in_ms=10000; role_manager=CassandraRoleManager; roles_cache_max_entries=1000; roles_update_interval_in_ms=-1; roles_validity_in_ms=2000; row_cache_class_name=org.apache.cassandra.cache.OHCProvider; row_cache_keys_to_save=2147483647; row_cache_save_period=0; row_cache_size_in_mb=0; rpc_address=10.120.8.116; rpc_interface=null; rpc_interface_prefer_ipv6=false; rpc_keepalive=true; rpc_listen_backlog=50; rpc_max_threads=2147483647; rpc_min_threads=16; rpc_port=9160; rpc_recv_buff_size_in_bytes=null; rpc_send_buff_size_in_bytes=null; rpc_server_type=sync; saved_caches_directory=/mnt/cassandra/data/saved_caches; seed_provider=org.apache.cassandra.locator.SimpleSeedProvider{seeds=10.120.8.233,10.120.8.213,10.120.8.116,10.120.8.29,10.120.8.251}; server_encryption_options=<REDACTED>; snapshot_before_compaction=false; ssl_storage_port=7001; sstable_preemptive_open_interval_in_mb=50; start_native_transport=true; start_rpc=false; storage_port=7000; stream_throughput_outbound_megabits_per_sec=200; streaming_socket_timeout_in_ms=86400000; thrift_framed_transport_size_in_mb=15; thrift_max_message_length_in_mb=16; thrift_prepared_statements_cache_size_mb=null; tombstone_failure_threshold=100000; tombstone_warn_threshold=1000; tracetype_query_ttl=86400; tracetype_repair_ttl=604800; transparent_data_encryption_options=org.apache.cassandra.config.TransparentDataEncryptionOptions@2f112965; trickle_fsync=false; trickle_fsync_interval_in_kb=10240; truncate_request_timeout_in_ms=60000; unlogged_batch_across_partitions_warn_threshold=10; user_defined_function_fail_timeout=1500; user_defined_function_warn_timeout=500; user_function_timeout_policy=die; windows_timer_interval=1; write_request_timeout_in_ms=2000
</code>```

But the initial_tokens are those which were auto-generated by cassandra when it was first started.

```<code>INFO  [main] 2017-11-16 05:52:57,322 StorageService.java:1030 - Generated random tokens. tokens are [-1389648523687197109, -732698274772120137, -6376639320886405616, -873424736264959023, 8595953819512872578, 6773654626092013980, 9148695480551165081, 8209470968081970646, 9110581623169741801, 8012929209487966833, 7452692620314248468, 3103266257146948503, 5679525578987403003, -4522063905876778141, -6135750996189542432, 415784996037656153, 4396058137183394429, 692447961111726586, -6531662267543500154, 245834976461441926, -3064167806548065705, 8943572903844965496, -8638802229987964486, -8160083686661602566, -3050334815467563212, -8542758292854754936, 5709282354905481607, 88986928287276648, 1373249395890303055, -1686001724516419324, -396828971815045007, -8794909476111352967, -222280635739262458, -5414806845469275848, -2054698046151951295, -3554921400589962677, -7505704101012649583, 4179877325296378655, 7507175622338132461, -3496771293631065989, -3269044636044041612, -2009963074060585591, -2105986620005447634, 5330076034215385934, -4344640060181026104, 617483922231457714, 6465679396586550255, 5268797296416377890, 8377470147983205477, -8297832552754006887, -74853680046366003, -2872441811245832825, -2916068111566416056, 8408680662553618809, -2520357715711164569, -1560036757814314210, -5257702498481345613, -1017232662177787435, -4767292845107768798, -907567868062273876, 8870536721819084448, -6581232938993081706, 3822595822833559746, -7289338527755522826, -7639859898047414864, -4037700692557190365, 5049983552065810879, -5561302251870351386, 4621684495888003169, -3131443300514015633, -1160430662405286954, -8097490517397089231, -7348298090590090758, 5509208719656812112, -6481250052576231824, -5996741154396422167, -8294729397011283217, 2995257461252438837, -4352117679133792335, 1233012258201042528, 9035122281098363653, 6405344801897697404, 8708109275467472592, 8539949944069553390, 213833451306356755, -4166035949030694285, -8970221914082044097, 4606844533012524108, 947526220642208048, -2801978367402508153, -4532865176940942027, -1594392693891556555, -5806887334100689059, -2394088246665207424, 4234652354740925563, -8076001124699026366, 8744811137913444802, 62796481248292599, 6455733404981444252, -126533974378819127, 5843584371728823073, 5445168425290460940, 6707320880322895668, 4573751191752231090, -2127663589976413582, 1954401089317717447, -5300938135871221896, 5093721835155884661, -2524179837794403109, -6385219008186858160, 7325353601705788106, -840570978863751222, 5759885770816159939, 9072054183035599574, -8308763822241266759, -2586762965601191160, -432658258571974620, 3019044186650827069, 5726665958978111481, 6052672856134820217, 7838411235214044945, 2112902061202895279, 6260813920434498398, -8658490402119023263, 2928460241999085176, -8088631625855485121, -3893350039068301015, -1883547399497783790, -4931508961242998715, 1962026677878034467, -3536945581565756993, -3980665635466622441, 1616177331508810053, 4312023170834343978, 2878951844701050184, 7237763498599271588, -4143611656813097424, -3034833307460628079, -8631680602869413810, -5149492198682224552, -2010682875598030955, 2599132540851755500, -2955657629453800874, 7849160639412118736, 4066126615292533141, 8785492290797937036, -2425804637592817359, -81469586499474786, -8457085973377633413, 7938935767281129568, 5555025259044091280, -928104310141668027, 7576407531657016973, 1924068444759082739, -714923442136005577, -7424796994965823987, -8286550103460241539, 3795917762129273051, -8178762033443435991, 199935774895264752, 7223315731747941169, 2131952788031994270, -5924194093356500134, 8312801612720650647, -3455990260940501757, -6752550707935826850, -6601973406625917854, 1003897288641305994, -2311356538255289914, 6198153789687000292, 4371280172613277105, -3103750689457909819, -4749463815536259135, -371035516354562506, -3121297865532053724, 8982910635457246180, -1228260466727841004, -8870629066952254909, -526008540797435088, -5031238755845142021, -8363050244592607033, 1050601700640744024, -9104611786673170314, -4479945644147199241, -6823419782998328301, -6797181997798727850, 5481659148496729987, -8215699248520360452, -517420190806294229, 3787637764983639252, 2805777124248862676, 847375026463710908, -752806257333244860, -5802733257867073965, -6973496662755627239, 3473454836096478605, 5913384000201698403, -5389236760772073822, -8414280654740947122, 3781334199812295253, 7106186427969879811, -5793392653945612514, 4025496630557953873, 2029509328065975744, 7572757562784032698, -2409285778846785268, 8978472449360675819, 1502576153090782858, -524754924171314294, -5430506207796491830, -3681655679894962053, 5884494403462724943, 7057525460429085795, 6045128197566372326, 3068439635150742873, 5459483613324200529, -1099342907611602685, -8333623299114170297, 5575333565033227947, -8354986150955517165, 8957282480649403114, -4820459891421864876, 6809654053429862128, 4545870922630195580, 7197311542935486176, -2224608079234315120, -2141755264538606024, 2567830060494624486, -6270558622819592064, -4631885184728004763, 5954771488972332706, 7426073577700947604, 9036595665094295454, -549019315323478217, -7605262589627026961, 7538503311332390280, 5243496430380841675, -5125800136257737648, -189067622801948902, 6609318324048658940, -6407003720857192075, 6821243825376985989, -8663409582093444260, -8403726365964456251, -6966940567562465809, 2209597621040018613, -785009207590992232, 7148233497746128406, 8290593398169627427, -1934557347998048138, -1747811994016572301, -5360972975488153447, -4344532326911873111, -2181569417592666651, -5367930324551905863, -7161819751367151648]
</code>```

What am I missing? Isn't it enough to specify initial_token and restart the cassandra?

I can't avoid random generation of initial_token by cassandra, because cassandra is automatically started after installation, i.e. even before I can edit cassandra.yaml for initial_token specification.

I am using cassandra 3.7.

I am using the same step to retrieve initial token from source node and then to verify on target node.

```<code>$ nodetool ring | grep ip_address_of_node | awk '{print $NF ","}' | xargs
</code>```

Edit: Adding more investigation details ...

I clear the system table data from the node and restart cassandra. But cassandra still picks auto-generated tokens and not those initial_tokens mentioned in cassandra.yml. This clearly violates step 4 of procedure mentioned in official documentation.

So I can rephrase my question as follows:
System tables are removed. It's not picking from cassandra.yml. Then where from cassandra picks intial_tokens after restart?

答: The initial_token should only be set when not using vnodes. It also should only be one token. When using vnodes the tokens will be automatically distributed when bootstraping a node and it will ignorde this setting.</p>

Title: Cassandra is not picking initial_token

Body:
I am following the official documentation for procedure for Restoring a snapshot into a new cluster. As per this,

4. Clear the system table data from each new node:
$ sudo rm -rf /var/lib/cassandra/data/system/*
This allows the new nodes to use the initial tokens defined in the cassandra.yaml when they restart.

5. Start each node using the specified list of token ranges in new cluster's cassandra.yaml:
initial_token: -9211270970129494930, -9138351317258731895, -8980763462514965928, ...

I am following these 2 steps exactly.
In fact, it is verified by cassandra debug logs.

INFO  [main] 2017-11-16 09:36:59,353 Config.java:456 - Node configuration:[allocate_tokens_for_keyspace=null; authenticator=AllowAllAuthenticator; authorizer=AllowAllAuthorizer; auto_bootstrap=true; auto_snapshot=true; batch_size_fail_threshold_in_kb=50; batch_size_warn_threshold_in_kb=5; batchlog_replay_throttle_in_kb=1024; broadcast_address=null; broadcast_rpc_address=null; buffer_pool_use_heap_if_exhausted=true; cas_contention_timeout_in_ms=1000; client_encryption_options=<REDACTED>; cluster_name=cassandra-staging-restored; column_index_cache_size_in_kb=2; column_index_size_in_kb=64; commit_failure_policy=stop; commitlog_compression=null; commitlog_directory=/mnt/cassandra/data/commitlog; commitlog_max_compression_buffers_in_pool=3; commitlog_periodic_queue_size=-1; commitlog_segment_size_in_mb=32; commitlog_sync=periodic; commitlog_sync_batch_window_in_ms=null; commitlog_sync_period_in_ms=10000; commitlog_total_space_in_mb=null; compaction_large_partition_warning_threshold_mb=100; compaction_throughput_mb_per_sec=16; concurrent_compactors=null; concurrent_counter_writes=32; concurrent_materialized_view_writes=32; concurrent_reads=32; concurrent_replicates=null; concurrent_writes=32; counter_cache_keys_to_save=2147483647; counter_cache_save_period=7200; counter_cache_size_in_mb=null; counter_write_request_timeout_in_ms=5000; credentials_cache_max_entries=1000; credentials_update_interval_in_ms=-1; credentials_validity_in_ms=2000; cross_node_timeout=false; data_file_directories=[Ljava.lang.String;@43301423; disk_access_mode=auto; disk_failure_policy=stop; disk_optimization_estimate_percentile=0.95; disk_optimization_page_cross_chance=0.1; disk_optimization_strategy=ssd; dynamic_snitch=true; dynamic_snitch_badness_threshold=0.1; dynamic_snitch_reset_interval_in_ms=600000; dynamic_snitch_update_interval_in_ms=100; enable_scripted_user_defined_functions=false; enable_user_defined_functions=false; enable_user_defined_functions_threads=true; encryption_options=null; endpoint_snitch=SimpleSnitch; file_cache_size_in_mb=null; gc_warn_threshold_in_ms=1000; hinted_handoff_disabled_datacenters=[]; hinted_handoff_enabled=true; hinted_handoff_throttle_in_kb=1024; hints_compression=null; hints_directory=/mnt/cassandra/data/hints; hints_flush_period_in_ms=10000; incremental_backups=true; index_interval=null; index_summary_capacity_in_mb=null; index_summary_resize_interval_in_minutes=60; initial_token=-9095105683159122588, -9064001015036599926, -9013000709875877114, -8829167773634478741, -8730304531409075421, -8615439886540673174, -8270623326447012978, -8176731878564157082, -8106822260307184341, -8089230042068892584, -8048906315856045311, -8028060929375944874, -7997403222481000091, -7980484429523277359, -7974470050771642191, -7851931228156318619, -7803664353182134419, -7788144370469500201, -7757626955856652301, -7712114049802319218, -7567720775920874700, -7551341429242695915, -7541865877881094180, -7514992388769119302, -7453108576041420033, -7431137934229111567, -7385697214426296194, -7326461701752475949, -7229952075030336177, -7218589485893294366, -7135605539700697459, -7062493953257887070, -6920687217081027707, -6916831669158286277, -6834053763268440089, -6822142837027528938, -6803094670398379101, -6602427539566207665, -6568182869870496307, -6511459920765505444, -6475249533685490199, -6428402884562770941, -6404676233544011759, -6360685224996369272, -6247121131610539884, -6246197555819424550, -6237368585021940017, -6153182247036415095, -6111450384148334970, -6042018771685803203, -5944793473876873149, -5863379160236916223, -5856475313797546183, -5832717016324856051, -5638468189438508210, -5539167370710819367, -5485280601523987503, -5474309089162218374, -5319174053461867928, -5300518577149097037, -5245536441075283612, -5112569688111722752, -4898240302203107111, -4881568115746221858, -4824104622873342498, -4701179017811291386, -4429755340063878775, -4413214557193145518, -4345418978114596882, -4079966796765885842, -4061762443047240866, -4030858175577795653, -4021547736638981847, -3836302740108504981, -3751768720526789019, -3743461742087956083, -3608810097734181459, -3607048178493709454, -3581158125752648978, -3562376827907111596, -3534668228830524620, -3431416556842048483, -3393885233868129949, -3339504094398301776, -3339170395338364082, -3307612236986384680, -3265920212434927166, -3204785075022793989, -3140386460827349755, -3099066887010465462, -3080689217189133335, -3007133744629835172, -2959846903344801620, -2888247723844507160, -2797992536166356195, -2712194459828626645, -2684177990525837322, -2658075701966969657, -2561917844478305786, -2492629295365129028, -2487719825222497546, -2399789247381255821, -2241309724624423586, -2108173119695457257, -2052360610564904726, -1939271054812802955, -1917043893384955146, -1808888302673267763, -1646863387940805021, -1634994825307804368, -1609712683106528653, -1300771381145801651, -1278385576576119381, -1274643898977022746, -950901630804463153, -940580146197028656, -731515730336327054, -642040964228514704, -608433393788453231, -478573951386945456, -436153095069462168, -416275106775833677, -378149959056786595, -346798880456427869, -305717523770204725, -284546652114461767, -166337978258482678, -101574744252082785, -30754271282451326, -6946162971722353, -4662052994008400, 68233019263256270, 126207333796953658, 132958619259436796, 166586855936325288, 180257471364193954, 222412061324634542, 299152219068289859, 307967555141655158, 499885456475913627, 510710569344453193, 512082871639239079, 551467999030970818, 560270740776978967, 563581994761305584, 687058605177782549, 793693682518320692, 917345500055208403, 935027642243141249, 1167582121991529631, 1177005535757550036, 1226282557885818866, 1279109759358271230, 1376609314865350358, 1388467321396881673, 1422156903349974253, 1475548349950097082, 1586261249441981681, 1594387271495404471, 1637548112971596569, 1759270488237130010, 1936016394983722984, 1991608383818464987, 2208451829114082571, 2242674193749084268, 2461080713362404466, 2539772799528407861, 2559844306686112571, 2620884963938532750, 2631650124112820870, 2664129588892760377, 2704157604972767845, 2736768902813611411, 2843328646543212128, 2856803091245137446, 2872960500638572538, 3138686478845054074, 3162031242206258542, 3185538412991024850, 3256233823832431553, 3284337403758100585, 3382411519818362465, 3490207566034869602, 3594317170903296648, 3669639735626576929, 3787200951518921417, 3805575545151951881, 3930156481299524524, 4109302677069830167, 4162318623147816383, 4174122441845031013, 4184778082562775012, 4333398546246868435, 4429402131470597299, 4454026097116561450, 4505802367873280245, 4538296977730990054, 4556607070107659214, 4570854427961759192, 4623296353148907992, 4679204413345951708, 4835621991534530902, 4873358208143831472, 4877348486234759943, 4909265243325179596, 4916889701925751547, 5050438954348872869, 5095687454372630280, 5225622553567840544, 5362122150810830638, 5453189930700137106, 5607985707233264385, 5627412929991624017, 5715642638971959215, 5792552742790972143, 5958282382337339668, 5966221173142140715, 6034708041737829912, 6035042265093059146, 6044918925766439026, 6117274929043661295, 6287231019632644302, 6317296677286381680, 6347246668613761526, 6386913449650684351, 6484548945192165912, 6809960070854586220, 7007749647532345769, 7064744556786092960, 7188015426890314535, 7381000932719845319, 7587261946507044657, 7642859702759477380, 7880162680349272441, 7908612477022491169, 7933323898613557131, 7937658449054724067, 7970141900392419694, 7979202070554210097, 7990763252197782986, 7995201022333707512, 7995792407943250493, 8140167553977835725, 8207869160118839667, 8384513993725731980, 8425627379584317458, 8450167920418959385, 8558753444678316624, 8635896206896058589, 8655999832148389735, 8749247593003798317, 8793336959659815954, 8811175299936105223, 8960172117500802825, 9082531635065196023, 9119004294127950942; inter_dc_stream_throughput_outbound_megabits_per_sec=200; inter_dc_tcp_nodelay=false; internode_authenticator=null; internode_compression=dc; internode_recv_buff_size_in_bytes=null; internode_send_buff_size_in_bytes=null; key_cache_keys_to_save=2147483647; key_cache_save_period=14400; key_cache_size_in_mb=null; listen_address=10.120.8.116; listen_interface=null; listen_interface_prefer_ipv6=false; listen_on_broadcast_address=false; max_hint_window_in_ms=10800000; max_hints_delivery_threads=2; max_hints_file_size_in_mb=128; max_mutation_size_in_kb=null; max_streaming_retries=3; max_value_size_in_mb=256; memtable_allocation_type=heap_buffers; memtable_cleanup_threshold=null; memtable_flush_writers=1; memtable_heap_space_in_mb=null; memtable_offheap_space_in_mb=null; native_transport_max_concurrent_connections=-1; native_transport_max_concurrent_connections_per_ip=-1; native_transport_max_frame_size_in_mb=256; native_transport_max_threads=128; native_transport_port=9042; native_transport_port_ssl=null; num_tokens=256; otc_coalescing_strategy=TIMEHORIZON; otc_coalescing_window_us=200; partitioner=org.apache.cassandra.dht.Murmur3Partitioner; permissions_cache_max_entries=1000; permissions_update_interval_in_ms=-1; permissions_validity_in_ms=2000; phi_convict_threshold=8.0; prepared_statements_cache_size_mb=null; range_request_timeout_in_ms=10000; read_request_timeout_in_ms=5000; request_scheduler=org.apache.cassandra.scheduler.NoScheduler; request_scheduler_id=null; request_scheduler_options=null; request_timeout_in_ms=10000; role_manager=CassandraRoleManager; roles_cache_max_entries=1000; roles_update_interval_in_ms=-1; roles_validity_in_ms=2000; row_cache_class_name=org.apache.cassandra.cache.OHCProvider; row_cache_keys_to_save=2147483647; row_cache_save_period=0; row_cache_size_in_mb=0; rpc_address=10.120.8.116; rpc_interface=null; rpc_interface_prefer_ipv6=false; rpc_keepalive=true; rpc_listen_backlog=50; rpc_max_threads=2147483647; rpc_min_threads=16; rpc_port=9160; rpc_recv_buff_size_in_bytes=null; rpc_send_buff_size_in_bytes=null; rpc_server_type=sync; saved_caches_directory=/mnt/cassandra/data/saved_caches; seed_provider=org.apache.cassandra.locator.SimpleSeedProvider{seeds=10.120.8.233,10.120.8.213,10.120.8.116,10.120.8.29,10.120.8.251}; server_encryption_options=<REDACTED>; snapshot_before_compaction=false; ssl_storage_port=7001; sstable_preemptive_open_interval_in_mb=50; start_native_transport=true; start_rpc=false; storage_port=7000; stream_throughput_outbound_megabits_per_sec=200; streaming_socket_timeout_in_ms=86400000; thrift_framed_transport_size_in_mb=15; thrift_max_message_length_in_mb=16; thrift_prepared_statements_cache_size_mb=null; tombstone_failure_threshold=100000; tombstone_warn_threshold=1000; tracetype_query_ttl=86400; tracetype_repair_ttl=604800; transparent_data_encryption_options=org.apache.cassandra.config.TransparentDataEncryptionOptions@2f112965; trickle_fsync=false; trickle_fsync_interval_in_kb=10240; truncate_request_timeout_in_ms=60000; unlogged_batch_across_partitions_warn_threshold=10; user_defined_function_fail_timeout=1500; user_defined_function_warn_timeout=500; user_function_timeout_policy=die; windows_timer_interval=1; write_request_timeout_in_ms=2000

But the initial_tokens are those which were auto-generated by cassandra when it was first started.

INFO  [main] 2017-11-16 05:52:57,322 StorageService.java:1030 - Generated random tokens. tokens are [-1389648523687197109, -732698274772120137, -6376639320886405616, -873424736264959023, 8595953819512872578, 6773654626092013980, 9148695480551165081, 8209470968081970646, 9110581623169741801, 8012929209487966833, 7452692620314248468, 3103266257146948503, 5679525578987403003, -4522063905876778141, -6135750996189542432, 415784996037656153, 4396058137183394429, 692447961111726586, -6531662267543500154, 245834976461441926, -3064167806548065705, 8943572903844965496, -8638802229987964486, -8160083686661602566, -3050334815467563212, -8542758292854754936, 5709282354905481607, 88986928287276648, 1373249395890303055, -1686001724516419324, -396828971815045007, -8794909476111352967, -222280635739262458, -5414806845469275848, -2054698046151951295, -3554921400589962677, -7505704101012649583, 4179877325296378655, 7507175622338132461, -3496771293631065989, -3269044636044041612, -2009963074060585591, -2105986620005447634, 5330076034215385934, -4344640060181026104, 617483922231457714, 6465679396586550255, 5268797296416377890, 8377470147983205477, -8297832552754006887, -74853680046366003, -2872441811245832825, -2916068111566416056, 8408680662553618809, -2520357715711164569, -1560036757814314210, -5257702498481345613, -1017232662177787435, -4767292845107768798, -907567868062273876, 8870536721819084448, -6581232938993081706, 3822595822833559746, -7289338527755522826, -7639859898047414864, -4037700692557190365, 5049983552065810879, -5561302251870351386, 4621684495888003169, -3131443300514015633, -1160430662405286954, -8097490517397089231, -7348298090590090758, 5509208719656812112, -6481250052576231824, -5996741154396422167, -8294729397011283217, 2995257461252438837, -4352117679133792335, 1233012258201042528, 9035122281098363653, 6405344801897697404, 8708109275467472592, 8539949944069553390, 213833451306356755, -4166035949030694285, -8970221914082044097, 4606844533012524108, 947526220642208048, -2801978367402508153, -4532865176940942027, -1594392693891556555, -5806887334100689059, -2394088246665207424, 4234652354740925563, -8076001124699026366, 8744811137913444802, 62796481248292599, 6455733404981444252, -126533974378819127, 5843584371728823073, 5445168425290460940, 6707320880322895668, 4573751191752231090, -2127663589976413582, 1954401089317717447, -5300938135871221896, 5093721835155884661, -2524179837794403109, -6385219008186858160, 7325353601705788106, -840570978863751222, 5759885770816159939, 9072054183035599574, -8308763822241266759, -2586762965601191160, -432658258571974620, 3019044186650827069, 5726665958978111481, 6052672856134820217, 7838411235214044945, 2112902061202895279, 6260813920434498398, -8658490402119023263, 2928460241999085176, -8088631625855485121, -3893350039068301015, -1883547399497783790, -4931508961242998715, 1962026677878034467, -3536945581565756993, -3980665635466622441, 1616177331508810053, 4312023170834343978, 2878951844701050184, 7237763498599271588, -4143611656813097424, -3034833307460628079, -8631680602869413810, -5149492198682224552, -2010682875598030955, 2599132540851755500, -2955657629453800874, 7849160639412118736, 4066126615292533141, 8785492290797937036, -2425804637592817359, -81469586499474786, -8457085973377633413, 7938935767281129568, 5555025259044091280, -928104310141668027, 7576407531657016973, 1924068444759082739, -714923442136005577, -7424796994965823987, -8286550103460241539, 3795917762129273051, -8178762033443435991, 199935774895264752, 7223315731747941169, 2131952788031994270, -5924194093356500134, 8312801612720650647, -3455990260940501757, -6752550707935826850, -6601973406625917854, 1003897288641305994, -2311356538255289914, 6198153789687000292, 4371280172613277105, -3103750689457909819, -4749463815536259135, -371035516354562506, -3121297865532053724, 8982910635457246180, -1228260466727841004, -8870629066952254909, -526008540797435088, -5031238755845142021, -8363050244592607033, 1050601700640744024, -9104611786673170314, -4479945644147199241, -6823419782998328301, -6797181997798727850, 5481659148496729987, -8215699248520360452, -517420190806294229, 3787637764983639252, 2805777124248862676, 847375026463710908, -752806257333244860, -5802733257867073965, -6973496662755627239, 3473454836096478605, 5913384000201698403, -5389236760772073822, -8414280654740947122, 3781334199812295253, 7106186427969879811, -5793392653945612514, 4025496630557953873, 2029509328065975744, 7572757562784032698, -2409285778846785268, 8978472449360675819, 1502576153090782858, -524754924171314294, -5430506207796491830, -3681655679894962053, 5884494403462724943, 7057525460429085795, 6045128197566372326, 3068439635150742873, 5459483613324200529, -1099342907611602685, -8333623299114170297, 5575333565033227947, -8354986150955517165, 8957282480649403114, -4820459891421864876, 6809654053429862128, 4545870922630195580, 7197311542935486176, -2224608079234315120, -2141755264538606024, 2567830060494624486, -6270558622819592064, -4631885184728004763, 5954771488972332706, 7426073577700947604, 9036595665094295454, -549019315323478217, -7605262589627026961, 7538503311332390280, 5243496430380841675, -5125800136257737648, -189067622801948902, 6609318324048658940, -6407003720857192075, 6821243825376985989, -8663409582093444260, -8403726365964456251, -6966940567562465809, 2209597621040018613, -785009207590992232, 7148233497746128406, 8290593398169627427, -1934557347998048138, -1747811994016572301, -5360972975488153447, -4344532326911873111, -2181569417592666651, -5367930324551905863, -7161819751367151648]

What am I missing? Isn't it enough to specify initial_token and restart the cassandra?

I can't avoid random generation of initial_token by cassandra, because cassandra is automatically started after installation, i.e. even before I can edit cassandra.yaml for initial_token specification.

I am using cassandra 3.7.

I am using the same step to retrieve initial token from source node and then to verify on target node.

$ nodetool ring | grep ip_address_of_node | awk '{print $NF ","}' | xargs

Edit: Adding more investigation details ...

I clear the system table data from the node and restart cassandra. But cassandra still picks auto-generated tokens and not those initial_tokens mentioned in cassandra.yml. This clearly violates step 4 of procedure mentioned in official documentation.

So I can rephrase my question as follows:
System tables are removed. It's not picking from cassandra.yml. Then where from cassandra picks intial_tokens after restart?


问:
Is it possible to store and query Array Spatial Data in CosmosDB?
Here is a sample document that we would like to store:

```
<code>
{
  "name": "Joe Bloggs",
   "locations": [
        { "type": "Point", "coordinates": [1,1] },
        { "type": "Point", "coordinates": [2,2] }
   ]
}
</code>
```

The key feature of the document is that the "locations" property is an array of GeoJSON points.

According to the documentation it is possible to define an indexing policy for the locations array.

However, it's not clear whether spatial queries such as ST_WITHIN can be used to search, for example, whether any of the points in the array fall within a certain radius of a specified point.

My question: Does CosmosDB support indexing and querying of spatial data when stored in an array?

答:
From private conversation with CosmosDB:

Can it be indexed?

yes, you just need to index /locations/[]/? or /locations/*

Can it be queried?

yes, you can query over an array of points by using a JOIN to unwind the array.

SELECT * FROM c JOIN loc IN c.locations WHERE ST_DISTANCE(loc, @myLocation) < @distance

Body:
Here is a sample document that we would like to store:

{
  "name": "Joe Bloggs",
   "locations": [
        { "type": "Point", "coordinates": [1,1] },
        { "type": "Point", "coordinates": [2,2] }
   ]
}

The key feature of the document is that the "locations" property is an array of GeoJSON points.

According to the documentation it is possible to define an indexing policy for the locations array.

However, it's not clear whether spatial queries such as ST_WITHIN can be used to search, for example, whether any of the points in the array fall within a certain radius of a specified point.

My question: Does CosmosDB support indexing and querying of spatial data when stored in an array?


问:
static initialization in interface
When I tried to write something like this:

```<code>public interface MyInterface {
    static {
        System.out.println("Hello!");
    }
}
</code>```

the compiler could not compile it.

But when I wrote something like this:

```<code>interface MyInterface {
    Integer iconst = Integer.valueOf(1);
}
</code>```

and decompiled it, I saw static initialization:

```<code>public interface MyInterface{
    public static final java.lang.Integer i;

    static {};
      Code:
      0:   iconst_1
      1:   invokestatic    #1; //Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      4:   putstatic       #2; //Field i:Ljava/lang/Integer;
      7:   return
}
</code>```

Could you please explain this behavior to me?

答:
Intefaces does not have any initialization blocks. Following code snippet may be helpful..</p>

```<code>public interface MyInterface {
public static final int a;// Compilation error as there is no way for
                          // explicit initialization

}

public class MyClass {
public static final int a;// Still no error as there is another way to
                          //initialize variable even though they are final.
 static{
    a=10;
   }

}
</code>```

Title: static initialization in interface

Body:
When I tried to write something like this:

public interface MyInterface {
    static {
        System.out.println("Hello!");
    }
}

the compiler could not compile it.

But when I wrote something like this:

interface MyInterface {
    Integer iconst = Integer.valueOf(1);
}

and decompiled it, I saw static initialization:

public interface MyInterface{
    public static final java.lang.Integer i;

    static {};
      Code:
      0:   iconst_1
      1:   invokestatic    #1; //Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      4:   putstatic       #2; //Field i:Ljava/lang/Integer;
      7:   return
}

Could you please explain this behavior to me?

Body:
Intefaces does not have any initialization blocks. Following code snippet may be helpful..

public interface MyInterface {
public static final int a;// Compilation error as there is no way for
                          // explicit initialization

}

public class MyClass {
public static final int a;// Still no error as there is another way to
                          //initialize variable even though they are final.
 static{
    a=10;
   }

}


问:
css line-height : number to px
am doing an automation tool which has to pick html css properties (font-color, size, etc..), and am done most of the part.Here the problem is, some case am getting the css property(line-height), line-height : 1.54 . Here for some purpose, i need to convert the number(1.54) to px value(like, line-height : 15px). So, Is it possible to do this calculation ?

答:
Unitless line-height refers to the font-size of the element.

If your element has set font-size: 14px, do the simple math:

```<code>1.54 * 14px = 21.56px
</code>```

You can get more information here:

https://developer.mozilla.org/en/docs/Web/CSS/line-height

Title: css line-height : number to px

Body:
Unitless line-height refers to the font-size of the element.

If your element has set font-size: 14px, do the simple math:

1.54 * 14px = 21.56px

You can get more information here:

https://developer.mozilla.org/en/docs/Web/CSS/line-height


问:
Add columns dynamically and Later Parse values in the respective columns
I have an SP which accepts the Inputtable as parameter, My Inputtable is as shown in the code

```<code>`create table inputTable ( id int,ItemQty varchar(100))
insert into inputTable(id, ItemQty) values(1,'a,b,c')
insert into inputTable(id, ItemQty) values(2,'x,y')
insert into inputTable(id, ItemQty) values(3,'l,m,n,o,p')
insert into inputTable(id, ItemQty) values(4,'a,b')
insert into inputTable(id, ItemQty) values(5,'m')`
</code>```

and SP i have written is like below

```<code>`ALTER PROCEDURE [dbo].[Column_Dynamics] (@tablename varchar(50))

AS
BEGIN

-----
declare @maxcount as int
set @maxcount='select MAX(len(ITEMQTY) - len(replace(ITEMQTY, '','', '''')) +1) from '+@tablename

exec('select MAX(len(ITEMQTY) - len(replace(ITEMQTY, '','', '''')) +1) from '+@tablename)
print @maxcount
exec @maxcount
print @maxcount

declare @var varchar(100)
IF EXISTS(SELECT * FROM   sys.columns WHERE  object_id = Object_id(@tablename))
set @var='alter table '+ @tablename +' ADD column QTY1'
exec(@var)
select * from @tablename
select max(len(ItemQty))-max(len(replace(ItemQty, ',', ''))-1) from inputtable

END`
</code>```

My table is :

step 1 ) I want to add the columns dynamically to inputtable like QTY1,QTY2,QTY3,QTY4,QTY5 because maximum count of ItemQty column is 5, by considering comma as delimiter as shown in figure1

**step 2) ** Parse values in the respective columns(by considering the delimiter comma (,).as shown in figure2

Later SP: I got till here, But Not getting the second step, that is update Parse values in the respective columns.

```<code>ALTER PROCEDURE dynamic_tbl (@tablename varchar(50))

AS
BEGIN

DECLARE @ColumnCount int
DECLARE @rowcount TABLE (Value int);
INSERT INTO @rowcount
EXEC('select MAX(len(ITEMQTY) - len(replace(ITEMQTY, '','', '''')) +1) from '+@tablename);
SELECT @ColumnCount = Value FROM @rowcount;

    Declare @ColumnName nvarchar(10)='qty_'
    Declare @count int =0
    IF(@ColumnCount>0)
    BEGIN
        IF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND  TABLE_NAME = 'dyn_tbl'))
        BEGIN
        DROP TABLE dyn_tbl
        END

        select * into dyn_tbl from inputtable
        SET @count=@count +1;
        WHile(@ColumnCount>=@count)
        BEGIN
            SET @ColumnName='qty_'+CONVERT(varchar(2),@count)
            EXEC ('ALTER TABLE dyn_tbl ADD ['+@ColumnName +'] varchar(20)')

            declare @myvar as varchar(max)

            set @myvar='update '+@tablename+' set '+@ColumnName +' =itemQty'

--exec dynamic_tbl 'dyn_tbl'

--select * from dyn_tbl

            --CAST('<A>'+REPLACE(ITEMQTY, ',', '</A><A>')+'</A>' AS XML)
            print @myvar

            exec(@myvar)

            SET @count=@count +1;
        END
    END

----
END
</code>```

答:
Procedure to alter given table dynamically based on column length as you have asked

```<code>Alter PROCEDURE [dbo].[Column_Dynamics] (@tablename varchar(50))
AS
BEGIN
drop table ##temp
declare @query1 varchar(max)
exec ( '
create table ##temp (id int identity,columnsl varchar(100))
declare @maxcount as int
set @maxcount = (select MAX(len(ITEMQTY) - len(replace(ITEMQTY, '','', '''')) +1) from '+@tablename+')

declare @count int = 1
while (@count <= @maxcount)
begin
declare @colvar nvarchar(100)= ''QTY''
set @colvar = concat(@colvar,@count)
set @count = @count + 1

insert into ##temp select @colvar
end
')

declare @tempstart int = 1
declare @templast int = (select count(*) from ##temp)
declare @updatecol varchar(100) = ''

while (@tempstart <= @templast)
Begin
set @updatecol = (select columnsl from ##temp where id = @tempstart)
exec ('alter table '+@tablename+' Add '+@updatecol+' varchar(100) ')
set @tempstart = @tempstart + 1
end
End
</code>```

output for inputTable:

```<code>id  ItemQty    QTY1   QTY2     QTY3   QTY4    QTY5
1   a,b,c      NULL   NULL    NULL    NULL     NULL
2   x,y        NULL   NULL    NULL    NULL    NULL
3   l,m,n,o,p  NULL   NULL    NULL    NULL    NULL
4   a,b        NULL   NULL    NULL    NULL    NULL
5   m          NULL   NULL    NULL    NULL    NULL
</code>```

may not be the best way but works.

edit

Altered above procedure to perform both actions, Please use below procedure

```<code>Alter PROCEDURE [dbo].[Column_Dynamics] (@tablename varchar(50))
AS
BEGIN
--  declare @tablename varchar(100) = 'inputTable'
drop table #temp if object_id('temp..#temp') is not null drop table #temp
declare @query1 varchar(max)
create table #temp (id int identity,columnsl varchar(100))
exec ( '
declare @maxcount as int
set @maxcount = (select MAX(len(ITEMQTY) - len(replace(ITEMQTY, '','', '''')) +1) from '+@tablename+')

declare @count int = 1
while (@count <= @maxcount)
begin
declare @colvar nvarchar(100)= ''QTY''
set @colvar = concat(@colvar,@count)
set @count = @count + 1

insert into #temp
select @colvar

end

')
declare @tempstart int = 1
declare @templast int = (select count(*) from #temp)
declare @updatecol varchar(100) = ''
declare @itemqty varchar(100)

while (@tempstart <= @templast)
Begin
set @updatecol = (select columnsl from #temp where id = @tempstart)
exec ('alter table '+@tablename+' Add '+@updatecol+' varchar(100) ')

set @tempstart = @tempstart + 1
end

declare @sysvar table (id int identity,cols varchar(100))
insert into @sysvar select sys.columns.name AS ColumnName FROM sys.columns JOIN sys.tables ON sys.columns.object_id = sys.tables.object_id  WHERE sys.tables.name = 'inputTable'

declare @finvar table (id int identity,cols varchar(100))
insert into @finvar select cols from @sysvar where id not in (1,2)

declare @cat int = 1  declare @dog int = (select max(id) from inputTable)

while (@cat <= @dog)
begin
drop table #tab2
if object_id('temp..#tab2') is not null drop table #tab2
create table #tab2 (id int identity,fnvalues varchar(100))

set @itemqty = (select itemqty from inputTable where id = @cat)
insert into #tab2 select item from [dbo].[fnSplit](@itemQty,',')

declare @cn int = 1
declare @max int = (select max(id) from #tab2)
declare @sql nvarchar (1000);

while (@cn <= @max)
begin
declare @upcol varchar(100) = (select fnvalues from #tab2 where id = @cn)
declare @plscol varchar(100) = (select cols from @finvar where id = @cn)

set @sql = N'update '+@tablename+' set ' + @plscol + '= '''+@upcol+''' where id = '''+cast(@cat as varchar(10))+''' ';
select @sql
exec sp_executesql @sql;

set @cn = @cn + 1

end
set @cat = @cat + 1
End

End
</code>```

output:

```<code>id  ItemQty    QTY1 QTY2 QTY3   QTY4    QTY5
1   a,b,c       a   b     c      NULL   NULL
2   x,y         x   y     NULL   NULL   NULL
3   l,m,n,o,p   l   m     n      o      p
4   a,b         a   b     NULL   NULL   NULL
5   m           m   NULL  NULL   NULL   NULL
</code>```

did not optimize the query but works fine.

Body:
I have an SP which accepts the Inputtable as parameter, My Inputtable is as shown in the code

`create table inputTable ( id int,ItemQty varchar(100))
insert into inputTable(id, ItemQty) values(1,'a,b,c')
insert into inputTable(id, ItemQty) values(2,'x,y')
insert into inputTable(id, ItemQty) values(3,'l,m,n,o,p')
insert into inputTable(id, ItemQty) values(4,'a,b')
insert into inputTable(id, ItemQty) values(5,'m')`

and SP i have written is like below

`ALTER PROCEDURE [dbo].[Column_Dynamics] (@tablename varchar(50))

AS
BEGIN

-----
declare @maxcount as int
set @maxcount='select MAX(len(ITEMQTY) - len(replace(ITEMQTY, '','', '''')) +1) from '+@tablename

exec('select MAX(len(ITEMQTY) - len(replace(ITEMQTY, '','', '''')) +1) from '+@tablename)
print @maxcount
exec @maxcount
print @maxcount

declare @var varchar(100)
IF EXISTS(SELECT * FROM   sys.columns WHERE  object_id = Object_id(@tablename))
set @var='alter table '+ @tablename +' ADD column QTY1'
exec(@var)
select * from @tablename
select max(len(ItemQty))-max(len(replace(ItemQty, ',', ''))-1) from inputtable

END`

My table is :

step 1 ) I want to add the columns dynamically to inputtable like QTY1,QTY2,QTY3,QTY4,QTY5 because maximum count of ItemQty column is 5, by considering comma as delimiter as shown in figure1

**step 2) ** Parse values in the respective columns(by considering the delimiter comma (,).as shown in figure2

Later SP: I got till here, But Not getting the second step, that is update Parse values in the respective columns.

ALTER PROCEDURE dynamic_tbl (@tablename varchar(50))

AS
BEGIN

DECLARE @ColumnCount int
DECLARE @rowcount TABLE (Value int);
INSERT INTO @rowcount
EXEC('select MAX(len(ITEMQTY) - len(replace(ITEMQTY, '','', '''')) +1) from '+@tablename);
SELECT @ColumnCount = Value FROM @rowcount;

    Declare @ColumnName nvarchar(10)='qty_'
    Declare @count int =0
    IF(@ColumnCount>0)
    BEGIN
        IF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND  TABLE_NAME = 'dyn_tbl'))
        BEGIN
        DROP TABLE dyn_tbl
        END

        select * into dyn_tbl from inputtable
        SET @count=@count +1;
        WHile(@ColumnCount>=@count)
        BEGIN
            SET @ColumnName='qty_'+CONVERT(varchar(2),@count)
            EXEC ('ALTER TABLE dyn_tbl ADD ['+@ColumnName +'] varchar(20)')

            declare @myvar as varchar(max)

            set @myvar='update '+@tablename+' set '+@ColumnName +' =itemQty'

--exec dynamic_tbl 'dyn_tbl'

--select * from dyn_tbl

            --CAST(''+REPLACE(ITEMQTY, ',', '')+'' AS XML)
            print @myvar

            exec(@myvar)

            SET @count=@count +1;
        END
    END

----
END

Body:
Procedure to alter given table dynamically based on column length as you have asked

Alter PROCEDURE [dbo].[Column_Dynamics] (@tablename varchar(50))
AS
BEGIN
drop table ##temp
declare @query1 varchar(max)
exec ( '
create table ##temp (id int identity,columnsl varchar(100))
declare @maxcount as int
set @maxcount = (select MAX(len(ITEMQTY) - len(replace(ITEMQTY, '','', '''')) +1) from '+@tablename+')

declare @count int = 1
while (@count <= @maxcount)
begin
declare @colvar nvarchar(100)= ''QTY''
set @colvar = concat(@colvar,@count)
set @count = @count + 1

insert into ##temp select @colvar
end
')

declare @tempstart int = 1
declare @templast int = (select count(*) from ##temp)
declare @updatecol varchar(100) = ''

while (@tempstart <= @templast)
Begin
set @updatecol = (select columnsl from ##temp where id = @tempstart)
exec ('alter table '+@tablename+' Add '+@updatecol+' varchar(100) ')
set @tempstart = @tempstart + 1
end
End

output for inputTable:

id  ItemQty    QTY1   QTY2     QTY3   QTY4    QTY5
1   a,b,c      NULL   NULL    NULL    NULL     NULL
2   x,y        NULL   NULL    NULL    NULL    NULL
3   l,m,n,o,p  NULL   NULL    NULL    NULL    NULL
4   a,b        NULL   NULL    NULL    NULL    NULL
5   m          NULL   NULL    NULL    NULL    NULL

may not be the best way but works.

edit

Altered above procedure to perform both actions, Please use below procedure

Alter PROCEDURE [dbo].[Column_Dynamics] (@tablename varchar(50))
AS
BEGIN
--  declare @tablename varchar(100) = 'inputTable'
drop table #temp if object_id('temp..#temp') is not null drop table #temp
declare @query1 varchar(max)
create table #temp (id int identity,columnsl varchar(100))
exec ( '
declare @maxcount as int
set @maxcount = (select MAX(len(ITEMQTY) - len(replace(ITEMQTY, '','', '''')) +1) from '+@tablename+')

declare @count int = 1
while (@count <= @maxcount)
begin
declare @colvar nvarchar(100)= ''QTY''
set @colvar = concat(@colvar,@count)
set @count = @count + 1

insert into #temp
select @colvar

end

')
declare @tempstart int = 1
declare @templast int = (select count(*) from #temp)
declare @updatecol varchar(100) = ''
declare @itemqty varchar(100)

while (@tempstart <= @templast)
Begin
set @updatecol = (select columnsl from #temp where id = @tempstart)
exec ('alter table '+@tablename+' Add '+@updatecol+' varchar(100) ')

set @tempstart = @tempstart + 1
end

declare @sysvar table (id int identity,cols varchar(100))
insert into @sysvar select sys.columns.name AS ColumnName FROM sys.columns JOIN sys.tables ON sys.columns.object_id = sys.tables.object_id  WHERE sys.tables.name = 'inputTable'

declare @finvar table (id int identity,cols varchar(100))
insert into @finvar select cols from @sysvar where id not in (1,2)

declare @cat int = 1  declare @dog int = (select max(id) from inputTable)

while (@cat <= @dog)
begin
drop table #tab2
if object_id('temp..#tab2') is not null drop table #tab2
create table #tab2 (id int identity,fnvalues varchar(100))

set @itemqty = (select itemqty from inputTable where id = @cat)
insert into #tab2 select item from [dbo].[fnSplit](@itemQty,',')

declare @cn int = 1
declare @max int = (select max(id) from #tab2)
declare @sql nvarchar (1000);

while (@cn <= @max)
begin
declare @upcol varchar(100) = (select fnvalues from #tab2 where id = @cn)
declare @plscol varchar(100) = (select cols from @finvar where id = @cn)

set @sql = N'update '+@tablename+' set ' + @plscol + '= '''+@upcol+''' where id = '''+cast(@cat as varchar(10))+''' ';
select @sql
exec sp_executesql @sql;

set @cn = @cn + 1

end
set @cat = @cat + 1
End

End

output:

id  ItemQty    QTY1 QTY2 QTY3   QTY4    QTY5
1   a,b,c       a   b     c      NULL   NULL
2   x,y         x   y     NULL   NULL   NULL
3   l,m,n,o,p   l   m     n      o      p
4   a,b         a   b     NULL   NULL   NULL
5   m           m   NULL  NULL   NULL   NULL

did not optimize the query but works fine.


问:
Pagination will not go beyond the post
Next and Previous pagination.
For previous pagination page not go to negative like not below to 0 but for Next it should not go more than the posts. When i click next it will make the pages to the amount of click going more than the posts. For precious i have done this but what do i do for next. How to disable the next when the posts end or page will not go more then the posts. I can't figure this out. Any help would be appreciate.

php

```<code><?php
$page = (isset($_GET['page']) && $_GET['page'] > 0) ? (int)$_GET['page'] : 1;
$perpage = 10;
$limitp = ($page > 1) ? ($page * $perpage) - $perpage : 0;

$query = mysqli_query($dbc, "SELECT SQL_CALC_FOUND_ROWS * FROM test LIMIT {$limitp}, {$perpage}");
$records = mysqli_fetch_all($query);

$total = mysqli_query($dbc, "SELECT FOUND_ROWS() as total");
$total = mysqli_fetch_assoc($total)['total'];

$pages = ceil($total/$perpage);

?>

<?php
include ("connection.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Pagination</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>

<div>
    <a href="?page=<?php $pagep = $page -1; echo $pagep; ?>">Prev</a>
    <a href="?page=<?php $pagen = $page +1; echo $pagen; ?>">Next</a>
</div>

<table>
    <tr>
        <th>ID</th>
        <th>Email</th>
    </tr>
    <?php foreach ($records as $record): ?>
        <tr>
            <td><?php echo $record[0]; ?></td>
            <td><?php echo $record[4]; ?></td>
        </tr>
    <?php endforeach; ?>
</table>
</body>
</html>
</code>```

答:
you need to add condition for prev button if current page is greter than 1 than and than you display prev btn same as for next button if you current page is less total pages (i.e totalrecord / limit in your case limit is 10 and if total record is 22 than 22/10 is equal to 2.2 get ceil valu which make 2.2 to 3) so if current page is less than 3 than and than display next buttton

hope its make sense I am also trying to solved in your code hope this code work

<?php
$page = (isset($_GET['page']) && $_GET['page'] > 0) ? (int)$_GET['page'] : 1;
$perpage = 10;
$limitp = ($page > 1) ? ($page * $perpage) - $perpage : 0;
$limitn = ($limito)

$query = mysqli_query($dbc, "SELECT SQL_CALC_FOUND_ROWS * FROM test LIMIT {$limitp}, {$perpage}");
$records = mysqli_fetch_all($query);

$total = mysqli_query($dbc, "SELECT FOUND_ROWS() as total");
$total = mysqli_fetch_assoc($total)['total'];

$pages = ceil($total/$perpage);

?>

<?php
include ("connection.php");
?>
<!DOCTYPE html>

    <meta charset="UTF-8">
    <title>Pagination</title>
    <link rel="stylesheet" href="style.css">

<?php
if($page>1){
?>
    ">Prev
<?php
}
?>

<?php
if($page<$pages){
?>
    ">Next
<?php
}
?>

        ID
        Email

    <?php foreach ($records as $record): ?>

            <?php echo $record[0]; ?>
            <?php echo $record[4]; ?>

    <?php endforeach; ?>

```

Title: Pagination will not go beyond the post

Body:
Next and Previous pagination.
For previous pagination page not go to negative like not below to 0 but for Next it should not go more than the posts. When i click next it will make the pages to the amount of click going more than the posts. For precious i have done this but what do i do for next. How to disable the next when the posts end or page will not go more then the posts. I can't figure this out. Any help would be appreciate.

php

<?php
$page = (isset($_GET['page']) && $_GET['page'] > 0) ? (int)$_GET['page'] : 1;
$perpage = 10;
$limitp = ($page > 1) ? ($page * $perpage) - $perpage : 0;

$query = mysqli_query($dbc, "SELECT SQL_CALC_FOUND_ROWS * FROM test LIMIT {$limitp}, {$perpage}");
$records = mysqli_fetch_all($query);

$total = mysqli_query($dbc, "SELECT FOUND_ROWS() as total");
$total = mysqli_fetch_assoc($total)['total'];

$pages = ceil($total/$perpage);

?>

<?php
include ("connection.php");
?>
<!DOCTYPE html>

    <meta charset="UTF-8">
    <title>Pagination</title>
    <link rel="stylesheet" href="style.css">

    <a href="?page=<?php $pagep = $page -1; echo $pagep; ?>">Prev
    <a href="?page=<?php $pagen = $page +1; echo $pagen; ?>">Next

        ID
        Email

    <?php foreach ($records as $record): ?>

            <?php echo $record[0]; ?>
            <?php echo $record[4]; ?>

    <?php endforeach; ?>

Body:
you need to add condition for prev button if current page is greter than 1 than and than you display prev btn same as for next button if you current page is less total pages (i.e totalrecord / limit in your case limit is 10 and if total record is 22 than 22/10 is equal to 2.2 get ceil valu which make 2.2 to 3) so if current page is less than 3 than and than display next buttton

hope its make sense I am also trying to solved in your code hope this code work

<?php
$page = (isset($_GET['page']) && $_GET['page'] > 0) ? (int)$_GET['page'] : 1;
$perpage = 10;
$limitp = ($page > 1) ? ($page * $perpage) - $perpage : 0;
$limitn = ($limito)

$query = mysqli_query($dbc, "SELECT SQL_CALC_FOUND_ROWS * FROM test LIMIT {$limitp}, {$perpage}");
$records = mysqli_fetch_all($query);

$total = mysqli_query($dbc, "SELECT FOUND_ROWS() as total");
$total = mysqli_fetch_assoc($total)['total'];

$pages = ceil($total/$perpage);

?>

<?php
include ("connection.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Pagination</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>

<div>
<?php
if($page>1){
?>
    <a href="?page=<?php $pagep = $page -1; echo $pagep; ?>">Prev</a>
<?php
}
?>

<?php
if($page<$pages){
?>
    <a href="?page=<?php $pagen = $page +1; echo $pagen; ?>">Next</a>
<?php
}
?>

</div>

<table>
    <tr>
        <th>ID</th>
        <th>Email</th>
    </tr>
    <?php foreach ($records as $record): ?>
        <tr>
            <td><?php echo $record[0]; ?></td>
            <td><?php echo $record[4]; ?></td>
        </tr>
    <?php endforeach; ?>
</table>
</body>
</html>


问:
Insert Separator in glue_data using magrittr
I am building up a simple INSERT INTO query from a data frame as with the toy example:

```<code>library(datasets)
library(magrittr)
library(reprex)
insert_into_01 <-
    "INSERT INTO teams (mpg, cyl, disp, hp, drat)\nVALUES"

# The separator does not get inserted at the end of each () line
insert_into_02 <- head(mtcars, 5) %>%
    glue::glue_data("({mpg}, {cyl}, {disp}, \\
                    {hp}, {drat})", .sep = ",")

insert_into_03 <- ";"

qry_create_teams_04 <- stringr::str_c(c(insert_into_01, insert_into_02,
                                        insert_into_03),
                                      collapse = "\n")

qry_create_teams_04 %>% cat()
#> INSERT INTO teams (mpg, cyl, disp, hp, drat)
#> VALUES
#> (21, 6, 160, 110, 3.9)
#> (21, 6, 160, 110, 3.9)
#> (22.8, 4, 108, 93, 3.85)
#> (21.4, 6, 258, 110, 3.08)
#> (18.7, 8, 360, 175, 3.15)
#> ;
</code>```

The problem is that the .sep command does not seem to be passed in correctly in the glue_data function. The value entries should have a comma , after each entry.

EDIT: The expected output is:

```<code>#> INSERT INTO teams (mpg, cyl, disp, hp, drat)
#> VALUES
#> (21, 6, 160, 110, 3.9), #<-- see the comma at the end
#> (21, 6, 160, 110, 3.9), #<-- another comma here
#> (22.8, 4, 108, 93, 3.85),
#> (21.4, 6, 258, 110, 3.08),
#> (18.7, 8, 360, 175, 3.15) # <-- no comma for the last entry
#> ;
</code>```

Could anyone please help assist with the above?

I specifically want to code to use tidyverse and glue packages as cleanly as possible to allow for this ideally

答:
.sep is a separator that is applied when you supply multiple arguments. If you need a trailing character, just add it as last argument:

```<code>glue_data(head(mtcars, 4), "({mpg}, {cyl}, {disp}, {hp}, {drat})", ",")
#> (21, 6, 160, 110, 3.9),
#> (21, 6, 160, 110, 3.9),
#> (22.8, 4, 108, 93, 3.85),
#> (21.4, 6, 258, 110, 3.08),
</code>```

This supposes an empty separator "" which is the default.

Body:
I am building up a simple INSERT INTO query from a data frame as with the toy example:

library(datasets)
library(magrittr)
library(reprex)
insert_into_01 <-
    "INSERT INTO teams (mpg, cyl, disp, hp, drat)\nVALUES"

# The separator does not get inserted at the end of each () line
insert_into_02 <- head(mtcars, 5) %>%
    glue::glue_data("({mpg}, {cyl}, {disp}, \\
                    {hp}, {drat})", .sep = ",")

insert_into_03 <- ";"

qry_create_teams_04 <- stringr::str_c(c(insert_into_01, insert_into_02,
                                        insert_into_03),
                                      collapse = "\n")

qry_create_teams_04 %>% cat()
#> INSERT INTO teams (mpg, cyl, disp, hp, drat)
#> VALUES
#> (21, 6, 160, 110, 3.9)
#> (21, 6, 160, 110, 3.9)
#> (22.8, 4, 108, 93, 3.85)
#> (21.4, 6, 258, 110, 3.08)
#> (18.7, 8, 360, 175, 3.15)
#> ;

The problem is that the .sep command does not seem to be passed in correctly in the glue_data function. The value entries should have a comma , after each entry.

EDIT: The expected output is:

#> INSERT INTO teams (mpg, cyl, disp, hp, drat)
#> VALUES
#> (21, 6, 160, 110, 3.9), #<-- see the comma at the end
#> (21, 6, 160, 110, 3.9), #<-- another comma here
#> (22.8, 4, 108, 93, 3.85),
#> (21.4, 6, 258, 110, 3.08),
#> (18.7, 8, 360, 175, 3.15) # <-- no comma for the last entry
#> ;

Could anyone please help assist with the above?

I specifically want to code to use tidyverse and glue packages as cleanly as possible to allow for this ideally

Body:
.sep is a separator that is applied when you supply multiple arguments. If you need a trailing character, just add it as last argument:

glue_data(head(mtcars, 4), "({mpg}, {cyl}, {disp}, {hp}, {drat})", ",")
#> (21, 6, 160, 110, 3.9),
#> (21, 6, 160, 110, 3.9),
#> (22.8, 4, 108, 93, 3.85),
#> (21.4, 6, 258, 110, 3.08),

This supposes an empty separator "" which is the default.


问:
Understanding solr field cache
While I was working on this solr LowerCaseFilterFactory not working, I got the following error:

```<code>...enable docvalues true n reindex or place useFieldCache=true...
</code>```

It was resolved by specifying useFieldCache=true in the query.

Is it the lucene FieldCache?

Can anybody help me know more about this?

答:
When you're using docValues, the field cache isn't used. Since docValues isn't implemented for TextFields yet, the filtering hasn't been applied like you think it would, so the values used for sorting isn't lowercased as you'd assume they'd be.

When you tell Solr to explicitly use the FieldCache, you're saying "don't use the docValues, even if they're available - use the old FieldCache implementation instead".

The correct solution would be to disable docValues for the Text field.

Title: Understanding solr field cache

Body:
While I was working on this solr LowerCaseFilterFactory not working, I got the following error:

...enable docvalues true n reindex or place useFieldCache=true...

It was resolved by specifying useFieldCache=true in the query.

Is it the lucene FieldCache?

Can anybody help me know more about this?


问:
how to Disappear app icon from launcher?
I want to disappear my app icon from launcher and app will automatically restart after some time.
I did code for hiding icon below:

```<code> try {
       PackageManager p = context.getPackageManager();
        ComponentName componentName = new ComponentName("com.package.name", "com.class.name");
        p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    } catch (Exception e) {
        Log.d("ERROR@@", "" + e.toString());
    }
</code>```

this is code for reopening my app after some time

```<code>public void initializingTimerTask() {
    timerTask = new TimerTask() {
        @Override
        public void run() {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    if (mIsInForegroundMode == false) {
                        Intent LaunchIntent=getPackageManager().getLaunchIntentForPackage("com.package.name");
                        LaunchIntent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(LaunchIntent);
                    } else {
                    }
                }
            });
        }
    };
}
</code>```

The error:

```<code> 11-16 14:10:02.802 18503-18503/com.package.newproject E/AndroidRuntime: FATAL EXCEPTION:
    main Process: com.package.newproject, PID: 18503 java.lang.NullPointerException
    at com.mspatel.package.newproject.AutoOpenAppService$1$1.run(AutoOpenAppService.java:101)
    at android.os.Handler.handleCallback(Handler.java:743)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5212)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
    at dalvik.system.NativeStart.main(Native Method)
</code>```

but when turn to restart application app going to crash please help me.

答:
If I am understanding correctly than here it is.
To hide the icon use this:

```<code>PackageManager p = getPackageManager();
    ComponentName componentName = new ComponentName(this, com.sstudio.sysUtil.TheActivity.class); // activity which is first time open in manifiest file which is declare as <category android:name="android.intent.category.LAUNCHER" />
    p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
</code>```

And remember, before opening the app again, you need to unhide the icon first, and then open the app, or else it will crash. do it like this:

```<code>PackageManager p = context.getPackageManager();
        ComponentName componentName = new ComponentName(context, TheActivity.class);
        p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); // to unhide the icon and to prevent the app from crashing
        Intent i = new Intent(context, TheActivity.class);// use your own intent as required
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);// and add flags as required
        context.startActivity(i);//and open activity
</code>```

I had the same problem. This did solve mine. Hope it solves yours too.

Edit
change your code:

```<code>public void initializingTimerTask() {
timerTask = new TimerTask() {
    @Override
    public void run() {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                if (mIsInForegroundMode == false) {
                    Intent LaunchIntent=getPackageManager().getLaunchIntentForPackage("com.package.name");
                    LaunchIntent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(LaunchIntent);
                } else {
                }
            }
        });
    }
};}
</code>```

with this:

```<code> public void initializingTimerTask() {
    timerTask = new TimerTask() {
        @Override
        public void run() {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    if (mIsInForegroundMode == false) {
PackageManager p = getPackageManager();
        ComponentName componentName = new ComponentName(getApplicationContext(), TheActivity.class);
        p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
                        Intent LaunchIntent=getPackageManager().getLaunchIntentForPackage("com.package.name");
                        LaunchIntent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(LaunchIntent);
                    } else {
                    }
                }
            });
        }
    };}
</code>```

Body:
I want to disappear my app icon from launcher and app will automatically restart after some time.
I did code for hiding icon below:

 try {
       PackageManager p = context.getPackageManager();
        ComponentName componentName = new ComponentName("com.package.name", "com.class.name");
        p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    } catch (Exception e) {
        Log.d("ERROR@@", "" + e.toString());
    }

this is code for reopening my app after some time

public void initializingTimerTask() {
    timerTask = new TimerTask() {
        @Override
        public void run() {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    if (mIsInForegroundMode == false) {
                        Intent LaunchIntent=getPackageManager().getLaunchIntentForPackage("com.package.name");
                        LaunchIntent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(LaunchIntent);
                    } else {
                    }
                }
            });
        }
    };
}

The error:

 11-16 14:10:02.802 18503-18503/com.package.newproject E/AndroidRuntime: FATAL EXCEPTION:
    main Process: com.package.newproject, PID: 18503 java.lang.NullPointerException
    at com.mspatel.package.newproject.AutoOpenAppService$1$1.run(AutoOpenAppService.java:101)
    at android.os.Handler.handleCallback(Handler.java:743)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5212)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
    at dalvik.system.NativeStart.main(Native Method)

but when turn to restart application app going to crash please help me.

Body:
If I am understanding correctly than here it is.
To hide the icon use this:

PackageManager p = getPackageManager();
    ComponentName componentName = new ComponentName(this, com.sstudio.sysUtil.TheActivity.class); // activity which is first time open in manifiest file which is declare as <category android:name="android.intent.category.LAUNCHER" />
    p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

And remember, before opening the app again, you need to unhide the icon first, and then open the app, or else it will crash. do it like this:

PackageManager p = context.getPackageManager();
        ComponentName componentName = new ComponentName(context, TheActivity.class);
        p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); // to unhide the icon and to prevent the app from crashing
        Intent i = new Intent(context, TheActivity.class);// use your own intent as required
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);// and add flags as required
        context.startActivity(i);//and open activity

I had the same problem. This did solve mine. Hope it solves yours too.

Edit
change your code:

public void initializingTimerTask() {
timerTask = new TimerTask() {
    @Override
    public void run() {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                if (mIsInForegroundMode == false) {
                    Intent LaunchIntent=getPackageManager().getLaunchIntentForPackage("com.package.name");
                    LaunchIntent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(LaunchIntent);
                } else {
                }
            }
        });
    }
};}

with this:

 public void initializingTimerTask() {
    timerTask = new TimerTask() {
        @Override
        public void run() {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    if (mIsInForegroundMode == false) {
PackageManager p = getPackageManager();
        ComponentName componentName = new ComponentName(getApplicationContext(), TheActivity.class);
        p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
                        Intent LaunchIntent=getPackageManager().getLaunchIntentForPackage("com.package.name");
                        LaunchIntent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(LaunchIntent);
                    } else {
                    }
                }
            });
        }
    };}


问:
How to resolve "Specify the 'raw' format explicitly to remove the restrictions." in qemu?
I am trying to run helloos.img on MACBOOK Pro, and even program works fine, it is showing

```<code>Specify the 'raw' format explicitly to remove the restrictions.
</code>```

How to deal with this? Is this important?

答:
The reason for this warning is that QEMU is automatically guessing the format of your disk image as raw. The problem with doing that is that if your guest was able to write to the whole of the raw image it could maliciously write (say) a QCOW2 disk header to the start of the raw image, which would mean that when the VM was restarted QEMU would guess the image type wrongly, possibly with bad results. To prevent this, QEMU refuses to allow the guest to write to the start of a probed raw format image. Mostly that won't hurt but if you try to for instance repartition the disk from within the guest it will fail.

To fix this you need to explicitly tell QEMU that the image is in raw format, but you can't do that with the convenience short options or with the "just pass a disk image filename which is assumed to be the harddisk" approach you're using. You need to use the 'long format' options to specify your disk image so that you can pass it format=raw. In this case that would be

-drive file=helloos.img,format=raw,index=0,media=disk

(This is documented in the QEMU manpage where it has "Instead of -hda, -hdb, -hdc, -hdd you can use:" and long format equivalents for the short options.)

See also https://unix.stackexchange.com/questions/276480/booting-a-raw-disk-image-in-qemu which is a similar query.

PS: your question would be easier to answer if you gave the command line you're running and the full error message in the text of the question, rather than just in a screenshot where the windows are overlapping.

Body:
I am trying to run helloos.img on MACBOOK Pro, and even program works fine, it is showing

Specify the 'raw' format explicitly to remove the restrictions.

How to deal with this? Is this important?


问:
Pandas: using shift to dataframe
I have dataframe

```<code>id     event_path
111    google.com
111    yandex.ru
111     vk.com
222     twitter.com
222     twitter.com
333     twitter.com
333     facebook.com
</code>```

Desire output

```<code>id     event_path
111    google.com
111    yandex.ru
111     vk.com
222     twitter.com
333     twitter.com
333     facebook.com
</code>```

I try to use shift to column

```<code>df.loc[(df.event_path != df.event_path.shift()) & \
       (df.id == df.id.shift())]
</code>```

and it returns me

```<code>id     event_path
111    google.com
111    yandex.ru
111     vk.com
222     twitter.com
333     facebook.com
</code>```

How can I fix that?

答:
Use pd.DataFrame.drop_duplicates

```<code>df.drop_duplicates()

    id    event_path
0  111    google.com
1  111     yandex.ru
2  111        vk.com
3  222   twitter.com
5  333   twitter.com
6  333  facebook.com
</code>```

IIUC:  OP wants to remove only when duplicate is adjacent.

```<code>df[df.eq(df.shift().bfill()).any(1)]

    id    event_path
0  111    google.com
1  111     yandex.ru
2  111        vk.com
4  222   twitter.com
5  333   twitter.com
6  333  facebook.com
</code>```

Title: Pandas: using shift to dataframe

Body:
I have dataframe

id     event_path
111    google.com
111    yandex.ru
111     vk.com
222     twitter.com
222     twitter.com
333     twitter.com
333     facebook.com

Desire output

id     event_path
111    google.com
111    yandex.ru
111     vk.com
222     twitter.com
333     twitter.com
333     facebook.com

I try to use shift to column

df.loc[(df.event_path != df.event_path.shift()) & \
       (df.id == df.id.shift())]

and it returns me

id     event_path
111    google.com
111    yandex.ru
111     vk.com
222     twitter.com
333     facebook.com

How can I fix that?

Body:
Use pd.DataFrame.drop_duplicates

df.drop_duplicates()

    id    event_path
0  111    google.com
1  111     yandex.ru
2  111        vk.com
3  222   twitter.com
5  333   twitter.com
6  333  facebook.com

IIUC:  OP wants to remove only when duplicate is adjacent.

df[df.eq(df.shift().bfill()).any(1)]

    id    event_path
0  111    google.com
1  111     yandex.ru
2  111        vk.com
4  222   twitter.com
5  333   twitter.com
6  333  facebook.com


问:
PHP line break inside of cell remove qoute
This is my PHP

```<code>$val = "";
foreach($data as $v){
  $val .= '"' . $v . "\n" . '"';
}
</code>```

The result is

```<code>//this is inside of cell
sample
"sample
"sample
</code>```

This is correct but I cant figure out how to remove the double quote in "sample. Only the first value dont have a double quote the rest will have a double quote.

EDIT

This is the result of my code

This is what I want

答:
Just Remove some part of your code, you will get solution:

```<code>$val = "";
foreach($data as $v){
  $val .= $v . "\n";
}
</code>```

Just try (Maintaining line break in excel):

```<code>    $val = "";
   foreach($data as $v){
          $val .= $v . "<br style='mso-data-placement:same-cell;' />";
        }
</code>```

Body:
This is my PHP

$val = "";
foreach($data as $v){
  $val .= '"' . $v . "\n" . '"';
}

The result is

//this is inside of cell
sample
"sample
"sample

This is correct but I cant figure out how to remove the double quote in "sample. Only the first value dont have a double quote the rest will have a double quote.

EDIT

This is the result of my code

This is what I want

Body:
Just Remove some part of your code, you will get solution:

$val = "";
foreach($data as $v){
  $val .= $v . "\n";
}

Just try (Maintaining line break in excel):

    $val = "";
   foreach($data as $v){
          $val .= $v . "<br style='mso-data-placement:same-cell;' />";
        }


问:
What does it mean myFunction is not a function?
I'm passing storyLike function from parent to child.Sometimes when onPress is clicked I get following error:           this.props.storyLike(props.story) is not a function.
I thought it's a context issue but couldn't resolve it.

Here is my Parent:

```<code>renderRow(item) {
        return (
          <Story
            story={item}
            openStory={this.props.openStory}
            getProfile={this.props.getProfile}
            storyLike={this.props.storyLike}
          />
        );
      }
</code>```

Here is child component Story, just passing props to StoryFooter component:

```<code>class Story extends Component {
  render() {
    return (
      <View style={styles.container}>
        <StoryHeader {...this.props} />
        <StoryContent {...this.props} />
        <StoryFooter {...this.props} storyViewType={"feed"} />
      </View>
    );
  }
}
</code>```

Bellow is child component, I'm triggering storyLike from onPress changeLikedStatus function:

```<code>class StoryFooter extends Component {
  state = { isLiked: false, likes: 0 };

  changeLikedState(props) {
    const numberOflikes = this.state.isLiked
      ? this.state.likes - 1
      : this.state.likes + 1;

    if (this.state.isLiked) {
      this.setState({ isLiked: false, likes: numberOflikes });
    } else {
      this.setState({ isLiked: true, likes: numberOflikes });
    }
      this.props.storyLike(props.story);
  }

            <TouchableOpacity onPress={() => this.changeLikedState(this.props)}>
</code>```

答:
This is how your parent should look like

```<code>  renderRow(item) {
            return (
              <Story
                // ... other props
                storyLike={(prop) => this.props.storyLike(prop)}
              />
            );
          }
</code>```

This way you explicitly tell that the child will be passing a prop to the function.

Hopefully your storyLike function is an arrow function that looks like this:

```<code>storyLike = (prop) => {
    // code
}
</code>```

Body:
I'm passing storyLike function from parent to child.Sometimes when onPress is clicked I get following error:           this.props.storyLike(props.story) is not a function.
I thought it's a context issue but couldn't resolve it.

Here is my Parent:

renderRow(item) {
        return (
          <Story
            story={item}
            openStory={this.props.openStory}
            getProfile={this.props.getProfile}
            storyLike={this.props.storyLike}
          />
        );
      }

Here is child component Story, just passing props to StoryFooter component:

class Story extends Component {
  render() {
    return (
      <View style={styles.container}>
        <StoryHeader {...this.props} />
        <StoryContent {...this.props} />
        <StoryFooter {...this.props} storyViewType={"feed"} />
      </View>
    );
  }
}

Bellow is child component, I'm triggering storyLike from onPress changeLikedStatus function:

class StoryFooter extends Component {
  state = { isLiked: false, likes: 0 };

  changeLikedState(props) {
    const numberOflikes = this.state.isLiked
      ? this.state.likes - 1
      : this.state.likes + 1;

    if (this.state.isLiked) {
      this.setState({ isLiked: false, likes: numberOflikes });
    } else {
      this.setState({ isLiked: true, likes: numberOflikes });
    }
      this.props.storyLike(props.story);
  }

            <TouchableOpacity onPress={() => this.changeLikedState(this.props)}>

Body:
This is how your parent should look like

  renderRow(item) {
            return (
              <Story
                // ... other props
                storyLike={(prop) => this.props.storyLike(prop)}
              />
            );
          }

This way you explicitly tell that the child will be passing a prop to the function.

Hopefully your storyLike function is an arrow function that looks like this:

storyLike = (prop) => {
    // code
}


问:
Regular expression to get class in Java
I have a dynamic array which brings back methods, class and parameters. For example:

```<code>org.junit.internal.builders.AllDefaultPossibilitiesBuilder.ignoredBuilder()---begin--->count:1
</code>```

I need a regular expression to get class org.junit.internal.builders and count

How to do the regex? I have tried this

```<code>(.*([.]))
</code>```

and i m not sure if this is right.

答:
It seems your looking for the package name, not the class name.

you might use this regex to capture its parts:

```<code>^([a-z][^.]+(?:\.[a-z][^.]*)*)\.([A-Z][^.]+)\.([\w]+\([^)]*\))[-]*([^-]+)[->]*([^:]+):([^:]*)
</code>```

Applied to your string:

Group 1: org.junit.internal.builders

Group 2: AllDefaultPossibilitiesBuilder

Group 3: ignoredBuilder()

Group 4: begin

Group 5: count

Group 6: 1

Title: Regular expression to get class in Java

Body:
I have a dynamic array which brings back methods, class and parameters. For example:

org.junit.internal.builders.AllDefaultPossibilitiesBuilder.ignoredBuilder()---begin--->count:1

I need a regular expression to get class org.junit.internal.builders and count

How to do the regex? I have tried this

(.*([.]))

and i m not sure if this is right.

Body:
It seems your looking for the package name, not the class name.

you might use this regex to capture its parts:

^([a-z][^.]+(?:\.[a-z][^.]*)*)\.([A-Z][^.]+)\.([\w]+\([^)]*\))[-]*([^-]+)[->]*([^:]+):([^:]*)

Applied to your string:

Group 1: org.junit.internal.builders

Group 2: AllDefaultPossibilitiesBuilder

Group 3: ignoredBuilder()

Group 4: begin

Group 5: count

Group 6: 1