mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-20 12:36:07 -05:00
#72 Enhances management of wildcard values for aliases. Calculates a relative weighting for each wildcard alias id and then orders (smallest to largest) the wildcard values so that when attempting to lookup an id value, it first attempts to look for a direct match and then defaults to iterating the list of wildcard values until it finds the most specific or best matching wildcard value.
This commit is contained in:
1
.idea/dictionaries/denny.xml
generated
1
.idea/dictionaries/denny.xml
generated
@@ -1,6 +1,7 @@
|
|||||||
<component name="ProjectDictionaryState">
|
<component name="ProjectDictionaryState">
|
||||||
<dictionary name="denny">
|
<dictionary name="denny">
|
||||||
<words>
|
<words>
|
||||||
|
<w>esnid</w>
|
||||||
<w>fleetsync</w>
|
<w>fleetsync</w>
|
||||||
<w>ident</w>
|
<w>ident</w>
|
||||||
<w>talkgroup</w>
|
<w>talkgroup</w>
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
package alias;
|
package alias;
|
||||||
|
|
||||||
import alias.id.AliasID;
|
import alias.id.AliasID;
|
||||||
|
import alias.id.WildcardID;
|
||||||
import alias.id.esn.Esn;
|
import alias.id.esn.Esn;
|
||||||
import alias.id.fleetsync.FleetsyncID;
|
import alias.id.fleetsync.FleetsyncID;
|
||||||
import alias.id.lojack.LoJackFunctionAndID;
|
import alias.id.lojack.LoJackFunctionAndID;
|
||||||
@@ -36,33 +37,36 @@ import sample.Listener;
|
|||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAttribute;
|
import javax.xml.bind.annotation.XmlAttribute;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class AliasList implements Listener<AliasEvent>
|
public class AliasList implements Listener<AliasEvent>
|
||||||
{
|
{
|
||||||
private final static Logger mLog = LoggerFactory.getLogger( AliasList.class );
|
private final static Logger mLog = LoggerFactory.getLogger(AliasList.class);
|
||||||
public static final String WILDCARD = "*";
|
public static final String WILDCARD = "*";
|
||||||
|
public static final String REGEX_WILDCARD = ".";
|
||||||
|
|
||||||
private Map<String,Alias> mESN = new HashMap<>();
|
private Map<String, Alias> mESN = new HashMap<>();
|
||||||
private Map<String,Alias> mFleetsync = new HashMap<>();
|
private Map<String, Alias> mFleetsync = new HashMap<>();
|
||||||
private Map<LoJackFunctionAndID,Alias> mLoJack = new HashMap<>();
|
private Map<LoJackFunctionAndID, Alias> mLoJack = new HashMap<>();
|
||||||
private Map<String,Alias> mMDC1200 = new HashMap<>();
|
private Map<String, Alias> mMDC1200 = new HashMap<>();
|
||||||
private Map<String,Alias> mMobileID = new HashMap<>();
|
private Map<String, Alias> mMobileID = new HashMap<>();
|
||||||
private Map<String,Alias> mMPT1327 = new HashMap<>();
|
private Map<String, Alias> mMPT1327 = new HashMap<>();
|
||||||
private Map<String, Alias> mSiteID = new HashMap<>();
|
private Map<String, Alias> mSiteID = new HashMap<>();
|
||||||
private Map<Integer, Alias> mStatus = new HashMap<>();
|
private Map<Integer, Alias> mStatus = new HashMap<>();
|
||||||
private Map<String,Alias> mTalkgroup = new HashMap<>();
|
private Map<String, Alias> mTalkgroup = new HashMap<>();
|
||||||
private Map<Integer,Alias> mUniqueID = new HashMap<>();
|
private Map<Integer, Alias> mUniqueID = new HashMap<>();
|
||||||
|
|
||||||
private List<String> mESNWildcards = new ArrayList<>();
|
private List<WildcardID> mESNWildcards = new ArrayList<>();
|
||||||
private List<String> mMobileIDWildcards = new ArrayList<>();
|
private List<WildcardID> mMobileIDWildcards = new ArrayList<>();
|
||||||
private List<String> mFleetsyncWildcards = new ArrayList<>();
|
private List<WildcardID> mFleetsyncWildcards = new ArrayList<>();
|
||||||
private List<String> mMDC1200Wildcards = new ArrayList<>();
|
private List<WildcardID> mMDC1200Wildcards = new ArrayList<>();
|
||||||
private List<String> mMPT1327Wildcards = new ArrayList<>();
|
private List<WildcardID> mMPT1327Wildcards = new ArrayList<>();
|
||||||
private List<String> mSiteWildcards = new ArrayList<>();
|
private List<WildcardID> mSiteWildcards = new ArrayList<>();
|
||||||
private List<String> mTalkgroupWildcards = new ArrayList<>();
|
private List<WildcardID> mTalkgroupWildcards = new ArrayList<>();
|
||||||
|
|
||||||
private String mName;
|
private String mName;
|
||||||
|
|
||||||
@@ -72,7 +76,7 @@ public class AliasList implements Listener<AliasEvent>
|
|||||||
*
|
*
|
||||||
* Responds to alias change events to keep the internal alias list updated.
|
* Responds to alias change events to keep the internal alias list updated.
|
||||||
*/
|
*/
|
||||||
public AliasList( String name )
|
public AliasList(String name)
|
||||||
{
|
{
|
||||||
mName = name;
|
mName = name;
|
||||||
}
|
}
|
||||||
@@ -80,13 +84,13 @@ public class AliasList implements Listener<AliasEvent>
|
|||||||
/**
|
/**
|
||||||
* Adds the alias to this list
|
* Adds the alias to this list
|
||||||
*/
|
*/
|
||||||
public void addAlias( Alias alias )
|
public void addAlias(Alias alias)
|
||||||
{
|
{
|
||||||
if( alias != null )
|
if (alias != null)
|
||||||
{
|
{
|
||||||
for( AliasID aliasID: alias.getId() )
|
for (AliasID aliasID : alias.getId())
|
||||||
{
|
{
|
||||||
addAliasID( aliasID, alias );
|
addAliasID(aliasID, alias);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,131 +98,119 @@ public class AliasList implements Listener<AliasEvent>
|
|||||||
/**
|
/**
|
||||||
* Adds the alias and alias identifier to the internal type mapping.
|
* Adds the alias and alias identifier to the internal type mapping.
|
||||||
*/
|
*/
|
||||||
private void addAliasID( AliasID id, Alias alias )
|
private void addAliasID(AliasID id, Alias alias)
|
||||||
{
|
{
|
||||||
if(id.isValid())
|
if (id.isValid())
|
||||||
{
|
{
|
||||||
switch( id.getType() )
|
try
|
||||||
|
{
|
||||||
|
switch (id.getType())
|
||||||
{
|
{
|
||||||
case ESN:
|
case ESN:
|
||||||
Esn esn = (Esn)id;
|
String esn = ((Esn)id).getEsn();
|
||||||
if( esn.getEsn().contains(WILDCARD) )
|
|
||||||
{
|
|
||||||
String regexESN = convertToRegex(esn.getEsn());
|
|
||||||
|
|
||||||
mESNWildcards.add(regexESN);
|
if(esn != null)
|
||||||
mESN.put( regexESN, alias );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
mESN.put( esn.getEsn(), alias );
|
if (esn.contains(WILDCARD))
|
||||||
|
{
|
||||||
|
mESNWildcards.add(new WildcardID(esn));
|
||||||
|
Collections.sort(mESNWildcards);
|
||||||
|
}
|
||||||
|
|
||||||
|
mESN.put(esn, alias);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Fleetsync:
|
case Fleetsync:
|
||||||
FleetsyncID fs = (FleetsyncID)id;
|
String fleetsync = ((FleetsyncID)id).getIdent();
|
||||||
|
|
||||||
if( fs.getIdent().contains(WILDCARD) )
|
if(fleetsync != null)
|
||||||
{
|
{
|
||||||
String regexFleetsync = convertToRegex( fs.getIdent() );
|
if (fleetsync.contains(WILDCARD))
|
||||||
|
{
|
||||||
mFleetsyncWildcards.add(regexFleetsync);
|
mFleetsyncWildcards.add(new WildcardID(fleetsync));
|
||||||
mFleetsync.put( regexFleetsync, alias );
|
Collections.sort(mFleetsyncWildcards);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
mFleetsync.put(fleetsync, alias);
|
||||||
mFleetsync.put( fs.getIdent(), alias );
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case LoJack:
|
case LoJack:
|
||||||
mLoJack.put( (LoJackFunctionAndID)id, alias );
|
mLoJack.put((LoJackFunctionAndID) id, alias);
|
||||||
break;
|
break;
|
||||||
case MDC1200:
|
case MDC1200:
|
||||||
MDC1200ID mdc = (MDC1200ID)id;
|
String mdc = ((MDC1200ID)id).getIdent();
|
||||||
|
|
||||||
if( mdc.getIdent().contains(WILDCARD) )
|
if(mdc != null)
|
||||||
{
|
{
|
||||||
String regexMDC = convertToRegex(mdc.getIdent());
|
if (mdc.contains(WILDCARD))
|
||||||
|
{
|
||||||
mMDC1200Wildcards.add(regexMDC);
|
mMDC1200Wildcards.add(new WildcardID(mdc));
|
||||||
mMDC1200.put(regexMDC, alias);
|
Collections.sort(mMDC1200Wildcards);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
mMDC1200.put(mdc, alias);
|
||||||
mMDC1200.put( mdc.getIdent(), alias );
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MPT1327:
|
case MPT1327:
|
||||||
MPT1327ID mpt = (MPT1327ID)id;
|
String mpt = ((MPT1327ID)id).getIdent();
|
||||||
|
|
||||||
String ident = mpt.getIdent();
|
if(mpt != null)
|
||||||
|
|
||||||
if( ident != null )
|
|
||||||
{
|
{
|
||||||
if( ident.contains(WILDCARD) )
|
if (mpt.contains(WILDCARD))
|
||||||
{
|
{
|
||||||
String regexMPT1327 = convertToRegex(ident);
|
mMPT1327Wildcards.add(new WildcardID(mpt));
|
||||||
|
Collections.sort(mMPT1327Wildcards);
|
||||||
mMPT1327Wildcards.add(regexMPT1327);
|
|
||||||
mMPT1327.put(regexMPT1327, alias);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mMPT1327.put( ident, alias );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mMPT1327.put(mpt, alias);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MIN:
|
case MIN:
|
||||||
Min min = (Min)id;
|
String min = ((Min)id).getMin();
|
||||||
|
|
||||||
if( min.getMin().contains(WILDCARD) )
|
if(min != null)
|
||||||
{
|
{
|
||||||
String regexMIN = convertToRegex(min.getMin());
|
if (min.contains(WILDCARD))
|
||||||
|
{
|
||||||
mMobileIDWildcards.add(regexMIN);
|
mMobileIDWildcards.add(new WildcardID(min));
|
||||||
mMobileID.put( regexMIN, alias );
|
Collections.sort(mMobileIDWildcards);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
mMobileID.put(min, alias);
|
||||||
mMobileID.put( min.getMin(), alias );
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case LTRNetUID:
|
case LTRNetUID:
|
||||||
UniqueID uid = (UniqueID)id;
|
mUniqueID.put(((UniqueID)id).getUid(), alias);
|
||||||
|
|
||||||
mUniqueID.put( uid.getUid(), alias );
|
|
||||||
break;
|
break;
|
||||||
case Site:
|
case Site:
|
||||||
SiteID siteID = (SiteID)id;
|
String siteID = ((SiteID)id).getSite();
|
||||||
|
|
||||||
if( siteID.getSite().contains(WILDCARD) )
|
if(siteID != null)
|
||||||
{
|
{
|
||||||
String regexSiteID = convertToRegex(siteID.getSite());
|
if (siteID.contains(WILDCARD))
|
||||||
|
|
||||||
mSiteWildcards.add(regexSiteID);
|
|
||||||
mSiteID.put( regexSiteID, alias );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
mSiteID.put( siteID.getSite(), alias );
|
mSiteWildcards.add(new WildcardID(siteID));
|
||||||
|
Collections.sort(mSiteWildcards);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mSiteID.put(siteID, alias);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Status:
|
case Status:
|
||||||
mStatus.put( ((StatusID)id).getStatus(), alias );
|
mStatus.put(((StatusID) id).getStatus(), alias);
|
||||||
break;
|
break;
|
||||||
case Talkgroup:
|
case Talkgroup:
|
||||||
TalkgroupID tgid = (TalkgroupID)id;
|
String tgid = ((TalkgroupID)id).getTalkgroup();
|
||||||
|
|
||||||
if( tgid.getTalkgroup().contains(WILDCARD) )
|
if(tgid != null)
|
||||||
{
|
{
|
||||||
String regexTalkgroup = convertToRegex(tgid.getTalkgroup());
|
if (tgid.contains(WILDCARD))
|
||||||
|
{
|
||||||
mTalkgroupWildcards.add(regexTalkgroup);
|
mTalkgroupWildcards.add(new WildcardID(tgid));
|
||||||
mTalkgroup.put( regexTalkgroup, alias );
|
Collections.sort(mTalkgroupWildcards);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
mTalkgroup.put(tgid, alias);
|
||||||
mTalkgroup.put( tgid.getTalkgroup(), alias );
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NonRecordable:
|
case NonRecordable:
|
||||||
@@ -226,22 +218,41 @@ public class AliasList implements Listener<AliasEvent>
|
|||||||
//We don't maintain lookups for these items
|
//We don't maintain lookups for these items
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
mLog.warn( "Unrecognized Alias ID Type:" + id.getType().name() );
|
mLog.warn("Unrecognized Alias ID Type:" + id.getType().name());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
mLog.error("Couldn't add alias ID " + id + " for alias " + alias);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the alias from this list
|
* Removes the alias from this list
|
||||||
*/
|
*/
|
||||||
public void removeAlias( Alias alias )
|
public void removeAlias(Alias alias)
|
||||||
{
|
{
|
||||||
if( alias != null )
|
if (alias != null)
|
||||||
{
|
{
|
||||||
for( AliasID aliasID: alias.getId() )
|
for (AliasID aliasID : alias.getId())
|
||||||
{
|
{
|
||||||
removeAliasID( aliasID, alias );
|
removeAliasID(aliasID, alias);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeWildcard(String value, List<WildcardID> wildcards)
|
||||||
|
{
|
||||||
|
if(value != null)
|
||||||
|
{
|
||||||
|
for(WildcardID wildcardID: wildcards)
|
||||||
|
{
|
||||||
|
if(wildcardID.value().equals(value))
|
||||||
|
{
|
||||||
|
wildcards.remove(wildcardID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -249,106 +260,100 @@ public class AliasList implements Listener<AliasEvent>
|
|||||||
/**
|
/**
|
||||||
* Removes the alias and alias identifier from internal mappings.
|
* Removes the alias and alias identifier from internal mappings.
|
||||||
*/
|
*/
|
||||||
private void removeAliasID( AliasID id, Alias alias )
|
private void removeAliasID(AliasID id, Alias alias)
|
||||||
{
|
{
|
||||||
if(id.isValid())
|
if (id.isValid())
|
||||||
{
|
{
|
||||||
switch( id.getType() )
|
switch (id.getType())
|
||||||
{
|
{
|
||||||
case ESN:
|
case ESN:
|
||||||
Esn esn = (Esn)id;
|
String esn = ((Esn)id).getEsn();
|
||||||
|
|
||||||
if( esn.getEsn().contains(WILDCARD))
|
if(esn != null)
|
||||||
{
|
{
|
||||||
String regexESN = convertToRegex(esn.getEsn());
|
if(esn.contains(WILDCARD))
|
||||||
mESN.remove(regexESN);
|
|
||||||
mESNWildcards.remove(regexESN);
|
|
||||||
}
|
|
||||||
else if( mESN.containsKey( esn.getEsn() ) )
|
|
||||||
{
|
{
|
||||||
mESN.remove(esn.getEsn());
|
removeWildcard(esn, mESNWildcards);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mESN.remove(esn);
|
||||||
break;
|
break;
|
||||||
case Fleetsync:
|
case Fleetsync:
|
||||||
FleetsyncID fs = (FleetsyncID)id;
|
String fleetsync = ((FleetsyncID)id).getIdent();
|
||||||
|
|
||||||
if(fs.getIdent().contains(WILDCARD))
|
if(fleetsync != null)
|
||||||
{
|
{
|
||||||
String regexFleetsync = convertToRegex(fs.getIdent());
|
if(fleetsync.contains(WILDCARD))
|
||||||
mFleetsync.remove(regexFleetsync);
|
{
|
||||||
mFleetsyncWildcards.remove(regexFleetsync);
|
removeWildcard(fleetsync,mFleetsyncWildcards);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
mFleetsync.remove(fleetsync);
|
||||||
mFleetsync.remove( fs.getIdent() );
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case LoJack:
|
case LoJack:
|
||||||
mLoJack.remove((LoJackFunctionAndID)id);
|
mLoJack.remove((LoJackFunctionAndID) id);
|
||||||
break;
|
break;
|
||||||
case MDC1200:
|
case MDC1200:
|
||||||
MDC1200ID mdc = (MDC1200ID)id;
|
String mdc = ((MDC1200ID)id).getIdent();
|
||||||
|
|
||||||
if(mdc.getIdent().contains(WILDCARD))
|
if(mdc != null)
|
||||||
{
|
{
|
||||||
String regexMDC1200 = convertToRegex(mdc.getIdent());
|
if(mdc.contains(WILDCARD))
|
||||||
mMDC1200.remove(regexMDC1200);
|
{
|
||||||
mMDC1200Wildcards.remove(regexMDC1200);
|
removeWildcard(mdc, mMDC1200Wildcards);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
mMDC1200.remove(mdc);
|
||||||
mMDC1200.remove( mdc.getIdent() );
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MPT1327:
|
case MPT1327:
|
||||||
MPT1327ID mpt = (MPT1327ID)id;
|
String mpt = ((MPT1327ID)id).getIdent();
|
||||||
|
|
||||||
if(mpt.getIdent().contains(WILDCARD))
|
if(mpt != null)
|
||||||
{
|
{
|
||||||
String regexMPT1327 = convertToRegex(mpt.getIdent());
|
if(mpt.contains(WILDCARD))
|
||||||
mMPT1327.remove(regexMPT1327);
|
{
|
||||||
mMPT1327Wildcards.remove(regexMPT1327);
|
removeWildcard(mpt, mMPT1327Wildcards);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
mMPT1327.remove(mpt);
|
||||||
mMPT1327.remove( mpt.getIdent() );
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MIN:
|
case MIN:
|
||||||
Min min = (Min)id;
|
String min = ((Min)id).getMin();
|
||||||
|
|
||||||
if(min.getMin().contains(WILDCARD))
|
if(min != null)
|
||||||
{
|
{
|
||||||
String regexMIN = convertToRegex(min.getMin());
|
if(min.contains(WILDCARD))
|
||||||
mMobileID.remove(regexMIN);
|
{
|
||||||
mMobileIDWildcards.remove(regexMIN);
|
removeWildcard(min, mMobileIDWildcards);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
mMobileID.remove(min);
|
||||||
mMobileID.remove( min.getMin() );
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case LTRNetUID:
|
case LTRNetUID:
|
||||||
mUniqueID.remove( ((UniqueID)id).getUid() );
|
mUniqueID.remove(((UniqueID) id).getUid());
|
||||||
break;
|
break;
|
||||||
case Site:
|
case Site:
|
||||||
mSiteID.remove( ((SiteID)id).getSite() );
|
mSiteID.remove(((SiteID) id).getSite());
|
||||||
break;
|
break;
|
||||||
case Status:
|
case Status:
|
||||||
mStatus.remove( ((StatusID)id).getStatus() );
|
mStatus.remove(((StatusID) id).getStatus());
|
||||||
break;
|
break;
|
||||||
case Talkgroup:
|
case Talkgroup:
|
||||||
TalkgroupID tg = (TalkgroupID)id;
|
String tgid = ((TalkgroupID)id).getTalkgroup();
|
||||||
|
|
||||||
if(tg.getTalkgroup().contains(WILDCARD))
|
if(tgid != null)
|
||||||
{
|
{
|
||||||
String regexTalkgroup = convertToRegex(tg.getTalkgroup());
|
if(tgid.contains(WILDCARD))
|
||||||
mTalkgroup.remove(regexTalkgroup);
|
{
|
||||||
mTalkgroupWildcards.remove(regexTalkgroup);
|
removeWildcard(tgid, mTalkgroupWildcards);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
mTalkgroup.remove(tgid);
|
||||||
mTalkgroup.remove( tg.getTalkgroup() );
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NonRecordable:
|
case NonRecordable:
|
||||||
@@ -356,26 +361,12 @@ public class AliasList implements Listener<AliasEvent>
|
|||||||
//We don't maintain lookups for these items
|
//We don't maintain lookups for these items
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
mLog.warn( "Unrecognized Alias ID Type:" + id.getType().name() );
|
mLog.warn("Unrecognized Alias ID Type:" + id.getType().name());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts user wildcard character (*) to regex single character wildcard (.)
|
|
||||||
* but ignores a regex multi-character wildcard (.*)
|
|
||||||
*/
|
|
||||||
private String convertToRegex(String value )
|
|
||||||
{
|
|
||||||
if( value.contains(WILDCARD) && !value.contains( ".*" ) )
|
|
||||||
{
|
|
||||||
return value.replace(WILDCARD, "." );
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the first matching regex wildcard from the list of wildcards that matches the
|
* Returns the first matching regex wildcard from the list of wildcards that matches the
|
||||||
* identifier.
|
* identifier.
|
||||||
@@ -384,15 +375,15 @@ public class AliasList implements Listener<AliasEvent>
|
|||||||
* @param wildcards to match against
|
* @param wildcards to match against
|
||||||
* @return matching wildcard ID or null
|
* @return matching wildcard ID or null
|
||||||
*/
|
*/
|
||||||
private String getWildcardMatch( String id, List<String> wildcards )
|
private String getWildcardMatch(String id, List<WildcardID> wildcards)
|
||||||
{
|
{
|
||||||
if(id != null)
|
if (id != null)
|
||||||
{
|
{
|
||||||
for(String wildcard: wildcards)
|
for (WildcardID wildcard : wildcards)
|
||||||
{
|
{
|
||||||
if(id.matches(wildcard))
|
if (wildcard.matches(id))
|
||||||
{
|
{
|
||||||
return wildcard;
|
return wildcard.value();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -403,19 +394,19 @@ public class AliasList implements Listener<AliasEvent>
|
|||||||
/**
|
/**
|
||||||
* Lookup alias by site ID
|
* Lookup alias by site ID
|
||||||
*/
|
*/
|
||||||
public Alias getSiteID( String siteID )
|
public Alias getSiteID(String siteID)
|
||||||
{
|
{
|
||||||
Alias alias = null;
|
Alias alias = null;
|
||||||
|
|
||||||
if(siteID != null)
|
if (siteID != null)
|
||||||
{
|
{
|
||||||
alias = mSiteID.get(siteID);
|
alias = mSiteID.get(siteID);
|
||||||
|
|
||||||
if(alias == null)
|
if (alias == null)
|
||||||
{
|
{
|
||||||
String wildcard = getWildcardMatch(siteID, mSiteWildcards);
|
String wildcard = getWildcardMatch(siteID, mSiteWildcards);
|
||||||
|
|
||||||
if(wildcard != null)
|
if (wildcard != null)
|
||||||
{
|
{
|
||||||
alias = mSiteID.get(wildcard);
|
alias = mSiteID.get(wildcard);
|
||||||
}
|
}
|
||||||
@@ -428,35 +419,35 @@ public class AliasList implements Listener<AliasEvent>
|
|||||||
/**
|
/**
|
||||||
* Lookup alias by status ID
|
* Lookup alias by status ID
|
||||||
*/
|
*/
|
||||||
public Alias getStatus( int status )
|
public Alias getStatus(int status)
|
||||||
{
|
{
|
||||||
return mStatus.get( status );
|
return mStatus.get(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lookup alias by Unique ID (UID)
|
* Lookup alias by Unique ID (UID)
|
||||||
*/
|
*/
|
||||||
public Alias getUniqueID( int uniqueID )
|
public Alias getUniqueID(int uniqueID)
|
||||||
{
|
{
|
||||||
return mUniqueID.get( uniqueID );
|
return mUniqueID.get(uniqueID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lookup alias by ESN
|
* Lookup alias by ESN
|
||||||
*/
|
*/
|
||||||
public Alias getESNAlias( String esn )
|
public Alias getESNAlias(String esn)
|
||||||
{
|
{
|
||||||
Alias alias = null;
|
Alias alias = null;
|
||||||
|
|
||||||
if(esn != null)
|
if (esn != null)
|
||||||
{
|
{
|
||||||
alias = mESN.get(esn);
|
alias = mESN.get(esn);
|
||||||
|
|
||||||
if(alias == null)
|
if (alias == null)
|
||||||
{
|
{
|
||||||
String wildcard = getWildcardMatch(esn, mESNWildcards);
|
String wildcard = getWildcardMatch(esn, mESNWildcards);
|
||||||
|
|
||||||
if(wildcard != null)
|
if (wildcard != null)
|
||||||
{
|
{
|
||||||
alias = mESN.get(wildcard);
|
alias = mESN.get(wildcard);
|
||||||
}
|
}
|
||||||
@@ -469,19 +460,19 @@ public class AliasList implements Listener<AliasEvent>
|
|||||||
/**
|
/**
|
||||||
* Lookup alias by fleetsync ID
|
* Lookup alias by fleetsync ID
|
||||||
*/
|
*/
|
||||||
public Alias getFleetsyncAlias( String ident )
|
public Alias getFleetsyncAlias(String ident)
|
||||||
{
|
{
|
||||||
Alias alias = null;
|
Alias alias = null;
|
||||||
|
|
||||||
if( ident != null )
|
if (ident != null)
|
||||||
{
|
{
|
||||||
alias = mFleetsync.get(ident);
|
alias = mFleetsync.get(ident);
|
||||||
|
|
||||||
if(alias == null)
|
if (alias == null)
|
||||||
{
|
{
|
||||||
String wildcard = getWildcardMatch(ident, mFleetsyncWildcards);
|
String wildcard = getWildcardMatch(ident, mFleetsyncWildcards);
|
||||||
|
|
||||||
if(wildcard != null)
|
if (wildcard != null)
|
||||||
{
|
{
|
||||||
alias = mFleetsync.get(wildcard);
|
alias = mFleetsync.get(wildcard);
|
||||||
}
|
}
|
||||||
@@ -494,15 +485,15 @@ public class AliasList implements Listener<AliasEvent>
|
|||||||
/**
|
/**
|
||||||
* Lookup alias by lojack function and ID
|
* Lookup alias by lojack function and ID
|
||||||
*/
|
*/
|
||||||
public Alias getLoJackAlias( Function function, String id )
|
public Alias getLoJackAlias(Function function, String id)
|
||||||
{
|
{
|
||||||
if( id != null )
|
if (id != null)
|
||||||
{
|
{
|
||||||
for( LoJackFunctionAndID lojack: mLoJack.keySet() )
|
for (LoJackFunctionAndID lojack : mLoJack.keySet())
|
||||||
{
|
{
|
||||||
if( lojack.matches( function, id ) )
|
if (lojack.matches(function, id))
|
||||||
{
|
{
|
||||||
return mLoJack.get( lojack );
|
return mLoJack.get(lojack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -513,19 +504,19 @@ public class AliasList implements Listener<AliasEvent>
|
|||||||
/**
|
/**
|
||||||
* Lookup alias by MDC1200 ID
|
* Lookup alias by MDC1200 ID
|
||||||
*/
|
*/
|
||||||
public Alias getMDC1200Alias( String ident )
|
public Alias getMDC1200Alias(String ident)
|
||||||
{
|
{
|
||||||
Alias alias = null;
|
Alias alias = null;
|
||||||
|
|
||||||
if( ident != null )
|
if (ident != null)
|
||||||
{
|
{
|
||||||
alias = mMDC1200.get(ident);
|
alias = mMDC1200.get(ident);
|
||||||
|
|
||||||
if(alias == null)
|
if (alias == null)
|
||||||
{
|
{
|
||||||
String wildcard = getWildcardMatch(ident, mMDC1200Wildcards);
|
String wildcard = getWildcardMatch(ident, mMDC1200Wildcards);
|
||||||
|
|
||||||
if(wildcard != null)
|
if (wildcard != null)
|
||||||
{
|
{
|
||||||
alias = mMDC1200.get(wildcard);
|
alias = mMDC1200.get(wildcard);
|
||||||
}
|
}
|
||||||
@@ -538,19 +529,19 @@ public class AliasList implements Listener<AliasEvent>
|
|||||||
/**
|
/**
|
||||||
* Lookup alias by MPT1327 Ident
|
* Lookup alias by MPT1327 Ident
|
||||||
*/
|
*/
|
||||||
public Alias getMPT1327Alias( String ident )
|
public Alias getMPT1327Alias(String ident)
|
||||||
{
|
{
|
||||||
Alias alias = null;
|
Alias alias = null;
|
||||||
|
|
||||||
if( ident != null )
|
if (ident != null)
|
||||||
{
|
{
|
||||||
alias = mMPT1327.get(ident);
|
alias = mMPT1327.get(ident);
|
||||||
|
|
||||||
if(alias == null)
|
if (alias == null)
|
||||||
{
|
{
|
||||||
String wildcard = getWildcardMatch(ident, mMPT1327Wildcards);
|
String wildcard = getWildcardMatch(ident, mMPT1327Wildcards);
|
||||||
|
|
||||||
if(wildcard != null)
|
if (wildcard != null)
|
||||||
{
|
{
|
||||||
alias = mMPT1327.get(wildcard);
|
alias = mMPT1327.get(wildcard);
|
||||||
}
|
}
|
||||||
@@ -563,19 +554,19 @@ public class AliasList implements Listener<AliasEvent>
|
|||||||
/**
|
/**
|
||||||
* Lookup alias by Mobile ID Number (MIN)
|
* Lookup alias by Mobile ID Number (MIN)
|
||||||
*/
|
*/
|
||||||
public Alias getMobileIDNumberAlias( String ident )
|
public Alias getMobileIDNumberAlias(String ident)
|
||||||
{
|
{
|
||||||
Alias alias = null;
|
Alias alias = null;
|
||||||
|
|
||||||
if( ident != null )
|
if (ident != null)
|
||||||
{
|
{
|
||||||
alias = mMobileID.get(ident);
|
alias = mMobileID.get(ident);
|
||||||
|
|
||||||
if(alias == null)
|
if (alias == null)
|
||||||
{
|
{
|
||||||
String wildcard = getWildcardMatch(ident, mMobileIDWildcards);
|
String wildcard = getWildcardMatch(ident, mMobileIDWildcards);
|
||||||
|
|
||||||
if(wildcard != null)
|
if (wildcard != null)
|
||||||
{
|
{
|
||||||
alias = mMobileID.get(wildcard);
|
alias = mMobileID.get(wildcard);
|
||||||
}
|
}
|
||||||
@@ -588,19 +579,19 @@ public class AliasList implements Listener<AliasEvent>
|
|||||||
/**
|
/**
|
||||||
* Lookup alias by talkgroup
|
* Lookup alias by talkgroup
|
||||||
*/
|
*/
|
||||||
public Alias getTalkgroupAlias( String tgid )
|
public Alias getTalkgroupAlias(String tgid)
|
||||||
{
|
{
|
||||||
Alias alias = null;
|
Alias alias = null;
|
||||||
|
|
||||||
if( tgid != null )
|
if (tgid != null)
|
||||||
{
|
{
|
||||||
alias = mTalkgroup.get(tgid);
|
alias = mTalkgroup.get(tgid);
|
||||||
|
|
||||||
if(alias == null)
|
if (alias == null)
|
||||||
{
|
{
|
||||||
String wildcard = getWildcardMatch(tgid, mTalkgroupWildcards);
|
String wildcard = getWildcardMatch(tgid, mTalkgroupWildcards);
|
||||||
|
|
||||||
if(wildcard != null)
|
if (wildcard != null)
|
||||||
{
|
{
|
||||||
alias = mTalkgroup.get(wildcard);
|
alias = mTalkgroup.get(wildcard);
|
||||||
}
|
}
|
||||||
@@ -630,30 +621,30 @@ public class AliasList implements Listener<AliasEvent>
|
|||||||
/**
|
/**
|
||||||
* Lookup an alias by metadata type and string value
|
* Lookup an alias by metadata type and string value
|
||||||
*/
|
*/
|
||||||
public Alias getAlias( String value, MetadataType type )
|
public Alias getAlias(String value, MetadataType type)
|
||||||
{
|
{
|
||||||
switch( type )
|
switch (type)
|
||||||
{
|
{
|
||||||
case ESN:
|
case ESN:
|
||||||
return getESNAlias( value );
|
return getESNAlias(value);
|
||||||
case FLEETSYNC:
|
case FLEETSYNC:
|
||||||
return getFleetsyncAlias( value );
|
return getFleetsyncAlias(value);
|
||||||
case MDC1200:
|
case MDC1200:
|
||||||
return getMDC1200Alias( value );
|
return getMDC1200Alias(value);
|
||||||
case MOBILE_ID:
|
case MOBILE_ID:
|
||||||
return getMobileIDNumberAlias( value );
|
return getMobileIDNumberAlias(value);
|
||||||
case MPT1327:
|
case MPT1327:
|
||||||
return getMPT1327Alias( value );
|
return getMPT1327Alias(value);
|
||||||
case SITE_ID:
|
case SITE_ID:
|
||||||
return getSiteID( value );
|
return getSiteID(value);
|
||||||
case STATUS:
|
case STATUS:
|
||||||
if( value != null )
|
if (value != null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return getStatus( Integer.valueOf( value ) );
|
return getStatus(Integer.valueOf(value));
|
||||||
}
|
}
|
||||||
catch( Exception e )
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
//do nothing, we couldn't parse the int value
|
//do nothing, we couldn't parse the int value
|
||||||
}
|
}
|
||||||
@@ -661,15 +652,15 @@ public class AliasList implements Listener<AliasEvent>
|
|||||||
break;
|
break;
|
||||||
case FROM:
|
case FROM:
|
||||||
case TO:
|
case TO:
|
||||||
return getTalkgroupAlias( value );
|
return getTalkgroupAlias(value);
|
||||||
case UNIQUE_ID:
|
case UNIQUE_ID:
|
||||||
if( value != null )
|
if (value != null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return getUniqueID( Integer.valueOf( value ) );
|
return getUniqueID(Integer.valueOf(value));
|
||||||
}
|
}
|
||||||
catch( Exception e )
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
//do nothing, we couldn't parse the int value
|
//do nothing, we couldn't parse the int value
|
||||||
}
|
}
|
||||||
@@ -686,28 +677,28 @@ public class AliasList implements Listener<AliasEvent>
|
|||||||
* Receive alias change event notifications and modify this list accordingly
|
* Receive alias change event notifications and modify this list accordingly
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void receive( AliasEvent event )
|
public void receive(AliasEvent event)
|
||||||
{
|
{
|
||||||
Alias alias = event.getAlias();
|
Alias alias = event.getAlias();
|
||||||
|
|
||||||
switch( event.getEvent() )
|
switch (event.getEvent())
|
||||||
{
|
{
|
||||||
case ADD:
|
case ADD:
|
||||||
if( alias.getList() != null && getName().equalsIgnoreCase( alias.getList() ) )
|
if (alias.getList() != null && getName().equalsIgnoreCase(alias.getList()))
|
||||||
{
|
{
|
||||||
addAlias( alias );
|
addAlias(alias);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CHANGE:
|
case CHANGE:
|
||||||
if( alias.getList() != null && getName().equalsIgnoreCase( alias.getList() ) )
|
if (alias.getList() != null && getName().equalsIgnoreCase(alias.getList()))
|
||||||
{
|
{
|
||||||
addAlias( alias );
|
addAlias(alias);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DELETE:
|
case DELETE:
|
||||||
if( alias.getList() != null && getName().equalsIgnoreCase( alias.getList() ) )
|
if (alias.getList() != null && getName().equalsIgnoreCase(alias.getList()))
|
||||||
{
|
{
|
||||||
removeAlias( alias );
|
removeAlias(alias);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
111
src/alias/id/WildcardID.java
Normal file
111
src/alias/id/WildcardID.java
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* sdrtrunk
|
||||||
|
* Copyright (C) 2014-2016 Dennis Sheirer
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
package alias.id;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class WildcardID implements Comparable<WildcardID>
|
||||||
|
{
|
||||||
|
public static final String WILDCARD = "*";
|
||||||
|
public static final String REGEX_WILDCARD = ".";
|
||||||
|
|
||||||
|
private String mValue;
|
||||||
|
private Pattern mPattern;
|
||||||
|
private int mWeight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wildcard identifier for matching to string identifiers containing single-character (*) wildcard values.
|
||||||
|
*
|
||||||
|
* Supports ordering from most-specific to least-specific using the build-in weighting calculation where identifier
|
||||||
|
* patterns containing fewer wildcards closer to the least significant digit will be weighted more heavily than
|
||||||
|
* identifier patterns containing more wildcards, or wildcard characters in the most significant digits.
|
||||||
|
*
|
||||||
|
* @param value is a string value containing one or more asterisk (*) single character wildcard with a maximum
|
||||||
|
* length of 10 characters.
|
||||||
|
*
|
||||||
|
* @throws AssertionError if the value is null, longer than 10 characters, or doesn't contain at least 1 asterisk
|
||||||
|
* @throws IllegalArgumentException if the value cannot be compiled as a regular expression after converting the
|
||||||
|
* asterisk characters to the regex single-character wildcard value (.)
|
||||||
|
*/
|
||||||
|
public WildcardID(String value)
|
||||||
|
{
|
||||||
|
assert(value != null && value.contains(WILDCARD) && value.length() < 10);
|
||||||
|
|
||||||
|
mValue = value;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mPattern = Pattern.compile(value.replace(WILDCARD, REGEX_WILDCARD));
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("Invalid regex pattern for alias ID value [" + value + "]", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
mWeight = calculateWeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String value()
|
||||||
|
{
|
||||||
|
return mValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the id matches the internal regex pattern for this wildcard alias ID
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean matches(String id)
|
||||||
|
{
|
||||||
|
return id != null && mPattern.matcher(id).matches();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int weight()
|
||||||
|
{
|
||||||
|
return mWeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates a weighting value for wildcard character quantity and significant digit location
|
||||||
|
*/
|
||||||
|
private int calculateWeight()
|
||||||
|
{
|
||||||
|
int weight = 0;
|
||||||
|
int characterCount = -1;
|
||||||
|
|
||||||
|
for( int x = 0; x < mValue.length(); x++)
|
||||||
|
{
|
||||||
|
if(mValue.substring(x, x + 1).equals(WILDCARD))
|
||||||
|
{
|
||||||
|
weight += (int)(Math.pow(2, mValue.length() - x - 1)); //Position weight
|
||||||
|
characterCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
weight += (int)(Math.pow(2, characterCount)) * 1000; //Character count weight
|
||||||
|
|
||||||
|
return weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(WildcardID otherWildcardID)
|
||||||
|
{
|
||||||
|
return Integer.compare(this.weight(), otherWildcardID.weight());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user